097f8fcbc72532b9ca3b7ab20b105bdee58485cd
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / uclibc / 0.9.33.2 / 0015-add-posix_madvise.c.patch
1 From 93b8ce8886e30986be31c1403b606b6367dc258a Mon Sep 17 00:00:00 2001
2 From: "Peter S. Mazinger" <ps.m@gmx.net>
3 Date: Tue, 26 Apr 2011 23:03:44 +0200
4 Subject: [PATCH] add posix_madvise.c
5
6 Signed-off-by: Peter S. Mazinger <ps.m@gmx.net>
7 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
8 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
9 ---
10  libc/sysdeps/linux/common/Makefile.in     |    2 +-
11  libc/sysdeps/linux/common/posix_madvise.c |   25 +++++++++++++++++++++++++
12  2 files changed, 26 insertions(+), 1 deletion(-)
13  create mode 100644 libc/sysdeps/linux/common/posix_madvise.c
14
15 diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in
16 index 3b5763c..b39082b 100644
17 --- a/libc/sysdeps/linux/common/Makefile.in
18 +++ b/libc/sysdeps/linux/common/Makefile.in
19 @@ -81,7 +81,7 @@ CSRC-$(UCLIBC_HAS_REALTIME) += clock_getres.c clock_gettime.c clock_settime.c \
20         sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \
21         sched_rr_get_interval.c sched_setparam.c sched_setscheduler.c sigqueue.c
22  # 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
23 -CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c
24 +CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c
25  CSRC-$(UCLIBC_SUSV4_LEGACY) += utime.c
26  CSRC-$(UCLIBC_HAS_EPOLL) += epoll.c
27  CSRC-$(UCLIBC_HAS_XATTR) += xattr.c
28 diff --git a/libc/sysdeps/linux/common/posix_madvise.c b/libc/sysdeps/linux/common/posix_madvise.c
29 new file mode 100644
30 index 0000000..2f95bcb
31 --- /dev/null
32 +++ b/libc/sysdeps/linux/common/posix_madvise.c
33 @@ -0,0 +1,25 @@
34 +/* vi: set sw=4 ts=4: */
35 +/* Licensed under the LGPL v2.1, see the file LICENSE in this tarball. */
36 +
37 +#include <sys/mman.h>
38 +#include <sys/syscall.h>
39 +
40 +#if defined __NR_madvise && defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
41 +int posix_madvise(void *addr, size_t len, int advice)
42 +{
43 +       int result;
44 +       /* We have one problem: the kernel's MADV_DONTNEED does not
45 +        * correspond to POSIX's POSIX_MADV_DONTNEED.  The former simply
46 +        * discards changes made to the memory without writing it back to
47 +        * disk, if this would be necessary.  The POSIX behaviour does not
48 +        * allow this.  There is no functionality mapping for the POSIX
49 +        * behaviour so far so we ignore that advice for now. */
50 +       if (advice == POSIX_MADV_DONTNEED)
51 +               return 0;
52 +
53 +       /* this part might use madvise function */
54 +       INTERNAL_SYSCALL_DECL (err);
55 +       result = INTERNAL_SYSCALL (madvise, err, 3, addr, len, advice);
56 +       return INTERNAL_SYSCALL_ERRNO (result, err);
57 +}
58 +#endif
59 -- 
60 1.7.10.4
61