GNU Linux-libre 4.9.309-gnu1
[releases.git] / arch / x86 / include / asm / switch_to.h
1 #ifndef _ASM_X86_SWITCH_TO_H
2 #define _ASM_X86_SWITCH_TO_H
3
4 struct task_struct; /* one of the stranger aspects of C forward declarations */
5
6 struct task_struct *__switch_to_asm(struct task_struct *prev,
7                                     struct task_struct *next);
8
9 __visible struct task_struct *__switch_to(struct task_struct *prev,
10                                           struct task_struct *next);
11
12 /* This runs runs on the previous thread's stack. */
13 static 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
34 asmlinkage void ret_from_fork(void);
35
36 /* data that is pointed to by thread.sp */
37 struct inactive_task_frame {
38         unsigned long flags;
39 #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;
49         unsigned long bp;
50         unsigned long ret_addr;
51 };
52
53 struct fork_frame {
54         struct inactive_task_frame frame;
55         struct pt_regs regs;
56 };
57
58 #define switch_to(prev, next, last)                                     \
59 do {                                                                    \
60         prepare_switch_to(prev, next);                                  \
61                                                                         \
62         ((last) = __switch_to_asm((prev), (next)));                     \
63 } while (0)
64
65 #endif /* _ASM_X86_SWITCH_TO_H */