(2) obtain the task port in the child, prior to execve (the child has
self rights)
(3) send the port from the child to the parent process (the parent
can
then use the port)
How does this part work? I can't figure out how to get a communication
channel from the child to the parent that can transfer a port right.
That was more or less intended for Andy... if you knew enough about
Mach to be using task_info() and introspecting the structure to get VM
information back out in the first place (like Andy was doing), then
you'd sort of be expected to know about this aspect of Mach...
Here's the short version:
You have to send it in a Mach message; specifically, access rights to
a port are granted to a task by sending a "send right" or "receive
right" message to the task you want to be able to use the port; only
one task can hold a receive right at one time, and ports are
unidirectional for the purposes of messaging, so if you expect to do
IPC, you usually get sent a "send" right, create a port, and send a
"send" right back to the task that sent you the "send" right. Then
you talk on the "send" port they sent you, and listen on the port for
which you retained the "receive" right, and the other task does vice
versa.
As far as I know, we don't document this very completely because we
want people to use higher level APIs to ensure that their code is
portable in the face of the possibility of future changes in low level
code. In general terms, the higher level the API, the less likely it
will be to change out from under you without a deprecation process.
This keeps applications from breaking on point releases of the OS. So
this stuff is documented only in source code, and (of course) in Mach
documentation from CMU, MIT, and OSF; here's a pointer to the MIT (GNU
Hurd) documentation for the functions used in sending and receiving of
messages in Mach:
You could probably get a useful example of using this facility by
looking at the source code for "launchd", since launchd implements
port listeners for on-demand starting of programs that provide
services via Mach IPC on Mac OS X, and its sources are published by
Apple.
You could also look at the source code for "task_for_pid()" in the
published xnu kernel sources, and see how it works between processes
(effectively, the API is the same from user or kernel space, since it
involves Mach messages to transfer the rights).
Chapter 9 (specifically, 9.2.*) of the recent Singh book also talks
about how to use this, but only gives partial examples, so if you
aren't coming to it from already having a basic understanding of some
of the code, it won't be useful for this.
Again, if you can live without this information on a per-task basis,
you should attempt to do so.
-- Terry
(4) execve normally (whatever you execve doesn't have to know about
the port)
(5) use the port in the parent process to call task_info() for the
task
--
Greg Parker email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/email@hidden