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