kernel-module

human readable timestamp in linux kernel

你说的曾经没有我的故事 提交于 2019-12-04 00:36:14
问题 How can I write human readable timestamp in linux kernel? I think do_gettimeofday returns epoch but I don't want to try to convert it to readable time. I just want a format like Hour:Min:Sec:Msec . Thanks 回答1: Later kernels have a function time_to_tm to break epoch time into human readable format. Here's an example: struct timeval t; struct tm broken; do_gettimeofday(&t); time_to_tm(t.tv_sec, 0, &broken); printk("%d:%d:%d:%ld\n", broken.tm_hour, broken.tm_min, broken.tm_sec, t.tv_usec); Again

Examples for reading text files in FreeBSD kernel module

穿精又带淫゛_ 提交于 2019-12-03 22:06:45
问题 Could anyone give some simple examples (function names are good) for reading text files line by line (binary is OK if text is really hard) in a FreeBSD kernel module, from a given directory? Really appreciate your kind help. 回答1: Here's a sample kernel module that'll cat your /etc/motd on load: // kernel module motd catter. // Doug Luce doug@forephypodia.con.com #include <sys/param.h> #include <sys/vnode.h> #include <sys/fcntl.h> #include <sys/module.h> #include <sys/kernel.h> #include <sys

Netlink Multicast Kernel Group

走远了吗. 提交于 2019-12-03 17:34:28
The task I am trying to achieve is actually quite simple (multicast the string "TEST" to a userland daemon), but the kernel module doesn't compile. It stops with the error: passing argument 4 of ‘genlmsg_multicast_allns’ makes integer from pointer without a cast [enabled by default] But shouldn't it just be the multicast group I defined? Here is the code for "clarification": #include <linux/module.h> #include <net/sock.h> #include <linux/netlink.h> #include <linux/skbuff.h> #include <linux/string.h> #include <net/netlink.h> #include <net/genetlink.h> struct sock *nl_sk = NULL; static void

Unknown symbol in while loading a kernel module

社会主义新天地 提交于 2019-12-03 17:13:24
问题 I need help understanding why I get an error when I insert a module. I have tried this with no success. $ sudo modprobe lpfc_scst FATAL: Error inserting lpfc_scst (/lib/modules/2.6.32-33-generic/extra/lpfc_scst.ko): Unknown symbol in module, or unknown parameter (see dmesg) $ dmesg | tail [ 1201.262842] lpfc_scst: Unknown symbol scst_register_target [ 1201.262949] lpfc_scst: Unknown symbol lpfc_tm_term [ 1201.263161] lpfc_scst: no symbol version for scst_register_session [ 1201.263164] lpfc

Getting user process pid when writing Linux Kernel Module

只愿长相守 提交于 2019-12-03 17:11:51
问题 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 ) ? 回答1: When your read function is executing, it's doing so in the context of the process that issued the system call. You should thus pe able to use current , i.e. current->pid . 回答2: These days, we have some helper functions defined in sched.h. In the case of pid, you can use: pid = task_pid_nr(current); to get the current task's pid. here is

How do I access any kernel symbol in a kernel module?

我只是一个虾纸丫 提交于 2019-12-03 16:43:06
I am wanting to use the function getname in my kernel module. It is not exported. Since I am running into this problem right now, I would like to know how to access and use any kernel symbol that is not exported. I figure that the steps necessary to use one will differ depending what the symbol is, so I'd like to see how it would be done for a type (e.g., a struct), a variable, a table of pointers (like the system call table), and a function. How can these be done in either of these cases: When I know the address of the symbol from System.map or /proc/kallsyms . When I know the name of the

difference between the physical address,device address and virtiual address

∥☆過路亽.° 提交于 2019-12-03 16:40:22
What is the difference between device address , physical address and virtual address ? Actually I am trying for mmap in drivers, I am stuck on this concept. The documentation says: The kernel normally uses virtual addresses. Any address returned by kmalloc(), vmalloc(), and similar interfaces is a virtual address and can be stored in a "void *". The virtual memory system (TLB, page tables, etc.) translates virtual addresses to CPU physical addresses, which are stored as "phys_addr_t" or "resource_size_t". The kernel manages device resources like registers as physical addresses. These are the

Changing the Interrupt descriptor Table

久未见 提交于 2019-12-03 15:06:36
I am using Linux 2.6.26 kernel version and I am trying to change the interrupt descriptor table using a kernel module. I am only trying to change the page fault table entry here. So I make a copy of the original IDT and make changes to the page fault table entry only. The objective of the ISR is to print out information of the page fault before calling the original Page fault handler. But the kernel just crashes once I load it with insmod i.e it specifically crashed with the "loadIDTR" function. With further debugging, I found out that by not changing any entry if I load the IDTR it works fine

Linux Kernel Module (*.ko) compatibility between kernels

橙三吉。 提交于 2019-12-03 14:58:17
I have a simple kernel object that I built for probing around at kernel memory. If I build it on my 64-bit Ubuntu (3.2) machine it works fine on that machine. But it won't insmod on my 64-bit Ubuntu (3.9) machine. And vice versa. It gives me a "-1 Invalid module format" error if I try to run it on a Kernel rev other than the one I'd built it on. I thought insmod linked it dynamically against the exported symbol table and the exported symbol table does not change between kernel revisions. (It gets appended.) Can someone tell me how I can build a kernel module (.ko) that is compatible with

The address in Kernel

笑着哭i 提交于 2019-12-03 13:49:28
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? I did something wrong? Thanks PS: I used a tool to dump the whole memory, physical addresses.