xref: /dragonfly/lib/libc/sys/shmat.2 (revision 6ca88057)
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: src/lib/libc/sys/shmat.2,v 1.8.2.6 2001/12/14 18:34:01 ru Exp $
27.\"
28.Dd January 4, 2014
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 machine/param.h
39.In sys/types.h
40.In sys/ipc.h
41.In sys/shm.h
42.Ft void *
43.Fn shmat "int shmid" "const void *addr" "int flag"
44.Ft int
45.Fn shmdt "const void *addr"
46.Sh DESCRIPTION
47.Fn Shmat
48attaches the shared memory segment identified by
49.Fa shmid
50to the calling process's address space.
51The address where the segment 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
58If
59.Fa addr
60is 0, the segment is attached at an address selected by the
61kernel.
62.It
63If
64.Fa addr
65is nonzero and
66.Dv SHM_RND
67is not specified in
68.Fa flag ,
69the segment is attached the specified address.
70.It
71If
72.Fa addr
73is specified and
74.Dv SHM_RND
75is specified,
76.Fa addr
77is rounded down to the nearest multiple of
78.Dv SHMLBA .
79.El
80.Pp
81.Fn Shmdt
82detaches the shared memory segment at the address specified by
83.Fa addr
84from the calling process's address space.
85.Sh RETURN VALUES
86Upon success,
87.Fn shmat
88returns the address where the segment is attached; otherwise, -1
89is returned and
90.Va errno
91is set to indicate the error.
92.Pp
93.Rv -std shmdt
94.Sh ENVIRONMENT
95The XSI Interprocess Communication family of functions is also available
96as an implementation in userspace.
97To use it, the
98.Xr sysvipcd 8
99daemon has to be running.
100.Pp
101If the
102.Ev USR_SYSVIPC
103variable is set in a process' environment, the process and its children
104will use the userspace implementation.
105.Sh ERRORS
106.Fn Shmat
107will fail if:
108.Bl -tag -width Er
109.It Bq Er EINVAL
110No shared memory segment was found corresponding to
111.Fa shmid .
112.It Bq Er EINVAL
113.Fa addr
114was not an acceptable address.
115.El
116.Pp
117.Fn Shmdt
118will fail if:
119.Bl -tag -width Er
120.It Bq Er EINVAL
121.Fa addr
122does not point to a shared memory segment.
123.El
124.Sh "SEE ALSO"
125.Xr shmctl 2 ,
126.Xr shmget 2
127.Sh AUTHORS
128.An -nosplit
129The
130.Dx
131specific userspace implementation (see
132.Sx ENVIRONMENT )
133was written by
134.An Larisa Grigore .
135