wiring/unwiring memory
wiring/unwiring memory
- Subject: wiring/unwiring memory
- From: Andrew Gallatin <email@hidden>
- Date: Thu, 17 Jan 2002 15:39:03 -0500 (EST)
I've ported an OS-bypass network driver to Darwin / OS-X.
However, I have one serious problem that I need advice on.
The driver wires memory for user-level applications. These apps use
this memory for communications with other nodes on the network
(send/recv from/to the wired memory, no kernel involvement once the
wiring is setup, similar to VI).
The sequence of events is that the app mallocs some memory, ioctl's the
driver to get it wired (the driver also gets the DMA handle to the
physical memory & tells the nic about it). The app then communicates
using the wired memory. Sometime later, the app ioctl's the driver,
which shoots down the nic's association with that dma handle & unwires
the memory. The app then frees the memory.
Right now I'm using IOMemoryDescriptor::withAddress() to get a memory
descriptor for the user's memory & using prepare() to wire it, and
complete() to unwire it. This works quite well in the common case.
However, a poorly written app which free's the memory prior to
deregistering it will end up waiting forever in vm_map_delete()
for the driver to unwire the memory. The driver has no idea the app
tried to free the memory, so it will never unwire it.
I'd like to have the user app be able to free the memory, but have the
driver be able to hold onto it until the unwiring happens (in the
worst case, close on the special device will trigger the driver to
tear down everything). Are there any manipulations I can do from
within IOKit to achieve this?
Thanks for the advice..
Drew