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

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

Version: ~ [ linux-5.16-rc1 ] ~ [ linux-5.15.2 ] ~ [ linux-5.14.18 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.79 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.159 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.217 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.255 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.290 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.292 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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