Re: Memory Mapping examples/documentation?
Re: Memory Mapping examples/documentation?
- Subject: Re: Memory Mapping examples/documentation?
- From: "mm w" <email@hidden>
- Date: Mon, 3 Mar 2008 08:23:49 -0800
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 <email@hidden> 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 (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
--
-mmw
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden