kernel-module

Why printk doesn't print message in kernel log(dmesg)

。_饼干妹妹 提交于 2019-11-29 14:53:29
I wrote small kernel module code as mentioned below, I am testing it in ubuntu 14.04 #include <linux/module.h> #include <linux/version.h> #include <linux/kernel.h> #include <linux/init.h> int init_mod_func(void) { printk(KERN_INFO "My module inserted\n "); return 0; } void cleanup_mod_func(void) { printk(KERN_INFO "My module removed\n "); } module_init(init_mod_func); module_exit(cleanup_mod_func); MODULE_AUTHOR("Ankur"); MODULE_DESCRIPTION("TEST MODULE"); MODULE_LICENSE("GPL"); Now when I compile and insert above module using insmod I don't see printk message in the dmesg. However after

How do I use a Linux System call from a Linux Kernel Module

百般思念 提交于 2019-11-29 14:42:45
I am having some difficulty calling a system call from inside a Linux Kernel Module. The system calls have been tested and work properly from a standard c user space program but I can't seem to get the kernel module to compile and run them. In my user program I include the following code and the system call works: #include <linux/unistd.h> #define __NR_sys_mycall 343 extern long int _syscall(long int_sysno,...)__THROW; //and then a simple call is done as such long value = syscall(__NR_sys_mycall); printf("The value is %ld\n",value); But when I try the same thing in my Linux Kernel Module I get

Linux: modpost does not build anything

时光怂恿深爱的人放手 提交于 2019-11-29 13:54:10
I am having problems getting any kernel modules to build on my machine. Whenever I build a module, modpost always says there are zero modules: MODPOST 0 modules To troubleshoot the problem, I wrote a test module (hello.c): #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/init.h> /* Needed for the macros */ static int __init hello_start(void) { printk(KERN_INFO "Loading hello module...\n"); printk(KERN_INFO "Hello world\n"); return 0; } static void __exit hello_end(void) { printk(KERN_INFO "Goodbye Mr.\n"); } module_init

How to make one Linux kernel module depend on another external module with depmod?

房东的猫 提交于 2019-11-29 11:04:01
I'm writing a kernel module which depends on one existing kernel module. I'm building my module out of the tree (as an external module). How can I declare the dependency, so that it is recognized by depmod? While not entirely satisfying, the best I've come up with to make modprobe work is either adding an entry to modules.dep # tail -1 modules.dep ../../../../home/ctuffli/mymod/mymod.ko: kernel/drivers/scsi/libsas/libsas.ko kernel/drivers/scsi/scsi_transport_sas.ko or alternatively, symbolically linking the out-of-tree module to /lib/modules/ and let depmod figure out the dependencies # ln -s

linux kernel module linker warnings: “*** Warning: <function> [<module>] undefined!” - any way to get rid of them?

*爱你&永不变心* 提交于 2019-11-29 06:48:14
问题 While compiling Linux kernel modules that depend on each other, linker gives undefined symbol warnings like Building modules, stage 2. MODPOST *** Warning: "function_name1" [module_name] undefined! *** Warning: "function_name2" [module_name] undefined! *** Warning: "function_name3" [module_name] undefined! The unresolved symbols are resolved as soon as module is inserted into kernel using insmod or modprobe. Is there any way to get rid of the linker warning, though? I have read through 3

Make a system call to get list of processes

大城市里の小女人 提交于 2019-11-29 04:53:23
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? 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 /proc . Every directory that's an integer in there is an existing process ID and contains a bunch of useful

Compiling out-of-tree kernel module against any kernel source tree on the filesystem

泪湿孤枕 提交于 2019-11-29 02:33:41
I am trying to compile a module against any source tree on the file system but I am having trouble with the Makefile. This was the original Makefile I had against the kernel specified: obj-m += new-mod.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean This Makefile would compile correctly, but goal is to have it compile against any source tree. I have tried just: obj-m += new-mod.o I thought that "all:" is assumed but I get error: make: *** No targets. Stop. I have also added: all: to the Makefile with no

Docker loading kernel modules

我只是一个虾纸丫 提交于 2019-11-29 01:56:17
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 container?( CentOS container, Ubuntu host) Containers interact with the kernel through system calls and don't include any part of the kernel or the kernel modules inside the container. This is one of the reasons why containers designed to be light weight and portable. Also xfsprogs are user space programs and not kernel modules. How can a new kernel module

How remap_pfn_range remaps kernel memory to user space?

妖精的绣舞 提交于 2019-11-28 23:28:43
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 access all memory while in NPM some memory is restricted - cannot be accessed by CPU. When remap_pfn_range is called, how is that range of memory which was restricted only to PM is now accessible to user space? Looking at remap_pfn_range code there is pgprot_t struct . This is protection mapping related struct. What is protection mapping? Is it the

Linux kernel - add system call dynamically through module

两盒软妹~` 提交于 2019-11-28 21:24:25
问题 Is there any way to add a system call dynamic, such as through a module? I have found places where I can override an existing system call with a module by just changing the sys_call_table[] array to get my overridden function instead of the native when my module is installed, but can you do this with a new system call and a module? 回答1: No, sys_call_table is of fixed size: const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = { ... The best you can do, as you probably already discovered,