]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/shmat.2
sqlite3: Vendor import of sqlite3 3.44.0
[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 .Dd January 14, 2019
27 .Dt SHMAT 2
28 .Os
29 .Sh NAME
30 .Nm shmat ,
31 .Nm shmdt
32 .Nd attach or detach shared memory
33 .Sh LIBRARY
34 .Lb libc
35 .Sh SYNOPSIS
36 .In sys/types.h
37 .In sys/ipc.h
38 .In sys/shm.h
39 .Ft void *
40 .Fn shmat "int shmid" "const void *addr" "int flag"
41 .Ft int
42 .Fn shmdt "const void *addr"
43 .Sh DESCRIPTION
44 The
45 .Fn shmat
46 system call
47 attaches the shared memory segment identified by
48 .Fa shmid
49 to the calling process's address space.
50 The address where the segment
51 is attached is determined as follows:
52 .\"
53 .\" These are cribbed almost exactly from Stevens, _Advanced Programming in
54 .\" the UNIX Environment_.
55 .\"
56 .Bl -bullet
57 .It
58 If
59 .Fa addr
60 is 0, the segment is attached at an address selected by the
61 kernel.
62 .It
63 If
64 .Fa addr
65 is nonzero and
66 .Va SHM_RND
67 is not specified in
68 .Fa flag ,
69 the segment is attached the specified address.
70 .It
71 If
72 .Fa addr
73 is specified and
74 .Va SHM_RND
75 is specified,
76 .Fa addr
77 is rounded down to the nearest multiple of SHMLBA.
78 .El
79 .Pp
80 If the
81 .Va SHM_REMAP
82 flag is specified and the passed
83 .Fa addr
84 is not
85 .Dv NULL ,
86 any existing mappings in the virtual addresses range are
87 cleared before the segment is attached.
88 If the flag is not specified,
89 .Fa addr
90 is not
91 .Dv NULL ,
92 and the virtual address range contains
93 some pre-existing mappings, the
94 .Fn shmat
95 call fails.
96 .Pp
97 The
98 .Fn shmdt
99 system call
100 detaches the shared memory segment at the address specified by
101 .Fa addr
102 from the calling process's address space.
103 .Sh RETURN VALUES
104 Upon success,
105 .Fn shmat
106 returns the address where the segment is attached; otherwise, -1
107 is returned and
108 .Va errno
109 is set to indicate the error.
110 .Pp
111 .Rv -std shmdt
112 .Sh ERRORS
113 The
114 .Fn shmat
115 system call
116 will fail if:
117 .Bl -tag -width Er
118 .It Bq Er EINVAL
119 No shared memory segment was found corresponding to
120 .Fa shmid .
121 .It Bq Er EINVAL
122 The
123 .Fa addr
124 argument
125 was not an acceptable address.
126 .It Bq Er ENOMEM
127 The specified
128 .Fa addr
129 cannot be used for mapping, for instance due to the amount of available
130 space being smaller than the segment size,
131 or because pre-existing mappings are in the range and no
132 .Va SHM_REMAP
133 flag was provided.
134 .It Bq Er EMFILE
135 Failed to attach the shared memory segment because the per-process
136 .Va kern.ipc.shmseg
137 .Xr sysctl 3
138 limit was reached.
139 .El
140 .Pp
141 The
142 .Fn shmdt
143 system call
144 will fail if:
145 .Bl -tag -width Er
146 .It Bq Er EINVAL
147 The
148 .Fa addr
149 argument
150 does not point to a shared memory segment.
151 .El
152 .Sh "SEE ALSO"
153 .Xr shmctl 2 ,
154 .Xr shmget 2