Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_SEM_H |
| 2 | #define _LINUX_SEM_H |
| 3 | |
| 4 | #include <linux/ipc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
| 6 | /* semop flags */ |
| 7 | #define SEM_UNDO 0x1000 /* undo the operation on exit */ |
| 8 | |
| 9 | /* semctl Command Definitions. */ |
| 10 | #define GETPID 11 /* get sempid */ |
| 11 | #define GETVAL 12 /* get semval */ |
| 12 | #define GETALL 13 /* get all semval's */ |
| 13 | #define GETNCNT 14 /* get semncnt */ |
| 14 | #define GETZCNT 15 /* get semzcnt */ |
| 15 | #define SETVAL 16 /* set semval */ |
| 16 | #define SETALL 17 /* set all semval's */ |
| 17 | |
| 18 | /* ipcs ctl cmds */ |
| 19 | #define SEM_STAT 18 |
| 20 | #define SEM_INFO 19 |
| 21 | |
| 22 | /* Obsolete, used only for backwards compatibility and libc5 compiles */ |
| 23 | struct semid_ds { |
| 24 | struct ipc_perm sem_perm; /* permissions .. see ipc.h */ |
| 25 | __kernel_time_t sem_otime; /* last semop time */ |
| 26 | __kernel_time_t sem_ctime; /* last change time */ |
| 27 | struct sem *sem_base; /* ptr to first semaphore in array */ |
| 28 | struct sem_queue *sem_pending; /* pending operations to be processed */ |
| 29 | struct sem_queue **sem_pending_last; /* last pending operation */ |
| 30 | struct sem_undo *undo; /* undo requests on this array */ |
| 31 | unsigned short sem_nsems; /* no. of semaphores in array */ |
| 32 | }; |
| 33 | |
| 34 | /* Include the definition of semid64_ds */ |
| 35 | #include <asm/sembuf.h> |
| 36 | |
| 37 | /* semop system calls takes an array of these. */ |
| 38 | struct sembuf { |
| 39 | unsigned short sem_num; /* semaphore index in array */ |
| 40 | short sem_op; /* semaphore operation */ |
| 41 | short sem_flg; /* operation flags */ |
| 42 | }; |
| 43 | |
| 44 | /* arg for semctl system calls. */ |
| 45 | union semun { |
| 46 | int val; /* value for SETVAL */ |
| 47 | struct semid_ds __user *buf; /* buffer for IPC_STAT & IPC_SET */ |
| 48 | unsigned short __user *array; /* array for GETALL & SETALL */ |
| 49 | struct seminfo __user *__buf; /* buffer for IPC_INFO */ |
| 50 | void __user *__pad; |
| 51 | }; |
| 52 | |
| 53 | struct seminfo { |
| 54 | int semmap; |
| 55 | int semmni; |
| 56 | int semmns; |
| 57 | int semmnu; |
| 58 | int semmsl; |
| 59 | int semopm; |
| 60 | int semume; |
| 61 | int semusz; |
| 62 | int semvmx; |
| 63 | int semaem; |
| 64 | }; |
| 65 | |
| 66 | #define SEMMNI 128 /* <= IPCMNI max # of semaphore identifiers */ |
| 67 | #define SEMMSL 250 /* <= 8 000 max num of semaphores per id */ |
| 68 | #define SEMMNS (SEMMNI*SEMMSL) /* <= INT_MAX max # of semaphores in system */ |
| 69 | #define SEMOPM 32 /* <= 1 000 max num of ops per semop call */ |
| 70 | #define SEMVMX 32767 /* <= 32767 semaphore maximum value */ |
| 71 | #define SEMAEM SEMVMX /* adjust on exit max value */ |
| 72 | |
| 73 | /* unused */ |
| 74 | #define SEMUME SEMOPM /* max num of undo entries per process */ |
| 75 | #define SEMMNU SEMMNS /* num of undo structures system wide */ |
| 76 | #define SEMMAP SEMMNS /* # of entries in semaphore map */ |
| 77 | #define SEMUSZ 20 /* sizeof struct sem_undo */ |
| 78 | |
| 79 | #ifdef __KERNEL__ |
David Woodhouse | 8ffbc75 | 2006-04-25 14:55:13 +0100 | [diff] [blame] | 80 | #include <asm/atomic.h> |
Manfred Spraul | 380af1b | 2008-07-25 01:48:06 -0700 | [diff] [blame] | 81 | #include <linux/rcupdate.h> |
Manfred Spraul | 31a7c47 | 2010-05-26 14:43:42 -0700 | [diff] [blame] | 82 | #include <linux/cache.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Tim Schmielau | 8c65b4a | 2005-11-07 00:59:43 -0800 | [diff] [blame] | 84 | struct task_struct; |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* One semaphore structure for each semaphore in the system. */ |
| 87 | struct sem { |
| 88 | int semval; /* current value */ |
| 89 | int sempid; /* pid of last operation */ |
Manfred Spraul | b97e820 | 2009-12-15 16:47:32 -0800 | [diff] [blame] | 90 | struct list_head sem_pending; /* pending single-sop operations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /* One sem_array data structure for each set of semaphores in the system. */ |
| 94 | struct sem_array { |
Manfred Spraul | 31a7c47 | 2010-05-26 14:43:42 -0700 | [diff] [blame] | 95 | struct kern_ipc_perm ____cacheline_aligned_in_smp |
| 96 | sem_perm; /* permissions .. see ipc.h */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | time_t sem_otime; /* last semop time */ |
| 98 | time_t sem_ctime; /* last change time */ |
| 99 | struct sem *sem_base; /* ptr to first semaphore in array */ |
Manfred Spraul | a1193f8 | 2008-07-25 01:48:06 -0700 | [diff] [blame] | 100 | struct list_head sem_pending; /* pending operations to be processed */ |
Manfred Spraul | 4daa28f | 2008-07-25 01:48:04 -0700 | [diff] [blame] | 101 | struct list_head list_id; /* undo requests on this array */ |
Manfred Spraul | b97e820 | 2009-12-15 16:47:32 -0800 | [diff] [blame] | 102 | int sem_nsems; /* no. of semaphores in array */ |
| 103 | int complex_count; /* pending complex operations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | /* One queue for each sleeping process in the system. */ |
| 107 | struct sem_queue { |
Manfred Spraul | b97e820 | 2009-12-15 16:47:32 -0800 | [diff] [blame] | 108 | struct list_head simple_list; /* queue of pending operations */ |
Manfred Spraul | a1193f8 | 2008-07-25 01:48:06 -0700 | [diff] [blame] | 109 | struct list_head list; /* queue of pending operations */ |
| 110 | struct task_struct *sleeper; /* this process */ |
| 111 | struct sem_undo *undo; /* undo structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | int pid; /* process id of requesting process */ |
| 113 | int status; /* completion status of operation */ |
Manfred Spraul | a1193f8 | 2008-07-25 01:48:06 -0700 | [diff] [blame] | 114 | struct sembuf *sops; /* array of pending operations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | int nsops; /* number of operations */ |
| 116 | int alter; /* does the operation alter the array? */ |
| 117 | }; |
| 118 | |
| 119 | /* Each task has a list of undo requests. They are executed automatically |
| 120 | * when the process exits. |
| 121 | */ |
| 122 | struct sem_undo { |
Manfred Spraul | 380af1b | 2008-07-25 01:48:06 -0700 | [diff] [blame] | 123 | struct list_head list_proc; /* per-process list: all undos from one process. */ |
| 124 | /* rcu protected */ |
| 125 | struct rcu_head rcu; /* rcu struct for sem_undo() */ |
| 126 | struct sem_undo_list *ulp; /* sem_undo_list for the process */ |
Manfred Spraul | 4daa28f | 2008-07-25 01:48:04 -0700 | [diff] [blame] | 127 | struct list_head list_id; /* per semaphore array list: all undos for one array */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | int semid; /* semaphore set identifier */ |
| 129 | short * semadj; /* array of adjustments, one per semaphore */ |
| 130 | }; |
| 131 | |
| 132 | /* sem_undo_list controls shared access to the list of sem_undo structures |
| 133 | * that may be shared among all a CLONE_SYSVSEM task group. |
| 134 | */ |
| 135 | struct sem_undo_list { |
Manfred Spraul | 4daa28f | 2008-07-25 01:48:04 -0700 | [diff] [blame] | 136 | atomic_t refcnt; |
| 137 | spinlock_t lock; |
| 138 | struct list_head list_proc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | struct sysv_sem { |
| 142 | struct sem_undo_list *undo_list; |
| 143 | }; |
| 144 | |
| 145 | #ifdef CONFIG_SYSVIPC |
| 146 | |
| 147 | extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk); |
| 148 | extern void exit_sem(struct task_struct *tsk); |
| 149 | |
| 150 | #else |
| 151 | static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk) |
| 152 | { |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static inline void exit_sem(struct task_struct *tsk) |
| 157 | { |
| 158 | return; |
| 159 | } |
| 160 | #endif |
| 161 | |
| 162 | #endif /* __KERNEL__ */ |
| 163 | |
| 164 | #endif /* _LINUX_SEM_H */ |