Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_IPC_H |
| 2 | #define _LINUX_IPC_H |
| 3 | |
| 4 | #include <linux/types.h> |
| 5 | |
| 6 | #define IPC_PRIVATE ((__kernel_key_t) 0) |
| 7 | |
| 8 | /* Obsolete, used only for backwards compatibility and libc5 compiles */ |
| 9 | struct ipc_perm |
| 10 | { |
| 11 | __kernel_key_t key; |
| 12 | __kernel_uid_t uid; |
| 13 | __kernel_gid_t gid; |
| 14 | __kernel_uid_t cuid; |
| 15 | __kernel_gid_t cgid; |
| 16 | __kernel_mode_t mode; |
| 17 | unsigned short seq; |
| 18 | }; |
| 19 | |
| 20 | /* Include the definition of ipc64_perm */ |
| 21 | #include <asm/ipcbuf.h> |
| 22 | |
| 23 | /* resource get request flags */ |
| 24 | #define IPC_CREAT 00001000 /* create if key is nonexistent */ |
| 25 | #define IPC_EXCL 00002000 /* fail if key exists */ |
| 26 | #define IPC_NOWAIT 00004000 /* return error on wait */ |
| 27 | |
| 28 | /* these fields are used by the DIPC package so the kernel as standard |
| 29 | should avoid using them if possible */ |
| 30 | |
| 31 | #define IPC_DIPC 00010000 /* make it distributed */ |
| 32 | #define IPC_OWN 00020000 /* this machine is the DIPC owner */ |
| 33 | |
| 34 | /* |
| 35 | * Control commands used with semctl, msgctl and shmctl |
| 36 | * see also specific commands in sem.h, msg.h and shm.h |
| 37 | */ |
| 38 | #define IPC_RMID 0 /* remove resource */ |
| 39 | #define IPC_SET 1 /* set ipc_perm options */ |
| 40 | #define IPC_STAT 2 /* get ipc_perm options */ |
| 41 | #define IPC_INFO 3 /* see ipcs */ |
| 42 | |
| 43 | /* |
| 44 | * Version flags for semctl, msgctl, and shmctl commands |
| 45 | * These are passed as bitflags or-ed with the actual command |
| 46 | */ |
| 47 | #define IPC_OLD 0 /* Old version (no 32-bit UID support on many |
| 48 | architectures) */ |
| 49 | #define IPC_64 0x0100 /* New version (support 32-bit UIDs, bigger |
| 50 | message sizes, etc. */ |
| 51 | |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 52 | /* |
| 53 | * These are used to wrap system calls. |
| 54 | * |
| 55 | * See architecture code for ugly details.. |
| 56 | */ |
| 57 | struct ipc_kludge { |
| 58 | struct msgbuf __user *msgp; |
| 59 | long msgtyp; |
| 60 | }; |
| 61 | |
| 62 | #define SEMOP 1 |
| 63 | #define SEMGET 2 |
| 64 | #define SEMCTL 3 |
| 65 | #define SEMTIMEDOP 4 |
| 66 | #define MSGSND 11 |
| 67 | #define MSGRCV 12 |
| 68 | #define MSGGET 13 |
| 69 | #define MSGCTL 14 |
| 70 | #define SHMAT 21 |
| 71 | #define SHMDT 22 |
| 72 | #define SHMGET 23 |
| 73 | #define SHMCTL 24 |
| 74 | |
| 75 | /* Used by the DIPC package, try and avoid reusing it */ |
| 76 | #define DIPC 25 |
| 77 | |
| 78 | #define IPCCALL(version,op) ((version)<<16 | (op)) |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #ifdef __KERNEL__ |
| 81 | |
Cedric Le Goater | b119f13 | 2006-10-04 02:15:19 -0700 | [diff] [blame] | 82 | #include <linux/kref.h> |
Robert P. J. Day | 0a3021f | 2007-07-15 23:39:57 -0700 | [diff] [blame] | 83 | #include <linux/spinlock.h> |
Cedric Le Goater | b119f13 | 2006-10-04 02:15:19 -0700 | [diff] [blame] | 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */ |
| 86 | |
| 87 | /* used by in-kernel data structures */ |
| 88 | struct kern_ipc_perm |
| 89 | { |
| 90 | spinlock_t lock; |
| 91 | int deleted; |
Nadia Derbey | 7ca7e56 | 2007-10-18 23:40:48 -0700 | [diff] [blame] | 92 | int id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | key_t key; |
| 94 | uid_t uid; |
| 95 | gid_t gid; |
| 96 | uid_t cuid; |
| 97 | gid_t cgid; |
| 98 | mode_t mode; |
| 99 | unsigned long seq; |
| 100 | void *security; |
| 101 | }; |
| 102 | |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 103 | struct ipc_ids; |
| 104 | struct ipc_namespace { |
| 105 | struct kref kref; |
| 106 | struct ipc_ids *ids[3]; |
| 107 | |
| 108 | int sem_ctls[4]; |
| 109 | int used_sems; |
| 110 | |
| 111 | int msg_ctlmax; |
| 112 | int msg_ctlmnb; |
| 113 | int msg_ctlmni; |
Kirill Korotaev | 3ac88a4 | 2007-10-18 23:40:56 -0700 | [diff] [blame] | 114 | atomic_t msg_bytes; |
| 115 | atomic_t msg_hdrs; |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 116 | |
| 117 | size_t shm_ctlmax; |
| 118 | size_t shm_ctlall; |
| 119 | int shm_ctlmni; |
| 120 | int shm_tot; |
| 121 | }; |
| 122 | |
| 123 | extern struct ipc_namespace init_ipc_ns; |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 124 | |
| 125 | #ifdef CONFIG_SYSVIPC |
| 126 | #define INIT_IPC_NS(ns) .ns = &init_ipc_ns, |
Cedric Le Goater | 7d69a1f | 2007-07-15 23:40:58 -0700 | [diff] [blame] | 127 | extern void free_ipc_ns(struct kref *kref); |
Badari Pulavarty | e3222c4 | 2007-05-08 00:25:21 -0700 | [diff] [blame] | 128 | extern struct ipc_namespace *copy_ipcs(unsigned long flags, |
| 129 | struct ipc_namespace *ns); |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 130 | #else |
| 131 | #define INIT_IPC_NS(ns) |
Badari Pulavarty | e3222c4 | 2007-05-08 00:25:21 -0700 | [diff] [blame] | 132 | static inline struct ipc_namespace *copy_ipcs(unsigned long flags, |
| 133 | struct ipc_namespace *ns) |
| 134 | { |
| 135 | return ns; |
| 136 | } |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 137 | #endif |
| 138 | |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 139 | static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns) |
| 140 | { |
Cedric Le Goater | 7d69a1f | 2007-07-15 23:40:58 -0700 | [diff] [blame] | 141 | #ifdef CONFIG_SYSVIPC |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 142 | if (ns) |
| 143 | kref_get(&ns->kref); |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 144 | #endif |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 145 | return ns; |
| 146 | } |
| 147 | |
| 148 | static inline void put_ipc_ns(struct ipc_namespace *ns) |
| 149 | { |
Cedric Le Goater | 7d69a1f | 2007-07-15 23:40:58 -0700 | [diff] [blame] | 150 | #ifdef CONFIG_SYSVIPC |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 151 | kref_put(&ns->kref, free_ipc_ns); |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 152 | #endif |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | #endif /* __KERNEL__ */ |
| 156 | |
| 157 | #endif /* _LINUX_IPC_H */ |