xref: /dragonfly/lib/libc/sys/shmat.2 (revision c3762235)
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.  The address where the segment
51is 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 SHM_RND is not specified in
66.Fa flag ,
67the segment is attached the specified address.
68.It
69If
70.Fa addr
71is specified and SHM_RND is specified,
72.Fa addr
73is rounded down to the nearest multiple of SHMLBA.
74.El
75.Pp
76.Fn Shmdt
77detaches the shared memory segment at the address specified by
78.Fa addr
79from the calling process's address space.
80.Sh RETURN VALUES
81Upon success,
82.Fn shmat
83returns the address where the segment is attached; otherwise, -1
84is returned and
85.Va errno
86is set to indicate the error.
87.Pp
88.Rv -std shmdt
89.Sh ENVIRONMENT
90The XSI Interprocess Communication family of functions is also available
91as an implementation in userspace.
92To use it, the
93.Xr sysvipcd 8
94daemon has to be running.
95.Pp
96If the
97.Ev USR_SYSVIPC
98variable is set in a process' environment, the process and its children
99will use the userspace implementation.
100.Sh ERRORS
101.Fn Shmat
102will fail if:
103.Bl -tag -width Er
104.It Bq Er EINVAL
105No shared memory segment was found corresponding to
106.Fa shmid .
107.It Bq Er EINVAL
108.Fa addr
109was not an acceptable address.
110.El
111.Pp
112.Fn Shmdt
113will fail if:
114.Bl -tag -width Er
115.It Bq Er EINVAL
116.Fa addr
117does not point to a shared memory segment.
118.El
119.Sh "SEE ALSO"
120.Xr shmctl 2 ,
121.Xr shmget 2
122.Sh AUTHORS
123.An -nosplit
124The
125.Dx
126specific userspace implementation (see
127.Sx ENVIRONMENT )
128was written by
129.An Larisa Grigore .
130