xref: /titanic_51/usr/src/lib/libc/port/sys/msgsys.c (revision 2722387f30847b828b57ba9ca59d2b47ee9244ec)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*	Copyright (c) 1988 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 #pragma weak msgctl = _msgctl
33 #pragma weak msgctl64 = _msgctl64
34 #pragma weak msgget = _msgget
35 #pragma weak msgids = _msgids
36 #pragma weak msgsnap = _msgsnap
37 
38 #include "synonyms.h"
39 #include <sys/types.h>
40 #include <sys/ipc.h>
41 #include <sys/ipc_impl.h>
42 #include <sys/msg.h>
43 #include <sys/msg_impl.h>
44 #include <sys/syscall.h>
45 #include <errno.h>
46 #include <limits.h>
47 
48 int
49 msgget(key_t key, int msgflg)
50 {
51 	return (syscall(SYS_msgsys, MSGGET, key, msgflg));
52 }
53 
54 int
55 msgctl(int msqid, int cmd, struct msqid_ds *buf)
56 {
57 	if (cmd == IPC_SET64 || cmd == IPC_STAT64) {
58 		(void) __set_errno(EINVAL);
59 		return (-1);
60 	}
61 
62 	return (syscall(SYS_msgsys, MSGCTL, msqid, cmd, buf));
63 }
64 
65 int
66 msgctl64(int msqid, int cmd, struct msqid_ds64 *buf)
67 {
68 	if (cmd != IPC_SET64 && cmd != IPC_STAT64) {
69 		(void) __set_errno(EINVAL);
70 		return (-1);
71 	}
72 
73 	return (syscall(SYS_msgsys, MSGCTL, msqid, cmd, buf));
74 }
75 
76 ssize_t
77 __msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
78 {
79 	if (msgsz > INT_MAX) {
80 		sysret_t rval;
81 		int error;
82 
83 		/*
84 		 * We have to use __systemcall here because in the
85 		 * 64-bit case, we need to return a long, while
86 		 * syscall() is doomed to return an int
87 		 */
88 		error = __systemcall(&rval, SYS_msgsys, MSGRCV, msqid,
89 		    msgp, msgsz, msgtyp, msgflg);
90 		if (error)
91 			(void) __set_errno(error);
92 		return ((ssize_t)rval.sys_rval1);
93 	}
94 	return ((ssize_t)syscall(SYS_msgsys, MSGRCV, msqid,
95 	    msgp, msgsz, msgtyp, msgflg));
96 }
97 
98 int
99 __msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
100 {
101 	if (msgsz > INT_MAX) {
102 		sysret_t rval;
103 		int error;
104 
105 		error = __systemcall(&rval, SYS_msgsys, MSGSND, msqid,
106 		    msgp, msgsz, msgflg);
107 		if (error)
108 			(void) __set_errno(error);
109 		return ((int)rval.sys_rval1);
110 	}
111 	return (syscall(SYS_msgsys, MSGSND, msqid, msgp, msgsz, msgflg));
112 }
113 
114 int
115 msgids(int *buf, uint_t nids, uint_t *pnids)
116 {
117 	return (syscall(SYS_msgsys, MSGIDS, buf, nids, pnids));
118 }
119 
120 int
121 msgsnap(int msqid, void *buf, size_t bufsz, long msgtyp)
122 {
123 	return (syscall(SYS_msgsys, MSGSNAP, msqid, buf, bufsz, msgtyp));
124 }
125