Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_SEM_H |
| 2 | #define _LINUX_SEM_H |
| 3 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 4 | #include <linux/atomic.h> |
Manfred Spraul | 380af1b | 2008-07-25 01:48:06 -0700 | [diff] [blame] | 5 | #include <linux/rcupdate.h> |
Manfred Spraul | 31a7c47 | 2010-05-26 14:43:42 -0700 | [diff] [blame] | 6 | #include <linux/cache.h> |
Deepa Dinamani | e54d02b | 2017-08-02 19:51:13 -0700 | [diff] [blame] | 7 | #include <linux/time64.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 8 | #include <uapi/linux/sem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Tim Schmielau | 8c65b4a | 2005-11-07 00:59:43 -0800 | [diff] [blame] | 10 | struct task_struct; |
| 11 | |
Manfred Spraul | 1a23395 | 2017-07-12 14:34:38 -0700 | [diff] [blame] | 12 | /* One semaphore structure for each semaphore in the system. */ |
| 13 | struct sem { |
| 14 | int semval; /* current value */ |
| 15 | /* |
| 16 | * PID of the process that last modified the semaphore. For |
| 17 | * Linux, specifically these are: |
| 18 | * - semop |
| 19 | * - semctl, via SETVAL and SETALL. |
| 20 | * - at task exit when performing undo adjustments (see exit_sem). |
| 21 | */ |
| 22 | int sempid; |
| 23 | spinlock_t lock; /* spinlock for fine-grained semtimedop */ |
| 24 | struct list_head pending_alter; /* pending single-sop operations */ |
| 25 | /* that alter the semaphore */ |
| 26 | struct list_head pending_const; /* pending single-sop operations */ |
| 27 | /* that do not alter the semaphore*/ |
| 28 | time_t sem_otime; /* candidate for sem_otime */ |
| 29 | } ____cacheline_aligned_in_smp; |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* One sem_array data structure for each set of semaphores in the system. */ |
| 32 | struct sem_array { |
Davidlohr Bueso | 60f3e00 | 2017-05-08 15:57:06 -0700 | [diff] [blame] | 33 | struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */ |
Deepa Dinamani | e54d02b | 2017-08-02 19:51:13 -0700 | [diff] [blame] | 34 | time64_t sem_ctime; /* create/last semctl() time */ |
Manfred Spraul | 1a82e9e | 2013-07-08 16:01:23 -0700 | [diff] [blame] | 35 | struct list_head pending_alter; /* pending operations */ |
| 36 | /* that alter the array */ |
| 37 | struct list_head pending_const; /* pending complex operations */ |
| 38 | /* that do not alter semvals */ |
Manfred Spraul | 4daa28f | 2008-07-25 01:48:04 -0700 | [diff] [blame] | 39 | struct list_head list_id; /* undo requests on this array */ |
Manfred Spraul | b97e820 | 2009-12-15 16:47:32 -0800 | [diff] [blame] | 40 | int sem_nsems; /* no. of semaphores in array */ |
| 41 | int complex_count; /* pending complex operations */ |
Manfred Spraul | 9de5ab8 | 2017-02-27 14:28:18 -0800 | [diff] [blame] | 42 | unsigned int use_global_lock;/* >0: global lock required */ |
Manfred Spraul | 1a23395 | 2017-07-12 14:34:38 -0700 | [diff] [blame] | 43 | |
| 44 | struct sem sems[]; |
Kees Cook | 3859a27 | 2016-10-28 01:22:25 -0700 | [diff] [blame] | 45 | } __randomize_layout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Manfred Spraul | f567a18 | 2011-11-02 13:38:56 -0700 | [diff] [blame] | 47 | #ifdef CONFIG_SYSVIPC |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | struct sysv_sem { |
| 50 | struct sem_undo_list *undo_list; |
| 51 | }; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk); |
| 54 | extern void exit_sem(struct task_struct *tsk); |
| 55 | |
| 56 | #else |
Manfred Spraul | f567a18 | 2011-11-02 13:38:56 -0700 | [diff] [blame] | 57 | |
| 58 | struct sysv_sem { |
| 59 | /* empty */ |
| 60 | }; |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk) |
| 63 | { |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static inline void exit_sem(struct task_struct *tsk) |
| 68 | { |
| 69 | return; |
| 70 | } |
| 71 | #endif |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #endif /* _LINUX_SEM_H */ |