thread_info.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2009 Chen Liqin <liqin.chen@sunplusct.com>
  4. * Copyright (C) 2012 Regents of the University of California
  5. * Copyright (C) 2017 SiFive
  6. */
  7. #ifndef _ASM_RISCV_THREAD_INFO_H
  8. #define _ASM_RISCV_THREAD_INFO_H
  9. #include <asm/page.h>
  10. #include <linux/const.h>
  11. #include <linux/sizes.h>
  12. /* thread information allocation */
  13. #ifdef CONFIG_KASAN
  14. #define KASAN_STACK_ORDER 1
  15. #else
  16. #define KASAN_STACK_ORDER 0
  17. #endif
  18. #define THREAD_SIZE_ORDER (CONFIG_THREAD_SIZE_ORDER + KASAN_STACK_ORDER)
  19. #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
  20. /*
  21. * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
  22. * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
  23. * assembly.
  24. */
  25. #ifdef CONFIG_VMAP_STACK
  26. #define THREAD_ALIGN (2 * THREAD_SIZE)
  27. #else
  28. #define THREAD_ALIGN THREAD_SIZE
  29. #endif
  30. #define THREAD_SHIFT (PAGE_SHIFT + THREAD_SIZE_ORDER)
  31. #define OVERFLOW_STACK_SIZE SZ_4K
  32. #define IRQ_STACK_SIZE THREAD_SIZE
  33. #ifndef __ASSEMBLY__
  34. #include <asm/processor.h>
  35. #include <asm/csr.h>
  36. /*
  37. * low level task data that entry.S needs immediate access to
  38. * - this struct should fit entirely inside of one cache line
  39. * - if the members of this struct changes, the assembly constants
  40. * in asm-offsets.c must be updated accordingly
  41. * - thread_info is included in task_struct at an offset of 0. This means that
  42. * tp points to both thread_info and task_struct.
  43. */
  44. struct thread_info {
  45. unsigned long flags; /* low level flags */
  46. int preempt_count; /* 0=>preemptible, <0=>BUG */
  47. /*
  48. * These stack pointers are overwritten on every system call or
  49. * exception. SP is also saved to the stack it can be recovered when
  50. * overwritten.
  51. */
  52. long kernel_sp; /* Kernel stack pointer */
  53. long user_sp; /* User stack pointer */
  54. int cpu;
  55. unsigned long syscall_work; /* SYSCALL_WORK_ flags */
  56. #ifdef CONFIG_SHADOW_CALL_STACK
  57. void *scs_base;
  58. void *scs_sp;
  59. #endif
  60. #ifdef CONFIG_64BIT
  61. /*
  62. * Used in handle_exception() to save a0, a1 and a2 before knowing if we
  63. * can access the kernel stack.
  64. */
  65. unsigned long a0, a1, a2;
  66. #endif
  67. };
  68. #ifdef CONFIG_SHADOW_CALL_STACK
  69. #define INIT_SCS \
  70. .scs_base = init_shadow_call_stack, \
  71. .scs_sp = init_shadow_call_stack,
  72. #else
  73. #define INIT_SCS
  74. #endif
  75. /*
  76. * macros/functions for gaining access to the thread information structure
  77. *
  78. * preempt_count needs to be 1 initially, until the scheduler is functional.
  79. */
  80. #define INIT_THREAD_INFO(tsk) \
  81. { \
  82. .flags = 0, \
  83. .preempt_count = INIT_PREEMPT_COUNT, \
  84. INIT_SCS \
  85. }
  86. void arch_release_task_struct(struct task_struct *tsk);
  87. int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
  88. #endif /* !__ASSEMBLY__ */
  89. /*
  90. * thread information flags
  91. * - these are process state flags that various assembly files may need to
  92. * access
  93. * - pending work-to-be-done flags are in lowest half-word
  94. * - other flags in upper half-word(s)
  95. */
  96. #define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
  97. #define TIF_SIGPENDING 2 /* signal pending */
  98. #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
  99. #define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
  100. #define TIF_MEMDIE 5 /* is terminating due to OOM killer */
  101. #define TIF_NOTIFY_SIGNAL 9 /* signal notifications exist */
  102. #define TIF_UPROBE 10 /* uprobe breakpoint or singlestep */
  103. #define TIF_32BIT 11 /* compat-mode 32bit process */
  104. #define TIF_RISCV_V_DEFER_RESTORE 12 /* restore Vector before returing to user */
  105. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  106. #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  107. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  108. #define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
  109. #define _TIF_UPROBE (1 << TIF_UPROBE)
  110. #define _TIF_RISCV_V_DEFER_RESTORE (1 << TIF_RISCV_V_DEFER_RESTORE)
  111. #endif /* _ASM_RISCV_THREAD_INFO_H */