VM: bump stack_reserved from 1kb to 4kb
The added test case fails with a doulbe fault, which appears to be caused by a stack overflow in the code that tries to handle the stack overflow. So bumping it to 4096 bytes should give the code enough stack space to play with.db4
parent
beb71ce49b
commit
6fedb79c73
|
@ -1,6 +1,5 @@
|
||||||
USING: kernel math namespaces io tools.test sequences vectors
|
USING: accessors arrays continuations debugger eval io kernel kernel.private
|
||||||
continuations debugger parser memory arrays words
|
math memory namespaces parser sequences system tools.test vectors words ;
|
||||||
kernel.private accessors eval ;
|
|
||||||
IN: continuations.tests
|
IN: continuations.tests
|
||||||
|
|
||||||
: (callcc1-test) ( n obj -- n' obj )
|
: (callcc1-test) ( n obj -- n' obj )
|
||||||
|
@ -56,6 +55,25 @@ IN: continuations.tests
|
||||||
! : callstack-overflow callstack-overflow f ;
|
! : callstack-overflow callstack-overflow f ;
|
||||||
! [ callstack-overflow ] must-fail
|
! [ callstack-overflow ] must-fail
|
||||||
|
|
||||||
|
! This tries to verify that enough bytes are cut off from the
|
||||||
|
! callstack to run the error handler.
|
||||||
|
: pre ( -- ) nano-count 0 = [ ] [ ] if ;
|
||||||
|
|
||||||
|
: post ( -- ) ;
|
||||||
|
|
||||||
|
: do-overflow ( -- )
|
||||||
|
pre do-overflow post ;
|
||||||
|
|
||||||
|
: recurse ( -- ? )
|
||||||
|
[ do-overflow f ] [ ] recover
|
||||||
|
second ERROR-CALLSTACK-OVERFLOW = ;
|
||||||
|
|
||||||
|
os windows? [
|
||||||
|
{ t } [
|
||||||
|
10 [ recurse ] replicate [ ] all?
|
||||||
|
] unit-test
|
||||||
|
] unless
|
||||||
|
|
||||||
: don't-compile-me ( -- ) ;
|
: don't-compile-me ( -- ) ;
|
||||||
: foo ( -- ) callstack "c" set don't-compile-me ;
|
: foo ( -- ) callstack "c" set don't-compile-me ;
|
||||||
: bar ( -- a b ) 1 foo 2 ;
|
: bar ( -- a b ) 1 foo 2 ;
|
||||||
|
|
|
@ -12,7 +12,11 @@ enum context_object {
|
||||||
OBJ_IN_CALLBACK_P,
|
OBJ_IN_CALLBACK_P,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const cell stack_reserved = 1024;
|
/* When the callstack fills up (e.g by to deep recursion), a callstack
|
||||||
|
overflow error is triggered. So before continuing executing on it
|
||||||
|
in general_error(), we chop of this many bytes to have some space
|
||||||
|
to work with. */
|
||||||
|
static const cell stack_reserved = 4096;
|
||||||
|
|
||||||
struct context {
|
struct context {
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
namespace factor {
|
namespace factor {
|
||||||
|
|
||||||
void factor_vm::dispatch_signal_handler(cell* sp, cell* pc, cell handler) {
|
void factor_vm::dispatch_signal_handler(cell* sp, cell* pc, cell handler) {
|
||||||
if (!code->seg->in_segment_p(*pc) ||
|
|
||||||
*sp < ctx->callstack_seg->start + stack_reserved) {
|
cell callstack_limit = ctx->callstack_seg->start + stack_reserved;
|
||||||
|
if (!code->seg->in_segment_p(*pc) || *sp < callstack_limit) {
|
||||||
/* Fault came from the VM, foreign code, a callstack overflow, or
|
/* Fault came from the VM, foreign code, a callstack overflow, or
|
||||||
we don't have enough callstack room to try the resumable
|
we don't have enough callstack room to try the resumable
|
||||||
handler. Cut the callstack down to the shallowest Factor stack
|
handler. Cut the callstack down to the shallowest Factor stack
|
||||||
|
@ -15,8 +16,7 @@ void factor_vm::dispatch_signal_handler(cell* sp, cell* pc, cell handler) {
|
||||||
|
|
||||||
cell frame_top = ctx->callstack_top;
|
cell frame_top = ctx->callstack_top;
|
||||||
|
|
||||||
while (frame_top < ctx->callstack_bottom &&
|
while (frame_top < ctx->callstack_bottom && frame_top < callstack_limit) {
|
||||||
frame_top < ctx->callstack_seg->start + stack_reserved) {
|
|
||||||
frame_top = frame_predecessor(frame_top);
|
frame_top = frame_predecessor(frame_top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue