From b1fa4fd88a7e9b191254eb2f1e854d50b98e913d Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Wed, 7 Aug 2024 18:31:32 +0200 Subject: [PATCH] wasm: prevent macros from mutating functions --- impls/wasm/step8_macros.wam | 7 +++++-- impls/wasm/step9_try.wam | 7 +++++-- impls/wasm/stepA_mal.wam | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/impls/wasm/step8_macros.wam b/impls/wasm/step8_macros.wam index f8e58d3760..d50a5014e0 100644 --- a/impls/wasm/step8_macros.wam +++ b/impls/wasm/step8_macros.wam @@ -293,12 +293,15 @@ (then (local.set $a1 ($MAL_GET_A1 $ast)) (local.set $a2 ($MAL_GET_A2 $ast)) - (local.set $res ($EVAL $a2 $env)) + (local.set $f ($EVAL $a2 $env)) + (local.set $res ($MALFUNC ($MEM_VAL0_ptr $f) + ($MEM_VAL1_ptr $f) ($MEM_VAL2_ptr $f))) ($SET_TYPE $res (global.get $MACRO_T)) (br_if $EVAL_return (global.get $error_type)) + ($RELEASE $f) ;; set a1 in env to a2 - (local.set $res ($ENV_SET $env $a1 $res)) + (drop ($ENV_SET $env $a1 $res)) (br $EVAL_return)) ) (if (i32.eqz ($strcmp "if" $a0sym)) diff --git a/impls/wasm/step9_try.wam b/impls/wasm/step9_try.wam index 9ac89481d0..486906c2f8 100644 --- a/impls/wasm/step9_try.wam +++ b/impls/wasm/step9_try.wam @@ -293,12 +293,15 @@ (then (local.set $a1 ($MAL_GET_A1 $ast)) (local.set $a2 ($MAL_GET_A2 $ast)) - (local.set $res ($EVAL $a2 $env)) + (local.set $f ($EVAL $a2 $env)) + (local.set $res ($MALFUNC ($MEM_VAL0_ptr $f) + ($MEM_VAL1_ptr $f) ($MEM_VAL2_ptr $f))) ($SET_TYPE $res (global.get $MACRO_T)) (br_if $EVAL_return (global.get $error_type)) + ($RELEASE $f) ;; set a1 in env to a2 - (local.set $res ($ENV_SET $env $a1 $res)) + (drop ($ENV_SET $env $a1 $res)) (br $EVAL_return)) ) (if (i32.eqz ($strcmp "try*" $a0sym)) diff --git a/impls/wasm/stepA_mal.wam b/impls/wasm/stepA_mal.wam index 5276d26f40..9cd6dcdfd0 100644 --- a/impls/wasm/stepA_mal.wam +++ b/impls/wasm/stepA_mal.wam @@ -293,12 +293,15 @@ (then (local.set $a1 ($MAL_GET_A1 $ast)) (local.set $a2 ($MAL_GET_A2 $ast)) - (local.set $res ($EVAL $a2 $env)) + (local.set $f ($EVAL $a2 $env)) + (local.set $res ($MALFUNC ($MEM_VAL0_ptr $f) + ($MEM_VAL1_ptr $f) ($MEM_VAL2_ptr $f))) ($SET_TYPE $res (global.get $MACRO_T)) (br_if $EVAL_return (global.get $error_type)) + ($RELEASE $f) ;; set a1 in env to a2 - (local.set $res ($ENV_SET $env $a1 $res)) + (drop ($ENV_SET $env $a1 $res)) (br $EVAL_return)) ) (if (i32.eqz ($strcmp "try*" $a0sym))