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