Annotation of sys/sys/sem.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: sem.h,v 1.19 2005/12/13 00:35:23 millert Exp $ */
2: /* $NetBSD: sem.h,v 1.8 1996/02/09 18:25:29 christos 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/cdefs.h>
14: #ifndef _SYS_IPC_H_
15: #include <sys/ipc.h>
16: #endif
17: #include <sys/queue.h>
18:
19: #if __BSD_VISIBLE
20:
21: /* sem-specific sysctl variables corresponding to members of struct seminfo */
22: #define KERN_SEMINFO_SEMMNI 1 /* int: # of semaphore identifiers */
23: #define KERN_SEMINFO_SEMMNS 2 /* int: # of semaphores in system */
24: #define KERN_SEMINFO_SEMMNU 3 /* int: # of undo structures in system */
25: #define KERN_SEMINFO_SEMMSL 4 /* int: max semaphores per id */
26: #define KERN_SEMINFO_SEMOPM 5 /* int: max operations per semop call */
27: #define KERN_SEMINFO_SEMUME 6 /* int: max undo entries per process */
28: #define KERN_SEMINFO_SEMUSZ 7 /* int: size in bytes of struct undo */
29: #define KERN_SEMINFO_SEMVMX 8 /* int: semaphore maximum value */
30: #define KERN_SEMINFO_SEMAEM 9 /* int: adjust on exit max value */
31: #define KERN_SEMINFO_MAXID 10 /* number of valid semaphore sysctls */
32:
33: #define CTL_KERN_SEMINFO_NAMES { \
34: { 0, 0 }, \
35: { "semmni", CTLTYPE_INT }, \
36: { "semmns", CTLTYPE_INT }, \
37: { "semmnu", CTLTYPE_INT }, \
38: { "semmsl", CTLTYPE_INT }, \
39: { "semopm", CTLTYPE_INT }, \
40: { "semume", CTLTYPE_INT }, \
41: { "semusz", CTLTYPE_INT }, \
42: { "semvmx", CTLTYPE_INT }, \
43: { "semaem", CTLTYPE_INT }, \
44: }
45:
46: #endif /* __BSD_VISIBLE */
47:
48: struct sem {
49: unsigned short semval; /* semaphore value */
50: pid_t sempid; /* pid of last operation */
51: unsigned short semncnt; /* # awaiting semval > cval */
52: unsigned short semzcnt; /* # awaiting semval = 0 */
53: };
54:
55: struct semid_ds {
56: struct ipc_perm sem_perm; /* operation permission struct */
57: struct sem *sem_base; /* pointer to first semaphore in set */
58: unsigned short sem_nsems; /* number of sems in set */
59: time_t sem_otime; /* last operation time */
60: long sem_pad1; /* SVABI/386 says I need this here */
61: time_t sem_ctime; /* last change time */
62: /* Times measured in secs since */
63: /* 00:00:00 GMT, Jan. 1, 1970 */
64: long sem_pad2; /* SVABI/386 says I need this here */
65: long sem_pad3[4]; /* SVABI/386 says I need this here */
66: };
67:
68: #ifdef _KERNEL
69: struct semid_ds23 {
70: struct ipc_perm23 sem_perm; /* operation permission struct */
71: struct sem *sem_base; /* pointer to first semaphore in set */
72: unsigned short sem_nsems; /* number of sems in set */
73: time_t sem_otime; /* last operation time */
74: long sem_pad1; /* SVABI/386 says I need this here */
75: time_t sem_ctime; /* last change time */
76: /* Times measured in secs since */
77: /* 00:00:00 GMT, Jan. 1, 1970 */
78: long sem_pad2; /* SVABI/386 says I need this here */
79: long sem_pad3[4]; /* SVABI/386 says I need this here */
80: };
81:
82: struct semid_ds35 {
83: struct ipc_perm35 sem_perm; /* operation permission struct */
84: struct sem *sem_base; /* pointer to first semaphore in set */
85: unsigned short sem_nsems; /* number of sems in set */
86: time_t sem_otime; /* last operation time */
87: long sem_pad1; /* SVABI/386 says I need this here */
88: time_t sem_ctime; /* last change time */
89: /* Times measured in secs since */
90: /* 00:00:00 GMT, Jan. 1, 1970 */
91: long sem_pad2; /* SVABI/386 says I need this here */
92: long sem_pad3[4]; /* SVABI/386 says I need this here */
93: };
94: #endif
95:
96: /*
97: * semop's sops parameter structure
98: */
99: struct sembuf {
100: unsigned short sem_num; /* semaphore # */
101: short sem_op; /* semaphore operation */
102: short sem_flg; /* operation flags */
103: };
104: #define SEM_UNDO 010000
105:
106: /*
107: * semctl's arg parameter structure
108: */
109: union semun {
110: int val; /* value for SETVAL */
111: struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
112: unsigned short *array; /* array for GETALL & SETALL */
113: };
114:
115: /*
116: * commands for semctl
117: */
118: #define GETNCNT 3 /* Return the value of semncnt {READ} */
119: #define GETPID 4 /* Return the value of sempid {READ} */
120: #define GETVAL 5 /* Return the value of semval {READ} */
121: #define GETALL 6 /* Return semvals into arg.array {READ} */
122: #define GETZCNT 7 /* Return the value of semzcnt {READ} */
123: #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
124: #define SETALL 9 /* Set semvals from arg.array {ALTER} */
125:
126:
127: /*
128: * Permissions
129: */
130: #define SEM_A 0200 /* alter permission */
131: #define SEM_R 0400 /* read permission */
132:
133:
134: #ifdef _KERNEL
135: /*
136: * Kernel implementation stuff
137: */
138: #define SEMVMX 32767 /* semaphore maximum value */
139: #define SEMAEM 16384 /* adjust on exit max value */
140:
141: /*
142: * Undo structure (one per process)
143: */
144: struct sem_undo {
145: SLIST_ENTRY(sem_undo) un_next; /* ptr to next active undo structure */
146: struct proc *un_proc; /* owner of this structure */
147: short un_cnt; /* # of active entries */
148: struct undo {
149: short un_adjval; /* adjust on exit values */
150: short un_num; /* semaphore # */
151: int un_id; /* semid */
152: } un_ent[1]; /* undo entries */
153: };
154:
155: /*
156: * semaphore info struct
157: */
158: struct seminfo {
159: int semmni, /* # of semaphore identifiers */
160: semmns, /* # of semaphores in system */
161: semmnu, /* # of undo structures in system */
162: semmsl, /* max # of semaphores per id */
163: semopm, /* max # of operations per semop call */
164: semume, /* max # of undo entries per process */
165: semusz, /* size in bytes of undo structure */
166: semvmx, /* semaphore maximum value */
167: semaem; /* adjust on exit max value */
168: };
169:
170: struct sem_sysctl_info {
171: struct seminfo seminfo;
172: struct semid_ds semids[1];
173: };
174:
175: extern struct seminfo seminfo;
176:
177: /*
178: * Configuration parameters
179: */
180: #ifndef SEMMNI
181: #define SEMMNI 10 /* # of semaphore identifiers */
182: #endif
183: #ifndef SEMMNS
184: #define SEMMNS 60 /* # of semaphores in system */
185: #endif
186: #ifndef SEMUME
187: #define SEMUME 10 /* max # of undo entries per process */
188: #endif
189: #ifndef SEMMNU
190: #define SEMMNU 30 /* # of undo structures in system */
191: #endif
192:
193: /* shouldn't need tuning */
194: #ifndef SEMMSL
195: #define SEMMSL SEMMNS /* max # of semaphores per id */
196: #endif
197: #ifndef SEMOPM
198: #define SEMOPM 100 /* max # of operations per semop call */
199: #endif
200:
201: /* actual size of an undo structure */
202: #define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME)
203:
204: extern struct semid_ds **sema; /* semaphore id list */
205:
206: #endif /* _KERNEL */
207:
208: #ifndef _KERNEL
209: __BEGIN_DECLS
210: int semctl(int, int, int, ...);
211: int __semctl(int, int, int, union semun *);
212: int semget(key_t, int, int);
213: int semop(int, struct sembuf *, size_t);
214: int semconfig(int);
215: __END_DECLS
216: #else
217: void seminit(void);
218: void semexit(struct proc *);
219: int sysctl_sysvsem(int *, u_int, void *, size_t *, void *, size_t);
220: int semctl1(struct proc *, int, int, int, union semun *, register_t *,
221: int (*)(const void *, void *, size_t),
222: int (*)(const void *, void *, size_t));
223: #endif /* !_KERNEL */
224:
225: #endif /* !_SEM_H_ */
CVSweb