xref: /dragonfly/lib/libc/sys/shmctl.2 (revision 1cef5f30)
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/shmctl.2,v 1.9.2.4 2001/12/14 18:34:01 ru Exp $
27.\"
28.Dd September 12, 2019
29.Dt SHMCTL 2
30.Os
31.Sh NAME
32.Nm shmctl
33.Nd shared memory control
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In machine/param.h
38.In sys/types.h
39.In sys/ipc.h
40.In sys/shm.h
41.Ft int
42.Fn shmctl "int shmid" "int cmd" "struct shmid_ds *buf"
43.Sh DESCRIPTION
44Performs the action specified by
45.Fa cmd
46on the shared memory segment identified by
47.Fa shmid :
48.Bl -tag -width SHM_UNLOCKX
49.It Dv IPC_STAT
50Fetch the segment's
51.Fa "struct shmid_ds" ,
52storing it in the memory pointed to by
53.Fa buf .
54.\"
55.\" XXX need to make sure that this is correct for FreeBSD
56.\"
57.It Dv IPC_SET
58Changes the
59.Fa shm_perm.uid ,
60.Fa shm_perm.gid ,
61and
62.Fa shm_perm.mode
63members of the segment's
64.Fa "struct shmid_ds"
65to match those of the struct pointed to by
66.Fa buf .
67The calling process's effective uid must
68match either
69.Fa shm_perm.uid
70or
71.Fa shm_perm.cuid ,
72or it must have superuser privileges.
73.It Dv IPC_RMID
74Removes the segment from the system.
75The removal will not take
76effect until all processes having attached the segment have exited;
77however, once the
78.Dv IPC_RMID
79operation has taken place, no further
80processes will be allowed to attach the segment.
81For the operation
82to succeed, the calling process's effective uid must match
83.Fa shm_perm.uid
84or
85.Fa shm_perm.cuid ,
86or the process must have superuser privileges.
87.\" .It Dv SHM_LOCK
88.\" Locks the segment in memory.
89.\" The calling process must have superuser privileges.
90.\" Not implemented in FreeBSD.
91.\" .It Dv SHM_UNLOCK
92.\" Unlocks the segment from memory.
93.\" The calling process must have superuser privileges.
94.\" Not implemented in FreeBSD.
95.El
96.Pp
97The
98.Fa shmid_ds
99struct is defined as follows:
100.\"
101.\" I fiddled with the spaces a bit to make it fit well when viewed
102.\" with nroff, but otherwise it's straight from sys/shm.h
103.\"
104.Bd -literal
105typedef unsigned int shmatt_t;
106
107struct shmid_ds {
108    struct ipc_perm shm_perm;   /* operation permission structure */
109    size_t          shm_segsz;  /* size of segment in bytes */
110    pid_t           shm_lpid;   /* process ID of last shared memory op */
111    pid_t           shm_cpid;   /* process ID of creator */
112    shmatt_t        shm_nattch; /* number of current attaches */
113    time_t          shm_atime;  /* time of last shmat() */
114    time_t          shm_dtime;  /* time of last shmdt() */
115    time_t          shm_ctime;  /* time of last change by shmctl() */
116    void           *shm_internal; /* sysv stupidity */
117};
118.Ed
119.Pp
120The
121.Vt ipc_perm
122structure used inside the
123.Vt shmid_ds
124structure is defined in
125.In sys/ipc.h .
126.Sh RETURN VALUES
127.Rv -std shmctl
128.Sh ENVIRONMENT
129The XSI Interprocess Communication family of functions is also available
130as an implementation in userspace.
131To use it, the
132.Xr sysvipcd 8
133daemon has to be running.
134.Pp
135If the
136.Ev USR_SYSVIPC
137variable is set in a process' environment, the process and its children
138will use the userspace implementation.
139.Sh ERRORS
140.Fn Shmctl
141will fail if:
142.Bl -tag -width Er
143.It Bq Er EINVAL
144Invalid operation, or
145no shared memory segment was found corresponding to
146.Fa shmid .
147.\"
148.\" XXX I think the following is right: ipcperm() only returns EPERM
149.\"	when an attempt is made to modify (IPC_M) by a non-creator
150.\"	non-owner
151.It Bq Er EPERM
152The calling process's effective uid does not match the uid of
153the shared memory segment's owner or creator.
154.It Bq Er EACCES
155Permission denied due to mismatch between operation and mode of
156shared memory segment.
157.El
158.Sh "SEE ALSO"
159.Xr shmat 2 ,
160.Xr shmdt 2 ,
161.Xr shmget 2 ,
162.Xr ftok 3
163.Sh AUTHORS
164.An -nosplit
165The
166.Dx
167specific userspace implementation (see
168.Sx ENVIRONMENT )
169was written by
170.An Larisa Grigore .
171