123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- (define-module (mach port-move)
- #:export (port-insert-right! port-extract-right!)
- #:use-module (mach msg-type)
- #:use-module (mach ffi)
- #:use-module (mach task)
- #:use-module (mach types))
- ;; Documentation: (mach)Ports and other Tasks
- (define-ffi ("mach_port_insert_right" %mach-port-insert-right!)
- ;; One of kern:success, kern:invalid-task, kern:invalid-value,
- ;; kern:name-exist, kern:invalid-capability, kern:right-exists,
- ;; kern:user-references-overlow, kern:resource-shortage,
- ;; or an error code from 'mach_msg'.
- (err identity)
- (task ffi:ipc-space %unwrap-ipc-space)
- (port-name ffi:mach-port %unwrap-mach-port)
- (right ffi:mach-port %unwrap-mach-port)
- (right-type ffi:msg-type-name %unwrap-msg-type-name))
- (define* (port-insert-right! port-name right right-type
- #:optional (task (task-self)))
- "Insert the specified port right into the target task @var{task}
- (by default, the caller's task). The port will be named
- @var{port-name} (a @code{ffi:mach-port} in the target task, and the right
- @var{right} (a @code{ffi:mach-port}) will be taken from the caller.
- @var{port-name} and @var{right} may not be @code{%port:null} or
- @code{%port:dead}.
- @var{right-type} must be a @code{ffi:msg-type-name} denoting a kind of
- port right to insert.
- TODO document error codes."
- (%mach-port-insert-right! task port-name right right-type))
- (define-ffi ("mach_port_extract_right" %mach-port-extract-right)
- (err identity)
- (task ffi:ipc-space %unwrap-ipc-space)
- (name ffi:mach-port %unwrap-mach-port)
- (desired-type ffi:msg-type-name %unwrap-msg-type-name)
- (right ffi:pointer identity)
- (acquired-type ffi:pointer identity))
- (define* (port-extract-right! name desired-type #:optional (task (task-self)))
- "Extracts a port right @var{name} from the target task @var{task} and
- returns it to the caller as if the task sent the right voluntarily.
- @var{desired-type} must be a @code{ffi:msg-type-name} denoting a kind of
- port right to extract.
- TODO document error codes and return values. What about acquired-type?"
- ;; Any initial value will do.
- (with-foreign-variables*
- ((acquired-right %acquired-right ffi:mach-port %port:null)
- (acquired-type %acquired-type ffi:msg-type-name 0))
- (let ((return-code
- (%mach-port-extract-right task name desired-type
- %acquired-right %acquired-type)))
- ;; TODO figure out the select-error macro
- (select-error return-code (values acquired-right acquired-type)))))
|