mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-09-24 05:53:54 +08:00
完善了find-task驱动...
This commit is contained in:
@@ -7,7 +7,7 @@ ifneq ($(KERNELRELEASE),)
|
||||
MODULE_NAME := find-task
|
||||
|
||||
RESMAIN_CORE_OBJS := find_task.o
|
||||
RESMAIN_GLUE_OBJS := get_task.o
|
||||
RESMAIN_GLUE_OBJS := print_task.o print_vmarea.o
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
|
||||
#include <linux/sched.h>
|
||||
|
||||
#include "get_task.h"
|
||||
|
||||
#include "print_task.h"
|
||||
|
||||
/*
|
||||
* macro for find_task_by_pid in the process list
|
||||
@@ -37,7 +38,6 @@ module_param(PID, uint, 0400);
|
||||
|
||||
|
||||
|
||||
void print_vm_list(struct task_struct *task);
|
||||
|
||||
|
||||
void getTaskinfo(struct task_struct *task)
|
||||
@@ -156,7 +156,7 @@ static int init_find_task(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
print_vm_list(pTask);
|
||||
print_task(pTask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,15 @@
|
||||
#include <linux/mm.h>
|
||||
#include <linux/mm_types.h>
|
||||
|
||||
#include "print_vmarea.h"
|
||||
|
||||
|
||||
void print_task(struct task_struct *task)
|
||||
{
|
||||
struct vm_area_struct *tmp = task->mm->mmap;
|
||||
|
||||
printk("process : %s, pid : %d\n", task->comm, task->pid);
|
||||
|
||||
printf_task_vmarea(task->mm->mmap);
|
||||
print_task_vmarea(task);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
#ifndef __GET_TASK_H_INCLUDE__
|
||||
#define __GET_TASK_H_INCLUDE__
|
||||
#ifndef __PRINT_TASK_H_INCLUDE__
|
||||
#define __PRINT_TASK_H_INCLUDE__
|
||||
|
||||
|
||||
void print_vm_list(struct task_struct *task);
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
|
||||
#include <linux/sched.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/mm_types.h>
|
||||
|
||||
#include "print_vmarea.h"
|
||||
|
||||
|
||||
#endif
|
||||
void print_task(struct task_struct *task);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // #define __PRINT_TASK_H_INCLUDE__
|
||||
|
||||
@@ -31,53 +31,52 @@ static void print_vmarea(struct vm_area_struct *vmarea)
|
||||
|
||||
static void print_vmarea_by_list(struct task_struct *task)
|
||||
{
|
||||
struct vm_area_struct *tmp = task->mm->mmap;
|
||||
struct vm_area_struct *vmarea = task->mm->mmap;
|
||||
|
||||
printk("process : %s, pid : %d\n", task->comm, task->pid);
|
||||
|
||||
while (tmp != NULL)
|
||||
while (vmarea != NULL)
|
||||
{
|
||||
print_vm_area(tmp);
|
||||
tmp = tmp->vm_next;
|
||||
print_vmarea(vmarea);
|
||||
vmarea = vmarea->vm_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void visit_rbtree_node(struct rb_node *root)
|
||||
{
|
||||
struct vm_area_struct *vmarea NULL;
|
||||
struct vm_area_struct *vmarea = NULL;
|
||||
|
||||
vmarea = container_of(root,struct vm_area_struct,vm_rb);
|
||||
|
||||
print_vm_area(tmp);
|
||||
print_vmarea(vmarea);
|
||||
}
|
||||
|
||||
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);
|
||||
visit_rbtree_node(root);
|
||||
preorder_rbtree(root->rb_left);
|
||||
preorder_rbtree(root->rb_right);
|
||||
}
|
||||
}
|
||||
|
||||
static void print_vmarea_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);
|
||||
|
||||
preorder_rbtree(root);
|
||||
|
||||
}
|
||||
|
||||
static void print_stack_vmarea(struct task_struct *task)
|
||||
void print_task_vmarea(struct task_struct *task)
|
||||
{
|
||||
printk(KERN_ALERT "print vmarea_list");
|
||||
print_vmarea_list(task);
|
||||
print_vmarea_by_list(task);
|
||||
printk(KERN_ALERT "print vmarea_rbtree");
|
||||
print_vmarea_rbtree(task);
|
||||
print_vmarea_by_rbtree(task);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef __PRINT_VMAREA_H_INCLUDE__
|
||||
#define __PRINT_VMAREA_H_INCLUDE__
|
||||
|
||||
|
||||
|
||||
void print_task_vmarea(struct task_struct *task);
|
||||
|
||||
|
||||
#endif // #define __PRINT_VMAREA_H_INCLUDE__
|
||||
Reference in New Issue
Block a user