2024-09-20 08:13:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
2024-09-29 04:50:59 +00:00
|
|
|
#include <string.h>
|
2024-09-20 08:13:20 +00:00
|
|
|
|
|
|
|
extern void *
|
2024-09-29 04:50:59 +00:00
|
|
|
shared_heap_malloc(uint32_t size);
|
2024-09-20 08:13:20 +00:00
|
|
|
extern void
|
2024-09-29 04:50:59 +00:00
|
|
|
shared_heap_free(void *ptr);
|
2024-09-20 08:13:20 +00:00
|
|
|
|
|
|
|
void *
|
2024-09-29 04:50:59 +00:00
|
|
|
my_shared_heap_malloc(uint32_t size, uint32_t index)
|
2024-09-20 08:13:20 +00:00
|
|
|
{
|
2024-09-29 04:50:59 +00:00
|
|
|
char *buf1 = NULL, *buf2 = NULL, *buf;
|
2024-09-20 08:13:20 +00:00
|
|
|
|
2024-09-29 04:50:59 +00:00
|
|
|
buf1 = shared_heap_malloc(128);
|
|
|
|
if (!buf1)
|
|
|
|
return NULL;
|
2024-09-20 08:13:20 +00:00
|
|
|
|
2024-09-29 04:50:59 +00:00
|
|
|
buf1[0] = 'H';
|
|
|
|
buf1[1] = 'e';
|
|
|
|
buf1[2] = 'l';
|
|
|
|
buf1[3] = 'l';
|
|
|
|
buf1[4] = 'o';
|
|
|
|
buf1[5] = ',';
|
|
|
|
buf1[6] = ' ';
|
|
|
|
|
|
|
|
buf2 = shared_heap_malloc(128);
|
|
|
|
if (!buf2) {
|
|
|
|
shared_heap_free(buf1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf2, 128, "this is buf %u allocated from shared heap", index);
|
|
|
|
|
|
|
|
buf = shared_heap_malloc(size);
|
|
|
|
if (!buf) {
|
|
|
|
shared_heap_free(buf1);
|
|
|
|
shared_heap_free(buf2);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buf, 0, size);
|
|
|
|
memcpy(buf, buf1, strlen(buf1));
|
|
|
|
memcpy(buf + strlen(buf1), buf2, strlen(buf2));
|
|
|
|
|
|
|
|
shared_heap_free(buf1);
|
|
|
|
shared_heap_free(buf2);
|
2024-09-20 08:13:20 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2024-09-29 04:50:59 +00:00
|
|
|
my_shared_heap_free(void *ptr)
|
2024-09-20 08:13:20 +00:00
|
|
|
{
|
2024-09-29 04:50:59 +00:00
|
|
|
shared_heap_free(ptr);
|
2024-09-20 08:13:20 +00:00
|
|
|
}
|