18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 38c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 48c2ecf20Sopenharmony_ci * for more details. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 by Ralf Baechle 78c2ecf20Sopenharmony_ci * Copyright (C) 1999, 2000 Silicon Graphics, Inc. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#ifndef _ASM_PTRACE_H 108c2ecf20Sopenharmony_ci#define _ASM_PTRACE_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/compiler.h> 148c2ecf20Sopenharmony_ci#include <linux/linkage.h> 158c2ecf20Sopenharmony_ci#include <linux/types.h> 168c2ecf20Sopenharmony_ci#include <asm/isadep.h> 178c2ecf20Sopenharmony_ci#include <asm/page.h> 188c2ecf20Sopenharmony_ci#include <asm/thread_info.h> 198c2ecf20Sopenharmony_ci#include <uapi/asm/ptrace.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* 228c2ecf20Sopenharmony_ci * This struct defines the way the registers are stored on the stack during a 238c2ecf20Sopenharmony_ci * system call/exception. As usual the registers k0/k1 aren't being saved. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * If you add a register here, also add it to regoffset_table[] in 268c2ecf20Sopenharmony_ci * arch/mips/kernel/ptrace.c. 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_cistruct pt_regs { 298c2ecf20Sopenharmony_ci#ifdef CONFIG_32BIT 308c2ecf20Sopenharmony_ci /* Pad bytes for argument save space on the stack. */ 318c2ecf20Sopenharmony_ci unsigned long pad0[8]; 328c2ecf20Sopenharmony_ci#endif 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci /* Saved main processor registers. */ 358c2ecf20Sopenharmony_ci unsigned long regs[32]; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci /* Saved special registers. */ 388c2ecf20Sopenharmony_ci unsigned long cp0_status; 398c2ecf20Sopenharmony_ci unsigned long hi; 408c2ecf20Sopenharmony_ci unsigned long lo; 418c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_HAS_SMARTMIPS 428c2ecf20Sopenharmony_ci unsigned long acx; 438c2ecf20Sopenharmony_ci#endif 448c2ecf20Sopenharmony_ci unsigned long cp0_badvaddr; 458c2ecf20Sopenharmony_ci unsigned long cp0_cause; 468c2ecf20Sopenharmony_ci unsigned long cp0_epc; 478c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_CAVIUM_OCTEON 488c2ecf20Sopenharmony_ci unsigned long long mpl[6]; /* MTM{0-5} */ 498c2ecf20Sopenharmony_ci unsigned long long mtp[6]; /* MTP{0-5} */ 508c2ecf20Sopenharmony_ci#endif 518c2ecf20Sopenharmony_ci unsigned long __last[0]; 528c2ecf20Sopenharmony_ci} __aligned(8); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic inline unsigned long kernel_stack_pointer(struct pt_regs *regs) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci return regs->regs[31]; 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistatic inline void instruction_pointer_set(struct pt_regs *regs, 608c2ecf20Sopenharmony_ci unsigned long val) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci regs->cp0_epc = val; 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* Query offset/name of register from its name/offset */ 668c2ecf20Sopenharmony_ciextern int regs_query_register_offset(const char *name); 678c2ecf20Sopenharmony_ci#define MAX_REG_OFFSET (offsetof(struct pt_regs, __last)) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/** 708c2ecf20Sopenharmony_ci * regs_get_register() - get register value from its offset 718c2ecf20Sopenharmony_ci * @regs: pt_regs from which register value is gotten. 728c2ecf20Sopenharmony_ci * @offset: offset number of the register. 738c2ecf20Sopenharmony_ci * 748c2ecf20Sopenharmony_ci * regs_get_register returns the value of a register. The @offset is the 758c2ecf20Sopenharmony_ci * offset of the register in struct pt_regs address which specified by @regs. 768c2ecf20Sopenharmony_ci * If @offset is bigger than MAX_REG_OFFSET, this returns 0. 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_cistatic inline unsigned long regs_get_register(struct pt_regs *regs, 798c2ecf20Sopenharmony_ci unsigned int offset) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci if (unlikely(offset > MAX_REG_OFFSET)) 828c2ecf20Sopenharmony_ci return 0; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci return *(unsigned long *)((unsigned long)regs + offset); 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/** 888c2ecf20Sopenharmony_ci * regs_within_kernel_stack() - check the address in the stack 898c2ecf20Sopenharmony_ci * @regs: pt_regs which contains kernel stack pointer. 908c2ecf20Sopenharmony_ci * @addr: address which is checked. 918c2ecf20Sopenharmony_ci * 928c2ecf20Sopenharmony_ci * regs_within_kernel_stack() checks @addr is within the kernel stack page(s). 938c2ecf20Sopenharmony_ci * If @addr is within the kernel stack, it returns true. If not, returns false. 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_cistatic inline int regs_within_kernel_stack(struct pt_regs *regs, 968c2ecf20Sopenharmony_ci unsigned long addr) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci return ((addr & ~(THREAD_SIZE - 1)) == 998c2ecf20Sopenharmony_ci (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))); 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/** 1038c2ecf20Sopenharmony_ci * regs_get_kernel_stack_nth() - get Nth entry of the stack 1048c2ecf20Sopenharmony_ci * @regs: pt_regs which contains kernel stack pointer. 1058c2ecf20Sopenharmony_ci * @n: stack entry number. 1068c2ecf20Sopenharmony_ci * 1078c2ecf20Sopenharmony_ci * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which 1088c2ecf20Sopenharmony_ci * is specified by @regs. If the @n th entry is NOT in the kernel stack, 1098c2ecf20Sopenharmony_ci * this returns 0. 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_cistatic inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, 1128c2ecf20Sopenharmony_ci unsigned int n) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci addr += n; 1178c2ecf20Sopenharmony_ci if (regs_within_kernel_stack(regs, (unsigned long)addr)) 1188c2ecf20Sopenharmony_ci return *addr; 1198c2ecf20Sopenharmony_ci else 1208c2ecf20Sopenharmony_ci return 0; 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistruct task_struct; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ciextern int ptrace_getregs(struct task_struct *child, 1268c2ecf20Sopenharmony_ci struct user_pt_regs __user *data); 1278c2ecf20Sopenharmony_ciextern int ptrace_setregs(struct task_struct *child, 1288c2ecf20Sopenharmony_ci struct user_pt_regs __user *data); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ciextern int ptrace_getfpregs(struct task_struct *child, __u32 __user *data); 1318c2ecf20Sopenharmony_ciextern int ptrace_setfpregs(struct task_struct *child, __u32 __user *data); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ciextern int ptrace_get_watch_regs(struct task_struct *child, 1348c2ecf20Sopenharmony_ci struct pt_watch_regs __user *addr); 1358c2ecf20Sopenharmony_ciextern int ptrace_set_watch_regs(struct task_struct *child, 1368c2ecf20Sopenharmony_ci struct pt_watch_regs __user *addr); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci/* 1398c2ecf20Sopenharmony_ci * Does the process account for user or for system time? 1408c2ecf20Sopenharmony_ci */ 1418c2ecf20Sopenharmony_ci#define user_mode(regs) (((regs)->cp0_status & KU_MASK) == KU_USER) 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic inline int is_syscall_success(struct pt_regs *regs) 1448c2ecf20Sopenharmony_ci{ 1458c2ecf20Sopenharmony_ci return !regs->regs[7]; 1468c2ecf20Sopenharmony_ci} 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_cistatic inline long regs_return_value(struct pt_regs *regs) 1498c2ecf20Sopenharmony_ci{ 1508c2ecf20Sopenharmony_ci if (is_syscall_success(regs) || !user_mode(regs)) 1518c2ecf20Sopenharmony_ci return regs->regs[2]; 1528c2ecf20Sopenharmony_ci else 1538c2ecf20Sopenharmony_ci return -regs->regs[2]; 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci#define instruction_pointer(regs) ((regs)->cp0_epc) 1578c2ecf20Sopenharmony_ci#define profile_pc(regs) instruction_pointer(regs) 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ciextern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall); 1608c2ecf20Sopenharmony_ciextern asmlinkage void syscall_trace_leave(struct pt_regs *regs); 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ciextern void die(const char *, struct pt_regs *) __noreturn; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistatic inline void die_if_kernel(const char *str, struct pt_regs *regs) 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci if (unlikely(!user_mode(regs))) 1678c2ecf20Sopenharmony_ci die(str, regs); 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci#define current_pt_regs() \ 1718c2ecf20Sopenharmony_ci({ \ 1728c2ecf20Sopenharmony_ci unsigned long sp = (unsigned long)__builtin_frame_address(0); \ 1738c2ecf20Sopenharmony_ci (struct pt_regs *)((sp | (THREAD_SIZE - 1)) + 1 - 32) - 1; \ 1748c2ecf20Sopenharmony_ci}) 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/* Helpers for working with the user stack pointer */ 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistatic inline unsigned long user_stack_pointer(struct pt_regs *regs) 1798c2ecf20Sopenharmony_ci{ 1808c2ecf20Sopenharmony_ci return regs->regs[29]; 1818c2ecf20Sopenharmony_ci} 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic inline void user_stack_pointer_set(struct pt_regs *regs, 1848c2ecf20Sopenharmony_ci unsigned long val) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci regs->regs[29] = val; 1878c2ecf20Sopenharmony_ci} 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci#endif /* _ASM_PTRACE_H */ 190