hurd-start.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /** Commentary:
  21. Inspired by implementation in GNU C Library:
  22. Initialization code run first thing by the ELF startup code. For i386/Hurd.
  23. Copyright (C) 1995-2016 Free Software Foundation, Inc.
  24. */
  25. #include <mes/lib-mini.h>
  26. #include <argz.h>
  27. #include <gnu/hurd.h>
  28. #include <gnu/syscall.h>
  29. #include <mach/mach-init.h>
  30. #include <mach/mach_types.h>
  31. #include <mach/message.h>
  32. #include <mach/port.h>
  33. struct hurd_startup_data _hurd_startup_data;
  34. mach_port_t _hurd_dtable[_HURD_DTABLE_MAX];
  35. int _hurd_dtable_count;
  36. size_t __argc;
  37. char *__argv[_HURD_ARGV_MAX];
  38. char *__envv[_HURD_ENVV_MAX];
  39. void __mach_init (void);
  40. void
  41. _hurd_start ()
  42. {
  43. mach_port_t bootstrap;
  44. __mach_init ();
  45. __task_get_special_port (mach_task_self (), TASK_BOOTSTRAP_PORT,
  46. &bootstrap);
  47. __exec_startup_get_data (bootstrap, &_hurd_startup_data);
  48. _hurd_dtable_count = _hurd_startup_data.dtable_count;
  49. for (int i = 0; i < _hurd_dtable_count; i++)
  50. _hurd_dtable[i] = _hurd_startup_data.dtable[i];
  51. __argc = __argz_extract_count (_hurd_startup_data.argp, _hurd_startup_data.arg_size, __argv);
  52. __argz_extract (_hurd_startup_data.envp, _hurd_startup_data.env_size, __envv);
  53. environ = __envv;
  54. }