更新了内存管理的目录结构...

This commit is contained in:
gatieme
2016-08-08 20:06:05 +08:00
parent 7faf1cab7b
commit b0fd6ff592
6 changed files with 439 additions and 48 deletions
+80 -18
View File
@@ -1,18 +1,80 @@
ifneq ($(KERNELRELEASE),)
obj-m := crs_pgd.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
make -C $(KERNELDIR) M=$(PWD) modules
clean:
make -C $(KERNELDIR) M=$(PWD) clean
endif
# ------------------------------------------------------------------------------
#
# Makefile for the LDD-LinuxDeviceDrivers.
#
# Author: gatieme
# Create: 2016-07-29 15:50:46
# Last modified: 2016-07-29 16:10:29
# Description:
# This program is loaded as a kernel(v2.6.18 or later) module.
# Use "make install" to load it into kernel.
# Use "make remove" to remove the module out of kernel.
#
# ------------------------------------------------------------------------------
ROOT=../../../../../
#PLATFORM=$(shell $(ROOT)/systype.sh)
#include $(ROOT)/Make.defines.$(PLATFORM)
# my driver description
DRIVER_VERSION := "1.0.0"
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
DRIVER_DESC := "Demo module for LDD-LinuxDeviceDrivers devices"
DRIVER_LICENSE := "Dual BSD/GPL"
MODULE_NAME := crs_pgd
ifneq ($(KERNELRELEASE),)
#CFG_FLAGS += -O2 -I./
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
obj-m := $(MODULE_NAME).o #smodule.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
make -C $(KERNELDIR) M=$(PWD) modules
modules_install:
make -C $(KERNELDIR) M=$(PWD) modules_install
insmod:
sudo insmod $(MODULE_NAME).ko
reinsmod:
sudo rmmod $(MODULE_NAME)
sudo insmod $(MODULE_NAME).ko itype=2 btype=1 ctype=0xAC stype='a'
COMMIT="[1.1.4 带参数的可加载模块](http://book.51cto.com/art/201205/337663.htm)"
github:
cd $(ROOT) && make github
rmmod:
sudo rmmod $(MODULE_NAME)
test :
sudo ../injector/memInjector -l stack -m random -t word_0 --time 1 --timeout 3 -p 1
clean:
make -C $(KERNELDIR) M=$(PWD) clean
rm -f modules.order Module.symvers Module.markers
.PHNOY:
modules modules_install clean
endif
@@ -1,4 +1,4 @@
//#include <asm/system.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/mm_types.h>
#include <linux/sched.h>
@@ -9,11 +9,16 @@ static unsigned long read_pgd(void)
return (unsigned long)current->mm->pgd;
}
extern enum system_states system_state;
static int __init init_cr3_pgd(void)
{
unsigned long cr3;
unsigned long pgd = 0;
printk("system_state = %d\n", system_state);
cr3 = read_cr3();
printk("cr3----------------->0x%lx\n", cr3);
pgd = __pa(read_pgd());