From aa3d65272a7a9c1f0bd8e38e3671eab33f70f33a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 5 Feb 2010 14:29:45 +1300 Subject: [PATCH] cpu.x86: fix crashes when using certain features (threads, errors, etc) with profiling enabled on x86-64. The profiling stub was clobbering an argument for the unwind_native_frames() entry point --- basis/cpu/x86/bootstrap.factor | 10 +++++----- basis/tools/profiler/profiler-tests.factor | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor index 19ac0189a3..8f1a4d7f49 100644 --- a/basis/cpu/x86/bootstrap.factor +++ b/basis/cpu/x86/bootstrap.factor @@ -56,15 +56,15 @@ big-endian off [ ! Load word - temp0 0 MOV rc-absolute-cell rt-literal jit-rel + safe-reg 0 MOV rc-absolute-cell rt-literal jit-rel ! Bump profiling counter - temp0 profile-count-offset [+] 1 tag-fixnum ADD + safe-reg profile-count-offset [+] 1 tag-fixnum ADD ! Load word->code - temp0 temp0 word-code-offset [+] MOV + safe-reg safe-reg word-code-offset [+] MOV ! Compute word entry point - temp0 compiled-header-size ADD + safe-reg compiled-header-size ADD ! Jump to entry point - temp0 JMP + safe-reg JMP ] jit-profiling jit-define [ diff --git a/basis/tools/profiler/profiler-tests.factor b/basis/tools/profiler/profiler-tests.factor index a85d934506..5c31cdaeb4 100644 --- a/basis/tools/profiler/profiler-tests.factor +++ b/basis/tools/profiler/profiler-tests.factor @@ -1,6 +1,6 @@ USING: accessors tools.profiler tools.test kernel memory math threads alien alien.c-types tools.profiler.private sequences -compiler.test compiler.units words ; +compiler.test compiler.units words arrays ; IN: tools.profiler.tests [ t ] [ @@ -9,7 +9,7 @@ IN: tools.profiler.tests \ length counter>> = ] unit-test -[ ] [ [ 10 [ gc ] times ] profile ] unit-test +[ ] [ [ 3 [ gc ] times ] profile ] unit-test [ ] [ [ 1000000 sleep ] profile ] unit-test @@ -72,3 +72,8 @@ IN: tools.profiler.tests ] profile counter>> ] unit-test + +! unwind_native_frames() would fail if profiling was enabled +! because the jit-profiling stub would clobber a parameter register +! on x86-64 +[ [ -10 f ] profile ] must-fail