[REFACTOR] us_manager: install helper probes
[kernel/swap-modules.git] / writer / kernel_operations_arm.c
1 /*
2  *  SWAP Writer
3  *  modules/writer/kernel_operations_arm.c
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Copyright (C) Samsung Electronics, 2013
20  *
21  * 2013  Alexander Aksenov <a.aksenov@samsung.com>: SWAP Writer module kernel
22  * operaions implement
23  *
24  */
25
26 #include <asm/ptrace.h>
27 #include <asm/uaccess.h>
28 #include <asm/page.h>
29 #include <linux/kernel.h>
30 #include <linux/mm.h>
31 #include <generated/autoconf.h>
32
33 #include "kernel_operations.h"
34
35
36 /* ======================= ARGS ========================== */
37
38 int get_args(unsigned long args[], int cnt, struct pt_regs *regs)
39 {
40         /* All args, except first 4, are passed on the stack */
41         enum { stack_args = 4 };
42         int i, args_in_regs;
43
44         args_in_regs = cnt < 3 ? cnt : 3;
45
46         /* Get first 4 args from registers */
47         switch (args_in_regs) {
48                 case 3:
49                         args[3] = regs->ARM_r3;
50                 case 2:
51                         args[2] = regs->ARM_r2;
52                 case 1:
53                         args[1] = regs->ARM_r1;
54                 case 0:
55                         args[0] = regs->ARM_r0;
56         }
57
58         /* Get other args from stack */
59         for (i = stack_args; i < cnt; ++i) {
60                 unsigned long *args_in_sp = (unsigned long *)regs->ARM_sp +
61                                             i - stack_args;
62                 if (get_user(args[i], args_in_sp))
63                         printk("failed to dereference a pointer, addr=%p\n",
64                                args_in_sp);
65         }
66
67         return 0;
68 }
69
70
71 /* ================== KERNEL SHARED MEM ===================== */
72
73 /* CONFIG_VECTORS_BASE used to handle both MMU and non-MMU cases.
74  * According to docs (Documentation/arm/memory.txt) all vector addresses
75  * are fixed and vectors are always equal to one page, so,
76  * end = start + PAGE_SIZE
77  * */
78
79 const char *get_shared_kmem(struct mm_struct *mm, unsigned long *start,
80                             unsigned long *end)
81 {
82         *start = CONFIG_VECTORS_BASE;
83         *end = CONFIG_VECTORS_BASE + PAGE_SIZE;
84
85         return "[vectors]";
86 }