Skip to content

Commit

Permalink
x86: Clean up current_stack_pointer
Browse files Browse the repository at this point in the history
There's no good reason for it to be a macro, and x86_64 will want to
use it, so it should be in a header.

Acked-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
  • Loading branch information
Andy Lutomirski committed Jan 2, 2015
1 parent 9592747 commit 83653c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 11 additions & 0 deletions arch/x86/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ static inline struct thread_info *current_thread_info(void)
return ti;
}

static inline unsigned long current_stack_pointer(void)
{
unsigned long sp;
#ifdef CONFIG_X86_64
asm("mov %%rsp,%0" : "=g" (sp));
#else
asm("mov %%esp,%0" : "=g" (sp));
#endif
return sp;
}

#else /* !__ASSEMBLY__ */

/* how to get the thread information struct from ASM */
Expand Down
13 changes: 3 additions & 10 deletions arch/x86/kernel/irq_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,9 @@ static void call_on_stack(void *func, void *stack)
: "memory", "cc", "edx", "ecx", "eax");
}

/* how to get the current stack pointer from C */
#define current_stack_pointer ({ \
unsigned long sp; \
asm("mov %%esp,%0" : "=g" (sp)); \
sp; \
})

static inline void *current_stack(void)
{
return (void *)(current_stack_pointer & ~(THREAD_SIZE - 1));
return (void *)(current_stack_pointer() & ~(THREAD_SIZE - 1));
}

static inline int
Expand All @@ -103,7 +96,7 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)

/* Save the next esp at the bottom of the stack */
prev_esp = (u32 *)irqstk;
*prev_esp = current_stack_pointer;
*prev_esp = current_stack_pointer();

if (unlikely(overflow))
call_on_stack(print_stack_overflow, isp);
Expand Down Expand Up @@ -156,7 +149,7 @@ void do_softirq_own_stack(void)

/* Push the previous esp onto the stack */
prev_esp = (u32 *)irqstk;
*prev_esp = current_stack_pointer;
*prev_esp = current_stack_pointer();

call_on_stack(__do_softirq, isp);
}
Expand Down

0 comments on commit 83653c1

Please sign in to comment.