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 <varargs.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 /*VARARGS3*/ 44 semctl(semid, semnum, cmd, arg) 45 int semid, cmd; 46 int semnum; 47 union semun arg; 48 { 49 switch (cmd) { 50 51 case IPC_STAT: 52 case IPC_SET: 53 cmd += 10; 54 /* fall-through */ 55 case SETVAL: 56 case GETALL: 57 case SETALL: 58 return(_syscall(SYS_semsys,SEMCTL,semid,semnum,cmd,arg.val)); 59 60 case IPC_RMID: 61 cmd += 10; 62 /* fall-through */ 63 default: 64 return(_syscall(SYS_semsys,SEMCTL,semid,semnum,cmd,0)); 65 } 66 } 67 68 semget(key, nsems, semflg) 69 key_t key; 70 int nsems, semflg; 71 { 72 return(_syscall(SYS_semsys, SEMGET, key, nsems, semflg)); 73 } 74 75 semop(semid, sops, nsops) 76 int semid; 77 struct sembuf *sops; 78 int nsops; 79 { 80 return(_syscall(SYS_semsys, SEMOP, semid, sops, nsops)); 81 } 82 83 semsys(sysnum, va_alist) 84 int sysnum; 85 va_dcl 86 { 87 va_list ap; 88 int semid, cmd; 89 int semnum, val; 90 union semun arg; 91 key_t key; 92 int nsems, semflg; 93 struct sembuf *sops; 94 int nsops; 95 96 va_start(ap); 97 switch (sysnum) { 98 case SEMCTL: 99 semid=va_arg(ap, int); 100 semnum=va_arg(ap, int); 101 cmd=va_arg(ap, int); 102 val=va_arg(ap, int); 103 if ((cmd == IPC_STAT) || (cmd == IPC_SET) || (cmd == IPC_RMID)) 104 cmd += 10; 105 return(_syscall(SYS_semsys, SEMCTL, semid, semnum, cmd, val)); 106 case SEMGET: 107 key=va_arg(ap, key_t); 108 nsems=va_arg(ap, int); 109 semflg=va_arg(ap, int); 110 return(semget(key, nsems, semflg)); 111 case SEMOP: 112 semid=va_arg(ap, int); 113 sops=va_arg(ap, struct sembuf *); 114 nsops=va_arg(ap, int); 115 return(semop(semid, sops, nsops)); 116 } 117 } 118 119