]> git.ipfire.org Git - thirdparty/glibc.git/blame - hurd/privports.c
2.5-18.1
[thirdparty/glibc.git] / hurd / privports.c
CommitLineData
f58f41f1 1/* Copyright (C) 1993,94,97,2001,02 Free Software Foundation, Inc.
c84142e8
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
c84142e8
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
c84142e8 13
41bdb6e2
AJ
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
28f540f4
RM
18
19#include <hurd.h>
20
21/* The program might set these if it is the initial task
22 bootstrapped by the microkernel. */
23
24mach_port_t _hurd_host_priv, _hurd_device_master;
25
26
27kern_return_t
f58f41f1 28__get_privileged_ports (mach_port_t *host_priv_ptr,
5017b2c8 29 device_t *device_master_ptr)
28f540f4 30{
377f22d8
RM
31 if ((host_priv_ptr && _hurd_host_priv == MACH_PORT_NULL)
32 || (device_master_ptr && _hurd_device_master == MACH_PORT_NULL))
28f540f4
RM
33 {
34 error_t err;
35
36 if (_hurd_ports)
37 /* We have gotten some initial ports, so perhaps
38 we have a proc server to talk to. */
39 err = __USEPORT (PROC, __proc_getprivports (port,
40 &_hurd_host_priv,
41 &_hurd_device_master));
42 else
43 return MACH_SEND_INVALID_DEST;
44
45 if (err)
46 return err;
47 }
48
49 if (host_priv_ptr)
50 {
377f22d8
RM
51 error_t err = _hurd_host_priv == MACH_PORT_NULL ? 0
52 : __mach_port_mod_refs (mach_task_self (),
53 _hurd_host_priv, MACH_PORT_RIGHT_SEND, +1);
54 if (err)
55 return err;
28f540f4
RM
56 *host_priv_ptr = _hurd_host_priv;
57 }
377f22d8 58
28f540f4
RM
59 if (device_master_ptr)
60 {
377f22d8
RM
61 error_t err = _hurd_device_master == MACH_PORT_NULL ? 0
62 : __mach_port_mod_refs (mach_task_self (),
63 _hurd_device_master, MACH_PORT_RIGHT_SEND, +1);
64 if (err)
65 return err;
28f540f4
RM
66 *device_master_ptr = _hurd_device_master;
67 }
377f22d8 68
28f540f4
RM
69 return KERN_SUCCESS;
70}
5017b2c8 71weak_alias (__get_privileged_ports, get_privileged_ports)