1 | /* |
2 | * Mach Operating System |
3 | * Copyright (c) 1991,1990,1989, 1995 Carnegie Mellon University |
4 | * All Rights Reserved. |
5 | * |
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. |
11 | * |
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. |
15 | * |
16 | * Carnegie Mellon requests users of this software to return to |
17 | * |
18 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
19 | * School of Computer Science |
20 | * Carnegie Mellon University |
21 | * Pittsburgh PA 15213-3890 |
22 | * |
23 | * any improvements or extensions that they make and grant Carnegie Mellon |
24 | * the rights to redistribute these changes. |
25 | */ |
26 | #include <mach/port.h> |
27 | #include <mach/message.h> |
28 | #include <mach.h> |
29 | |
30 | #ifdef MACH_MSG_OVERWRITE |
31 | /* In variants with this feature, the actual system call is |
32 | __mach_msg_overwrite_trap. */ |
33 | mach_msg_return_t |
34 | __mach_msg_trap (mach_msg_header_t *msg, |
35 | mach_msg_option_t option, |
36 | mach_msg_size_t send_size, |
37 | mach_msg_size_t rcv_size, |
38 | mach_port_t rcv_name, |
39 | mach_msg_timeout_t timeout, |
40 | mach_port_t notify) |
41 | { |
42 | return __mach_msg_overwrite_trap (msg, option, send_size, |
43 | rcv_size, rcv_name, timeout, notify, |
44 | MACH_MSG_NULL, 0); |
45 | } |
46 | weak_alias (__mach_msg_trap, mach_msg_trap) |
47 | |
48 | /* See comments below in __mach_msg. */ |
49 | mach_msg_return_t |
50 | __mach_msg_overwrite (mach_msg_header_t *msg, |
51 | mach_msg_option_t option, |
52 | mach_msg_size_t send_size, |
53 | mach_msg_size_t rcv_size, |
54 | mach_port_t rcv_name, |
55 | mach_msg_timeout_t timeout, |
56 | mach_port_t notify, |
57 | mach_msg_header_t *rcv_msg, |
58 | mach_msg_size_t rcv_msg_size) |
59 | |
60 | { |
61 | mach_msg_return_t ret; |
62 | |
63 | /* Consider the following cases: |
64 | 1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED |
65 | plus special bits). |
66 | 2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options. |
67 | 3. RPC calls with interruptions in one/both halves. |
68 | */ |
69 | |
70 | ret = __mach_msg_overwrite_trap (msg, option, send_size, |
71 | rcv_size, rcv_name, timeout, notify, |
72 | rcv_msg, rcv_msg_size); |
73 | if (ret == MACH_MSG_SUCCESS) |
74 | return MACH_MSG_SUCCESS; |
75 | |
76 | if (!(option & MACH_SEND_INTERRUPT)) |
77 | while (ret == MACH_SEND_INTERRUPTED) |
78 | ret = __mach_msg_overwrite_trap (msg, option, send_size, |
79 | rcv_size, rcv_name, timeout, notify, |
80 | rcv_msg, rcv_msg_size); |
81 | |
82 | if (!(option & MACH_RCV_INTERRUPT)) |
83 | while (ret == MACH_RCV_INTERRUPTED) |
84 | ret = __mach_msg_overwrite_trap (msg, option & ~MACH_SEND_MSG, |
85 | 0, rcv_size, rcv_name, timeout, notify, |
86 | rcv_msg, rcv_msg_size); |
87 | |
88 | return ret; |
89 | } |
90 | weak_alias (__mach_msg_overwrite, mach_msg_overwrite) |
91 | #endif |
92 | |
93 | mach_msg_return_t |
94 | __mach_msg (mach_msg_header_t *msg, |
95 | mach_msg_option_t option, |
96 | mach_msg_size_t send_size, |
97 | mach_msg_size_t rcv_size, |
98 | mach_port_t rcv_name, |
99 | mach_msg_timeout_t timeout, |
100 | mach_port_t notify) |
101 | { |
102 | mach_msg_return_t ret; |
103 | |
104 | /* Consider the following cases: |
105 | 1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED |
106 | plus special bits). |
107 | 2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options. |
108 | 3. RPC calls with interruptions in one/both halves. |
109 | */ |
110 | |
111 | ret = __mach_msg_trap (msg, option, send_size, |
112 | rcv_size, rcv_name, timeout, notify); |
113 | if (ret == MACH_MSG_SUCCESS) |
114 | return MACH_MSG_SUCCESS; |
115 | |
116 | if (!(option & MACH_SEND_INTERRUPT)) |
117 | while (ret == MACH_SEND_INTERRUPTED) |
118 | ret = __mach_msg_trap (msg, option, send_size, |
119 | rcv_size, rcv_name, timeout, notify); |
120 | |
121 | if (!(option & MACH_RCV_INTERRUPT)) |
122 | while (ret == MACH_RCV_INTERRUPTED) |
123 | ret = __mach_msg_trap (msg, option & ~MACH_SEND_MSG, |
124 | 0, rcv_size, rcv_name, timeout, notify); |
125 | |
126 | return ret; |
127 | } |
128 | weak_alias (__mach_msg, mach_msg) |
129 | libc_hidden_def (__mach_msg) |
130 | |
131 | mach_msg_return_t |
132 | __mach_msg_send (mach_msg_header_t *msg) |
133 | { |
134 | return __mach_msg (msg, MACH_SEND_MSG, |
135 | msg->msgh_size, 0, MACH_PORT_NULL, |
136 | MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); |
137 | } |
138 | weak_alias (__mach_msg_send, mach_msg_send) |
139 | |
140 | mach_msg_return_t |
141 | __mach_msg_receive (mach_msg_header_t *msg) |
142 | { |
143 | return __mach_msg (msg, MACH_RCV_MSG, |
144 | 0, msg->msgh_size, msg->msgh_local_port, |
145 | MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); |
146 | } |
147 | weak_alias (__mach_msg_receive, mach_msg_receive) |
148 | |