On Sat, Apr 24, 2010 at 08:52:25PM -0700, Philip Guenther wrote:
> On Sat, Apr 24, 2010 at 1:33 PM, Brad <[email protected]> wrote:
> ...
> > I have updated the diff with your suggestions.
>
> Close: I think the #include of <sys/cdefs.h> needs to be moved up in
> sys/mman.h so that the __BSD_VISIBLE test actually works. Otherwise,
> looks good to me.
How about this?
Index: sys/sys/mman.h
===================================================================
RCS file: /cvs/src/sys/sys/mman.h,v
retrieving revision 1.18
diff -u -p -r1.18 mman.h
--- sys/sys/mman.h 21 Jul 2003 22:52:19 -0000 1.18
+++ sys/sys/mman.h 25 Apr 2010 15:24:06 -0000
@@ -32,6 +32,10 @@
* @(#)mman.h 8.1 (Berkeley) 6/2/93
*/
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+#endif
+
/*
* Protections are chosen from these bits, or-ed together
*/
@@ -72,15 +76,28 @@
#define MAP_FLAGMASK 0x17f7
/*
- * Advice to madvise
+ * POSIX memory advisory values.
+ * Note: keep consistent with the original defintions below.
*/
-#define MADV_NORMAL 0 /* no further special treatment */
-#define MADV_RANDOM 1 /* expect random page references */
-#define MADV_SEQUENTIAL 2 /* expect sequential page references */
-#define MADV_WILLNEED 3 /* will need these pages */
-#define MADV_DONTNEED 4 /* dont need these pages */
-#define MADV_SPACEAVAIL 5 /* insure that resources are reserved */
-#define MADV_FREE 6 /* pages are empty, free them */
+#define POSIX_MADV_NORMAL 0 /* no further special treatment
*/
+#define POSIX_MADV_RANDOM 1 /* expect random page
references */
+#define POSIX_MADV_SEQUENTIAL 2 /* expect sequential page
references */
+#define POSIX_MADV_WILLNEED 3 /* will need these pages */
+#define POSIX_MADV_DONTNEED 4 /* don't need these pages */
+
+#if __BSD_VISIBLE
+/*
+ * Original advice values, equivalent to POSIX defintions,
+ * and few implementation-specific ones.
+ */
+#define MADV_NORMAL POSIX_MADV_NORMAL
+#define MADV_RANDOM POSIX_MADV_RANDOM
+#define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL
+#define MADV_WILLNEED POSIX_MADV_WILLNEED
+#define MADV_DONTNEED POSIX_MADV_DONTNEED
+#define MADV_SPACEAVAIL 5 /* insure that resources are
reserved */
+#define MADV_FREE 6 /* pages are empty, free them */
+#endif
/*
* Flags to minherit
@@ -105,8 +122,17 @@
#define MCL_FUTURE 0x02 /* lock all pages mapped in the future
*/
#ifndef _KERNEL
+#include <sys/_types.h>
-#include <sys/cdefs.h>
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#ifndef _OFF_T_DEFINED_
+#define _OFF_T_DEFINED_
+typedef __off_t off_t;
+#endif
__BEGIN_DECLS
/* Some of these int's should probably be size_t's */
@@ -118,10 +144,13 @@ int mlock(const void *, size_t);
int munlock(const void *, size_t);
int mlockall(int);
int munlockall(void);
+#if __BSD_VISIBLE
int madvise(void *, size_t, int);
int mincore(void *, size_t, char *);
int minherit(void *, size_t, int);
void * mquery(void *, size_t, int, int, int, off_t);
+#endif
+int posix_madvise(void *, size_t, int);
__END_DECLS
#endif /* !_KERNEL */
Index: lib/libc/shlib_version
===================================================================
RCS file: /cvs/src/lib/libc/shlib_version,v
retrieving revision 1.121
diff -u -p -r1.121 shlib_version
@@ -1,4 +1,4 @@
major=53
-minor=1
+minor=2
# note: If changes were made to include/thread_private.h or if system
# calls were added/changed then libpthread must also be updated.
Index: lib/libc/sys/Makefile.inc
===================================================================
RCS file: /cvs/src/lib/libc/sys/Makefile.inc,v
retrieving revision 1.89
diff -u -p -r1.89 Makefile.inc
--- lib/libc/sys/Makefile.inc 3 Feb 2010 20:49:00 -0000 1.89
+++ lib/libc/sys/Makefile.inc 20 Apr 2010 00:35:43 -0000
@@ -23,6 +23,9 @@ DPSRCS+= Lint_Ovfork.c Lint_brk.c Lint_e
Lint_setjmp.c Lint_longjmp.c \
Lint_sigsetjmp.c Lint_siglongjmp.c
+# glue to offer userland wrappers for some syscalls
+SRCS+= posix_madvise.c
+
# glue to provide compatibility between GCC 1.X and 2.X and for compat
# with old syscall interfaces.
SRCS+= ftruncate.c lseek.c mquery.c mmap.c ptrace.c semctl.c truncate.c \
@@ -264,6 +267,7 @@ MLINKS+=gettimeofday.2 settimeofday.2
MLINKS+=getuid.2 geteuid.2
MLINKS+=kqueue.2 kevent.2 kqueue.2 EV_SET.2
MLINKS+=intro.2 errno.2
+MLINKS+=madvise.2 posix_madvise.2
MLINKS+=mlock.2 munlock.2
MLINKS+=mlockall.2 munlockall.2
MLINKS+=mount.2 unmount.2
Index: lib/libc/sys/madvise.2
===================================================================
RCS file: /cvs/src/lib/libc/sys/madvise.2,v
retrieving revision 1.14
diff -u -p -r1.14 madvise.2
--- lib/libc/sys/madvise.2 31 May 2007 19:19:32 -0000 1.14
+++ lib/libc/sys/madvise.2 24 Apr 2010 20:29:43 -0000
@@ -30,23 +30,29 @@
.\"
.\" @(#)madvise.2 8.1 (Berkeley) 6/9/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate$
.Dt MADVISE 2
.Os
.Sh NAME
-.Nm madvise
+.Nm madvise ,
+.Nm posix_madvise
.Nd give advice about use of memory
.Sh SYNOPSIS
-.Fd #include <sys/types.h>
.Fd #include <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 possible behaviors are:
.Bl -tag -width MADV_SEQUENTIAL
.It Dv MADV_NORMAL
@@ -64,6 +70,15 @@ Ensure that resources are reserved.
.It Dv MADV_FREE
The pages don't contain any useful data and can be recycled.
.El
+.Pp
+Portable programs that call the
+.Fn posix_madvise
+interface should use the aliases
+.Dv POSIX_MADV_NORMAL , POSIX_MADV_RANDOM ,
+.Dv POSIX_MADV_SEQUENTIAL , POSIX_MADV_WILLNEED ,
+and
+.Dv POSIX_MADV_DONTNEED
+rather than the flags described above.
.Sh RETURN VALUES
Upon successful completion,
a value of 0 is returned.
@@ -75,9 +90,21 @@ is set to indicate the error.
.Xr minherit 2 ,
.Xr mprotect 2 ,
.Xr msync 2 ,
-.Xr munmap 2
+.Xr munmap 2 ,
+.Xr posix_madvise 2
+.Sh STANDARDS
+The
+.Fn posix_madvise
+system call is expected to conform to the
+.St -p1003.1-2001
+standard.
.Sh HISTORY
The
.Nm madvise
function first appeared in
.Bx 4.4 .
+The
+.Nm posix_madvise
+function first appeared in
+.Ox 4.8 .
+
Index: lib/libc/sys/posix_madvise.c
===================================================================
RCS file: lib/libc/sys/posix_madvise.c
diff -N lib/libc/sys/posix_madvise.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/libc/sys/posix_madvise.c 24 Apr 2010 20:17:48 -0000
@@ -0,0 +1,37 @@
+/* $OpenBSD$ */
+/* $NetBSD: posix_madvise.c,v 1.1 2008/04/22 10:42:16 rmind Exp $ */
+
+/*
+ * Copyright (c) 2008, Mindaugas Rasiukevicius <rmind at NetBSD org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/mman.h>
+
+int
+posix_madvise(void *addr, size_t len, int advice)
+{
+ return _thread_sys_madvise(addr, len, advice);
+}
+
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.