Re: darwin-kernel: convert pid to a task right?
Re: darwin-kernel: convert pid to a task right?
- Subject: Re: darwin-kernel: convert pid to a task right?
- From: Jim Magee <email@hidden>
- Date: Tue, 13 Aug 2002 19:46:10 -0400
On Tuesday, August 13, 2002, at 05:28 PM, Joshua LeVasseur wrote:
I want a client program to send a mach message to a server program.
But
I know of no mechanism to communicate the server's port send name to
the
client. The typical paradigm uses a third party name server, to which
the server registers its service port, and to which the client can
query
for port rights to the server. The client obtains access to the name
server's port during the process bootstrap.
Try task_get_bootstrap_port(mach_task_self(), &my_bootstrap_port) or
just using the bootstrap_port global variable. Neither of these should
be NULL.
The array forms (mach_ports_register() and mach_ports_lookup()) are
obsolete (which probably explains why they panic and we didn't notice).
It seems like you may be working from an old Mach 2.5 documentation
(forgetting to insert a send right is common problem when converting
from Mach 2.5 to Mach 3.0). You may want to look at the later Darwin
documentation, and specifically the "Bootstrap Contexts Unleashed"
chapter:
http://developer.apple.com/techpubs/macosx/Darwin/General/
KernelProgramming/index.html
The book title is a bit misleading. It is more about using the kernel
services than programming within the kernel.
My Darwin install seems to operate without a name server. The
bootstrap
ports are all nil, if I inspect them via mach_ports_lookup(). I tried
installing my own server ports in the bootstrap ports via
mach_ports_register(), but that only causes a kernel panic.
As I said in another message, I'm looking into the panic. But the
mach_init process should be running on your Darwin system, and it is
the bootstrap Mach port name server that handles bootstrap_register()
and bootstrap_look_up() RPCs and should be the default bootstrap server
for all tasks in the system.
So for an alternative solution, if I want a server to give send rights
to a client, I can make the server the parent of the client. Then the
server can execute mach_port_insert_right() on the child task to
transfer the send rights. But the parent needs to know the task port
of
the child process. The parent should get the task port when it calls
task_create(). But in Darwin, task_create() is hidden behind fork().
And so the parent has the child's pid, but not the child's task port.
Is there anyway to convert a pid to a task right?
There is, it's called task_for_pid(), but you should restrict your
usage of it if you can avoid it. You shouldn't need it in this case.
--Jim
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.