blob: 10d6b226afc5aebdda9f3a65c72550e1af54d3c5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SEM_H
2#define _LINUX_SEM_H
3
4#include <linux/ipc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
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 */
23struct 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. */
38struct 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. */
45union 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
53struct 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__
Arun Sharma600634972011-07-26 16:09:06 -070080#include <linux/atomic.h>
Manfred Spraul380af1b2008-07-25 01:48:06 -070081#include <linux/rcupdate.h>
Manfred Spraul31a7c472010-05-26 14:43:42 -070082#include <linux/cache.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080084struct task_struct;
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086/* One sem_array data structure for each set of semaphores in the system. */
87struct sem_array {
Manfred Spraul31a7c472010-05-26 14:43:42 -070088 struct kern_ipc_perm ____cacheline_aligned_in_smp
89 sem_perm; /* permissions .. see ipc.h */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 time_t sem_otime; /* last semop time */
91 time_t sem_ctime; /* last change time */
92 struct sem *sem_base; /* ptr to first semaphore in array */
Manfred Spraula1193f82008-07-25 01:48:06 -070093 struct list_head sem_pending; /* pending operations to be processed */
Manfred Spraul4daa28f2008-07-25 01:48:04 -070094 struct list_head list_id; /* undo requests on this array */
Manfred Spraulb97e8202009-12-15 16:47:32 -080095 int sem_nsems; /* no. of semaphores in array */
96 int complex_count; /* pending complex operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
Manfred Spraulf567a182011-11-02 13:38:56 -070099#ifdef CONFIG_SYSVIPC
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101struct sysv_sem {
102 struct sem_undo_list *undo_list;
103};
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
106extern void exit_sem(struct task_struct *tsk);
107
108#else
Manfred Spraulf567a182011-11-02 13:38:56 -0700109
110struct sysv_sem {
111 /* empty */
112};
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
115{
116 return 0;
117}
118
119static inline void exit_sem(struct task_struct *tsk)
120{
121 return;
122}
123#endif
124
125#endif /* __KERNEL__ */
126
127#endif /* _LINUX_SEM_H */