From 6035cdb0a32b76247722137cac4d5c2f64fba86f Mon Sep 17 00:00:00 2001 From: gatieme Date: Tue, 9 May 2017 23:49:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E6=A0=B8=E5=90=8C=E6=AD=A5=E6=9C=BA?= =?UTF-8?q?=E5=88=B6,,,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernel/07-sync/00-code/01-atomic/Makefile | 80 +++++++++++++++++++ .../kernel/07-sync/00-code/01-atomic/hello.c | 50 ++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 study/kernel/07-sync/00-code/01-atomic/Makefile create mode 100644 study/kernel/07-sync/00-code/01-atomic/hello.c diff --git a/study/kernel/07-sync/00-code/01-atomic/Makefile b/study/kernel/07-sync/00-code/01-atomic/Makefile new file mode 100644 index 0000000..dd6b061 --- /dev/null +++ b/study/kernel/07-sync/00-code/01-atomic/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" + + +MODULE_NAME := hello +#MODCFLAGS:=-O2 -Wall -DMODULE -D__KERNEL__ -DLINUX -std=c99 +#EXTRA_CFLAGS += $(MODULE_FLAGS) $(CFG_INC) $(CFG_INC) + + + +ifneq ($(KERNELRELEASE),) # kernelspace + +obj-m := $(MODULE_NAME).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/kernel/07-sync/00-code/01-atomic/hello.c b/study/kernel/07-sync/00-code/01-atomic/hello.c new file mode 100644 index 0000000..f2fb4f4 --- /dev/null +++ b/study/kernel/07-sync/00-code/01-atomic/hello.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +//#include +//#include +//#include + + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_AUTHOR("Gatieme"); +MODULE_DESCRIPTION("test atomic_t"); + + +atomic_t count = ATOMIC_INIT(1); + +static int hello_init(void) +{ + printk("init : %d\n", atomic_read(count)); + + atomic_set(count, 2); + printk("set2 : %d\n", atomic_read(count)); + + atomic_add(count, 3); + printk("add3 : %d\n", atomic_read(count)); + + atomic_sub(count); + printk("sub3 : %d\n", atomic_read(count)); + + + atomic_inc(count); + printk("inc : %d\n", atomic_read(count)); + + atomic_dec(count); + printk("dev : %d\n", atomic_read(count)); + + return 0; +} + + + +static void hello_exit(void) +{ + printk(KERN_ERR"exit"); +} + + +module_init(hello_init); +module_exit(hello_exit);