diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2003-04-14 04:53:52 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2003-04-14 04:53:52 +0000 |
commit | 901c826a09497ead7016206abf7b50656baff91e (patch) | |
tree | 2721a7366483b12d83c3a02b75f402e9e3fd0860 /lib/libc/sys | |
parent | bcf4f93c865e19f6d796c4f4095be600cd2b319e (diff) |
There are two related changes.
The first one is an mquery(2) syscall. It's for asking the VM system
about where to map things. It will be used by ld.so, read the man page
for details.
The second change is related and is a centralization of uvm_map hint
that all callers of uvm_map calculated. This will allow us to adjust
this hint on architectures that have segments for non-exec mappings.
deraadt@ drahn@ ok.
Diffstat (limited to 'lib/libc/sys')
-rw-r--r-- | lib/libc/sys/Makefile.inc | 8 | ||||
-rw-r--r-- | lib/libc/sys/mquery.2 | 127 | ||||
-rw-r--r-- | lib/libc/sys/mquery.c | 17 |
3 files changed, 148 insertions, 4 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index e6030715104..4501f4d6445 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.64 2003/01/31 21:47:46 millert Exp $ +# $OpenBSD: Makefile.inc,v 1.65 2003/04/14 04:53:50 art Exp $ # $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 @@ -21,7 +21,7 @@ DPSRCS+= Lint_Ovfork.c Lint_brk.c Lint_exect.c Lint_fork.c \ # glue to provide compatibility between GCC 1.X and 2.X and for compat # with old syscall interfaces. -SRCS+= ftruncate.c lseek.c mmap.c ptrace.c semctl.c truncate.c \ +SRCS+= ftruncate.c lseek.c mquery.c mmap.c ptrace.c semctl.c truncate.c \ timer_create.c timer_delete.c timer_getoverrun.c timer_gettime.c \ timer_settime.c pread.c preadv.c pwrite.c pwritev.c @@ -216,8 +216,8 @@ MAN+= accept.2 access.2 acct.2 adjtime.2 bind.2 brk.2 chdir.2 chflags.2 \ getpid.2 getpriority.2 getrlimit.2 getrusage.2 getsid.2 getsockname.2 \ getsockopt.2 gettimeofday.2 getuid.2 intro.2 issetugid.2 ioctl.2 \ kill.2 kqueue.2 ktrace.2 link.2 \ - listen.2 lseek.2 mkdir.2 mkfifo.2 mknod.2 madvise.2 mincore.2 \ - minherit.2 mlock.2 mlockall.2 \ + listen.2 lseek.2 mkdir.2 mkfifo.2 mknod.2 madvise.2 \ + mquery.2 mincore.2 minherit.2 mlock.2 mlockall.2 \ mmap.2 mount.2 mprotect.2 msync.2 munmap.2 nanosleep.2 \ nfssvc.2 open.2 pathconf.2 \ pipe.2 profil.2 poll.2 ptrace.2 quotactl.2 read.2 readlink.2 reboot.2 \ diff --git a/lib/libc/sys/mquery.2 b/lib/libc/sys/mquery.2 new file mode 100644 index 00000000000..9e835bc4233 --- /dev/null +++ b/lib/libc/sys/mquery.2 @@ -0,0 +1,127 @@ +.\" $OpenBSD: mquery.2,v 1.1 2003/04/14 04:53:50 art Exp $ +.\" +.\" Copyright (c) 2003 Artur Grabowski <art@openbsd.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. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED ``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 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. +.\" +.Dd April 2, 2003 +.Dt MQUERY 2 +.Os +.Sh NAME +.Nm mquery +.Nd provide mapping hints to applications +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/mman.h> +.Ft int +.Fn mquery "int flags" "void **addr" "size_t size" "int fd" "off_t off" +.Sh DESCRIPTION +The +.Nm mqeury +system call checks the existing memory mappings of a process and returns +hints to the caller about where to put a memory mapping. +This hint can be later used when performing memory mappings with the +.Fn mmap +system call with +.Dv MAP_FIXED +in the flags. +The +.Fa addr +argument should point to a memory location that stores a pointer +which is used both as an input argument where the caller specifies the +preferred address and as an output of the resulting hint. +The +.Fa size +argument specifies the requested size of the memory area the caller +is looking for. +The +.Fa fd +and +.Fa off +arguments specify the file that will be mapped and the offset in it, +this is the same as the corresponding arguments to +.Fn mmap . +.Pp +The behavior of the function depends on the +.Fa flags +argument. +If set to +.Dv MAP_FIXED +the pointer +.Fa *addr +is used as a fixed hint and +.Fn mquery +will return \-1 and set +.Va errno +to +.Dv ENOMEM +if there is not +.Fa size +bytes free after that address. +Otherwise it will return 0 and +.Fa *addr +will not be changed. +If no flags are set +.Fn mquery +will use +.Fa *addr +as a starting point in memory and will search forward to find +a memory area with +.Fa size +bytes free and that will be suitable for creating a mapping for the +file and offset specified in the +.Fa fd +and +.Fa off +arguments. +When no such area can be found +.Fn mquery +will return \-1 and set +.Va errno +to +.Dv ENOMEM . +.Sh RETURN VALUES +When a memory range satisfying the request is found +.Fn mquery +returns 0. +Otherwise, \-1 is returned and +.Va errno +is set to indicate the error. +.Sh ERRORS +.Fn mquery +will fail if: +.Bl -tag -width ENOMEM +.It Bq Er ENOMEM +.Dv MAP_FIXED +was specified and the requested memory area is unavailable. +.It Bq Er ENOMEM +There was not enough memory left after the hint specified. +.It Bq Er EBADF +.Fa fd +is not a valid open file descriptor. +.Sh SEE ALSO +.Xr mmap 2 +.Sh HISTORY +The +.Fn mquery +function first appeared in +.Ox 3.4 . diff --git a/lib/libc/sys/mquery.c b/lib/libc/sys/mquery.c new file mode 100644 index 00000000000..2cb28e27a9b --- /dev/null +++ b/lib/libc/sys/mquery.c @@ -0,0 +1,17 @@ +/* $OpenBSD: mquery.c,v 1.1 2003/04/14 04:53:50 art Exp $ */ +/* + * Written by Artur Grabowski <art@openbsd.org> Public Domain + */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/syscall.h> + +/* + * This function provides 64-bit offset padding. + */ +int +mquery(int flags, void **addr, size_t size, int fd, off_t off) +{ + return(__syscall((quad_t)SYS_mquery, flags, addr, size, fd, off)); +} |