From a8c3a7ccaf3e1d820a7902a478948a55f5324f50 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Mon, 2 Jun 2008 14:37:26 +0000 Subject: [PATCH] FIX #2231: add missing stack check when applying a PAP This program makes a PAP with 203 arguments :-) --- rts/Interpreter.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rts/Interpreter.c b/rts/Interpreter.c index ab59533..d541dfc 100644 --- a/rts/Interpreter.c +++ b/rts/Interpreter.c @@ -63,6 +63,7 @@ SpLim = cap->r.rCurrentTSO->stack + RESERVED_STACK_WORDS; #define SAVE_STACK_POINTERS \ + ASSERT(Sp > SpLim); \ cap->r.rCurrentTSO->sp = Sp #define RETURN_TO_SCHEDULER(todo,retcode) \ @@ -549,6 +550,16 @@ do_apply: goto defer_apply_to_sched; } + // Stack check: we're about to unpack the PAP onto the + // stack. The (+1) is for the (arity < n) case, where we + // also need space for an extra info pointer. + if (Sp - (pap->n_args + 1) < SpLim) { + Sp -= 2; + Sp[1] = (W_)tagged_obj; + Sp[0] = (W_)&stg_enter_info; + RETURN_TO_SCHEDULER(ThreadInterpret, StackOverflow); + } + Sp++; arity = pap->arity; ASSERT(arity > 0); -- 1.7.10.4