/* Hurd server introspection.
Copyright (C) 2014 Free Software Foundation, Inc.
Written by Justus Winter <4winter@informatik.uni-hamburg.de>
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. If not, see . */
#include
#include "introspection.h"
#include "hurd_port_U.h"
error_t
introspection_set_port (mach_port_t task,
mach_port_t introspection_port)
{
error_t err;
mach_port_t *ports;
size_t ports_len;
err = mach_ports_lookup (task, &ports, &ports_len);
if (err)
return err;
if (MACH_PORT_VALID (ports[HURD_PORT_REGISTER_INTROSPECTION]))
mach_port_deallocate (mach_task_self (),
ports[HURD_PORT_REGISTER_INTROSPECTION]);
ports[HURD_PORT_REGISTER_INTROSPECTION] = introspection_port;
err = mach_ports_register (task, ports, ports_len);
if (err)
{
size_t i;
for (i = 0; i < ports_len; i++)
if (MACH_PORT_VALID (ports[i]))
mach_port_deallocate (mach_task_self (), ports[i]);
return err;
}
return 0;
}
error_t
introspection_get_port (mach_port_t task, mach_port_t *introspection_port)
{
error_t err;
mach_port_t *ports;
size_t ports_len;
err = mach_ports_lookup (task, &ports, &ports_len);
if (! err)
{
size_t i;
if (MACH_PORT_VALID (*introspection_port))
mach_port_deallocate (mach_task_self (), *introspection_port);
for (i = 0; i < ports_len; i++)
if (i == HURD_PORT_REGISTER_INTROSPECTION)
*introspection_port = ports[i];
else
{
if (MACH_PORT_VALID (ports[i]))
mach_port_deallocate (mach_task_self (), ports[i]);
}
}
else
*introspection_port = MACH_PORT_DEAD;
return err;
}