kernel-module

how to write cross-version/platform Linux kernel modules?

偶尔善良 提交于 2019-12-07 06:33:22
问题 I'm new to programming Linux kernel modules, and many getting started guides on the topic include little information about how to build a kernel module which will run on many versions and CPU platforms of Linux. Most of the guides I've seen simply state things like, "Linux doesn't ensure any ABI/API compatibility between versions." However, other OSes do provide these guarantees for major versions, and the guides are mostly targeting 2.7 (which is a bit old now). I was wondering if there is

How to rename a kernel module name without renaming the .ko passed to insmod?

怎甘沉沦 提交于 2019-12-07 05:17:26
问题 I need to rename a kernel module (the name that get displayed with lsmod) of an already existing driver without changing the name of the source file. e.g. # insmod xxx.ko <<module loads successfully>> # lsmod Module Size Used by Tainted: P xxx 191527 0 # I want to rename xxx to yyy . Now I know that changing the name of the driver source file (when it involves a single file) changes the name of the module. But I don't want to change the name of a source file. 回答1: Rename your obj-m in

How to mmap a file in linux kernel space?

允我心安 提交于 2019-12-07 05:02:24
问题 I try to mmap a file in a linux kernel module. I have tried to use the function do_mmap_pgoff . But the address returned is memory virtual address in current process' user space, i.e., below the kernel boundary. Instead, I want to map the file in the kernel space and get the kernel virtual address of the mapped region. Is there any kernel API in Linux support this operation? Thanks 来源: https://stackoverflow.com/questions/13465095/how-to-mmap-a-file-in-linux-kernel-space

Why is my kernel module throwing “broken pipe” errors when I try to write to a device?

自古美人都是妖i 提交于 2019-12-07 04:02:49
问题 I am currently in the process of writing a Linux kernel module in C. The module provides an extremely basic driver for a USB light (the device consists of three colored LEDs). I have managed to get the driver to load and unload without problems and also create the device ( /dev/wn0 , /dev/wn1 , etc.). However, I keep getting errors when attempting to write to the device: $ echo "1" >/dev/wn0 bash: echo: write error: Broken pipe The entire code for the module is here. However, the interesting

Linux Kernel Module/IOCTL: inappropriate ioctl for device

做~自己de王妃 提交于 2019-12-07 02:43:03
问题 I am in the process of writing a Linux Kernel Module (LKM) serving as a pseudo-driver - I am unable to figure out how to make IOCTL calls between the LKM ( wait.c ) and the user-level program ( user.c ). The magic number for the device driver is 0xBF - the LKM does not communicate with a physical block/char device, it is simply an exercise. From what I can tell, the IOCTL call to KERN_IOCTL_CREATE_EVENT is not formatted properly & the magic number is incorrect. The IOCTL call that I am

Programmatically check whether a linux kernel module exists or not at runtime

回眸只為那壹抹淺笑 提交于 2019-12-06 23:23:58
问题 I am writing a C daemon, which depends on the existence of two kernel modules in order to do its job. The program does not directly use these (or any other) modules. It only needs them to exist. Therefore, I would like to programmatically check whether these modules are already loaded or not, in order to warn the user at runtime. Before I start to do things like parsing /proc/modules or lsmod output, does a utility function already exist somewhere? Something like is_module_loaded(const char*

Intercepting syscalls in Android kernel — device reboots when module is removed

瘦欲@ 提交于 2019-12-06 19:14:27
I have been trying to intercept the read syscall in Android kernel (3.0.72 for maguro). I am using kernel module for such purpose. An example is as follows: #include <linux/module.h> #include <linux/unistd.h> MODULE_LICENSE ("Dual BSD/GPL"); asmlinkage long (*orig_call_open) (const char __user * filename, int flags, int mode); asmlinkage long (*orig_call_read) (unsigned int fd, char __user * buf, size_t count); #define SYS_CALL_TABLE_ADDR 0xc0058828 void **sys_call_table; asmlinkage long new_sys_open (const char __user * filename, int flags, int mode) { printk ("Calling my open\n"); return

How to kill a wait queue in kernel module?

白昼怎懂夜的黑 提交于 2019-12-06 16:34:44
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_interruptible(wait_queue, does_buffer_have_data()); ... } } Common way for wait within kernel thread:

YOCTO : can't insert linux module to the kernel : versions are different

。_饼干妹妹 提交于 2019-12-06 16:18:16
I'm using YOCTO PROJECT to build a linux os for my embedded board. I have a module named uleds which i want insert to my kernel so i taped this insmod command: insmod /lib/modules/4.14.73-linux4sam-6.0-dirty/kernel/drivers/leds/uleds.ko But an errors comes out : uleds: version magic '4.14.88-01445-g234c56a01768-dirty mod_unload ARMv7 p2v8 ' should be '4.14.73-linux4sam-6.0-dirty mod_unload ARMv7 p2v8 ' uleds: version magic '4.14.88-01445-g234c56a01768-dirty mod_unload ARMv7 p2v8 ' should be '4.14.73-linux4sam-6.0-dirty mod_unload ARMv7 p2v8 ' insmod: can't insert '/lib/modules/4.14.73

Create ProcFS entry in /proc/net

☆樱花仙子☆ 提交于 2019-12-06 13:15:55
I try to create an entry inside /proc/net from a kernel module, like this: struct file *filp = filp_open("/proc/net", O_RDONLY, 0); struct proc_dir_entry *parent = PDE(filp->f_dentry->d_inode); filp_close(filp, NULL); proc_file = create_proc_entry("test", 0644, parent); Crudely taken from here Why does it create my entry like /proc/test instead of /proc/net/test ? (Note: I'd like too use create_proc_entry , not proc_create .) In recent kernels you won't find create_proc_entry() anymore, it's been removed completely. Take a look at https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git