cr suggestions

This commit is contained in:
TL 2025-02-12 16:41:34 +08:00 committed by Marcin Kolny
parent dfcadc6202
commit 2e4ebfb20a
3 changed files with 25 additions and 11 deletions

View File

@ -61,14 +61,16 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
request_size += HUGE_PAGE_SIZE; request_size += HUGE_PAGE_SIZE;
#endif #endif
if ((size_t)request_size < size) if ((size_t)request_size < size) {
/* integer overflow */ os_printf("mmap failed: request size overflow due to paging\n");
return NULL; return NULL;
}
#if WASM_ENABLE_MEMORY64 == 0 #if WASM_ENABLE_MEMORY64 == 0
if (request_size > 16 * (uint64)UINT32_MAX) if (request_size > 16 * (uint64)UINT32_MAX) {
/* at most 64 G is allowed */ os_printf("mmap failed: for memory64 at most 64G is allowed\n");
return NULL; return NULL;
}
#endif #endif
if (prot & MMAP_PROT_READ) if (prot & MMAP_PROT_READ)
@ -155,7 +157,7 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
if (addr == MAP_FAILED) { if (addr == MAP_FAILED) {
os_printf("mmap failed with errno: %d, hint: %p, size: %" PRIu64 os_printf("mmap failed with errno: %d, hint: %p, size: %" PRIu64
", prot: %d, flags: %d", ", prot: %d, flags: %d\n",
errno, hint, request_size, map_prot, map_flags); errno, hint, request_size, map_prot, map_flags);
return NULL; return NULL;
} }
@ -268,6 +270,8 @@ os_mprotect(void *addr, size_t size, int prot)
int map_prot = PROT_NONE; int map_prot = PROT_NONE;
uint64 page_size = (uint64)getpagesize(); uint64 page_size = (uint64)getpagesize();
uint64 request_size = (size + page_size - 1) & ~(page_size - 1); uint64 request_size = (size + page_size - 1) & ~(page_size - 1);
// printf("mprotect addr: %p, size: %llu, prot: %d\n", addr, request_size,
// prot);
if (!addr) if (!addr)
return 0; return 0;
@ -281,12 +285,17 @@ os_mprotect(void *addr, size_t size, int prot)
if (prot & MMAP_PROT_EXEC) if (prot & MMAP_PROT_EXEC)
map_prot |= PROT_EXEC; map_prot |= PROT_EXEC;
if (mprotect(addr, request_size, map_prot) == -1) {
printf("mprotect failed\n");
}
return mprotect(addr, request_size, map_prot); return mprotect(addr, request_size, map_prot);
} }
void void
os_dcache_flush(void) os_dcache_flush(void)
{} {
}
void void
os_icache_flush(void *start, size_t len) os_icache_flush(void *start, size_t len)

View File

@ -149,8 +149,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
page_size = getpagesize(); page_size = getpagesize();
aligned_size = (size + page_size - 1) & ~(page_size - 1); aligned_size = (size + page_size - 1) & ~(page_size - 1);
if (aligned_size >= UINT32_MAX) if (aligned_size >= UINT32_MAX) {
os_printf("mmap failed: request size overflow due to paging\n");
return NULL; return NULL;
}
ret = sgx_alloc_rsrv_mem(aligned_size); ret = sgx_alloc_rsrv_mem(aligned_size);
if (ret == NULL) { if (ret == NULL) {
@ -214,8 +216,10 @@ os_mprotect(void *addr, size_t size, int prot)
void void
os_dcache_flush(void) os_dcache_flush(void)
{} {
}
void void
os_icache_flush(void *start, size_t len) os_icache_flush(void *start, size_t len)
{} {
}

View File

@ -39,9 +39,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
page_size = os_getpagesize(); page_size = os_getpagesize();
request_size = (size + page_size - 1) & ~(page_size - 1); request_size = (size + page_size - 1) & ~(page_size - 1);
if (request_size < size) if (request_size < size) {
/* integer overflow */ printf("mmap failed: request size overflow due to paging\n");
return NULL; return NULL;
}
#if WASM_ENABLE_JIT != 0 #if WASM_ENABLE_JIT != 0
/** /**