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 1991 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" /* from S5R2 1.3 */ 31 32 #include <syscall.h> 33 #include <varargs.h> 34 #include <sys/types.h> 35 #include <sys/ipc.h> 36 #include <sys/shm.h> 37 #include <sys/errno.h> 38 39 40 /* shmsys dispatch argument */ 41 #define SHMAT 0 42 #define SHMCTL 1 43 #define SHMDT 2 44 #define SHMGET 3 45 46 struct shmid_sv { 47 struct ipc_perm shm_perm; 48 int shm_segsz; 49 struct anon_map *shm_amp; 50 unsigned short shm_lkcnt; 51 char pad[2]; 52 short shm_lpid; 53 short shm_cpid; 54 unsigned short shm_nattch; 55 unsigned short shm_cnattch; 56 time_t shm_atime; 57 time_t shm_dtime; 58 time_t shm_ctime; 59 }; 60 61 62 char * 63 shmat(shmid, shmaddr, shmflg) 64 int shmid; 65 char *shmaddr; 66 int shmflg; 67 { 68 return ((char *)_syscall(SYS_shmsys, SHMAT, shmid, shmaddr, shmflg)); 69 } 70 71 shmctl(shmid, cmd, buf) 72 int shmid, cmd; 73 struct shmid_ds *buf; 74 { 75 struct shmid_sv n_buf; 76 int ret; 77 extern int errno; 78 79 if (buf == (struct shmid_ds *)-1) { 80 errno = EFAULT; 81 return(-1); 82 } 83 84 if (buf == 0) { 85 ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, 0); 86 } else { 87 n_buf.shm_perm = buf->shm_perm; 88 n_buf.shm_segsz = buf->shm_segsz; 89 n_buf.shm_amp = buf->shm_amp; 90 n_buf.shm_lpid = buf->shm_lpid; 91 n_buf.shm_cpid = buf->shm_cpid; 92 n_buf.shm_nattch = buf->shm_nattch; 93 n_buf.shm_atime = buf->shm_atime; 94 n_buf.shm_dtime = buf->shm_dtime; 95 n_buf.shm_ctime = buf->shm_ctime; 96 n_buf.shm_lkcnt = 0; 97 n_buf.shm_cnattch = 0; 98 99 ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, &n_buf); 100 101 buf->shm_perm = n_buf.shm_perm; 102 buf->shm_segsz = n_buf.shm_segsz; 103 buf->shm_amp = n_buf.shm_amp; 104 buf->shm_lpid = n_buf.shm_lpid; 105 buf->shm_cpid = n_buf.shm_cpid; 106 buf->shm_nattch = n_buf.shm_nattch; 107 buf->shm_atime = n_buf.shm_atime; 108 buf->shm_dtime = n_buf.shm_dtime; 109 buf->shm_ctime = n_buf.shm_ctime; 110 } 111 112 return(ret); 113 } 114 115 shmdt(shmaddr) 116 char *shmaddr; 117 { 118 119 return (_syscall(SYS_shmsys, SHMDT, shmaddr)); 120 } 121 122 shmget(key, size, shmflg) 123 key_t key; 124 int size, shmflg; 125 { 126 return (_syscall(SYS_shmsys, SHMGET, key, size, shmflg)); 127 } 128 129 shmsys(sysnum, va_alist) 130 int sysnum; 131 va_dcl 132 { 133 va_list ap; 134 int shmid, shmflg, cmd, size; 135 char *shmaddr; 136 struct shmid_ds *buf; 137 key_t key; 138 139 va_start(ap); 140 switch (sysnum) { 141 case SHMAT: 142 shmid=va_arg(ap, int); 143 shmaddr=va_arg(ap, char *); 144 shmflg=va_arg(ap, int); 145 return((int)shmat(shmid, shmaddr, shmflg)); 146 case SHMCTL: 147 shmid=va_arg(ap, int); 148 cmd=va_arg(ap, int); 149 buf=va_arg(ap, struct shmid_ds *); 150 return(shmctl(shmid, cmd, buf)); 151 case SHMDT: 152 shmaddr=va_arg(ap, char *); 153 return(shmdt(shmaddr)); 154 case SHMGET: 155 key=va_arg(ap, key_t); 156 size=va_arg(ap, int); 157 shmflg=va_arg(ap, int); 158 return(shmget(key, size, shmflg)); 159 } 160 } 161