Skip to content

Commit 0d1060b

Browse files
authored
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.
1 parent 9fc124b commit 0d1060b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static size_t total_size_munmapped = 0;
1616

1717
#define HUGE_PAGE_SIZE (2 * 1024 * 1024)
1818

19-
#if !defined(__APPLE__) && !defined(__NuttX__)
19+
#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
2020
static inline uintptr_t
2121
round_up(uintptr_t v, uintptr_t b)
2222
{
@@ -44,7 +44,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
4444
page_size = (uint64)getpagesize();
4545
request_size = (size + page_size - 1) & ~(page_size - 1);
4646

47-
#if !defined(__APPLE__) && !defined(__NuttX__)
47+
#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
4848
/* huge page isn't supported on MacOS and NuttX */
4949
if (request_size >= HUGE_PAGE_SIZE)
5050
/* apply one extra huge page */
@@ -148,7 +148,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
148148
addr, request_size, total_size_mmapped, total_size_munmapped);
149149
#endif
150150

151-
#if !defined(__APPLE__) && !defined(__NuttX__)
151+
#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
152152
/* huge page isn't supported on MacOS and NuttX */
153153
if (request_size > HUGE_PAGE_SIZE) {
154154
uintptr_t huge_start, huge_end;
@@ -200,7 +200,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
200200
}
201201
}
202202
}
203-
#endif /* end of __APPLE__ || __NuttX__ */
203+
#endif /* end of __APPLE__ || __NuttX__ || !MADV_HUGEPAGE */
204204

205205
return addr;
206206
}

0 commit comments

Comments
 (0)