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/shm.h> 37*3224Sraf #include <errno.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* shmsys dispatch argument */ 410Sstevel@tonic-gate #define SHMAT 0 420Sstevel@tonic-gate #define SHMCTL 1 430Sstevel@tonic-gate #define SHMDT 2 44*3224Sraf #define SHMGET 3 450Sstevel@tonic-gate 460Sstevel@tonic-gate struct shmid_sv { 470Sstevel@tonic-gate struct ipc_perm shm_perm; 480Sstevel@tonic-gate int shm_segsz; 490Sstevel@tonic-gate struct anon_map *shm_amp; 500Sstevel@tonic-gate unsigned short shm_lkcnt; 510Sstevel@tonic-gate char pad[2]; 520Sstevel@tonic-gate short shm_lpid; 530Sstevel@tonic-gate short shm_cpid; 540Sstevel@tonic-gate unsigned short shm_nattch; 550Sstevel@tonic-gate unsigned short shm_cnattch; 560Sstevel@tonic-gate time_t shm_atime; 570Sstevel@tonic-gate time_t shm_dtime; 580Sstevel@tonic-gate time_t shm_ctime; 590Sstevel@tonic-gate }; 60*3224Sraf 610Sstevel@tonic-gate 620Sstevel@tonic-gate char * 63722Smuffin shmat(int shmid, char *shmaddr, int shmflg) 640Sstevel@tonic-gate { 650Sstevel@tonic-gate return ((char *)_syscall(SYS_shmsys, SHMAT, shmid, shmaddr, shmflg)); 660Sstevel@tonic-gate } 670Sstevel@tonic-gate 68722Smuffin int 69722Smuffin shmctl(int shmid, int cmd, struct shmid_ds *buf) 700Sstevel@tonic-gate { 710Sstevel@tonic-gate struct shmid_sv n_buf; 720Sstevel@tonic-gate int ret; 730Sstevel@tonic-gate 740Sstevel@tonic-gate if (buf == (struct shmid_ds *)-1) { 750Sstevel@tonic-gate errno = EFAULT; 76722Smuffin return (-1); 770Sstevel@tonic-gate } 780Sstevel@tonic-gate 790Sstevel@tonic-gate if (buf == 0) { 800Sstevel@tonic-gate ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, 0); 810Sstevel@tonic-gate } else { 820Sstevel@tonic-gate n_buf.shm_perm = buf->shm_perm; 830Sstevel@tonic-gate n_buf.shm_segsz = buf->shm_segsz; 840Sstevel@tonic-gate n_buf.shm_amp = buf->shm_amp; 850Sstevel@tonic-gate n_buf.shm_lpid = buf->shm_lpid; 860Sstevel@tonic-gate n_buf.shm_cpid = buf->shm_cpid; 870Sstevel@tonic-gate n_buf.shm_nattch = buf->shm_nattch; 880Sstevel@tonic-gate n_buf.shm_atime = buf->shm_atime; 890Sstevel@tonic-gate n_buf.shm_dtime = buf->shm_dtime; 900Sstevel@tonic-gate n_buf.shm_ctime = buf->shm_ctime; 910Sstevel@tonic-gate n_buf.shm_lkcnt = 0; 920Sstevel@tonic-gate n_buf.shm_cnattch = 0; 930Sstevel@tonic-gate 940Sstevel@tonic-gate ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, &n_buf); 950Sstevel@tonic-gate 960Sstevel@tonic-gate buf->shm_perm = n_buf.shm_perm; 970Sstevel@tonic-gate buf->shm_segsz = n_buf.shm_segsz; 980Sstevel@tonic-gate buf->shm_amp = n_buf.shm_amp; 990Sstevel@tonic-gate buf->shm_lpid = n_buf.shm_lpid; 1000Sstevel@tonic-gate buf->shm_cpid = n_buf.shm_cpid; 1010Sstevel@tonic-gate buf->shm_nattch = n_buf.shm_nattch; 1020Sstevel@tonic-gate buf->shm_atime = n_buf.shm_atime; 1030Sstevel@tonic-gate buf->shm_dtime = n_buf.shm_dtime; 1040Sstevel@tonic-gate buf->shm_ctime = n_buf.shm_ctime; 1050Sstevel@tonic-gate } 1060Sstevel@tonic-gate 107722Smuffin return (ret); 1080Sstevel@tonic-gate } 1090Sstevel@tonic-gate 110722Smuffin int 111722Smuffin shmdt(char *shmaddr) 1120Sstevel@tonic-gate { 1130Sstevel@tonic-gate return (_syscall(SYS_shmsys, SHMDT, shmaddr)); 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate 116722Smuffin int 117722Smuffin shmget(key_t key, int size, int shmflg) 1180Sstevel@tonic-gate { 1190Sstevel@tonic-gate return (_syscall(SYS_shmsys, SHMGET, key, size, shmflg)); 1200Sstevel@tonic-gate } 1210Sstevel@tonic-gate 122722Smuffin int 123722Smuffin shmsys(int sysnum, ...) 1240Sstevel@tonic-gate { 125*3224Sraf va_list ap; 1260Sstevel@tonic-gate int shmid, shmflg, cmd, size; 1270Sstevel@tonic-gate char *shmaddr; 1280Sstevel@tonic-gate struct shmid_ds *buf; 1290Sstevel@tonic-gate key_t key; 1300Sstevel@tonic-gate 131722Smuffin va_start(ap, sysnum); 1320Sstevel@tonic-gate switch (sysnum) { 1330Sstevel@tonic-gate case SHMAT: 134*3224Sraf shmid = va_arg(ap, int); 135*3224Sraf shmaddr = va_arg(ap, char *); 136*3224Sraf shmflg = va_arg(ap, int); 137*3224Sraf va_end(ap); 138*3224Sraf return ((int)shmat(shmid, shmaddr, shmflg)); 1390Sstevel@tonic-gate case SHMCTL: 140*3224Sraf shmid = va_arg(ap, int); 141*3224Sraf cmd = va_arg(ap, int); 142*3224Sraf buf = va_arg(ap, struct shmid_ds *); 143*3224Sraf va_end(ap); 144*3224Sraf return (shmctl(shmid, cmd, buf)); 1450Sstevel@tonic-gate case SHMDT: 146*3224Sraf shmaddr = va_arg(ap, char *); 147*3224Sraf va_end(ap); 148*3224Sraf return (shmdt(shmaddr)); 1490Sstevel@tonic-gate case SHMGET: 150*3224Sraf key = va_arg(ap, key_t); 151*3224Sraf size = va_arg(ap, int); 152*3224Sraf shmflg = va_arg(ap, int); 153*3224Sraf va_end(ap); 154*3224Sraf return (shmget(key, size, shmflg)); 1550Sstevel@tonic-gate } 156722Smuffin va_end(ap); 157722Smuffin return (-1); 1580Sstevel@tonic-gate } 159