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