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 5*3224Sraf * Common Development and Distribution License (the "License"). 6*3224Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*3224Sraf 220Sstevel@tonic-gate /* 23*3224Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 27*3224Sraf /* Copyright (c) 1984 AT&T */ 28*3224Sraf /* All Rights Reserved */ 290Sstevel@tonic-gate 30722Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 32*3224Sraf #include <sys/syscall.h> 33*3224Sraf #include <stdarg.h> 34*3224Sraf #include <sys/types.h> 35*3224Sraf #include <sys/ipc.h> 36*3224Sraf #include <sys/sem.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate /* semsys dispatch argument */ 39*3224Sraf #define SEMCTL 0 40*3224Sraf #define SEMGET 1 41*3224Sraf #define SEMOP 2 420Sstevel@tonic-gate 43722Smuffin int 44722Smuffin 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*3224Sraf return (_syscall(SYS_semsys, SEMCTL, 56*3224Sraf semid, semnum, cmd, arg->val)); 570Sstevel@tonic-gate 580Sstevel@tonic-gate case IPC_RMID: 590Sstevel@tonic-gate cmd += 10; 600Sstevel@tonic-gate /* fall-through */ 610Sstevel@tonic-gate default: 62*3224Sraf return (_syscall(SYS_semsys, SEMCTL, 63*3224Sraf semid, semnum, cmd, 0)); 640Sstevel@tonic-gate } 650Sstevel@tonic-gate } 660Sstevel@tonic-gate 67722Smuffin int 68722Smuffin semget(key_t key, int nsems, int semflg) 690Sstevel@tonic-gate { 70722Smuffin return (_syscall(SYS_semsys, SEMGET, key, nsems, semflg)); 710Sstevel@tonic-gate } 720Sstevel@tonic-gate 73722Smuffin int 74722Smuffin semop(int semid, struct sembuf *sops, int nsops) 750Sstevel@tonic-gate { 76722Smuffin return (_syscall(SYS_semsys, SEMOP, semid, sops, nsops)); 770Sstevel@tonic-gate } 780Sstevel@tonic-gate 79722Smuffin int 80722Smuffin semsys(int sysnum, ...) 810Sstevel@tonic-gate { 820Sstevel@tonic-gate va_list ap; 830Sstevel@tonic-gate int semid, cmd; 840Sstevel@tonic-gate int semnum, val; 850Sstevel@tonic-gate union semun arg; 860Sstevel@tonic-gate key_t key; 870Sstevel@tonic-gate int nsems, semflg; 880Sstevel@tonic-gate struct sembuf *sops; 890Sstevel@tonic-gate int nsops; 900Sstevel@tonic-gate 91722Smuffin va_start(ap, sysnum); 920Sstevel@tonic-gate switch (sysnum) { 930Sstevel@tonic-gate case SEMCTL: 94*3224Sraf semid = va_arg(ap, int); 95*3224Sraf semnum = va_arg(ap, int); 96*3224Sraf cmd = va_arg(ap, int); 97*3224Sraf val = va_arg(ap, int); 980Sstevel@tonic-gate if ((cmd == IPC_STAT) || (cmd == IPC_SET) || (cmd == IPC_RMID)) 990Sstevel@tonic-gate cmd += 10; 100722Smuffin va_end(ap); 101722Smuffin return (_syscall(SYS_semsys, SEMCTL, semid, semnum, cmd, val)); 1020Sstevel@tonic-gate case SEMGET: 103*3224Sraf key = va_arg(ap, key_t); 104*3224Sraf nsems = va_arg(ap, int); 105*3224Sraf semflg = va_arg(ap, int); 106722Smuffin va_end(ap); 107722Smuffin return (semget(key, nsems, semflg)); 1080Sstevel@tonic-gate case SEMOP: 109*3224Sraf semid = va_arg(ap, int); 110*3224Sraf sops = va_arg(ap, struct sembuf *); 111*3224Sraf nsops = va_arg(ap, int); 112722Smuffin va_end(ap); 113722Smuffin return (semop(semid, sops, nsops)); 1140Sstevel@tonic-gate } 115722Smuffin va_end(ap); 116722Smuffin return (-1); 1170Sstevel@tonic-gate } 118