treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / arch / c6x / kernel / ptrace.c
blob67af1562da866522e44156472937dc773123e706
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Port on Texas Instruments TMS320C6x architecture
5 * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
6 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
8 * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
9 */
10 #include <linux/ptrace.h>
11 #include <linux/tracehook.h>
12 #include <linux/regset.h>
13 #include <linux/elf.h>
14 #include <linux/sched/task_stack.h>
16 #include <asm/cacheflush.h>
18 #define PT_REG_SIZE (sizeof(struct pt_regs))
21 * Called by kernel/ptrace.c when detaching.
23 void ptrace_disable(struct task_struct *child)
25 /* nothing to do */
29 * Get a register number from live pt_regs for the specified task.
31 static inline long get_reg(struct task_struct *task, int regno)
33 long *addr = (long *)task_pt_regs(task);
35 if (regno == PT_TSR || regno == PT_CSR)
36 return 0;
38 return addr[regno];
42 * Write contents of register REGNO in task TASK.
44 static inline int put_reg(struct task_struct *task,
45 int regno,
46 unsigned long data)
48 unsigned long *addr = (unsigned long *)task_pt_regs(task);
50 if (regno != PT_TSR && regno != PT_CSR)
51 addr[regno] = data;
53 return 0;
56 /* regset get/set implementations */
58 static int gpr_get(struct task_struct *target,
59 const struct user_regset *regset,
60 unsigned int pos, unsigned int count,
61 void *kbuf, void __user *ubuf)
63 struct pt_regs *regs = task_pt_regs(target);
65 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
66 regs,
67 0, sizeof(*regs));
70 enum c6x_regset {
71 REGSET_GPR,
74 static const struct user_regset c6x_regsets[] = {
75 [REGSET_GPR] = {
76 .core_note_type = NT_PRSTATUS,
77 .n = ELF_NGREG,
78 .size = sizeof(u32),
79 .align = sizeof(u32),
80 .get = gpr_get,
84 static const struct user_regset_view user_c6x_native_view = {
85 .name = "tic6x",
86 .e_machine = EM_TI_C6000,
87 .regsets = c6x_regsets,
88 .n = ARRAY_SIZE(c6x_regsets),
91 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
93 return &user_c6x_native_view;
97 * Perform ptrace request
99 long arch_ptrace(struct task_struct *child, long request,
100 unsigned long addr, unsigned long data)
102 int ret = 0;
104 switch (request) {
106 * write the word at location addr.
108 case PTRACE_POKETEXT:
109 ret = generic_ptrace_pokedata(child, addr, data);
110 if (ret == 0 && request == PTRACE_POKETEXT)
111 flush_icache_range(addr, addr + 4);
112 break;
113 default:
114 ret = ptrace_request(child, request, addr, data);
115 break;
118 return ret;
122 * handle tracing of system call entry
123 * - return the revised system call number or ULONG_MAX to cause ENOSYS
125 asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
127 if (tracehook_report_syscall_entry(regs))
128 /* tracing decided this syscall should not happen, so
129 * We'll return a bogus call number to get an ENOSYS
130 * error, but leave the original number in
131 * regs->orig_a4
133 return ULONG_MAX;
135 return regs->b0;
139 * handle tracing of system call exit
141 asmlinkage void syscall_trace_exit(struct pt_regs *regs)
143 tracehook_report_syscall_exit(regs, 0);