Re: User-space to kernel communication
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com - Greg On Jan 8, 2007, at 8:04 PM, Brian Bergstrand wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jan 8, 2007, at 6:18 PM, Greg wrote: typedef struct { unsigned char buffer[256]; unsigned char bufferSize; } MyIOUserClientArg; Then just cast 'buffer' as needed. The interesting bits as far as kernel<->user communication are in: pplib/ppmsg.h pplib/pplib.c kern/PeerProtector.c kern/pp_session.c kern/pplog.c - Greg On Jan 8, 2007, at 7:07 PM, Brian Bergstrand wrote: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jan 8, 2007, at 5:41 PM, Greg wrote: - Greg On Jan 8, 2007, at 6:17 PM, Greg Miller wrote: G~ - Greg On Jan 8, 2007, at 3:15 PM, Josh Graessley wrote: Brian Bergstrand <http://www.bergstrand.org/brian/> PGP Key ID: 0xB6C7B6A2 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin) iD8DBQFFouoOedHYW7bHtqIRAmtZAJ4hLO5Ip3DX8dAVZHxlyd5chFcxmQCfQX7p g3XhL63bYRraNiZPGHU4csw= =Z7ob -----END PGP SIGNATURE----- _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... Thanks for pointing this out! I've looked into this some more and found documentation on kernel control sockets here: http://developer.apple.com/documentation/Darwin/Conceptual/ NKEConceptual/index.html?http://developer.apple.com/documentation/ Darwin/Conceptual/NKEConceptual/control/chapter_3_section_2.html This looks very interesting and so far it seems to be exactly what I want as it uses a familiar API (bsd sockets) and allows for bidirectional communication. With this available I don't see why anyone would want to use sysctl or the IOUserClient stuff... are there any disadvantages associated with using kernel control sockets over the aforementioned sysctl/IOConnectMethod stuff?
From what I've read about IOUserClient and its IOConnectMethod*'s, it does not seem like they support passing variable length data. Perhaps I'm missing something, could you point me to what you're referring to or perhaps a code example?
No, you'd have to combine memory mapping with an IOUserKitClient to get true variable length support (by passing a ptr in a struct arg to your method). However, you say you only need around 50 bytes, so just have a static buffer in your struct large enough to fix the max amount of data: As for an example, that's about all I can give you for IOUserClient, but I do have a public project that uses a kernel control socket to send variable sized data if you are interested in seeing that: http://prdownloads.sourceforge.net/peerguardian/ PeerGuardianSrc_1.4.2.zip?download There is no "correct" way. There are ways that make more "sense" given your current setup, but that's about it. If you want bi- directional communication and you are already an IOKit kext, the easiest method will be an IOUserClient nub (as Josh already stated). You could also easily use a kernel control socket or memory mapping (from personal experience, the former is a tad easier than the latter because of certain kernel restrictions on mapping memory from userland into the kernel). Also from personal experience, sysctls and ioctls do not make for easy bi-directional communication channels. Sorry for the followup, but perhaps somebody could just advice me on a specific method. That document does provide details for the sysctl API but skims over memory-mapping and a few others. Apple provides an IODataQueue example but that is only for kernel -> user-client communication, I'm not exactly sure how I would reverse that direction. However, it seems that sysctl is a viable option for my purposes. It does seem to be able to handle variable length data of moderate size, I guess I'll just use that. The reason for my confusion is simply the shear number of options and the rather sparse documentation on them; I'm just trying to find the "correct" way of doing this... Take a look at the document at http://developer.apple.com/documentation/Darwin/Conceptual/ KernelProgramming/boundaries/chapter_14_section_1.html#// apple_ref/doc/uid/TP30000905-CH217-DontLinkElementID_9 On 1/8/07, Greg <greg@kinostudios.com> wrote: Like I said, I'm trying to send the kernel variable length data of around 50 bytes. I am using the IOKit but I would also like to know how to do this without it. Is there any documentation on this? I would really prefer to avoid blindly going through header files.
This depends on what you are trying to communicate with in the
kernel. If you are already using IOKit, I would imagine an
IOUserClient would be the way to go. If you're writing a non- IOKit
kext, you may want to look in to a kernel control socket (sys/
kern_control.h).
-josh
On Jan 7, 2007, at 6:40 PM, Greg wrote:
Hi, what is the best way(s) to send variable length data (around
50 bytes or so) to a kernel extension from a user-land
application? Are there different ways to do this if the kext uses
the IOUserClient schema to talk to user-land apps? If you could
also point me to documentation or a tutorial on how to do this I
would be much obliged!
Thanks,
This email sent to site_archiver@lists.apple.com
participants (1)
-
Greg