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