ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I am looking into creating a simulation of a hardware device. This hardware device is directly mapped into memory and its registers and memory are accessed that way in user space.
What I would like to be able to do is when a certain memory area (that I control via mapping or allocation of some type) is written, I would like to get some type of an interrupt or signal so that I can asynchronously get information written into a virtual register and use it. I would also like to get interrupted or signaled when a certain memory area is read so that I can update whatever is accessing it with the very latest information and results of some processing that I need to do.
My initial thinking was to use either SIGSEGV or some type of page fault handler in a module. My problem is that I believe I may be able to get this to work for one access, but I may have to make the memory area valid in the handler in order for the user code to continue so therefore it would not interrupt/signal on the next access. Does anyone know if these ideas would work? Are there other ideas anyone has?
I don't have experience with your sort of problem, but my initial thought is to create a kernel module that creates a character device, give it a set of ioctls to protect or unprotect certain memory areas, then mmap that character device as "shared" and use the mapped memory for your virtual machine. All the module would need to do is maintain a table of protected memory addresses and create a signal if there's a violation. I'm sure there's a better way than this other than actually changing the protection of memory in the process' memory table, but I don't know that I'm awake enough to think it through any more than that.
I feel silly for not thinking of this before, but you could create two shared mappings using the same underlying file: one R/O for the virtual machine and the other R/W for the program managing it. They would both be the same memory, but the managing program would be able to make direct conversions between the R/O and R/W versions with simple pointer arithmetic.
The requirement for this went away for a while so I haven't been thinking much about it. This seems logical for doing what I need at least on a write access. I will pursue this further when it comes up again. Thanks.