kernel-module

Listening for new Processes in Linux Kernel Module

大城市里の小女人 提交于 2020-01-02 04:50:07
问题 Is it possible to get notified (via callback or similar) when a new process is executed, when one is closed, and when state changes (ie. stopped, paged, etc)? In user-land, it would be easy to set up a directory listener on /proc. 回答1: Have you considered kprobes? You can use kprobes to execute a callback function when some kernel code is executed. E.g., you could add a do_fork kprobe to alert when new processes are created as in this example. Similarly, you can add a probe for do_exit() to

How do I access any kernel symbol in a kernel module?

好久不见. 提交于 2020-01-01 06:06:25
问题 I am wanting to use the function getname in my kernel module. It is not exported. Since I am running into this problem right now, I would like to know how to access and use any kernel symbol that is not exported. I figure that the steps necessary to use one will differ depending what the symbol is, so I'd like to see how it would be done for a type (e.g., a struct), a variable, a table of pointers (like the system call table), and a function. How can these be done in either of these cases:

How do I access any kernel symbol in a kernel module?

浪尽此生 提交于 2020-01-01 06:06:06
问题 I am wanting to use the function getname in my kernel module. It is not exported. Since I am running into this problem right now, I would like to know how to access and use any kernel symbol that is not exported. I figure that the steps necessary to use one will differ depending what the symbol is, so I'd like to see how it would be done for a type (e.g., a struct), a variable, a table of pointers (like the system call table), and a function. How can these be done in either of these cases:

Linux Kernel Module (*.ko) compatibility between kernels

走远了吗. 提交于 2020-01-01 05:21:32
问题 I have a simple kernel object that I built for probing around at kernel memory. If I build it on my 64-bit Ubuntu (3.2) machine it works fine on that machine. But it won't insmod on my 64-bit Ubuntu (3.9) machine. And vice versa. It gives me a "-1 Invalid module format" error if I try to run it on a Kernel rev other than the one I'd built it on. I thought insmod linked it dynamically against the exported symbol table and the exported symbol table does not change between kernel revisions. (It

What is EXPORT_SYMBOL_GPL in Linux kernel code?

坚强是说给别人听的谎言 提交于 2019-12-30 01:53:29
问题 What is EXPORT_SYMBOL_GPL in Linux kernel code? Below is a piece of code, which contains EXPORT_SYMBOL_GPL 62 struct resource *platform_get_resource(struct platform_device *dev, 63 unsigned int type, unsigned int num) 64 { 65 int i; 66 67 for (i = 0; i < dev->num_resources; i++) { 68 struct resource *r = &dev->resource[i]; 69 70 if (type == resource_type(r) && num-- == 0) 71 return r; 72 } 73 return NULL; 74 } 75 EXPORT_SYMBOL_GPL(platform_get_resource); That macro appears many a times in

Make a system call to get list of processes

匆匆过客 提交于 2019-12-29 06:29:49
问题 I'm new on modules programming and I need to make a system call to retrieve the system processes and show how much CPU they are consuming. How can I make this call? 回答1: Why would you implement a system call for this? You don't want to add a syscall to the existing Linux API. This is the primary Linux interface to userspace and nobody touches syscalls except top kernel developers who know what they do. If you want to get a list of processes and their parameters and real-time statuses, use

Get current time in seconds in kernel module

无人久伴 提交于 2019-12-28 17:11:39
问题 What is the standard way to get the current time in seconds (since the epoch) in a kernel module? I have seen techniques involving getting xtime which are very long-winded and involve while-loops and locks. There must be a better way. [This is not a duplicate. I have looked through previous questions on SO. The answers to many of these either don't specify the function used, or incorrectly refer to time.h which is not allowed in the kernel] 回答1: You can use getnstimeofday for that. /*

Registering Platform Device with info from Device Tree

流过昼夜 提交于 2019-12-25 05:05:48
问题 I am using Petalinux for a Xilinx Zynq application, and I am new to kernel driver development. I created a kernel module for a platform driver for an AXI FIFO interface. The devices seems to be recognised from the device tree using the .of_match_table, since I can see the correct memory space reserved with cat /proc/iomem . If I search for the driver name xxx I get ./lib/modules/4.4.0-xilinx/extra/xxx.ko ./sys/bus/platform/drivers/xxx ./sys/module/xxx ./sys/module/xxx/drivers/platform:xxx I

Linux: Instantiate from user-space : eeprom new_device

五迷三道 提交于 2019-12-25 03:49:10
问题 Environment : x86 / Ubuntu 14.04 I want obtain something similar to &i2c0 { eeprom: eeprom@50 { compatible = "at,24c32"; reg = <0x50>; }; }; But because in x86 no Device Tree is available, I am follow i2c/instantiating-device document in the Linux kernel and use "Method 4: Instantiate from user-space". Process to instantiate: Load at24 driver Load i2c-dev driver Instantiate: # echo eeprom 0x50 > /sys/bus/i2c/devices/i2c-0/new_device Response from kernel in dmesg: i2c i2c-0: new_device:

Print Virtual Address of mem_map using a proc file

 ̄綄美尐妖づ 提交于 2019-12-25 03:14:27
问题 I have to print the contents of the mem_map variable in the kernel. However when I compile my code by issuing make I see: WARNING: "mem_map" [/home/babak/code/module/mem_map.ko] undefined! from: make -C /home/babak/code/linux-3.19.5 M=/home/babak/code/module modules make[1]: Entering directory '/home/babak/code/linux-3.19.5' CC [M] /home/babak/code/module/mem_map.o Building modules, stage 2. MODPOST 1 modules WARNING: "mem_map" [/home/babak/code/module/mem_map.ko] undefined! LD [M] /home