2018-12-19 09:28:06

by Maninder Singh

[permalink] [raw]
Subject: [PATCH 1/1] task_stack: make code generic for getting end of stack.

currently code provides end of stack by considering stack grows
downwards. Make it useful for architectures where stack grows upward.

Although CONFIG_THREAD_INFO_IN_TASK is selected only for
architectures where stack grows downward.

Signed-off-by: Maninder Singh <[email protected]>
Signed-off-by: Vaneet Narang <[email protected]>
---
include/linux/sched/task_stack.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h
index 6a84192..4f099d3 100644
--- a/include/linux/sched/task_stack.h
+++ b/include/linux/sched/task_stack.h
@@ -25,7 +25,11 @@ static inline void *task_stack_page(const struct task_struct *task)

static inline unsigned long *end_of_stack(const struct task_struct *task)
{
+#ifdef CONFIG_STACK_GROWSUP
+ return (unsigned long *)((unsigned long)task->stack + THREAD_SIZE) - 1;
+#else
return task->stack;
+#endif
}

#elif !defined(__HAVE_THREAD_FUNCTIONS)
--
1.9.1