* bits/types.h: Don't include stddef.h, don't define __need_size_t.
[glibc.git] / mach / msg.c
blobbccad7fd26e6e1e8c60e14b469cb1ec899f60691
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990,1989, 1995 Carnegie Mellon University
4 * All Rights Reserved.
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
26 #include <mach/port.h>
27 #include <mach/message.h>
29 #ifdef MACH_MSG_OVERWRITE
30 /* In variants with this feature, the actual system call is
31 __mach_msg_overwrite_trap. */
32 mach_msg_return_t
33 __mach_msg_trap (mach_msg_header_t *msg,
34 mach_msg_option_t option,
35 mach_msg_size_t send_size,
36 mach_msg_size_t rcv_size,
37 mach_port_t rcv_name,
38 mach_msg_timeout_t timeout,
39 mach_port_t notify)
41 return __mach_msg_overwrite_trap (msg, option, send_size,
42 rcv_size, rcv_name, timeout, notify,
43 MACH_MSG_NULL, 0);
45 weak_alias (__mach_msg_trap, mach_msg_trap)
47 /* See comments below in __mach_msg. */
48 mach_msg_return_t
49 __mach_msg_overwrite (mach_msg_header_t *msg,
50 mach_msg_option_t option,
51 mach_msg_size_t send_size,
52 mach_msg_size_t rcv_size,
53 mach_port_t rcv_name,
54 mach_msg_timeout_t timeout,
55 mach_port_t notify,
56 mach_msg_header_t *rcv_msg,
57 mach_msg_size_t rcv_msg_size)
60 mach_msg_return_t ret;
62 /* Consider the following cases:
63 1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
64 plus special bits).
65 2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
66 3. RPC calls with interruptions in one/both halves.
69 ret = __mach_msg_overwrite_trap (msg, option, send_size,
70 rcv_size, rcv_name, timeout, notify,
71 rcv_msg, rcv_msg_size);
72 if (ret == MACH_MSG_SUCCESS)
73 return MACH_MSG_SUCCESS;
75 if (!(option & MACH_SEND_INTERRUPT))
76 while (ret == MACH_SEND_INTERRUPTED)
77 ret = __mach_msg_overwrite_trap (msg, option, send_size,
78 rcv_size, rcv_name, timeout, notify,
79 rcv_msg, rcv_msg_size);
81 if (!(option & MACH_RCV_INTERRUPT))
82 while (ret == MACH_RCV_INTERRUPTED)
83 ret = __mach_msg_overwrite_trap (msg, option & ~MACH_SEND_MSG,
84 0, rcv_size, rcv_name, timeout, notify,
85 rcv_msg, rcv_msg_size);
87 return ret;
89 weak_alias (__mach_msg_overwrite, mach_msg_overwrite)
90 #endif
92 mach_msg_return_t
93 __mach_msg (mach_msg_header_t *msg,
94 mach_msg_option_t option,
95 mach_msg_size_t send_size,
96 mach_msg_size_t rcv_size,
97 mach_port_t rcv_name,
98 mach_msg_timeout_t timeout,
99 mach_port_t notify)
101 mach_msg_return_t ret;
103 /* Consider the following cases:
104 1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
105 plus special bits).
106 2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
107 3. RPC calls with interruptions in one/both halves.
110 ret = __mach_msg_trap (msg, option, send_size,
111 rcv_size, rcv_name, timeout, notify);
112 if (ret == MACH_MSG_SUCCESS)
113 return MACH_MSG_SUCCESS;
115 if (!(option & MACH_SEND_INTERRUPT))
116 while (ret == MACH_SEND_INTERRUPTED)
117 ret = __mach_msg_trap (msg, option, send_size,
118 rcv_size, rcv_name, timeout, notify);
120 if (!(option & MACH_RCV_INTERRUPT))
121 while (ret == MACH_RCV_INTERRUPTED)
122 ret = __mach_msg_trap (msg, option & ~MACH_SEND_MSG,
123 0, rcv_size, rcv_name, timeout, notify);
125 return ret;
127 weak_alias (__mach_msg, mach_msg)
129 mach_msg_return_t
130 __mach_msg_send (mach_msg_header_t *msg)
132 return __mach_msg (msg, MACH_SEND_MSG,
133 msg->msgh_size, 0, MACH_PORT_NULL,
134 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
136 weak_alias (__mach_msg_send, mach_msg_send)
138 mach_msg_return_t
139 __mach_msg_receive (mach_msg_header_t *msg)
141 return __mach_msg (msg, MACH_RCV_MSG,
142 0, msg->msgh_size, msg->msgh_local_port,
143 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
145 weak_alias (__mach_msg_receive, mach_msg_receive)