ptrace.h 9.1 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (C) 2001 PPC64 Team, IBM Corp
 *
 * This struct defines the way the registers are stored on the
 * kernel stack during a system call or other kernel entry.
 *
 * this should only contain volatile regs
 * since we can keep non-volatile in the thread_struct
 * should set this up when only volatiles are saved
 * by intr code.
 *
 * Since this is going on the stack, *CARE MUST BE TAKEN* to insure
 * that the overall structure is a multiple of 16 bytes in length.
 *
 * Note that the offsets of the fields in this struct correspond with
S
Stephen Rothwell 已提交
17
 * the PT_* values below.  This simplifies arch/powerpc/kernel/ptrace.c.
L
Linus Torvalds 已提交
18
 */
19 20
#ifndef _ASM_POWERPC_PTRACE_H
#define _ASM_POWERPC_PTRACE_H
L
Linus Torvalds 已提交
21

22
#include <uapi/asm/ptrace.h>
23
#include <asm/asm-const.h>
L
Linus Torvalds 已提交
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#ifndef __ASSEMBLY__
struct pt_regs
{
	union {
		struct user_pt_regs user_regs;
		struct {
			unsigned long gpr[32];
			unsigned long nip;
			unsigned long msr;
			unsigned long orig_gpr3;
			unsigned long ctr;
			unsigned long link;
			unsigned long xer;
			unsigned long ccr;
#ifdef CONFIG_PPC64
			unsigned long softe;
#else
			unsigned long mq;
#endif
			unsigned long trap;
			unsigned long dar;
			unsigned long dsisr;
			unsigned long result;
		};
	};
50

51 52
	union {
		struct {
53
#ifdef CONFIG_PPC64
54 55
			unsigned long ppr;
#endif
56
			union {
57
#ifdef CONFIG_PPC_KUAP
58
				unsigned long kuap;
59
#endif
60 61 62 63
#ifdef CONFIG_PPC_PKEY
				unsigned long amr;
#endif
			};
64 65 66
#ifdef CONFIG_PPC_PKEY
			unsigned long iamr;
#endif
67
		};
68
		unsigned long __pad[4];	/* Maintain 16 byte interrupt stack alignment */
69
	};
70 71
};
#endif
A
Anton Blanchard 已提交
72

S
Stephen Rothwell 已提交
73 74
#ifdef __powerpc64__

75 76 77 78 79 80 81 82 83 84 85 86
/*
 * Size of redzone that userspace is allowed to use below the stack
 * pointer.  This is 288 in the 64-bit big-endian ELF ABI, and 512 in
 * the new ELFv2 little-endian ABI, so we allow the larger amount.
 *
 * For kernel code we allow a 288-byte redzone, in order to conserve
 * kernel stack space; gcc currently only uses 288 bytes, and will
 * hopefully allow explicit control of the redzone size in future.
 */
#define USER_REDZONE_SIZE	512
#define KERNEL_REDZONE_SIZE	288

S
Stephen Rothwell 已提交
87
#define STACK_FRAME_OVERHEAD	112	/* size of minimum stack frame */
88 89 90
#define STACK_FRAME_LR_SAVE	2	/* Location of LR in stack frame */
#define STACK_FRAME_REGS_MARKER	ASM_CONST(0x7265677368657265)
#define STACK_INT_FRAME_SIZE	(sizeof(struct pt_regs) + \
91
				 STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE)
92
#define STACK_FRAME_MARKER	12
S
Stephen Rothwell 已提交
93

94
#ifdef PPC64_ELF_ABI_v2
95 96 97 98 99
#define STACK_FRAME_MIN_SIZE	32
#else
#define STACK_FRAME_MIN_SIZE	STACK_FRAME_OVERHEAD
#endif

S
Stephen Rothwell 已提交
100 101 102 103 104 105
/* Size of dummy stack frame allocated when calling signal handler. */
#define __SIGNAL_FRAMESIZE	128
#define __SIGNAL_FRAMESIZE32	64

#else /* __powerpc64__ */

106 107
#define USER_REDZONE_SIZE	0
#define KERNEL_REDZONE_SIZE	0
S
Stephen Rothwell 已提交
108
#define STACK_FRAME_OVERHEAD	16	/* size of minimum stack frame */
109 110 111 112
#define STACK_FRAME_LR_SAVE	1	/* Location of LR in stack frame */
#define STACK_FRAME_REGS_MARKER	ASM_CONST(0x72656773)
#define STACK_INT_FRAME_SIZE	(sizeof(struct pt_regs) + STACK_FRAME_OVERHEAD)
#define STACK_FRAME_MARKER	2
113
#define STACK_FRAME_MIN_SIZE	STACK_FRAME_OVERHEAD
S
Stephen Rothwell 已提交
114 115 116 117 118

/* Size of stack frame allocated when calling signal handler. */
#define __SIGNAL_FRAMESIZE	64

#endif /* __powerpc64__ */
A
Anton Blanchard 已提交
119

S
Stephen Rothwell 已提交
120 121
#ifndef __ASSEMBLY__

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
static inline unsigned long instruction_pointer(struct pt_regs *regs)
{
	return regs->nip;
}

static inline void instruction_pointer_set(struct pt_regs *regs,
		unsigned long val)
{
	regs->nip = val;
}

static inline unsigned long user_stack_pointer(struct pt_regs *regs)
{
	return regs->gpr[1];
}

static inline unsigned long frame_pointer(struct pt_regs *regs)
{
	return 0;
}
142 143 144

#ifdef CONFIG_SMP
extern unsigned long profile_pc(struct pt_regs *regs);
145 146
#else
#define profile_pc(regs) instruction_pointer(regs)
147 148
#endif

149 150 151
long do_syscall_trace_enter(struct pt_regs *regs);
void do_syscall_trace_leave(struct pt_regs *regs);

152
#define kernel_stack_pointer(regs) ((regs)->gpr[1])
153 154 155 156 157 158 159 160 161 162 163 164
static inline int is_syscall_success(struct pt_regs *regs)
{
	return !(regs->ccr & 0x10000000);
}

static inline long regs_return_value(struct pt_regs *regs)
{
	if (is_syscall_success(regs))
		return regs->gpr[3];
	else
		return -regs->gpr[3];
}
165

166 167 168 169 170
static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
{
	regs->gpr[3] = rc;
}

S
Stephen Rothwell 已提交
171
#ifdef __powerpc64__
L
Linus Torvalds 已提交
172
#define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1)
S
Stephen Rothwell 已提交
173 174 175
#else
#define user_mode(regs) (((regs)->msr & MSR_PR) != 0)
#endif
L
Linus Torvalds 已提交
176 177

#define force_successful_syscall_return()   \
S
Stephen Rothwell 已提交
178
	do { \
179
		set_thread_flag(TIF_NOERROR); \
S
Stephen Rothwell 已提交
180
	} while(0)
L
Linus Torvalds 已提交
181

182
#define current_pt_regs() \
183
	((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE) - 1)
184 185 186

#ifdef __powerpc64__
#ifdef CONFIG_PPC_BOOK3S
187 188
#define TRAP_FLAGS_MASK		0x10
#define TRAP(regs)		((regs)->trap & ~TRAP_FLAGS_MASK)
189 190 191
#define FULL_REGS(regs)		true
#define SET_FULL_REGS(regs)	do { } while (0)
#else
192 193
#define TRAP_FLAGS_MASK		0x11
#define TRAP(regs)		((regs)->trap & ~TRAP_FLAGS_MASK)
194 195 196 197 198 199
#define FULL_REGS(regs)		(((regs)->trap & 1) == 0)
#define SET_FULL_REGS(regs)	((regs)->trap |= 1)
#endif
#define CHECK_FULL_REGS(regs)	BUG_ON(!FULL_REGS(regs))
#define NV_REG_POISON		0xdeadbeefdeadbeefUL
#else
L
Linus Torvalds 已提交
200 201 202 203
/*
 * We use the least-significant bit of the trap field to indicate
 * whether we have saved the full set of registers, or only a
 * partial set.  A 1 there means the partial set.
S
Stephen Rothwell 已提交
204 205
 * On 4xx we use the next bit to indicate whether the exception
 * is a critical exception (1 means it is).
L
Linus Torvalds 已提交
206
 */
207 208
#define TRAP_FLAGS_MASK		0x1F
#define TRAP(regs)		((regs)->trap & ~TRAP_FLAGS_MASK)
L
Linus Torvalds 已提交
209
#define FULL_REGS(regs)		(((regs)->trap & 1) == 0)
210
#define SET_FULL_REGS(regs)	((regs)->trap |= 1)
211 212
#define IS_CRITICAL_EXC(regs)	(((regs)->trap & 2) != 0)
#define IS_MCHECK_EXC(regs)	(((regs)->trap & 4) != 0)
213
#define IS_DEBUG_EXC(regs)	(((regs)->trap & 8) != 0)
214
#define NV_REG_POISON		0xdeadbeef
S
Stephen Rothwell 已提交
215 216 217
#define CHECK_FULL_REGS(regs)						      \
do {									      \
	if ((regs)->trap & 1)						      \
218
		printk(KERN_CRIT "%s: partial register set\n", __func__); \
S
Stephen Rothwell 已提交
219 220
} while (0)
#endif /* __powerpc64__ */
A
Anton Blanchard 已提交
221

222 223 224 225 226
static inline void set_trap(struct pt_regs *regs, unsigned long val)
{
	regs->trap = (regs->trap & TRAP_FLAGS_MASK) | (val & ~TRAP_FLAGS_MASK);
}

227 228 229 230 231
static inline bool trap_is_scv(struct pt_regs *regs)
{
	return (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && TRAP(regs) == 0x3000);
}

232 233 234 235 236
static inline bool trap_is_unsupported_scv(struct pt_regs *regs)
{
	return IS_ENABLED(CONFIG_PPC_BOOK3S_64) && TRAP(regs) == 0x7ff0;
}

237 238
static inline bool trap_is_syscall(struct pt_regs *regs)
{
239
	return (trap_is_scv(regs) || TRAP(regs) == 0xc00);
240 241
}

242 243 244 245 246 247 248 249 250 251
static inline bool trap_norestart(struct pt_regs *regs)
{
	return regs->trap & 0x10;
}

static inline void set_trap_norestart(struct pt_regs *regs)
{
	regs->trap |= 0x10;
}

R
Roland McGrath 已提交
252
#define arch_has_single_step()	(1)
253
#define arch_has_block_step()	(true)
254
#define ARCH_HAS_USER_SINGLE_STEP_REPORT
255

256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
/*
 * kprobe-based event tracer support
 */

#include <linux/stddef.h>
#include <linux/thread_info.h>
extern int regs_query_register_offset(const char *name);
extern const char *regs_query_register_name(unsigned int offset);
#define MAX_REG_OFFSET (offsetof(struct pt_regs, dsisr))

/**
 * regs_get_register() - get register value from its offset
 * @regs:	   pt_regs from which register value is gotten
 * @offset:    offset number of the register.
 *
 * regs_get_register returns the value of a register whose offset from @regs.
 * The @offset is the offset of the register in struct pt_regs.
 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
 */
static inline unsigned long regs_get_register(struct pt_regs *regs,
						unsigned int offset)
{
	if (unlikely(offset > MAX_REG_OFFSET))
		return 0;
	return *(unsigned long *)((unsigned long)regs + offset);
}

/**
 * regs_within_kernel_stack() - check the address in the stack
 * @regs:      pt_regs which contains kernel stack pointer.
 * @addr:      address which is checked.
 *
 * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
 * If @addr is within the kernel stack, it returns true. If not, returns false.
 */

static inline bool regs_within_kernel_stack(struct pt_regs *regs,
						unsigned long addr)
{
	return ((addr & ~(THREAD_SIZE - 1))  ==
		(kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
}

/**
 * regs_get_kernel_stack_nth() - get Nth entry of the stack
 * @regs:	pt_regs which contains kernel stack pointer.
 * @n:		stack entry number.
 *
 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
 * is specified by @regs. If the @n th entry is NOT in the kernel stack,
 * this returns 0.
 */
static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
						      unsigned int n)
{
	unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
	addr += n;
	if (regs_within_kernel_stack(regs, (unsigned long)addr))
		return *addr;
	else
		return 0;
}

A
Anton Blanchard 已提交
319 320
#endif /* __ASSEMBLY__ */

S
Stephen Rothwell 已提交
321
#ifndef __powerpc64__
322 323
/* We need PT_SOFTE defined at all time to avoid #ifdefs */
#define PT_SOFTE PT_MQ
S
Stephen Rothwell 已提交
324
#else /* __powerpc64__ */
A
Anton Blanchard 已提交
325
#define PT_FPSCR32 (PT_FPR0 + 2*32 + 1)	/* each FP reg occupies 2 32-bit userspace slots */
L
Linus Torvalds 已提交
326 327 328
#define PT_VR0_32 164	/* each Vector reg occupies 4 slots in 32-bit */
#define PT_VSCR_32 (PT_VR0 + 32*4 + 3)
#define PT_VRSAVE_32 (PT_VR0 + 33*4)
329
#define PT_VSR0_32 300 	/* each VSR reg occupies 4 slots in 32-bit */
S
Stephen Rothwell 已提交
330 331
#endif /* __powerpc64__ */
#endif /* _ASM_POWERPC_PTRACE_H */