mach_rpc.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 1994 The University of Utah and
  3. * the Computer Systems Laboratory (CSL). All rights reserved.
  4. *
  5. * Permission to use, copy, modify and distribute this software is hereby
  6. * granted provided that (1) source code retains these copyright, permission,
  7. * and disclaimer notices, and (2) redistributions including binaries
  8. * reproduce the notices in supporting documentation, and (3) all advertising
  9. * materials mentioning features or use of this software display the following
  10. * acknowledgement: ``This product includes software developed by the
  11. * Computer Systems Laboratory at the University of Utah.''
  12. *
  13. * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
  14. * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
  15. * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  16. *
  17. * CSL requests users of this software to return to csl-dist@cs.utah.edu any
  18. * improvements that they make and grant CSL redistribution rights.
  19. *
  20. */
  21. #pragma GCC diagnostic error "-Wundef"
  22. #ifdef MIGRATING_THREADS
  23. #include <glue/gnulinux.h>
  24. #include <kern/printf.h>
  25. #include <mach/kern_return.h>
  26. #include <mach/port.h>
  27. #include <mach/rpc.h>
  28. #include <mach/notify.h>
  29. #include <mach/mach_param.h>
  30. #include <mach/vm_param.h>
  31. #include <mach/vm_prot.h>
  32. #include <kern/task.h>
  33. #include <kern/act.h>
  34. #include <vm/vm_map.h>
  35. #include <vm/vm_kern.h>
  36. #include <vm/vm_user.h>
  37. #include <ipc/ipc_entry.h>
  38. #include <ipc/ipc_space.h>
  39. #include <ipc/ipc_object.h>
  40. #include <ipc/ipc_notify.h>
  41. #include <ipc/ipc_port.h>
  42. #include <ipc/ipc_pset.h>
  43. #include <ipc/ipc_right.h>
  44. #undef DEBUG_MPRC
  45. /*
  46. * XXX need to identify if one endpoint of an RPC is the kernel to
  47. * ensure proper port name translation (or lack of). This is bogus.
  48. */
  49. #define ISKERNELACT(act) ((act)->task == kernel_task)
  50. /*
  51. * Copy the indicated port from the task associated with the source
  52. * activation into the task associated with the destination activation.
  53. *
  54. * XXX on errors we should probably clear the portp to avoid leaking
  55. * info to the other side.
  56. */
  57. kern_return_t
  58. mach_port_rpc_copy(
  59. struct rpc_port_desc *portp,
  60. struct Act *sact,
  61. struct Act *dact)
  62. {
  63. ipc_space_t sspace, dspace;
  64. mach_msg_type_name_t tname;
  65. ipc_object_t iname;
  66. kern_return_t kr;
  67. #ifdef DEBUG_MPRC
  68. printf("m_p_rpc_copy(portp=%x/%x, sact=%x, dact=%x): ",
  69. portp->name, portp->msgt_name, sact, dact);
  70. #endif
  71. sspace = sact->task->itk_space;
  72. dspace = dact->task->itk_space;
  73. if (sspace == IS_NULL || dspace == IS_NULL) {
  74. #ifdef DEBUG_MPRC
  75. printf("bogus src (%x) or dst (%x) space\n", sspace, dspace);
  76. #endif
  77. return KERN_INVALID_TASK;
  78. }
  79. if (!MACH_MSG_TYPE_PORT_ANY(portp->msgt_name)) {
  80. #ifdef DEBUG_MPRC
  81. printf("invalid port type\n");
  82. #endif
  83. return KERN_INVALID_VALUE;
  84. }
  85. if (ISKERNELACT(sact)) {
  86. iname = (ipc_object_t) portp->name;
  87. ipc_object_copyin_from_kernel(iname, portp->msgt_name);
  88. kr = KERN_SUCCESS;
  89. } else {
  90. kr = ipc_object_copyin(sspace, portp->name, portp->msgt_name,
  91. &iname);
  92. }
  93. if (kr != KERN_SUCCESS) {
  94. #ifdef DEBUG_MPRC
  95. printf("copyin returned %x\n", kr);
  96. #endif
  97. return kr;
  98. }
  99. tname = ipc_object_copyin_type(portp->msgt_name);
  100. if (!IO_VALID(iname)) {
  101. portp->name = (mach_port_t) iname;
  102. portp->msgt_name = tname;
  103. #ifdef DEBUG_MPRC
  104. printf("iport %x invalid\n", iname);
  105. #endif
  106. return KERN_SUCCESS;
  107. }
  108. if (ISKERNELACT(dact)) {
  109. portp->name = (mach_port_t) iname;
  110. kr = KERN_SUCCESS;
  111. } else {
  112. kr = ipc_object_copyout(dspace, iname, tname, TRUE,
  113. &portp->name);
  114. }
  115. if (kr != KERN_SUCCESS) {
  116. ipc_object_destroy(iname, tname);
  117. if (kr == KERN_INVALID_CAPABILITY)
  118. portp->name = MACH_PORT_DEAD;
  119. else {
  120. portp->name = MACH_PORT_NULL;
  121. #ifdef DEBUG_MPRC
  122. printf("copyout iport %x returned %x\n", iname);
  123. #endif
  124. return kr;
  125. }
  126. }
  127. portp->msgt_name = tname;
  128. #ifdef DEBUG_MPRC
  129. printf("portp=%x/%x, iname=%x\n", portp->name, portp->msgt_name, iname);
  130. #endif
  131. return KERN_SUCCESS;
  132. }
  133. kern_return_t
  134. mach_port_rpc_sig(const ipc_space_t space, const char *name, const char *buffer, unsigned int buflen)
  135. {
  136. return KERN_FAILURE;
  137. }
  138. #endif /* MIGRATING_THREADS */