xref: /titanic_41/usr/src/lib/libc/port/sys/shmsys.c (revision ba2e4443695ee6a6f420a35cd4fc3d3346d22932)
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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*	Copyright (c) 1988 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 
33 #pragma weak shmat = _shmat
34 #pragma weak shmctl = _shmctl
35 #pragma weak shmctl64 = _shmctl64
36 #pragma weak shmdt = _shmdt
37 #pragma weak shmget = _shmget
38 #pragma weak shmids = _shmids
39 
40 #include "synonyms.h"
41 #include <sys/types.h>
42 #include <sys/ipc.h>
43 #include <sys/ipc_impl.h>
44 #include <sys/shm.h>
45 #include <sys/shm_impl.h>
46 #include <sys/syscall.h>
47 #include <errno.h>
48 
49 void *
50 shmat(int shmid, const void *shmaddr, int shmflg)
51 {
52 	sysret_t rval;
53 	int error;
54 
55 	error = __systemcall(&rval, SYS_shmsys, SHMAT, shmid, shmaddr, shmflg);
56 	if (error)
57 		(void) __set_errno(error);
58 	return ((void *)rval.sys_rval1);
59 }
60 
61 int
62 shmctl(int shmid, int cmd, struct shmid_ds *buf)
63 {
64 	if (cmd == IPC_SET64 || cmd == IPC_STAT64) {
65 		(void) __set_errno(EINVAL);
66 		return (-1);
67 	}
68 	return (syscall(SYS_shmsys, SHMCTL, shmid, cmd, buf));
69 }
70 
71 int
72 shmctl64(int shmid, int cmd, struct shmid_ds64 *buf)
73 {
74 	if (cmd != IPC_SET64 && cmd != IPC_STAT64) {
75 		(void) __set_errno(EINVAL);
76 		return (-1);
77 	}
78 	return (syscall(SYS_shmsys, SHMCTL, shmid, cmd, buf));
79 }
80 
81 int
82 shmdt(char *shmaddr)
83 {
84 	return (syscall(SYS_shmsys, SHMDT, shmaddr));
85 }
86 
87 int
88 shmget(key_t key, size_t size, int shmflg)
89 {
90 	return (syscall(SYS_shmsys, SHMGET, key, size, shmflg));
91 }
92 
93 int
94 shmids(int *buf, uint_t nids, uint_t *pnids)
95 {
96 	return (syscall(SYS_shmsys, SHMIDS, buf, nids, pnids));
97 }
98