task.scm 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. (define-module (mach task)
  2. #:export (task-self task-get-special-port task-get-bootstrap-port)
  3. #:use-module (mach ffi)
  4. #:use-module (mach types))
  5. (define-ffi ("mach_task_self" %mach-task-self)
  6. (ffi:ipc-space identity))
  7. ;; TODO: is this a new send right?
  8. ;; That is, do we need to deallocate this eventually?
  9. (define (task-self)
  10. "Return a send right associated with the task_self port"
  11. (%mach-task-self))
  12. (define-ffi ("task_get_special_port" %task-get-special-port)
  13. (err identity) ; XXX ???
  14. (task ffi:task %unwrap-task)
  15. (what special-port-type %unwrap-special-port-type)
  16. (port-box '* identity)) ;; <-- IIUC, the port will be written there.
  17. ;; XXX what is WHAT?
  18. ;; XXX what is a ‘send write’?
  19. (define* (task-get-special-port what #:optional (task (task-self)))
  20. "Return a send write to the indicated special port."
  21. ;; The initial value of the foreign box does not matter.
  22. (let* ((port-box (make-c-struct '* %null-pointer))
  23. (return-code (%task-get-special-port task what port-box)))
  24. (select-error return-code
  25. (%wrap-mach-port (dereference-pointer port-box)))))
  26. (define* (task-get-bootstrap-port #:optional (task (task-self)))
  27. "Return a send write to the bootstrap port."
  28. ;; XXX where is :task-bootstrap-port defined?
  29. (task-get-special-port :task-bootstrap-port task))