1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1988 University of Utah. 5 * Copyright (c) 1990, 1993 6 * The Regents of the University of California. All rights reserved. 7 * (c) UNIX System Laboratories, Inc. 8 * All or some portions of this file are derived from material licensed 9 * to the University of California by American Telephone and Telegraph 10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 11 * the permission of UNIX System Laboratories, Inc. 12 * 13 * This code is derived from software contributed to Berkeley by 14 * the Systems Programming Group of the University of Utah Computer 15 * Science Department. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 3. Neither the name of the University nor the names of its contributors 26 * may be used to endorse or promote products derived from this software 27 * without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 */ 41 42 /* 43 * SVID compatible ipc.h file 44 */ 45 #ifndef _SYS_IPC_H_ 46 #define _SYS_IPC_H_ 47 48 #include <sys/cdefs.h> 49 #include <sys/_types.h> 50 51 #ifndef _GID_T_DECLARED 52 typedef __gid_t gid_t; 53 #define _GID_T_DECLARED 54 #endif 55 56 #ifndef _KEY_T_DECLARED 57 typedef __key_t key_t; 58 #define _KEY_T_DECLARED 59 #endif 60 61 #ifndef _MODE_T_DECLARED 62 typedef __mode_t mode_t; 63 #define _MODE_T_DECLARED 64 #endif 65 66 #ifndef _UID_T_DECLARED 67 typedef __uid_t uid_t; 68 #define _UID_T_DECLARED 69 #endif 70 71 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ 72 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \ 73 defined(COMPAT_43) 74 struct ipc_perm_old { 75 unsigned short cuid; /* creator user id */ 76 unsigned short cgid; /* creator group id */ 77 unsigned short uid; /* user id */ 78 unsigned short gid; /* group id */ 79 unsigned short mode; /* r/w permission */ 80 unsigned short seq; /* sequence # (to generate unique ipcid) */ 81 key_t key; /* user specified msg/sem/shm key */ 82 }; 83 #endif 84 85 struct ipc_perm { 86 uid_t cuid; /* creator user id */ 87 gid_t cgid; /* creator group id */ 88 uid_t uid; /* user id */ 89 gid_t gid; /* group id */ 90 mode_t mode; /* r/w permission */ 91 unsigned short seq; /* sequence # (to generate unique ipcid) */ 92 key_t key; /* user specified msg/sem/shm key */ 93 }; 94 95 #if __BSD_VISIBLE 96 /* common mode bits */ 97 #define IPC_R 000400 /* read permission */ 98 #define IPC_W 000200 /* write/alter permission */ 99 #define IPC_M 010000 /* permission to change control info */ 100 #endif 101 102 /* SVID required constants (same values as system 5) */ 103 #define IPC_CREAT 001000 /* create entry if key does not exist */ 104 #define IPC_EXCL 002000 /* fail if key exists */ 105 #define IPC_NOWAIT 004000 /* error if request must wait */ 106 107 #define IPC_PRIVATE (key_t)0 /* private key */ 108 109 #define IPC_RMID 0 /* remove identifier */ 110 #define IPC_SET 1 /* set options */ 111 #define IPC_STAT 2 /* get options */ 112 #if __BSD_VISIBLE 113 /* 114 * For Linux compatibility. 115 */ 116 #define IPC_INFO 3 /* get info */ 117 #endif 118 119 #if defined(_KERNEL) || defined(_WANT_SYSVIPC_INTERNALS) 120 /* Macros to convert between ipc ids and array indices or sequence ids */ 121 #define IPCID_TO_IX(id) ((id) & 0xffff) 122 #define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff) 123 #define IXSEQ_TO_IPCID(ix,perm) (((perm.seq) << 16) | (ix & 0xffff)) 124 #endif 125 126 #ifdef _KERNEL 127 struct thread; 128 struct proc; 129 struct vmspace; 130 struct vm_object; 131 132 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ 133 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) 134 void ipcperm_old2new(struct ipc_perm_old *, struct ipc_perm *); 135 void ipcperm_new2old(struct ipc_perm *, struct ipc_perm_old *); 136 #endif 137 138 int ipcperm(struct thread *, struct ipc_perm *, int); 139 extern void (*shmfork_hook)(struct proc *, struct proc *); 140 extern void (*shmexit_hook)(struct vmspace *); 141 extern void (*shmobjinfo_hook)(struct vm_object *obj, key_t *key, 142 unsigned short *seq); 143 144 #else /* ! _KERNEL */ 145 146 __BEGIN_DECLS 147 key_t ftok(const char *, int); 148 __END_DECLS 149 150 #endif /* _KERNEL */ 151 152 #endif /* !_SYS_IPC_H_ */ 153