How to access kernel memory from user space

Gerry Weaver gerryw at compvia.com
Wed Dec 24 13:22:20 PST 2008


_____  

From: Peter Jeremy [mailto:peterjeremy at optushome.com.au]
To: Gerry Weaver [mailto:gerryw at compvia.com]
Cc: freebsd-hackers at freebsd.org
Sent: Wed, 24 Dec 2008 02:44:45 -0600
Subject: Re: How to access kernel memory from user space

On 2008-Dec-22 18:05:34 -0600, Gerry Weaver <gerryw at compvia.com> wrote:
  >I am working on a driver that collects various network statistics via
  >pfil. I have a simple array of structures that I use to store the
  >statistics. I also have a user space process that needs to collect
  >these statistics every second or so.
  
  The easiest (and hackiest) approach would be to kldsym(2) to locate
  the symbol in KVM and then mmap(2) the relevant part of /dev/kmem.
  The biggest downside is that the userland process needs to be group
  kmem.
  
  The other approach would be for your kernel driver to grow a character
  device node and directly support mmap.
  
  -- 
  Peter Jeremy
  Please excuse any delays as the result of my ISP's inability to implement
  an MTA that is either RFC2821-compliant or matches their claimed behaviour.Hello All,

Happy Holidays Everyone!!

Thanks for the advice Peter. In this case, the driver I'm working on will run on a dedicated
embedded platform, so process group membership shouldn't be an issue. My main 
concern is performance. Any additional overhead will effect the stats, so I want to try
to keep it minimal. Is there any significant trade off in performance between the two
approaches? The typical data array size is around 20k. Also, Is there anything in the source
or ports tree that I could use as an example for the device node case? I've been looking around,
but haven't found anything yet. I'll continue digging though ;-)

Thanks Again,
Gerry


  


More information about the freebsd-hackers mailing list