]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/shmat.2
libc: Fix most issues reported by mandoc
[FreeBSD/FreeBSD.git] / lib / libc / sys / shmat.2
1 .\"
2 .\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
3 .\"
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 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd January 14, 2019
29 .Dt SHMAT 2
30 .Os
31 .Sh NAME
32 .Nm shmat ,
33 .Nm shmdt
34 .Nd attach or detach shared memory
35 .Sh LIBRARY
36 .Lb libc
37 .Sh SYNOPSIS
38 .In sys/types.h
39 .In sys/ipc.h
40 .In sys/shm.h
41 .Ft void *
42 .Fn shmat "int shmid" "const void *addr" "int flag"
43 .Ft int
44 .Fn shmdt "const void *addr"
45 .Sh DESCRIPTION
46 The
47 .Fn shmat
48 system call
49 attaches the shared memory segment identified by
50 .Fa shmid
51 to the calling process's address space.
52 The address where the segment
53 is attached is determined as follows:
54 .\"
55 .\" These are cribbed almost exactly from Stevens, _Advanced Programming in
56 .\" the UNIX Environment_.
57 .\"
58 .Bl -bullet
59 .It
60 If
61 .Fa addr
62 is 0, the segment is attached at an address selected by the
63 kernel.
64 .It
65 If
66 .Fa addr
67 is nonzero and
68 .Va SHM_RND
69 is not specified in
70 .Fa flag ,
71 the segment is attached the specified address.
72 .It
73 If
74 .Fa addr
75 is specified and
76 .Va SHM_RND
77 is specified,
78 .Fa addr
79 is rounded down to the nearest multiple of SHMLBA.
80 .El
81 .Pp
82 If the
83 .Va SHM_REMAP
84 flag is specified and the passed
85 .Fa addr
86 is not
87 .Dv NULL ,
88 any existing mappings in the virtual addresses range are
89 cleared before the segment is attached.
90 If the flag is not specified,
91 .Fa addr
92 is not
93 .Dv NULL ,
94 and the virtual address range contains
95 some pre-existing mappings, the
96 .Fn shmat
97 call fails.
98 .Pp
99 The
100 .Fn shmdt
101 system call
102 detaches the shared memory segment at the address specified by
103 .Fa addr
104 from the calling process's address space.
105 .Sh RETURN VALUES
106 Upon success,
107 .Fn shmat
108 returns the address where the segment is attached; otherwise, -1
109 is returned and
110 .Va errno
111 is set to indicate the error.
112 .Pp
113 .Rv -std shmdt
114 .Sh ERRORS
115 The
116 .Fn shmat
117 system call
118 will fail if:
119 .Bl -tag -width Er
120 .It Bq Er EINVAL
121 No shared memory segment was found corresponding to
122 .Fa shmid .
123 .It Bq Er EINVAL
124 The
125 .Fa addr
126 argument
127 was not an acceptable address.
128 .It Bq Er ENOMEM
129 The specified
130 .Fa addr
131 cannot be used for mapping, for instance due to the amount of available
132 space being smaller than the segment size,
133 or because pre-existing mappings are in the range and no
134 .Va SHM_REMAP
135 flag was provided.
136 .It Bq Er EMFILE
137 Failed to attach the shared memory segment because the per-process
138 .Va kern.ipc.shmseg
139 .Xr sysctl 3
140 limit was reached.
141 .El
142 .Pp
143 The
144 .Fn shmdt
145 system call
146 will fail if:
147 .Bl -tag -width Er
148 .It Bq Er EINVAL
149 The
150 .Fa addr
151 argument
152 does not point to a shared memory segment.
153 .El
154 .Sh "SEE ALSO"
155 .Xr shmctl 2 ,
156 .Xr shmget 2