Skip to content

Commit

Permalink
lib: Ignore ENOSYS errors from madvise() calls.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen committed Feb 11, 2016
1 parent d5cdf90 commit 4ff6d11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/lib/mmap-util.c
Expand Up @@ -37,13 +37,18 @@ void *mmap_rw_file(int fd, size_t *length)
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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/mmap-util.h
Expand Up @@ -14,9 +14,9 @@
# 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
Expand Down

0 comments on commit 4ff6d11

Please sign in to comment.