thread_info.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /* thread_info.h: low-level thread information
  2. *
  3. * Copyright (C) 2002 David Howells (dhowells@redhat.com)
  4. * - Incorporating suggestions made by Linus Torvalds and Dave Miller
  5. */
  6. #ifndef _ASM_X86_THREAD_INFO_H
  7. #define _ASM_X86_THREAD_INFO_H
  8. #include <linux/compiler.h>
  9. #include <asm/page.h>
  10. #include <asm/types.h>
  11. /*
  12. * low level task data that entry.S needs immediate access to
  13. * - this struct should fit entirely inside of one cache line
  14. * - this struct shares the supervisor stack pages
  15. */
  16. #ifndef __ASSEMBLY__
  17. struct task_struct;
  18. struct exec_domain;
  19. #include <asm/processor.h>
  20. struct thread_info {
  21. struct task_struct *task; /* main task structure */
  22. struct exec_domain *exec_domain; /* execution domain */
  23. __u32 flags; /* low level flags */
  24. __u32 status; /* thread synchronous flags */
  25. __u32 cpu; /* current CPU */
  26. int preempt_count; /* 0 => preemptable,
  27. <0 => BUG */
  28. mm_segment_t addr_limit;
  29. struct restart_block restart_block;
  30. void __user *sysenter_return;
  31. #ifdef CONFIG_X86_32
  32. unsigned long previous_esp; /* ESP of the previous stack in
  33. case of nested (IRQ) stacks
  34. */
  35. __u8 supervisor_stack[0];
  36. #endif
  37. };
  38. #else /* !__ASSEMBLY__ */
  39. #include <asm/asm-offsets.h>
  40. #endif
  41. #ifdef CONFIG_X86_32
  42. #define PREEMPT_ACTIVE 0x10000000
  43. #ifdef CONFIG_4KSTACKS
  44. #define THREAD_SIZE (4096)
  45. #else
  46. #define THREAD_SIZE (8192)
  47. #endif
  48. #define STACK_WARN (THREAD_SIZE/8)
  49. /*
  50. * macros/functions for gaining access to the thread information structure
  51. *
  52. * preempt_count needs to be 1 initially, until the scheduler is functional.
  53. */
  54. #ifndef __ASSEMBLY__
  55. #define INIT_THREAD_INFO(tsk) \
  56. { \
  57. .task = &tsk, \
  58. .exec_domain = &default_exec_domain, \
  59. .flags = 0, \
  60. .cpu = 0, \
  61. .preempt_count = 1, \
  62. .addr_limit = KERNEL_DS, \
  63. .restart_block = { \
  64. .fn = do_no_restart_syscall, \
  65. }, \
  66. }
  67. #define init_thread_info (init_thread_union.thread_info)
  68. #define init_stack (init_thread_union.stack)
  69. /* how to get the current stack pointer from C */
  70. register unsigned long current_stack_pointer asm("esp") __used;
  71. /* how to get the thread information struct from C */
  72. static inline struct thread_info *current_thread_info(void)
  73. {
  74. return (struct thread_info *)
  75. (current_stack_pointer & ~(THREAD_SIZE - 1));
  76. }
  77. /* thread information allocation */
  78. #ifdef CONFIG_DEBUG_STACK_USAGE
  79. #define alloc_thread_info(tsk) ((struct thread_info *) \
  80. __get_free_pages(GFP_KERNEL | __GFP_ZERO, get_order(THREAD_SIZE)))
  81. #else
  82. #define alloc_thread_info(tsk) ((struct thread_info *) \
  83. __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE)))
  84. #endif
  85. #else /* !__ASSEMBLY__ */
  86. /* how to get the thread information struct from ASM */
  87. #define GET_THREAD_INFO(reg) \
  88. movl $-THREAD_SIZE, reg; \
  89. andl %esp, reg
  90. /* use this one if reg already contains %esp */
  91. #define GET_THREAD_INFO_WITH_ESP(reg) \
  92. andl $-THREAD_SIZE, reg
  93. #endif
  94. /*
  95. * thread information flags
  96. * - these are process state flags that various
  97. * assembly files may need to access
  98. * - pending work-to-be-done flags are in LSW
  99. * - other flags in MSW
  100. */
  101. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  102. #define TIF_SIGPENDING 1 /* signal pending */
  103. #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
  104. #define TIF_SINGLESTEP 3 /* restore singlestep on return to
  105. user mode */
  106. #define TIF_IRET 4 /* return with iret */
  107. #define TIF_SYSCALL_EMU 5 /* syscall emulation active */
  108. #define TIF_SYSCALL_AUDIT 6 /* syscall auditing active */
  109. #define TIF_SECCOMP 7 /* secure computing */
  110. #define TIF_RESTORE_SIGMASK 8 /* restore signal mask in do_signal() */
  111. #define TIF_HRTICK_RESCHED 9 /* reprogram hrtick timer */
  112. #define TIF_MEMDIE 16
  113. #define TIF_DEBUG 17 /* uses debug registers */
  114. #define TIF_IO_BITMAP 18 /* uses I/O bitmap */
  115. #define TIF_FREEZE 19 /* is freezing for suspend */
  116. #define TIF_NOTSC 20 /* TSC is not accessible in userland */
  117. #define TIF_FORCED_TF 21 /* true if TF in eflags artificially */
  118. #define TIF_DEBUGCTLMSR 22 /* uses thread_struct.debugctlmsr */
  119. #define TIF_DS_AREA_MSR 23 /* uses thread_struct.ds_area_msr */
  120. #define TIF_BTS_TRACE_TS 24 /* record scheduling event timestamps */
  121. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  122. #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  123. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  124. #define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
  125. #define _TIF_IRET (1 << TIF_IRET)
  126. #define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
  127. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  128. #define _TIF_SECCOMP (1 << TIF_SECCOMP)
  129. #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
  130. #define _TIF_HRTICK_RESCHED (1 << TIF_HRTICK_RESCHED)
  131. #define _TIF_DEBUG (1 << TIF_DEBUG)
  132. #define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP)
  133. #define _TIF_FREEZE (1 << TIF_FREEZE)
  134. #define _TIF_NOTSC (1 << TIF_NOTSC)
  135. #define _TIF_FORCED_TF (1 << TIF_FORCED_TF)
  136. #define _TIF_DEBUGCTLMSR (1 << TIF_DEBUGCTLMSR)
  137. #define _TIF_DS_AREA_MSR (1 << TIF_DS_AREA_MSR)
  138. #define _TIF_BTS_TRACE_TS (1 << TIF_BTS_TRACE_TS)
  139. /* work to do on interrupt/exception return */
  140. #define _TIF_WORK_MASK \
  141. (0x0000FFFF & ~(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  142. _TIF_SECCOMP | _TIF_SYSCALL_EMU))
  143. /* work to do on any return to u-space */
  144. #define _TIF_ALLWORK_MASK (0x0000FFFF & ~_TIF_SECCOMP)
  145. /* flags to check in __switch_to() */
  146. #define _TIF_WORK_CTXSW \
  147. (_TIF_IO_BITMAP | _TIF_NOTSC | _TIF_DEBUGCTLMSR | \
  148. _TIF_DS_AREA_MSR | _TIF_BTS_TRACE_TS)
  149. #define _TIF_WORK_CTXSW_PREV _TIF_WORK_CTXSW
  150. #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW | _TIF_DEBUG)
  151. #else /* X86_32 */
  152. #include <asm/pda.h>
  153. /*
  154. * macros/functions for gaining access to the thread information structure
  155. * preempt_count needs to be 1 initially, until the scheduler is functional.
  156. */
  157. #ifndef __ASSEMBLY__
  158. #define INIT_THREAD_INFO(tsk) \
  159. { \
  160. .task = &tsk, \
  161. .exec_domain = &default_exec_domain, \
  162. .flags = 0, \
  163. .cpu = 0, \
  164. .preempt_count = 1, \
  165. .addr_limit = KERNEL_DS, \
  166. .restart_block = { \
  167. .fn = do_no_restart_syscall, \
  168. }, \
  169. }
  170. #define init_thread_info (init_thread_union.thread_info)
  171. #define init_stack (init_thread_union.stack)
  172. static inline struct thread_info *current_thread_info(void)
  173. {
  174. struct thread_info *ti;
  175. ti = (void *)(read_pda(kernelstack) + PDA_STACKOFFSET - THREAD_SIZE);
  176. return ti;
  177. }
  178. /* do not use in interrupt context */
  179. static inline struct thread_info *stack_thread_info(void)
  180. {
  181. struct thread_info *ti;
  182. asm("andq %%rsp,%0; " : "=r" (ti) : "0" (~(THREAD_SIZE - 1)));
  183. return ti;
  184. }
  185. /* thread information allocation */
  186. #ifdef CONFIG_DEBUG_STACK_USAGE
  187. #define THREAD_FLAGS (GFP_KERNEL | __GFP_ZERO)
  188. #else
  189. #define THREAD_FLAGS GFP_KERNEL
  190. #endif
  191. #define alloc_thread_info(tsk) \
  192. ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
  193. #else /* !__ASSEMBLY__ */
  194. /* how to get the thread information struct from ASM */
  195. #define GET_THREAD_INFO(reg) \
  196. movq %gs:pda_kernelstack,reg ; \
  197. subq $(THREAD_SIZE-PDA_STACKOFFSET),reg
  198. #endif
  199. /*
  200. * thread information flags
  201. * - these are process state flags that various assembly files
  202. * may need to access
  203. * - pending work-to-be-done flags are in LSW
  204. * - other flags in MSW
  205. * Warning: layout of LSW is hardcoded in entry.S
  206. */
  207. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  208. #define TIF_SIGPENDING 2 /* signal pending */
  209. #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
  210. #define TIF_SINGLESTEP 4 /* reenable singlestep on user return*/
  211. #define TIF_IRET 5 /* force IRET */
  212. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  213. #define TIF_SECCOMP 8 /* secure computing */
  214. #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal */
  215. #define TIF_MCE_NOTIFY 10 /* notify userspace of an MCE */
  216. #define TIF_HRTICK_RESCHED 11 /* reprogram hrtick timer */
  217. /* 16 free */
  218. #define TIF_IA32 17 /* 32bit process */
  219. #define TIF_FORK 18 /* ret_from_fork */
  220. #define TIF_ABI_PENDING 19
  221. #define TIF_MEMDIE 20
  222. #define TIF_DEBUG 21 /* uses debug registers */
  223. #define TIF_IO_BITMAP 22 /* uses I/O bitmap */
  224. #define TIF_FREEZE 23 /* is freezing for suspend */
  225. #define TIF_FORCED_TF 24 /* true if TF in eflags artificially */
  226. #define TIF_DEBUGCTLMSR 25 /* uses thread_struct.debugctlmsr */
  227. #define TIF_DS_AREA_MSR 26 /* uses thread_struct.ds_area_msr */
  228. #define TIF_BTS_TRACE_TS 27 /* record scheduling event timestamps */
  229. #define TIF_NOTSC 28 /* TSC is not accessible in userland */
  230. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  231. #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  232. #define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
  233. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  234. #define _TIF_IRET (1 << TIF_IRET)
  235. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  236. #define _TIF_SECCOMP (1 << TIF_SECCOMP)
  237. #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
  238. #define _TIF_MCE_NOTIFY (1 << TIF_MCE_NOTIFY)
  239. #define _TIF_HRTICK_RESCHED (1 << TIF_HRTICK_RESCHED)
  240. #define _TIF_IA32 (1 << TIF_IA32)
  241. #define _TIF_FORK (1 << TIF_FORK)
  242. #define _TIF_ABI_PENDING (1 << TIF_ABI_PENDING)
  243. #define _TIF_DEBUG (1 << TIF_DEBUG)
  244. #define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP)
  245. #define _TIF_FREEZE (1 << TIF_FREEZE)
  246. #define _TIF_FORCED_TF (1 << TIF_FORCED_TF)
  247. #define _TIF_DEBUGCTLMSR (1 << TIF_DEBUGCTLMSR)
  248. #define _TIF_DS_AREA_MSR (1 << TIF_DS_AREA_MSR)
  249. #define _TIF_BTS_TRACE_TS (1 << TIF_BTS_TRACE_TS)
  250. #define _TIF_NOTSC (1 << TIF_NOTSC)
  251. /* work to do on interrupt/exception return */
  252. #define _TIF_WORK_MASK \
  253. (0x0000FFFF & \
  254. ~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP|_TIF_SECCOMP))
  255. /* work to do on any return to user space */
  256. #define _TIF_ALLWORK_MASK (0x0000FFFF & ~_TIF_SECCOMP)
  257. #define _TIF_DO_NOTIFY_MASK \
  258. (_TIF_SIGPENDING|_TIF_SINGLESTEP|_TIF_MCE_NOTIFY|_TIF_HRTICK_RESCHED)
  259. /* flags to check in __switch_to() */
  260. #define _TIF_WORK_CTXSW \
  261. (_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_BTS_TRACE_TS|_TIF_NOTSC)
  262. #define _TIF_WORK_CTXSW_PREV _TIF_WORK_CTXSW
  263. #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG)
  264. #define PREEMPT_ACTIVE 0x10000000
  265. #endif /* !X86_32 */
  266. /*
  267. * Thread-synchronous status.
  268. *
  269. * This is different from the flags in that nobody else
  270. * ever touches our thread-synchronous status, so we don't
  271. * have to worry about atomic accesses.
  272. */
  273. #define TS_USEDFPU 0x0001 /* FPU was used by this task
  274. this quantum (SMP) */
  275. #define TS_COMPAT 0x0002 /* 32bit syscall active (64BIT)*/
  276. #define TS_POLLING 0x0004 /* true if in idle loop
  277. and not sleeping */
  278. #define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
  279. #ifndef __ASSEMBLY__
  280. extern void arch_task_cache_init(void);
  281. extern void free_thread_info(struct thread_info *ti);
  282. extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
  283. #define arch_task_cache_init arch_task_cache_init
  284. #endif
  285. #endif /* _ASM_X86_THREAD_INFO_H */