mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-08-20 22:04:56 +08:00
修改目录结构...
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
ROOT=../
|
||||
|
||||
DIRS=mem mmap v2p
|
||||
|
||||
|
||||
|
||||
all:
|
||||
for i in $(DIRS); do \
|
||||
(cd $$i && echo "making $$i" && $(MAKE) ) || exit 1; \
|
||||
done
|
||||
|
||||
clean:
|
||||
for i in $(DIRS); do \
|
||||
(cd $$i && echo "cleaning $$i" && $(MAKE) clean) || exit 1; \
|
||||
done
|
||||
|
||||
install :
|
||||
# for i in $(DIRS); do \
|
||||
# (cd $$i && echo "install $$i" && $(MAKE) install) || exit 1; \
|
||||
# done
|
||||
cp $(INJECTOR)/memInjector $(BIN)/memInjector
|
||||
cp $(ENGINE)/memoryEngine.ko $(BIN)/memoryEngine.ko
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
obj-m := mem_dev.o
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*************************************************************************
|
||||
> File Name: process.c
|
||||
> Author: GatieMe
|
||||
> Mail: gatieme@163.com
|
||||
> Created Time: 2016年04月01日 星期五 21时09分29秒
|
||||
************************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
|
||||
#include <linux/sched.h>
|
||||
|
||||
|
||||
|
||||
//#define METHOD 2
|
||||
static unsigned int METHOD = 1;
|
||||
module_param(METHOD, uint,0400);
|
||||
|
||||
long readPhysicsAddress(unsigned long pa, int *pStatus);
|
||||
|
||||
long writePhysicsAddress(unsigned long pa, unsigned long data, int *pStatus);
|
||||
|
||||
|
||||
|
||||
static int mem_dev_init(void)
|
||||
{
|
||||
readPhysicsAddress(0x12345, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mem_dev_exit(void)
|
||||
{
|
||||
printk( KERN_ALERT "GOOD BYE!!\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** add by gatieme */
|
||||
/*
|
||||
*
|
||||
*/
|
||||
long readPhysicsAddress(unsigned long pa, int *pStatus)
|
||||
{
|
||||
long data = -1;
|
||||
data = *(long *)pa;
|
||||
printk(KERN_INFO "physics address : 0x%lx, data : 0x%lx", pa, data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
long writePhysicsAddress(unsigned long pa, unsigned long data, int *pStatus)
|
||||
{
|
||||
long oldData = -1;
|
||||
|
||||
oldData = *(long *)pa;
|
||||
printk(KERN_INFO "physics address : 0x%lx, old data : 0x%lx", pa, *(long *)pa);
|
||||
|
||||
*(long *)pa = data;
|
||||
printk(KERN_INFO "physics address : 0x%lx, new data : 0x%lx", pa, *(long *)pa);
|
||||
|
||||
return oldData;
|
||||
}
|
||||
|
||||
module_init(mem_dev_init);
|
||||
module_exit(mem_dev_exit);
|
||||
|
||||
MODULE_AUTHOR("gatieme");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -0,0 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define DEVKMEM "/dev/kmem"
|
||||
|
||||
#define PAGE_SIZE 0x1000
|
||||
#define PAGE_MASK (~(PAGE_SIZE-1))
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc != 2)
|
||||
{
|
||||
printf("usage...");
|
||||
exit(-1);
|
||||
}
|
||||
int fd;
|
||||
char *mbase;
|
||||
char read_buf[10];
|
||||
unsigned int regAddr;
|
||||
unsigned int varAddr;
|
||||
|
||||
varAddr = strtoul(argv[1], 0, 16);
|
||||
|
||||
unsigned int ptr = varAddr & ~(PAGE_MASK);
|
||||
|
||||
fd = open(DEVKMEM, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
printf("%s %d", __func__, __LINE__);
|
||||
perror("open");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
mbase = (char *)mmap(0, PAGE_SIZE, PROT_READ, MAP_SHARED,fd, (varAddr & PAGE_MASK));
|
||||
if (mbase == MAP_FAILED)
|
||||
{
|
||||
printf("map failed %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
printf("varAddr = 0x%X \n", varAddr);
|
||||
printf("mapbase = 0x%X \n", (unsigned int)mbase);
|
||||
printf("value = 0x%X \n",*(unsigned int*)(mbase+ptr));
|
||||
printf("char = %c%c%c%c \n",
|
||||
*(char *)(mbase+ptr), *(char *)(mbase+ptr+1),
|
||||
*(char *)(mbase+ptr+2), *(char *)(mbase+ptr+3));
|
||||
|
||||
close(fd);
|
||||
munmap(mbase,PAGE_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* devmem2.c: Simple program to read/write from/to any location in memory.
|
||||
*
|
||||
* Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
|
||||
*
|
||||
*
|
||||
* This software has been developed for the LART computing board
|
||||
* (http://www.lart.tudelft.nl/). The development has been sponsored by
|
||||
* the Mobile MultiMedia Communications (http://www.mmc.tudelft.nl/)
|
||||
* and Ubiquitous Communications (http://www.ubicom.tudelft.nl/)
|
||||
* projects.
|
||||
*
|
||||
* The author can be reached at:
|
||||
*
|
||||
* Jan-Derk Bakker
|
||||
* Information and Communication Theory Group
|
||||
* Faculty of Information Technology and Systems
|
||||
* Delft University of Technology
|
||||
* P.O. Box 5031
|
||||
* 2600 GA Delft
|
||||
* The Netherlands
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <termios.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
|
||||
__LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
|
||||
|
||||
#define MAP_SIZE 4096UL
|
||||
#define MAP_MASK (MAP_SIZE - 1)
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int fd;
|
||||
void *map_base, *virt_addr;
|
||||
unsigned long read_result, writeval;
|
||||
off_t target;
|
||||
int access_type = 'w';
|
||||
|
||||
if(argc < 2) {
|
||||
fprintf(stderr, "\nUsage:\t%s { address } [ type [ data ] ]\n"
|
||||
"\taddress : memory address to act upon\n"
|
||||
"\ttype : access operation type : [b]yte, [h]alfword, [w]ord\n"
|
||||
"\tdata : data to be written\n\n",
|
||||
argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
target = strtoul(argv[1], 0, 0);
|
||||
|
||||
if(argc > 2)
|
||||
access_type = tolower(argv[2][0]);
|
||||
|
||||
|
||||
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
|
||||
printf("/dev/mem opened.\n");
|
||||
fflush(stdout);
|
||||
|
||||
/* Map one page */
|
||||
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
|
||||
if(map_base == (void *) -1) FATAL;
|
||||
printf("Memory mapped at address %p.\n", map_base);
|
||||
fflush(stdout);
|
||||
|
||||
virt_addr = map_base + (target & MAP_MASK);
|
||||
switch(access_type) {
|
||||
case 'b':
|
||||
read_result = *((unsigned char *) virt_addr);
|
||||
break;
|
||||
case 'h':
|
||||
read_result = *((unsigned short *) virt_addr);
|
||||
break;
|
||||
case 'w':
|
||||
read_result = *((unsigned long *) virt_addr);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Illegal data type '%c'.\n", access_type);
|
||||
exit(2);
|
||||
}
|
||||
printf("Value at address 0x%X (%p): 0x%X\n", target, virt_addr, read_result);
|
||||
fflush(stdout);
|
||||
|
||||
if(argc > 3)
|
||||
{
|
||||
writeval = strtoul(argv[3], 0, 0);
|
||||
switch(access_type) {
|
||||
case 'b':
|
||||
*((unsigned char *) virt_addr) = writeval;
|
||||
read_result = *((unsigned char *) virt_addr);
|
||||
break;
|
||||
case 'h':
|
||||
*((unsigned short *) virt_addr) = writeval;
|
||||
read_result = *((unsigned short *) virt_addr);
|
||||
break;
|
||||
case 'w':
|
||||
*((unsigned long *) virt_addr) = writeval;
|
||||
read_result = *((unsigned long *) virt_addr);
|
||||
break;
|
||||
}
|
||||
printf("Written 0x%X; readback 0x%X\n", writeval, read_result);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if(munmap(map_base, MAP_SIZE) == -1) FATAL;
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
|
||||
/*
|
||||
* getjiff.c
|
||||
*
|
||||
* this toolkit shows how to get jiffies value from user space:
|
||||
* 1. find jiffies's address from kernel image.
|
||||
* 2. access virtual address space to get jiffies value.
|
||||
* 3. access physical address sapce to get jiffies value.
|
||||
*
|
||||
* demostrate following techniques:
|
||||
* o get ELF object symbol address by calling nlist()
|
||||
* o access virtual memory space from /dev/kmem
|
||||
* o access virtual memory space from /dev/mem
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> //exit
|
||||
#include <linux/a.out.h> //nlist
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <memory.h>
|
||||
|
||||
#define LONG *(volatile unsigned long*)
|
||||
|
||||
/* read from virtual memory */
|
||||
int read_kmem(off_t offset, void* buf, size_t count)
|
||||
{
|
||||
int fd;
|
||||
int n;
|
||||
|
||||
fd = open("/dev/kmem", O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("open /dev/kmem failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
n = read(fd, buf, count);
|
||||
if (n != count)
|
||||
perror("/dev/kmem read failed");
|
||||
else
|
||||
printf("/dev/kmem read buf = %ld\n", *(unsigned long *)buf);
|
||||
|
||||
close(fd);
|
||||
return n;
|
||||
}
|
||||
|
||||
/* read from physical memory */
|
||||
int read_mem(off_t offset, void* buf, size_t count)
|
||||
{
|
||||
int fd;
|
||||
int n;
|
||||
int page_size;
|
||||
void *map_base;
|
||||
unsigned long value;
|
||||
|
||||
printf("/dev/mem: the offset is %lx\n", offset);
|
||||
|
||||
fd = open("/dev/mem", O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("open /dev/mem failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(1){
|
||||
page_size = getpagesize();
|
||||
printf("the page size = %d\n", page_size);
|
||||
map_base = mmap(0,page_size,PROT_READ,MAP_SHARED,fd,offset);
|
||||
if (map_base == MAP_FAILED){
|
||||
perror("mmap");
|
||||
exit(1);
|
||||
}
|
||||
value = LONG(map_base);
|
||||
printf("/dev/mem: the value is %ld\n", value);
|
||||
buf = (unsigned long *)map_base;
|
||||
}
|
||||
|
||||
if(0){
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
n = read(fd, buf, count);
|
||||
if (n != count)
|
||||
perror("/dev/mem read failed");
|
||||
else
|
||||
printf("/dev/mem read buf = %ld\n", *(unsigned long *)buf);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return n;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char addr_str[11]="0x";
|
||||
char var[51];
|
||||
unsigned long addr;
|
||||
unsigned long jiffies;
|
||||
char ch;
|
||||
int r;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr,"usage: %s System.map\n",argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if ((fp = fopen(argv[1],"r")) == NULL) {
|
||||
perror("fopen");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
do {
|
||||
r = fscanf(fp,"%8s %c %50s\n",&addr_str[2],&ch,var); // format of System.map
|
||||
if (strcmp(var,"jiffies")==0)
|
||||
break;
|
||||
} while(r > 0);
|
||||
if (r < 0) {
|
||||
printf("could not find jiffies\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
addr = strtoul(addr_str,NULL,16); //Convert string to unsigned long integer
|
||||
printf("found jiffies at (%s) %08lx\n",addr_str,addr);
|
||||
|
||||
read_kmem(addr, &jiffies, sizeof(jiffies));
|
||||
printf("jiffies=%ld (read from virtual memory)\n\n", jiffies);
|
||||
|
||||
jiffies = 0; //reinit for checking read_mem() below
|
||||
|
||||
read_mem(addr-0xC0000000, &jiffies, sizeof(jiffies));
|
||||
printf("jiffies=%ld (read from physical memory)\n", jiffies);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
v2p.o: \
|
||||
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/memory/v2p/v2p.c \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/include/linux/kconfig.h \
|
||||
include/linux/autoconf.h include/linux/module.h include/linux/list.h \
|
||||
include/linux/types.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/types.h \
|
||||
include/asm-generic/types.h include/asm-generic/int-ll64.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/bitsperlong.h \
|
||||
include/asm-generic/bitsperlong.h include/linux/posix_types.h \
|
||||
include/linux/stddef.h include/linux/compiler.h \
|
||||
include/linux/compiler-gcc.h include/linux/compiler-gcc4.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/posix_types.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/posix_types_64.h \
|
||||
include/linux/poison.h include/linux/prefetch.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/processor.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/processor-flags.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/vm86.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/ptrace.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/ptrace-abi.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/segment.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/cache.h \
|
||||
include/linux/linkage.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/linkage.h \
|
||||
include/linux/stringify.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/page_types.h \
|
||||
include/linux/const.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/page_64_types.h \
|
||||
include/linux/init.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/math_emu.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/sigcontext.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/current.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/percpu.h \
|
||||
include/linux/kernel.h \
|
||||
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stdarg.h \
|
||||
include/linux/bitops.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/bitops.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/alternative.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/asm.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/cpufeature.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/required-features.h \
|
||||
include/asm-generic/bitops/sched.h include/asm-generic/bitops/hweight.h \
|
||||
include/asm-generic/bitops/fls64.h \
|
||||
include/asm-generic/bitops/ext2-non-atomic.h \
|
||||
include/asm-generic/bitops/le.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/byteorder.h \
|
||||
include/linux/byteorder/little_endian.h include/linux/swab.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/swab.h \
|
||||
include/linux/byteorder/generic.h include/asm-generic/bitops/minix.h \
|
||||
include/linux/log2.h include/linux/typecheck.h include/linux/ratelimit.h \
|
||||
include/linux/param.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/param.h \
|
||||
include/asm-generic/param.h include/linux/dynamic_debug.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/bug.h \
|
||||
include/asm-generic/bug.h include/asm-generic/percpu.h \
|
||||
include/linux/threads.h include/linux/percpu-defs.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/system.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/cmpxchg.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/cmpxchg_64.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/nops.h \
|
||||
include/linux/irqflags.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/irqflags.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/paravirt.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/pgtable_types.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/pgtable_64_types.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/paravirt_types.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/desc_defs.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/kmap_types.h \
|
||||
include/asm-generic/kmap_types.h include/linux/cpumask.h \
|
||||
include/linux/bitmap.h include/linux/string.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/string.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/string_64.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/page.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/page_64.h \
|
||||
include/asm-generic/memory_model.h include/asm-generic/getorder.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/msr.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/msr-index.h \
|
||||
include/linux/ioctl.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/ioctl.h \
|
||||
include/asm-generic/ioctl.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/errno.h \
|
||||
include/asm-generic/errno.h include/asm-generic/errno-base.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/cpumask.h \
|
||||
include/linux/personality.h include/linux/cache.h include/linux/math64.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/div64.h \
|
||||
include/asm-generic/div64.h include/linux/err.h include/linux/stat.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/stat.h \
|
||||
include/linux/time.h include/linux/seqlock.h include/linux/spinlock.h \
|
||||
include/linux/preempt.h include/linux/thread_info.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/thread_info.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/ftrace.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/atomic.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/atomic_64.h \
|
||||
include/asm-generic/atomic-long.h include/linux/bottom_half.h \
|
||||
include/linux/spinlock_types.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/spinlock_types.h \
|
||||
include/linux/lockdep.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/spinlock.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/rwlock.h \
|
||||
include/linux/spinlock_api_smp.h include/linux/kmod.h \
|
||||
include/linux/gfp.h include/linux/mmzone.h include/linux/wait.h \
|
||||
include/linux/numa.h include/linux/nodemask.h \
|
||||
include/linux/pageblock-flags.h include/linux/bounds.h \
|
||||
include/linux/memory_hotplug.h include/linux/notifier.h \
|
||||
include/linux/errno.h include/linux/mutex.h include/linux/rwsem.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/rwsem.h \
|
||||
include/linux/srcu.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/mmzone.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/mmzone_64.h \
|
||||
include/linux/mmdebug.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/smp.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/mpspec.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/mpspec_def.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/x86_init.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/bootparam.h \
|
||||
include/linux/screen_info.h include/linux/apm_bios.h include/linux/edd.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/e820.h \
|
||||
include/linux/ioport.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/ist.h \
|
||||
include/video/edid.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/apic.h \
|
||||
include/linux/delay.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/delay.h \
|
||||
include/linux/pm.h include/linux/workqueue.h include/linux/timer.h \
|
||||
include/linux/ktime.h include/linux/jiffies.h include/linux/timex.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/timex.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/tsc.h \
|
||||
include/linux/debugobjects.h include/linux/completion.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/apicdef.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/fixmap.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/acpi.h \
|
||||
include/acpi/pdc_intel.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/numa.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/numa_64.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/mmu.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/vsyscall.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/idle.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/io_apic.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/irq_vectors.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/sparsemem.h \
|
||||
include/linux/topology.h include/linux/smp.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/topology.h \
|
||||
include/asm-generic/topology.h include/linux/sysctl.h \
|
||||
include/linux/elf.h include/linux/elf-em.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/elf.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/user.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/user_64.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/auxvec.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/vdso.h \
|
||||
include/linux/kobject.h include/linux/sysfs.h include/linux/kref.h \
|
||||
include/linux/moduleparam.h include/linux/tracepoint.h \
|
||||
include/linux/rcupdate.h include/linux/rcutree.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/local.h \
|
||||
include/linux/percpu.h include/linux/slab.h include/linux/slab_def.h \
|
||||
include/linux/kmalloc_sizes.h include/linux/pfn.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/module.h \
|
||||
include/asm-generic/module.h include/trace/events/module.h \
|
||||
include/trace/define_trace.h include/linux/sched.h \
|
||||
include/linux/capability.h include/linux/rbtree.h \
|
||||
include/linux/mm_types.h include/linux/auxvec.h \
|
||||
include/linux/prio_tree.h include/linux/page-debug-flags.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/cputime.h \
|
||||
include/asm-generic/cputime.h include/linux/sem.h include/linux/ipc.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/ipcbuf.h \
|
||||
include/asm-generic/ipcbuf.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/sembuf.h \
|
||||
include/linux/signal.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/signal.h \
|
||||
include/asm-generic/signal-defs.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/siginfo.h \
|
||||
include/asm-generic/siginfo.h include/linux/path.h include/linux/pid.h \
|
||||
include/linux/proportions.h include/linux/percpu_counter.h \
|
||||
include/linux/seccomp.h include/linux/rculist.h include/linux/rtmutex.h \
|
||||
include/linux/plist.h include/linux/resource.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/resource.h \
|
||||
include/asm-generic/resource.h include/linux/hrtimer.h \
|
||||
include/linux/task_io_accounting.h include/linux/latencytop.h \
|
||||
include/linux/cred.h include/linux/key.h include/linux/selinux.h \
|
||||
include/linux/percpu-rwsem.h include/linux/atomic.h include/linux/aio.h \
|
||||
include/linux/aio_abi.h include/linux/uio.h include/linux/mm.h \
|
||||
include/linux/debug_locks.h include/linux/bit_spinlock.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/pgtable.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/pgtable_64.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/pgtable_64_types.h \
|
||||
/usr/src/kernels/2.6.32-573.22.1.el6.x86_64/arch/x86/include/asm/mm_track.h \
|
||||
include/asm-generic/pgtable.h include/linux/page-flags.h \
|
||||
include/linux/huge_mm.h include/linux/vmstat.h
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
obj-m := v2p.o
|
||||
|
||||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
|
||||
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
make -C $(KERNELDIR) M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(KERNELDIR) M=$(PWD) clean
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*****************************************************************
|
||||
文件名:mem.c
|
||||
输入参数:
|
||||
pid 接收待查询进程的PID
|
||||
va 接收待查询的虚拟地址
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/mm.h>
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/page.h>
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
static int pid;
|
||||
static unsigned long va;
|
||||
|
||||
module_param(pid,int,0644);
|
||||
module_param(va,ulong,0644);
|
||||
|
||||
static int find_pgd_init(void)
|
||||
{
|
||||
unsigned long pa = 0;
|
||||
struct task_struct *pcb_tmp = NULL;
|
||||
pgd_t *pgd_tmp = NULL;
|
||||
pud_t *pud_tmp = NULL;
|
||||
pmd_t *pmd_tmp = NULL;
|
||||
pte_t *pte_tmp = NULL;
|
||||
|
||||
printk(KERN_INFO"PAGE_OFFSET = 0x%lx\n",PAGE_OFFSET);
|
||||
printk(KERN_INFO"PGDIR_SHIFT = %d\n",PGDIR_SHIFT);
|
||||
printk(KERN_INFO"PUD_SHIFT = %d\n",PUD_SHIFT);
|
||||
printk(KERN_INFO"PMD_SHIFT = %d\n",PMD_SHIFT);
|
||||
printk(KERN_INFO"PAGE_SHIFT = %d\n",PAGE_SHIFT);
|
||||
|
||||
printk(KERN_INFO"PTRS_PER_PGD = %d\n",PTRS_PER_PGD);
|
||||
printk(KERN_INFO"PTRS_PER_PUD = %d\n",PTRS_PER_PUD);
|
||||
printk(KERN_INFO"PTRS_PER_PMD = %d\n",PTRS_PER_PMD);
|
||||
printk(KERN_INFO"PTRS_PER_PTE = %d\n",PTRS_PER_PTE);
|
||||
|
||||
printk(KERN_INFO"PAGE_MASK = 0x%lx\n",PAGE_MASK);
|
||||
|
||||
if(!(pcb_tmp = find_task_by_pid(pid)))
|
||||
{
|
||||
printk(KERN_INFO"Can't find the task %d .\n",pid);
|
||||
return 0;
|
||||
}
|
||||
printk(KERN_INFO"pgd = 0x%p\n",pcb_tmp->mm->pgd);
|
||||
|
||||
/* 判断给出的地址va是否合法(va<vm_end)*/
|
||||
if(!find_vma(pcb_tmp->mm,va))
|
||||
{
|
||||
printk(KERN_INFO"virt_addr 0x%lx not available.\n",va);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pgd_tmp = pgd_offset(pcb_tmp->mm,va);
|
||||
printk(KERN_INFO"pgd_tmp = 0x%p\n",pgd_tmp);
|
||||
printk(KERN_INFO"pgd_val(*pgd_tmp) = 0x%lx\n",pgd_val(*pgd_tmp));
|
||||
if(pgd_none(*pgd_tmp))
|
||||
{
|
||||
printk(KERN_INFO"Not mapped in pgd.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
pud_tmp = pud_offset(pgd_tmp,va);
|
||||
printk(KERN_INFO"pud_tmp = 0x%p\n",pud_tmp);
|
||||
printk(KERN_INFO"pud_val(*pud_tmp) = 0x%lx\n",pud_val(*pud_tmp));
|
||||
if(pud_none(*pud_tmp))
|
||||
{
|
||||
printk(KERN_INFO"Not mapped in pud.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
pmd_tmp = pmd_offset(pud_tmp,va);
|
||||
printk(KERN_INFO"pmd_tmp = 0x%p\n",pmd_tmp);
|
||||
printk(KERN_INFO"pmd_val(*pmd_tmp) = 0x%lx\n",pmd_val(*pmd_tmp));
|
||||
if(pmd_none(*pmd_tmp))
|
||||
{
|
||||
printk(KERN_INFO"Not mapped in pmd.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*在这里,把原来的pte_offset_map()改成了pte_offset_kernel*/
|
||||
pte_tmp = pte_offset_kernel(pmd_tmp,va);
|
||||
|
||||
printk(KERN_INFO"pte_tmp = 0x%p\n",pte_tmp);
|
||||
printk(KERN_INFO"pte_val(*pte_tmp) = 0x%lx\n",pte_val(*pte_tmp));
|
||||
if(pte_none(*pte_tmp))
|
||||
{
|
||||
printk(KERN_INFO"Not mapped in pte.\n");
|
||||
return 0;
|
||||
}
|
||||
if(!pte_present(*pte_tmp)){
|
||||
printk(KERN_INFO"pte not in RAM.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
pa = (pte_val(*pte_tmp) & PAGE_MASK) | (va & ~PAGE_MASK);
|
||||
printk(KERN_INFO"virt_addr 0x%lx in RAM is 0x%lx t .\n",va,pa);
|
||||
printk(KERN_INFO"contect in 0x%lx is 0x%lx\n", pa, *(unsigned long *)((char *)pa + PAGE_OFFSET));
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static void find_pgd_exit(void)
|
||||
{
|
||||
printk(KERN_INFO"Goodbye!\n");
|
||||
|
||||
}
|
||||
|
||||
module_init(find_pgd_init);
|
||||
module_exit(find_pgd_exit);
|
||||
Reference in New Issue
Block a user