Back to index

glibc  2.9
msg.c
Go to the documentation of this file.
00001 /*
00002  * Mach Operating System
00003  * Copyright (c) 1991,1990,1989, 1995 Carnegie Mellon University
00004  * All Rights Reserved.
00005  *
00006  * Permission to use, copy, modify and distribute this software and its
00007  * documentation is hereby granted, provided that both the copyright
00008  * notice and this permission notice appear in all copies of the
00009  * software, derivative works or modified versions, and any portions
00010  * thereof, and that both notices appear in supporting documentation.
00011  *
00012  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
00013  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
00014  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00015  *
00016  * Carnegie Mellon requests users of this software to return to
00017  *
00018  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
00019  *  School of Computer Science
00020  *  Carnegie Mellon University
00021  *  Pittsburgh PA 15213-3890
00022  *
00023  * any improvements or extensions that they make and grant Carnegie Mellon
00024  * the rights to redistribute these changes.
00025  */
00026 #include <mach/port.h>
00027 #include <mach/message.h>
00028 
00029 #ifdef MACH_MSG_OVERWRITE
00030 /* In variants with this feature, the actual system call is
00031    __mach_msg_overwrite_trap.  */
00032 mach_msg_return_t
00033 __mach_msg_trap (mach_msg_header_t *msg,
00034                mach_msg_option_t option,
00035                mach_msg_size_t send_size,
00036                mach_msg_size_t rcv_size,
00037                mach_port_t rcv_name,
00038                mach_msg_timeout_t timeout,
00039                mach_port_t notify)
00040 {
00041   return __mach_msg_overwrite_trap (msg, option, send_size,
00042                                 rcv_size, rcv_name, timeout, notify,
00043                                 MACH_MSG_NULL, 0);
00044 }
00045 weak_alias (__mach_msg_trap, mach_msg_trap)
00046 
00047 /* See comments below in __mach_msg.  */
00048 mach_msg_return_t
00049 __mach_msg_overwrite (mach_msg_header_t *msg,
00050                     mach_msg_option_t option,
00051                     mach_msg_size_t send_size,
00052                     mach_msg_size_t rcv_size,
00053                     mach_port_t rcv_name,
00054                     mach_msg_timeout_t timeout,
00055                     mach_port_t notify,
00056                     mach_msg_header_t *rcv_msg,
00057                     mach_msg_size_t rcv_msg_size)
00058 
00059 {
00060   mach_msg_return_t ret;
00061 
00062   /* Consider the following cases:
00063      1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
00064      plus special bits).
00065      2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
00066      3. RPC calls with interruptions in one/both halves.
00067   */
00068 
00069   ret = __mach_msg_overwrite_trap (msg, option, send_size,
00070                                rcv_size, rcv_name, timeout, notify,
00071                                rcv_msg, rcv_msg_size);
00072   if (ret == MACH_MSG_SUCCESS)
00073     return MACH_MSG_SUCCESS;
00074 
00075   if (!(option & MACH_SEND_INTERRUPT))
00076     while (ret == MACH_SEND_INTERRUPTED)
00077       ret = __mach_msg_overwrite_trap (msg, option, send_size,
00078                                    rcv_size, rcv_name, timeout, notify,
00079                                    rcv_msg, rcv_msg_size);
00080 
00081   if (!(option & MACH_RCV_INTERRUPT))
00082     while (ret == MACH_RCV_INTERRUPTED)
00083       ret = __mach_msg_overwrite_trap (msg, option & ~MACH_SEND_MSG,
00084                                    0, rcv_size, rcv_name, timeout, notify,
00085                                    rcv_msg, rcv_msg_size);
00086 
00087   return ret;
00088 }
00089 weak_alias (__mach_msg_overwrite, mach_msg_overwrite)
00090 #endif
00091 
00092 mach_msg_return_t
00093 __mach_msg (mach_msg_header_t *msg,
00094            mach_msg_option_t option,
00095            mach_msg_size_t send_size,
00096            mach_msg_size_t rcv_size,
00097            mach_port_t rcv_name,
00098            mach_msg_timeout_t timeout,
00099            mach_port_t notify)
00100 {
00101   mach_msg_return_t ret;
00102 
00103   /* Consider the following cases:
00104      1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
00105      plus special bits).
00106      2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
00107      3. RPC calls with interruptions in one/both halves.
00108      */
00109 
00110   ret = __mach_msg_trap (msg, option, send_size,
00111                       rcv_size, rcv_name, timeout, notify);
00112   if (ret == MACH_MSG_SUCCESS)
00113     return MACH_MSG_SUCCESS;
00114 
00115   if (!(option & MACH_SEND_INTERRUPT))
00116     while (ret == MACH_SEND_INTERRUPTED)
00117       ret = __mach_msg_trap (msg, option, send_size,
00118                           rcv_size, rcv_name, timeout, notify);
00119 
00120   if (!(option & MACH_RCV_INTERRUPT))
00121     while (ret == MACH_RCV_INTERRUPTED)
00122       ret = __mach_msg_trap (msg, option & ~MACH_SEND_MSG,
00123                           0, rcv_size, rcv_name, timeout, notify);
00124 
00125   return ret;
00126 }
00127 weak_alias (__mach_msg, mach_msg)
00128 
00129 mach_msg_return_t
00130 __mach_msg_send      (mach_msg_header_t *msg)
00131 {
00132   return __mach_msg (msg, MACH_SEND_MSG,
00133                    msg->msgh_size, 0, MACH_PORT_NULL,
00134                    MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
00135 }
00136 weak_alias (__mach_msg_send, mach_msg_send)
00137 
00138 mach_msg_return_t
00139 __mach_msg_receive (mach_msg_header_t *msg)
00140 {
00141   return __mach_msg (msg, MACH_RCV_MSG,
00142                    0, msg->msgh_size, msg->msgh_local_port,
00143                    MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
00144 }
00145 weak_alias (__mach_msg_receive, mach_msg_receive)