Przeglądaj źródła

Fix ‘MADV_HUGEPAGE’ undeclared compilation error (#1012)

In some Linux systems whose kernel version is smaller than 2.6.38, the macro
MADV_HUGEPAGE isn't introduced yet which causes compilation error.
Add macro control to fix the compilation error.
Namhyeon, Go 4 lat temu
rodzic
commit
0d1060b3cc
1 zmienionych plików z 4 dodań i 4 usunięć
  1. 4 4
      core/shared/platform/common/posix/posix_memmap.c

+ 4 - 4
core/shared/platform/common/posix/posix_memmap.c

@@ -16,7 +16,7 @@ static size_t total_size_munmapped = 0;
 
 #define HUGE_PAGE_SIZE (2 * 1024 * 1024)
 
-#if !defined(__APPLE__) && !defined(__NuttX__)
+#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
 static inline uintptr_t
 round_up(uintptr_t v, uintptr_t b)
 {
@@ -44,7 +44,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
     page_size = (uint64)getpagesize();
     request_size = (size + page_size - 1) & ~(page_size - 1);
 
-#if !defined(__APPLE__) && !defined(__NuttX__)
+#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
     /* huge page isn't supported on MacOS and NuttX */
     if (request_size >= HUGE_PAGE_SIZE)
         /* apply one extra huge page */
@@ -148,7 +148,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
               addr, request_size, total_size_mmapped, total_size_munmapped);
 #endif
 
-#if !defined(__APPLE__) && !defined(__NuttX__)
+#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
     /* huge page isn't supported on MacOS and NuttX */
     if (request_size > HUGE_PAGE_SIZE) {
         uintptr_t huge_start, huge_end;
@@ -200,7 +200,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
             }
         }
     }
-#endif /* end of __APPLE__ || __NuttX__ */
+#endif /* end of __APPLE__ || __NuttX__ || !MADV_HUGEPAGE */
 
     return addr;
 }