blob: 9badd322dcee809bcd398977ad511868be96cc6a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_SEM_H
3#define _LINUX_SEM_H
4
Arun Sharma600634972011-07-26 16:09:06 -07005#include <linux/atomic.h>
Manfred Spraul380af1b2008-07-25 01:48:06 -07006#include <linux/rcupdate.h>
Manfred Spraul31a7c472010-05-26 14:43:42 -07007#include <linux/cache.h>
Deepa Dinamanie54d02b2017-08-02 19:51:13 -07008#include <linux/time64.h>
David Howells607ca462012-10-13 10:46:48 +01009#include <uapi/linux/sem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080011struct task_struct;
12
Manfred Spraul1a233952017-07-12 14:34:38 -070013/* One semaphore structure for each semaphore in the system. */
14struct 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 Torvalds1da177e2005-04-16 15:20:36 -070032/* One sem_array data structure for each set of semaphores in the system. */
33struct sem_array {
Davidlohr Bueso60f3e002017-05-08 15:57:06 -070034 struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
Deepa Dinamanie54d02b2017-08-02 19:51:13 -070035 time64_t sem_ctime; /* create/last semctl() time */
Manfred Spraul1a82e9e2013-07-08 16:01:23 -070036 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 Spraul4daa28f2008-07-25 01:48:04 -070040 struct list_head list_id; /* undo requests on this array */
Manfred Spraulb97e8202009-12-15 16:47:32 -080041 int sem_nsems; /* no. of semaphores in array */
42 int complex_count; /* pending complex operations */
Manfred Spraul9de5ab82017-02-27 14:28:18 -080043 unsigned int use_global_lock;/* >0: global lock required */
Manfred Spraul1a233952017-07-12 14:34:38 -070044
45 struct sem sems[];
Kees Cook3859a272016-10-28 01:22:25 -070046} __randomize_layout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Manfred Spraulf567a182011-11-02 13:38:56 -070048#ifdef CONFIG_SYSVIPC
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050struct sysv_sem {
51 struct sem_undo_list *undo_list;
52};
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
55extern void exit_sem(struct task_struct *tsk);
56
57#else
Manfred Spraulf567a182011-11-02 13:38:56 -070058
59struct sysv_sem {
60 /* empty */
61};
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
64{
65 return 0;
66}
67
68static inline void exit_sem(struct task_struct *tsk)
69{
70 return;
71}
72#endif
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#endif /* _LINUX_SEM_H */