sem.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <linux/atomic.h>
  69. #include <linux/rcupdate.h>
  70. #include <linux/cache.h>
  71. struct task_struct;
  72. /* One sem_array data structure for each set of semaphores in the system. */
  73. struct sem_array {
  74. struct kern_ipc_perm ____cacheline_aligned_in_smp
  75. sem_perm; /* permissions .. see ipc.h */
  76. time_t sem_otime; /* last semop time */
  77. time_t sem_ctime; /* last change time */
  78. struct sem *sem_base; /* ptr to first semaphore in array */
  79. struct list_head sem_pending; /* pending operations to be processed */
  80. struct list_head list_id; /* undo requests on this array */
  81. int sem_nsems; /* no. of semaphores in array */
  82. int complex_count; /* pending complex operations */
  83. };
  84. #ifdef CONFIG_SYSVIPC
  85. struct sysv_sem {
  86. struct sem_undo_list *undo_list;
  87. };
  88. extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
  89. extern void exit_sem(struct task_struct *tsk);
  90. #else
  91. struct sysv_sem {
  92. /* empty */
  93. };
  94. static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
  95. {
  96. return 0;
  97. }
  98. static inline void exit_sem(struct task_struct *tsk)
  99. {
  100. return;
  101. }
  102. #endif
  103. #endif /* __KERNEL__ */
  104. #endif /* _LINUX_SEM_H */