mach-init.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 1992-2016 Free Software Foundation, Inc.
  4. * Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  5. *
  6. * This file is part of GNU Mes.
  7. *
  8. * GNU Mes is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * GNU Mes is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /** Commentary:
  22. Taken from GNU C Library
  23. */
  24. #define _GNU_SOURCE 1
  25. #define __USE_GNU 1
  26. #define __FILE_defined 1
  27. #include <stdio.h>
  28. #include <mach/mach-init.h>
  29. #include <mach.h>
  30. #include <unistd.h>
  31. mach_port_t __mach_task_self_;
  32. mach_port_t __mach_host_self_;
  33. vm_size_t __vm_page_size = 0;
  34. void
  35. __mach_init (void)
  36. {
  37. kern_return_t err;
  38. #ifdef HAVE_HOST_PAGE_SIZE
  39. if (err = __host_page_size (mach_host_self (), &__vm_page_size))
  40. _exit (err);
  41. #else
  42. {
  43. vm_statistics_data_t stats;
  44. if (err = __vm_statistics (mach_task_self (), &stats))
  45. _exit (err);
  46. __vm_page_size = stats.pagesize;
  47. }
  48. #endif
  49. }
  50. extern mach_port_t __mach_host_self (void);
  51. mach_port_t
  52. mach_host_self (void)
  53. {
  54. if (!__mach_host_self_)
  55. __mach_host_self_ = __mach_host_self ();
  56. return __mach_host_self_;
  57. }
  58. extern mach_port_t __mach_task_self (void);
  59. mach_port_t
  60. mach_task_self (void)
  61. {
  62. if (!__mach_task_self_)
  63. __mach_task_self_ = __mach_task_self ();
  64. return __mach_task_self_;
  65. }