eb51ed75b790cfebb3ead8691831ba257ada01f9
[platform/kernel/swap-modules.git] / writer / kernel_operations.h
1 /**
2  * @file writer/kernel_operations.h
3  * @author Alexander Aksenov <a.aksenov@samsung.com>
4  *
5  * @section LICENSE
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * @section COPYRIGHT
22  *
23  * Copyright (C) Samsung Electronics, 2013
24  *
25  * @section DESCRIPTION
26  *
27  * Writer kernel operations.
28  */
29
30 /* Kernel functions wrap */
31
32 #ifndef __KERNEL_OPERATIONS_H__
33 #define __KERNEL_OPERATIONS_H__
34
35 #include <linux/kernel.h>
36 #include <asm/ptrace.h>
37
38 /* MESSAGES */
39
40 /** Prints debug message.*/
41 #define print_debug(msg, args...) \
42         printk(KERN_DEBUG "SWAP_WRITER DEBUG : " msg, ##args)
43 /** Prints info message.*/
44 #define print_msg(msg, args...)   \
45         printk(KERN_INFO "SWAP_WRITER : " msg, ##args)
46 /** Prints warning message.*/
47 #define print_warn(msg, args...)  \
48         printk(KERN_WARNING "SWAP_WRITER WARNING : " msg, ##args)
49 /** Prints error message.*/
50 #define print_err(msg, args...)   \
51         printk(KERN_ERR "SWAP_WRITER ERROR : " msg, ##args)
52 /** Prints critical error message.*/
53 #define print_crit(msg, args...)  \
54         printk(KERN_CRIT "SWAP_WRITER CRITICAL : " msg, ##args)
55
56 /* ARCH-DEPENDED OPERATIONS */
57
58
59 /* Regs manipulations */
60 #if defined(CONFIG_ARM)
61
62 #define get_regs_ip(regs)           (regs->ARM_pc)    /**< Get pc reg. */
63 #define get_regs_ret_func(regs)     (regs->ARM_lr)    /**< Get lr reg. */
64 #define get_regs_ret_val(regs)      (regs->ARM_r0)    /**< Get ret val. */
65 #define get_regs_stack_ptr(regs)    (regs->ARM_sp)    /**< Get stack pointer. */
66
67 #elif defined(CONFIG_X86_32)
68
69 #define get_regs_ip(regs)           (regs->ip - 1)    /**< Get ip. */
70 #define get_regs_ret_val(regs)      (regs->ax)        /**< Get ret val. */
71 #define get_regs_stack_ptr(regs)    (regs->sp)        /**< Get stack pointer. */
72
73 static inline u32 get_regs_ret_func(struct pt_regs *regs)
74 {
75         u32 *sp, addr = 0;
76
77         if (user_mode(regs)) {
78                 sp = (u32 *)regs->sp;
79                 if (get_user(addr, sp))
80                         printk(KERN_INFO "failed to dereference a pointer, sp=%p, "
81                                "pc=%lx\n", sp, get_regs_ip(regs));
82         } else {
83                 sp = (u32 *)kernel_stack_pointer(regs);
84                 addr = *sp;
85         }
86
87         return addr;
88 }
89
90 #endif /* CONFIG_arch */
91
92 int get_args(unsigned long args[], int cnt, struct pt_regs *regs);
93
94 /* Returns shared kernel memory area name if it is found, otherwise - NULL */
95 const char *get_shared_kmem(struct mm_struct *mm, unsigned long *start,
96                             unsigned long *end);
97
98 #endif /* __KERNEL_OPERATIONS_H__ */