site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=NfntJmtJh14zi64M7JYqzJ4W9F47XNWMnveVFOYi9J4=; b=bwU/AlNQAe6gQ06qgXXxajQrrToNxln7+yYJMwljTGvYhiGMe8l9lsx9LAOeZwHI0VUU9wECopMb7D6MPrrITVdhl05QirFdOC/Of33WssI0RhtyUjR8lLKnJT9ix+DwXh25Q8FVEtgetMJKTWdCu0tWApkuvJhPEAIpEvndS+w= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=XI641EcKkeXqPrCeCg8bGUTNMIt0vrGeP064WNzjQ2JhEMUjO3goKoumVazV2GgzsyJzj9G006eIhJ2x4UoPrVstXYuZFG5HMWV4Zax/tCbXtvs2r5dL01P+4AVbcLuinbxZeugcPCXU+/DsJ7P7gHKAbIFlD6784bts9yh4ed0= Hi Greg, In the doc there is a small chapter regarding Memory wiring called: Memory Mapping and Block Copying, I guess it's exactly what you asked, as Michael said most people think that not using IOKit is more efficient, for the most of cases, it's really wrong, as you have may be noticed IOKit is not a full C++, it's based on Embedded C++, Iokit provides many facilities and kern controls, If you want re/over/write many of them it's not a problem, some people do it for special devels (and also, for your code "perenity") you can see the evolution of xnu, sometimes there are strong gaps betwen versions especially at kpi level, but, as you want, you can develop a la BSD (your kmod in C) using sysctl, vm APIs ecetera... Cheers! -mmw On Mon, Mar 3, 2008 at 1:15 AM, Michael Smith <drivers@mu.org> wrote:
On Mar 2, 2008, at 11:30 PM, Greg wrote:
Hi, I'm searching for documentation or examples on how to transfer data from a kernel extension written in C to a user-space program. Currently I am using kernel controls to do this, but I would prefer to do this using memory mapping as I feel it would be more efficient, and I think would also simplify my code.
Can you explain why you think it would be more efficient, or that it would simplify your code?
I ask because it's possible that it might, but without seeing your reasoning I can't comment on whether it might actually be, and it's common for folks to think that mapping would be cheaper when in fact it's not.
I've seen one example that uses IOConnectMapMemory in a user-space C program to connect to an IOKit kernel extension written (obviously) in C++. That kernel extension creates an IODataQueue and uses it as shared memory.
Based on this I have two questions:
1) Can I convert my C kernel extension (of the Name_start/Name_stop kind) directly to C++ (by simply changing its file-extension) so that I can use the IODataQueue?
No; you would need to refactor your extension to some degree to do this. It's possible to be a mostly-C extension but participate in the I/O Kit world, but it takes more than just a file renaming.
2) Since I'm guessing the answer to #1 is probably "no", then are there any examples of how to do something like this in a C-based kernel extension? Or any documentation? I do not want to make my kernel extension an IOKit extension.
You have to become an I/O Kit extension to use the IODataQueue. There are other ways to share mapped memory between the kernel and user space however.
I'd like to put/copy data into this shared memory, and upon doing so have the user-space program be notified of the new data so that it can be immediately used/copied.
Unless your data is large, you'll tend to find that copying it along with the notification (as you are currently doing) will be easier and more efficient than trying to manage a shared memory buffer. Again, it would help to be able to put this in perspective with your current workload.
= Mike
_______________________________________________ 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/openspecies%40gmail.com
This email sent to openspecies@gmail.com
-- -mmw _______________________________________________ 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... This email sent to site_archiver@lists.apple.com
participants (1)
-
mm w