notify-wrapper.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* notify.defs wrapper code.
  2. Copyright (C) 2008 Free Software Foundation, Inc.
  3. Written by FlÃvio Cruz <flaviocruz@gmail.com>
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include <mach/boolean.h>
  16. #include <mach/kern_return.h>
  17. #include <mach/message.h>
  18. #include <mach/mig_errors.h>
  19. #include <mach/mig_support.h>
  20. #include <mach/std_types.h>
  21. #include <mach/mach_types.h>
  22. #include <device/device_types.h>
  23. #include <device/net_status.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/statfs.h>
  27. #include <sys/resource.h>
  28. #include <sys/utsname.h>
  29. #include <hurd/hurd_types.h>
  30. #include <stdio.h>
  31. #include <assert.h>
  32. #include "notify-wrapper.h"
  33. /* this is NULL initialized */
  34. static void *routines[_NUMBER_OF_ROUTINES];
  35. /* function wrappers follows... */
  36. /* do mach notify port deleted */
  37. typedef kern_return_t (*do_mach_notify_port_deleted_type) (mach_port_t,
  38. mach_port_t name);
  39. kern_return_t
  40. lisp_do_mach_notify_port_deleted (mach_port_t notify, mach_port_t name)
  41. {
  42. if (routines[DO_MACH_NOTIFY_PORT_DELETED] == NULL)
  43. {
  44. return 0;
  45. }
  46. do_mach_notify_port_deleted_type do_mach_notify_port_deleted_routine =
  47. routines[DO_MACH_NOTIFY_PORT_DELETED];
  48. return do_mach_notify_port_deleted_routine (notify, name);
  49. }
  50. /* do mach notify msg accepted */
  51. typedef kern_return_t (*do_mach_notify_msg_accepted_type) (mach_port_t,
  52. mach_port_t);
  53. kern_return_t
  54. lisp_do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t name)
  55. {
  56. if (routines[DO_MACH_NOTIFY_MSG_ACCEPTED] == NULL)
  57. {
  58. return 0;
  59. }
  60. do_mach_notify_msg_accepted_type do_mach_notify_msg_accepted_routine =
  61. routines[DO_MACH_NOTIFY_MSG_ACCEPTED];
  62. return do_mach_notify_msg_accepted_routine (notify, name);
  63. }
  64. /* do mach notify port destroyed */
  65. typedef kern_return_t (*do_mach_notify_port_destroyed_type) (mach_port_t,
  66. mach_port_t);
  67. kern_return_t
  68. lisp_do_mach_notify_port_destroyed (mach_port_t notify, mach_port_t rights)
  69. {
  70. if (routines[DO_MACH_NOTIFY_PORT_DESTROYED] == NULL)
  71. {
  72. return 0;
  73. }
  74. do_mach_notify_port_destroyed_type
  75. do_mach_port_notify_port_destroyed_routine =
  76. routines[DO_MACH_NOTIFY_PORT_DESTROYED];
  77. return do_mach_port_notify_port_destroyed_routine (notify, rights);
  78. }
  79. /* do mach notify no senders */
  80. typedef kern_return_t (*do_mach_notify_no_senders_type) (mach_port_t,
  81. mach_port_mscount_t);
  82. kern_return_t
  83. lisp_do_mach_notify_no_senders (mach_port_t notify,
  84. mach_port_mscount_t mscount)
  85. {
  86. if (routines[DO_MACH_NOTIFY_NO_SENDERS] == NULL)
  87. {
  88. return EOPNOTSUPP;
  89. }
  90. do_mach_notify_no_senders_type do_mach_notify_no_senders_routine =
  91. routines[DO_MACH_NOTIFY_NO_SENDERS];
  92. return do_mach_notify_no_senders_routine (notify, mscount);
  93. }
  94. /* do mach notify send once */
  95. typedef kern_return_t (*do_mach_notify_send_once_type) (mach_port_t);
  96. kern_return_t
  97. lisp_do_mach_notify_send_once (mach_port_t notify)
  98. {
  99. if (routines[DO_MACH_NOTIFY_SEND_ONCE] == NULL)
  100. {
  101. return 0;
  102. }
  103. do_mach_notify_send_once_type do_mach_notify_send_once_routine =
  104. routines[DO_MACH_NOTIFY_SEND_ONCE];
  105. return do_mach_notify_send_once_routine (notify);
  106. }
  107. /* do mach notify dead name */
  108. typedef kern_return_t (*do_mach_notify_dead_name_type) (mach_port_t,
  109. mach_port_t);
  110. kern_return_t
  111. lisp_do_mach_notify_dead_name (mach_port_t notify, mach_port_t name)
  112. {
  113. if (routines[DO_MACH_NOTIFY_DEAD_NAME] == NULL)
  114. {
  115. return EOPNOTSUPP;
  116. }
  117. do_mach_notify_dead_name_type do_mach_notify_dead_name_routine =
  118. routines[DO_MACH_NOTIFY_DEAD_NAME];
  119. return do_mach_notify_dead_name_routine (notify, name);
  120. }
  121. static const char *
  122. routine_to_str (const NotifyRoutine rot)
  123. {
  124. #define RET(val) case val: return #val ;
  125. switch (rot)
  126. {
  127. RET (DO_MACH_NOTIFY_PORT_DELETED)
  128. RET (DO_MACH_NOTIFY_MSG_ACCEPTED)
  129. RET (DO_MACH_NOTIFY_PORT_DESTROYED)
  130. RET (DO_MACH_NOTIFY_NO_SENDERS)
  131. RET (DO_MACH_NOTIFY_SEND_ONCE)
  132. RET (DO_MACH_NOTIFY_DEAD_NAME)
  133. case _NUMBER_OF_ROUTINES:
  134. default:
  135. return "";
  136. }
  137. #undef RET
  138. }
  139. #include "common.c"
  140. COMMON_FUNCTIONS (notify);