kernel-module

Why is the probe function in my kernel module not being called?

会有一股神秘感。 提交于 2019-12-13 02:35:21
问题 While following, among others, this tutorial ([http://tali.admingilde.org/linux-docbook/writing_usb_driver.pdf][1]) and reading certain chapters in the linux device drivers book, I cannot get the pr_debug statements in the probe function to show any output in dmesg. Here's my code: #include <linux/module.h> /*included for all kernel modules*/ #include <linux/kernel.h> /*included for KERN_DEBUG*/ #include <linux/init.h> /*included for __init and __exit macros*/ #include <linux/usb.h> #include

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

送分小仙女□ 提交于 2019-12-12 10:16:15
问题 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

How to write kernel space memory (physical address) to a file using O_DIRECT?

寵の児 提交于 2019-12-12 08:23:11
问题 I want to write a physical memory to a file. The memory itself will not be touched again, thus I want to use O_DIRECT to gain the best write performance. My first idea was to open /dev/mem and mmap the memory and write everything to a file, which is opened with O_DIRECT . The write call fails ( EFAULT ) on the memory-address returned by mmap. If I do not use O_DIRECT , it results in a memcpy . #include <cstdint> #include <iostream> #include <unistd.h> #include <sys/types.h> #include <sys/stat

Changing the Interrupt descriptor Table

坚强是说给别人听的谎言 提交于 2019-12-12 08:08:18
问题 I am using Linux 2.6.26 kernel version and I am trying to change the interrupt descriptor table using a kernel module. I am only trying to change the page fault table entry here. So I make a copy of the original IDT and make changes to the page fault table entry only. The objective of the ISR is to print out information of the page fault before calling the original Page fault handler. But the kernel just crashes once I load it with insmod i.e it specifically crashed with the "loadIDTR"

What is a Kernel thread?

落花浮王杯 提交于 2019-12-12 07:08:46
问题 i am just started coding of device driver and new to threading, went through many documents for getting an idea about threads. i still have some doubts. what is a kernel thread ?. how it differs from user thread ?. what is the relationship between the two threads ?. how can i implement kernel threads ?. where can i see the output of the implementation?. Can anyone help me ?. thanks. 回答1: A kernel thread is a kernel task running only in kernel mode; it usually has not been created by fork() or

Detecting AES-NI CPU instructions

馋奶兔 提交于 2019-12-12 05:38:10
问题 Recent Intel and AMD CPUs support specific AES instructions that increase the performance of encryption and decryption. Is it possible to to detect when these instructions are called? For example by writing a kernel module that monitors the instructions that are sent to the CPU? Or is the kernel still to high-level? 回答1: My understanding is that instructions like AESENC require no special privileges, so you won't be able to trap them with one of the usual fault handlers even in the kernel.

Modifying control register in kernel module

爷,独闯天下 提交于 2019-12-12 04:54:17
问题 The following simple kernel module sets the 13th bit of the cr4 register ( CR4.VMXE ) once it is loaded and clears the bit on exit. vmx.c #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> MODULE_LICENSE("GPL"); static inline uint64_t getcr4(void) { register uint64_t ret = 0; asm volatile ( "movq %%cr4, %0\n" :"=r"(ret) ); return ret; } static inline void setcr4(register uint64_t val) { asm volatile ( "movq %0, %%cr4\n" : :"r"(val) ); } static int __init init_routine

Example of use pwm_get() in linux kernel

不想你离开。 提交于 2019-12-12 04:37:08
问题 I want to try to use PWM in linux kernel module for my Rasperry Pi. I've successfully enabled PWM via SYSFS interface. For usage of pwm in kernel modules documentation states: New users should use the pwm_get() function and pass to it the consumer device or a consumer name. pwm_put() is used to free the PWM device. Managed variants of these functions, devm_pwm_get() and devm_pwm_put(), also exist. pwm_get function looks like this: /** * pwm_get() - look up and request a PWM device * @dev:

maximum allocated memory by linux-kernel module

南楼画角 提交于 2019-12-12 04:14:40
问题 I want to write a module whose task is to capture the incoming packets without sending them to the user space application & doing some modification on the captured packet. then this module will send this packet for transmission to the NIC. But main problem is that my module is very big in size & it also does a lot of processing. So will it be good to do this processing inside kernel module or should we pass the information & packet to the user space for processing to avoid complexity. & i m

Build external modules against a running kernel

对着背影说爱祢 提交于 2019-12-12 02:54:09
问题 I'm trying to build the latest linux crypto drivers for a Ubuntu server. Ubuntu server has a running kernel, extras and headers installed. However, the source code for the crypto modules are coming from Torvald's GitHub (and not Ubuntu). I'm also working from the kernel doc Building External Modules. I cloned the latest kernel with: git clone --depth=1 https://github.com/torvalds/linux.git Then: cd linux Next: $ make -C /usr/src/linux-headers-4.2.0-34 M=$PWD crypto make: Entering directory '