procfs

How to find all read-write memory address of a process in Linux/UNIX with C/C++ language?

与世无争的帅哥 提交于 2021-02-10 07:25:35
问题 Through /proc file system , it's probable to read memory mappings with /proc/PID_PROCESS/maps , but is there any native APIs that dedicated for this function in C/C++ ? i.e to find out memory address that are writable and readable for process with PID 9322: %> awk -F "-| " '$3 ~ /rw/ { print $1 " " $2}' /proc/9322/maps 0804e000 0804f000 085ed000 0860e000 b7707000 b7708000 b7864000 b7865000 b7865000 b7868000 b7897000 b7898000 b78b6000 b78b7000 bfd2e000 bfd50000 And those address are passed

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(

mmap on /proc/pid/mem

和自甴很熟 提交于 2020-01-19 06:01:49
问题 Has anybody succeeded in mmap'ing a /proc/pid/mem file with Linux kernel 2.6? I am getting an ENODEV (No such device) error. My call looks like this: char * map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, mem_fd, offset); And I have verified by looking at the /proc/pid/maps file while debugging that, when execution reaches this call, offset has the value of the top of the stack minus PAGE_SIZE. I have also verified with ptrace that mmap is setting errno to ENODEV. 回答1: See proc_mem

mmap on /proc/pid/mem

青春壹個敷衍的年華 提交于 2020-01-19 06:01:07
问题 Has anybody succeeded in mmap'ing a /proc/pid/mem file with Linux kernel 2.6? I am getting an ENODEV (No such device) error. My call looks like this: char * map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, mem_fd, offset); And I have verified by looking at the /proc/pid/maps file while debugging that, when execution reaches this call, offset has the value of the top of the stack minus PAGE_SIZE. I have also verified with ptrace that mmap is setting errno to ENODEV. 回答1: See proc_mem

How to parse large amount of data passed to kernel module through /proc file?

久未见 提交于 2019-12-30 08:14:43
问题 Edit: I have found seq_file that eases writing a lot of data from kernel to user-space. What I am looking for is the opposite; an API that facilitates reading a lot of data (more than one page) from user-space. Edit 2 : I am implementing a port of <stdio.h> as a kernel module that would be able to open /proc (and later, other virtual file systems) similar to FILE s and handle input and output similar to <stdio.h> . You can find the project here. I have found a LOT of questions on how the

how to send the kernel data to the user the space using procfs?

▼魔方 西西 提交于 2019-12-25 16:44:42
问题 I am calculating a timestamp in the kernel and later I want to tranfer the tmestamp from kernel to the user space. So I am using procfs for communication between kernel and user. I am using the procfile_read function for sending the data from kernel as shown below. I modified and calculated the timestamp of the kernel code as shown below. //this code is at network device driver level. int netif_rx(struct sk_buff *skb) { __net_timestamp(skb);//I modify the code in kernel to get the timestamp

Print Virtual Address of mem_map using a proc file

 ̄綄美尐妖づ 提交于 2019-12-25 03:14:27
问题 I have to print the contents of the mem_map variable in the kernel. However when I compile my code by issuing make I see: WARNING: "mem_map" [/home/babak/code/module/mem_map.ko] undefined! from: make -C /home/babak/code/linux-3.19.5 M=/home/babak/code/module modules make[1]: Entering directory '/home/babak/code/linux-3.19.5' CC [M] /home/babak/code/module/mem_map.o Building modules, stage 2. MODPOST 1 modules WARNING: "mem_map" [/home/babak/code/module/mem_map.ko] undefined! LD [M] /home

reading the timestamp from kernel using procfs - where is it stored after reading from kernel?

╄→гoц情女王★ 提交于 2019-12-23 04:45:27
问题 when the interrupt occurs in the kernel and If I am reading a timestamp in the kernel. I am reading the timestamp from kernel to the user via procfs. where that interrupt time value will be stored ?? how should the user read that value from the user space ?? ssize_t dev_read(struct file *filp,const char *buf,size_t count,loff_t *offset) { if ( count < sizeof(InterruptTime) ) { // Not enough space provided. return 0; // Or some error code maybe. } if (copy_to_user(buf,&InterruptTime,sizeof

How to create proc entry under /proc/driver?

限于喜欢 提交于 2019-12-21 13:23:03
问题 I want to create a file under a /proc/driver directory. I would like to use a macro like proc_root_driver (or something else provided) rather than use "driver/MODULE_NAME" explicitly. I use create_proc_entry : struct proc_dir_entry *simpleproc_fops_entry; simpleproc_fops_entry = create_proc_entry(MODULE_NAME, 0400, NULL /* proc_root_dir */); After googling, I found suggestion to use proc_root_driver , but when I use it, I get the error proc_root_driver undeclared in this function And also,

What do the counters in /proc/[pid]/io mean?

喜你入骨 提交于 2019-12-17 15:54:09
问题 I'm creating a plugin for Munin to monitor stats of named processes. One of the sources of information would be /proc/[pid]/io. But I have a hard time finding out what the difference is between rchar / wchar and read_bytes / written_bytes . They are not the same, as they provide different values. What do they represent? 回答1: While the proc manpage is woefully behind (and so are most manpages/documentation on anything not relating to cookie-cutter user-space development), this stuff is