96 lines
1.9 KiB
C
96 lines
1.9 KiB
C
/*
|
|
* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
|
* source code may only be used and distributed under the Widevine Master
|
|
* License Agreement.
|
|
*/
|
|
|
|
#include "bump_allocator.h"
|
|
#include "marshaller_base.h"
|
|
|
|
static void InitBytes(uint8_t* ptr, size_t count) {
|
|
if (ptr && count) {
|
|
memset(ptr, 0, count);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* The functions here are declared weak so they can
|
|
* be overriden by test functions that inject
|
|
* various initialized values for testing
|
|
*/
|
|
|
|
__attribute__((weak)) void Init_bool(bool* value) {
|
|
if (value) {
|
|
*value = false;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void Init_size_t(size_t* value) {
|
|
if (value) {
|
|
*value = 0;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void Init_c_str(char** value) {
|
|
if (value) {
|
|
*value = NULL;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void Init_uint8_t(uint8_t* value) {
|
|
if (value) {
|
|
*value = 0;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void Init_uint16_t(uint16_t* value) {
|
|
if (value) {
|
|
*value = 0;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void Init_uint32_t(uint32_t* value) {
|
|
if (value) {
|
|
*value = 0;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void Init_uint64_t(uint64_t* value) {
|
|
if (value) {
|
|
*value = 0;
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void InitMemory(uint8_t* address, size_t length)
|
|
{
|
|
if (address && length) {
|
|
InitBytes(address, length);
|
|
}
|
|
}
|
|
|
|
__attribute__((weak)) void InitPointer(uint8_t** ptr) {
|
|
if (ptr) {
|
|
*ptr = NULL;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Allocate memory for a variable from the bump allocator, used for
|
|
* DeclarePackVar, DeclareUnpackVar, for some pointer types
|
|
*/
|
|
__attribute__((weak)) uint8_t* VarAlloc(size_t size) {
|
|
return BumpAllocate(size);
|
|
}
|
|
|
|
/*
|
|
* Special cases due to union & shared memory
|
|
*/
|
|
__attribute__((weak)) void Init_OEMCrypto_DestBufferDesc(OEMCrypto_DestBufferDesc* d) {
|
|
if (d) {
|
|
d->type = OEMCrypto_BufferType_Clear;
|
|
d->buffer.clear.address = NULL;
|
|
d->buffer.clear.max_length = 0;
|
|
}
|
|
}
|
|
|