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