msg.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1991,1990,1989, 1995 Carnegie Mellon University
  4. * All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify and distribute this software and its
  7. * documentation is hereby granted, provided that both the copyright
  8. * notice and this permission notice appear in all copies of the
  9. * software, derivative works or modified versions, and any portions
  10. * thereof, and that both notices appear in supporting documentation.
  11. *
  12. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15. *
  16. * Carnegie Mellon requests users of this software to return to
  17. *
  18. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  19. * School of Computer Science
  20. * Carnegie Mellon University
  21. * Pittsburgh PA 15213-3890
  22. *
  23. * any improvements or extensions that they make and grant Carnegie Mellon
  24. * the rights to redistribute these changes.
  25. */
  26. #include <mach/port.h>
  27. #include <mach/message.h>
  28. #include <mach.h>
  29. #ifdef MACH_MSG_OVERWRITE
  30. /* In variants with this feature, the actual system call is
  31. __mach_msg_overwrite_trap. */
  32. mach_msg_return_t
  33. __mach_msg_trap (mach_msg_header_t *msg,
  34. mach_msg_option_t option,
  35. mach_msg_size_t send_size,
  36. mach_msg_size_t rcv_size,
  37. mach_port_t rcv_name,
  38. mach_msg_timeout_t timeout,
  39. mach_port_t notify)
  40. {
  41. return __mach_msg_overwrite_trap (msg, option, send_size,
  42. rcv_size, rcv_name, timeout, notify,
  43. MACH_MSG_NULL, 0);
  44. }
  45. weak_alias (__mach_msg_trap, mach_msg_trap)
  46. /* See comments below in __mach_msg. */
  47. mach_msg_return_t
  48. __mach_msg_overwrite (mach_msg_header_t *msg,
  49. mach_msg_option_t option,
  50. mach_msg_size_t send_size,
  51. mach_msg_size_t rcv_size,
  52. mach_port_t rcv_name,
  53. mach_msg_timeout_t timeout,
  54. mach_port_t notify,
  55. mach_msg_header_t *rcv_msg,
  56. mach_msg_size_t rcv_msg_size)
  57. {
  58. mach_msg_return_t ret;
  59. /* Consider the following cases:
  60. 1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
  61. plus special bits).
  62. 2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
  63. 3. RPC calls with interruptions in one/both halves.
  64. */
  65. ret = __mach_msg_overwrite_trap (msg, option, send_size,
  66. rcv_size, rcv_name, timeout, notify,
  67. rcv_msg, rcv_msg_size);
  68. if (ret == MACH_MSG_SUCCESS)
  69. return MACH_MSG_SUCCESS;
  70. if (!(option & MACH_SEND_INTERRUPT))
  71. while (ret == MACH_SEND_INTERRUPTED)
  72. ret = __mach_msg_overwrite_trap (msg, option, send_size,
  73. rcv_size, rcv_name, timeout, notify,
  74. rcv_msg, rcv_msg_size);
  75. if (!(option & MACH_RCV_INTERRUPT))
  76. while (ret == MACH_RCV_INTERRUPTED)
  77. ret = __mach_msg_overwrite_trap (msg, option & ~MACH_SEND_MSG,
  78. 0, rcv_size, rcv_name, timeout, notify,
  79. rcv_msg, rcv_msg_size);
  80. return ret;
  81. }
  82. weak_alias (__mach_msg_overwrite, mach_msg_overwrite)
  83. #endif
  84. mach_msg_return_t
  85. __mach_msg (mach_msg_header_t *msg,
  86. mach_msg_option_t option,
  87. mach_msg_size_t send_size,
  88. mach_msg_size_t rcv_size,
  89. mach_port_t rcv_name,
  90. mach_msg_timeout_t timeout,
  91. mach_port_t notify)
  92. {
  93. mach_msg_return_t ret;
  94. /* Consider the following cases:
  95. 1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
  96. plus special bits).
  97. 2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
  98. 3. RPC calls with interruptions in one/both halves.
  99. */
  100. ret = __mach_msg_trap (msg, option, send_size,
  101. rcv_size, rcv_name, timeout, notify);
  102. if (ret == MACH_MSG_SUCCESS)
  103. return MACH_MSG_SUCCESS;
  104. if (!(option & MACH_SEND_INTERRUPT))
  105. while (ret == MACH_SEND_INTERRUPTED)
  106. ret = __mach_msg_trap (msg, option, send_size,
  107. rcv_size, rcv_name, timeout, notify);
  108. if (!(option & MACH_RCV_INTERRUPT))
  109. while (ret == MACH_RCV_INTERRUPTED)
  110. ret = __mach_msg_trap (msg, option & ~MACH_SEND_MSG,
  111. 0, rcv_size, rcv_name, timeout, notify);
  112. return ret;
  113. }
  114. weak_alias (__mach_msg, mach_msg)
  115. libc_hidden_def (__mach_msg)
  116. mach_msg_return_t
  117. __mach_msg_send (mach_msg_header_t *msg)
  118. {
  119. return __mach_msg (msg, MACH_SEND_MSG,
  120. msg->msgh_size, 0, MACH_PORT_NULL,
  121. MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
  122. }
  123. weak_alias (__mach_msg_send, mach_msg_send)
  124. mach_msg_return_t
  125. __mach_msg_receive (mach_msg_header_t *msg)
  126. {
  127. return __mach_msg (msg, MACH_RCV_MSG,
  128. 0, msg->msgh_size, msg->msgh_local_port,
  129. MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
  130. }
  131. weak_alias (__mach_msg_receive, mach_msg_receive)