diff --git a/books/fengguojin/src/1-drivermodel/1-3register_chrdev/test/test b/books/fengguojin/src/1-drivermodel/1-3register_chrdev/test/test new file mode 100755 index 0000000..42dc9dd Binary files /dev/null and b/books/fengguojin/src/1-drivermodel/1-3register_chrdev/test/test differ diff --git a/study/debug/tools/systemtap/00-code/3-components_of_a_systemTap_script/1.stp b/study/debug/tools/systemtap/00-code/3-components_of_a_systemTap_script/1.stp new file mode 100644 index 0000000..1943202 --- /dev/null +++ b/study/debug/tools/systemtap/00-code/3-components_of_a_systemTap_script/1.stp @@ -0,0 +1,16 @@ + + +probe syscall.mkdir +{ + printf("exit %s\n", argstr); +} + +probe begin +{ + printf("test mkdir begin\n"); +} + +probe end +{ + printf("test mkdir end\n"); +} diff --git a/study/debug/tools/systemtap/1.stp b/study/debug/tools/systemtap/1.stp new file mode 100644 index 0000000..4ee8be6 --- /dev/null +++ b/study/debug/tools/systemtap/1.stp @@ -0,0 +1,22 @@ +probe begin +{ + log("begin to probe") +} + + +probe syscall.open +{ + printf ("%s(%d) open (%s)\n", execname(), pid(), argstr) +} + + +probe timer.ms(4000) # after 4 seconds +{ + exit () +} + + +probe end +{ + log("end to probe") +} diff --git a/study/debug/tools/systemtap/m.stp b/study/debug/tools/systemtap/m.stp new file mode 100644 index 0000000..2a5760f --- /dev/null +++ b/study/debug/tools/systemtap/m.stp @@ -0,0 +1,9 @@ +probe process("/lib64/libc.so.6").function("malloc") { + if (target()== pid()) { + print_ubacktrace(); + exit(); + } +} +probe begin { + println("~"); +} diff --git a/study/debug/tools/systemtap/t.c b/study/debug/tools/systemtap/t.c new file mode 100644 index 0000000..5539c31 --- /dev/null +++ b/study/debug/tools/systemtap/t.c @@ -0,0 +1,21 @@ +/************************************************************************* + > File Name: t.c + > Author: gatieme + > Created Time: Thu 13 Apr 2017 06:13:39 PM CST + ************************************************************************/ + +#include +#include + + +void fun() +{ + malloc(1000); +} + +int main(int argc, char *argv[]) +{ + fun(); + + return 0; +} diff --git a/study/driver/00-code/android/hello/hello.c b/study/driver/00-code/android/hello/hello.c index 2d22a1a..e99ec2d 100644 --- a/study/driver/00-code/android/hello/hello.c +++ b/study/driver/00-code/android/hello/hello.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "hello.h" diff --git a/study/driver/00-code/export_symbol/Makefile b/study/driver/00-code/export_symbol/Makefile new file mode 100644 index 0000000..b14b45c --- /dev/null +++ b/study/driver/00-code/export_symbol/Makefile @@ -0,0 +1,80 @@ +# ------------------------------------------------------------------------------ +# +# 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 := "Linux input module for Elo MultiTouch(MT) devices" +DRIVER_LICENSE := "Dual BSD/GPL" + + +#MODCFLAGS:=-O2 -Wall -DMODULE -D__KERNEL__ -DLINUX -std=c99 +#EXTRA_CFLAGS += $(MODULE_FLAGS) $(CFG_INC) $(CFG_INC) + + + +ifneq ($(KERNELRELEASE),) # kernelspace + +obj-m += add_sub.o +obj-m += test.o + +else # userspace + + +CURRENT_PATH ?= $(shell pwd) +LINUX_KERNEL ?= $(shell uname -r) +LINUX_KERNEL_PATH ?= /lib/modules/$(LINUX_KERNEL)/build + +CURRENT_PATH := $(shell pwd) + +modules: + make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules + +modules_install: + make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) 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 $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean + rm -f modules.order Module.symvers Module.markers + +.PHNOY: + modules modules_install clean + + + +endif + diff --git a/study/driver/00-code/export_symbol/add_sub.c b/study/driver/00-code/export_symbol/add_sub.c new file mode 100644 index 0000000..fca0130 --- /dev/null +++ b/study/driver/00-code/export_symbol/add_sub.c @@ -0,0 +1,21 @@ +#include +#include + + +/* 函数返回 a 和 a 的和 */ +long add_integer(int a, int b) +{ + return a + b; +} +EXPORT_SYMBOL(add_integer); + + +/* 函数返回 a 和 b 的差 */ +long sub_integer(int a, int b) +{ + return a - b; +} +EXPORT_SYMBOL_GPL(sub_integer); + + +MODULE_LICENSE("Dual BSD/GPL"); diff --git a/study/driver/00-code/export_symbol/add_sub.h b/study/driver/00-code/export_symbol/add_sub.h new file mode 100644 index 0000000..212ebc5 --- /dev/null +++ b/study/driver/00-code/export_symbol/add_sub.h @@ -0,0 +1,8 @@ +#ifndef _ADD_SUB_H_ +#define _ADD_SUB_H_ + +long add_integer(long a, long b); + +long sub_integer(long a, long b); + +#endif diff --git a/study/driver/00-code/export_symbol/test.c b/study/driver/00-code/export_symbol/test.c new file mode 100644 index 0000000..1830b79 --- /dev/null +++ b/study/driver/00-code/export_symbol/test.c @@ -0,0 +1,52 @@ +#include +#include + +#include "add_sub.h" + + +/* 定义模块传递的参数 a, b */ +static long a = 1; +module_param(a, long, S_IRUGO); + +static long b = 1; +module_param(b, long, S_IRUGO); + +static int add_or_sub = 1; +module_param(add_or_sub, int, S_IRUGO); + + +static int test_init(void) +{ + long result = 0; + printk(KERN_ALERT "test init\n"); + + if(add_or_sub == 1) + { + result = add_integer(a, b); + } + else + { + result = sub_integer(a, b); + } + + printk(KERN_ALERT "The %s result is %ld\n", + add_or_sub == 1 ? "ADD" : "SUB", result); + + + return 0; +} + + +static void test_exit(void) +{ + printk(KERN_ALERT "test exit\n"); +} + +module_init(test_init); +module_exit(test_exit); + +/* 描述信息 */ +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_AUTHOR("Zheng Qiang"); +MODULE_DESCRIPTION("A module for testing module param and EXPORT_SYMBOL"); +MODULE_VERSION("V1.0");