Browse Source

Replace DUK_USE_DEEP_C_STACK with explicit limits

pull/297/head
Sami Vaarala 9 years ago
parent
commit
08c0457d80
  1. 6
      src/duk_bi_json.c
  2. 25
      src/duk_heap.h
  3. 2
      src/duk_heap_alloc.c
  4. 2
      src/duk_heap_markandsweep.c
  5. 2
      src/duk_js_compiler.c
  6. 5
      src/duk_js_compiler.h
  7. 9
      src/duk_json.h
  8. 10
      src/duk_regexp.h
  9. 2
      src/duk_regexp_compiler.c
  10. 2
      src/duk_regexp_executor.c

6
src/duk_bi_json.c

@ -2436,7 +2436,7 @@ void duk_bi_json_parse_helper(duk_context *ctx,
#ifdef DUK_USE_EXPLICIT_NULL_INIT
/* nothing now */
#endif
js_ctx->recursion_limit = DUK_JSON_DEC_RECURSION_LIMIT;
js_ctx->recursion_limit = DUK_USE_JSON_DEC_RECLIMIT;
DUK_ASSERT(js_ctx->recursion_depth == 0);
/* Flag handling currently assumes that flags are consistent. This is OK
@ -2745,7 +2745,7 @@ void duk_bi_json_stringify_helper(duk_context *ctx,
* slow path has a much larger recursion limit which we'll use if
* necessary.
*/
DUK_ASSERT(DUK_JSON_ENC_RECURSION_LIMIT >= DUK_JSON_ENC_LOOPARRAY);
DUK_ASSERT(DUK_USE_JSON_ENC_RECLIMIT >= DUK_JSON_ENC_LOOPARRAY);
js_ctx->recursion_limit = DUK_JSON_ENC_LOOPARRAY;
DUK_ASSERT(js_ctx->recursion_depth == 0);
@ -2812,7 +2812,7 @@ void duk_bi_json_stringify_helper(duk_context *ctx,
/* [ ... buf loop (proplist) (gap) holder "" ] */
js_ctx->recursion_limit = DUK_JSON_ENC_RECURSION_LIMIT;
js_ctx->recursion_limit = DUK_USE_JSON_ENC_RECLIMIT;
DUK_ASSERT(js_ctx->recursion_depth == 0);
undef = duk__enc_value1(js_ctx, idx_holder); /* [ ... holder key ] -> [ ... holder key val ] */

25
src/duk_heap.h

@ -92,31 +92,6 @@
* Other heap related defines
*/
/* Maximum duk_handle_call / duk_handle_safe_call depth. Note that this
* does not limit bytecode executor internal call depth at all (e.g.
* for Ecmascript-to-Ecmascript calls, thread yields/resumes, etc).
* There is a separate callstack depth limit for threads.
*/
#if defined(DUK_USE_DEEP_C_STACK)
#define DUK_HEAP_DEFAULT_CALL_RECURSION_LIMIT 1000 /* assuming 0.5 kB between calls, about 500kB of stack */
#else
#define DUK_HEAP_DEFAULT_CALL_RECURSION_LIMIT 60 /* assuming 0.5 kB between calls, about 30kB of stack */
#endif
/* Mark-and-sweep C recursion depth for marking phase; if reached,
* mark object as a TEMPROOT and use multi-pass marking.
*/
#if defined(DUK_USE_MARK_AND_SWEEP)
#if defined(DUK_USE_GC_TORTURE)
#define DUK_HEAP_MARK_AND_SWEEP_RECURSION_LIMIT 3
#elif defined(DUK_USE_DEEP_C_STACK)
#define DUK_HEAP_MARK_AND_SWEEP_RECURSION_LIMIT 256
#else
#define DUK_HEAP_MARK_AND_SWEEP_RECURSION_LIMIT 32
#endif
#endif
/* Mark-and-sweep interval is relative to combined count of objects and
* strings kept in the heap during the latest mark-and-sweep pass.
* Fixed point .8 multiplier and .0 adder. Trigger count (interval) is

2
src/duk_heap_alloc.c

@ -758,7 +758,7 @@ duk_heap *duk_heap_alloc(duk_alloc_function alloc_func,
/* res->mark_and_sweep_trigger_counter == 0 -> now causes immediate GC; which is OK */
res->call_recursion_depth = 0;
res->call_recursion_limit = DUK_HEAP_DEFAULT_CALL_RECURSION_LIMIT;
res->call_recursion_limit = DUK_USE_NATIVE_CALL_RECLIMIT;
/* XXX: use the pointer as a seed for now: mix in time at least */

2
src/duk_heap_markandsweep.c

@ -150,7 +150,7 @@ DUK_LOCAL void duk__mark_heaphdr(duk_heap *heap, duk_heaphdr *h) {
}
DUK_HEAPHDR_SET_REACHABLE(h);
if (heap->mark_and_sweep_recursion_depth >= DUK_HEAP_MARK_AND_SWEEP_RECURSION_LIMIT) {
if (heap->mark_and_sweep_recursion_depth >= DUK_USE_MARK_AND_SWEEP_RECLIMIT) {
/* log this with a normal debug level because this should be relatively rare */
DUK_D(DUK_DPRINT("mark-and-sweep recursion limit reached, marking as temproot: %p", (void *) h));
DUK_HEAP_SET_MARKANDSWEEP_RECLIMIT_REACHED(heap);

2
src/duk_js_compiler.c

@ -7540,7 +7540,7 @@ DUK_LOCAL duk_ret_t duk__js_compile_raw(duk_context *ctx) {
comp_ctx->tok12_idx = entry_top + 2;
comp_ctx->tok21_idx = entry_top + 3;
comp_ctx->tok22_idx = entry_top + 4;
comp_ctx->recursion_limit = DUK_COMPILER_RECURSION_LIMIT;
comp_ctx->recursion_limit = DUK_USE_COMPILER_RECLIMIT;
/* comp_ctx->lex has been pre-initialized by caller: it has been
* zeroed and input/input_length has been set.

5
src/duk_js_compiler.h

@ -6,11 +6,6 @@
#define DUK_JS_COMPILER_H_INCLUDED
/* ecmascript compiler limits */
#if defined(DUK_USE_DEEP_C_STACK)
#define DUK_COMPILER_RECURSION_LIMIT 2500L
#else
#define DUK_COMPILER_RECURSION_LIMIT 50L
#endif
#define DUK_COMPILER_TOKEN_LIMIT 100000000L /* 1e8: protects against deeply nested inner functions */
/* maximum loopcount for peephole optimization */

9
src/duk_json.h

@ -5,15 +5,6 @@
#ifndef DUK_JSON_H_INCLUDED
#define DUK_JSON_H_INCLUDED
/* Object/array recursion limit (to protect C stack) */
#if defined(DUK_USE_DEEP_C_STACK)
#define DUK_JSON_ENC_RECURSION_LIMIT 1000
#define DUK_JSON_DEC_RECURSION_LIMIT 1000
#else
#define DUK_JSON_ENC_RECURSION_LIMIT 100
#define DUK_JSON_DEC_RECURSION_LIMIT 100
#endif
/* Encoding/decoding flags */
#define DUK_JSON_FLAG_ASCII_ONLY (1 << 0) /* escape any non-ASCII characters */
#define DUK_JSON_FLAG_AVOID_KEY_QUOTES (1 << 1) /* avoid key quotes when key is an ASCII Identifier */

10
src/duk_regexp.h

@ -9,19 +9,9 @@
#define DUK_RE_MAX_ATOM_COPIES 1000
/* regexp compilation limits */
#if defined(DUK_USE_DEEP_C_STACK)
#define DUK_RE_COMPILE_RECURSION_LIMIT 10000
#else
#define DUK_RE_COMPILE_RECURSION_LIMIT 100
#endif
#define DUK_RE_COMPILE_TOKEN_LIMIT 100000000L /* 1e8 */
/* regexp execution limits */
#if defined(DUK_USE_DEEP_C_STACK)
#define DUK_RE_EXECUTE_RECURSION_LIMIT 10000
#else
#define DUK_RE_EXECUTE_RECURSION_LIMIT 100
#endif
#define DUK_RE_EXECUTE_STEPS_LIMIT 1000000000L /* 1e9 */
/* regexp opcodes */

2
src/duk_regexp_compiler.c

@ -942,7 +942,7 @@ DUK_INTERNAL void duk_regexp_compile(duk_hthread *thr) {
re_ctx.lex.input = DUK_HSTRING_GET_DATA(h_pattern);
re_ctx.lex.input_length = DUK_HSTRING_GET_BYTELEN(h_pattern);
re_ctx.lex.token_limit = DUK_RE_COMPILE_TOKEN_LIMIT;
re_ctx.recursion_limit = DUK_RE_COMPILE_RECURSION_LIMIT;
re_ctx.recursion_limit = DUK_USE_REGEXP_COMPILER_RECLIMIT;
re_ctx.re_flags = duk__parse_regexp_flags(thr, h_flags);
DUK_BW_INIT_PUSHBUF(thr, &re_ctx.bw, DUK__RE_INITIAL_BUFSIZE);

2
src/duk_regexp_executor.c

@ -718,7 +718,7 @@ DUK_LOCAL void duk__regexp_match_helper(duk_hthread *thr, duk_small_int_t force_
re_ctx.bytecode = (duk_uint8_t *) DUK_HSTRING_GET_DATA(h_bytecode);
re_ctx.bytecode_end = re_ctx.bytecode + DUK_HSTRING_GET_BYTELEN(h_bytecode);
re_ctx.saved = NULL;
re_ctx.recursion_limit = DUK_RE_EXECUTE_RECURSION_LIMIT;
re_ctx.recursion_limit = DUK_USE_REGEXP_EXECUTOR_RECLIMIT;
re_ctx.steps_limit = DUK_RE_EXECUTE_STEPS_LIMIT;
/* read header */

Loading…
Cancel
Save