From 1d329efe312141d5385af1d2e98f72f938b5f7b6 Mon Sep 17 00:00:00 2001 From: Alastair Bridgewater Date: Sat, 7 Aug 2010 13:46:12 +0000 Subject: [PATCH] 1.0.41.20: runtime: Straighten out access to binding stack pointers. * Unify all non-cheneygc access to binding stack pointers under one common interface. * Non-threaded targets are unaffected. Threaded targets with a binding stack pointer register (reg_BSP) must use the pointer in the thread structure rather than the global variable during call in / call out when built with LISP_FEATURE_SB_THREAD. --- src/runtime/dynbind.c | 20 ++++++-------------- src/runtime/globals.c | 2 +- src/runtime/globals.h | 4 ++-- src/runtime/interrupt.c | 5 ++--- src/runtime/monitor.c | 2 +- src/runtime/pseudo-atomic.h | 6 ------ src/runtime/purify.c | 2 +- src/runtime/thread.c | 4 +--- src/runtime/thread.h | 19 +++++++++++++++++++ version.lisp-expr | 2 +- 10 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/runtime/dynbind.c b/src/runtime/dynbind.c index 6f20b63..1d62ee0 100644 --- a/src/runtime/dynbind.c +++ b/src/runtime/dynbind.c @@ -27,20 +27,12 @@ #include "genesis/thread.h" #include "genesis/static-symbols.h" -#if defined(BINDING_STACK_POINTER) -#define GetBSP() ((struct binding *)SymbolValue(BINDING_STACK_POINTER,thread)) -#define SetBSP(value) SetSymbolValue(BINDING_STACK_POINTER, (lispobj)(value),thread) -#else -#define GetBSP() ((struct binding *)current_binding_stack_pointer) -#define SetBSP(value) (current_binding_stack_pointer=(lispobj *)(value)) -#endif - void bind_variable(lispobj symbol, lispobj value, void *th) { struct binding *binding; struct thread *thread=(struct thread *)th; - binding = GetBSP(); - SetBSP(binding+1); + binding = (struct binding *)get_binding_stack_pointer(thread); + set_binding_stack_pointer(thread,binding+1); #ifdef LISP_FEATURE_SB_THREAD { struct symbol *sym=(struct symbol *)native_pointer(symbol); @@ -78,7 +70,7 @@ unbind(void *th) struct binding *binding; lispobj symbol; - binding = GetBSP() - 1; + binding = ((struct binding *)get_binding_stack_pointer(thread)) - 1; symbol = binding->symbol; @@ -87,7 +79,7 @@ unbind(void *th) binding->symbol = 0; binding->value = 0; - SetBSP(binding); + set_binding_stack_pointer(thread,binding); } void @@ -95,7 +87,7 @@ unbind_to_here(lispobj *bsp,void *th) { struct thread *thread=(struct thread *)th; struct binding *target = (struct binding *)bsp; - struct binding *binding = GetBSP(); + struct binding *binding = (struct binding *)get_binding_stack_pointer(thread); lispobj symbol; while (target < binding) { @@ -110,5 +102,5 @@ unbind_to_here(lispobj *bsp,void *th) binding->value = 0; } } - SetBSP(binding); + set_binding_stack_pointer(thread,binding); } diff --git a/src/runtime/globals.c b/src/runtime/globals.c index 5e84af0..9eec708 100644 --- a/src/runtime/globals.c +++ b/src/runtime/globals.c @@ -28,7 +28,7 @@ int foreign_function_call_active; lispobj *current_control_stack_pointer; lispobj *current_control_frame_pointer; -#ifndef BINDING_STACK_POINTER +#if !defined(BINDING_STACK_POINTER) && !defined(LISP_FEATURE_SB_THREAD) lispobj *current_binding_stack_pointer; #endif diff --git a/src/runtime/globals.h b/src/runtime/globals.h index a51964c..7d424a8 100644 --- a/src/runtime/globals.h +++ b/src/runtime/globals.h @@ -49,9 +49,9 @@ extern pthread_key_t specials; extern lispobj *current_control_stack_pointer; extern lispobj *current_control_frame_pointer; -# if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64) +#if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64) && !defined(LISP_FEATURE_SB_THREAD) extern lispobj *current_binding_stack_pointer; -# endif +#endif #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64) /* This is unused on X86 and X86_64, but is used as the global diff --git a/src/runtime/interrupt.c b/src/runtime/interrupt.c index 4db3cb2..5f057aa 100644 --- a/src/runtime/interrupt.c +++ b/src/runtime/interrupt.c @@ -688,9 +688,8 @@ fake_foreign_function_call(os_context_t *context) #endif #endif #ifdef reg_BSP - current_binding_stack_pointer = - (lispobj *)(unsigned long) - (*os_context_register_addr(context, reg_BSP)); + set_binding_stack_pointer(thread, + *os_context_register_addr(context, reg_BSP)); #endif build_fake_control_stack_frames(thread,context); diff --git a/src/runtime/monitor.c b/src/runtime/monitor.c index 5bc83c3..193f4c1 100644 --- a/src/runtime/monitor.c +++ b/src/runtime/monitor.c @@ -194,7 +194,7 @@ regs_cmd(char **ptr) printf("CFP\t=\t0x%08lx ", (unsigned long)current_control_frame_pointer); #ifdef reg_BSP - printf("BSP\t=\t0x%08lx\n", (unsigned long)current_binding_stack_pointer); + printf("BSP\t=\t0x%08lx\n", (unsigned long)get_binding_stack_pointer(thread)); #else /* printf("BSP\t=\t0x%08lx\n", (unsigned long)SymbolValue(BINDING_STACK_POINTER)); */ diff --git a/src/runtime/pseudo-atomic.h b/src/runtime/pseudo-atomic.h index 8556e0c..230e3e8 100644 --- a/src/runtime/pseudo-atomic.h +++ b/src/runtime/pseudo-atomic.h @@ -22,8 +22,6 @@ SetSymbolValue(ALLOCATION_POINTER, value, 0) #define get_alloc_pointer() \ SymbolValue(ALLOCATION_POINTER, 0) -#define get_binding_stack_pointer(thread) \ - SymbolValue(BINDING_STACK_POINTER, thread) #if defined(LISP_FEATURE_X86) #define LISPOBJ_ASM_SUFFIX "l" @@ -108,8 +106,6 @@ clear_pseudo_atomic_interrupted(struct thread *thread) ((unsigned long) dynamic_space_free_pointer & ~LOWTAG_MASK) #ifdef LISP_FEATURE_SB_THREAD -#define get_binding_stack_pointer(thread) \ - ((thread)->binding_stack_pointer) #define get_pseudo_atomic_atomic(thread) \ ((thread)->pseudo_atomic_bits & flag_PseudoAtomic) #define set_pseudo_atomic_atomic(thread) \ @@ -123,8 +119,6 @@ clear_pseudo_atomic_interrupted(struct thread *thread) #define clear_pseudo_atomic_interrupted(thread) \ ((thread)->pseudo_atomic_bits &= ~flag_PseudoAtomicInterrupted) #else -#define get_binding_stack_pointer(thread) \ - (current_binding_stack_pointer) #define get_pseudo_atomic_atomic(thread) \ ((unsigned long)dynamic_space_free_pointer & flag_PseudoAtomic) #define set_pseudo_atomic_atomic(thread) \ diff --git a/src/runtime/purify.c b/src/runtime/purify.c index 59acf19..eeedda4 100644 --- a/src/runtime/purify.c +++ b/src/runtime/purify.c @@ -964,7 +964,7 @@ purify(lispobj static_roots, lispobj read_only_roots) #endif pscav( (lispobj *)all_threads->binding_stack_start, - (lispobj *)current_binding_stack_pointer - + (lispobj *)get_binding_stack_pointer(all_threads) - all_threads->binding_stack_start, 0); diff --git a/src/runtime/thread.c b/src/runtime/thread.c index b71eba0..60821ee 100644 --- a/src/runtime/thread.c +++ b/src/runtime/thread.c @@ -420,7 +420,7 @@ create_thread_struct(lispobj initial_function) { th->control_stack_guard_page_protected = T; th->alien_stack_start= (lispobj*)((void*)th->binding_stack_start+BINDING_STACK_SIZE); - th->binding_stack_pointer=th->binding_stack_start; + set_binding_stack_pointer(th,th->binding_stack_start); th->this=th; th->os_thread=0; #ifdef LISP_FEATURE_SB_THREAD @@ -467,11 +467,9 @@ create_thread_struct(lispobj initial_function) { SetSymbolValue(CONTROL_STACK_START,(lispobj)th->control_stack_start,th); SetSymbolValue(CONTROL_STACK_END,(lispobj)th->control_stack_end,th); #if defined(LISP_FEATURE_X86) || defined (LISP_FEATURE_X86_64) - SetSymbolValue(BINDING_STACK_POINTER,(lispobj)th->binding_stack_pointer,th); SetSymbolValue(ALIEN_STACK,(lispobj)th->alien_stack_pointer,th); SetSymbolValue(PSEUDO_ATOMIC_BITS,(lispobj)th->pseudo_atomic_bits,th); #else - current_binding_stack_pointer=th->binding_stack_pointer; current_control_stack_pointer=th->control_stack_start; #endif #endif diff --git a/src/runtime/thread.h b/src/runtime/thread.h index eb653c1..fa4b7bc 100644 --- a/src/runtime/thread.h +++ b/src/runtime/thread.h @@ -170,6 +170,25 @@ StaticSymbolFunction(lispobj sym) return ((struct fdefn *)native_pointer(SymbolValue(sym, 0)))->fun; } +/* These are for use during GC, on the current thread, or on prenatal + * threads only. */ +#if defined(LISP_FEATURE_SB_THREAD) +#define get_binding_stack_pointer(thread) \ + ((thread)->binding_stack_pointer) +#define set_binding_stack_pointer(thread,value) \ + ((thread)->binding_stack_pointer = (lispobj *)(value)) +#elif defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64) +#define get_binding_stack_pointer(thread) \ + SymbolValue(BINDING_STACK_POINTER, thread) +#define set_binding_stack_pointer(thread,value) \ + SetSymbolValue(BINDING_STACK_POINTER, (lispobj)(value), thread) +#else +#define get_binding_stack_pointer(thread) \ + (current_binding_stack_pointer) +#define set_binding_stack_pointer(thread,value) \ + (current_binding_stack_pointer = (lispobj *)(value)) +#endif + #if defined(LISP_FEATURE_SB_THREAD) && defined(LISP_FEATURE_GCC_TLS) extern __thread struct thread *current_thread; #endif diff --git a/version.lisp-expr b/version.lisp-expr index ecb0493..ceec0e9 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.41.19" +"1.0.41.20" -- 1.7.10.4