On 7/21/19 6:21 PM, Laurie Jennings wrote: > > Im wondering if there have been changes to the api since FreeBSD 9 as I can't > get some code I'm porting to work. > I have a block of kernel memory wired down and I want to map it to user > space. Its just a big structure that has stats and other volatile info. In > 9.x I was able to simply do: > // kptr has the kernel address obtained from an ioctl call > > fd=open("/dev/kmem",O_RDWR);memp=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,(off_t)kptr); > > And it just worked. In 11.3 it fails, and I havent been able to get ANYTHING > to work with this method. I'm open to another method; I read something about > mmap no longer supportinjgkmem. In which case, what can I do?
Supporting arbitrary mmap of /dev/kmem is not safe as the user mappings weren't updated if the kernel mappings changed. To do what you want, you would create a dedicated device in /dev that you can mmap to access your data structure. The simplest way is to just have your device's d_mmap callback use the offset as an offset into your in-kernel pointer and then use pmap_kextract() to get the physical address to return. A fancier version would be to build an sglist describing your buffer and create an OBJT_SG VM object that you returned from the d_mmap_single callback, but if you only ever have a single object that is never freed, the simple version will work fine. -- John Baldwin _______________________________________________ freebsd-net@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-net To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"