2019-06-04 15:11:33 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2008-08-02 16:55:55 +07:00
|
|
|
* arch/arm/include/asm/ptrace.h
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Copyright (C) 1996-2003 Russell King
|
|
|
|
*/
|
|
|
|
#ifndef __ASM_ARM_PTRACE_H
|
|
|
|
#define __ASM_ARM_PTRACE_H
|
|
|
|
|
2012-10-12 19:05:52 +07:00
|
|
|
#include <uapi/asm/ptrace.h>
|
2009-07-24 18:34:58 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#ifndef __ASSEMBLY__
|
2016-05-13 16:22:38 +07:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
2010-01-06 16:50:08 +07:00
|
|
|
struct pt_regs {
|
|
|
|
unsigned long uregs[18];
|
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2016-05-13 16:22:38 +07:00
|
|
|
struct svc_pt_regs {
|
|
|
|
struct pt_regs regs;
|
|
|
|
u32 dacr;
|
2016-05-13 17:40:20 +07:00
|
|
|
u32 addr_limit;
|
2016-05-13 16:22:38 +07:00
|
|
|
};
|
|
|
|
|
2016-05-13 16:26:10 +07:00
|
|
|
#define to_svc_pt_regs(r) container_of(r, struct svc_pt_regs, regs)
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#define user_mode(regs) \
|
|
|
|
(((regs)->ARM_cpsr & 0xf) == 0)
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARM_THUMB
|
|
|
|
#define thumb_mode(regs) \
|
|
|
|
(((regs)->ARM_cpsr & PSR_T_BIT))
|
|
|
|
#else
|
|
|
|
#define thumb_mode(regs) (0)
|
|
|
|
#endif
|
|
|
|
|
2013-12-16 16:24:46 +07:00
|
|
|
#ifndef CONFIG_CPU_V7M
|
2007-06-26 07:38:27 +07:00
|
|
|
#define isa_mode(regs) \
|
2013-12-16 16:24:46 +07:00
|
|
|
((((regs)->ARM_cpsr & PSR_J_BIT) >> (__ffs(PSR_J_BIT) - 1)) | \
|
|
|
|
(((regs)->ARM_cpsr & PSR_T_BIT) >> (__ffs(PSR_T_BIT))))
|
|
|
|
#else
|
|
|
|
#define isa_mode(regs) 1 /* Thumb */
|
|
|
|
#endif
|
2007-06-26 07:38:27 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#define processor_mode(regs) \
|
|
|
|
((regs)->ARM_cpsr & MODE_MASK)
|
|
|
|
|
|
|
|
#define interrupts_enabled(regs) \
|
|
|
|
(!((regs)->ARM_cpsr & PSR_I_BIT))
|
|
|
|
|
|
|
|
#define fast_interrupts_enabled(regs) \
|
|
|
|
(!((regs)->ARM_cpsr & PSR_F_BIT))
|
|
|
|
|
|
|
|
/* Are the current registers suitable for user mode?
|
|
|
|
* (used to maintain security in signal handlers)
|
|
|
|
*/
|
|
|
|
static inline int valid_user_regs(struct pt_regs *regs)
|
|
|
|
{
|
2010-05-22 00:06:41 +07:00
|
|
|
#ifndef CONFIG_CPU_V7M
|
2010-08-14 05:33:46 +07:00
|
|
|
unsigned long mode = regs->ARM_cpsr & MODE_MASK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Always clear the F (FIQ) and A (delayed abort) bits
|
|
|
|
*/
|
|
|
|
regs->ARM_cpsr &= ~(PSR_F_BIT | PSR_A_BIT);
|
|
|
|
|
|
|
|
if ((regs->ARM_cpsr & PSR_I_BIT) == 0) {
|
|
|
|
if (mode == USR_MODE)
|
|
|
|
return 1;
|
|
|
|
if (elf_hwcap & HWCAP_26BIT && mode == USR26_MODE)
|
|
|
|
return 1;
|
2007-07-11 17:29:39 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Force CPSR to something logical...
|
|
|
|
*/
|
2010-08-14 05:33:46 +07:00
|
|
|
regs->ARM_cpsr &= PSR_f | PSR_s | PSR_x | PSR_T_BIT | MODE32_BIT;
|
2007-07-11 17:29:39 +07:00
|
|
|
if (!(elf_hwcap & HWCAP_26BIT))
|
|
|
|
regs->ARM_cpsr |= USR_MODE;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return 0;
|
2010-05-22 00:06:41 +07:00
|
|
|
#else /* ifndef CONFIG_CPU_V7M */
|
|
|
|
return 1;
|
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2012-01-04 02:23:09 +07:00
|
|
|
static inline long regs_return_value(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
return regs->ARM_r0;
|
|
|
|
}
|
|
|
|
|
2008-09-06 16:14:24 +07:00
|
|
|
#define instruction_pointer(regs) (regs)->ARM_pc
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-06-04 01:48:10 +07:00
|
|
|
#ifdef CONFIG_THUMB2_KERNEL
|
|
|
|
#define frame_pointer(regs) (regs)->ARM_r7
|
|
|
|
#else
|
|
|
|
#define frame_pointer(regs) (regs)->ARM_fp
|
|
|
|
#endif
|
|
|
|
|
2014-03-07 23:23:04 +07:00
|
|
|
static inline void instruction_pointer_set(struct pt_regs *regs,
|
|
|
|
unsigned long val)
|
|
|
|
{
|
|
|
|
instruction_pointer(regs) = val;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
extern unsigned long profile_pc(struct pt_regs *regs);
|
|
|
|
#else
|
|
|
|
#define profile_pc(regs) instruction_pointer(regs)
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 21:50:36 +07:00
|
|
|
#define predicate(x) ((x) & 0xf0000000)
|
2005-04-17 05:20:36 +07:00
|
|
|
#define PREDICATE_ALWAYS 0xe0000000
|
2008-07-25 15:47:34 +07:00
|
|
|
|
2011-03-27 02:19:07 +07:00
|
|
|
/*
|
|
|
|
* True if instr is a 32-bit thumb instruction. This works if instr
|
|
|
|
* is the first or only half-word of a thumb instruction. It also works
|
|
|
|
* when instr holds all 32-bits of a wide thumb instruction if stored
|
|
|
|
* in the form (first_half<<16)|(second_half)
|
|
|
|
*/
|
|
|
|
#define is_wide_instruction(instr) ((unsigned)(instr) >= 0xe800)
|
|
|
|
|
2010-06-25 18:24:53 +07:00
|
|
|
/*
|
|
|
|
* kprobe-based event tracer support
|
|
|
|
*/
|
linux/compiler.h: Split into compiler.h and compiler_types.h
linux/compiler.h is included indirectly by linux/types.h via
uapi/linux/types.h -> uapi/linux/posix_types.h -> linux/stddef.h
-> uapi/linux/stddef.h and is needed to provide a proper definition of
offsetof.
Unfortunately, compiler.h requires a definition of
smp_read_barrier_depends() for defining lockless_dereference() and soon
for defining READ_ONCE(), which means that all
users of READ_ONCE() will need to include asm/barrier.h to avoid splats
such as:
In file included from include/uapi/linux/stddef.h:1:0,
from include/linux/stddef.h:4,
from arch/h8300/kernel/asm-offsets.c:11:
include/linux/list.h: In function 'list_empty':
>> include/linux/compiler.h:343:2: error: implicit declaration of function 'smp_read_barrier_depends' [-Werror=implicit-function-declaration]
smp_read_barrier_depends(); /* Enforce dependency ordering from x */ \
^
A better alternative is to include asm/barrier.h in linux/compiler.h,
but this requires a type definition for "bool" on some architectures
(e.g. x86), which is defined later by linux/types.h. Type "bool" is also
used directly in linux/compiler.h, so the whole thing is pretty fragile.
This patch splits compiler.h in two: compiler_types.h contains type
annotations, definitions and the compiler-specific parts, whereas
compiler.h #includes compiler-types.h and additionally defines macros
such as {READ,WRITE.ACCESS}_ONCE().
uapi/linux/stddef.h and linux/linkage.h are then moved over to include
linux/compiler_types.h, which fixes the build for h8 and blackfin.
Signed-off-by: Will Deacon <will.deacon@arm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1508840570-22169-2-git-send-email-will.deacon@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-24 17:22:46 +07:00
|
|
|
#include <linux/compiler.h>
|
2010-06-25 18:24:53 +07:00
|
|
|
#define MAX_REG_OFFSET (offsetof(struct pt_regs, ARM_ORIG_r0))
|
|
|
|
|
|
|
|
extern int regs_query_register_offset(const char *name);
|
|
|
|
extern const char *regs_query_register_name(unsigned int offset);
|
|
|
|
extern bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr);
|
|
|
|
extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
|
|
|
|
unsigned int n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Valid only for Kernel mode traps. */
|
|
|
|
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
return regs->ARM_sp;
|
|
|
|
}
|
|
|
|
|
2012-04-04 22:19:47 +07:00
|
|
|
static inline unsigned long user_stack_pointer(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
return regs->ARM_sp;
|
|
|
|
}
|
|
|
|
|
2014-09-27 06:31:06 +07:00
|
|
|
#define current_pt_regs(void) ({ (struct pt_regs *) \
|
|
|
|
((current_stack_pointer | (THREAD_SIZE - 1)) - 7) - 1; \
|
2012-08-02 14:49:43 +07:00
|
|
|
})
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif
|