summaryrefslogtreecommitdiff
path: root/writer
diff options
context:
space:
mode:
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>2013-10-02 16:17:47 +0400
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>2013-10-02 18:00:26 +0400
commit64fce1a30e74cb420a7385afa7bca3e728e28e1b (patch)
treeb02268fcab2319742a7a87f1c63acafd2aceaefe /writer
parent920a19045f303ce8acb9cb180be6b3a60e6446cd (diff)
downloadswap-modules-64fce1a30e74cb420a7385afa7bca3e728e28e1b.tar.gz
swap-modules-64fce1a30e74cb420a7385afa7bca3e728e28e1b.tar.bz2
swap-modules-64fce1a30e74cb420a7385afa7bca3e728e28e1b.zip
[IMPROVE] write US messages via sysfs
Change-Id: I2c1e94d1c907e7a764c656e6ca31b0d37cf9f3b6 Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
Diffstat (limited to 'writer')
-rw-r--r--writer/Kbuild4
-rw-r--r--writer/debugfs_writer.c123
-rw-r--r--writer/debugfs_writer.h31
-rw-r--r--writer/swap_writer_module.c27
-rw-r--r--writer/swap_writer_module.h2
5 files changed, 176 insertions, 11 deletions
diff --git a/writer/Kbuild b/writer/Kbuild
index d13f497d..72d7ef34 100644
--- a/writer/Kbuild
+++ b/writer/Kbuild
@@ -1,4 +1,6 @@
EXTRA_CFLAGS := $(extra_cflags)
obj-m := swap_writer.o
-swap_writer-y := swap_writer_module.o kernel_operations.o
+swap_writer-y := swap_writer_module.o \
+ kernel_operations.o \
+ debugfs_writer.o
diff --git a/writer/debugfs_writer.c b/writer/debugfs_writer.c
new file mode 100644
index 00000000..9986a54e
--- /dev/null
+++ b/writer/debugfs_writer.c
@@ -0,0 +1,123 @@
+/*
+ * Dynamic Binary Instrumentation Module based on KProbes
+ * writer/debugfs_writer.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, 2013
+ *
+ * 2013 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include <linux/module.h>
+#include <linux/debugfs.h>
+#include <linux/vmalloc.h>
+#include <asm/uaccess.h>
+#include <driver/swap_debugfs.h>
+#include "swap_writer_module.h"
+
+
+/* ============================================================================
+ * === BUFFER ===
+ * ============================================================================
+ */
+static char *buf = NULL;
+enum { buf_size = 64*1024*1024 };
+
+static int init_buffer(void)
+{
+ buf = vmalloc(buf_size);
+
+ return buf ? 0 : -ENOMEM;
+}
+
+static void exit_buffer(void)
+{
+ vfree(buf);
+ buf = NULL;
+}
+
+
+
+
+
+/* ============================================================================
+ * === FOPS_RAW ===
+ * ============================================================================
+ */
+static ssize_t write_raw(struct file *file, const char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ if (count > buf_size)
+ return -EINVAL;
+
+ if (copy_from_user(buf, user_buf, count))
+ return -EFAULT;
+
+ return raw_msg(buf, count);
+}
+
+static const struct file_operations fops_raw = {
+ .write = write_raw,
+ .llseek = default_llseek
+};
+
+
+
+
+
+/* ============================================================================
+ * === INIT/EXIT ===
+ * ============================================================================
+ */
+static struct dentry *writer_dir = NULL;
+
+void exit_debugfs_writer(void)
+{
+ if (writer_dir)
+ debugfs_remove_recursive(writer_dir);
+
+ writer_dir = NULL;
+
+ exit_buffer();
+}
+
+int init_debugfs_writer(void)
+{
+ int ret;
+ struct dentry *swap_dir, *dentry;
+
+ ret = init_buffer();
+ if (ret)
+ return ret;
+
+ swap_dir = get_swap_debugfs_dir();
+ if (swap_dir == NULL)
+ return -ENOENT;
+
+ writer_dir = debugfs_create_dir("writer", swap_dir);
+ if (writer_dir == NULL)
+ return -ENOMEM;
+
+ dentry = debugfs_create_file("raw", 0600, writer_dir, NULL, &fops_raw);
+ if (dentry == NULL) {
+ exit_debugfs_writer();
+ return -ENOMEM;
+ }
+
+ return 0;
+}
diff --git a/writer/debugfs_writer.h b/writer/debugfs_writer.h
new file mode 100644
index 00000000..60a82057
--- /dev/null
+++ b/writer/debugfs_writer.h
@@ -0,0 +1,31 @@
+#ifndef _DEBUGFS_WRITER_H
+#define _DEBUGFS_WRITER_H
+
+/*
+ * Dynamic Binary Instrumentation Module based on KProbes
+ * writer/debugfs_writer.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, 2013
+ *
+ * 2013 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+int init_debugfs_writer(void);
+void exit_debugfs_writer(void);
+
+#endif /* _DEBUGFS_WRITER_H */
diff --git a/writer/swap_writer_module.c b/writer/swap_writer_module.c
index 481696f0..5748d164 100644
--- a/writer/swap_writer_module.c
+++ b/writer/swap_writer_module.c
@@ -41,6 +41,7 @@
#include "swap_writer_module.h"
#include "swap_writer_errors.h"
#include "kernel_operations.h"
+#include "debugfs_writer.h"
enum MSG_ID {
@@ -660,31 +661,39 @@ int error_msg(const char *fmt, ...)
}
EXPORT_SYMBOL_GPL(error_msg);
+
+
+
+
/* ============================================================================
* = MESSAGES FROM USER SPACE =
* ============================================================================
*/
-int us_msg(void *us_message)
+int raw_msg(char *buf, size_t len)
{
- struct basic_msg_fmt *bmf = (struct basic_msg_fmt *)us_message;
+ struct basic_msg_fmt *bmf = (struct basic_msg_fmt *)buf;
+
+ if (sizeof(*bmf) > len)
+ return -EINVAL;
+
+ if (bmf->len + sizeof(*bmf) != len)
+ return -EINVAL;
set_seq_num(bmf);
- return write_to_buffer(us_message);
-}
-EXPORT_SYMBOL_GPL(us_msg);
+ write_to_buffer(buf);
+ return len;
+}
static int __init swap_writer_module_init(void)
{
- print_msg("SWAP Writer initialized\n");
-
- return 0;
+ return init_debugfs_writer();
}
static void __exit swap_writer_module_exit(void)
{
- print_msg("SWAP Writer uninitialized\n");
+ exit_debugfs_writer();
}
diff --git a/writer/swap_writer_module.h b/writer/swap_writer_module.h
index d69181aa..60acd5f6 100644
--- a/writer/swap_writer_module.h
+++ b/writer/swap_writer_module.h
@@ -64,6 +64,6 @@ int switch_exit(struct pt_regs *regs);
int error_msg(const char *fmt, ...);
-int us_msg(void *us_message);
+int raw_msg(char *buf, size_t len);
#endif /* _SWAP_MSG_H */