1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984 AT&T */ 28 /* All Rights Reserved */ 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <syscall.h> 33 #include <stdarg.h> 34 #include <sys/types.h> 35 #include <sys/ipc.h> 36 #include <sys/sem.h> 37 38 /* semsys dispatch argument */ 39 #define SEMCTL 0 40 #define SEMGET 1 41 #define SEMOP 2 42 43 int 44 semctl(int semid, int semnum, int cmd, union semun *arg) 45 { 46 switch (cmd) { 47 48 case IPC_STAT: 49 case IPC_SET: 50 cmd += 10; 51 /* fall-through */ 52 case SETVAL: 53 case GETALL: 54 case SETALL: 55 return (_syscall(SYS_semsys,SEMCTL,semid,semnum,cmd,arg->val)); 56 57 case IPC_RMID: 58 cmd += 10; 59 /* fall-through */ 60 default: 61 return (_syscall(SYS_semsys,SEMCTL,semid,semnum,cmd,0)); 62 } 63 } 64 65 int 66 semget(key_t key, int nsems, int semflg) 67 { 68 return (_syscall(SYS_semsys, SEMGET, key, nsems, semflg)); 69 } 70 71 int 72 semop(int semid, struct sembuf *sops, int nsops) 73 { 74 return (_syscall(SYS_semsys, SEMOP, semid, sops, nsops)); 75 } 76 77 int 78 semsys(int sysnum, ...) 79 { 80 va_list ap; 81 int semid, cmd; 82 int semnum, val; 83 union semun arg; 84 key_t key; 85 int nsems, semflg; 86 struct sembuf *sops; 87 int nsops; 88 89 va_start(ap, sysnum); 90 switch (sysnum) { 91 case SEMCTL: 92 semid=va_arg(ap, int); 93 semnum=va_arg(ap, int); 94 cmd=va_arg(ap, int); 95 val=va_arg(ap, int); 96 if ((cmd == IPC_STAT) || (cmd == IPC_SET) || (cmd == IPC_RMID)) 97 cmd += 10; 98 va_end(ap); 99 return (_syscall(SYS_semsys, SEMCTL, semid, semnum, cmd, val)); 100 case SEMGET: 101 key=va_arg(ap, key_t); 102 nsems=va_arg(ap, int); 103 semflg=va_arg(ap, int); 104 va_end(ap); 105 return (semget(key, nsems, semflg)); 106 case SEMOP: 107 semid=va_arg(ap, int); 108 sops=va_arg(ap, struct sembuf *); 109 nsops=va_arg(ap, int); 110 va_end(ap); 111 return (semop(semid, sops, nsops)); 112 } 113 va_end(ap); 114 return (-1); 115 } 116