mach_userland.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <stdlib.h>
  2. #include <assert.h>
  3. #include <stdio.h>
  4. #include <mach.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <sys/ioctl.h>
  10. #include <mach/mach_kernel.h>
  11. static mach_port_t mach_task_self_=0;
  12. extern mach_msg_return_t
  13. mach_msg
  14. (mach_msg_header_t *msg,
  15. mach_msg_option_t option,
  16. mach_msg_size_t send_size,
  17. mach_msg_size_t rcv_size,
  18. mach_port_t rcv_name,
  19. mach_msg_timeout_t timeout,
  20. mach_port_t notify)
  21. {
  22. struct mach_msg_args args;
  23. args.msg = msg;
  24. args.option = option;
  25. args.send_size = send_size;
  26. args.rcv_size = rcv_size;
  27. args.rcv_name = rcv_name;
  28. args.timeout = timeout;
  29. args.notify = notify;
  30. return ioctl(MACH_TRAP_DUMMY_FD,NR_mach_msg,&args);
  31. }
  32. #if 0
  33. mach_port_t mig_get_reply_port()
  34. {
  35. //TODO 3
  36. }
  37. void mig_dealloc_reply_port (mach_port_t port)
  38. {
  39. //TODO 4
  40. }
  41. void mig_put_reply_port (mach_port_t port)
  42. {
  43. //TODO 5
  44. }
  45. #endif
  46. mach_port_t mach_task_self()
  47. {
  48. return mach_task_self_;
  49. }
  50. kern_return_t mach_port_allocate
  51. (ipc_space_t task,
  52. mach_port_right_t right,
  53. mach_port_t *name)
  54. {
  55. struct mach_port_allocate_args args;
  56. args.task = task;
  57. args.right = right;
  58. args.name = name;
  59. return ioctl(MACH_TRAP_DUMMY_FD,NR_mach_port_allocate,&args);
  60. }
  61. void gnumach_init(void)
  62. {
  63. //ioctl(MACH_TRAP_DUMMY_FD,0);//get api version
  64. mach_task_self_ = ioctl(MACH_TRAP_DUMMY_FD,NR_mach_task_self);
  65. }