get_cpu_gdt_table...

This commit is contained in:
gatieme
2017-03-22 00:11:46 +08:00
parent 5ec939293f
commit 879f3738f9
12 changed files with 1557 additions and 0 deletions
@@ -0,0 +1,28 @@
/*************************************************************************
> File Name: 1.c
> Author: GatieMe
> Mail: gatieme@163.com
> Created Time: Tue 21 Mar 2017 11:45:53 PM CST
************************************************************************/
// Linux内核源代码情景分析
// 2.2 地址映射的全过程
#include <stdio.h>
#include <stdlib.h>
void greeting(void)
{
printf("Hello World\n");
}
int main(int argc, char *argv[])
{
greeting( );
return EXIT_SUCCESS;
}
@@ -8,6 +8,7 @@
#include <linux/mm_types.h>
// [《深入理解Linux内核》内存寻址学习心得](http://blog.chinaunix.net/uid-27776472-id-4304663.html)
MODULE_LICENSE("Dual BSD/GPL");
@@ -0,0 +1 @@
cmd_/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/03-vmarea/00-code/02-gdt_table/get_gdt_table.ko := ld -r -m elf_x86_64 -T ./scripts/module-common.lds --build-id -o /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/03-vmarea/00-code/02-gdt_table/get_gdt_table.ko /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/03-vmarea/00-code/02-gdt_table/get_gdt_table.o /home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/03-vmarea/00-code/02-gdt_table/get_gdt_table.mod.o
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/03-vmarea/00-code/02-gdt_table/get_gdt_table.ko
/home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/03-vmarea/00-code/02-gdt_table/get_gdt_table.o
@@ -0,0 +1,75 @@
# ------------------------------------------------------------------------------
#
# 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.
#
# ------------------------------------------------------------------------------
# my driver description
DRIVER_VERSION := "1.0.0"
DRIVER_AUTHOR := "Gatieme @ AderStep Inc..."
DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices"
DRIVER_LICENSE := "Dual BSD/GPL"
MODULE_NAME := get_gdt_table
ifneq ($(KERNELRELEASE),)
#CFG_FLAGS += -O2 -I./
#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC)
obj-m := $(MODULE_NAME).o #print_vmarea.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
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
@@ -0,0 +1,36 @@
#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>
#include <asm/desc.h>
// [《深入理解Linux内核》内存寻址学习心得](http://blog.chinaunix.net/uid-27776472-id-4304663.html)
// [lxr-get_cpu_gdt_table-Identifier Search](http://lxr.free-electrons.com/source/arch/x86/include/asm/desc.h#L48)
// [lxr-desc_struct-Identifier Search](http://lxr.free-electrons.com/source/arch/x86/include/asm/desc_defs.h#L22)
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
struct desc_struct *gdt_table = get_cpu_gdt_table(0);
return 0;
}
static void hello_exit(void)
{
}
module_init(hello_init);
module_exit(hello_exit);
@@ -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"))) = {
{ 0x9d35aeec, __VMLINUX_SYMBOL_STR(module_layout) },
{ 0xbdfb6dbb, __VMLINUX_SYMBOL_STR(__fentry__) },
};
static const char __module_depends[]
__used
__attribute__((section(".modinfo"))) =
"depends=";
MODULE_INFO(srcversion, "6C7185198AC94911B82AE33");
@@ -0,0 +1 @@
kernel//home/gatieme/Work/GitHub/LDD-LinuxDeviceDrivers/study/kernel/03-vmarea/00-code/02-gdt_table/get_gdt_table.ko