我正在为充当 FIFO 设备的 debian 6 内核编写设备驱动程序模块,编译显然是正确的,我使用以下代码创建它:
Major = register_chrdev(0, DEVICE_NAME, &fops); //Major is an integer value
if (Major < 0) {
printk(KERN_ALERT "Registering char device failed with %d\n", Major);
return -Major;
}
/*
* Creation of buffer;
*/
if( (buf = create_cbuffer_t(MAX_BUFFER_SIZE)) == NULL){
printk(KERN_ALERT "Error when creating the FIFO device.");
return -EINVAL;
}
printk(KERN_INFO "Buffer created without error.\n");
Run Code Online (Sandbox Code Playgroud)
分配的主要数字是 251,我使用这个创建它的文件:
sudo mknod /dev/fifodev c 251 0
Run Code Online (Sandbox Code Playgroud)
它工作正常,但是当我尝试在终端中访问时,结果是
dsouser@debian:~/Escritorio/Prac3/ParteB$ echo whatever > /dev/fifodev
bash: /dev/fifodev: Permiso denegado **This means:Permission denied** …Run Code Online (Sandbox Code Playgroud) 我有一个由多个函数调用的函数.有些函数使用自旋锁定调用它,有些函数没有任何锁定.我怎么知道我的函数是否被保持螺旋锁调用?
我有一段时间写了一大段代码.它有一些函数可以使用和不使用不同代码路径的锁来调用.只考虑没有锁的情况,函数使用GFP_KERNEL标志分配skbs.使用spin_lock()调用时会导致问题.我需要处理这两种情况以避免在spin_lock中睡觉.
linux kernel-module linux-device-driver linux-kernel embedded-linux
我试图了解如何在Linux内核中实现wait_event。ldd3中有一个代码示例,其中使用prepare_to_wait(http://www.makelinux.net/ldd3/chp-6-sect-2)解释了内部实现。
static int scull_getwritespace(struct scull_pipe *dev, struct file *filp)
{
while (spacefree(dev) == 0) {
DEFINE_WAIT(wait);
up(&dev->sem);
if (filp->f_flags & O_NONBLOCK)
return -EAGAIN;
PDEBUG("\"%s\" writing: going to sleep\n",current->comm);
prepare_to_wait(&dev->outq, &wait, TASK_INTERRUPTIBLE);
if (spacefree(dev) == 0) // Why is this check necessary ??
schedule( );
finish_wait(&dev->outq, &wait);
if (signal_pending(current))
return -ERESTARTSYS; /* signal: tell the fs layer to handle it */
if (down_interruptible(&dev->sem))
return -ERESTARTSYS;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在书中,解释如下。
然后是对缓冲区的强制检查;我们必须处理以下情况:在进入while循环(并丢弃了信号灯)之后但在进入等待队列之前,缓冲区中的空间变得可用。如果没有该检查,如果读取器进程能够在那个时候完全清空缓冲区,那么我们可能会错过唯一一次唤醒并永远休眠的唤醒。在满足自己必须睡觉的满足感之后,我们可以拨打时间表了。
我无法理解这一解释。如果if (spacefree(dev) == 0)在调用schedule()之前未完成睡眠,我们将如何进入不确定的睡眠状态?如果不存在此强制检查,则wakeup()仍将过程状态重置为TASK_RUNNING并按下一段所述返回计划。
值得再次研究这种情况:如果在if语句中的测试与计划调用之间发生唤醒,会发生什么情况?在这种情况下,一切都很好。唤醒会将过程状态重置为TASK_RUNNING并返回计划-尽管不一定立即进行。只要在流程将自己置于等待队列并更改其状态之后进行测试,事情就可以正常进行。
在下面的 2 种情况下,“current->pid”打印什么
1) 硬IRQ上下文
2) 软IRQ上下文
我知道 IRQ 上下文和进程上下文是不同的,并且 PID 在 IRQ 上下文的情况下必须无效。但是当尝试在 IRQ 上下文中打印“current->pid”时,它正在打印一些有效的 PID,因此产生了疑问。请澄清。
谢谢你,
戈皮纳斯。
我需要使用 C++ 以编程方式根据供应商 ID 在 Linux 环境中搜索硬件。我知道我可以使用以下命令获取列表
-lspci
有人可以在这里提供一些线索吗?
谢谢并致以最诚挚的问候
在驱动程序端,pci_register_driver()在加载驱动程序模块时调用,如果模块是内置的,则在启动时调用。(每当添加设备/驱动程序时,驱动程序/设备列表都会循环以查找匹配项,我得到了那部分。)
但是在哪里/何时发现 pci 设备并在总线上注册?我想这是特定于架构的,并且会涉及 x86 上的 BIOS,例如 - BIOS 例程探测 PCI 设备,然后在加载内核之前将结果放在 RAM 中某个位置的列表中,并且每个列表条目都包含单个 pci 的信息设备包括vendorId/deviceId 等。内核然后拿起列表并将它们插入pci_bus_type.p.klist_devices到某个点。但这纯粹是猜测,谁能给一些提示?
我的代码中有如下内容:这是在 linux 下创建设备的代码 /dev
#define PRINTER_STR "printer_"
char str[32];
snprintf(str, sizeof(str), PRINTER_STR "%s%s", dev->type, "%u");
device_create(mycan_drv.class, parent,
MKDEV(dev->nMajor, dev->nMinor),
dev, str, dev->nMinor);
Run Code Online (Sandbox Code Playgroud)
第四参数snprintf被dev->type分配有像琴弦epson,hp,canon。
实现的输出是这样的:
printer_epson32, printer_hp33,printer_canon34
在上面的输出字符串中,我无法理解像32, 33, 之类的数字是如何34构建的。我可以理解这是因为第 5 个参数"%u"传递给snprintf. 但是怎么样?
我得到的所有参考文献都包含最多 3 个或 4 个snprintf. 请帮忙。
具体来说,(*llseek) 术语是对象转换吗?这个语法 < ( * < name > ) (...) > 是否有一个术语,我可以谷歌搜索它以了解更多信息。
为什么“struct file *”没有变量名,以及如何访问它(假设我需要或允许访问它)。同样,其余参数没有变量名“loff_t,int”,这是为什么呢?最后, __user (在这个例子中或 __ 通常)是一个宏吗?
struct file_operations {
loff_t (*llseek) (struct file *, loff_t, int);
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
Run Code Online (Sandbox Code Playgroud)
谢谢!
有人可以指导我完成编译linux内核的过程,
/usr/src/linux/我需要编译什么? 编译内核的步骤是:
cd /usr/src/linux make bzImage make modulesmake modules_installcd arch/i386/bootcp bzImage /boot/vmlinuz-"linux version" cd /bootmkinitrd "the image".img "version ..." reboot 有问题的步骤是make modules和make modules_install.
我想知道使用数值系统调用是否有任何意义?
例如,取wait(4)或exit(3).我希望链接到这些的一些文档或解释.
使用 ls -l 通常会生成一个包含文件大小的长列表...
-rw-r--r--@ 1 user1 staff 881344 Sep 1 15:35 someFile.png
Run Code Online (Sandbox Code Playgroud)
在 macOS 10.13.5 和 Ubuntu 20.04 上,字符特殊(设备)文件大小非常不同......
crw------- 1 root wheel 31, 0 Aug 30 16:11 autofs
Run Code Online (Sandbox Code Playgroud)
在这种情况下,“31, 0”是什么意思?
int main()
{
int *p;
p = malloc(5 * sizeof(int));
p =(int[5]) {11,12,13,14,15};
printf("[%d] [%d] [%d] [%d] [%d] \n",p[0],p[1],p[2],p[3],p[4]);
printf("[%lu] [%lu] [%lu] [%lu]\n",sizeof(&p[0]),sizeof(&p[1]),sizeof(&p[2]),sizeof(p));
printf("[%p] [%p] [%p] \n",&p[0],&p[1],p);
free(p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在运行exe时,我得到以下内容
[11] [12] [13] [14] [15]
[8] [8] [8] [8]
[0x7fff48ee93e0] [0x7fff48ee93e4] [0x7fff48ee93e0]
*** glibc detected *** ./a.out: double free or corruption (out): 0x00007fff48ee93e0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7fcce0856b96]
./a.out[0x40068a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7fcce07f976d]
./a.out[0x4004c9]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:05 408246 /home/user1/Desktop/c/a.out
00600000-00601000 r--p 00000000 08:05 408246 /home/user1/Desktop/c/a.out
00601000-00602000 …Run Code Online (Sandbox Code Playgroud)