Questions tagged [kernel-module]

A kernel module is a run-time loadable object file that is loaded into operating system kernel to add functionality to a running kernel. Examples include device drivers and other kernel items.

2228 questions
23
votes
1 answer

Linux Kernel Modules: When to use try_module_get / module_put

I was reading the LKMPG ( See Section 4.1.4. Unregistering A Device ) and it wasn't clear to me when to use the try_module_get / module_put functions. Some of the LKMPG examples use them, some don't. To add to the confusion, try_module_get appears…
Robert S. Barnes
  • 39,711
  • 30
  • 131
  • 179
22
votes
3 answers

Docker loading kernel modules

I tried to install a kernel module, xfsprogs. It was successfully installed inside a container. It is really surprising, but lsmod doesn't list this module inside container or in the host system. How can a new kernel module loaded in a…
user4725754
22
votes
6 answers

File I/O in a Linux kernel module

I'm writing a Linux kernel module that needs to open and read files. What's the best way to accomplish that?
mipadi
  • 398,885
  • 90
  • 523
  • 479
21
votes
5 answers

How to get current hour (time of day) in linux kernel space

I'm writing a kernel module that checks to see if the time is between two specified hours, and disables input if it is. This has to do with me wanting to make sure I go to bed early. (I know I could also use any number of different techniques…
Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59
19
votes
5 answers

module compiling : asm/linkage.h file not found

I am trying to compile an example of "hello world" Kernel Module, problems found on ubuntu 11.04, kernel 3.2.6, gcc 4.5.2 and fedora 16, kernel 3.2.7, gcc 4.6.7. code: #include #include MODULE_LICENSE("GPL"); static…
Raiden Awkward
  • 203
  • 1
  • 2
  • 6
19
votes
2 answers

How remap_pfn_range remaps kernel memory to user space?

remap_pfn_range function (used in mmap call in driver) can be used to map kernel memory to user space. How is it done? Can anyone explain precise steps? Kernel Mode is a privileged mode (PM) while user space is non privileged (NPM). In PM CPU can…
19
votes
3 answers

insmod fails with "Unknown symbol in module" for a symbol defined in another module

I am working in Ubuntu. I am trying to make two kernel modules which uses each other functions. My problem is that I got modules properly compiled, but the symbol is not resolved for one of them. To make things simple, let's call these modules as…
user5485048
19
votes
3 answers

Getting user process pid when writing Linux Kernel Module

How can I get the PID of the user process which triggered my Kernel module's file_operation.read routine (i.e., which process is reading /dev/mydev) ?
user1592383
18
votes
1 answer

How can I get a filename from a file descriptor inside a kernel module?

I need to get the name of a file from a given file descriptor, inside a small linux kernel module that I wrote. I tried the solution given at Getting Filename from file descriptor in C, but for some reason, it prints out garbage values (on using…
Siddhant
  • 2,535
  • 4
  • 20
  • 22
18
votes
3 answers

How do you create a loadable kernel module for Android?

I know there a number of walkthroughs and tutorials floating around out there which describe this activity, but after having read many of them I still can't get this working. If anyone has the patience to wade through the steps I've taken (posted…
Brian Sweeney
  • 6,693
  • 14
  • 54
  • 69
18
votes
5 answers

kernel module mokutil: failed to enroll new keys

I'm trying to sign some kernel modules (for virtualbox) as explained here. As explained there, I create the new keys: openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -days 36500 -subj "/CN=Descriptive…
user1950164
18
votes
1 answer

Order of preference - printk() vs dev_dbg() vs netdev_dbg()

I recently ran a the scripts/checkpatch.pl script within the linux source tree and got this Warning: WARNING: Prefer netdev_dbg(netdev, ... then dev_dbg(dev, ... then pr_debug(... to printk(KERN_DEBUG ... printk(KERN_DEBUG "Hello World! \n"); I…
Yogesh
  • 740
  • 2
  • 7
  • 15
17
votes
2 answers

Using ioctl communication between Kernel mode and user mode

I want to communicate with my kernel module using ioctl. I have written two c program one for kernel module and other for user mode. I am getting this error while compiling kernel module: error: unknown field ‘ioctl’ specified in initializer at this…
Dalchand
  • 223
  • 1
  • 3
  • 8
17
votes
1 answer

What is the error of "linux unable to handle kernel paging request at ffffffff00000010"?

I have written some Linux kernel code, which causes runtime error, and reports linux unable to handle kernel paging request at ffffffff00000010. It is just a code to hook the open system call in Linux kernel programming. The code is listed…
Victor
  • 1,303
  • 1
  • 10
  • 28
17
votes
4 answers

How to execute shell command in kernel programming?

I want to use system() function of stdlib.h in my c code. I am actually working on kernel programming. Whenever i want to use system() in it, it gives error to stdlib.h saying no such file found.
user2122972
  • 191
  • 1
  • 1
  • 3