TL 1 rok temu
rodzic
commit
2e4ebfb20a

+ 15 - 6
core/shared/platform/common/posix/posix_memmap.c

@@ -61,14 +61,16 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
         request_size += HUGE_PAGE_SIZE;
 #endif
 
-    if ((size_t)request_size < size)
-        /* integer overflow */
+    if ((size_t)request_size < size) {
+        os_printf("mmap failed: request size overflow due to paging\n");
         return NULL;
+    }
 
 #if WASM_ENABLE_MEMORY64 == 0
-    if (request_size > 16 * (uint64)UINT32_MAX)
-        /* at most 64 G is allowed */
+    if (request_size > 16 * (uint64)UINT32_MAX) {
+        os_printf("mmap failed: for memory64 at most 64G is allowed\n");
         return NULL;
+    }
 #endif
 
     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) {
         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);
         return NULL;
     }
@@ -268,6 +270,8 @@ os_mprotect(void *addr, size_t size, int prot)
     int map_prot = PROT_NONE;
     uint64 page_size = (uint64)getpagesize();
     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)
         return 0;
@@ -281,12 +285,17 @@ os_mprotect(void *addr, size_t size, int prot)
     if (prot & MMAP_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);
 }
 
 void
 os_dcache_flush(void)
-{}
+{
+}
 
 void
 os_icache_flush(void *start, size_t len)

+ 7 - 3
core/shared/platform/linux-sgx/sgx_platform.c

@@ -149,8 +149,10 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
     page_size = getpagesize();
     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;
+    }
 
     ret = sgx_alloc_rsrv_mem(aligned_size);
     if (ret == NULL) {
@@ -214,8 +216,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 - 2
core/shared/platform/windows/win_memmap.c

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