10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55891Sraf * Common Development and Distribution License (the "License").
65891Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
215891Sraf
220Sstevel@tonic-gate /*
235891Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
30*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
310Sstevel@tonic-gate
32*6812Sraf #pragma weak _msgctl = msgctl
33*6812Sraf #pragma weak _msgget = msgget
34*6812Sraf #pragma weak _msgids = msgids
35*6812Sraf #pragma weak _msgsnap = msgsnap
36*6812Sraf
37*6812Sraf #include "lint.h"
380Sstevel@tonic-gate #include <sys/types.h>
390Sstevel@tonic-gate #include <sys/ipc.h>
400Sstevel@tonic-gate #include <sys/ipc_impl.h>
410Sstevel@tonic-gate #include <sys/msg.h>
420Sstevel@tonic-gate #include <sys/msg_impl.h>
430Sstevel@tonic-gate #include <sys/syscall.h>
440Sstevel@tonic-gate #include <errno.h>
450Sstevel@tonic-gate #include <limits.h>
460Sstevel@tonic-gate
470Sstevel@tonic-gate int
msgget(key_t key,int msgflg)480Sstevel@tonic-gate msgget(key_t key, int msgflg)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate return (syscall(SYS_msgsys, MSGGET, key, msgflg));
510Sstevel@tonic-gate }
520Sstevel@tonic-gate
530Sstevel@tonic-gate int
msgctl(int msqid,int cmd,struct msqid_ds * buf)540Sstevel@tonic-gate msgctl(int msqid, int cmd, struct msqid_ds *buf)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate if (cmd == IPC_SET64 || cmd == IPC_STAT64) {
570Sstevel@tonic-gate (void) __set_errno(EINVAL);
580Sstevel@tonic-gate return (-1);
590Sstevel@tonic-gate }
600Sstevel@tonic-gate
610Sstevel@tonic-gate return (syscall(SYS_msgsys, MSGCTL, msqid, cmd, buf));
620Sstevel@tonic-gate }
630Sstevel@tonic-gate
640Sstevel@tonic-gate int
msgctl64(int msqid,int cmd,struct msqid_ds64 * buf)650Sstevel@tonic-gate msgctl64(int msqid, int cmd, struct msqid_ds64 *buf)
660Sstevel@tonic-gate {
670Sstevel@tonic-gate if (cmd != IPC_SET64 && cmd != IPC_STAT64) {
680Sstevel@tonic-gate (void) __set_errno(EINVAL);
690Sstevel@tonic-gate return (-1);
700Sstevel@tonic-gate }
710Sstevel@tonic-gate
720Sstevel@tonic-gate return (syscall(SYS_msgsys, MSGCTL, msqid, cmd, buf));
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate ssize_t
__msgrcv(int msqid,void * msgp,size_t msgsz,long msgtyp,int msgflg)765891Sraf __msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate if (msgsz > INT_MAX) {
790Sstevel@tonic-gate sysret_t rval;
800Sstevel@tonic-gate int error;
810Sstevel@tonic-gate
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate * We have to use __systemcall here because in the
840Sstevel@tonic-gate * 64-bit case, we need to return a long, while
850Sstevel@tonic-gate * syscall() is doomed to return an int
860Sstevel@tonic-gate */
870Sstevel@tonic-gate error = __systemcall(&rval, SYS_msgsys, MSGRCV, msqid,
880Sstevel@tonic-gate msgp, msgsz, msgtyp, msgflg);
890Sstevel@tonic-gate if (error)
900Sstevel@tonic-gate (void) __set_errno(error);
910Sstevel@tonic-gate return ((ssize_t)rval.sys_rval1);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate return ((ssize_t)syscall(SYS_msgsys, MSGRCV, msqid,
940Sstevel@tonic-gate msgp, msgsz, msgtyp, msgflg));
950Sstevel@tonic-gate }
960Sstevel@tonic-gate
970Sstevel@tonic-gate int
__msgsnd(int msqid,const void * msgp,size_t msgsz,int msgflg)985891Sraf __msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate if (msgsz > INT_MAX) {
1010Sstevel@tonic-gate sysret_t rval;
1020Sstevel@tonic-gate int error;
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate error = __systemcall(&rval, SYS_msgsys, MSGSND, msqid,
1050Sstevel@tonic-gate msgp, msgsz, msgflg);
1060Sstevel@tonic-gate if (error)
1070Sstevel@tonic-gate (void) __set_errno(error);
1080Sstevel@tonic-gate return ((int)rval.sys_rval1);
1090Sstevel@tonic-gate }
1100Sstevel@tonic-gate return (syscall(SYS_msgsys, MSGSND, msqid, msgp, msgsz, msgflg));
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate int
msgids(int * buf,uint_t nids,uint_t * pnids)1140Sstevel@tonic-gate msgids(int *buf, uint_t nids, uint_t *pnids)
1150Sstevel@tonic-gate {
1160Sstevel@tonic-gate return (syscall(SYS_msgsys, MSGIDS, buf, nids, pnids));
1170Sstevel@tonic-gate }
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate int
msgsnap(int msqid,void * buf,size_t bufsz,long msgtyp)1200Sstevel@tonic-gate msgsnap(int msqid, void *buf, size_t bufsz, long msgtyp)
1210Sstevel@tonic-gate {
1220Sstevel@tonic-gate return (syscall(SYS_msgsys, MSGSNAP, msqid, buf, bufsz, msgtyp));
1230Sstevel@tonic-gate }
124