Go to the documentation of this file. 1 #ifndef _ASM_X86_SWITCH_TO_H
2 #define _ASM_X86_SWITCH_TO_H
13 #ifdef CONFIG_CC_STACKPROTECTOR
14 #define __switch_canary \
15 "movl %P[task_canary](%[next]), %%ebx\n\t" \
16 "movl %%ebx, "__percpu_arg([stack_canary])"\n\t"
17 #define __switch_canary_oparam \
18 , [stack_canary] "=m" (stack_canary.canary)
19 #define __switch_canary_iparam \
20 , [task_canary] "i" (offsetof(struct task_struct, stack_canary))
22 #define __switch_canary
23 #define __switch_canary_oparam
24 #define __switch_canary_iparam
31 #define switch_to(prev, next, last) \
40 unsigned long ebx, ecx, edx, esi, edi; \
42 asm volatile("pushfl\n\t" \
44 "movl %%esp,%[prev_sp]\n\t" \
45 "movl %[next_sp],%%esp\n\t" \
46 "movl $1f,%[prev_ip]\n\t" \
47 "pushl %[next_ip]\n\t" \
55 : [prev_sp] "=m" (prev->thread.sp), \
56 [prev_ip] "=m" (prev->thread.ip), \
60 "=b" (ebx), "=c" (ecx), "=d" (edx), \
61 "=S" (esi), "=D" (edi) \
63 __switch_canary_oparam \
66 : [next_sp] "m" (next->thread.sp), \
67 [next_ip] "m" (next->thread.ip), \
73 __switch_canary_iparam \
82 #define SAVE_CONTEXT "pushf ; pushq %%rbp ; movq %%rsi,%%rbp\n\t"
83 #define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp ; popf\t"
85 #define __EXTRA_CLOBBER \
86 , "rcx", "rbx", "rdx", "r8", "r9", "r10", "r11", \
87 "r12", "r13", "r14", "r15"
89 #ifdef CONFIG_CC_STACKPROTECTOR
90 #define __switch_canary \
91 "movq %P[task_canary](%%rsi),%%r8\n\t" \
92 "movq %%r8,"__percpu_arg([gs_canary])"\n\t"
93 #define __switch_canary_oparam \
94 , [gs_canary] "=m" (irq_stack_union.stack_canary)
95 #define __switch_canary_iparam \
96 , [task_canary] "i" (offsetof(struct task_struct, stack_canary))
98 #define __switch_canary
99 #define __switch_canary_oparam
100 #define __switch_canary_iparam
104 #define switch_to(prev, next, last) \
105 asm volatile(SAVE_CONTEXT \
106 "movq %%rsp,%P[threadrsp](%[prev])\n\t" \
107 "movq %P[threadrsp](%[next]),%%rsp\n\t" \
108 "call __switch_to\n\t" \
109 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
111 "movq %P[thread_info](%%rsi),%%r8\n\t" \
112 "movq %%rax,%%rdi\n\t" \
113 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
114 "jnz ret_from_fork\n\t" \
117 __switch_canary_oparam \
118 : [next] "S" (next), [prev] "D" (prev), \
119 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
120 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
121 [_tif_fork] "i" (_TIF_FORK), \
122 [thread_info] "i" (offsetof(struct task_struct, stack)), \
123 [current_task] "m" (current_task) \
124 __switch_canary_iparam \
125 : "memory", "cc" __EXTRA_CLOBBER)