162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __UM_X86_PTRACE_H
362306a36Sopenharmony_ci#define __UM_X86_PTRACE_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/compiler.h>
662306a36Sopenharmony_ci#ifndef CONFIG_X86_32
762306a36Sopenharmony_ci#define __FRAME_OFFSETS /* Needed to get the R* macros */
862306a36Sopenharmony_ci#endif
962306a36Sopenharmony_ci#include <asm/ptrace-generic.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define user_mode(r) UPT_IS_USER(&(r)->regs)
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#define PT_REGS_AX(r) UPT_AX(&(r)->regs)
1462306a36Sopenharmony_ci#define PT_REGS_BX(r) UPT_BX(&(r)->regs)
1562306a36Sopenharmony_ci#define PT_REGS_CX(r) UPT_CX(&(r)->regs)
1662306a36Sopenharmony_ci#define PT_REGS_DX(r) UPT_DX(&(r)->regs)
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#define PT_REGS_SI(r) UPT_SI(&(r)->regs)
1962306a36Sopenharmony_ci#define PT_REGS_DI(r) UPT_DI(&(r)->regs)
2062306a36Sopenharmony_ci#define PT_REGS_BP(r) UPT_BP(&(r)->regs)
2162306a36Sopenharmony_ci#define PT_REGS_EFLAGS(r) UPT_EFLAGS(&(r)->regs)
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define PT_REGS_CS(r) UPT_CS(&(r)->regs)
2462306a36Sopenharmony_ci#define PT_REGS_SS(r) UPT_SS(&(r)->regs)
2562306a36Sopenharmony_ci#define PT_REGS_DS(r) UPT_DS(&(r)->regs)
2662306a36Sopenharmony_ci#define PT_REGS_ES(r) UPT_ES(&(r)->regs)
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define PT_REGS_ORIG_SYSCALL(r) PT_REGS_AX(r)
2962306a36Sopenharmony_ci#define PT_REGS_SYSCALL_RET(r) PT_REGS_AX(r)
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define PT_FIX_EXEC_STACK(sp) do ; while(0)
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define profile_pc(regs) PT_REGS_IP(regs)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define UPT_RESTART_SYSCALL(r) (UPT_IP(r) -= 2)
3662306a36Sopenharmony_ci#define PT_REGS_SET_SYSCALL_RETURN(r, res) (PT_REGS_AX(r) = (res))
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cistatic inline long regs_return_value(struct pt_regs *regs)
3962306a36Sopenharmony_ci{
4062306a36Sopenharmony_ci	return PT_REGS_AX(regs);
4162306a36Sopenharmony_ci}
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/*
4462306a36Sopenharmony_ci * Forward declaration to avoid including sysdep/tls.h, which causes a
4562306a36Sopenharmony_ci * circular include, and compilation failures.
4662306a36Sopenharmony_ci */
4762306a36Sopenharmony_cistruct user_desc;
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#ifdef CONFIG_X86_32
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciextern int ptrace_get_thread_area(struct task_struct *child, int idx,
5262306a36Sopenharmony_ci                                  struct user_desc __user *user_desc);
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciextern int ptrace_set_thread_area(struct task_struct *child, int idx,
5562306a36Sopenharmony_ci                                  struct user_desc __user *user_desc);
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#else
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define PT_REGS_R8(r) UPT_R8(&(r)->regs)
6062306a36Sopenharmony_ci#define PT_REGS_R9(r) UPT_R9(&(r)->regs)
6162306a36Sopenharmony_ci#define PT_REGS_R10(r) UPT_R10(&(r)->regs)
6262306a36Sopenharmony_ci#define PT_REGS_R11(r) UPT_R11(&(r)->regs)
6362306a36Sopenharmony_ci#define PT_REGS_R12(r) UPT_R12(&(r)->regs)
6462306a36Sopenharmony_ci#define PT_REGS_R13(r) UPT_R13(&(r)->regs)
6562306a36Sopenharmony_ci#define PT_REGS_R14(r) UPT_R14(&(r)->regs)
6662306a36Sopenharmony_ci#define PT_REGS_R15(r) UPT_R15(&(r)->regs)
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#include <asm/errno.h>
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistatic inline int ptrace_get_thread_area(struct task_struct *child, int idx,
7162306a36Sopenharmony_ci                                         struct user_desc __user *user_desc)
7262306a36Sopenharmony_ci{
7362306a36Sopenharmony_ci        return -ENOSYS;
7462306a36Sopenharmony_ci}
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_cistatic inline int ptrace_set_thread_area(struct task_struct *child, int idx,
7762306a36Sopenharmony_ci                                         struct user_desc __user *user_desc)
7862306a36Sopenharmony_ci{
7962306a36Sopenharmony_ci        return -ENOSYS;
8062306a36Sopenharmony_ci}
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ciextern long arch_prctl(struct task_struct *task, int option,
8362306a36Sopenharmony_ci		       unsigned long __user *addr);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#endif
8662306a36Sopenharmony_ci#define user_stack_pointer(regs) PT_REGS_SP(regs)
8762306a36Sopenharmony_ci#endif /* __UM_X86_PTRACE_H */
88