Sharing the same VM address space between Kernel and UserSpace

Scott Long scottl at samsco.org
Mon Nov 14 20:57:16 GMT 2005


John Giacomoni wrote:

> I am in need of a way to share memory between kernel space and possibly
> multiple different user-space processes for an extended period of time.
> This memory would need to be a single unpageable region.
> 
> I am using the vm routines as cribbed from mmap, however I'd like the
> address spaces to be viewed as the same regardless of which process I'm
> in to avoid swizzling pointers as I'm storing data structures in the
> shared memory region.
> 
> I imagine I'd need to find a way to expose part of the kernel address
> space to user space to accomplish this.
> 
> Is there a way to do this?
> 
> thanks
> 
> John G
> 

If you get this working then it'll be very useful for the syspage 
support that was talked about recently.

The kernel can access addresses in the user space so long as they
are wired and won't cause a fault.  Thus I imagine that you
only need to allocate the memory, wire it, mark it with the appropriate
page permissions, and reserve a user address range for it in the
process map.  I'd look at the process exec path in the kernel for
places to hook in.  The only other trick then is how to let the user
process know the address for this magic region.  An easy way would be
to store it in a sysctl that can be read at runtime.  A harder way would
be to have the kernel dummy up an elf segment in the image activator
code that the dynamic linker could read and put into a global variable
for the program to access.

Scott



More information about the freebsd-hackers mailing list