mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-08-19 01:22:36 +08:00
list/rbtree遍历进程虚拟地址空间vm_area_struct的学习代码中增加了输出文件映射的代码print_vm_file--驱动print_vmarea
This commit is contained in:
@@ -16,3 +16,17 @@ clean:
|
||||
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
insmod:
|
||||
sudo insmod ./print_task.ko
|
||||
|
||||
rmmod:
|
||||
sudo rmmod print_task
|
||||
|
||||
reinsmod:
|
||||
make rmmod
|
||||
make insmod
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,20 @@
|
||||
#include <linux/mm.h>
|
||||
#include <linux/mm_types.h>
|
||||
|
||||
|
||||
#include <linux/sched.h>
|
||||
#include <linux/sched/rt.h>
|
||||
|
||||
|
||||
|
||||
#if !defined(NICE_TO_PRIO)
|
||||
#define NICE_TO_PRIO(nice) ((nice) + DEFAULT_PRIO)
|
||||
#endif
|
||||
|
||||
#if !defined(PRIO_TO_NICE)
|
||||
#define PRIO_TO_NICE(prio) ((prio) - DEFAULT_PRIO)
|
||||
#endif
|
||||
|
||||
#ifndef offsetof
|
||||
#define offsetof(type, field) ((long) &((type *)0)->field)
|
||||
#endif /* offsetof */
|
||||
@@ -21,12 +35,78 @@
|
||||
static int pid = 1;
|
||||
module_param(pid,int,0644);
|
||||
|
||||
static void print_task_struct(struct task_struct *ptask)
|
||||
{
|
||||
|
||||
static inline int print_task_policy(int policy)
|
||||
{
|
||||
printk("POLICY = ");
|
||||
switch(policy)
|
||||
{
|
||||
case SCHED_FIFO :
|
||||
printk("Real-Time FIFO SCHEDULER TASK\n");
|
||||
break;
|
||||
case SCHED_RR :
|
||||
printk("Real-Time RR SCHEDULER TASK\n");
|
||||
break;
|
||||
case SCHED_DEADLINE :
|
||||
printk("Real-Time EDF SCHEDULER TASK\n");
|
||||
break;
|
||||
case SCHED_NORMAL :
|
||||
printk("Normal NORMAL SCHEDULER TASK\n");
|
||||
break;
|
||||
case SCHED_BATCH :
|
||||
printk("Normal BATCH SCHEDULER TASK\n");
|
||||
break;
|
||||
case SCHED_IDLE :
|
||||
printk("IDLE SCHEDULER TASK\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_task_sched_class(struct sched_class *schedclass)
|
||||
{
|
||||
switch(sched_class)
|
||||
{
|
||||
case &rt_
|
||||
}
|
||||
}
|
||||
|
||||
void print_task_priority(struct task_struct *ptask)
|
||||
{
|
||||
// priority
|
||||
if(rt_task(ptask) == 1)
|
||||
{
|
||||
printk("Real Time Process\n");
|
||||
printk("rt_priority = %d\n", ptask->rt_priority);
|
||||
}
|
||||
else
|
||||
{
|
||||
printk("Normal Process\n");
|
||||
printk("static prio = %d, NICE(%d)\n", ptask->static_prio, PRIO_TO_NICE(ptask->static_prio));
|
||||
}
|
||||
printk("normal_prio = %d\n", ptask->normal_prio);
|
||||
printk("prio = %d\n", ptask->prio);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void print_task_struct(struct task_struct *ptask)
|
||||
{
|
||||
printk("flag = 0x%x\n", ptask->flags);
|
||||
// priority
|
||||
print_task_priority(ptask);
|
||||
|
||||
// policy
|
||||
print_task_policy(ptask->policy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void print_task(int pid)
|
||||
{
|
||||
struct task_struct *ptask;
|
||||
@@ -35,7 +115,7 @@ static void print_task(int pid)
|
||||
k = find_vpid(pid);
|
||||
ptask = pid_task(k, PIDTYPE_PID);
|
||||
|
||||
print_task_struct(task);
|
||||
print_task_struct(ptask);
|
||||
|
||||
|
||||
return ;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
cmd_/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/memory/kv2p/kv2p.ko := aarch64-linux-gnu-ld -EL -r -T /usr/src/linux-headers-3.14.0-20150821.kylin.3.desktop/scripts/module-common.lds --build-id -o /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/memory/kv2p/kv2p.ko /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/memory/kv2p/kv2p.o /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/memory/kv2p/kv2p.mod.o
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/memory/kv2p/kv2p.ko
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/memory/kv2p/kv2p.o
|
||||
@@ -1,7 +1,9 @@
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
|
||||
obj-m := kv2p.o
|
||||
|
||||
else
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
@@ -12,3 +14,19 @@ all:
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
insmod:
|
||||
sudo insmod ./kv2p.ko
|
||||
|
||||
rmmod:
|
||||
sudo rmmod kv2p
|
||||
|
||||
reinsmod:
|
||||
make rmmod
|
||||
make insmod
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ va 接收待查询的虚拟地址
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/sched.h>
|
||||
@@ -22,13 +22,14 @@ module_param(VA, ulong, 0644);
|
||||
|
||||
|
||||
|
||||
static int __init kv2p_init( )
|
||||
static int __init kv2p_init(void)
|
||||
{
|
||||
int value = 10;
|
||||
// use virt_to_phys
|
||||
// http://lxr.free-electrons.com/source/arch/arm64/include/asm/memory.h?v4.7#L189
|
||||
//
|
||||
virt_to_phys(VA);
|
||||
|
||||
phys_addr_t phyaddr = virt_to_phys((const volatile void *)&value);
|
||||
printk("0x%lx\n", (unsigned long )phyaddr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#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"))) = {
|
||||
{ 0x146be775, __VMLINUX_SYMBOL_STR(module_layout) },
|
||||
{ 0x8d2e268b, __VMLINUX_SYMBOL_STR(param_ops_ulong) },
|
||||
{ 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) },
|
||||
{ 0xf8e398fc, __VMLINUX_SYMBOL_STR(memstart_addr) },
|
||||
};
|
||||
|
||||
static const char __module_depends[]
|
||||
__used
|
||||
__attribute__((section(".modinfo"))) =
|
||||
"depends=";
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
kernel//home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/memory/kv2p/kv2p.ko
|
||||
Reference in New Issue
Block a user