mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-11-09 08:38:04 +08:00
完善了list/rbtree遍历进程虚拟地址空间vm_area_struct的学习代码--驱动print_vmarea
This commit is contained in:
1 parent
60cd3d0774
commit
7abbf2743b
11 files changed
+51
-1408
No files matched your search
@@ -2,7 +2,7 @@ all:github
|
||||
|
||||
|
||||
|
||||
COMMIT="完善了thread_info的学习代码--print_thread_info驱动"
|
||||
COMMIT="完善了list/rbtree遍历进程虚拟地址空间vm_area_struct的学习代码--驱动print_vmarea"
|
||||
|
||||
.PHONY : github
|
||||
github:
|
||||
|
||||
@@ -81,7 +81,7 @@ unsigned long show_kstack(union thread_union *threadunion)
|
||||
unsigned long kstack_thread = (unsigned long)threadunion->stack;
|
||||
unsigned long kstack_task = (unsigned long)threadunion->thread_info.task->stack;
|
||||
|
||||
printk(KERN_INFO "THREAD_SIZE : %ld == %ld == %ldKB",
|
||||
printk(KERN_INFO "THREAD_SIZE : %ldB == %ldB == %ldKB",
|
||||
sizeof(union thread_union), THREAD_SIZE, THREAD_SIZE / 1024);
|
||||
//printk(KERN_INFO "THREAD_MASK : 0x%x\n", ~(THREAD_SIZE - 1));
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
cmd_/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/01-process/01-task/print_vmarea/print_vmarea.ko := ld -r -m elf_x86_64 -T ./scripts/module-common.lds --build-id -o /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/01-process/01-task/print_vmarea/print_vmarea.ko /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/01-process/01-task/print_vmarea/print_vmarea.o /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/01-process/01-task/print_vmarea/print_vmarea.mod.o
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,2 +0,0 @@
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/01-process/01-task/print_vmarea/print_vmarea.ko
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/01-process/01-task/print_vmarea/print_vmarea.o
|
||||
@@ -16,3 +16,17 @@ clean:
|
||||
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
insmod:
|
||||
sudo insmod ./print_vmarea.ko
|
||||
|
||||
rmmod:
|
||||
sudo rmmod print_vmarea
|
||||
|
||||
reinsmod:
|
||||
make rmmod
|
||||
make insmod
|
||||
|
||||
|
||||
Whitespace-only changes.
@@ -1 +0,0 @@
|
||||
kernel//home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/01-process/01-task/print_vmarea/print_vmarea.ko
|
||||
@@ -18,6 +18,9 @@
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define STACK_SIZE (8192 * 1024)
|
||||
|
||||
static int pid = 1;
|
||||
|
||||
module_param(pid,int,0644);
|
||||
@@ -47,15 +50,12 @@ void print_vmraea_node(struct vm_area_struct *vmnode)
|
||||
}
|
||||
|
||||
|
||||
static void printvm_list(struct vm_area_struct *vmlist)
|
||||
static void print_vm_list(struct vm_area_struct *vmlist)
|
||||
{
|
||||
struct vm_area_struct *vmnode = vmlist;
|
||||
|
||||
printk("0x%lx - 0x%lx\t",vmnode->vm_start,vmnode->vm_end);
|
||||
|
||||
while (vmnode != NULL)
|
||||
{
|
||||
|
||||
print_vmraea_node(vmnode);
|
||||
|
||||
vmnode = vmnode->vm_next;
|
||||
@@ -71,36 +71,57 @@ static void visit(struct rb_node *root)
|
||||
print_vmraea_node(vmnode);
|
||||
}
|
||||
|
||||
static void print_rb_tree(struct rb_node *root)
|
||||
|
||||
static void print_vm_rb_tree(struct rb_node *root)
|
||||
{
|
||||
if (root != NULL)
|
||||
{
|
||||
print_vm_rb_tree(root->rb_left);
|
||||
visit(root);
|
||||
print_rb_tree(root->rb_left);
|
||||
print_rb_tree(root->rb_right);
|
||||
print_vm_rb_tree(root->rb_right);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print_mm_struct(struct mm_struct *mm)
|
||||
{
|
||||
printk("code : [0x%lx, 0x%lx]\n", mm->start_code, mm->end_code);
|
||||
printk("data : [0x%lx, 0x%lx]\n", mm->start_data, mm->end_data);
|
||||
|
||||
// heap从低地址向高地址扩展,做内存管理相对要简单些。
|
||||
// stack从高地址向低地址扩展,这样栈空间的起始位置就能确定下来,动态的调整栈空间大>
|
||||
printk("heap : [0x%lx, 0x%lx]\n", mm->start_brk, mm->brk);
|
||||
printk("stack: [0x%lx, 0x%lx]\n", mm->start_stack - STACK_SIZE, mm->start_stack);
|
||||
}
|
||||
|
||||
|
||||
static void print_vmarea(void)
|
||||
{
|
||||
struct task_struct *p = NULL;
|
||||
struct pid *k = NULL;
|
||||
|
||||
struct mm_struct *mm = NULL;
|
||||
|
||||
struct vm_area_struct *vmlist = NULL;
|
||||
struct rb_node *root = NULL;
|
||||
|
||||
k = find_vpid(pid);
|
||||
p = pid_task(k, PIDTYPE_PID);
|
||||
|
||||
mm = p->mm;
|
||||
print_mm_struct(mm);
|
||||
|
||||
// visit vmarea by list
|
||||
printk("-------[visit vmarea by list START]-------\n");
|
||||
vmlist = p->mm->mmap;
|
||||
printvm_list(vmlist);
|
||||
vmlist = mm->mmap;
|
||||
print_vm_list(vmlist);
|
||||
printk("-------[visit vmarea by list END]-------\n");
|
||||
|
||||
// visit vmarea by rbtree
|
||||
printk("-------[visit vmarea by rbtree START]-------\n");
|
||||
root = p->mm->mm_rb.rb_node;
|
||||
print_rb_tree(root);
|
||||
root = mm->mm_rb.rb_node;
|
||||
print_vm_rb_tree(root);
|
||||
|
||||
printk("-------[visit vmarea by rbtree END]-------\n");
|
||||
|
||||
return ;
|
||||
@@ -114,9 +135,11 @@ static int __init printvm_init(void)
|
||||
|
||||
static void __exit printvm_exit(void)
|
||||
{
|
||||
printk("<1>exit ---------------------!\n");
|
||||
printk(KERN_INFO"printvm exit ---------------------!\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
module_init(printvm_init);
|
||||
module_exit(printvm_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -1,34 +0,0 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/vermagic.h>
|
||||
#include <linux/compiler.h>
|
||||
|
||||
MODULE_INFO(vermagic, VERMAGIC_STRING);
|
||||
|
||||
__visible struct module __this_module
|
||||
__attribute__((section(".gnu.linkonce.this_module"))) = {
|
||||
.name = KBUILD_MODNAME,
|
||||
.init = init_module,
|
||||
#ifdef CONFIG_MODULE_UNLOAD
|
||||
.exit = cleanup_module,
|
||||
#endif
|
||||
.arch = MODULE_ARCH_INIT,
|
||||
};
|
||||
|
||||
static const struct modversion_info ____versions[]
|
||||
__used
|
||||
__attribute__((section("__versions"))) = {
|
||||
{ 0xcd71858e, __VMLINUX_SYMBOL_STR(module_layout) },
|
||||
{ 0xedf578ce, __VMLINUX_SYMBOL_STR(param_ops_int) },
|
||||
{ 0x41b892fa, __VMLINUX_SYMBOL_STR(pid_task) },
|
||||
{ 0x55d7e3d9, __VMLINUX_SYMBOL_STR(find_vpid) },
|
||||
{ 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) },
|
||||
{ 0xbdfb6dbb, __VMLINUX_SYMBOL_STR(__fentry__) },
|
||||
};
|
||||
|
||||
static const char __module_depends[]
|
||||
__used
|
||||
__attribute__((section(".modinfo"))) =
|
||||
"depends=";
|
||||
|
||||
|
||||
MODULE_INFO(srcversion, "1407329B4F1FA1039D668F7");
|
||||
Reference in new issue
Block a user