Add Linux SGX support (#106)

This commit is contained in:
wenyongh
2019-08-28 15:08:52 +08:00
committed by GitHub
parent c808aa2ebb
commit 5c69543c54
26 changed files with 2223 additions and 24 deletions

View File

@ -15,9 +15,9 @@
*/
#include "bh_config.h"
#include "bh_platform.h"
#include "bh_memory.h"
#include "mem_alloc.h"
#include <stdio.h>
#include <stdlib.h>
#if BEIHAI_ENABLE_MEMORY_PROFILING != 0
@ -76,7 +76,7 @@ int bh_memory_init_with_pool(void *mem, unsigned int bytes)
global_pool_size = bytes;
return 0;
}
printf("Init memory with pool (%p, %u) failed.\n", mem, bytes);
bh_printf("Init memory with pool (%p, %u) failed.\n", mem, bytes);
return -1;
}
@ -91,7 +91,7 @@ int bh_memory_init_with_allocator(void *_malloc_func, void *_free_func)
#endif
return 0;
}
printf("Init memory with allocator (%p, %p) failed.\n", _malloc_func,
bh_printf("Init memory with allocator (%p, %p) failed.\n", _malloc_func,
_free_func);
return -1;
}
@ -117,7 +117,7 @@ int bh_memory_pool_size()
void* bh_malloc_internal(unsigned int size)
{
if (memory_mode == MEMORY_MODE_UNKNOWN) {
printf("bh_malloc failed: memory hasn't been initialize.\n");
bh_printf("bh_malloc failed: memory hasn't been initialize.\n");
return NULL;
} else if (memory_mode == MEMORY_MODE_POOL) {
return mem_allocator_malloc(pool_allocator, size);
@ -129,7 +129,7 @@ void* bh_malloc_internal(unsigned int size)
void bh_free_internal(void *ptr)
{
if (memory_mode == MEMORY_MODE_UNKNOWN) {
printf("bh_free failed: memory hasn't been initialize.\n");
bh_printf("bh_free failed: memory hasn't been initialize.\n");
} else if (memory_mode == MEMORY_MODE_POOL) {
mem_allocator_free(pool_allocator, ptr);
} else {
@ -250,7 +250,7 @@ void memory_usage_summarize()
profile = memory_profiles_list;
while (profile) {
printf("malloc:%d:malloc_num:%d:free:%d:free_num:%d:%s\n",
bh_printf("malloc:%d:malloc_num:%d:free:%d:free_num:%d:%s\n",
profile->total_malloc,
profile->malloc_num,
profile->total_free,
@ -267,7 +267,7 @@ void memory_profile_print(const char *file,
const char *func,
int alloc)
{
printf("location:%s@%d:used:%d:contribution:%d\n",
bh_printf("location:%s@%d:used:%d:contribution:%d\n",
func, line, memory_in_use, alloc);
}
@ -328,4 +328,3 @@ void bh_free_profile(const char *file, int line, const char *func, void *ptr)
}
#endif /* end of BEIHAI_ENABLE_MEMORY_PROFILING */
#endif /* end of MALLOC_MEMORY_FROM_SYSTEM*/

View File

@ -118,7 +118,7 @@ static void unlink_hmu(gc_heap_t *heap, hmu_t *hmu)
}
if (!node) {
printf("[GC_ERROR]couldn't find the node in the normal list");
bh_printf("[GC_ERROR]couldn't find the node in the normal list");
}
} else {
remove_tree_node((hmu_tree_node_t *) hmu);
@ -392,7 +392,7 @@ gc_object_t _gc_alloc_vo_i_heap(void *vheap,
ret = hmu_to_obj(hmu);
#if BH_ENABLE_MEMORY_PROFILING != 0
printf("HEAP.ALLOC: heap: %p, size: %u", heap, size);
bh_printf("HEAP.ALLOC: heap: %p, size: %u", heap, size);
#endif
FINISH:
@ -434,7 +434,7 @@ gc_object_t _gc_alloc_jo_i_heap(void *vheap,
ret = hmu_to_obj(hmu);
#if BH_ENABLE_MEMORY_PROFILING != 0
printf("HEAP.ALLOC: heap: %p, size: %u", heap, size);
bh_printf("HEAP.ALLOC: heap: %p, size: %u", heap, size);
#endif
FINISH:
@ -495,7 +495,7 @@ int gc_free_i_heap(void *vheap, gc_object_t obj ALLOC_EXTRA_PARAMETERS)
heap->total_free_size += size;
#endif
#if BH_ENABLE_MEMORY_PROFILING != 0
printf("HEAP.FREE, heap: %p, size: %u\n",heap, size);
bh_printf("HEAP.FREE, heap: %p, size: %u\n",heap, size);
#endif
if (!hmu_get_pinuse(hmu)) {
@ -538,12 +538,12 @@ int gc_free_i_heap(void *vheap, gc_object_t obj ALLOC_EXTRA_PARAMETERS)
void gc_dump_heap_stats(gc_heap_t *heap)
{
printf("heap: %p, heap start: %p\n", heap, heap->base_addr);
printf(
bh_printf("heap: %p, heap start: %p\n", heap, heap->base_addr);
bh_printf(
"total malloc: totalfree: %u, current: %u, highmark: %u, gc cnt: %u\n",
heap->total_free_size, heap->current_size, heap->highmark_size,
heap->total_gc_count);
printf("g_total_malloc=%lu, g_total_free=%lu, occupied=%lu\n",
bh_printf("g_total_malloc=%lu, g_total_free=%lu, occupied=%lu\n",
g_total_malloc, g_total_free, g_total_malloc - g_total_free);
}

View File

@ -21,6 +21,7 @@
extern "C" {
#endif
#include "bh_platform.h"
#include "bh_thread.h"
#include "bh_memory.h"
#include "bh_assert.h"
@ -279,4 +280,3 @@ extern int (*gct_vm_gc_finished)(void);
#endif
#endif

View File

@ -30,7 +30,7 @@ int gci_check_platform()
{
#define CHECK(x, y) do { \
if((x) != (y)) { \
printf("Platform checking failed on LINE %d at FILE %s.", \
bh_printf("Platform checking failed on LINE %d at FILE %s.", \
__LINE__, __FILE__); \
return GC_ERROR; \
} \
@ -62,12 +62,12 @@ gc_handle_t gc_init_with_pool(char *buf, gc_size_t buf_size)
/* check system compatibility*/
if (gci_check_platform() == GC_ERROR) {
printf("Check platform compatibility failed");
bh_printf("Check platform compatibility failed");
return NULL;
}
if (buf_size < 1024) {
printf("[GC_ERROR]heap_init_size(%d) < 1024", buf_size);
bh_printf("[GC_ERROR]heap_init_size(%d) < 1024", buf_size);
return NULL;
}
@ -79,12 +79,12 @@ gc_handle_t gc_init_with_pool(char *buf, gc_size_t buf_size)
ret = gct_vm_mutex_init(&heap->lock);
if (ret != BHT_OK) {
printf("[GC_ERROR]failed to init lock ");
bh_printf("[GC_ERROR]failed to init lock ");
return NULL;
}
#ifdef BH_FOOTPRINT
printf("\nINIT HEAP 0x%08x %d\n", base_addr, heap_max_size);
bh_printf("\nINIT HEAP 0x%08x %d\n", base_addr, heap_max_size);
#endif
/* init all data structures*/
@ -131,7 +131,7 @@ gc_handle_t gc_init_with_pool(char *buf, gc_size_t buf_size)
&& HMU_FC_NORMAL_MAX_SIZE < q->size); /*@NOTIFY*/
#if BH_ENABLE_MEMORY_PROFILING != 0
printf("heap is successfully initialized with max_size=%u.",
bh_printf("heap is successfully initialized with max_size=%u.",
heap_max_size);
#endif
return heap;