https://bugs.winehq.org/show_bug.cgi?id=37355
--- Comment #21 from Richard Yao ryao@gentoo.org --- To improve on my previous comment, this probably should be implemented as a wine server service. Upon being asked to do it, the requesting “kernel process” could block on recvmsg with the wineserver. Then the wineserver could attach ptrace to the target process and then:
1. Insert the information needed to service the request. 2. Save the registers to a predefined region. 3. Change the instruction pointer to jump into the interrupt handler.
Before finally letting the process continue:
Then the interrupt handler could do the messy stuff that I described previously, send the file descriptor to the wineserver with sendmsg and resume execution. Now, the wineserver can simply send the file descriptor to the “kernel process”.
This makes it easier to handle concurrent usage of this API. Specifically, calls to the API could be serialized would make implementation easier.
There would be more to it than this (especially when the function is called to map invalid or already shared memory), but this should be doable as long as the goal is to simulate a “mmap” that lets you map already existent regions of memory that pre-existing regions.
Another idea that could also work would be if the wineserver kept file descriptors for all memory regions mapped into child processes. Then when shared memory is desired, it could just call dup on the file descriptor, call lseek on the duplicated file descriptor, send it to the child to mmap and then close the duplicate on its end. The child could close it too after mmap’ing it. This would also require keeping track of where everything is mapped with reference counters, but it would easier to be convinced of correctness and there would be no issue from having to do memcopy() and worry about whether this is on memory already shared across multiple processes.
You would have to worry about running out of file-descriptors unless you do a hack where you let child processes hold onto the file descriptors for the wineserver until it needs it to bypass the system limit on the maximum number of file descriptors open by a process.