Blame hurd/privports.c

Packit 6c4009
/* Copyright (C) 1993-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <hurd.h>
Packit 6c4009
Packit 6c4009
/* The program might set these if it is the initial task
Packit 6c4009
   bootstrapped by the microkernel.  */
Packit 6c4009
Packit 6c4009
mach_port_t _hurd_host_priv, _hurd_device_master;
Packit 6c4009
Packit 6c4009
Packit 6c4009
kern_return_t
Packit 6c4009
__get_privileged_ports (mach_port_t *host_priv_ptr,
Packit 6c4009
			device_t *device_master_ptr)
Packit 6c4009
{
Packit 6c4009
  if ((host_priv_ptr && _hurd_host_priv == MACH_PORT_NULL)
Packit 6c4009
      || (device_master_ptr && _hurd_device_master == MACH_PORT_NULL))
Packit 6c4009
    {
Packit 6c4009
      error_t err;
Packit 6c4009
Packit 6c4009
      if (_hurd_ports)
Packit 6c4009
	/* We have gotten some initial ports, so perhaps
Packit 6c4009
	   we have a proc server to talk to.  */
Packit 6c4009
	err = __USEPORT (PROC, __proc_getprivports (port,
Packit 6c4009
						    &_hurd_host_priv,
Packit 6c4009
						    &_hurd_device_master));
Packit 6c4009
      else
Packit 6c4009
	return MACH_SEND_INVALID_DEST;
Packit 6c4009
Packit 6c4009
      if (err)
Packit 6c4009
	return err;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (host_priv_ptr)
Packit 6c4009
    {
Packit 6c4009
      error_t err = _hurd_host_priv == MACH_PORT_NULL ? 0
Packit 6c4009
	: __mach_port_mod_refs (mach_task_self (),
Packit 6c4009
				_hurd_host_priv, MACH_PORT_RIGHT_SEND, +1);
Packit 6c4009
      if (err)
Packit 6c4009
	return err;
Packit 6c4009
      *host_priv_ptr = _hurd_host_priv;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (device_master_ptr)
Packit 6c4009
    {
Packit 6c4009
      error_t err = _hurd_device_master == MACH_PORT_NULL ? 0
Packit 6c4009
	: __mach_port_mod_refs (mach_task_self (),
Packit 6c4009
				_hurd_device_master, MACH_PORT_RIGHT_SEND, +1);
Packit 6c4009
      if (err)
Packit 6c4009
	return err;
Packit 6c4009
      *device_master_ptr = _hurd_device_master;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return KERN_SUCCESS;
Packit 6c4009
}
Packit 6c4009
weak_alias (__get_privileged_ports, get_privileged_ports)