blob: 3fd3ddd5f0d9e4bb885367f8de6fde50dc00918d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 */
9struct 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 Goaterb119f132006-10-04 02:15:19 -070054#include <linux/kref.h>
Robert P. J. Day0a3021f2007-07-15 23:39:57 -070055#include <linux/spinlock.h>
Cedric Le Goaterb119f132006-10-04 02:15:19 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define IPCMNI 32768 /* <= MAX_INT limit for ipc arrays (including sysctl changes) */
58
59/* used by in-kernel data structures */
60struct kern_ipc_perm
61{
62 spinlock_t lock;
63 int deleted;
64 key_t key;
65 uid_t uid;
66 gid_t gid;
67 uid_t cuid;
68 gid_t cgid;
69 mode_t mode;
70 unsigned long seq;
71 void *security;
72};
73
Kirill Korotaev25b21cb2006-10-02 02:18:19 -070074struct ipc_ids;
75struct ipc_namespace {
76 struct kref kref;
77 struct ipc_ids *ids[3];
78
79 int sem_ctls[4];
80 int used_sems;
81
82 int msg_ctlmax;
83 int msg_ctlmnb;
84 int msg_ctlmni;
85
86 size_t shm_ctlmax;
87 size_t shm_ctlall;
88 int shm_ctlmni;
89 int shm_tot;
90};
91
92extern struct ipc_namespace init_ipc_ns;
Kirill Korotaev73ea4132006-10-02 02:18:20 -070093
94#ifdef CONFIG_SYSVIPC
95#define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
Cedric Le Goater7d69a1f2007-07-15 23:40:58 -070096extern void free_ipc_ns(struct kref *kref);
Badari Pulavartye3222c42007-05-08 00:25:21 -070097extern struct ipc_namespace *copy_ipcs(unsigned long flags,
98 struct ipc_namespace *ns);
Kirill Korotaev73ea4132006-10-02 02:18:20 -070099#else
100#define INIT_IPC_NS(ns)
Badari Pulavartye3222c42007-05-08 00:25:21 -0700101static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
102 struct ipc_namespace *ns)
103{
104 return ns;
105}
Kirill Korotaev73ea4132006-10-02 02:18:20 -0700106#endif
107
Kirill Korotaev25b21cb2006-10-02 02:18:19 -0700108static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
109{
Cedric Le Goater7d69a1f2007-07-15 23:40:58 -0700110#ifdef CONFIG_SYSVIPC
Kirill Korotaev25b21cb2006-10-02 02:18:19 -0700111 if (ns)
112 kref_get(&ns->kref);
Kirill Korotaev73ea4132006-10-02 02:18:20 -0700113#endif
Kirill Korotaev25b21cb2006-10-02 02:18:19 -0700114 return ns;
115}
116
117static inline void put_ipc_ns(struct ipc_namespace *ns)
118{
Cedric Le Goater7d69a1f2007-07-15 23:40:58 -0700119#ifdef CONFIG_SYSVIPC
Kirill Korotaev25b21cb2006-10-02 02:18:19 -0700120 kref_put(&ns->kref, free_ipc_ns);
Kirill Korotaev73ea4132006-10-02 02:18:20 -0700121#endif
Kirill Korotaev25b21cb2006-10-02 02:18:19 -0700122}
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#endif /* __KERNEL__ */
125
126#endif /* _LINUX_IPC_H */