]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/man/man2/shmctl.2
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / man / man2 / shmctl.2
... / ...
CommitLineData
1.\" $OpenBSD: shmctl.2,v 1.2 1996/10/08 01:20:15 michaels Exp $
2.\" $NetBSD: shmctl.2,v 1.1 1995/10/16 23:49:30 jtc Exp $
3.\"
4.\" Copyright (c) 1995 Frank van der Linden
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\" must display the following acknowledgement:
17.\" This product includes software developed for the NetBSD Project
18.\" by Frank van der Linden
19.\" 4. The name of the author may not be used to endorse or promote products
20.\" derived from this software without specific prior written permission
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"/
33.Dd August 17, 1995
34.Dt SHMCTL 2
35.Os
36.Sh NAME
37.Nm shmctl
38.Nd shared memory control operations
39.Sh SYNOPSIS
40.Fd #include <sys/types.h>
41.Fd #include <sys/ipc.h>
42.Fd #include <sys/msg.h>
43.Ft int
44.Fn shmctl "int shmid" "int cmd" "struct shmid_ds *buf"
45.Sh DESCRIPTION
46The
47.Fn shmctl
48system call performs some control operations on the shared memory area
49specified by
50.Fa shmid .
51Each shared memory segment has a data structure associated with it,
52parts of which may be altered by
53.Fn shmctl
54and parts of which determine the actions of
55.Fn shmctl .
56This structure is defined as follows in
57.Aq Pa sys/shm.h :
58.Bd -literal
59struct shmid_ds {
60 struct ipc_perm shm_perm; /* operation permissions */
61 int shm_segsz; /* size of segment in bytes */
62 pid_t shm_lpid; /* pid of last shm op */
63 pid_t shm_cpid; /* pid of creator */
64 short shm_nattch; /* # of current attaches */
65 time_t shm_atime; /* last shmat() time*/
66 time_t shm_dtime; /* last shmdt() time */
67 time_t shm_ctime; /* last change by shmctl() */
68 void *shm_internal; /* sysv stupidity */
69};
70.Ed
71The
72.Bf -literal
73ipc_perm
74.Ef
75structure used inside the
76.Bf -literal
77shmid_ds
78.Ef
79structure is defined in
80.Aq Pa sys/ipc.h
81and looks like this:
82.Bd -literal
83struct ipc_perm {
84 ushort cuid; /* creator user id */
85 ushort cgid; /* creator group id */
86 ushort uid; /* user id */
87 ushort gid; /* group id */
88 ushort mode; /* r/w permission (see chmod(2)) */
89 ushort seq; /* sequence # (to generate unique msg/sem/shm id) */
90 key_t key; /* user specified msg/sem/shm key */
91};
92.Ed
93The operation to be performed by
94.Fn shmctl
95is specified in
96.Fa cmd
97and is one of:
98.Bl -tag -width IPC_RMIDX
99.It Dv IPC_STAT
100Gather information about the shared memory segment and place it in the
101structure pointed to by
102.Fa buf .
103.It Dv IPC_SET
104Set the value of the
105.Va shm_perm.uid ,
106.Va shm_perm.gid
107and
108.Va shm_perm.mode
109fields in the structure associated with
110.Fa shmid .
111The values are taken from the corresponding fields in the structure
112pointed to by
113.Fa buf .
114This operation can only be executed by the super-user, or a process that
115has an effective user id equal to either
116.Va shm_perm.cuid
117or
118.Va shm_perm.uid
119in the data structure associated with the shared memory segment.
120.It Dv IPC_RMID
121Remove the shared memory segment specified by
122.Fa shmid
123and destroy the data associated with it. Only the super-user or a process
124with an effective uid equal to the
125.Va shm_perm.cuid
126or
127.Va shm_perm.uid
128values in the data structure associated with the queue can do this.
129.El
130The read and write permissions on a shared memory identifier
131are determined by the
132.Va shm_perm.mode
133field in the same way as is
134done with files (see
135.Xr chmod 2 ),
136but the effective uid can match either the
137.Va shm_perm.cuid
138field or the
139.Va shm_perm.uid
140field, and the
141effective gid can match either
142.Va shm_perm.cgid
143or
144.Va shm_perm.gid .
145.Sh RETURN VALUES
146Upon successful completion, a value of 0 is returned. Otherwise, -1 is
147returned and the global variable
148.Va errno
149is set to indicate the error.
150.Sh ERRORS
151.Fn shmctl
152will fail if:
153.Bl -tag -width Er
154.It Bq Er EPERM
155.Fa cmd
156is equal to IPC_SET or IPC_RMID and the caller is not the super-user, nor does
157the effective uid match either the
158.Va shm_perm.uid
159or
160.Va shm_perm.cuid
161fields of the data structure associated with the shared memory segment.
162An attempt is made to increase the value of
163.Va shm_qbytes
164through IPC_SET
165but the caller is not the super-user.
166.It Bq Er EACCES
167The command is IPC_STAT
168and the caller has no read permission for this shared memory segment.
169.It Bq Er EINVAL
170.Fa shmid
171is not a valid shared memory segment identifier.
172.Va cmd
173is not a valid command.
174.It Bq Er EFAULT
175.Fa buf
176specifies an invalid address.
177.El
178.Sh SEE ALSO
179.Xr shmat 2 ,
180.Xr shmdt 2 ,
181.Xr shmget 2