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

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

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/sched/task_stack.h (Version linux-6.12-rc7) and /include/linux/sched/task_stack.h (Version linux-4.20.17)


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

~ [ 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.

sflogo.php