sem.h 5.1 KB

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