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 | |
| 52 | #ifdef __KERNEL__ |
| 53 | |
Cedric Le Goater | b119f13 | 2006-10-04 02:15:19 -0700 | [diff] [blame] | 54 | #include <linux/kref.h> |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */ |
| 57 | |
| 58 | /* used by in-kernel data structures */ |
| 59 | struct kern_ipc_perm |
| 60 | { |
| 61 | spinlock_t lock; |
| 62 | int deleted; |
| 63 | key_t key; |
| 64 | uid_t uid; |
| 65 | gid_t gid; |
| 66 | uid_t cuid; |
| 67 | gid_t cgid; |
| 68 | mode_t mode; |
| 69 | unsigned long seq; |
| 70 | void *security; |
| 71 | }; |
| 72 | |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 73 | struct ipc_ids; |
| 74 | struct ipc_namespace { |
| 75 | struct kref kref; |
| 76 | struct ipc_ids *ids[3]; |
| 77 | |
| 78 | int sem_ctls[4]; |
| 79 | int used_sems; |
| 80 | |
| 81 | int msg_ctlmax; |
| 82 | int msg_ctlmnb; |
| 83 | int msg_ctlmni; |
| 84 | |
| 85 | size_t shm_ctlmax; |
| 86 | size_t shm_ctlall; |
| 87 | int shm_ctlmni; |
| 88 | int shm_tot; |
| 89 | }; |
| 90 | |
| 91 | extern struct ipc_namespace init_ipc_ns; |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 92 | |
| 93 | #ifdef CONFIG_SYSVIPC |
| 94 | #define INIT_IPC_NS(ns) .ns = &init_ipc_ns, |
Serge E. Hallyn | a28d193 | 2007-03-26 21:32:31 -0800 | [diff] [blame] | 95 | extern int copy_ipcs(unsigned long flags, struct task_struct *tsk); |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 96 | #else |
| 97 | #define INIT_IPC_NS(ns) |
Serge E. Hallyn | a28d193 | 2007-03-26 21:32:31 -0800 | [diff] [blame] | 98 | static inline int copy_ipcs(unsigned long flags, struct task_struct *tsk) |
| 99 | { return 0; } |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 100 | #endif |
| 101 | |
| 102 | #ifdef CONFIG_IPC_NS |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 103 | extern void free_ipc_ns(struct kref *kref); |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 104 | extern int unshare_ipcs(unsigned long flags, struct ipc_namespace **ns); |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 105 | #endif |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 106 | |
| 107 | static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns) |
| 108 | { |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 109 | #ifdef CONFIG_IPC_NS |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 110 | if (ns) |
| 111 | kref_get(&ns->kref); |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 112 | #endif |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 113 | return ns; |
| 114 | } |
| 115 | |
| 116 | static inline void put_ipc_ns(struct ipc_namespace *ns) |
| 117 | { |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 118 | #ifdef CONFIG_IPC_NS |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 119 | kref_put(&ns->kref, free_ipc_ns); |
Kirill Korotaev | 73ea413 | 2006-10-02 02:18:20 -0700 | [diff] [blame] | 120 | #endif |
Kirill Korotaev | 25b21cb | 2006-10-02 02:18:19 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #endif /* __KERNEL__ */ |
| 124 | |
| 125 | #endif /* _LINUX_IPC_H */ |
| 126 | |
| 127 | |