You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2019/12/06 11:52:27 UTC
[mynewt-core] 02/02: kernel/os: Fix invalid stacktop references
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 13423bde3b2a8177431b740e4e61f93beac1faf1
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Dec 5 10:40:32 2019 +0100
kernel/os: Fix invalid stacktop references
---
kernel/os/src/os_sched.c | 6 +++---
kernel/os/src/os_stacktrace.c | 6 ++++--
kernel/os/src/os_task.c | 2 +-
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/kernel/os/src/os_sched.c b/kernel/os/src/os_sched.c
index 1a468b2..151079e 100644
--- a/kernel/os/src/os_sched.c
+++ b/kernel/os/src/os_sched.c
@@ -77,12 +77,12 @@ os_sched_ctx_sw_hook(struct os_task *next_t)
uint32_t ticks;
#if MYNEWT_VAL(OS_CTX_SW_STACK_CHECK)
- os_stack_t *top;
+ os_stack_t *stack;
int i;
- top = g_current_task->t_stacktop - g_current_task->t_stacksize;
+ stack = g_current_task->t_stackbottom;
for (i = 0; i < MYNEWT_VAL(OS_CTX_SW_STACK_GUARD); i++) {
- assert(top[i] == OS_STACK_PATTERN);
+ assert(stack[i] == OS_STACK_PATTERN);
}
#endif
next_t->t_ctx_sw_cnt++;
diff --git a/kernel/os/src/os_stacktrace.c b/kernel/os/src/os_stacktrace.c
index 91a3bc4..33e0453 100644
--- a/kernel/os/src/os_stacktrace.c
+++ b/kernel/os/src/os_stacktrace.c
@@ -78,14 +78,16 @@ os_stacktrace(uintptr_t sp)
uintptr_t addr;
uintptr_t end;
struct os_task *t;
+ os_stack_t *stacktop;
sp &= ~(sizeof(uintptr_t) - 1);
end = sp + OS_STACK_DEPTH_MAX;
if (g_os_started && g_current_task) {
t = g_current_task;
- if (sp > (uintptr_t)t->t_stacktop && end > (uintptr_t)t->t_stacktop) {
- end = (uintptr_t)t->t_stacktop;
+ stacktop = os_task_stacktop_get(t);
+ if (end > (uintptr_t)stacktop) {
+ end = (uintptr_t)stacktop;
}
} else {
t = NULL;
diff --git a/kernel/os/src/os_task.c b/kernel/os/src/os_task.c
index 2129493..7fbeeef 100644
--- a/kernel/os/src/os_task.c
+++ b/kernel/os/src/os_task.c
@@ -95,7 +95,7 @@ os_task_init(struct os_task *t, const char *name, os_task_func_t func,
_clear_stack(stack_bottom, stack_size);
t->t_stackbottom = stack_bottom;
t->t_stacksize = stack_size;
- t->t_stackptr = os_arch_task_stack_init(t, &stack_bottom[stack_size],
+ t->t_stackptr = os_arch_task_stack_init(t, os_task_stacktop_get(t),
t->t_stacksize);
STAILQ_FOREACH(task, &g_os_task_list, t_os_task_list) {