内核线程之User-Mode Helpers
这次学习下如何在Linux内核态执行用户态程序,这就要用到User-Mode Helpers,为什么要这么“逆操作”呢?有些与平常用户态系统调用内核态反着来,其实在U盘热插拔时,就需要用到该功能了,当U盘插入时,驱动识别到U盘设备,最终需要调用用户态的程序和设定好的规则来将其挂载起来,还有其他的应用场景也需要这样的操作,自己好好探索下吧。 接下来说说关于User-Mode Helpers,下面是相关的函数(在kernel/kmod.c文件中有定义,下面只给出函数头和函数体较少的代码): 1.call_usermodehelper_setup struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, char **envp, gfp_t gfp_mask, int (*init)(struct subprocess_info *info, struct cred *new), void (*cleanup)(struct subprocess_info *info), void *data) ; 2.call_usermodehelper_exec int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait) ; 3.call_usermodehelper int call_usermodehelper(char *path, char **argv, char **envp, int wait) { struct subprocess_info *info; gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; info = call_usermodehelper_setup(path, argv, envp, gfp_mask, NULL, NULL, NULL); if (info == NULL) re...