021-add-posix_madvise.c.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From: "Peter S. Mazinger" <ps.m@gmx.net>
  2. Date: Tue, 26 Apr 2011 23:03:44 +0200
  3. Subject: [PATCH] add posix_madvise.c
  4. Signed-off-by: Peter S. Mazinger <ps.m@gmx.net>
  5. Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
  6. ---
  7. create mode 100644 libc/sysdeps/linux/common/posix_madvise.c
  8. --- a/libc/sysdeps/linux/common/Makefile.in
  9. +++ b/libc/sysdeps/linux/common/Makefile.in
  10. @@ -81,7 +81,7 @@ CSRC-$(UCLIBC_HAS_REALTIME) += clock_get
  11. sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \
  12. sched_rr_get_interval.c sched_setparam.c sched_setscheduler.c sigqueue.c
  13. # clock_getcpuclockid|clock_nanosleep|mq_timedreceive|mq_timedsend|posix_fadvise|posix_fallocate|posix_madvise|posix_memalign|posix_mem_offset|posix_spawnattr_destroy|posix_spawnattr_init|posix_spawnattr_getflags|posix_spawnattr_setflags|posix_spawnattr_getpgroup|posix_spawnattr_setpgroup|posix_spawnattr_getschedparam|posix_spawnattr_setschedparam|posix_spawnattr_getschedpolicy|posix_spawnattr_setschedpolicy|posix_spawnattr_getsigdefault|posix_spawnattr_setsigdefault|posix_spawnattr_getsigmask|posix_spawnattr_setsigmask|posix_spawnattr_init|posix_spawnattr_setflags|posix_spawnattr_setpgroup|posix_spawnattr_setschedparam|posix_spawnattr_setschedpolicy|posix_spawnattr_setsigdefault|posix_spawnattr_setsigmask|posix_spawn_file_actions_addclose|posix_spawn_file_actions_addopen|posix_spawn_file_actions_adddup2|posix_spawn_file_actions_addopen|posix_spawn_file_actions_destroy|posix_spawn_file_actions_init|posix_spawn_file_actions_init|posix_spawn|posix_spawnp|posix_spawnp|posix_typed_mem_get_info|pthread_mutex_timedlock|sem_timedwait
  14. -CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c
  15. +CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c
  16. CSRC-$(UCLIBC_SUSV4_LEGACY) += utime.c
  17. CSRC-$(UCLIBC_HAS_EPOLL) += epoll.c
  18. CSRC-$(UCLIBC_HAS_XATTR) += xattr.c
  19. --- /dev/null
  20. +++ b/libc/sysdeps/linux/common/posix_madvise.c
  21. @@ -0,0 +1,25 @@
  22. +/* vi: set sw=4 ts=4: */
  23. +/* Licensed under the LGPL v2.1, see the file LICENSE in this tarball. */
  24. +
  25. +#include <sys/mman.h>
  26. +#include <sys/syscall.h>
  27. +
  28. +#if defined __NR_madvise && defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
  29. +int posix_madvise(void *addr, size_t len, int advice)
  30. +{
  31. + int result;
  32. + /* We have one problem: the kernel's MADV_DONTNEED does not
  33. + * correspond to POSIX's POSIX_MADV_DONTNEED. The former simply
  34. + * discards changes made to the memory without writing it back to
  35. + * disk, if this would be necessary. The POSIX behaviour does not
  36. + * allow this. There is no functionality mapping for the POSIX
  37. + * behaviour so far so we ignore that advice for now. */
  38. + if (advice == POSIX_MADV_DONTNEED)
  39. + return 0;
  40. +
  41. + /* this part might use madvise function */
  42. + INTERNAL_SYSCALL_DECL (err);
  43. + result = INTERNAL_SYSCALL (madvise, err, 3, addr, len, advice);
  44. + return INTERNAL_SYSCALL_ERRNO (result, err);
  45. +}
  46. +#endif