xref: /illumos-gate/usr/src/lib/libc/port/sys/shmsys.c (revision c242ec1b4cd260e90178d81575297bb3b3648766)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #pragma weak _shmat = shmat
31 #pragma weak _shmctl = shmctl
32 #pragma weak _shmctl64 = shmctl64
33 #pragma weak _shmdt = shmdt
34 #pragma weak _shmget = shmget
35 #pragma weak _shmids = shmids
36 
37 #include "lint.h"
38 #include <sys/types.h>
39 #include <sys/ipc.h>
40 #include <sys/ipc_impl.h>
41 #include <sys/shm.h>
42 #include <sys/shm_impl.h>
43 #include <sys/syscall.h>
44 #include <errno.h>
45 
46 void *
shmat(int shmid,const void * shmaddr,int shmflg)47 shmat(int shmid, const void *shmaddr, int shmflg)
48 {
49 	sysret_t rval;
50 	int error;
51 
52 	error = __systemcall(&rval, SYS_shmsys, SHMAT, shmid, shmaddr, shmflg);
53 	if (error)
54 		(void) __set_errno(error);
55 	return ((void *)rval.sys_rval1);
56 }
57 
58 int
shmctl(int shmid,int cmd,struct shmid_ds * buf)59 shmctl(int shmid, int cmd, struct shmid_ds *buf)
60 {
61 	if (cmd == IPC_SET64 || cmd == IPC_STAT64) {
62 		(void) __set_errno(EINVAL);
63 		return (-1);
64 	}
65 	return (syscall(SYS_shmsys, SHMCTL, shmid, cmd, buf));
66 }
67 
68 int
shmctl64(int shmid,int cmd,struct shmid_ds64 * buf)69 shmctl64(int shmid, int cmd, struct shmid_ds64 *buf)
70 {
71 	if (cmd != IPC_SET64 && cmd != IPC_STAT64) {
72 		(void) __set_errno(EINVAL);
73 		return (-1);
74 	}
75 	return (syscall(SYS_shmsys, SHMCTL, shmid, cmd, buf));
76 }
77 
78 int
shmdt(char * shmaddr)79 shmdt(char *shmaddr)
80 {
81 	return (syscall(SYS_shmsys, SHMDT, shmaddr));
82 }
83 
84 int
shmget(key_t key,size_t size,int shmflg)85 shmget(key_t key, size_t size, int shmflg)
86 {
87 	return (syscall(SYS_shmsys, SHMGET, key, size, shmflg));
88 }
89 
90 int
shmids(int * buf,uint_t nids,uint_t * pnids)91 shmids(int *buf, uint_t nids, uint_t *pnids)
92 {
93 	return (syscall(SYS_shmsys, SHMIDS, buf, nids, pnids));
94 }
95