energy/ \
parser/ \
retprobe/ \
- webprobe/ \
preload/ \
fbiprobe/ \
wsp/ \
energy/swap_energy.ko
parser/swap_message_parser.ko
retprobe/swap_retprobe.ko
- webprobe/swap_webprobe.ko
loader/swap_loader.ko
preload/swap_preload.ko
uihv/swap_uihv.ko
return 1;
}
-/**
- * @brief Gets webprobe data and puts it to the probe_info struct.
- *
- * @param mb Pointer to the message buffer.
- * @param pd Pointer to the probe_desc struct.
- * @return 0 on success, error code on error.
- */
-int get_webprobe(struct msg_buf *mb, struct probe_desc *pd)
-{
- pd->type = SWAP_WEBPROBE;
-
- return 0;
-}
-
-static int cmp_webprobe(struct probe_info *p0, struct probe_info *p1)
-{
- return 0;
-}
-
/**
* @brief Gets preload data and puts it to the probe_info struct.
*
case SWAP_RETPROBE:
get_probe = get_retprobe;
break;
- case SWAP_WEBPROBE:
- get_probe = get_webprobe;
- break;
case SWAP_PRELOAD_PROBE:
get_probe = get_preload_probe;
break;
case SWAP_RETPROBE:
put_retprobe(&(probe->p_desc.info));
break;
- case SWAP_WEBPROBE:
- break;
case SWAP_PRELOAD_PROBE:
put_preload_probe(&(probe->p_desc.info));
break;
case SWAP_RETPROBE:
cmp_probe = cmp_retprobe;
break;
- case SWAP_WEBPROBE:
- cmp_probe = cmp_webprobe;
- break;
case SWAP_PRELOAD_PROBE:
cmp_probe = cmp_preload_probe;
break;
SWAP_RETPROBE = 0, /* Retprobe */
SWAP_FBIPROBE = 1, /* FBI probe */
SWAP_PRELOAD_PROBE = 2, /* Preload probe */
- SWAP_WEBPROBE = 3, /* Webprobe */
SWAP_GET_CALLER = 4, /* Get caller probe. Supports preload */
SWAP_GET_CALL_TYPE = 5, /* Get call type probe. Supports preload */
SWAP_WRITE_MSG = 6, /* Write messages from user space directly to
+++ /dev/null
-EXTRA_CFLAGS := $(extra_cflags)
-
-obj-m := swap_webprobe.o
-swap_webprobe-y := webprobe.o \
- webprobe_debugfs.o \
- web_msg.o
+++ /dev/null
-/*
- * 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, see <http://www.gnu.org/licenses/>.
- *
- * Copyright (C) Samsung Electronics, 2015
- *
- * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
- *
- */
-
-#include <linux/types.h>
-#include <linux/sched.h>
-#include <linux/stddef.h>
-#include <linux/uaccess.h>
-#include <writer/swap_msg.h>
-#include <writer/event_filter.h>
-#include <swap-asm/swap_uprobes.h>
-#include "web_msg.h"
-
-#define WEB_PREFIX KERN_INFO "[WEB_PROF] "
-/* TODO: develop method for obtaining this data during build... */
-#define LINE_NUMBER_OFFSET 16
-#define FUNCTION_NAME_OFFSET 8
-#define SOURCE_FILE_NAME_OFFSET 12
-
-static long pack_str_form_user(void *data, size_t size, const char __user *s)
-{
- long ret, len;
-
- if (!size)
- return -ENOMEM;
-
- ret = strncpy_from_user(data, s, size);
- if (ret < 0) {
- pr_err(WEB_PREFIX "failed to get userspace string s=%p\n", s);
- return ret;
-
- } else if (ret == size) {
- pr_warn(WEB_PREFIX "user string is very long ret=%ld\n", ret);
- len = ret;
- } else {
- len = ret + 1;
- }
-
- ((char *)data)[len - 1] = '\0';
-
- return len;
-}
-
-void web_sample_msg(struct pt_regs *regs)
-{
- struct task_struct *task = current;
- struct swap_msg *m;
- void *p;
- size_t old_size, size;
- long ret;
- void __user *obj_ptr;
- int line;
- int __user *line_number_ptr;
- const char __user **func_name_ptr;
- const char __user *func_name;
- const char __user **file_name_ptr;
- const char __user *file_name;
-
- if (!check_event(task))
- return;
-
- /* Get opbject pointer */
- obj_ptr = (void __user *)swap_get_uarg(regs, 1);
-
- m = swap_msg_get(MSG_WEB_PROFILING);
- p = swap_msg_payload(m);
- old_size = size = swap_msg_size(m);
-
- /* Type */
- *(u8 *)p = WEB_MSG_SAMPLING;
- p += sizeof(u8);
- size -= sizeof(u8);
-
- /* PID */
- *(u32 *)p = task->tgid;
- p += sizeof(u32);
- size -= sizeof(u32);
-
- /* TID */
- *(u32 *)p = task->pid;
- p += sizeof(u32);
- size -= sizeof(u32);
-
- /* Line number (in source file) */
- line_number_ptr = obj_ptr + LINE_NUMBER_OFFSET;
- if (get_user(line, line_number_ptr)) {
- pr_err("failed to get line number\n");
- goto out;
- }
- *(u32 *)p = (u32)line;
- p += sizeof(u32);
- size -= sizeof(u32);
-
- /* Get function name string pointer */
- func_name_ptr = obj_ptr + FUNCTION_NAME_OFFSET;
- if (get_user(func_name, func_name_ptr)) {
- pr_err("failed to get function name\n");
- goto out;
- }
- ret = pack_str_form_user(p, size, func_name);
- if (ret < 0)
- goto out;
- p += ret;
- size -= ret;
-
- /* Get source file name string pointer */
- file_name_ptr = obj_ptr + SOURCE_FILE_NAME_OFFSET;
- if (get_user(file_name, file_name_ptr)) {
- pr_err("failed to get file name\n");
- goto out;
- }
- ret = pack_str_form_user(p, size, file_name);
- if (ret < 0)
- goto out;
- size -= ret;
-
- swap_msg_flush(m, old_size - size);
-
-out:
- swap_msg_put(m);
-}
+++ /dev/null
-/*
- * 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, see <http://www.gnu.org/licenses/>.
- *
- * Copyright (C) Samsung Electronics, 2015
- *
- * 2015 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
- *
- */
-
-#ifndef _WEB_MSG_H
-#define _WEB_MSG_H
-
-struct pt_regs;
-
-/* Web messages subtype */
-enum web_msg_type {
- WEB_MSG_SAMPLING = 0x00,
-};
-
-void web_msg_entry(struct pt_regs *regs);
-void web_msg_exit(struct pt_regs *regs);
-void web_sample_msg(struct pt_regs *regs);
-
-#endif /* _WEB_MSG_H */
+++ /dev/null
-/**
- * webprobe/webprobe.c
- * @author Ruslan Soloviev
- *
- * @section LICENSE
- *
- * 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, see <http://www.gnu.org/licenses/>.
- *
- * @section COPYRIGHT
- *
- * Copyright (C) Samsung Electronics, 2014
- *
- * @section DESCRIPTION
- *
- * Web application profiling
- */
-
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <us_manager/us_manager.h>
-#include <us_manager/pf/pf_group.h>
-#include <us_manager/probes/probe_info_new.h>
-#include <uprobe/swap_uprobes.h>
-#include <parser/msg_cmd.h>
-#include <master/swap_initializer.h>
-
-#include "webprobe.h"
-#include "webprobe_debugfs.h"
-#include "web_msg.h"
-
-struct web_prof_data {
- struct dentry *app_dentry;
- struct dentry *lib_dentry;
- struct pf_group *pfg;
- u64 inspserver_addr;
- u64 tick_addr;
-
- struct probe_new inspserver_probe;
- struct probe_new tick_probe;
-
- bool enable;
-};
-
-static DEFINE_MUTEX(web_mutex);
-static const char *CHROMIUM_EWK = "/usr/lib/libchromium-ewk.so";
-static struct web_prof_data *web_data;
-
-/* function tick handler */
-static int tick_handler(struct uprobe *p, struct pt_regs *regs);
-static struct probe_desc pin_tick_handler = MAKE_UPROBE(tick_handler);
-
-/* function inspector port */
-static int insport_rhandler(struct uretprobe_instance *ri,
- struct pt_regs *regs);
-static struct probe_desc pin_insport_rhandler =
- MAKE_URPROBE(NULL, insport_rhandler, 0);
-
-static int insport_rhandler(struct uretprobe_instance *ri,
- struct pt_regs *regs)
-{
- set_wrt_launcher_port((int)regs_return_value(regs));
-
- return 0;
-}
-
-static int tick_handler(struct uprobe *p, struct pt_regs *regs)
-{
- web_sample_msg(regs);
-
- return 0;
-}
-
-u64 *web_prof_addr_ptr(enum web_prof_addr_t type)
-{
- u64 *addr_ptr;
-
- mutex_lock(&web_mutex);
- switch (type) {
- case INSPSERVER_START:
- addr_ptr = &web_data->inspserver_addr;
- break;
- case TICK_PROBE:
- addr_ptr = &web_data->tick_addr;
- break;
- default:
- pr_err("ERROR: WEB_PROF_ADDR_PTR_TYPE=0x%x\n", type);
- addr_ptr = NULL;
- }
- mutex_unlock(&web_mutex);
-
- return addr_ptr;
-}
-
-int web_prof_data_set(char *app_path, char *app_id)
-{
- int ret = 0;
-
- mutex_lock(&web_mutex);
- web_data->app_dentry = dentry_by_path(app_path);
- if (!web_data->app_dentry) {
- ret = -EFAULT;
- goto out;
- }
-
- web_data->lib_dentry = dentry_by_path(CHROMIUM_EWK);
- if (!web_data->lib_dentry) {
- ret = -EFAULT;
- goto out;
- }
-
- if (web_data->pfg) {
- put_pf_group(web_data->pfg);
- web_data->pfg = NULL;
- }
-
- web_data->pfg = get_pf_group_by_comm(app_id, web_data->app_dentry);
- if (!web_data->pfg) {
- ret = -EFAULT;
- goto out;
- }
-
-out:
- mutex_unlock(&web_mutex);
-
- return 0;
-}
-
-bool web_prof_enabled(void)
-{
- bool ret;
-
- mutex_lock(&web_mutex);
- ret = web_data->enable;
- mutex_unlock(&web_mutex);
-
- return ret;
-}
-
-static void __web_prof_disable(struct web_prof_data *data)
-{
- pin_unregister(&data->tick_probe, data->pfg);
- pin_unregister(&data->inspserver_probe, data->pfg);
-}
-
-static int __web_prof_enable(struct web_prof_data *data)
-{
- int ret;
-
- data->tick_probe.offset = (unsigned long)data->tick_addr;
- data->tick_probe.desc = &pin_tick_handler;
- ret = pin_register(&data->tick_probe, data->pfg, data->lib_dentry);
- if (ret)
- goto fail0;
-
- data->inspserver_probe.offset = (unsigned long)data->inspserver_addr;
- data->inspserver_probe.desc = &pin_insport_rhandler;
- ret = pin_register(&data->inspserver_probe, data->pfg,
- data->lib_dentry);
- if (ret)
- goto fail1;
-
- return 0;
-
-fail1:
- pin_unregister(&data->tick_probe, data->pfg);
-fail0:
- return ret;
-}
-
-int web_prof_enable(void)
-{
- int ret = 0;
-
- mutex_lock(&web_mutex);
- if (web_data->enable) {
- pr_err("ERROR: Web profiling is already enabled\n");
- ret = -EBUSY;
- goto out;
- }
-
- if (!web_data->inspserver_addr) {
- pr_err("bad inspserver addr 0x%llx\n",
- web_data->inspserver_addr);
- goto out;
- }
-
- if (!web_data->tick_addr) {
- pr_err("bad tick addr 0x%llx\n", web_data->tick_addr);
- goto out;
- }
-
- ret = __web_prof_enable(web_data);
- if (ret) {
- pr_err("failed to enable Web profiling\n");
- goto out;
- }
-
- web_data->enable = true;
-
-out:
- mutex_unlock(&web_mutex);
-
- return ret;
-}
-
-int web_prof_disable(void)
-{
- int ret = 0;
-
- mutex_lock(&web_mutex);
- if (!web_data->enable) {
- pr_err("ERROR: Web profiling is already disabled\n");
- ret = -EBUSY;
- goto out;
- }
-
- __web_prof_disable(web_data);
- if (web_data->pfg) {
- put_pf_group(web_data->pfg);
- web_data->pfg = NULL;
- }
- web_data->enable = false;
-
-out:
- mutex_unlock(&web_mutex);
- return ret;
-}
-
-static int webprobe_module_init(void)
-{
- mutex_lock(&web_mutex);
- web_data = kzalloc(sizeof(*web_data), GFP_KERNEL);
- if (!web_data)
- return -ENOMEM;
-
- web_data->enable = false;
- mutex_unlock(&web_mutex);
-
- return 0;
-}
-
-static void webprobe_module_exit(void)
-{
- mutex_lock(&web_mutex);
- if (web_data->enable)
- __web_prof_disable(web_data);
-
- if (web_data->pfg) {
- put_pf_group(web_data->pfg);
- web_data->pfg = NULL;
- }
-
- kfree(web_data);
- web_data = NULL;
- mutex_unlock(&web_mutex);
-}
-
-SWAP_LIGHT_INIT_MODULE(NULL, webprobe_module_init, webprobe_module_exit,
- webprobe_debugfs_init, webprobe_debugfs_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("SWAP webprobe");
-MODULE_AUTHOR("Ruslan Soloviev <r.soloviev@samsung.com>"
- "Anastasia Lyupa <a.lyupa@samsung.com>");
+++ /dev/null
-#ifndef _WEBPROBE_H
-#define _WEBPROBE_H
-
-/**
- * @file webprobe/webprobe_prof.h
- * @author Anastasia Lyupa <a.lyupa@samsung.com>
- *
- * @section LICENSE
- * 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, see <http://www.gnu.org/licenses/>.
- *
- * @section COPYRIGHT
- * Copyright (C) Samsung Electronics, 2015
- *
- * @section DESCRIPTION
- * Profiling for webprobe
- */
-
-enum web_prof_addr_t {
- INSPSERVER_START = 1,
- TICK_PROBE
-};
-
-int web_prof_enable(void);
-int web_prof_disable(void);
-bool web_prof_enabled(void);
-u64 *web_prof_addr_ptr(enum web_prof_addr_t type);
-int web_prof_data_set(char *app_path, char *app_id);
-
-#endif /* _WEBPROBE_H */
+++ /dev/null
-/**
- * webprobe/webprobe_debugfs.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, see <http://www.gnu.org/licenses/>.
- *
- * Copyright (C) Samsung Electronics, 2015
- *
- * 2015 Anastasia Lyupa <a.lyupa@samsung.com>
- *
- */
-
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/debugfs.h>
-#include <linux/uaccess.h>
-
-#include <master/swap_debugfs.h>
-#include <master/swap_initializer.h>
-
-#include "webprobe_debugfs.h"
-#include "webprobe.h"
-
-static const char ENABLED_FILE[] = "enabled";
-static const char APP_INFO_FILE[] = "app_info";
-static const char INSPSERVER_START_FILE[] = "inspector_server_start";
-static const char TICK_PROBE_FILE[] = "tick_probe";
-
-enum { max_count = 256 };
-static char app_info[max_count];
-
-/* ============================================================================
- * === DEBUGFS FOR WEBPROBE INSTRUMENTATION ===
- * ============================================================================
- */
-
-static ssize_t read_enabled(struct file *file, char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- char buf[2];
-
- buf[0] = web_prof_enabled() ? '1' : '0';
- buf[1] = '\n';
-
- return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
-}
-
-static ssize_t write_enabled(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- int ret = 0;
- char buf[32];
- size_t buf_size;
-
- buf_size = min(count, (sizeof(buf) - 1));
- if (copy_from_user(buf, user_buf, buf_size))
- return -EFAULT;
-
- buf[buf_size] = '\0';
- switch (buf[0]) {
- case '1':
- ret = web_prof_enable();
- break;
- case '0':
- ret = web_prof_disable();
- break;
- default:
- return -EINVAL;
- }
-
- if (ret)
- return ret;
-
- return count;
-}
-
-static const struct file_operations fops_enabled = {
- .write = write_enabled,
- .read = read_enabled,
- .open = swap_init_simple_open,
- .release = swap_init_simple_release,
-};
-
-static ssize_t write_app_info(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- int ret = 0;
- char *buf, *path, *id;
- int n;
-
- if (count > max_count)
- return -ENOMEM;
-
- buf = kmalloc(count + 1, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- if (copy_from_user(buf, user_buf, count)) {
- ret = -EFAULT;
- goto free_buf;
- }
-
- buf[count] = '\0';
-
- path = kmalloc(count, GFP_KERNEL);
- if (!path) {
- ret = -ENOMEM;
- goto free_buf;
- }
-
- id = kmalloc(count, GFP_KERNEL);
- if (!id) {
- ret = -ENOMEM;
- goto free_path;
- }
-
- n = sscanf(buf, "%s %s", path, id);
-
- if (n != 2) {
- ret = -EINVAL;
- goto free_app_info;
- }
-
- web_prof_data_set(path, id);
- snprintf(app_info, sizeof(app_info), "%s\n", buf);
-
-free_app_info:
- kfree(id);
-free_path:
- kfree(path);
-free_buf:
- kfree(buf);
-
- return ret ? ret : count;
-}
-
-static ssize_t read_app_info(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
-{
- return simple_read_from_buffer(userbuf, count, ppos, app_info,
- sizeof(app_info) - 1);
-}
-
-static const struct file_operations fops_app_info = {
- .write = write_app_info,
- .read = read_app_info,
- .open = swap_init_simple_open,
- .release = swap_init_simple_release,
-};
-
-/* ============================================================================
- * === INIT/EXIT ===
- * ============================================================================
- */
-
-static struct dentry *webprobe_dir;
-
-void webprobe_debugfs_exit(void)
-{
- debugfs_remove_recursive(webprobe_dir);
- webprobe_dir = NULL;
-}
-
-int webprobe_debugfs_init(void)
-{
- struct dentry *dentry;
-
- dentry = swap_debugfs_getdir();
- if (!dentry)
- return -ENOENT;
-
- webprobe_dir = swap_debugfs_create_dir("webprobe", dentry);
- if (!webprobe_dir)
- return -ENOMEM;
-
- dentry = swap_debugfs_create_file(ENABLED_FILE, 0600, webprobe_dir,
- NULL, &fops_enabled);
-
- dentry = swap_debugfs_create_file(APP_INFO_FILE, 0600, webprobe_dir,
- NULL, &fops_app_info);
- if (!dentry)
- goto fail;
-
- dentry = swap_debugfs_create_x64(INSPSERVER_START_FILE, 0600,
- webprobe_dir,
- web_prof_addr_ptr(INSPSERVER_START));
- if (!dentry)
- goto fail;
-
- dentry = swap_debugfs_create_x64(TICK_PROBE_FILE, 0600, webprobe_dir,
- web_prof_addr_ptr(TICK_PROBE));
- if (!dentry)
- goto fail;
-
- return 0;
-
-fail:
- webprobe_debugfs_exit();
- return -ENOMEM;
-}
+++ /dev/null
-#ifndef _WEBPROBE_DEBUGFS_H
-#define _WEBPROBE_DEBUGFS_H
-
-/**
- * @file webprobe/webprobe_debugfs.h
- * @author Anastasia Lyupa <a.lyupa@samsung.com>
- *
- * @section LICENSE
- * 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, see <http://www.gnu.org/licenses/>.
- *
- * @section COPYRIGHT
- * Copyright (C) Samsung Electronics, 2015
- *
- * @section DESCRIPTION
- * Debugfs for webprobe
- */
-
-int webprobe_debugfs_init(void);
-void webprobe_debugfs_exit(void);
-
-#endif /* _WEBPROBE_DEBUGFS_H */