For example Raspberry Pi kernels have removed this. We'll wrap all the
madvise() calls with my_madvise() to avoid extra checks all over the place.
return mmap_file(fd, length, PROT_READ | PROT_WRITE);
}
-#ifndef HAVE_MADVISE
+#undef madvise
int my_madvise(void *start ATTR_UNUSED, size_t length ATTR_UNUSED,
int advice ATTR_UNUSED)
{
+#ifdef HAVE_MADVISE
+ /* Ignore ENOSYS errors, which happen if the kernel hasn't implemented
+ the syscall even if libc has. */
+ if (madvise(start, length, advice) < 0 && errno != ENOSYS)
+ return -1;
+#endif
return 0;
}
-#endif
size_t mmap_get_page_size(void)
{
# define MREMAP_MAYMOVE 1
#endif
-#ifndef HAVE_MADVISE
-# define madvise my_madvise
+#define madvise my_madvise
int my_madvise(void *start, size_t length, int advice);
+#ifndef HAVE_MADVISE
# ifndef MADV_NORMAL
# define MADV_NORMAL 0
# define MADV_RANDOM 0