X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fx86-win32-os.c;h=fc076de1ff7e62fc7be25706c35423d849bcb2d7;hb=b83ac6ca16d5c9ee7aa6f261959035accf697681;hp=ada97e3bb254d268b943ef1319c90d64d343f45e;hpb=7fb597b585fc715537ea644f7d84440eca217ca1;p=sbcl.git diff --git a/src/runtime/x86-win32-os.c b/src/runtime/x86-win32-os.c index ada97e3..fc076de 100644 --- a/src/runtime/x86-win32-os.c +++ b/src/runtime/x86-win32-os.c @@ -42,36 +42,47 @@ #include "validate.h" size_t os_vm_page_size; -int arch_os_thread_init(struct thread *thread) { +int arch_os_thread_init(struct thread *thread) +{ { - //unsigned long cur_stack_base; - //unsigned long cur_stack_end; + void *top_exception_frame; void *cur_stack_end; - - //asm volatile ("movl %%fs:8,%0": "=r" (cur_stack_base)); - // asm volatile ("movl %%fs:4,%0": "=r" (cur_stack_end)); - - asm volatile ("movl %%fs:0,%0": "=r" (cur_stack_end)); - - // fprintf(stderr, "#x%08lx #x%08lx.\n", cur_stack_base, cur_stack_end); - - //if (cur_stack_base > thread->control_stack_start) { - // cur_stack_base = thread->control_stack_start; - //} - - //if (cur_stack_end < thread->control_stack_end) { - // cur_stack_end = thread->control_stack_end; - //} - - // fprintf(stderr, "#x%08lx #x%08lx.\n", cur_stack_base, cur_stack_end); - //fflush(stderr); - - //getchar(); - - //asm volatile ("movl %0,%%fs:8": : "r" (cur_stack_base)); - //asm volatile ("movl %0,%%fs:4": : "r" (cur_stack_end)); - - thread->control_stack_end = cur_stack_end; + void *cur_stack_start; + MEMORY_BASIC_INFORMATION stack_memory; + + asm volatile ("movl %%fs:0,%0": "=r" (top_exception_frame)); + asm volatile ("movl %%fs:4,%0": "=r" (cur_stack_end)); + + /* Can't pull stack start from fs:4 or fs:8 or whatever, + * because that's only what currently has memory behind + * it from being used, so do a quick VirtualQuery() and + * grab the AllocationBase. -AB 2006/11/25 + */ + + if (!VirtualQuery(&stack_memory, &stack_memory, sizeof(stack_memory))) { + fprintf(stderr, "VirtualQuery: 0x%lx.\n", GetLastError()); + lose("Could not query stack memory information."); + } + cur_stack_start = stack_memory.AllocationBase; + + /* We use top_exception_frame rather than cur_stack_end to + * elide the last few (boring) stack entries at the bottom of + * the backtrace. + */ + thread->control_stack_start = cur_stack_start; + thread->control_stack_end = top_exception_frame; + +#ifndef LISP_FEATURE_SB_THREAD + /* + * Theoretically, threaded SBCL binds directly against + * the thread structure for these values. We don't do + * threads yet, but we'll probably do the same. We do + * need to reset these, though, because they were + * initialized based on the wrong stack space. + */ + SetSymbolValue(CONTROL_STACK_START,(lispobj)thread->control_stack_start,thread); + SetSymbolValue(CONTROL_STACK_END,(lispobj)thread->control_stack_end,thread); +#endif } #ifdef LISP_FEATURE_SB_THREAD