我是内核编程的新手,正在尝试在linux内核3.19中实现系统调用,该系统跟踪链接列表中的进程。因此,每次从用户空间(通过某些包装函数)调用系统调用时,都必须将新进程添加到该列表中。我的系统调用看起来像
asmlinkage long sys_newcall(pid_t pid)
{
/*
* mytasks is the name of the structure
* kmalloc() is invoked to create an instance
*/
struct mytasks newTask = kmalloc(sizeof(struct mytasks), GFP_KERNEL);
/* various checks */
/* now adding the new instance to the list */
list_add_tail(&(newTask->list),&(mylist->list));
/* i have put list_head struct in my own structure to make use of above interface */
}
现在mylist
,应该将上面使用的变量定义为全局变量,以便维护后续系统调用的列表。如何做到这一点?我必须在中声明mylist
变量,linux/init/main.c
还是可以简单地使用EXPORT_GLOBAL
。我还阅读了有关使用extern的信息,但无法弄清楚在何处声明和定义变量。
最好使用EXPORT_SYMBOL,因为这对于可加载模块也是可见的,并将其声明为正在使用的文件或本地头文件中的int
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句