17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*d4188195Sraf * Common Development and Distribution License (the "License"). 6*d4188195Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*d4188195Sraf 227c478bd9Sstevel@tonic-gate /* 23*d4188195Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 305d54f3d8Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 32*d4188195Sraf #include <sys/syscall.h> 335d54f3d8Smuffin #include <stdarg.h> 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/ipc.h> 367c478bd9Sstevel@tonic-gate #include <sys/shm.h> 375d54f3d8Smuffin #include <errno.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* shmsys dispatch argument */ 417c478bd9Sstevel@tonic-gate #define SHMAT 0 427c478bd9Sstevel@tonic-gate #define SHMCTL 1 437c478bd9Sstevel@tonic-gate #define SHMDT 2 447c478bd9Sstevel@tonic-gate #define SHMGET 3 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate struct shmid_sv { 477c478bd9Sstevel@tonic-gate struct ipc_perm shm_perm; 487c478bd9Sstevel@tonic-gate int shm_segsz; 497c478bd9Sstevel@tonic-gate struct anon_map *shm_amp; 507c478bd9Sstevel@tonic-gate unsigned short shm_lkcnt; 517c478bd9Sstevel@tonic-gate char pad[2]; 527c478bd9Sstevel@tonic-gate short shm_lpid; 537c478bd9Sstevel@tonic-gate short shm_cpid; 547c478bd9Sstevel@tonic-gate unsigned short shm_nattch; 557c478bd9Sstevel@tonic-gate unsigned short shm_cnattch; 567c478bd9Sstevel@tonic-gate time_t shm_atime; 577c478bd9Sstevel@tonic-gate time_t shm_dtime; 587c478bd9Sstevel@tonic-gate time_t shm_ctime; 597c478bd9Sstevel@tonic-gate }; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate char * 635d54f3d8Smuffin shmat(int shmid, char *shmaddr, int shmflg) 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate return ((char *)_syscall(SYS_shmsys, SHMAT, shmid, shmaddr, shmflg)); 667c478bd9Sstevel@tonic-gate } 677c478bd9Sstevel@tonic-gate 685d54f3d8Smuffin int 695d54f3d8Smuffin shmctl(int shmid, int cmd, struct shmid_ds *buf) 707c478bd9Sstevel@tonic-gate { 717c478bd9Sstevel@tonic-gate struct shmid_sv n_buf; 727c478bd9Sstevel@tonic-gate int ret; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate if (buf == (struct shmid_ds *)-1) { 757c478bd9Sstevel@tonic-gate errno = EFAULT; 767c478bd9Sstevel@tonic-gate return (-1); 777c478bd9Sstevel@tonic-gate } 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate if (buf == 0) { 807c478bd9Sstevel@tonic-gate ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, 0); 817c478bd9Sstevel@tonic-gate } else { 827c478bd9Sstevel@tonic-gate n_buf.shm_perm = buf->shm_perm; 837c478bd9Sstevel@tonic-gate n_buf.shm_segsz = buf->shm_segsz; 847c478bd9Sstevel@tonic-gate n_buf.shm_amp = buf->shm_amp; 857c478bd9Sstevel@tonic-gate n_buf.shm_lpid = buf->shm_lpid; 867c478bd9Sstevel@tonic-gate n_buf.shm_cpid = buf->shm_cpid; 877c478bd9Sstevel@tonic-gate n_buf.shm_nattch = buf->shm_nattch; 887c478bd9Sstevel@tonic-gate n_buf.shm_atime = buf->shm_atime; 897c478bd9Sstevel@tonic-gate n_buf.shm_dtime = buf->shm_dtime; 907c478bd9Sstevel@tonic-gate n_buf.shm_ctime = buf->shm_ctime; 917c478bd9Sstevel@tonic-gate n_buf.shm_lkcnt = 0; 927c478bd9Sstevel@tonic-gate n_buf.shm_cnattch = 0; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, &n_buf); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate buf->shm_perm = n_buf.shm_perm; 977c478bd9Sstevel@tonic-gate buf->shm_segsz = n_buf.shm_segsz; 987c478bd9Sstevel@tonic-gate buf->shm_amp = n_buf.shm_amp; 997c478bd9Sstevel@tonic-gate buf->shm_lpid = n_buf.shm_lpid; 1007c478bd9Sstevel@tonic-gate buf->shm_cpid = n_buf.shm_cpid; 1017c478bd9Sstevel@tonic-gate buf->shm_nattch = n_buf.shm_nattch; 1027c478bd9Sstevel@tonic-gate buf->shm_atime = n_buf.shm_atime; 1037c478bd9Sstevel@tonic-gate buf->shm_dtime = n_buf.shm_dtime; 1047c478bd9Sstevel@tonic-gate buf->shm_ctime = n_buf.shm_ctime; 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate return (ret); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1105d54f3d8Smuffin int 1115d54f3d8Smuffin shmdt(char *shmaddr) 1127c478bd9Sstevel@tonic-gate { 1137c478bd9Sstevel@tonic-gate return (_syscall(SYS_shmsys, SHMDT, shmaddr)); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate 1165d54f3d8Smuffin int 1175d54f3d8Smuffin shmget(key_t key, int size, int shmflg) 1187c478bd9Sstevel@tonic-gate { 1197c478bd9Sstevel@tonic-gate return (_syscall(SYS_shmsys, SHMGET, key, size, shmflg)); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate 1225d54f3d8Smuffin int 1235d54f3d8Smuffin shmsys(int sysnum, ...) 1247c478bd9Sstevel@tonic-gate { 1257c478bd9Sstevel@tonic-gate va_list ap; 1267c478bd9Sstevel@tonic-gate int shmid, shmflg, cmd, size; 1277c478bd9Sstevel@tonic-gate char *shmaddr; 1287c478bd9Sstevel@tonic-gate struct shmid_ds *buf; 1297c478bd9Sstevel@tonic-gate key_t key; 1307c478bd9Sstevel@tonic-gate 1315d54f3d8Smuffin va_start(ap, sysnum); 1327c478bd9Sstevel@tonic-gate switch (sysnum) { 1337c478bd9Sstevel@tonic-gate case SHMAT: 1347c478bd9Sstevel@tonic-gate shmid = va_arg(ap, int); 1357c478bd9Sstevel@tonic-gate shmaddr = va_arg(ap, char *); 1367c478bd9Sstevel@tonic-gate shmflg = va_arg(ap, int); 1375d54f3d8Smuffin va_end(ap); 1387c478bd9Sstevel@tonic-gate return ((int)shmat(shmid, shmaddr, shmflg)); 1397c478bd9Sstevel@tonic-gate case SHMCTL: 1407c478bd9Sstevel@tonic-gate shmid = va_arg(ap, int); 1417c478bd9Sstevel@tonic-gate cmd = va_arg(ap, int); 1427c478bd9Sstevel@tonic-gate buf = va_arg(ap, struct shmid_ds *); 1435d54f3d8Smuffin va_end(ap); 1447c478bd9Sstevel@tonic-gate return (shmctl(shmid, cmd, buf)); 1457c478bd9Sstevel@tonic-gate case SHMDT: 1467c478bd9Sstevel@tonic-gate shmaddr = va_arg(ap, char *); 1475d54f3d8Smuffin va_end(ap); 1487c478bd9Sstevel@tonic-gate return (shmdt(shmaddr)); 1497c478bd9Sstevel@tonic-gate case SHMGET: 1507c478bd9Sstevel@tonic-gate key = va_arg(ap, key_t); 1517c478bd9Sstevel@tonic-gate size = va_arg(ap, int); 1527c478bd9Sstevel@tonic-gate shmflg = va_arg(ap, int); 1535d54f3d8Smuffin va_end(ap); 1547c478bd9Sstevel@tonic-gate return (shmget(key, size, shmflg)); 1557c478bd9Sstevel@tonic-gate } 1565d54f3d8Smuffin va_end(ap); 1575d54f3d8Smuffin return (-1); 1587c478bd9Sstevel@tonic-gate } 159