From 1911905c6bbb0f33183297340382e9c2fbaa6205 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 30 Nov 2011 12:39:21 -0800 Subject: [PATCH] vm: frame size for signal handler code blocks --- basis/cpu/x86/32/bootstrap.factor | 3 ++- basis/cpu/x86/64/bootstrap.factor | 2 ++ basis/cpu/x86/64/unix/bootstrap.factor | 1 + basis/cpu/x86/64/windows/bootstrap.factor | 1 + vm/cpu-x86.32.hpp | 5 +++-- vm/inline_cache.cpp | 2 +- vm/jit.cpp | 4 ++-- vm/jit.hpp | 2 +- vm/os-linux-x86.64.hpp | 5 +++-- vm/os-macosx-x86.64.hpp | 5 +++-- vm/os-windows.64.hpp | 5 +++-- vm/quotations.cpp | 6 +++++- 12 files changed, 27 insertions(+), 14 deletions(-) diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index 5930ba910a..268597d41e 100755 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -10,6 +10,7 @@ IN: bootstrap.x86 4 \ cell set : leaf-stack-frame-size ( -- n ) 4 bootstrap-cells ; +: signal-handler-stack-frame-size ( -- n ) 12 bootstrap-cells ; : stack-frame-size ( -- n ) 8 bootstrap-cells ; : shift-arg ( -- reg ) ECX ; : div-arg ( -- reg ) EAX ; @@ -104,7 +105,7 @@ IN: bootstrap.x86 ! peform their own prolog/epilog preserving registers. :: jit-signal-handler-prolog ( -- frame-size ) - stack-frame-size 8 bootstrap-cells + :> frame-size + signal-handler-stack-frame-size :> frame-size ! minus a cell each for flags and return address ! use LEA so we don't dirty flags ESP ESP frame-size 2 bootstrap-cells - neg [+] LEA diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor index 8ed80af2c6..8367b54ae4 100755 --- a/basis/cpu/x86/64/bootstrap.factor +++ b/basis/cpu/x86/64/bootstrap.factor @@ -97,6 +97,8 @@ IN: bootstrap.x86 :: jit-signal-handler-prolog ( -- frame-size ) signal-handler-save-regs :> save-regs save-regs length 1 + bootstrap-cells 16 align stack-frame-size + :> frame-size + frame-size signal-handler-stack-frame-size = + [ "unexpected signal handler frame size" throw ] unless ! minus a cell each for flags, return address ! use LEA so we don't dirty flags RSP RSP frame-size 2 bootstrap-cells - neg [+] LEA diff --git a/basis/cpu/x86/64/unix/bootstrap.factor b/basis/cpu/x86/64/unix/bootstrap.factor index deeb31cd77..f5265dc020 100644 --- a/basis/cpu/x86/64/unix/bootstrap.factor +++ b/basis/cpu/x86/64/unix/bootstrap.factor @@ -6,6 +6,7 @@ sequences system vocabs ; IN: bootstrap.x86 : leaf-stack-frame-size ( -- n ) 4 bootstrap-cells ; +: signal-handler-stack-frame-size ( -- n ) 20 bootstrap-cells ; : stack-frame-size ( -- n ) 4 bootstrap-cells ; : nv-regs ( -- seq ) { RBX R12 R13 R14 R15 } ; : volatile-regs ( -- seq ) { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ; diff --git a/basis/cpu/x86/64/windows/bootstrap.factor b/basis/cpu/x86/64/windows/bootstrap.factor index cc701a6b63..00f1cc1acb 100644 --- a/basis/cpu/x86/64/windows/bootstrap.factor +++ b/basis/cpu/x86/64/windows/bootstrap.factor @@ -8,6 +8,7 @@ IN: bootstrap.x86 DEFER: stack-reg : leaf-stack-frame-size ( -- n ) 4 bootstrap-cells ; +: signal-handler-stack-frame-size ( -- n ) 24 bootstrap-cells ; : stack-frame-size ( -- n ) 8 bootstrap-cells ; : nv-regs ( -- seq ) { RBX RSI RDI R12 R13 R14 R15 } ; : volatile-regs ( -- seq ) { RAX RCX RDX R8 R9 R10 R11 } ; diff --git a/vm/cpu-x86.32.hpp b/vm/cpu-x86.32.hpp index 0bc90416f1..c0afc9f683 100644 --- a/vm/cpu-x86.32.hpp +++ b/vm/cpu-x86.32.hpp @@ -3,9 +3,10 @@ namespace factor #define FACTOR_CPU_STRING "x86.32" -/* Must match the leaf-stack-frame-size stack-frame-size constants in -cpu/x86/32/bootstrap.factor */ +/* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, +and stack-frame-size constants in cpu/x86/32/bootstrap.factor */ static const unsigned LEAF_FRAME_SIZE = 16; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 48; static const unsigned JIT_FRAME_SIZE = 32; } diff --git a/vm/inline_cache.cpp b/vm/inline_cache.cpp index b7cd7630ac..4f1e907d7f 100755 --- a/vm/inline_cache.cpp +++ b/vm/inline_cache.cpp @@ -141,7 +141,7 @@ code_block *factor_vm::compile_inline_cache(fixnum index, methods.value(), cache_entries.value(), tail_call_p); - code_block *code = jit.to_code_block(); + code_block *code = jit.to_code_block(JIT_FRAME_SIZE); initialize_code_block(code); return code; } diff --git a/vm/jit.cpp b/vm/jit.cpp index 29eb6f19db..9f3d7b5ed7 100644 --- a/vm/jit.cpp +++ b/vm/jit.cpp @@ -124,7 +124,7 @@ void jit::compute_position(cell offset_) } /* Allocates memory */ -code_block *jit::to_code_block() +code_block *jit::to_code_block(cell frame_size) { /* Emit dummy GC info */ code.grow_bytes(alignment_for(code.count + 4,data_alignment)); @@ -144,7 +144,7 @@ code_block *jit::to_code_block() relocation.elements.value(), parameters.elements.value(), literals.elements.value(), - JIT_FRAME_SIZE); + frame_size); } } diff --git a/vm/jit.hpp b/vm/jit.hpp index 1024751747..a20788a499 100644 --- a/vm/jit.hpp +++ b/vm/jit.hpp @@ -68,7 +68,7 @@ struct jit { } - code_block *to_code_block(); + code_block *to_code_block(cell frame_size); private: jit(const jit&); diff --git a/vm/os-linux-x86.64.hpp b/vm/os-linux-x86.64.hpp index 94e102c37f..366a135751 100644 --- a/vm/os-linux-x86.64.hpp +++ b/vm/os-linux-x86.64.hpp @@ -28,9 +28,10 @@ inline static void uap_clear_fpu_status(void *uap) #define UAP_STACK_POINTER_TYPE greg_t -/* Must match the leaf-stack-frame-size and stack-frame-size constants -in basis/cpu/x86/64/unix/bootstrap.factor */ +/* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, +and stack-frame-size constants in basis/cpu/x86/64/unix/bootstrap.factor */ static const unsigned LEAF_FRAME_SIZE = 32; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 160; static const unsigned JIT_FRAME_SIZE = 32; } diff --git a/vm/os-macosx-x86.64.hpp b/vm/os-macosx-x86.64.hpp index d8bb821678..2b1c02beb0 100644 --- a/vm/os-macosx-x86.64.hpp +++ b/vm/os-macosx-x86.64.hpp @@ -73,9 +73,10 @@ inline static void uap_clear_fpu_status(void *uap) mach_clear_fpu_status(UAP_FS(uap)); } -/* Must match the leaf-stack-frame-size and stack-frame-size constants -in basis/cpu/x86/64/unix/bootstrap.factor */ +/* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, +and stack-frame-size constants in basis/cpu/x86/64/unix/bootstrap.factor */ static const unsigned LEAF_FRAME_SIZE = 32; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 160; static const unsigned JIT_FRAME_SIZE = 32; } diff --git a/vm/os-windows.64.hpp b/vm/os-windows.64.hpp index 42b4362b1a..19b43a74f5 100644 --- a/vm/os-windows.64.hpp +++ b/vm/os-windows.64.hpp @@ -8,9 +8,10 @@ namespace factor #define MXCSR(ctx) (ctx)->MxCsr -/* Must match the leaf-stack-frame-size and stack-frame-size constants -in basis/cpu/x86/64/windows/bootstrap.factor */ +/* Must match the leaf-stack-frame-size, signal-handler-stack-frame-size, +and stack-frame-size constants in basis/cpu/x86/64/windows/bootstrap.factor */ static const unsigned LEAF_FRAME_SIZE = 32; +static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 192; static const unsigned JIT_FRAME_SIZE = 64; } diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 0f591e3503..dc84ef506e 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -319,7 +319,11 @@ code_block *factor_vm::jit_compile_quot(cell owner_, cell quot_, bool relocating compiler.init_quotation(quot.value()); compiler.iterate_quotation(); - code_block *compiled = compiler.to_code_block(); + cell frame_size = compiler.special_subprimitive_p(owner_) + ? SIGNAL_HANDLER_STACK_FRAME_SIZE + : JIT_FRAME_SIZE; + + code_block *compiled = compiler.to_code_block(frame_size); if(relocating) initialize_code_block(compiled);