Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Jul 2003 13:17:00 +0100 (BST)
From:      Bruce M Simpson <bms@spc.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   standards/54634: [PATCH] add posix_madvise() call to -CURRENT
Message-ID:  <20030719121700.C047F933@saboteur.dek.spc.org>
Resent-Message-ID: <200307191220.h6JCKD1Z009682@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         54634
>Category:       standards
>Synopsis:       [PATCH] add posix_madvise() call to -CURRENT
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 19 05:20:13 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Bruce M Simpson
>Release:        FreeBSD 5.1-RELEASE i386
>Organization:
>Environment:
System: FreeBSD saboteur.dek.spc.org 5.1-RELEASE FreeBSD 5.1-RELEASE #3: Mon Jun 23 06:55:01 BST 2003 root@saboteur.dek.spc.org:/usr/src/sys/i386/compile/SABOTEUR i386


	
>Description:
	Here is a patch to add posix_madvise() -part of the POSIX/C99
	conformance project.
>How-To-Repeat:
>Fix:

	

--- posix_madvise.patch begins here ---
Generated by diffcoll on Sat 21 Jun 2003 10:22:04 BST

diff -uN src/sys/sys/mman.h.orig src/sys/sys/mman.h
--- /usr/src/sys/sys/mman.h.orig	Sat Jun 21 09:57:14 2003
+++ /usr/src/sys/sys/mman.h	Sat Jun 21 09:59:13 2003
@@ -125,6 +125,11 @@
 #define	MADV_NOCORE	8	/* do not include these pages in a core file */
 #define	MADV_CORE	9	/* revert to including pages in a core file */
 #define	MADV_PROTECT	10	/* protect process from pageout kill */
+#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
 
 /*
  * Return bits from mincore
@@ -160,7 +165,7 @@
 
 __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
@@ -178,6 +183,7 @@
 int	munlock(const void *, size_t);
 int	munmap(void *, size_t);
 #if __POSIX_VISIBLE >= 199309
+int	posix_madvise(void *, size_t, int);
 int	shm_open(const char *, int, mode_t);
 int	shm_unlink(const char *);
 #endif

diff -uN src/lib/libc/gen/Makefile.inc.orig src/lib/libc/gen/Makefile.inc
--- /usr/src/lib/libc/gen/Makefile.inc.orig	Sat Jun 21 10:02:13 2003
+++ /usr/src/lib/libc/gen/Makefile.inc	Sat Jun 21 10:02:56 2003
@@ -19,7 +19,8 @@
 	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 popen.c posixshm.c pmadvise.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 -uN src/lib/libc/gen/pmadvise.c.orig src/lib/libc/gen/pmadvise.c
--- /usr/src/lib/libc/gen/pmadvise.c.orig	Fri Feb  1 00:57:29 2002
+++ /usr/src/lib/libc/gen/pmadvise.c	Sat Jun 21 10:01:39 2003
@@ -1,7 +1,7 @@
 /*
  * The contents of this file are in the public domain.
  * Written by Garrett A. Wollman, 2000-10-07.
- *
+ * Updated by Bruce M. Simpson, 2003-06-21.
  */
 
 #include <sys/cdefs.h>
@@ -10,7 +10,7 @@
 #include <sys/mman.h>
 
 int
-(posix_madvise)(void *address, size_t size, int how)
+posix_madvise(void *addr, size_t len, int advice)
 {
-	return posix_madvise(address, size, how);
+	return madvise(addr, len, advice);
 }

diff -uN src/lib/libc/sys/Makefile.inc.orig src/lib/libc/sys/Makefile.inc
--- /usr/src/lib/libc/sys/Makefile.inc.orig	Sat Jun 21 10:03:26 2003
+++ /usr/src/lib/libc/sys/Makefile.inc	Sat Jun 21 10:04:04 2003
@@ -119,6 +119,7 @@
 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 -uN src/lib/libc/sys/madvise.2.orig src/lib/libc/sys/madvise.2
--- /usr/src/lib/libc/sys/madvise.2.orig	Sat Jun 21 10:04:10 2003
+++ /usr/src/lib/libc/sys/madvise.2	Sat Jun 21 10:22:02 2003
@@ -36,7 +36,8 @@
 .Dt MADVISE 2
 .Os
 .Sh NAME
-.Nm madvise
+.Nm madvise ,
+.Nm posix_madvise
 .Nd give advice about use of memory
 .Sh LIBRARY
 .Lb libc
@@ -44,6 +45,8 @@
 .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 advice"
 .Sh DESCRIPTION
 The
 .Fn madvise
@@ -51,6 +54,13 @@
 allows a process that has knowledge of its memory behavior
 to describe it to the system.
 .Pp
+The
+.Fn posix_madvise
+interface is identical and is provided for the purposes of
+standards conformance.  The
+.Dv POSIX_
+prefixed definitions should be used when calling this interface.
+.Pp
 The known behaviors are:
 .Bl -tag -width MADV_SEQUENTIAL
 .It Dv MADV_NORMAL
@@ -123,7 +133,44 @@
 The process must have superuser privileges.
 This should be used judiciously in processes that must remain running
 for the system to properly function.
+.It Dv POSIX_MADV_NORMAL
+Same as
+.Dv MADV_NORMAL
+but used with the
+.Fn posix_madvise
+system call.
+.It Dv POSIX_MADV_SEQUENTIAL
+Same as
+.Dv MADV_SEQUENTIAL
+but used with the
+.Fn posix_madvise
+system call.
+.It Dv POSIX_MADV_RANDOM
+Same as
+.Dv MADV_RANDOM
+but used with the
+.Fn posix_madvise
+system call.
+.It Dv POSIX_MADV_WILLNEED
+Same as
+.Dv MADV_WILLNEED
+but used with the
+.Fn posix_madvise
+system call.
+.It Dv POSIX_MADV_WONTNEED
+Same as
+.Dv MADV_WONTNEED
+but used with the
+.Fn posix_madvise
+system call.
 .El
+.Sh IMPLEMENTATION NOTES
+The
+.Fn posix_madvise
+function is implemented as a function within libc
+which simply calls the
+.Fn madvise
+system call stub.
 .Sh RETURN VALUES
 .Rv -std madvise
 .Sh ERRORS
@@ -146,6 +193,10 @@
 .Xr mprotect 2 ,
 .Xr msync 2 ,
 .Xr munmap 2
+.Sh STANDARDS
+The
+.Fn posix_madvise
+interface is believed to conform to IEEE Std 1003.1-2001 (``POSIX.1'').
 .Sh HISTORY
 The
 .Fn madvise
--- posix_madvise.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030719121700.C047F933>