linux-kernel

How can a kernel module unload itself without generating errors in kernel log?

安稳与你 提交于 2021-01-28 04:58:54
问题 I've made a simple module which prints GDT and IDT on loading. After it's done its work, it's no longer needed and can be unloaded. But if it returns a negative number in order to stop loading, insmod will complain, and an error message will be logged in kernel log. How can a kernel module gracefully unload itself? 回答1: As far as I can tell, it is not possible with a stock kernel (you can modify the module loader core as I describe below but that's probably not a good thing to rely on). Okay,

What is not allowed in restricted C for ebpf?

放肆的年华 提交于 2021-01-28 02:29:57
问题 From bpf man page: eBPF programs can be written in a restricted C that is compiled (using the clang compiler) into eBPF bytecode. Various features are omitted from this restricted C, such as loops, global variables, variadic functions, floating-point numbers, and passing structures as function arguments. AFAIK the man page it's not updated. I'd like to know what is exactly forbidden when using restricted C to write an eBPF program? Is what the man page says still true? 回答1: It is not really a

Creating a simple write only proc entry in kernel

混江龙づ霸主 提交于 2021-01-28 01:06:21
问题 #include <linux/module.h> #include <linux/kernel.h> #include <linux/proc_fs.h> #include<linux/sched.h> #include <asm/uaccess.h> #include <linux/slab.h> char *msg; ssize_t write_proc(struct file *filp,const char *buf,size_t count,loff_t *offp) { copy_from_user(msg,buf,count); printk(KERN_INFO "%s",msg); return count; } struct file_operations proc_fops = { write: write_proc }; int proc_init (void) { proc_create("write",0,NULL,&proc_fops); return 0; } void proc_cleanup(void) { remove_proc_entry(

C - Linux - Custom kernel module to iterate over a process' children blows up kernel log and the computer

不打扰是莪最后的温柔 提交于 2021-01-27 21:49:30
问题 I'm new to linux kernel modules and I am trying to implement some basic concepts before handling complex ones. I wrote a code which takes a module parameter (an int) and checks if there is a process with that pid. If there is, it takes its children as a list and iterates over it while printing the children's ids and descriptions. Here is the code: #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/types.h> #include <linux/slab.h

What is not allowed in restricted C for ebpf?

别来无恙 提交于 2021-01-27 21:16:19
问题 From bpf man page: eBPF programs can be written in a restricted C that is compiled (using the clang compiler) into eBPF bytecode. Various features are omitted from this restricted C, such as loops, global variables, variadic functions, floating-point numbers, and passing structures as function arguments. AFAIK the man page it's not updated. I'd like to know what is exactly forbidden when using restricted C to write an eBPF program? Is what the man page says still true? 回答1: It is not really a

__LITTLE_ENDIAN_BITFIELD and __BIG_ENDIAN_BITFIELD? [duplicate]

房东的猫 提交于 2021-01-27 18:20:25
问题 This question already has answers here : Why bit endianness is an issue in bitfields? (7 answers) Closed 7 years ago . I want to know what compiler of kernel will do with different endian bitfield: struct iphdr { #if defined(__LITTLE_ENDIAN_BITFIELD) __u8 ihl:4, version:4; #elif defined (__BIG_ENDIAN_BITFIELD) __u8 version:4, ihl:4; #else #error "Please fix <asm/byteorder.h>" #endif ...... }; 回答1: The structure iphdr takes up 1 byte. In a little endian machine, the first field ihl occupies

How to use an own kernel configuration for a raspberry pi in yocto?

谁说我不能喝 提交于 2021-01-27 17:49:43
问题 I like to remove some unused drivers for my RPI2 + custom board. For that I am creating an own configuration via: bitbake linux-raspberrypi -c menuconfig and save the new kernel preset to the file defconfig . After this I created an append file for the linux-raspberryp recipe. So I created the file linux-raspberrypi%.bbappend and filled it with: FILESEXTRAPATHS_prepend := "${THISDIR}/linux-raspberrypi:" SRC_URI += "file://defconfig" PACKAGE_ARCH = "raspberrypi2" I put the defconfig file to:

Where is located syscall_table in kernel x86_64?

烈酒焚心 提交于 2021-01-27 15:16:47
问题 I'm trying to add new System Call to Linux Kernel(x86_64). Based on this article which explained how to add System Call to Kernel(x86). The article says I need to define my System Call name in a file called syscall_table_32.S which is located in src/arch/x86/syscall_table_32.S . But in my case, there is no file named syscall_table_32.S or syscall_table_64.S in the kernel source! There isn't even a directory for x64 System Call table in src/arch/ . So, where is syscall_table_64.S defined in

Kernel: Dealing with deadlocks in unix

你说的曾经没有我的故事 提交于 2021-01-27 13:46:38
问题 A deadlock would occur if process 1 locks resource A and waits for resource B , while simultaneously (due to context switches at the "right" places) process 2 locks resource B and waits for access to resource A . How does Unix deal with such deadlocks? I read the following here . Many deadlocks can be prevented by simply requiring all processes that lock multiple resources to lock them in the same order (e.g., alphabetically by lock name) How can it change the order in which locks are

Linux kernel behaviour on heap overrun or stack overflow

孤者浪人 提交于 2021-01-27 13:19:03
问题 I am trying to understand few important OS concepts (for simplicity, lets stick to Linux Kernel). Assume I run this in kernel mode , perhaps adding these lines (either caseA or caseB not both) into source code of some system call. # Assume __malloc() here is a simple heap memory manager void consume_heap_forever(void) { for (;;) (void) __malloc(PAGE_SIZE); } Case A: The above consumes heap in a loop. I will first start consuming memory and things will go normal. After a high enough