Skip to content

Commit 73b3075

Browse files
authored
Consume fuel in array.new_default (bytecodealliance#11428)
This commit updates the Cranelift-generated loop for `array.new_default` to contain fuel/epoch checks. This ensures that large arrays have an opportunity to context-switch away or otherwise interrupt the program to prevent excessively long-running executions. cc bytecodealliance#11427 (does not solve it though)
1 parent e895dd9 commit 73b3075

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

crates/cranelift/src/func_environ/gc/enabled.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ fn emit_array_fill_impl(
607607
builder.switch_to_block(loop_header_block);
608608
builder.append_block_param(loop_header_block, pointer_ty);
609609
log::trace!("emit_array_fill_impl: loop header");
610+
func_env.translate_loop_header(builder)?;
610611
let elem_addr = builder.block_params(loop_header_block)[0];
611612
let done = builder.ins().icmp(IntCC::Equal, elem_addr, fill_end);
612613
builder

tests/all/fuel.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ fn iloop(config: &mut Config) -> Result<()> {
171171
)
172172
"#,
173173
)?;
174+
iloop_aborts(
175+
&config,
176+
r#"
177+
(module
178+
(type $a (array i8))
179+
(start 0)
180+
(func
181+
i32.const 0x400_0000
182+
array.new_default $a
183+
drop
184+
)
185+
)
186+
"#,
187+
)?;
174188

175189
fn iloop_aborts(config: &Config, wat: &str) -> Result<()> {
176190
let engine = Engine::new(&config)?;

0 commit comments

Comments
 (0)