Reputation: 2896
In a linux kernel syscall, I want to map a region of memory in a similar manner as calling mmap
from user mode. If I wanted to map the region for the current process, I could simply use do_mmap_pgoff
. Instead, however, I want to map the region in a different process while running in kernel mode. do_mmap_pgoff
assumes/knows it is mapping for the current process and does not allow for anything else.
What I am planning on doing is replicating do_mmap_pgoff to take extra arguments specifying the task_struct and mm_struct of whatever process I want to map. However, this is very undesirable as I must manually traverse through many functions in the kernel source and essentially make duplicates of those functions so that they no longer assume they are doing work on behalf of current
.
Is there a better way to map memory in a process other than current
while operating in kernel mode?
Upvotes: 3
Views: 1531
Reputation: 4108
It's no surprise that those functions in kernel source assume that they change the mapping of the current process, and that it hasn't changed in the 20 years Linux exists. There's a reason why processes don't change memory mappings of other processes.
It's very "un-UNIXy".
If you elaborate on what you are trying to accomplish then perhaps people can suggest a more UNIX-y way for it.
Anyway, to focus on the question at hand, if you wouldn't like to perform hefty modifications to mm/* code, then I suggest you implement a workaround:
/sys
or /proc
file. Or, in a non-modular way: modify a system call that is being called frequently, or another code path - for example the signal handling code.do_mmap_pgoff()
, and it can be implemented using mechanisms exposed in linux/wait.h.Upvotes: 1