1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
/*
Copyright (C) 2009 Free Software Foundation, Inc.
Written by Zheng Da.
This file is part of the GNU Hurd.
The GNU Hurd is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
The GNU Hurd is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the GNU Hurd; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* This file implements the server-side RPC functions of mach_host. */
#include <mach.h>
#include <hurd.h>
#include <string.h>
#include <assert.h>
#include "util.h"
#include "mach_proxy.h"
kern_return_t
S_mach_port_names (mach_port_t task, mach_port_array_t *names,
mach_msg_type_number_t *namesCnt,
mach_port_type_array_t *types,
mach_msg_type_number_t *typesCnt)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_names (task_pi->task_port,
names, namesCnt, types, typesCnt);
debug ("%s", strerror (err));
/* The deallocation bit is set,
* so 'names' and 'types' will be deallocated after the reply is sent. */
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_type */
kern_return_t
S_mach_port_type (mach_port_t task, mach_port_t name, mach_port_type_t *ptype)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_type (task_pi->task_port, name, ptype);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_rename */
kern_return_t
S_mach_port_rename (mach_port_t task,
mach_port_t old_name, mach_port_t new_name)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
/* old_name and new_name are just names,
* so I don't need to deallocate them.
* It should be the same for other RPCs that only deal with port names */
err = mach_port_rename (task_pi->task_port, old_name, new_name);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_allocate_name */
kern_return_t
S_mach_port_allocate_name (mach_port_t task,
mach_port_right_t right, mach_port_t name)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_allocate_name (task_pi->task_port, right, name);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_allocate */
kern_return_t
S_mach_port_allocate (mach_port_t task,
mach_port_right_t right, mach_port_t *name)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_allocate (task_pi->task_port, right, name);
debug ("get a request from task %d: %s", task_pi->task_port, strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_destroy */
kern_return_t
S_mach_port_destroy (mach_port_t task, mach_port_t name)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_destroy (task_pi->task_port, name);
debug ("get a request from port %d: %s",
task_pi->task_port, strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_deallocate */
kern_return_t
S_mach_port_deallocate (mach_port_t task, mach_port_t name)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_deallocate (task_pi->task_port, name);
debug ("get a request from task %d, name: %d, %s",
task_pi->task_port, name, strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_get_refs */
kern_return_t
S_mach_port_get_refs (mach_port_t task, mach_port_t name,
mach_port_right_t right, mach_port_urefs_t *refs)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_get_refs (task_pi->task_port, name, right, refs);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_mod_refs */
kern_return_t
S_mach_port_mod_refs (mach_port_t task, mach_port_t name,
mach_port_right_t right, mach_port_delta_t delta)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_mod_refs (task_pi->task_port, name, right, delta);
debug ("get a request from task %d: port: %d, right: %d, delta: %d, %s",
task_pi->task_port, name, right, delta, strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine old_mach_port_get_receive_status */
kern_return_t
S_old_mach_port_get_receive_status (mach_port_t task, mach_port_t name,
old_mach_port_status_t *status)
{
debug ("%s", strerror (EOPNOTSUPP));
assert (0);
/* Hurd currently doesn't use it. */
return EOPNOTSUPP;
}
/* Routine mach_port_set_qlimit */
kern_return_t
S_mach_port_set_qlimit (mach_port_t task, mach_port_t name,
mach_port_msgcount_t qlimit)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_set_qlimit (task_pi->task_port, name, qlimit);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_set_mscount */
kern_return_t
S_mach_port_set_mscount (mach_port_t task, mach_port_t name,
mach_port_mscount_t mscount)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_set_mscount (task_pi->task_port, name, mscount);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_get_set_status */
kern_return_t
S_mach_port_get_set_status (mach_port_t task, mach_port_t name,
mach_port_array_t *members,
mach_msg_type_number_t *membersCnt)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_get_set_status (task_pi->task_port,
name, members, membersCnt);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
/* The deallocation bit is set,
* so 'members' will be deallocated after the reply is sent. */
return err;
}
/* Routine mach_port_move_member */
kern_return_t
S_mach_port_move_member (mach_port_t task, mach_port_t member,
mach_port_t after)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_move_member (task_pi->task_port, member, after);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_request_notification */
kern_return_t
S_mach_port_request_notification (mach_port_t task, mach_port_t name,
mach_msg_id_t id, mach_port_mscount_t sync,
mach_port_t notify, mach_port_t *previous,
mach_msg_type_name_t *previousPoly)
{
struct task_info *task_pi;
mach_msg_type_name_t notify_type = MACH_MSG_TYPE_MOVE_SEND_ONCE;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
if (notify == 0)
notify_type = 0;
/* notify is send-once right from the client. */
err = mach_port_request_notification (task_pi->task_port, name, id, sync,
notify, notify_type, previous);
debug ("get a request from task %d, port: %d, id: %d, notify: %d, notify_type: %d, old port: %d, %s",
task_pi->task_port, name, id, notify, notify_type, *previous, strerror (err));
ports_port_deref (task_pi);
if (err)
return err;
*previousPoly = MACH_MSG_TYPE_MOVE_SEND_ONCE;
return 0;
}
/* Routine mach_port_insert_right */
kern_return_t
S_mach_port_insert_right (mach_port_t task, mach_port_t name,
mach_port_t poly, mach_msg_type_name_t polyPoly)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
/* polyPoly can only be three possible values: MACH_MSG_TYPE_PORT_SEND,
* MACH_MSG_TYPE_PORT_SEND_ONCE and MACH_MSG_TYPE_PORT_RECEIVE,
* so port will be deallocated when mach_port_insert_right is called. */
err = mach_port_insert_right (task_pi->task_port, name, poly, polyPoly);
debug ("get a request from task %d: %s", task_pi->task_port, strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_extract_right */
kern_return_t
S_mach_port_extract_right (mach_port_t task, mach_port_t name,
mach_msg_type_name_t msgt_name, mach_port_t *poly,
mach_msg_type_name_t *polyPoly)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_extract_right (task_pi->task_port, name, msgt_name,
poly, polyPoly);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
/* *polyPoly can only be MACH_MSG_TYPE_PORT_SEND, MACH_MSG_TYPE_PORT_RECEIVE,
* or MACH_MSG_TYPE_PORT_SEND_ONCE, so the port extracted from 'task'
* will be moved to the client. */
return err;
}
/* Routine mach_port_get_receive_status */
kern_return_t
S_mach_port_get_receive_status (mach_port_t task, mach_port_t name,
mach_port_status_t *status)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_get_receive_status (task_pi->task_port, name, status);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
/* Routine mach_port_set_seqno */
kern_return_t
S_mach_port_set_seqno (mach_port_t task, mach_port_t name,
mach_port_seqno_t seqno)
{
struct task_info *task_pi;
error_t err;
task_pi = ports_lookup_port (port_bucket, task, task_portclass);
if (task_pi == NULL)
return EOPNOTSUPP;
err = mach_port_set_seqno (task_pi->task_port, name, seqno);
debug ("%s", strerror (err));
ports_port_deref (task_pi);
return err;
}
|