xref: /netbsd/lib/libc/sys/shmat.2 (revision bf9ec67e)
1.\"	$NetBSD: shmat.2,v 1.12 2002/02/08 01:28:22 ross Exp $
2.\"
3.\" Copyright (c) 1995 Frank van der Linden
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"      This product includes software developed for the NetBSD Project
17.\"      by Frank van der Linden
18.\" 4. The name of the author may not be used to endorse or promote products
19.\"    derived from this software without specific prior written permission
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31.\"
32.Dd August 25, 1999
33.Dt SHMAT 2
34.Os
35.Sh NAME
36.Nm shmat ,
37.Nm shmdt
38.Nd map/unmap shared memory
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.Fd #include \*[Lt]sys/shm.h\*[Gt]
43.Ft void *
44.Fn shmat "int shmid" "const void *shmaddr" "int shmflg"
45.Ft int
46.Fn shmdt "const void *shmaddr"
47.Sh DESCRIPTION
48.Fn shmat
49maps the shared memory segment associated with the shared memory identifier
50.Fa shmid
51into the address space of the calling process. The address at which the
52segment is mapped is determined by the
53.Fa shmaddr
54parameter. If it is equal to 0, the system will pick an address itself.
55Otherwise, an attempt is made to map the shared memory segment at the
56address
57.Fa shmaddr
58specifies. If
59.Dv SHM_RND
60is set in
61.Fa shmflg ,
62the system will round the address down to a multiple of
63.Dv SHMLBA
64bytes
65.Pf ( Dv SHMLBA
66is defined in
67.Aq Pa sys/shm.h ) .
68.Pp
69A shared memory segment can be mapped read-only by specifying the
70.Dv SHM_RDONLY
71flag in
72.Fa shmflg .
73.Pp
74.Fn shmdt
75unmaps the shared memory segment that is currently mapped at
76.Fa shmaddr
77from the calling process' address space.
78.Fa shmaddr
79must be a value returned by a prior
80.Fn shmat
81call. A shared memory segment will remain in existence until it is
82removed by a call to
83.Xr shmctl 2
84with the
85.Dv IPC_RMID
86command.
87.Sh RETURN VALUES
88.Fn shmat
89returns the address at which the shared memory segment has been mapped into
90the calling process' address space when successful,
91.Fn shmdt
92returns 0 on successful completion. Otherwise, a value of -1 is returned,
93and the global variable
94.Va errno
95is set to indicate the error.
96.Sh ERRORS
97.Fn shmat
98will fail if:
99.Bl -tag -width Er
100.It Bq Er EACCES
101The calling process has no permission to access this shared memory segment.
102.It Bq Er ENOMEM
103There is not enough available data space for the calling process to
104map the shared memory segment.
105.It Bq Er EINVAL
106.Fa shmid
107is not a valid shared memory identifier.
108.Pp
109.Fa shmaddr
110specifies an illegal address.
111.It Bq Er EMFILE
112The number of shared memory segments has reached the system-wide limit.
113.El
114.Pp
115.Fn shmdt
116will fail if:
117.Bl -tag -width Er
118.It Bq Er EINVAL
119.Fa shmaddr
120is not the start address of a mapped shared memory segment.
121.El
122.Sh SEE ALSO
123.Xr mmap 2 ,
124.Xr shmctl 2 ,
125.Xr shmget 2
126.Sh STANDARDS
127The
128.Nm shmat
129and
130.Nm shmdt
131system calls conform to
132.St -xsh5 .
133.Sh HISTORY
134Shared memory segments appeared in the first release of
135.At V .
136