ports-set.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright (C) 1994-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <hurd.h>
  15. static error_t
  16. setbootstrap (mach_port_t newport)
  17. {
  18. return __task_set_special_port (__mach_task_self (),
  19. TASK_BOOTSTRAP_PORT,
  20. newport);
  21. }
  22. extern error_t _hurd_setauth (auth_t);
  23. extern error_t _hurd_setproc (process_t);
  24. extern error_t _hurd_setcttyid (mach_port_t);
  25. error_t (*_hurd_ports_setters[INIT_PORT_MAX]) (mach_port_t newport) =
  26. {
  27. [INIT_PORT_BOOTSTRAP] = setbootstrap,
  28. [INIT_PORT_AUTH] = _hurd_setauth,
  29. [INIT_PORT_PROC] = _hurd_setproc,
  30. [INIT_PORT_CTTYID] = _hurd_setcttyid,
  31. };
  32. error_t
  33. _hurd_ports_set (unsigned int which, mach_port_t newport)
  34. {
  35. error_t err;
  36. if (which >= _hurd_nports)
  37. return EINVAL;
  38. if (err = __mach_port_mod_refs (__mach_task_self (), newport,
  39. MACH_PORT_RIGHT_SEND, 1))
  40. return err;
  41. if (which >= INIT_PORT_MAX || _hurd_ports_setters[which] == NULL)
  42. {
  43. _hurd_port_set (&_hurd_ports[which], newport);
  44. return 0;
  45. }
  46. return (*_hurd_ports_setters[which]) (newport);
  47. }