kernel-module

The address in Kernel

时光毁灭记忆、已成空白 提交于 2019-12-04 20:50:58
问题 I have a question when I located the address in kernel. I insert a hello module in kernel, in this module, I put these things: char mystring[]="this is my address"; printk("<1>The address of mystring is %p",virt_to_phys(mystring)); I think I can get the physical address of mystring, but what I found is, in syslog, the printed address of it is 0x38dd0000. However, I dumped the memory and found the real address of it is dcd2a000, which is quite different from the former one. How to explain this

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

六眼飞鱼酱① 提交于 2019-12-04 19:59:32
问题 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

Using stdlib.h within a device driver

本小妞迷上赌 提交于 2019-12-04 19:38:36
I am trying to write a device driver and I need to use system() function in the driver. To use system() we need to include <stdlib.h> , which dosnt seem to work from a driver. It says no such file or directory found. Is there an alternative to stdlib.h for device drivers? Or an alternative to system() ? stdlib.h is a user space header. User space is that set of memory locations in which user processes (i.e., everything other than the kernel) run. A process is an executing instance of a program. One of the roles of the kernel is to manage individual user processes within this space and to

Accessing a serial port from a linux kernel module

Deadly 提交于 2019-12-04 19:24:34
问题 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

Linux Kernel Module - Creating proc file - proc_root undeclared error

与世无争的帅哥 提交于 2019-12-04 18:55:05
问题 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 :=

Trigger Kernel Interrupt Handler: How?

和自甴很熟 提交于 2019-12-04 11:10:17
问题 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! 回答1: This picture from Robert Love's "Linux Kernel Development" pretty well

Writing x86_64 linux kernel module in assembler

∥☆過路亽.° 提交于 2019-12-04 11:04:05
问题 I try write simple kernel module (v3.6) in nasm, but insmod say me: $ sudo insmod ./hello.ko insmod: ERROR: could not insert module ./hello.ko: Invalid module format $ echo $? 1 I compile my code with: $ nasm -f elf64 -o hello.m hello.asm $ ld -m elf_x86_64 -r -o hello.ko hello.m and my module code: section .modinfo __mod_kernel_version db "kernel_version=3.6.8", 0 __mod_license db "license=GPL", 0 __mod_author db "author=actics", 0 __mod_description db "description=hello world module in nasm

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

本秂侑毒 提交于 2019-12-04 10:35:26
问题 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

Event-based sampling with the perf userland tool and PEBS

为君一笑 提交于 2019-12-04 09:35:32
I'm doing event-based sampling with the perf userland tool: the objective being trying to find out where certain performance-impacting events like branch misses and cache misses are occurring on a larger system I'm working on. Now, something like perf record -a -e branch-misses:pp -- sleep 5 works perfectly: the PEBS counting mode trigerred by the 'pp' modifier is really accurate when collecting the IP in the samples. Unfortunately, when I try to do the same for cache-misses, i.e. perf record -a -e cache-misses:pp -- sleep 5 # [1] I get Error: sys_perf_event_open() syscall returned with 22

Reading kernel memory using a module

萝らか妹 提交于 2019-12-04 09:22:15
As part of my project I need to read the kernel to get the memory address of system call table and system call address. Or in effect i need to extract the contents of the system call table and all the system calls. Till now I use GDB for this purpose. Is there any way so that I could do it using a kernel module. I am new the kernel module programming. Looking for advice from experts here. Let me first start by saying reading arbitrary kernel memory is tricky business! And there are many ways to do it, which vary in their degree of complexity and flexability. 1) Hard-code the address. Search