switch_to.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef _ASM_X86_SWITCH_TO_H
  2. #define _ASM_X86_SWITCH_TO_H
  3. struct task_struct; /* one of the stranger aspects of C forward declarations */
  4. struct task_struct *__switch_to_asm(struct task_struct *prev,
  5. struct task_struct *next);
  6. __visible struct task_struct *__switch_to(struct task_struct *prev,
  7. struct task_struct *next);
  8. struct tss_struct;
  9. void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
  10. struct tss_struct *tss);
  11. /* This runs runs on the previous thread's stack. */
  12. static inline void prepare_switch_to(struct task_struct *prev,
  13. struct task_struct *next)
  14. {
  15. #ifdef CONFIG_VMAP_STACK
  16. /*
  17. * If we switch to a stack that has a top-level paging entry
  18. * that is not present in the current mm, the resulting #PF will
  19. * will be promoted to a double-fault and we'll panic. Probe
  20. * the new stack now so that vmalloc_fault can fix up the page
  21. * tables if needed. This can only happen if we use a stack
  22. * in vmap space.
  23. *
  24. * We assume that the stack is aligned so that it never spans
  25. * more than one top-level paging entry.
  26. *
  27. * To minimize cache pollution, just follow the stack pointer.
  28. */
  29. READ_ONCE(*(unsigned char *)next->thread.sp);
  30. #endif
  31. }
  32. asmlinkage void ret_from_fork(void);
  33. /* data that is pointed to by thread.sp */
  34. struct inactive_task_frame {
  35. #ifdef CONFIG_X86_64
  36. unsigned long r15;
  37. unsigned long r14;
  38. unsigned long r13;
  39. unsigned long r12;
  40. #else
  41. unsigned long si;
  42. unsigned long di;
  43. #endif
  44. unsigned long bx;
  45. unsigned long bp;
  46. unsigned long ret_addr;
  47. };
  48. struct fork_frame {
  49. struct inactive_task_frame frame;
  50. struct pt_regs regs;
  51. };
  52. #define switch_to(prev, next, last) \
  53. do { \
  54. prepare_switch_to(prev, next); \
  55. \
  56. ((last) = __switch_to_asm((prev), (next))); \
  57. } while (0)
  58. #endif /* _ASM_X86_SWITCH_TO_H */