Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions core/shared/platform/linux-sgx/sgx_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you want to drop core/shared/platform/common/memory from core/shared/platform/linux-sgx/shared_platform.cmake ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I dropped it from shared_platform.cmake.

{
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)
{
Expand Down Expand Up @@ -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)
{}
{
}
3 changes: 0 additions & 3 deletions core/shared/platform/linux-sgx/shared_platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Loading