1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1991 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #include <syscall.h> 33*0Sstevel@tonic-gate #include <varargs.h> 34*0Sstevel@tonic-gate #include <sys/types.h> 35*0Sstevel@tonic-gate #include <sys/ipc.h> 36*0Sstevel@tonic-gate #include <sys/shm.h> 37*0Sstevel@tonic-gate #include <sys/errno.h> 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate /* shmsys dispatch argument */ 41*0Sstevel@tonic-gate #define SHMAT 0 42*0Sstevel@tonic-gate #define SHMCTL 1 43*0Sstevel@tonic-gate #define SHMDT 2 44*0Sstevel@tonic-gate #define SHMGET 3 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate struct shmid_sv { 47*0Sstevel@tonic-gate struct ipc_perm shm_perm; 48*0Sstevel@tonic-gate int shm_segsz; 49*0Sstevel@tonic-gate struct anon_map *shm_amp; 50*0Sstevel@tonic-gate unsigned short shm_lkcnt; 51*0Sstevel@tonic-gate char pad[2]; 52*0Sstevel@tonic-gate short shm_lpid; 53*0Sstevel@tonic-gate short shm_cpid; 54*0Sstevel@tonic-gate unsigned short shm_nattch; 55*0Sstevel@tonic-gate unsigned short shm_cnattch; 56*0Sstevel@tonic-gate time_t shm_atime; 57*0Sstevel@tonic-gate time_t shm_dtime; 58*0Sstevel@tonic-gate time_t shm_ctime; 59*0Sstevel@tonic-gate }; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate char * 63*0Sstevel@tonic-gate shmat(shmid, shmaddr, shmflg) 64*0Sstevel@tonic-gate int shmid; 65*0Sstevel@tonic-gate char *shmaddr; 66*0Sstevel@tonic-gate int shmflg; 67*0Sstevel@tonic-gate { 68*0Sstevel@tonic-gate return ((char *)_syscall(SYS_shmsys, SHMAT, shmid, shmaddr, shmflg)); 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate shmctl(shmid, cmd, buf) 72*0Sstevel@tonic-gate int shmid, cmd; 73*0Sstevel@tonic-gate struct shmid_ds *buf; 74*0Sstevel@tonic-gate { 75*0Sstevel@tonic-gate struct shmid_sv n_buf; 76*0Sstevel@tonic-gate int ret; 77*0Sstevel@tonic-gate extern int errno; 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate if (buf == (struct shmid_ds *)-1) { 80*0Sstevel@tonic-gate errno = EFAULT; 81*0Sstevel@tonic-gate return(-1); 82*0Sstevel@tonic-gate } 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate if (buf == 0) { 85*0Sstevel@tonic-gate ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, 0); 86*0Sstevel@tonic-gate } else { 87*0Sstevel@tonic-gate n_buf.shm_perm = buf->shm_perm; 88*0Sstevel@tonic-gate n_buf.shm_segsz = buf->shm_segsz; 89*0Sstevel@tonic-gate n_buf.shm_amp = buf->shm_amp; 90*0Sstevel@tonic-gate n_buf.shm_lpid = buf->shm_lpid; 91*0Sstevel@tonic-gate n_buf.shm_cpid = buf->shm_cpid; 92*0Sstevel@tonic-gate n_buf.shm_nattch = buf->shm_nattch; 93*0Sstevel@tonic-gate n_buf.shm_atime = buf->shm_atime; 94*0Sstevel@tonic-gate n_buf.shm_dtime = buf->shm_dtime; 95*0Sstevel@tonic-gate n_buf.shm_ctime = buf->shm_ctime; 96*0Sstevel@tonic-gate n_buf.shm_lkcnt = 0; 97*0Sstevel@tonic-gate n_buf.shm_cnattch = 0; 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, &n_buf); 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate buf->shm_perm = n_buf.shm_perm; 102*0Sstevel@tonic-gate buf->shm_segsz = n_buf.shm_segsz; 103*0Sstevel@tonic-gate buf->shm_amp = n_buf.shm_amp; 104*0Sstevel@tonic-gate buf->shm_lpid = n_buf.shm_lpid; 105*0Sstevel@tonic-gate buf->shm_cpid = n_buf.shm_cpid; 106*0Sstevel@tonic-gate buf->shm_nattch = n_buf.shm_nattch; 107*0Sstevel@tonic-gate buf->shm_atime = n_buf.shm_atime; 108*0Sstevel@tonic-gate buf->shm_dtime = n_buf.shm_dtime; 109*0Sstevel@tonic-gate buf->shm_ctime = n_buf.shm_ctime; 110*0Sstevel@tonic-gate } 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate return(ret); 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate shmdt(shmaddr) 116*0Sstevel@tonic-gate char *shmaddr; 117*0Sstevel@tonic-gate { 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate return (_syscall(SYS_shmsys, SHMDT, shmaddr)); 120*0Sstevel@tonic-gate } 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate shmget(key, size, shmflg) 123*0Sstevel@tonic-gate key_t key; 124*0Sstevel@tonic-gate int size, shmflg; 125*0Sstevel@tonic-gate { 126*0Sstevel@tonic-gate return (_syscall(SYS_shmsys, SHMGET, key, size, shmflg)); 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate shmsys(sysnum, va_alist) 130*0Sstevel@tonic-gate int sysnum; 131*0Sstevel@tonic-gate va_dcl 132*0Sstevel@tonic-gate { 133*0Sstevel@tonic-gate va_list ap; 134*0Sstevel@tonic-gate int shmid, shmflg, cmd, size; 135*0Sstevel@tonic-gate char *shmaddr; 136*0Sstevel@tonic-gate struct shmid_ds *buf; 137*0Sstevel@tonic-gate key_t key; 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate va_start(ap); 140*0Sstevel@tonic-gate switch (sysnum) { 141*0Sstevel@tonic-gate case SHMAT: 142*0Sstevel@tonic-gate shmid=va_arg(ap, int); 143*0Sstevel@tonic-gate shmaddr=va_arg(ap, char *); 144*0Sstevel@tonic-gate shmflg=va_arg(ap, int); 145*0Sstevel@tonic-gate return((int)shmat(shmid, shmaddr, shmflg)); 146*0Sstevel@tonic-gate case SHMCTL: 147*0Sstevel@tonic-gate shmid=va_arg(ap, int); 148*0Sstevel@tonic-gate cmd=va_arg(ap, int); 149*0Sstevel@tonic-gate buf=va_arg(ap, struct shmid_ds *); 150*0Sstevel@tonic-gate return(shmctl(shmid, cmd, buf)); 151*0Sstevel@tonic-gate case SHMDT: 152*0Sstevel@tonic-gate shmaddr=va_arg(ap, char *); 153*0Sstevel@tonic-gate return(shmdt(shmaddr)); 154*0Sstevel@tonic-gate case SHMGET: 155*0Sstevel@tonic-gate key=va_arg(ap, key_t); 156*0Sstevel@tonic-gate size=va_arg(ap, int); 157*0Sstevel@tonic-gate shmflg=va_arg(ap, int); 158*0Sstevel@tonic-gate return(shmget(key, size, shmflg)); 159*0Sstevel@tonic-gate } 160*0Sstevel@tonic-gate } 161