summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2010-05-18 22:24:54 +0000
committertedu <tedu@openbsd.org>2010-05-18 22:24:54 +0000
commit243f393511fee0e3dea053d89336d8b8f85b60ee (patch)
treef0de8eb1b6b3091104481b8be30b613f807883d6 /lib/libc/sys
parentAdd as yet untested support for the 82576 quad copper ET2 (diff)
downloadwireguard-openbsd-243f393511fee0e3dea053d89336d8b8f85b60ee.tar.xz
wireguard-openbsd-243f393511fee0e3dea053d89336d8b8f85b60ee.zip
add posix_madvise, posix_memalign, strndup, and strnlen. mostly from
brad and millert, with hints from guenther, jmc, and otto I think. ok previous.
Diffstat (limited to 'lib/libc/sys')
-rw-r--r--lib/libc/sys/Makefile.inc6
-rw-r--r--lib/libc/sys/madvise.237
-rw-r--r--lib/libc/sys/posix_madvise.c11
3 files changed, 48 insertions, 6 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index 6e440ac40ce..4d31ad1411c 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.89 2010/02/03 20:49:00 miod Exp $
+# $OpenBSD: Makefile.inc,v 1.90 2010/05/18 22:24:55 tedu Exp $
# $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/17/93
@@ -23,6 +23,9 @@ DPSRCS+= Lint_Ovfork.c Lint_brk.c Lint_exect.c Lint_fork.c \
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
diff --git a/lib/libc/sys/madvise.2 b/lib/libc/sys/madvise.2
index 7ac374636d0..0bd769da626 100644
--- a/lib/libc/sys/madvise.2
+++ b/lib/libc/sys/madvise.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: madvise.2,v 1.14 2007/05/31 19:19:32 jmc Exp $
+.\" $OpenBSD: madvise.2,v 1.15 2010/05/18 22:24:55 tedu Exp $
.\" $NetBSD: madvise.2,v 1.7 1995/12/27 21:17:02 jtc Exp $
.\"
.\" Copyright (c) 1991, 1993
@@ -30,23 +30,29 @@
.\"
.\" @(#)madvise.2 8.1 (Berkeley) 6/9/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: May 18 2010 $
.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 .
+
diff --git a/lib/libc/sys/posix_madvise.c b/lib/libc/sys/posix_madvise.c
new file mode 100644
index 00000000000..4952c5cc77a
--- /dev/null
+++ b/lib/libc/sys/posix_madvise.c
@@ -0,0 +1,11 @@
+/* $OpenBSD: posix_madvise.c,v 1.1 2010/05/18 22:24:55 tedu Exp $ */
+/*
+ * Ted Unangst wrote this file and placed it into the public domain.
+ */
+#include <sys/mman.h>
+
+int
+posix_madvise(void *addr, size_t len, int behav)
+{
+ return (_thread_sys_madvise(addr, len, behav));
+}