find-task中添加了print_vm_area的代码...

This commit is contained in:
gatieme
2016-05-16 21:26:51 +08:00
parent cd2534b666
commit 46682f8ea5
4 changed files with 136 additions and 15 deletions
+10 -14
View File
@@ -1,30 +1,26 @@
ifneq ($(KERNELRELEASE),)
CFG_FLAGS += -O2 -I./
EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
#CFG_FLAGS += -O2 -I./
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
# 注意:驱动模块的名字 千万 不能和本文件夹内的任何文件同名!
MODULE_NAME := find-task #指定驱动模块的名字
RESMAIN_CORE_OBJS := find_task.o #指定驱动模块的核心文件(有init 和 exit)
RESMAIN_GLUE_OBJS := get_task.o #依赖文件
MODULE_NAME := find-task
RESMAIN_CORE_OBJS := find_task.o
RESMAIN_GLUE_OBJS := get_task.o
#xxx-objs := 指定驱动模块的所有依赖文件
$(MODULE_NAME)-objs := $(RESMAIN_GLUE_OBJS) $(RESMAIN_CORE_OBJS)
find-task-objs := $(RESMAIN_GLUE_OBJS) $(RESMAIN_CORE_OBJS)
obj-m += find-task.o
#最终由xxx-objs链接生成find-task.o,再生成find-task.ko
obj-m := $(MODULE_NAME).o #最终由xxx-objs链接生成find-task.o,再生成find-task.ko
#$(MODULE_NAME)-objs := $(RESMAIN_GLUE_OBJS) $(RESMAIN_CORE_OBJS)
#obj-m := $(MODULE_NAME).o
else
#最终由xxx-objs链接生成find-task.o,再生成find-task.ko
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
@echo "module name : " $(MODULE_NAME)
@echo "module objs : " $($(MODULE_NAME)-objs)
modules:
make -C $(KERNELDIR) M=$(PWD) modules
modules_install:
@@ -0,0 +1,42 @@
ifneq ($(KERNELRELEASE),)
#CFG_FLAGS += -O2 -I./
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
# 注意:驱动模块的名字 千万 不能和本文件夹内的任何文件同名!
MODULE_NAME := findtask #指定驱动模块的名字
RESMAIN_CORE_OBJS := find_task.o #指定驱动模块的核心文件(有init 和 exit)
RESMAIN_GLUE_OBJS := get_task.o #依赖文件
#xxx-objs := 指定驱动模块的所有依赖文件
$(MODULE_NAME)-objs := $(RESMAIN_GLUE_OBJS) $(RESMAIN_CORE_OBJS)
#最终由xxx-objs链接生成find-task.o,再生成find-task.ko
obj-m := $(MODULE_NAME).o#最终由xxx-objs链接生成find-task.o,再生成find-task.ko
else
#最终由xxx-objs链接生成find-task.o,再生成find-task.ko
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
@echo "module name : " $(MODULE_NAME)
@echo "module objs : " $($(MODULE_NAME)-objs)
make -C $(KERNELDIR) M=$(PWD) modules
modules_install:
make -C $(KERNELDIR) M=$(PWD) modules_install
clean:
make -C $(KERNELDIR) M=$(PWD) clean
.PHNOY:
modules modules_install clean
endif
@@ -9,12 +9,16 @@
#include <linux/moduleparam.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/mm.h>
#include <linux/mm_types.h>
void print_vm_list(struct task_struct *task)
{
struct vm_area_struct *tmp = task->mm->mmap;
printk("process:%s,pid:%d\n", p->comm, p->pid);
printk("process:%s,pid:%d\n", task->comm, task->pid);
while (tmp != NULL)
{
@@ -0,0 +1,79 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/mm.h>
#include <linux/mm_types.h>
#ifndef offsetof
#define offsetof(type, field) ((long) &((type *)0)->field)
#endif /* offsetof */
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
static int pid = 1;
module_param(pid,int,0644);
static void print_vm_area(struct vm_area_struct)
{
((tmp->vm_flags & VM_READ) == 1) ? printk("r") : printk("-");
((tmp->vm_flags & VM_WRITE) == 1) ? printk("w") : printk("-");
((tmp->vm_flags & VM_EXEC) == 1) ? printk("x") : printk("-");
((tmp->vm_flags & VM_SHARED) == 1) ? printk("s") : printk("p");
printk("\n");
}
static void print_vm_area_by_list(struct task_struct *task)
{
struct vm_area_struct *tmp = task->mm->mmap;
printk("process:%s,pid:%d\n", task->comm, task->pid);
while (tmp != NULL)
{
print_vm_area(tmp);
tmp = tmp->vm_next;
}
}
static void visit_rbtree_node(struct rb_node *root)
{
struct vm_area_struct *tmp;
tmp = container_of(root,struct vm_area_struct,vm_rb);
printk("0x%lx - 0x%lx\t",tmp->vm_start,tmp->vm_end);
print_vm_area(tmp);
}
static void preorder_rbtree(struct rb_node *root)
{
if (root != NULL)
{
visit(root);
print_rb_tree(root->rb_left);
print_rb_tree(root->rb_right);
}
}
static void print_vm_area_by_rbtree(struct task_struct *task)
{
struct task_struct *p;
struct pid *k;
struct rb_node *root = NULL;
root = task->mm->mm_rb.rb_node;
print_rb_tree(root);
}