1
0
mirror of https://github.com/janet-lang/janet synced 2025-02-02 10:19:10 +00:00

Add per fiber stack limit.

This commit is contained in:
Calvin Rose 2018-02-12 17:36:29 -05:00
parent a614816a04
commit 2f4fd23884
4 changed files with 5 additions and 4 deletions

View File

@ -37,6 +37,7 @@ DstFiber *dst_fiber(int32_t capacity) {
fiber->data = NULL;
}
fiber->parent = NULL;
fiber->maxstack = DST_STACK_MAX;
return dst_fiber_reset(fiber);
}

View File

@ -572,11 +572,10 @@ static void *op_lookup[255] = {
VM_OP(DOP_CALL)
{
Dst callee = stack[oparg(2, 0xFFFF)];
#ifdef DST_STACK_MAX
if (dst_vm_fiber->stacktop > DST_STACK_MAX) {
if (dst_vm_fiber->maxstack &&
dst_vm_fiber->stacktop > dst_vm_fiber->maxstack) {
vm_throw("stack overflow");
}
#endif
if (dst_checktype(callee, DST_FUNCTION)) {
func = dst_unwrap_function(callee);
dst_stack_frame(stack)->pc = pc;

View File

@ -123,7 +123,7 @@ extern "C" {
/* Define max stack size for stacks before raising a stack overflow error.
* If this is not defined, fiber stacks can grow without limit (until memory
* runs out) */
#define DST_STACK_MAX 4096
#define DST_STACK_MAX 8192
/* Use nanboxed values - uses 8 bytes per value instead of 12 or 16. */
#define DST_NANBOX

View File

@ -314,6 +314,7 @@ struct DstFiber {
int32_t stackstart; /* Beginning of next args */
int32_t stacktop; /* Top of stack. Where values are pushed and popped from. */
int32_t capacity;
int32_t maxstack; /* Arbitrary defined limit for stack overflow */
enum {
DST_FIBER_PENDING,
DST_FIBER_NEW,