kernel-module

How to find physical and logical core number in a kernel module?

℡╲_俬逩灬. 提交于 2019-12-01 16:05:24
Are there kernel functions in Linux that would return the number of the physical core and logical core (in case of Hyperthreading) on which a kernel module is running ? Have a look at the end of include/linux/smp.h : smp_processor_id() gives you the number of the current executing CPU. get_cpu() will do the same and will also disable preemption so that you will stay on that CPU until put_cpu() is called. From user-space, you can use sched_getcpu() or getcpu() to obtain the same information. 来源: https://stackoverflow.com/questions/7315907/how-to-find-physical-and-logical-core-number-in-a-kernel

Is it possible to add a system call via a LKM?

若如初见. 提交于 2019-12-01 15:58:06
I'd like to add a new system call via an LKM, but I'm not sure how to do this. That is, I know that if I want to add a completely new system call, I can look through the sys_call_table and find a sys_ni_syscall and just replace it, but I was curious if it was possible to actually add to the sys_call_table . I realize it's probably not possible, given that it's a fixed size array, but I was wondering if there were any other clever ways to add system calls without overriding an unused system call number. Here's an example linux system calls edit: The example above shows howto implement a system

Hello world kernel module for android & unknown relocation: 27 when insmod

╄→尐↘猪︶ㄣ 提交于 2019-12-01 14:04:37
问题 I am trying to create a simple kernel module. I am trying to print messages to dmesg but i keep getting insmod: init_module 'hello.ko' failed (Exec format error) in android after : dmesg: unknown relocation: 27 #include <linux/module.h> #include <linux/kdb.h> int init_module(void) { printk(KERN_ALERT "Hello world!\n"); return 1; } void cleanup_module(void) { printk(KERN_INFO "Goodbye world 1.\n"); } MODULE_AUTHOR("Robert P. J. Day"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_VERSION("2:1.0") ;

Calling kernel_fpu_begin twice before kernel_fpu_end

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 09:41:07
I'm using the kernel_fpu_begin and kernel_fpu_end functions in asm/i387.h to protect the FPU register states for some simple floating point arithmetic inside of a Linux kernel module. I'm curious about the behavior of calling the kernel_fpu_begin function twice before the kernel_fpu_end function, and vice versa. For example: #include <asm/i387.h> double foo(unsigned num){ kernel_fpu_begin(); double x = 3.14; x += num; kernel_fpu_end(); return x; } ... kernel_fpu_begin(); double y = 1.23; unsigned z = 42; y -= foo(z); kernel_fpu_end(); In the foo function, I call kernel_fpu_begin and kernel_fpu

Calling kernel_fpu_begin twice before kernel_fpu_end

99封情书 提交于 2019-12-01 09:38:32
问题 I'm using the kernel_fpu_begin and kernel_fpu_end functions in asm/i387.h to protect the FPU register states for some simple floating point arithmetic inside of a Linux kernel module. I'm curious about the behavior of calling the kernel_fpu_begin function twice before the kernel_fpu_end function, and vice versa. For example: #include <asm/i387.h> double foo(unsigned num){ kernel_fpu_begin(); double x = 3.14; x += num; kernel_fpu_end(); return x; } ... kernel_fpu_begin(); double y = 1.23;

GCC Return optimiztion

扶醉桌前 提交于 2019-12-01 09:24:08
I'd like to know if GCC can optimize code like int foo(args) { if(is_true) { do_smth; n = call_func(args); do_smth; return n; } else { return call_func(args); } } so that if i'm in else branch call_func's call would be executed like there was no foo call? I'm writing kernel module, and for solving one particular issue I need it to look like this call_func was called directly. To be more specific call_func is some system call. Foo is my version of this system call. In is_true case I should do smth, call this system call and then return its return. But in !is_true I'd like to somehow change the

how does compiler/linker resolves kernel API like 'printk' called from a module on linux

蹲街弑〆低调 提交于 2019-12-01 09:03:45
I have written a sample hello.ko kernel module: #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ int init_module(void) { printk(KERN_INFO "Hello world.\n"); return 0; } void cleanup_module(void) { printk(KERN_INFO "Goodbye world 1.\n"); } Here, I have used "printk" method which is a Kernel API exposed by Linux. I can see the Linux exported symbols in "/proc/kallsyms". I am curious to know how do gcc/ld links the called Kernel APIs? Does gcc/ld gets address of kernel method from "/proc/kallsyms" or some other file and perform linking? If

Can I have more than 32 netlink sockets in kernelspace?

自闭症网瘾萝莉.ら 提交于 2019-12-01 07:28:40
问题 I have several kernel modules which need to interact with userspace. Hence, each module has a Netlink socket. My problem is that these sockets interfere with each other. This is because all of them register to the same Netlink address family (because there aren't many available to begin with - the max is 32 and more than half are already reserved) and also because they all bind themselves to the same pid (the kernel pid - zero). I wish there were more room for address families. Or, better yet

how does compiler/linker resolves kernel API like 'printk' called from a module on linux

ぐ巨炮叔叔 提交于 2019-12-01 06:50:23
问题 I have written a sample hello.ko kernel module: #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ int init_module(void) { printk(KERN_INFO "Hello world.\n"); return 0; } void cleanup_module(void) { printk(KERN_INFO "Goodbye world 1.\n"); } Here, I have used "printk" method which is a Kernel API exposed by Linux. I can see the Linux exported symbols in "/proc/kallsyms". I am curious to know how do gcc/ld links the called Kernel APIs?

Compile linux kernel (2.6) module including non kernel headers

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 04:10:48
Is it possible to compile a linux kernel(2.6) module that includes functionality defined by non-kernel includes? For example: kernelmodule.h #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> // printk() // ... #include <openssl/sha.h> // ... Makefile obj-m := kernelmodule.o all: $(MAKE) -C /lib/modules/`uname -r`/build M=`pwd` modules clean: $(MAKE) -C /lib/modules/`uname -r`/build M=`pwd` clean $(RM) Module.markers modules.order The kernel module I have written and are trying to compile contains functionality found in a number of openssl include files. The standard