Re: Mapping user buffers to kernel space
Re: Mapping user buffers to kernel space
- Subject: Re: Mapping user buffers to kernel space
- From: Joe van Tunen <email@hidden>
- Date: Fri, 23 Apr 2010 13:02:17 -0700
- Thread-topic: Mapping user buffers to kernel space
Title: Re: Mapping user buffers to kernel space
> From: Ken Hornstein <email@hidden>
> Date: Fri, 23 Apr 2010 10:03:06 -0400
>
> (I'm not sure if this should be on filesystem-dev or here; I'm sticking with
> this list for now).
>
> I'm porting a network filesystem to MacOS X. Right now when I get
> VNOP_READ()/VNOP_WRITE() calls to my filesystem, I copy the network data
> using uiomove() into a kernel buffer I allocate, then I send the data
> out over the network via sock_* (reverse that order for reads ... you
> know what I mean).
>
> I am wondering if it is possible to avoid that copy from userspace to
> kernel. The socket I/O functions take struct iov[] which have pointers
> to kernel address space, so I can't just give it the uio structure I
> get as part of the VNOP_READ/VNOP_WRITE arguments. And I haven't yet
> found a function which maps an arbitrary userspace address into kernel
> address space. If the answer is "you can't", then that's fine (but
> unfortunate); I'm just trying to make sure I'm not missing something.
>
> To answer some obvious questions:
>
> - Yes, I should be using the buffer cache. Pretend that I'm just caring
> about the DIRECT_IO case right now.
>
> - I know about the IOMemoryDescriptor calls, but from what I can see the
> way they work is that you have to allocate the buffer using them and
> then give that buffer to userspace. I don't see how to use
> IOMemoryDescriptor on a struct uio.
>
> --Ken
You’re user space code can tell your kext about a user space block of memory (make your own user space memory descriptor type) and the kext can map it into kernel address space.
IOMemoryDescriptor* memDesc = IOMemoryDescriptor::withAddress( (vm_address_t)userAddress, bufferSize, kIODirectionOutIn, userTask );
IOMemoryMap* memMapKernel = memDesc->map( kernel_task, 0, options | kIOMapAnywhere );
The kext should keep track of allocations and dispose of them when the user space code doesn’t need them anymore or if the user space code exits.
_______________________________________________
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