diff --git a/core/shared/platform/linux-sgx/sgx_platform.c b/core/shared/platform/linux-sgx/sgx_platform.c index db350bc8f4..d259908634 100644 --- a/core/shared/platform/linux-sgx/sgx_platform.c +++ b/core/shared/platform/linux-sgx/sgx_platform.c @@ -131,8 +131,9 @@ os_is_handle_valid(os_file_handle *handle) /* implemented in posix_file.c */ #endif -void * -os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) +static void * +os_mmap_internal(void *hint, size_t size, int prot, int flags, + os_file_handle file, bool clear) { int mprot = 0; uint64 aligned_size, page_size; @@ -161,6 +162,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) return NULL; } + if (clear) { + memset(ret, 0, aligned_size); + } + if (prot & MMAP_PROT_READ) mprot |= SGX_PROT_READ; if (prot & MMAP_PROT_WRITE) @@ -179,6 +184,30 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) return ret; } +void * +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) +{ + return os_mmap_internal(hint, size, prot, flags, file, true); +} + +void * +os_mremap(void *old_addr, size_t old_size, size_t new_size) +{ + void *new_memory = + os_mmap_internal(NULL, new_size, MMAP_PROT_WRITE | MMAP_PROT_READ, 0, + os_get_invalid_handle(), false); + if (!new_memory) { + return NULL; + } + size_t copy_size = new_size < old_size ? new_size : old_size; + memcpy(new_memory, old_addr, copy_size); + if (new_size > copy_size) { + memset((char *)new_memory + copy_size, 0, new_size - copy_size); + } + os_munmap(old_addr, old_size); + return new_memory; +} + void os_munmap(void *addr, size_t size) { @@ -216,8 +245,10 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush(void) -{} +{ +} void os_icache_flush(void *start, size_t len) -{} +{ +} diff --git a/core/shared/platform/linux-sgx/shared_platform.cmake b/core/shared/platform/linux-sgx/shared_platform.cmake index 9cd765be4e..e8e1670058 100644 --- a/core/shared/platform/linux-sgx/shared_platform.cmake +++ b/core/shared/platform/linux-sgx/shared_platform.cmake @@ -37,9 +37,6 @@ else() set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE}) endif() -include (${CMAKE_CURRENT_LIST_DIR}/../common/memory/platform_api_memory.cmake) -set (source_all ${source_all} ${PLATFORM_COMMON_MEMORY_SOURCE}) - file (GLOB source_all_untrusted ${PLATFORM_SHARED_DIR}/untrusted/*.c) set (PLATFORM_SHARED_SOURCE ${source_all})