2002-02-08 04:21:55 +03:00
|
|
|
.\" $NetBSD: shmat.2,v 1.12 2002/02/08 01:28:22 ross Exp $
|
1995-10-17 02:49:07 +03:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1995 Frank van der Linden
|
|
|
|
.\" 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.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed for the NetBSD Project
|
|
|
|
.\" by Frank van der Linden
|
|
|
|
.\" 4. 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 BY THE AUTHOR ``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.
|
1997-11-27 13:24:44 +03:00
|
|
|
.\"
|
1999-08-26 01:12:54 +04:00
|
|
|
.Dd August 25, 1999
|
1995-10-17 02:49:07 +03:00
|
|
|
.Dt SHMAT 2
|
1999-03-22 22:44:33 +03:00
|
|
|
.Os
|
1995-10-17 02:49:07 +03:00
|
|
|
.Sh NAME
|
|
|
|
.Nm shmat ,
|
|
|
|
.Nm shmdt
|
|
|
|
.Nd map/unmap shared memory
|
1999-12-03 00:42:35 +03:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1995-10-17 02:49:07 +03:00
|
|
|
.Sh SYNOPSIS
|
2002-02-08 04:21:55 +03:00
|
|
|
.Fd #include \*[Lt]sys/shm.h\*[Gt]
|
1995-10-17 02:49:07 +03:00
|
|
|
.Ft void *
|
1998-05-07 22:42:00 +04:00
|
|
|
.Fn shmat "int shmid" "const void *shmaddr" "int shmflg"
|
1995-10-17 02:49:07 +03:00
|
|
|
.Ft int
|
1998-05-07 22:42:00 +04:00
|
|
|
.Fn shmdt "const void *shmaddr"
|
1995-10-17 02:49:07 +03:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
.Fn shmat
|
|
|
|
maps the shared memory segment associated with the shared memory identifier
|
|
|
|
.Fa shmid
|
|
|
|
into the address space of the calling process. The address at which the
|
|
|
|
segment is mapped is determined by the
|
|
|
|
.Fa shmaddr
|
|
|
|
parameter. If it is equal to 0, the system will pick an address itself.
|
|
|
|
Otherwise, an attempt is made to map the shared memory segment at the
|
|
|
|
address
|
|
|
|
.Fa shmaddr
|
1997-11-27 13:24:44 +03:00
|
|
|
specifies. If
|
|
|
|
.Dv SHM_RND
|
|
|
|
is set in
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fa shmflg ,
|
1997-11-27 13:24:44 +03:00
|
|
|
the system will round the address down to a multiple of
|
|
|
|
.Dv SHMLBA
|
|
|
|
bytes
|
|
|
|
.Pf ( Dv SHMLBA
|
|
|
|
is defined in
|
|
|
|
.Aq Pa sys/shm.h ) .
|
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
A shared memory segment can be mapped read-only by specifying the
|
1997-11-27 13:24:44 +03:00
|
|
|
.Dv SHM_RDONLY
|
|
|
|
flag in
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fa shmflg .
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fn shmdt
|
|
|
|
unmaps the shared memory segment that is currently mapped at
|
|
|
|
.Fa shmaddr
|
|
|
|
from the calling process' address space.
|
|
|
|
.Fa shmaddr
|
|
|
|
must be a value returned by a prior
|
|
|
|
.Fn shmat
|
1997-11-27 13:24:44 +03:00
|
|
|
call. A shared memory segment will remain in existence until it is
|
|
|
|
removed by a call to
|
1995-10-17 02:49:07 +03:00
|
|
|
.Xr shmctl 2
|
1997-11-27 13:24:44 +03:00
|
|
|
with the
|
|
|
|
.Dv IPC_RMID
|
|
|
|
command.
|
1995-10-17 02:49:07 +03:00
|
|
|
.Sh RETURN VALUES
|
|
|
|
.Fn shmat
|
|
|
|
returns the address at which the shared memory segment has been mapped into
|
2001-09-16 05:38:59 +04:00
|
|
|
the calling process' address space when successful,
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fn shmdt
|
|
|
|
returns 0 on successful completion. Otherwise, a value of -1 is returned,
|
|
|
|
and the global variable
|
|
|
|
.Va errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.Sh ERRORS
|
|
|
|
.Fn shmat
|
|
|
|
will fail if:
|
|
|
|
.Bl -tag -width Er
|
1997-11-27 10:36:24 +03:00
|
|
|
.It Bq Er EACCES
|
1995-10-17 02:49:07 +03:00
|
|
|
The calling process has no permission to access this shared memory segment.
|
|
|
|
.It Bq Er ENOMEM
|
|
|
|
There is not enough available data space for the calling process to
|
|
|
|
map the shared memory segment.
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
.Fa shmid
|
|
|
|
is not a valid shared memory identifier.
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fa shmaddr
|
|
|
|
specifies an illegal address.
|
|
|
|
.It Bq Er EMFILE
|
|
|
|
The number of shared memory segments has reached the system-wide limit.
|
|
|
|
.El
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fn shmdt
|
|
|
|
will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
.Fa shmaddr
|
|
|
|
is not the start address of a mapped shared memory segment.
|
1999-03-09 06:58:14 +03:00
|
|
|
.El
|
1995-10-17 02:49:07 +03:00
|
|
|
.Sh SEE ALSO
|
1997-03-27 11:20:35 +03:00
|
|
|
.Xr mmap 2 ,
|
1995-10-17 02:49:07 +03:00
|
|
|
.Xr shmctl 2 ,
|
1997-03-27 11:20:35 +03:00
|
|
|
.Xr shmget 2
|
1999-08-26 01:12:54 +04:00
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
|
|
|
.Nm shmat
|
|
|
|
and
|
|
|
|
.Nm shmdt
|
|
|
|
system calls conform to
|
|
|
|
.St -xsh5 .
|
|
|
|
.Sh HISTORY
|
|
|
|
Shared memory segments appeared in the first release of
|
|
|
|
.At V .
|