[REFACTOR] Ksyms: move module declarations to separate file 73/14973/6
authorAlexander Aksenov <a.aksenov@samsung.com>
Tue, 14 Jan 2014 09:30:37 +0000 (13:30 +0400)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Thu, 27 Mar 2014 04:41:40 +0000 (21:41 -0700)
Change-Id: I1bf303a206f849bceb977a44585b27d5edd9c21e
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
ksyms/Kbuild
ksyms/ksyms.c
ksyms/ksyms_init.h [new file with mode: 0644]
ksyms/ksyms_module.c [new file with mode: 0644]
ksyms/no_ksyms.c

index 70bb2c9..c602e93 100644 (file)
@@ -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
index dca39eb..4545d91 100644 (file)
@@ -24,6 +24,7 @@
 
 
 #include "ksyms.h"
+#include "ksyms_init.h"
 #include <linux/kallsyms.h>
 #include <linux/module.h>
 #include <linux/percpu.h>
@@ -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 <v.cherkashin@samaung.com>");
-
diff --git a/ksyms/ksyms_init.h b/ksyms/ksyms_init.h
new file mode 100644 (file)
index 0000000..99d44b6
--- /dev/null
@@ -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 <a.aksenov@samsung.com>
+ *
+ */
+
+#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 (file)
index 0000000..cd4b852
--- /dev/null
@@ -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 <a.aksenov@samsung.com>
+ *
+ */
+
+#include "ksyms_init.h"
+
+#include <linux/module.h>
+
+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 <v.cherkashin@samaung.com>");
index 47c2e67..59c74e3 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "ksyms.h"
-#include <linux/module.h>
+#include "ksyms_init.h"
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <linux/semaphore.h>
@@ -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 <v.cherkashin@samaung.com>");