博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Kernel Modules and System Calls
阅读量:5958 次
发布时间:2019-06-19

本文共 2683 字,大约阅读时间需要 8 分钟。

Kernel Modules and System Calls

Creating a "Syscalls" moduleby John BrodieCreating a module for your system calls allows you to make quick changesto your syscalls, without the need to rebuild any of the kernel, and withoutthe need to install/reboot your new kernel version.  However, adding new syscalls via a module is not something supported by thekernel although you can intercept and override existing syscalls(http://www.linuxjournal.com/article/4378, not personally tested).Enter function pointers...1. Create your "wrapper" syscall: - Use a new file (or not):
#include 
#include
#include
long (*STUB_mygetpid)(void) = NULL;EXPORT_SYMBOL(STUB_mygetpid);asmlinkage long sys_mygetpid(void){ if(STUB_mygetpid) return STUB_mygetpid(); else return -ENOSYS;}
The above code creates a null function pointer, exports it for later use, andadds a syscall that will call the function pointer if it has been set.2. Create your module:
#include 
/* Needed by all modules */#include
/* Needed for KERN_INFO */#include
/* Needed for the macros */#include
#include
extern long (*STUB_mygetpid)(void); // Get our function pointerlong mygetpid(void);static int __init init_custom_syscalls(void){ printk(KERN_INFO "Syscalls module loaded...\n"); STUB_mygetpid=&(mygetpid); // Point to our new syscall on load. return 0;}static void __exit cleanup_custom_syscalls(void){ STUB_mygetpid=NULL; // Clean up after ourselves. printk(KERN_INFO "Syscalls module unloaded...\n");}long mygetpid(void){ printk(KERN_INFO "mygetpid called.\n"); return current->tgid;}/* Declare init/exit functions for module. */module_init(init_custom_syscalls);module_exit(cleanup_custom_syscalls);
The above creates a module that gets our function pointer, and points it toour newly created pseudo-syscall function on init.3. Create Makefile for your new files:
obj-m += syscalls.oobj-y += export_syscalls.oall:    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modulesclean:    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
4. Add your wrapper syscall to syscall_table.S, unistd.h, and syscall.h, thesame as you would for a normal syscall.5. Recompile your kernel with `make`, installing it as normal.  From now on,   you only need to touch/recompile your module.6. As root, use `insmod syscalls.ko` to load your module, and `rmmod syscalls`to remove it.  You can tail dmesg to check that it has loaded. From:https://www.cs.drexel.edu/~jjohnson/2012-13/fall/cs543/project/kmod.htm

转载地址:http://zouax.baihongyu.com/

你可能感兴趣的文章
Redis简介以及数据类型存储
查看>>
Tomcat怎么实现异步Servlet
查看>>
Kubernetes部署的最佳安全实践
查看>>
理解C语言——从小菜到大神的晋级之路(8)——数组、指针和字符串
查看>>
Windows Shellcode学习笔记——shellcode在栈溢出中的利用与优化
查看>>
关于多线程中使用SendMessage
查看>>
【云栖大会】阿里云移动云Apsara Mobile重磅发布 推出Cloud Native App全新研发范式...
查看>>
【PMP】Head First PMP 学习笔记 第九章 人力资源管理
查看>>
2015年末必备前端工具集
查看>>
【Solidity】8. 杂项 - 深入理解Solidity
查看>>
关于在VS2005中编写DLL遇到 C4251 警告的解决办法
查看>>
FT Partners CEO:Fintech游戏才刚刚开始,未来真正的关注点在这里
查看>>
Go语言大神亲述:历七劫方可成为程序员!
查看>>
【盘点】2017杭州云栖大会迁云实战Workshop
查看>>
Visual Studio 2008提高工作效率的小技巧
查看>>
深入研究Clang(七) Clang Lexer代码阅读笔记之Lexer
查看>>
对话依图医疗总裁倪浩:AI 产品只是第一步,未来要和医院制定中国儿童骨龄新标准...
查看>>
mysql并行复制
查看>>
Duilib学习笔记《06》— 窗体基类WindowImpBase
查看>>
共筑开放AI生态:ONNX标准得到华为、英特尔等更多厂商支持
查看>>