From f4b9ebea773983e7ddae33be16873272291e6ee8 Mon Sep 17 00:00:00 2001 From: Alexander Aksenov Date: Tue, 14 Jan 2014 13:30:37 +0400 Subject: [PATCH] [REFACTOR] Ksyms: move module declarations to separate file Change-Id: I1bf303a206f849bceb977a44585b27d5edd9c21e Signed-off-by: Alexander Aksenov --- ksyms/Kbuild | 5 +++-- ksyms/ksyms.c | 21 +-------------------- ksyms/ksyms_init.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ ksyms/ksyms_module.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ ksyms/no_ksyms.c | 13 +++---------- 5 files changed, 103 insertions(+), 32 deletions(-) create mode 100644 ksyms/ksyms_init.h create mode 100644 ksyms/ksyms_module.c diff --git a/ksyms/Kbuild b/ksyms/Kbuild index 70bb2c9..c602e93 100644 --- a/ksyms/Kbuild +++ b/ksyms/Kbuild @@ -1,9 +1,10 @@ EXTRA_CFLAGS := $(extra_cflags) obj-m := swap_ksyms.o +swap_ksyms-y := ksyms_module.o ifeq ($(CONFIG_KALLSYMS),y) - swap_ksyms-y := ksyms.o + swap_ksyms-y += ksyms.o else - swap_ksyms-y := no_ksyms.o + swap_ksyms-y += no_ksyms.o endif diff --git a/ksyms/ksyms.c b/ksyms/ksyms.c index dca39eb..4545d91 100644 --- a/ksyms/ksyms.c +++ b/ksyms/ksyms.c @@ -24,6 +24,7 @@ #include "ksyms.h" +#include "ksyms_init.h" #include #include #include @@ -62,23 +63,3 @@ unsigned long swap_ksyms_substr(const char *name) return sym_data.addr; } EXPORT_SYMBOL_GPL(swap_ksyms_substr); - -int __init swap_ksyms_init(void) -{ - printk("SWAP_KSYMS: Module initialized\n"); - - return 0; -} - -void __exit swap_ksyms_exit(void) -{ - printk("SWAP_KSYMS: Module uninitialized\n"); -} - -module_init(swap_ksyms_init); -module_exit(swap_ksyms_exit); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("SWAP ksyms module"); -MODULE_AUTHOR("Vyacheslav Cherkashin "); - diff --git a/ksyms/ksyms_init.h b/ksyms/ksyms_init.h new file mode 100644 index 0000000..99d44b6 --- /dev/null +++ b/ksyms/ksyms_init.h @@ -0,0 +1,46 @@ +/* + * Dynamic Binary Instrumentation Module based on KProbes + * modules/ksyms/ksyms_init.h + * + * 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. + * + * Copyright (C) Samsung Electronics, 2014 + * + * 2014 Alexander Aksenov + * + */ + +#ifndef __KSYMS_INIT_H__ +#define __KSYMS_INIT_H__ + +#ifdef CONFIG_KALLSYMS + +static inline int ksyms_init(void) +{ + return 0; +} + +static inline void ksyms_exit(void) +{ +} + +#else /* CONFIG_KALLSYMS */ + +int ksyms_init(void); +void ksyms_exit(void); + +#endif /* CONFIG_KALLSYMS */ + +#endif /* __KSYMS_INIT_H__ */ diff --git a/ksyms/ksyms_module.c b/ksyms/ksyms_module.c new file mode 100644 index 0000000..cd4b852 --- /dev/null +++ b/ksyms/ksyms_module.c @@ -0,0 +1,50 @@ +/* + * Dynamic Binary Instrumentation Module based on KProbes + * modules/ksyms/ksyms_module.c + * + * 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. + * + * Copyright (C) Samsung Electronics, 2014 + * + * 2014 Alexander Aksenov + * + */ + +#include "ksyms_init.h" + +#include + +int __init swap_ksyms_init(void) +{ + int ret = ksyms_init(); + + printk("SWAP_KSYMS: Module initialized\n"); + + return ret; +} + +void __exit swap_ksyms_exit(void) +{ + ksyms_exit(); + + printk("SWAP_KSYMS: Module uninitialized\n"); +} + +module_init(swap_ksyms_init); +module_exit(swap_ksyms_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("SWAP ksyms module"); +MODULE_AUTHOR("Vyacheslav Cherkashin "); diff --git a/ksyms/no_ksyms.c b/ksyms/no_ksyms.c index 47c2e67..59c74e3 100644 --- a/ksyms/no_ksyms.c +++ b/ksyms/no_ksyms.c @@ -23,7 +23,7 @@ */ #include "ksyms.h" -#include +#include "ksyms_init.h" #include #include #include @@ -319,7 +319,7 @@ unsigned long swap_ksyms_substr(const char *name) } EXPORT_SYMBOL_GPL(swap_ksyms_substr); -int __init swap_ksyms_init(void) +int ksyms_init(void) { int ret = 0; @@ -339,7 +339,7 @@ int __init swap_ksyms_init(void) return 0; } -void __exit swap_ksyms_exit(void) +void ksyms_exit(void) { down(&cnt_init_sm_lock); @@ -349,10 +349,3 @@ void __exit swap_ksyms_exit(void) up(&cnt_init_sm_lock); } - -module_init(swap_ksyms_init); -module_exit(swap_ksyms_exit); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("SWAP ksyms module"); -MODULE_AUTHOR("Vyacheslav Cherkashin "); -- 2.7.4