1 /* SPDX-License-Identifier: GPL-2.0-only */
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
8 #ifndef _ASM_RISCV_THREAD_INFO_H
9 #define _ASM_RISCV_THREAD_INFO_H
12 #include <linux/const.h>
15 #define KASAN_STACK_ORDER 1
17 #define KASAN_STACK_ORDER 0
20 /* thread information allocation */
22 #define THREAD_SIZE_ORDER (2 + KASAN_STACK_ORDER)
24 #define THREAD_SIZE_ORDER (1 + KASAN_STACK_ORDER)
26 #define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
29 * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
30 * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
33 #ifdef CONFIG_VMAP_STACK
34 #define THREAD_ALIGN (2 * THREAD_SIZE)
36 #define THREAD_ALIGN THREAD_SIZE
39 #define THREAD_SHIFT (PAGE_SHIFT + THREAD_SIZE_ORDER)
40 #define OVERFLOW_STACK_SIZE SZ_4K
41 #define SHADOW_OVERFLOW_STACK_SIZE (1024)
45 extern long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE / sizeof(long)];
46 extern unsigned long spin_shadow_stack;
48 #include <asm/processor.h>
52 * low level task data that entry.S needs immediate access to
53 * - this struct should fit entirely inside of one cache line
54 * - if the members of this struct changes, the assembly constants
55 * in asm-offsets.c must be updated accordingly
56 * - thread_info is included in task_struct at an offset of 0. This means that
57 * tp points to both thread_info and task_struct.
60 unsigned long flags; /* low level flags */
61 int preempt_count; /* 0=>preemptible, <0=>BUG */
63 * These stack pointers are overwritten on every system call or
64 * exception. SP is also saved to the stack it can be recovered when
67 long kernel_sp; /* Kernel stack pointer */
68 long user_sp; /* User stack pointer */
70 unsigned long syscall_work; /* SYSCALL_WORK_ flags */
74 * macros/functions for gaining access to the thread information structure
76 * preempt_count needs to be 1 initially, until the scheduler is functional.
78 #define INIT_THREAD_INFO(tsk) \
81 .preempt_count = INIT_PREEMPT_COUNT, \
84 #endif /* !__ASSEMBLY__ */
87 * thread information flags
88 * - these are process state flags that various assembly files may need to
90 * - pending work-to-be-done flags are in lowest half-word
91 * - other flags in upper half-word(s)
93 #define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
94 #define TIF_SIGPENDING 2 /* signal pending */
95 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
96 #define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
97 #define TIF_MEMDIE 5 /* is terminating due to OOM killer */
98 #define TIF_NOTIFY_SIGNAL 9 /* signal notifications exist */
99 #define TIF_UPROBE 10 /* uprobe breakpoint or singlestep */
100 #define TIF_32BIT 11 /* compat-mode 32bit process */
102 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
103 #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
104 #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
105 #define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
106 #define _TIF_UPROBE (1 << TIF_UPROBE)
108 #define _TIF_WORK_MASK \
109 (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED | \
110 _TIF_NOTIFY_SIGNAL | _TIF_UPROBE)
112 #endif /* _ASM_RISCV_THREAD_INFO_H */