Back to index

glibc  2.9
privports.c
Go to the documentation of this file.
00001 /* Copyright (C) 1993,94,97,2001,02 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <hurd.h>
00020 
00021 /* The program might set these if it is the initial task
00022    bootstrapped by the microkernel.  */
00023 
00024 mach_port_t _hurd_host_priv, _hurd_device_master;
00025 
00026 
00027 kern_return_t
00028 __get_privileged_ports (mach_port_t *host_priv_ptr,
00029                      device_t *device_master_ptr)
00030 {
00031   if ((host_priv_ptr && _hurd_host_priv == MACH_PORT_NULL)
00032       || (device_master_ptr && _hurd_device_master == MACH_PORT_NULL))
00033     {
00034       error_t err;
00035 
00036       if (_hurd_ports)
00037        /* We have gotten some initial ports, so perhaps
00038           we have a proc server to talk to.  */
00039        err = __USEPORT (PROC, __proc_getprivports (port,
00040                                               &_hurd_host_priv,
00041                                               &_hurd_device_master));
00042       else
00043        return MACH_SEND_INVALID_DEST;
00044 
00045       if (err)
00046        return err;
00047     }
00048 
00049   if (host_priv_ptr)
00050     {
00051       error_t err = _hurd_host_priv == MACH_PORT_NULL ? 0
00052        : __mach_port_mod_refs (mach_task_self (),
00053                             _hurd_host_priv, MACH_PORT_RIGHT_SEND, +1);
00054       if (err)
00055        return err;
00056       *host_priv_ptr = _hurd_host_priv;
00057     }
00058 
00059   if (device_master_ptr)
00060     {
00061       error_t err = _hurd_device_master == MACH_PORT_NULL ? 0
00062        : __mach_port_mod_refs (mach_task_self (),
00063                             _hurd_device_master, MACH_PORT_RIGHT_SEND, +1);
00064       if (err)
00065        return err;
00066       *device_master_ptr = _hurd_device_master;
00067     }
00068 
00069   return KERN_SUCCESS;
00070 }
00071 weak_alias (__get_privileged_ports, get_privileged_ports)