我想在/proc/driver目录下创建一个文件.我想使用宏proc_root_driver(或其他提供的)而不是明确使用"driver/MODULE_NAME".我用create_proc_entry:
struct proc_dir_entry *simpleproc_fops_entry;
simpleproc_fops_entry = create_proc_entry(MODULE_NAME, 0400, NULL /* proc_root_dir */);
Run Code Online (Sandbox Code Playgroud)
谷歌搜索后,我发现使用建议proc_root_driver,但当我使用它时,我得到错误
proc_root_driver在此函数中未声明
而且,proc_root_driver在linux/proc_fs.h中不可用.
我试图像这样声明结构:
struct proc_dir_entry proc_root;
struct proc_dir_entry *proc_root_driver = &proc_root;
Run Code Online (Sandbox Code Playgroud)
编译错误消失了,但文件没有出现在/proc/driver或/proc.如何创建条目/proc?
如何从linux内核模块代码(内核模式)中获取有关运行哪个内核版本的运行时信息?
我想在启动时自动加载一些内核模块.我已阅读手册,但无法帮助.现在我要自动加载vboxdrv vboxnetadp vboxpci vboxnetflt的模块是/lib/modules/3.0.6-gentoo/,模块目录是,配置文件目录是/etc/modules.autoload.d/kernel-3.0.6,在这个文件中,模块都包含在内.现在重新启动后,使用lsmod,我看不到这些模块已加载.有什么问题?
thinkpad walle # ls -l /boot/
??? 17068
lrwxrwxrwx 1 root root 1 1? 10 01:22 boot -> .
drwxr-xr-x 2 root root 4096 4? 27 10:55 grub
-rw-r--r-- 1 root root 5771120 3? 23 09:27 kernel-3.0.6
-rw-r--r-- 1 root root 5771120 4? 26 17:48 kernel-3.0.6-n5
-rw-r--r-- 1 root root 5876784 4? 27 10:55 kernel-3.0.6-n6
drwx------ 2 root root 16384 1? 17 15:47 lost+found
Run Code Online (Sandbox Code Playgroud)
现在我kernel-3.0.6-n6用作我的启动内核.
thinkpad …Run Code Online (Sandbox Code Playgroud) 我正在编写一个可加载的内核模块并尝试测试它.插入后,我试图使用rmmod xxx命令删除它,但我得到一个错误说module xxx is in use,模块卡住,我无法删除它.知道如何在不重启整个机器的情况下移除模块吗?(linux Kernel v.3.5.0)
注意:rmmod -f打印Error: device or resource busy
当他们被创建为以下时,我很困惑b/w workqueues和kthread
为每个在线CPU创建kthread并绑定到1个唯一的CPU
for_each_online_cpu(cpu) {
kthread = kthread_create(func, ...);
kthread_bind(kthread, cpu);
}
//Each kthread will process work in serialized manner
Run Code Online (Sandbox Code Playgroud)
为@max_active为1的每个在线CPU创建BOUND工作队列
for_each_online_cpu() {
wq = alloc_workqueue(name, WQ_MEM_RECLAIM, 1)
}
// queue_work_on(cpu, work) will ensure the works queued on a particular CPU are
processed in a serialized manner.
Run Code Online (Sandbox Code Playgroud)
如果我的理解是正确的,那么请告诉我kthread优于工作队列的优点,反之亦然.
提前致谢.
在Linux内核中,给定一个模块我怎么知道它是kobject?
上下文:我正在尝试在内核模块中执行sysfs_create_file(kobj,attr).我已经设置了所有属性,但我想在当前模块中添加一个属性.
在Linux PCI驱动程序上工作,现在我正尝试使用分散/聚集为DMA编写代码。
到目前为止,我已经了解到,要直接从用户空间访问DMA数据,我们需要将用户空间页面固定到内核空间。
为此,我们拥有get_user_pages,其完整定义如下:
int get_user_pages(struct task_struct * tsk,
struct mm_struct * mm,
unsigned long start,
int nr_pages,
int write,
int force,
struct page ** pages,
struct vm_area_struct ** vmas);
Run Code Online (Sandbox Code Playgroud)
我的第一个问题是关于struct page ** pages。在这里,我们需要为分配内存(kcalloc用于ex),pages然后再调用get_user_pages吗?
我的第二个问题是关于unsigned long start,在手册页上说“起始用户地址”,这是否意味着,如果我在用户空间中声明一个指针,例如int *p,我应该传递给内核空间的“起始用户地址”是p?
我的第三个问题也与有关unsigned long start,如果我对第二个问题的理解正确,那么我们如何确保该地址恰好在页面的开头?
所以这三个问题,谢谢你的推进。
我正在努力理解平台设备驱动程序与字符设备接口之间的链接以及将数据存储在特定于设备的数据结构中.
我创建了一个结构来跟踪与我的设备相关的数据,然后将它添加到probe函数的devices结构中:
dev_set_drvdata(dev, data_struct);
Run Code Online (Sandbox Code Playgroud)
我还保留了全球副本data_struct.
我注册了一个misc设备,以便我可以mmap()通过ioctl()命令访问设备.如果我想访问此设备data_struct,目前我通过全局副本访问它.是否有另一种方法通过inode或file指针访问我存储在设备结构中的数据?
我目前只允许一个设备实例,但我想确保我正确实现这一点,以便将来可能有多个设备使用相同的驱动程序.
driver kernel-module linux-device-driver linux-kernel embedded-linux
我正在编写一个内核模块来监视一些想要在调用成功时将函数参数返回到user-land(通过netlink socket)的系统调用.
jprobe.kp.symbol_name = "rename";
jprobe.entry = rename_handler;
kretprobe.kp.symbol_name = "rename";
kretprobe.handler = rename_ret_handler;
static rename_obj_t _g_cur_rename = NULL;
static void _rename_handler(const char *oldpath, const char *newpath)
{
_g_cur_rename = create_rename(oldpath, newpath);
jprobe_return();
}
static void _rename_ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
{
/* Send only if successful */
if (regs_return_value(regs) == 0) {
add_send_queue(_g_cur_rename);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我担心另一个重命名系统调用可以抢占[1] jprobe之后的当前一个,我将发送错误的返回码和参数.
jprobe: rename(a, b)
jprobe rename(c, d)
kretprobe
kretprobe
Run Code Online (Sandbox Code Playgroud)
编辑:本文[2]指出在kprobe处理程序期间禁用了中断.但这是否意味着整个链中断(jprobe - > kprobe - > kretprobe)或仅针对那个单独的kprobe中断?
我看到此页面有类似的错误消息:Nf_hook_ops在分配给hook_func -C -Linux -Netfilter时返回不兼容的指针
但是,它没有给出如何解决问题的明确答案.该问题的作者说,他发现他的netfilter.h位于其他地方导致了麻烦,但对我来说,我发现所有包含的四个文件都在正确的目录中(usr/src/linux-headers-4.8.在我的情况下0-22-generic/include/linux).
以下是我的代码,应该有助于更好地澄清.
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
static struct nf_hook_ops nfho;
unsigned int hook_func_incoming(unsigned int hooknum, struct sk_buff *sskb,
const struct net_device *in, const struct net_device *out, int (*okfn)
(struct sk_buff *)){
return NF_DROP;
}
int init_module(){
nfho.hook = hook_func_incoming;
nfho.hooknum = NF_INET_PRE_ROUTING;
nfho.pf = PF_INET;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
printk(KERN_INFO "SIMPLE FIREWALL LOADED\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
确切的错误消息是这样的:
错误:从不兼容的指针类型赋值[-Werror = incompatible-pointer-types] nfho.hook = hook_func_incoming; ^ cc1:某些警告被视为错误
请让我知道我应该怎么做才能编译我的netfilter,任何帮助表示赞赏!
kernel-module ×10
linux-kernel ×8
c ×4
linux ×4
kernel ×2
driver ×1
gentoo ×1
insmod ×1
kernel-mode ×1
netfilter ×1
procfs ×1