summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libc/gen/Makefile.inc3
-rw-r--r--lib/libc/gen/pmadvise.c4
-rw-r--r--lib/libc/sys/Makefile.inc1
-rw-r--r--lib/libc/sys/madvise.225
-rw-r--r--sys/sys/mman.h14
5 files changed, 41 insertions, 6 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 9ab8616..e26ed2f 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -19,7 +19,8 @@ SRCS+= __xuname.c _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \
initgroups.c isatty.c jrand48.c lcong48.c \
lockf.c lrand48.c mrand48.c nice.c \
nlist.c nrand48.c ntp_gettime.c opendir.c \
- pause.c popen.c posixshm.c pselect.c psignal.c pw_scan.c pwcache.c \
+ pause.c pmadvise.c popen.c posixshm.c pselect.c \
+ psignal.c pw_scan.c pwcache.c \
raise.c readdir.c readpassphrase.c rewinddir.c \
scandir.c seed48.c seekdir.c semctl.c \
setdomainname.c sethostname.c setjmperr.c setmode.c \
diff --git a/lib/libc/gen/pmadvise.c b/lib/libc/gen/pmadvise.c
index 4024d64..60cef63 100644
--- a/lib/libc/gen/pmadvise.c
+++ b/lib/libc/gen/pmadvise.c
@@ -10,7 +10,7 @@ __FBSDID("$FreeBSD$");
#include <sys/mman.h>
int
-(posix_madvise)(void *address, size_t size, int how)
+posix_madvise(void *address, size_t size, int how)
{
- return posix_madvise(address, size, how);
+ return madvise(address, size, how);
}
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index 0c53319..ae536d5 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -119,6 +119,7 @@ MLINKS+=jail.2 jail_attach.2
MLINKS+=kqueue.2 kevent.2
MLINKS+=kse.2 kse_create.2 kse.2 kse_exit.2 kse.2 kse_release.2 \
kse.2 kse_wakeup.2 kse.2 kse_thr_interrupt.2
+MLINKS+=madvise.2 posix_madvise.2
MLINKS+=mlock.2 munlock.2
MLINKS+=modnext.2 modfnext.2
MLINKS+=mount.2 unmount.2
diff --git a/lib/libc/sys/madvise.2 b/lib/libc/sys/madvise.2
index d783ea0..25cb5c7 100644
--- a/lib/libc/sys/madvise.2
+++ b/lib/libc/sys/madvise.2
@@ -36,7 +36,7 @@
.Dt MADVISE 2
.Os
.Sh NAME
-.Nm madvise
+.Nm madvise , posix_madvise
.Nd give advice about use of memory
.Sh LIBRARY
.Lb libc
@@ -44,12 +44,17 @@
.In sys/mman.h
.Ft int
.Fn madvise "void *addr" "size_t len" "int behav"
+.Ft int
+.Fn posix_madvise "void *addr" "size_t len" "int behav"
.Sh DESCRIPTION
The
.Fn madvise
system call
allows a process that has knowledge of its memory behavior
to describe it to the system.
+The
+.Fn posix_madvise
+interface is identical and is provided for standards conformance.
.Pp
The known behaviors are:
.Bl -tag -width MADV_SEQUENTIAL
@@ -124,6 +129,15 @@ The process must have superuser privileges.
This should be used judiciously in processes that must remain running
for the system to properly function.
.El
+.Pp
+Portable programs that call the
+.Fn posix_madvise
+interface should use the aliases
+.Dv POSIX_MADV_NORMAL , POSIX_MADV_SEQUENTIAL ,
+.Dv POSIX_MADV_RANDOM , POSIX_MADV_WILLNEED ,
+and
+.Dv POSIX_MADV_DONTNEED
+rather than the flags described above.
.Sh RETURN VALUES
.Rv -std madvise
.Sh ERRORS
@@ -132,6 +146,10 @@ The
system call will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
+The
+.Fa behav
+argument is not valid.
+.It Bq Er ENOMEM
The virtual address range specified by the
.Fa addr
and
@@ -146,6 +164,11 @@ was specified and the process does not have superuser privileges.
.Xr mprotect 2 ,
.Xr msync 2 ,
.Xr munmap 2
+.Sh STANDARDS
+The
+.Fn posix_madvise
+interface conforms to
+.St -p1003.1-2001 .
.Sh HISTORY
The
.Fn madvise
diff --git a/sys/sys/mman.h b/sys/sys/mman.h
index f8b94cc..ec058d8 100644
--- a/sys/sys/mman.h
+++ b/sys/sys/mman.h
@@ -137,9 +137,16 @@
#endif /* __BSD_VISIBLE */
/*
- * XXX missing POSIX_MADV_* macros, POSIX_TYPED_MEM_* macros, and
+ * XXX missing POSIX_TYPED_MEM_* macros and
* posix_typed_mem_info structure.
*/
+#if __POSIX_VISIBLE >= 200112
+#define POSIX_MADV_NORMAL MADV_NORMAL
+#define POSIX_MADV_RANDOM MADV_RANDOM
+#define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL
+#define POSIX_MADV_WILLNEED MADV_WILLNEED
+#define POSIX_MADV_DONTNEED MADV_DONTNEED
+#endif
#ifndef _MODE_T_DECLARED
typedef __mode_t mode_t;
@@ -160,7 +167,7 @@ typedef __size_t size_t;
__BEGIN_DECLS
/*
- * XXX not yet implemented: mlockall(), munlockall(), posix_madvise(),
+ * XXX not yet implemented: mlockall(), munlockall(),
* posix_mem_offset(), posix_typed_mem_get_info(), posix_typed_mem_open().
*/
#if __BSD_VISIBLE
@@ -177,6 +184,9 @@ int mprotect(const void *, size_t, int);
int msync(void *, size_t, int);
int munlock(const void *, size_t);
int munmap(void *, size_t);
+#if __POSIX_VISIBLE >= 200112
+int posix_madvise(void *, size_t, int);
+#endif
#if __POSIX_VISIBLE >= 199309
int shm_open(const char *, int, mode_t);
int shm_unlink(const char *);
OpenPOWER on IntegriCloud