~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/sched/task_stack.h

Version: ~ [ linux-6.6-rc1 ] ~ [ linux-6.5.2 ] ~ [ linux-6.4.15 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.52 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.131 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.194 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.256 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.294 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.325 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_SCHED_TASK_STACK_H
  3 #define _LINUX_SCHED_TASK_STACK_H
  4 
  5 /*
  6  * task->stack (kernel stack) handling interfaces:
  7  */
  8 
  9 #include <linux/sched.h>
 10 #include <linux/magic.h>
 11 
 12 #ifdef CONFIG_THREAD_INFO_IN_TASK
 13 
 14 /*
 15  * When accessing the stack of a non-current task that might exit, use
 16  * try_get_task_stack() instead.  task_stack_page will return a pointer
 17  * that could get freed out from under you.
 18  */
 19 static inline void *task_stack_page(const struct task_struct *task)
 20 {
 21         return task->stack;
 22 }
 23 
 24 #define setup_thread_stack(new,old)     do { } while(0)
 25 
 26 static inline unsigned long *end_of_stack(const struct task_struct *task)
 27 {
 28 #ifdef CONFIG_STACK_GROWSUP
 29         return (unsigned long *)((unsigned long)task->stack + THREAD_SIZE) - 1;
 30 #else
 31         return task->stack;
 32 #endif
 33 }
 34 
 35 #elif !defined(__HAVE_THREAD_FUNCTIONS)
 36 
 37 #define task_stack_page(task)   ((void *)(task)->stack)
 38 
 39 static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
 40 {
 41         *task_thread_info(p) = *task_thread_info(org);
 42         task_thread_info(p)->task = p;
 43 }
 44 
 45 /*
 46  * Return the address of the last usable long on the stack.
 47  *
 48  * When the stack grows down, this is just above the thread
 49  * info struct. Going any lower will corrupt the threadinfo.
 50  *
 51  * When the stack grows up, this is the highest address.
 52  * Beyond that position, we corrupt data on the next page.
 53  */
 54 static inline unsigned long *end_of_stack(struct task_struct *p)
 55 {
 56 #ifdef CONFIG_STACK_GROWSUP
 57         return (unsigned long *)((unsigned long)task_thread_info(p) + THREAD_SIZE) - 1;
 58 #else
 59         return (unsigned long *)(task_thread_info(p) + 1);
 60 #endif
 61 }
 62 
 63 #endif
 64 
 65 #ifdef CONFIG_THREAD_INFO_IN_TASK
 66 static inline void *try_get_task_stack(struct task_struct *tsk)
 67 {
 68         return refcount_inc_not_zero(&tsk->stack_refcount) ?
 69                 task_stack_page(tsk) : NULL;
 70 }
 71 
 72 extern void put_task_stack(struct task_struct *tsk);
 73 #else
 74 static inline void *try_get_task_stack(struct task_struct *tsk)
 75 {
 76         return task_stack_page(tsk);
 77 }
 78 
 79 static inline void put_task_stack(struct task_struct *tsk) {}
 80 #endif
 81 
 82 #define task_stack_end_corrupted(task) \
 83                 (*(end_of_stack(task)) != STACK_END_MAGIC)
 84 
 85 static inline int object_is_on_stack(const void *obj)
 86 {
 87         void *stack = task_stack_page(current);
 88 
 89         return (obj >= stack) && (obj < (stack + THREAD_SIZE));
 90 }
 91 
 92 extern void thread_stack_cache_init(void);
 93 
 94 #ifdef CONFIG_DEBUG_STACK_USAGE
 95 static inline unsigned long stack_not_used(struct task_struct *p)
 96 {
 97         unsigned long *n = end_of_stack(p);
 98 
 99         do {    /* Skip over canary */
100 # ifdef CONFIG_STACK_GROWSUP
101                 n--;
102 # else
103                 n++;
104 # endif
105         } while (!*n);
106 
107 # ifdef CONFIG_STACK_GROWSUP
108         return (unsigned long)end_of_stack(p) - (unsigned long)n;
109 # else
110         return (unsigned long)n - (unsigned long)end_of_stack(p);
111 # endif
112 }
113 #endif
114 extern void set_task_stack_end_magic(struct task_struct *tsk);
115 
116 #ifndef __HAVE_ARCH_KSTACK_END
117 static inline int kstack_end(void *addr)
118 {
119         /* Reliable end of stack detection:
120          * Some APM bios versions misalign the stack
121          */
122         return !(((unsigned long)addr+sizeof(void*)-1) & (THREAD_SIZE-sizeof(void*)));
123 }
124 #endif
125 
126 #endif /* _LINUX_SCHED_TASK_STACK_H */
127 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp