kernel-module

Miscellaneous Device Driver: Unable to open the device with open() system call

大兔子大兔子 提交于 2020-02-25 13:37:49
问题 I am trying to implement a system call interception for sys_open() call via kernel module and for that I have defined a miscellaneous device driver MyDevice which can be inserted as kernel module. Below is the code for my kernel module: #include <linux/version.h> #include <linux/module.h> #include <linux/miscdevice.h> #include <linux/fs.h> #include <linux/highmem.h> #include <asm/unistd.h> MODULE_LICENSE("GPL"); // IOCTL commands #define IOCTL_PATCH_TABLE 0x00000001 #define IOCTL_FIX_TABLE

Miscellaneous Device Driver: Unable to open the device with open() system call

☆樱花仙子☆ 提交于 2020-02-25 13:37:30
问题 I am trying to implement a system call interception for sys_open() call via kernel module and for that I have defined a miscellaneous device driver MyDevice which can be inserted as kernel module. Below is the code for my kernel module: #include <linux/version.h> #include <linux/module.h> #include <linux/miscdevice.h> #include <linux/fs.h> #include <linux/highmem.h> #include <asm/unistd.h> MODULE_LICENSE("GPL"); // IOCTL commands #define IOCTL_PATCH_TABLE 0x00000001 #define IOCTL_FIX_TABLE

copy_to_user and copy_from_user with structs

为君一笑 提交于 2020-02-05 05:14:29
问题 I have a simple question: when i have to copy a structure's content from userspace to kernel space for example with an ioctl call (or viceversa) (for simplicity code hasn't error check): typedef struct my_struct{ int a; char b; } my_struct; Userspace: my_struct s; s.a = 11; s.b = 'X'; ioctl(fd, MY_CMD, &s); Kernelspace: int my_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { ... my_struct ks; copy_from_user(&ks, (void __user *)arg, sizeof(ks)); ... } i

trouble using python 3 because of kernel error

末鹿安然 提交于 2020-01-25 09:27:06
问题 I just installed anaconda 3 and tried to use Jupyter Notebook for Python 3. However, it did not work because of the kernel error on the top right coner and the error message was Traceback (most recent call last): File "C:\Users\jiyoon\Anaconda3\lib\site-packages\tornado\web.py", line 1699, in _execute result = await result File "C:\Users\jiyoon\Anaconda3\lib\site-packages\tornado\gen.py", line 742, in run yielded = self.gen.throw(*exc_info) # type: ignore File "C:\Users\jiyoon\Anaconda3\lib

linux kernel module not able to find “nvme_ns” struct

情到浓时终转凉″ 提交于 2020-01-16 14:49:14
问题 I am writing a module in which I am accessing the nvme device using major and minor number. The code for the function is src_disk = get_gendisk(MKDEV(si->src_major, si->src_minor), &part); my_nvme_ns = (struct nvme_ns *)src_disk->private_data; for (i = 0; i <= 15; i++) { printk(KERN_CONT "%02x", my_nvme_ns->head.ids.nvme_ns_ids.nguid[i]); } Now, when I try to acces my_nvme_ns , it fails with error error: dereferencing pointer to incomplete type ‘struct nvme_ns’ printk(KERN_CONT "%02x", my

“ error: unknown field ‘compat_ioctl’ specified in initializer ” while creating dummy ioctl

折月煮酒 提交于 2020-01-15 18:51:44
问题 static const struct inode_operations msdos_dir_inode_operations = { .create = msdos_create, .lookup = msdos_lookup, .unlink = msdos_unlink, .mkdir = msdos_mkdir, .rmdir = msdos_rmdir, .rename = msdos_rename, .setattr = fat_setattr, .getattr = fat_getattr, .compat_ioctl = my_ioctl, ---->error }; i also tried with unlocked_ioctl but same error occured [root@localhost fat]# make make -C /lib/modules/3.11.10-100.fc18.x86_64/build M=/home/aditya/linux-3.12.6/fs/fat modules make[1]: Entering

Where is the standard kernel libraries to let kernel module link to?

女生的网名这么多〃 提交于 2020-01-15 07:23:18
问题 The kernel module can not call libc since libc run under user space. There are some other kernel specified APIs just like printk() to make modules work fine. As I understand that libc is a collection of several standard c function obj(s). It is supposed to exist a collection (or library) to include several kernel standard function objects. So I can link my kernel module with these kernel standard libraries to do work, right ? briefly speaking , my question is as followings ... in user space :

How to kill a wait queue in kernel module?

醉酒当歌 提交于 2020-01-14 03:30:14
问题 I am new to kernel module. Using a wait queue, I am blocking the thread until the buffer has data. Using hrtimer , I am periodically waking up the queue. Now, the problem is even after I remove the kernel module, I could see that the process "thread1" is still running. I think the issue is that the wait queue is waiting forever and the process got blocked here. Please help me how can I kill the wait queue when I remove my module. void thread1(void) { while (thread_running) { ... wait_event

module compiling : asm/linkage.h file not found

有些话、适合烂在心里 提交于 2020-01-12 14:05:12
问题 I am trying to compile an example of "hello world" Kernel Module, problems found on ubuntu 11.04, kernel 3.2.6, gcc 4.5.2 and fedora 16, kernel 3.2.7, gcc 4.6.7. code: #include <linux/module.h> #include <linux/init.h> MODULE_LICENSE("GPL"); static int __init hello_init (void) { printk("Hello module init\n"); return 0; } static void __exit hello_exit (void) { printk("Hello module exit\n"); } module_init(hello_init); module_exit(hello_exit); compiled with: gcc -D__KERNEL__ -I /usr/src/linux

How to recompile just a single kernel module?

99封情书 提交于 2020-01-11 15:05:39
问题 Usually kernel source are stored in /usr/src/linux-2.6.x/ . To avoid to recompile the entire kernel if I modify a module's source, how can I recompile just that module? 回答1: Switch to the root directory of your source tree and run the following command: $ make modules SUBDIRS=drivers/the_module_directory And to install the compiled module: $ make modules_install SUBDIRS=drivers/the_module_directory Note: As lunakid mentions, the latter command might not build the module first, so be careful.