Skip to content

Commit 2e4ebfb

Browse files
TianlongLiangloganek
authored andcommitted
cr suggestions
1 parent dfcadc6 commit 2e4ebfb

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

core/shared/platform/common/posix/posix_memmap.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
6161
request_size += HUGE_PAGE_SIZE;
6262
#endif
6363

64-
if ((size_t)request_size < size)
65-
/* integer overflow */
64+
if ((size_t)request_size < size) {
65+
os_printf("mmap failed: request size overflow due to paging\n");
6666
return NULL;
67+
}
6768

6869
#if WASM_ENABLE_MEMORY64 == 0
69-
if (request_size > 16 * (uint64)UINT32_MAX)
70-
/* at most 64 G is allowed */
70+
if (request_size > 16 * (uint64)UINT32_MAX) {
71+
os_printf("mmap failed: for memory64 at most 64G is allowed\n");
7172
return NULL;
73+
}
7274
#endif
7375

7476
if (prot & MMAP_PROT_READ)
@@ -155,7 +157,7 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
155157

156158
if (addr == MAP_FAILED) {
157159
os_printf("mmap failed with errno: %d, hint: %p, size: %" PRIu64
158-
", prot: %d, flags: %d",
160+
", prot: %d, flags: %d\n",
159161
errno, hint, request_size, map_prot, map_flags);
160162
return NULL;
161163
}
@@ -268,6 +270,8 @@ os_mprotect(void *addr, size_t size, int prot)
268270
int map_prot = PROT_NONE;
269271
uint64 page_size = (uint64)getpagesize();
270272
uint64 request_size = (size + page_size - 1) & ~(page_size - 1);
273+
// printf("mprotect addr: %p, size: %llu, prot: %d\n", addr, request_size,
274+
// prot);
271275

272276
if (!addr)
273277
return 0;
@@ -281,12 +285,17 @@ os_mprotect(void *addr, size_t size, int prot)
281285
if (prot & MMAP_PROT_EXEC)
282286
map_prot |= PROT_EXEC;
283287

288+
if (mprotect(addr, request_size, map_prot) == -1) {
289+
printf("mprotect failed\n");
290+
}
291+
284292
return mprotect(addr, request_size, map_prot);
285293
}
286294

287295
void
288296
os_dcache_flush(void)
289-
{}
297+
{
298+
}
290299

291300
void
292301
os_icache_flush(void *start, size_t len)

core/shared/platform/linux-sgx/sgx_platform.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
149149
page_size = getpagesize();
150150
aligned_size = (size + page_size - 1) & ~(page_size - 1);
151151

152-
if (aligned_size >= UINT32_MAX)
152+
if (aligned_size >= UINT32_MAX) {
153+
os_printf("mmap failed: request size overflow due to paging\n");
153154
return NULL;
155+
}
154156

155157
ret = sgx_alloc_rsrv_mem(aligned_size);
156158
if (ret == NULL) {
@@ -214,8 +216,10 @@ os_mprotect(void *addr, size_t size, int prot)
214216

215217
void
216218
os_dcache_flush(void)
217-
{}
219+
{
220+
}
218221

219222
void
220223
os_icache_flush(void *start, size_t len)
221-
{}
224+
{
225+
}

core/shared/platform/windows/win_memmap.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
3939
page_size = os_getpagesize();
4040
request_size = (size + page_size - 1) & ~(page_size - 1);
4141

42-
if (request_size < size)
43-
/* integer overflow */
42+
if (request_size < size) {
43+
printf("mmap failed: request size overflow due to paging\n");
4444
return NULL;
45+
}
4546

4647
#if WASM_ENABLE_JIT != 0
4748
/**

0 commit comments

Comments
 (0)