2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) Samsung Electronics, 2014
18 * 2014 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
23 #include <linux/slab.h>
24 #include <linux/limits.h>
25 #include <linux/debugfs.h>
26 #include <linux/uaccess.h>
27 #include <master/swap_debugfs.h>
31 /* remove end-line symbols */
32 static void rm_endline_symbols(char *buf, size_t len)
37 for (p = buf; p != buf_end; ++p)
38 if (*p == '\n' || *p == '\r')
47 * 0x00000d60:/bin/app_sample
49 static int do_add(const char *buf, size_t len)
53 unsigned long main_addr;
54 const char fmt[] = "%%lx:/%%%ds";
57 n = snprintf(fmt_buf, sizeof(fmt_buf), fmt, PATH_MAX - 2);
61 app_path = kmalloc(PATH_MAX, GFP_KERNEL);
65 n = sscanf(buf, fmt_buf, &main_addr, app_path + 1);
72 ret = nsp_add(app_path, main_addr);
86 static int do_rm(const char *buf, size_t len)
91 static int do_rm_all(const char *buf, size_t len)
98 * dlopen_addr@plt:dlsym_addr@plt:launchpad_path
101 * 0x000234:0x000342:/usr/bin/launchpad-loader
103 static int do_set_lpad_info(const char *data, size_t len)
106 unsigned long dlopen_addr;
107 unsigned long dlsym_addr;
109 const char fmt[] = "%%lx:%%lx:/%%%ds";
112 n = snprintf(fmt_buf, sizeof(fmt_buf), fmt, PATH_MAX - 2);
116 lpad_path = kmalloc(PATH_MAX, GFP_KERNEL);
117 if (lpad_path == NULL)
120 n = sscanf(data, fmt_buf, &dlopen_addr, &dlsym_addr, lpad_path + 1);
127 ret = nsp_set_lpad_info(lpad_path, dlopen_addr, dlsym_addr);
136 * appcore_efl_main:__do_app:appcore_init@plt:elm_run@plt:libappcore-efl
139 * 0x3730:0x2960:0x1810:0x1c70:/usr/lib/libappcore-efl.so.1
141 static int do_set_appcore_info(const char *data, size_t len)
144 struct appcore_info_data info;
145 const char fmt[] = "%%lx:%%lx:%%lx:%%lx:/%%%ds";
149 n = snprintf(fmt_buf, sizeof(fmt_buf), fmt, PATH_MAX - 2);
153 path = kmalloc(PATH_MAX, GFP_KERNEL);
157 n = sscanf(data, fmt_buf,
158 &info.ac_efl_main, &info.do_app,
159 &info.ac_init, &info.elm_run, path + 1);
167 ret = nsp_set_appcore_info(&info);
180 static int do_cmd(const char *data, size_t len)
184 const char *cmd_data;
188 return do_rm_all(data + 1, len - 1);
194 if (len < 2 || data[1] != ' ')
202 return do_add(cmd_data, len_data);
204 return do_set_lpad_info(cmd_data, len_data);
206 return do_set_appcore_info(cmd_data, len_data);
208 return do_rm(cmd_data, len_data);
219 /* ============================================================================
220 * === DEBUGFS FOR CMD ===
221 * ============================================================================
223 static ssize_t write_cmd(struct file *file, const char __user *user_buf,
224 size_t count, loff_t *ppos)
229 buf = kmalloc(count + 1, GFP_KERNEL);
233 if (copy_from_user(buf, user_buf, count)) {
239 rm_endline_symbols(buf, count);
241 if (do_cmd(buf, count))
250 static ssize_t read_cmd(struct file *file, char __user *user_buf,
251 size_t count, loff_t *ppos)
255 "\ta $app_path - add\n"
256 "\tr $app_path - remove\n"
258 "\tb dlopen_addr@plt:dlsym_addr@plt:launchpad_path\n"
259 "\tl appcore_efl_main:__do_app:appcore_init@plt:elm_run@plt:libappcore-efl_path\n";
262 ret = simple_read_from_buffer(user_buf, count, ppos,
268 static const struct file_operations fops_cmd = {
271 .llseek = default_llseek
277 /* ============================================================================
278 * === DEBUGFS FOR ENABLE ===
279 * ============================================================================
281 static ssize_t read_enabled(struct file *file, char /*__user*/ *user_buf,
282 size_t count, loff_t *ppos)
286 buf[0] = nsp_get_stat() == NS_OFF ? '0' : '1';
289 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
292 static ssize_t write_enabled(struct file *file, const char /*__user*/ *user_buf,
293 size_t count, loff_t *ppos)
299 buf_size = min(count, (sizeof(buf) - 1));
300 if (copy_from_user(buf, user_buf, buf_size))
303 buf[buf_size] = '\0';
306 ret = nsp_set_stat(NS_ON);
309 ret = nsp_set_stat(NS_OFF);
321 static const struct file_operations fops_enabled = {
322 .read = read_enabled,
323 .write = write_enabled,
324 .llseek = default_llseek,
330 static struct dentry *nsp_dir = NULL;
332 void nsp_debugfs_exit(void)
335 debugfs_remove_recursive(nsp_dir);
340 int nsp_debugfs_init(void)
342 struct dentry *dentry;
344 dentry = swap_debugfs_getdir();
348 nsp_dir = debugfs_create_dir("nsp", dentry);
352 dentry = debugfs_create_file("cmd", 0600, nsp_dir, NULL,
357 dentry = debugfs_create_file("enabled", 0600, nsp_dir, NULL,