sem.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. struct task_struct;
  70. /* One semaphore structure for each semaphore in the system. */
  71. struct sem {
  72. int semval; /* current value */
  73. int sempid; /* pid of last operation */
  74. };
  75. /* One sem_array data structure for each set of semaphores in the system. */
  76. struct sem_array {
  77. struct kern_ipc_perm sem_perm; /* permissions .. see ipc.h */
  78. int sem_id;
  79. time_t sem_otime; /* last semop time */
  80. time_t sem_ctime; /* last change time */
  81. struct sem *sem_base; /* ptr to first semaphore in array */
  82. struct sem_queue *sem_pending; /* pending operations to be processed */
  83. struct sem_queue **sem_pending_last; /* last pending operation */
  84. struct sem_undo *undo; /* undo requests on this array */
  85. unsigned long sem_nsems; /* no. of semaphores in array */
  86. };
  87. /* One queue for each sleeping process in the system. */
  88. struct sem_queue {
  89. struct sem_queue * next; /* next entry in the queue */
  90. struct sem_queue ** prev; /* previous entry in the queue, *(q->prev) == q */
  91. struct task_struct* sleeper; /* this process */
  92. struct sem_undo * undo; /* undo structure */
  93. int pid; /* process id of requesting process */
  94. int status; /* completion status of operation */
  95. struct sem_array * sma; /* semaphore array for operations */
  96. int id; /* internal sem id */
  97. struct sembuf * sops; /* array of pending operations */
  98. int nsops; /* number of operations */
  99. int alter; /* does the operation alter the array? */
  100. };
  101. /* Each task has a list of undo requests. They are executed automatically
  102. * when the process exits.
  103. */
  104. struct sem_undo {
  105. struct sem_undo * proc_next; /* next entry on this process */
  106. struct sem_undo * id_next; /* next entry on this semaphore set */
  107. int semid; /* semaphore set identifier */
  108. short * semadj; /* array of adjustments, one per semaphore */
  109. };
  110. /* sem_undo_list controls shared access to the list of sem_undo structures
  111. * that may be shared among all a CLONE_SYSVSEM task group.
  112. */
  113. struct sem_undo_list {
  114. atomic_t refcnt;
  115. spinlock_t lock;
  116. struct sem_undo *proc_list;
  117. };
  118. struct sysv_sem {
  119. struct sem_undo_list *undo_list;
  120. };
  121. #ifdef CONFIG_SYSVIPC
  122. extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
  123. extern void exit_sem(struct task_struct *tsk);
  124. #else
  125. static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
  126. {
  127. return 0;
  128. }
  129. static inline void exit_sem(struct task_struct *tsk)
  130. {
  131. return;
  132. }
  133. #endif
  134. #endif /* __KERNEL__ */
  135. #endif /* _LINUX_SEM_H */