1 /* $FreeBSD$ */ 2 /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ 3 4 /* 5 * SVID compatible sem.h file 6 * 7 * Author: Daniel Boulet 8 */ 9 10 #ifndef _SYS_SEM_H_ 11 #define _SYS_SEM_H_ 12 13 #include <sys/ipc.h> 14 15 #ifndef _PID_T_DECLARED 16 typedef __pid_t pid_t; 17 #define _PID_T_DECLARED 18 #endif 19 20 #ifndef _SIZE_T_DECLARED 21 typedef __size_t size_t; 22 #define _SIZE_T_DECLARED 23 #endif 24 25 #ifndef _TIME_T_DECLARED 26 typedef __time_t time_t; 27 #define _TIME_T_DECLARED 28 #endif 29 30 struct sem; 31 32 struct semid_ds { 33 struct ipc_perm sem_perm; /* operation permission struct */ 34 struct sem *sem_base; /* pointer to first semaphore in set */ 35 unsigned short sem_nsems; /* number of sems in set */ 36 time_t sem_otime; /* last operation time */ 37 long sem_pad1; /* SVABI/386 says I need this here */ 38 time_t sem_ctime; /* last change time */ 39 /* Times measured in secs since */ 40 /* 00:00:00 GMT, Jan. 1, 1970 */ 41 long sem_pad2; /* SVABI/386 says I need this here */ 42 long sem_pad3[4]; /* SVABI/386 says I need this here */ 43 }; 44 45 /* 46 * semop's sops parameter structure 47 */ 48 struct sembuf { 49 unsigned short sem_num; /* semaphore # */ 50 short sem_op; /* semaphore operation */ 51 short sem_flg; /* operation flags */ 52 }; 53 #define SEM_UNDO 010000 54 55 /* 56 * semctl's arg parameter structure 57 */ 58 union semun { 59 int val; /* value for SETVAL */ 60 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 61 unsigned short *array; /* array for GETALL & SETALL */ 62 }; 63 64 /* 65 * commands for semctl 66 */ 67 #define GETNCNT 3 /* Return the value of semncnt {READ} */ 68 #define GETPID 4 /* Return the value of sempid {READ} */ 69 #define GETVAL 5 /* Return the value of semval {READ} */ 70 #define GETALL 6 /* Return semvals into arg.array {READ} */ 71 #define GETZCNT 7 /* Return the value of semzcnt {READ} */ 72 #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ 73 #define SETALL 9 /* Set semvals from arg.array {ALTER} */ 74 #define SEM_STAT 10 /* Like IPC_STAT but treats semid as sema-index */ 75 #define SEM_INFO 11 /* Like IPC_INFO but treats semid as sema-index */ 76 77 /* 78 * Permissions 79 */ 80 #define SEM_A IPC_W /* alter permission */ 81 #define SEM_R IPC_R /* read permission */ 82 83 #ifdef _KERNEL 84 85 /* 86 * semaphore info struct 87 */ 88 struct seminfo { 89 int semmap, /* # of entries in semaphore map */ 90 semmni, /* # of semaphore identifiers */ 91 semmns, /* # of semaphores in system */ 92 semmnu, /* # of undo structures in system */ 93 semmsl, /* max # of semaphores per id */ 94 semopm, /* max # of operations per semop call */ 95 semume, /* max # of undo entries per process */ 96 semusz, /* size in bytes of undo structure */ 97 semvmx, /* semaphore maximum value */ 98 semaem; /* adjust on exit max value */ 99 }; 100 extern struct seminfo seminfo; 101 102 /* 103 * Kernel wrapper for the user-level structure 104 */ 105 struct semid_kernel { 106 struct semid_ds u; 107 struct label *label; /* MAC framework label */ 108 }; 109 110 /* internal "mode" bits */ 111 #define SEM_ALLOC 01000 /* semaphore is allocated */ 112 #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ 113 114 /* 115 * Process sem_undo vectors at proc exit. 116 */ 117 void semexit(struct proc *p); 118 119 #else /* ! _KERNEL */ 120 121 __BEGIN_DECLS 122 int semsys(int, ...); 123 int semctl(int, int, int, ...); 124 int semget(key_t, int, int); 125 int semop(int, struct sembuf *, size_t); 126 __END_DECLS 127 128 #endif /* !_KERNEL */ 129 130 #endif /* !_SYS_SEM_H_ */ 131