2 * @file writer/kernel_operations.h
3 * @author Alexander Aksenov <a.aksenov@samsung.com>
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.
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.
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.
23 * Copyright (C) Samsung Electronics, 2013
25 * @section DESCRIPTION
27 * Writer kernel operations.
30 /* Kernel functions wrap */
32 #ifndef __KERNEL_OPERATIONS_H__
33 #define __KERNEL_OPERATIONS_H__
35 #include <linux/kernel.h>
36 #include <linux/uaccess.h>
37 #include <asm/ptrace.h>
41 /** Prints debug message.*/
42 #define print_debug(msg, args...) \
43 printk(KERN_DEBUG "SWAP_WRITER DEBUG : " msg, ##args)
44 /** Prints info message.*/
45 #define print_msg(msg, args...) \
46 printk(KERN_INFO "SWAP_WRITER : " msg, ##args)
47 /** Prints warning message.*/
48 #define print_warn(msg, args...) \
49 printk(KERN_WARNING "SWAP_WRITER WARNING : " msg, ##args)
50 /** Prints error message.*/
51 #define print_err(msg, args...) \
52 printk(KERN_ERR "SWAP_WRITER ERROR : " msg, ##args)
53 /** Prints critical error message.*/
54 #define print_crit(msg, args...) \
55 printk(KERN_CRIT "SWAP_WRITER CRITICAL : " msg, ##args)
57 /* ARCH-DEPENDED OPERATIONS */
60 /* Regs manipulations */
61 #if defined(CONFIG_ARM)
63 #define get_regs_ip(regs) (regs->ARM_pc) /**< Get pc reg. */
64 #define get_regs_ret_func(regs) (regs->ARM_lr) /**< Get lr reg. */
65 #define get_regs_ret_val(regs) (regs->ARM_r0) /**< Get ret val. */
66 #define get_regs_stack_ptr(regs) (regs->ARM_sp) /**< Get stack pointer. */
68 #elif defined(CONFIG_X86_32)
70 #define get_regs_ip(regs) (regs->ip - 1) /**< Get ip. */
71 #define get_regs_ret_val(regs) (regs->ax) /**< Get ret val. */
72 #define get_regs_stack_ptr(regs) (regs->sp) /**< Get stack pointer. */
74 static inline u32 get_regs_ret_func(struct pt_regs *regs)
78 if (user_mode(regs)) {
80 if (get_user(addr, sp))
81 printk(KERN_INFO "failed to dereference a pointer, sp=%p, "
82 "pc=%lx\n", sp, get_regs_ip(regs));
84 sp = (u32 *)kernel_stack_pointer(regs);
91 #endif /* CONFIG_arch */
93 #endif /* __KERNEL_OPERATIONS_H__ */