10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* Copyright (c) 1984 AT&T */ 280Sstevel@tonic-gate /* All Rights Reserved */ 290Sstevel@tonic-gate 30*722Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <syscall.h> 33*722Smuffin #include <stdarg.h> 340Sstevel@tonic-gate #include <sys/types.h> 350Sstevel@tonic-gate #include <sys/ipc.h> 360Sstevel@tonic-gate #include <sys/sem.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* semsys dispatch argument */ 390Sstevel@tonic-gate #define SEMCTL 0 400Sstevel@tonic-gate #define SEMGET 1 410Sstevel@tonic-gate #define SEMOP 2 420Sstevel@tonic-gate 43*722Smuffin int 44*722Smuffin semctl(int semid, int semnum, int cmd, union semun *arg) 450Sstevel@tonic-gate { 460Sstevel@tonic-gate switch (cmd) { 470Sstevel@tonic-gate 480Sstevel@tonic-gate case IPC_STAT: 490Sstevel@tonic-gate case IPC_SET: 500Sstevel@tonic-gate cmd += 10; 510Sstevel@tonic-gate /* fall-through */ 520Sstevel@tonic-gate case SETVAL: 530Sstevel@tonic-gate case GETALL: 540Sstevel@tonic-gate case SETALL: 55*722Smuffin return (_syscall(SYS_semsys,SEMCTL,semid,semnum,cmd,arg->val)); 560Sstevel@tonic-gate 570Sstevel@tonic-gate case IPC_RMID: 580Sstevel@tonic-gate cmd += 10; 590Sstevel@tonic-gate /* fall-through */ 600Sstevel@tonic-gate default: 61*722Smuffin return (_syscall(SYS_semsys,SEMCTL,semid,semnum,cmd,0)); 620Sstevel@tonic-gate } 630Sstevel@tonic-gate } 640Sstevel@tonic-gate 65*722Smuffin int 66*722Smuffin semget(key_t key, int nsems, int semflg) 670Sstevel@tonic-gate { 68*722Smuffin return (_syscall(SYS_semsys, SEMGET, key, nsems, semflg)); 690Sstevel@tonic-gate } 700Sstevel@tonic-gate 71*722Smuffin int 72*722Smuffin semop(int semid, struct sembuf *sops, int nsops) 730Sstevel@tonic-gate { 74*722Smuffin return (_syscall(SYS_semsys, SEMOP, semid, sops, nsops)); 750Sstevel@tonic-gate } 760Sstevel@tonic-gate 77*722Smuffin int 78*722Smuffin semsys(int sysnum, ...) 790Sstevel@tonic-gate { 800Sstevel@tonic-gate va_list ap; 810Sstevel@tonic-gate int semid, cmd; 820Sstevel@tonic-gate int semnum, val; 830Sstevel@tonic-gate union semun arg; 840Sstevel@tonic-gate key_t key; 850Sstevel@tonic-gate int nsems, semflg; 860Sstevel@tonic-gate struct sembuf *sops; 870Sstevel@tonic-gate int nsops; 880Sstevel@tonic-gate 89*722Smuffin va_start(ap, sysnum); 900Sstevel@tonic-gate switch (sysnum) { 910Sstevel@tonic-gate case SEMCTL: 920Sstevel@tonic-gate semid=va_arg(ap, int); 930Sstevel@tonic-gate semnum=va_arg(ap, int); 940Sstevel@tonic-gate cmd=va_arg(ap, int); 950Sstevel@tonic-gate val=va_arg(ap, int); 960Sstevel@tonic-gate if ((cmd == IPC_STAT) || (cmd == IPC_SET) || (cmd == IPC_RMID)) 970Sstevel@tonic-gate cmd += 10; 98*722Smuffin va_end(ap); 99*722Smuffin return (_syscall(SYS_semsys, SEMCTL, semid, semnum, cmd, val)); 1000Sstevel@tonic-gate case SEMGET: 1010Sstevel@tonic-gate key=va_arg(ap, key_t); 1020Sstevel@tonic-gate nsems=va_arg(ap, int); 1030Sstevel@tonic-gate semflg=va_arg(ap, int); 104*722Smuffin va_end(ap); 105*722Smuffin return (semget(key, nsems, semflg)); 1060Sstevel@tonic-gate case SEMOP: 1070Sstevel@tonic-gate semid=va_arg(ap, int); 1080Sstevel@tonic-gate sops=va_arg(ap, struct sembuf *); 1090Sstevel@tonic-gate nsops=va_arg(ap, int); 110*722Smuffin va_end(ap); 111*722Smuffin return (semop(semid, sops, nsops)); 1120Sstevel@tonic-gate } 113*722Smuffin va_end(ap); 114*722Smuffin return (-1); 1150Sstevel@tonic-gate } 116