syscall-internal.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 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. #include <gnu/syscall.h>
  21. #include <mach/mach_traps.h>
  22. static mach_msg_type_t mach_msg_type_int32 =
  23. {
  24. .msgt_name = (unsigned char) MACH_MSG_TYPE_INTEGER_32, // msgt_name
  25. .msgt_size = 32, // msgt_size
  26. .msgt_number = 1, // msgt_number
  27. .msgt_inline = 1, // msgt_inline
  28. .msgt_longform = 0, // msgt_longform
  29. .msgt_deallocate = 0, // msgt_deallocate
  30. .msgt_unused = 0 // msgt_unused
  31. };
  32. static mach_msg_type_long_t mach_msg_type_pointer =
  33. {
  34. {
  35. 0, // msgt_name
  36. 0, // msgt_size
  37. 0, // msgt_number
  38. 1, // msgt_inline FIXME: we always outline...
  39. 1, // msgt_longform
  40. 0, // msgt_deallocate
  41. 0, // msgt_unused
  42. },
  43. MACH_MSG_TYPE_CHAR, // msgtl_name
  44. 8, // msgtl_size
  45. 2048, // msgtl_number
  46. };
  47. static mach_msg_type_t mach_msg_type_int64 =
  48. {
  49. (unsigned char) MACH_MSG_TYPE_INTEGER_64, // msgt_name
  50. 64, // msgt_size
  51. 1, // msgt_number
  52. 1, // msgt_inline
  53. 0, // msgt_longform
  54. 0, // msgt_deallocate
  55. 0, // msgt_unused
  56. };
  57. kern_return_t
  58. __syscall (mach_port_t port, int sys_call)
  59. {
  60. struct mach_msg message =
  61. {
  62. {
  63. MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE),
  64. 0,
  65. port,
  66. {__mach_reply_port (),},
  67. 0,
  68. sys_call,
  69. }
  70. };
  71. return __mach_msg (&message.header,
  72. MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
  73. sizeof (message),
  74. sizeof (message),
  75. message.header.msgh_local_port,
  76. MACH_MSG_TIMEOUT_NONE,
  77. MACH_PORT_NULL);
  78. }
  79. kern_return_t
  80. __syscall2 (mach_port_t port, int sys_call, int one, int two)
  81. {
  82. struct mach_msg_2 message =
  83. {
  84. {
  85. MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE),
  86. 0,
  87. port,
  88. {__mach_reply_port (),},
  89. 0,
  90. sys_call,
  91. },
  92. mach_msg_type_int32, one,
  93. mach_msg_type_int32, two,
  94. };
  95. return __mach_msg (&message.header,
  96. MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
  97. sizeof (message),
  98. sizeof (message),
  99. message.header.msgh_local_port,
  100. MACH_MSG_TIMEOUT_NONE,
  101. MACH_PORT_NULL);
  102. }
  103. kern_return_t
  104. __syscall_get (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size)
  105. {
  106. message->msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE);
  107. message->msgh_remote_port = port;
  108. message->msgh_local_port = __mach_reply_port ();
  109. message->msgh_seqno = 0;
  110. message->msgh_id = sys_call;
  111. return __mach_msg (message,
  112. MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
  113. message->msgh_size,
  114. size,
  115. message->msgh_local_port,
  116. MACH_MSG_TIMEOUT_NONE,
  117. MACH_PORT_NULL);
  118. }
  119. kern_return_t
  120. __syscall_put (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size)
  121. {
  122. message->msgh_bits |= MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE);
  123. message->msgh_remote_port = port;
  124. message->msgh_local_port = __mach_reply_port ();
  125. message->msgh_seqno = 0;
  126. message->msgh_id = sys_call;
  127. return __mach_msg (message,
  128. MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
  129. message->msgh_size,
  130. size,
  131. message->msgh_local_port,
  132. MACH_MSG_TIMEOUT_NONE,
  133. MACH_PORT_NULL);
  134. }