]> git.ipfire.org Git - thirdparty/glibc.git/blame - hurd/privports.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / hurd / privports.c
CommitLineData
f7a9f785 1/* Copyright (C) 1993-2016 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 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
28f540f4
RM
17
18#include <hurd.h>
19
20/* The program might set these if it is the initial task
21 bootstrapped by the microkernel. */
22
23mach_port_t _hurd_host_priv, _hurd_device_master;
24
25
26kern_return_t
f58f41f1 27__get_privileged_ports (mach_port_t *host_priv_ptr,
5017b2c8 28 device_t *device_master_ptr)
28f540f4 29{
377f22d8
RM
30 if ((host_priv_ptr && _hurd_host_priv == MACH_PORT_NULL)
31 || (device_master_ptr && _hurd_device_master == MACH_PORT_NULL))
28f540f4
RM
32 {
33 error_t err;
34
35 if (_hurd_ports)
36 /* We have gotten some initial ports, so perhaps
37 we have a proc server to talk to. */
38 err = __USEPORT (PROC, __proc_getprivports (port,
39 &_hurd_host_priv,
40 &_hurd_device_master));
41 else
42 return MACH_SEND_INVALID_DEST;
43
44 if (err)
45 return err;
46 }
47
48 if (host_priv_ptr)
49 {
377f22d8
RM
50 error_t err = _hurd_host_priv == MACH_PORT_NULL ? 0
51 : __mach_port_mod_refs (mach_task_self (),
52 _hurd_host_priv, MACH_PORT_RIGHT_SEND, +1);
53 if (err)
54 return err;
28f540f4
RM
55 *host_priv_ptr = _hurd_host_priv;
56 }
377f22d8 57
28f540f4
RM
58 if (device_master_ptr)
59 {
377f22d8
RM
60 error_t err = _hurd_device_master == MACH_PORT_NULL ? 0
61 : __mach_port_mod_refs (mach_task_self (),
62 _hurd_device_master, MACH_PORT_RIGHT_SEND, +1);
63 if (err)
64 return err;
28f540f4
RM
65 *device_master_ptr = _hurd_device_master;
66 }
377f22d8 67
28f540f4
RM
68 return KERN_SUCCESS;
69}
5017b2c8 70weak_alias (__get_privileged_ports, get_privileged_ports)