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

From: Maninder Singh
Date: Wed Dec 19 2018 - 03:47:00 EST


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 <maninder1.s@xxxxxxxxxxx>
Signed-off-by: Vaneet Narang <v.narang@xxxxxxxxxxx>
---
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