Re: IPC: interprocess communications
Re: IPC: interprocess communications
- Subject: Re: IPC: interprocess communications
- From: Quinn <email@hidden>
- Date: Sun, 7 Dec 2003 08:56:41 +0000
At 1:31 -0700 7/12/03, Matt Jaffa wrote:
I wrote this KEXT, a NKE, and I want to communicate with this daemon
that i will have running, so that the daemon can do all the reading
and writing to files since it is not smart to do it in the kernel,
How do I communicate between the two,
The best approach in this particular context is to use a socket. The
reason for this choice is that your KEXT is already knee deep in
sockets code, so it makes sense to use sockets for the user space
communication. An alternative approach (Mach messages, I/O Kit user
client, etc) might make sense if you're KEXT was plugged into the
kernel in some other place.
If you're looking for an example of this, grab the WebDAV file system
code from Darwin.
<
http://www.opensource.apple.com/darwinsource/tarballs/apsl/webdavfs-148.2.tar.gz>
[This link requires an APSL <
http://www.opensource.apple.com/apsl/> account.]
I know that if you match the KEXT from within the daemon you can
call the KEXT methods, but is there any way that the KEXT can start
the communication.
The best way to handle this is to have your user space daemon call
into the kernel to request work from the KEXT. When the KEXT has
work for the daemon to do, it sends a parameter block describing the
request to the socket, and unblocks the user space daemon. The
daemon does the work and calls back into the kernel with the results,
and then blocks waiting for the next request.
Most people new to Mac OS X kernel programming try to use some sort
of callout mechanism, where the kernel actually tries to call user
space code. This is not the right approach.
When programming this sort of communication, you have to be careful
about what happens when there's no user space daemon thread waiting
to pick up your request. This may just be a temporary condition, or
it may be that the daemon has crashed. For reliability reasons it is
important that your kernel code has a sensible alternative strategy.
For example, a firewall NKE might switch into "deny everything" or
"allow everything" mode, depending on the level of user paranoia.
S+E
--
Quinn "The Eskimo!" <
http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
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.