如何在内核模式下写入某些进程的虚拟内存
我想使用我的 Unix 模块写入另一个进程内存(我想在内核模式下执行此操作并避免使用 pthread 接口)。
我必须使用影响当前进程内存的函数(如 do_mmap(..)、do_unmmap(..)、sys_mprotect(..) 等),而不是我希望它影响的进程。
所以我想,我需要找到一种方法来进行上下文切换到我想要的进程,以便使我想要的进程成为当前进程。我尝试复制 Schedule() 的实现并进行一些细微的更改: 我替换了该行:
next = pick_next_task(rq);
与:
下一个= myNext;
我的问题是时间表需要太多我无法包含的结构和函数,所以我必须重新实现它们。做这样的事似乎很糟糕。您有什么建议吗?
我想避免修改现有的内核,因此我不必强迫用户重新启动并修改他们的操作系统才能使用我的程序(这就是我使用模块的原因)。
顺便说一下,我使用的是“2.6.38-11-generic”版本的Linux。
I want to use my Unix module in order to write to another process memory (I would like to do it in kernel mode and avoid the pthread interface).
I have to use function (like do_mmap(..), do_unmmap(..), sys_mprotect(..), etc.) which affect the current process memory instead of the process I'd like to it to affect.
So I figured, I need find a way to do a context switch to the process I want in order to make the process I want the current. I tried to copy the implementation of the schedule() with a minor change:
I replaced the line:
next = pick_next_task(rq);
with:
next = myNext;
My problem is that schedule requires so much structs and functions which I can't include, so I have to re-implement them. it seems pretty bad to do such a thing. Do you have any suggestions?
I want to avoid to modify the existing kernel, so I won't have to force the users to restart and modify their operating system in order to use my program (which is why I use modules).
By the way, I use the "2.6.38-11-generic" version of Linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
kmap()
或kmap_atomic()
映射您需要的页面(取决于上下文)kunmap()
或kunmap_atomic()
销毁映射kmap()
orkmap_atomic()
(depending on the context)kunmap()
orkunmap_atomic()