blob: e959b8d40473aaccce42bc73f4c84de905c2c9d0 [file] [log] [blame]
David Howellsf05e7982012-03-28 18:11:12 +01001#ifndef _ASM_X86_SWITCH_TO_H
2#define _ASM_X86_SWITCH_TO_H
3
4struct task_struct; /* one of the stranger aspects of C forward declarations */
Brian Gerst01003012016-08-13 12:38:19 -04005
6struct task_struct *__switch_to_asm(struct task_struct *prev,
7 struct task_struct *next);
8
Andi Kleen35ea79032013-08-05 15:02:39 -07009__visible struct task_struct *__switch_to(struct task_struct *prev,
Brian Gerst01003012016-08-13 12:38:19 -040010 struct task_struct *next);
David Howellsf05e7982012-03-28 18:11:12 +010011
Andy Lutomirskie37e43a2016-08-11 02:35:23 -070012/* This runs runs on the previous thread's stack. */
13static inline void prepare_switch_to(struct task_struct *prev,
14 struct task_struct *next)
15{
16#ifdef CONFIG_VMAP_STACK
17 /*
18 * If we switch to a stack that has a top-level paging entry
19 * that is not present in the current mm, the resulting #PF will
20 * will be promoted to a double-fault and we'll panic. Probe
21 * the new stack now so that vmalloc_fault can fix up the page
22 * tables if needed. This can only happen if we use a stack
23 * in vmap space.
24 *
25 * We assume that the stack is aligned so that it never spans
26 * more than one top-level paging entry.
27 *
28 * To minimize cache pollution, just follow the stack pointer.
29 */
30 READ_ONCE(*(unsigned char *)next->thread.sp);
31#endif
32}
33
Brian Gerst616d2482016-08-13 12:38:20 -040034asmlinkage void ret_from_fork(void);
35
Brian Gerst7b32aea2016-08-13 12:38:18 -040036/* data that is pointed to by thread.sp */
37struct inactive_task_frame {
Peter Zijlstra45fe6de2019-02-14 10:30:52 +010038 unsigned long flags;
Brian Gerst01003012016-08-13 12:38:19 -040039#ifdef CONFIG_X86_64
40 unsigned long r15;
41 unsigned long r14;
42 unsigned long r13;
43 unsigned long r12;
44#else
45 unsigned long si;
46 unsigned long di;
47#endif
48 unsigned long bx;
Brian Gerst7b32aea2016-08-13 12:38:18 -040049 unsigned long bp;
Brian Gerst01003012016-08-13 12:38:19 -040050 unsigned long ret_addr;
Brian Gerst7b32aea2016-08-13 12:38:18 -040051};
52
Brian Gerst01003012016-08-13 12:38:19 -040053struct fork_frame {
54 struct inactive_task_frame frame;
55 struct pt_regs regs;
56};
David Howellsf05e7982012-03-28 18:11:12 +010057
David Howellsf05e7982012-03-28 18:11:12 +010058#define switch_to(prev, next, last) \
59do { \
Andy Lutomirskie37e43a2016-08-11 02:35:23 -070060 prepare_switch_to(prev, next); \
61 \
Brian Gerst01003012016-08-13 12:38:19 -040062 ((last) = __switch_to_asm((prev), (next))); \
David Howellsf05e7982012-03-28 18:11:12 +010063} while (0)
64
David Howellsf05e7982012-03-28 18:11:12 +010065#endif /* _ASM_X86_SWITCH_TO_H */