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