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 1991 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/shm.h>
37*722Smuffin #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
440Sstevel@tonic-gate #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 };
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 
620Sstevel@tonic-gate char *
63*722Smuffin 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 
68*722Smuffin int
69*722Smuffin 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;
76*722Smuffin 		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 
107*722Smuffin 	return (ret);
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate 
110*722Smuffin int
111*722Smuffin shmdt(char *shmaddr)
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	return (_syscall(SYS_shmsys, SHMDT, shmaddr));
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate 
117*722Smuffin int
118*722Smuffin shmget(key_t key, int size, int shmflg)
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate 	return (_syscall(SYS_shmsys, SHMGET, key, size, shmflg));
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate 
123*722Smuffin int
124*722Smuffin shmsys(int sysnum, ...)
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate         va_list ap;
1270Sstevel@tonic-gate 	int shmid, shmflg, cmd, size;
1280Sstevel@tonic-gate 	char *shmaddr;
1290Sstevel@tonic-gate 	struct shmid_ds *buf;
1300Sstevel@tonic-gate 	key_t key;
1310Sstevel@tonic-gate 
132*722Smuffin 	va_start(ap, sysnum);
1330Sstevel@tonic-gate 	switch (sysnum) {
1340Sstevel@tonic-gate 	case SHMAT:
1350Sstevel@tonic-gate 			shmid=va_arg(ap, int);
1360Sstevel@tonic-gate 			shmaddr=va_arg(ap, char *);
1370Sstevel@tonic-gate 			shmflg=va_arg(ap, int);
138*722Smuffin 			va_end(ap);
139*722Smuffin 			return ((int)shmat(shmid, shmaddr, shmflg));
1400Sstevel@tonic-gate 	case SHMCTL:
1410Sstevel@tonic-gate 			shmid=va_arg(ap, int);
1420Sstevel@tonic-gate 			cmd=va_arg(ap, int);
1430Sstevel@tonic-gate 			buf=va_arg(ap, struct shmid_ds *);
144*722Smuffin 			va_end(ap);
145*722Smuffin 			return (shmctl(shmid, cmd, buf));
1460Sstevel@tonic-gate 	case SHMDT:
1470Sstevel@tonic-gate 			shmaddr=va_arg(ap, char *);
148*722Smuffin 			va_end(ap);
149*722Smuffin 			return (shmdt(shmaddr));
1500Sstevel@tonic-gate 	case SHMGET:
1510Sstevel@tonic-gate 			key=va_arg(ap, key_t);
1520Sstevel@tonic-gate 			size=va_arg(ap, int);
1530Sstevel@tonic-gate 			shmflg=va_arg(ap, int);
154*722Smuffin 			va_end(ap);
155*722Smuffin 			return (shmget(key, size, shmflg));
1560Sstevel@tonic-gate 	}
157*722Smuffin 	va_end(ap);
158*722Smuffin 	return (-1);
1590Sstevel@tonic-gate }
160