switch_to.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /*
  34. * This is the structure pointed to by thread.sp for an inactive task. The
  35. * order of the fields must match the code in __switch_to_asm().
  36. */
  37. struct inactive_task_frame {
  38. #ifdef CONFIG_X86_64
  39. unsigned long r15;
  40. unsigned long r14;
  41. unsigned long r13;
  42. unsigned long r12;
  43. #else
  44. unsigned long si;
  45. unsigned long di;
  46. #endif
  47. unsigned long bx;
  48. /*
  49. * These two fields must be together. They form a stack frame header,
  50. * needed by get_frame_pointer().
  51. */
  52. unsigned long bp;
  53. unsigned long ret_addr;
  54. };
  55. struct fork_frame {
  56. struct inactive_task_frame frame;
  57. struct pt_regs regs;
  58. };
  59. #define switch_to(prev, next, last) \
  60. do { \
  61. prepare_switch_to(prev, next); \
  62. \
  63. ((last) = __switch_to_asm((prev), (next))); \
  64. } while (0)
  65. #endif /* _ASM_X86_SWITCH_TO_H */