From 3ec7c3b74913b43dc2bee769e168f3f3e76efe39 Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Sun, 4 Feb 2018 21:53:45 +0100 Subject: [PATCH] threading: fix race conditions when interrupted while pushing in the stack We have to make sure that the stack pointers always point to a valid object. This means that we have to increase env->stack_top before we change things in the stack. --- src/c/interpreter.d | 2 +- src/h/stacks.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/c/interpreter.d b/src/c/interpreter.d index 0a0aaad8d..07985494b 100644 --- a/src/c/interpreter.d +++ b/src/c/interpreter.d @@ -124,8 +124,8 @@ ecl_stack_frame_push(cl_object f, cl_object o) if (top >= env->stack_limit) { top = ecl_stack_grow(env); } - *top = o; env->stack_top = ++top; + *(top-1) = o; f->frame.base = top - (++(f->frame.size)); f->frame.stack = env->stack; } diff --git a/src/h/stacks.h b/src/h/stacks.h index 15b068b78..815f7f563 100755 --- a/src/h/stacks.h +++ b/src/h/stacks.h @@ -334,8 +334,8 @@ extern ECL_API ecl_frame_ptr _ecl_frs_push(register cl_env_ptr, register cl_obje if (ecl_unlikely(__new_top >= __env->stack_limit)) { \ __new_top = ecl_stack_grow(__env); \ } \ - *__new_top = (o); \ - __env->stack_top = __new_top+1; } while (0) + __env->stack_top = __new_top+1; \ + *__new_top = (o); } while (0) #define ECL_STACK_POP_UNSAFE(env) *(--((env)->stack_top))