Skip to content

Commit

Permalink
mips: Implement "current_stack_pointer"
Browse files Browse the repository at this point in the history
To follow the existing per-arch conventions replace open-coded uses
of asm "sp" as "current_stack_pointer". This will let it be used in
non-arch places (like HARDENED_USERCOPY).

Cc: Thomas Bogendoerfer <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Guenter Roeck <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Yanteng Si <[email protected]>
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: Thomas Bogendoerfer <[email protected]>
  • Loading branch information
kees authored and tsbogend committed Mar 1, 2022
1 parent 455481f commit 200ed34
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions arch/mips/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config MIPS
default y
select ARCH_32BIT_OFF_T if !64BIT
select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
select ARCH_HAS_CURRENT_STACK_POINTER
select ARCH_HAS_DEBUG_VIRTUAL if !64BIT
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_KCOV
Expand Down
2 changes: 2 additions & 0 deletions arch/mips/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ static inline struct thread_info *current_thread_info(void)
return __current_thread_info;
}

register unsigned long current_stack_pointer __asm__("sp");

#endif /* !__ASSEMBLY__ */

/* thread information allocation */
Expand Down
3 changes: 1 addition & 2 deletions arch/mips/kernel/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ void __init init_IRQ(void)
#ifdef CONFIG_DEBUG_STACKOVERFLOW
static inline void check_stack_overflow(void)
{
unsigned long sp;
unsigned long sp = current_stack_pointer;

__asm__ __volatile__("move %0, $sp" : "=r" (sp));
sp &= THREAD_MASK;

/*
Expand Down
4 changes: 1 addition & 3 deletions arch/mips/lib/uncached.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ unsigned long run_uncached(void *func)
register long ret __asm__("$2");
long lfunc = (long)func, ufunc;
long usp;
long sp;

__asm__("move %0, $sp" : "=r" (sp));
long sp = current_stack_pointer;

if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
usp = CKSEG1ADDR(sp);
Expand Down

0 comments on commit 200ed34

Please sign in to comment.