sem.h 4.9 KB

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