summaryrefslogtreecommitdiff
path: root/lib/libc/sys/shmat.2
blob: 20addde9d44e17f9f04691f99652be58fe36fa1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
.\"	$OpenBSD: shmat.2,v 1.14 2007/05/31 19:19:33 jmc Exp $
.\"	$NetBSD: shmat.2,v 1.2 1997/03/27 08:20:38 mikel Exp $
.\"
.\" 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.
.\"/
.Dd $Mdocdate: May 31 2007 $
.Dt SHMAT 2
.Os
.Sh NAME
.Nm shmat ,
.Nm shmdt
.Nd map/unmap shared memory
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <sys/ipc.h>
.Fd #include <sys/shm.h>
.Ft void *
.Fn shmat "int shmid" "const void *shmaddr" "int shmflg"
.Ft int
.Fn shmdt "const void *shmaddr"
.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
specifies.
If
.Dv SHM_RND
is set in
.Fa shmflg ,
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
A shared memory segment can be mapped read-only by specifying the
.Dv SHM_RDONLY
flag in
.Fa shmflg .
.Pp
.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
call.
A shared memory segment will remain existent until it is removed by
a call to
.Xr shmctl 2
with the
.Dv IPC_RMID
command.
.Sh RETURN VALUES
.Fn shmat
returns the address at which the shared memory segment has been mapped into
the calling process' address space when successful,
.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
.It Bq Er EACCES
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.
.Pp
.Fa shmaddr
specifies an illegal address.
.It Bq Er EMFILE
The number of shared memory segments has reached the system-wide limit.
.El
.Pp
.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.
.El
.Sh SEE ALSO
.Xr ipcrm 1 ,
.Xr ipcs 1 ,
.Xr mmap 2 ,
.Xr shmctl 2 ,
.Xr shmget 2