kernel-module

Compiling a driver as a part of a kernel, not as a module

余生长醉 提交于 2019-12-03 12:50:59
I am trying to create a minimalistic Linux for an embedded device. That means the necessity of compiling kernel and drivers. One driver is written directly for the device's board by it's creator, so it is not a repository one. It can be compiled as a kernel module. However because of immutable nature of the Linux and requirement of extremely small use of memory I do not want to use modules. I want all drivers built-in in the kernel. And all drivers provided with kernel I have set this way. So my problem is how to compile that one special driver to the kernel? All searching have not provided me

Linux Kernel Module - Creating proc file - proc_root undeclared error

五迷三道 提交于 2019-12-03 12:41:39
I copy and paste code from this URL for creating and reading/writing a proc file using a kernel module and get the error that proc_root is undeclared. This same example is on a few sites so I assume it works. Any ideas why I'd get this error? Does my makefile need something different. Below is my makefile as well: Example code for a basic proc file creation (direct copy and paste to get initial test done): http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN769 Makefile I'm using: obj-m := counter.o KDIR := /MY/LINUX/SRC PWD := $(shell pwd) default: $(MAKE) ARCH=um -C $(KDIR) SUBDIRS=$(PWD)

Convert source IP address from struct iphdr* to string equivalent using Linux netfilter

这一生的挚爱 提交于 2019-12-03 12:29:39
问题 I want to convert the source & destination IP addresses from a packet captured using netfilter to char *. In my netfilter hook function, I have: sock_buff = skb; // argument 2 of hook function // ip_header is struct iphdr* ip_header = (struct iphdr *)skb_network_header(sock_buff); // now how to convert ip_header->saddr & ip_header->daddr to char * // ip_header->saddr & ip_header->daddr are of type __be32 Thanks. 回答1: The kernel's family of printf() functions has a special format specifier for

intercepting file system system calls

孤人 提交于 2019-12-03 11:58:29
I am writing an application for which I need to intercept some filesystem system calls eg. unlink. I would like to save some file say abc. If user deletes the file then I need to copy it to some other place. So I need unlink to call my code before deleting abc so that I could save it. I have gone through threads related to intercepting system calls but methods like LD_PRELOAD it wont work in my case because I want this to be secure and implemented in kernel so this method wont be useful. inotify notifies after the event so I could not be able to save it. Could you suggest any such method. I

Accessing a serial port from a linux kernel module

可紊 提交于 2019-12-03 11:33:30
Hello Linux Kernel Driver Gurus! I'm writing a v4l2 driver for a camera that uses a serial interface for configuration. I'd like the driver to configure the camera, as it keeps the client code consistent across camera models. The question is: what's the best way to access the camera's serial interface from the driver module? From what I hear, accessing files from a kernel driver is a big no-no, but it can be done. As such, I'm currently using the following code snippet, but it feels like a hack. oldfs = get_fs(); set_fs(KERNEL_DS); fd->f_pos=0; fd->f_op->write(fd, data, data_len, &fd->f_pos);

Warning building a kernel module that uses exported symbols

人走茶凉 提交于 2019-12-03 09:49:55
问题 I have two kernel modules (say modA and modB). modA exports a symbol with EXPORT_SYMBOL(symA) and modB uses it. I have the header modA.h for modA: ... extern void symA(int param); ... and in modB.c : #include "modA.h" ... static int __init modB_init(void) { symA(10); } ... If i insmod modB all works fine, my modB is correctly linked in the kernel and the function symA is correctly called. However when i build modB the compiler raises a warning: symA is undefined . An LKM is an ELF relocatable

Trigger Kernel Interrupt Handler: How?

北战南征 提交于 2019-12-03 07:00:44
I am trying to understand Asynchronous Interrupt handling in kernel, ofcourse through the legendary Understanding the Linux Kernel. In this process how and who will trigger Kernel Interrupt Handler? I would like some one to help me correcting this and to clarify my question on 1)How and Who trigger Kernel Interrupt Handler? 2)How to define new or change existing hardware interrupt handlers? Thank you in Advance! This picture from Robert Love's "Linux Kernel Development" pretty well describes path of interrupt. Processor interrupts the kernel in the predefined enty point do_IRQ() . If there is

Why processes are deprived of CPU for TOO long while busy looping in Linux kernel?

半腔热情 提交于 2019-12-03 06:23:06
At first glance, my question might look bit trivial. Please bear with me and read completely. I have identified a busy loop in my Linux kernel module. Due to this, other processes (e.g. sshd) are not getting CPU time for long spans of time (like 20 seconds). This is understandable as my machine has only single CPU and busy loop is not giving chance to schedule other processes. Just to experiment, I had added schedule() after each iteration in the busy loop. Even though, this would be keeping the CPU busy, it should still let other processes run as I am calling schedule(). But, this doesn't

How does the Linux kernel determine the order of __init calls?

扶醉桌前 提交于 2019-12-03 06:19:08
问题 There are many instances of __init calls in kernel both in drivers module_init and other functions of kernel. My doubt is how exactly kernel determines the sequence of the __init call. More importantly, How it also determine the sequence of driver module_init call? 回答1: All the init magic are implemented in files: include/asm-generic/vmlinux.lds.h include/linux/init.h init/main.c Firstly, look at include/asm-generic/vmlinux.lds.h that contains the following: 13 * . = START; 14 * __init_begin

How to find the list of processes using a particular kernel module?

戏子无情 提交于 2019-12-03 06:08:25
When I try to rmmod a module I get the error message "Error: Module in use" , lsmod | grep <module name> shows the count. Is there a way that would tell me which processes are using this particular kernel module/driver? wallyk This was asked before , but there was no great answer, probably because there is no good way to accomplish to find what is using what. The best suggestion is to dmesg and look for any indication of what loaded the module. You might also try using the --force parameter to rmmod in case your kernel was built with support for it. lsof /dev/ might help you to find the