Add the POSIX 1003.1-2001 posix_madvise() interface.

PR:		standards/54634
Reviewed by:	das
Approved by:	jake (mentor)
This commit is contained in:
Bruce M Simpson 2003-08-09 03:23:24 +00:00
parent fe3e8c5167
commit 662d85d6a2
5 changed files with 41 additions and 6 deletions

View File

@ -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 \

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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 *);