module scheme import arena import os import time fn close_pending_exit_without_storage(mut vm VM, machine &Machine, committed bool) { mut denied := arena.new(limits: arena.ChunkLimits{ max_live_bytes: 0 }) denied.push() defer { denied.pop() denied.free() } if committed { request := machine.abandon_process_exit_cleanup(mut vm, &vm_chunk_failure) assert request is ResourceLimitRequest } else { vm.cleanup_pending_exit_files(machine, &vm_chunk_failure) } } fn bounded_exit_cleanup_case(committed bool) ! { path := os.join_path(os.vtmp_dir(), 'vile-exit-quota-${os.getpid()}-${time.sys_mono_now()}') defer { os.rm(path) or {} } mut instance := new_bounded(Options{ max_open_files: 1 }, arena.ChunkLimits{ max_live_bytes: 8 * 1024 * 1024 })! defer { instance.close() or { panic(err) } } instance.eval('(define (saved) 42)')! assert instance.run(fn [path, committed] (mut vm VM) !Value { mut system := vm.system_state() system.exit_function = &process_exit_bridge_function vm.wind_transfer_function = &wind_transfer_bridge_function port := vm.open_output_file(path)! context := vm.next_context() entries := [cons(port, integer(i64(context)))] mut machine := Machine{ context: context } if committed { state := &ProcessExitCleanup{ request: ExitRequest{ status: 0 }, entries: entries, context: context } machine.function = &process_exit_cleanup_bridge machine.env = &Environment{ slots: [payload_value(.port_operation, state)] } } else { target := &Continuation{ owner: vm.owner, context: context, function: system.exit_function, stack: entries } machine.function = vm.wind_transfer_function machine.env = &Environment{ slots: [payload_value(.wind_plan, target), integer(0), payload_value(.wind_frame, unsafe { &WindFrame(nil) })] } } assert vm.owner.file_budget.used.load() == 1 close_pending_exit_without_storage(mut vm, &machine, committed) assert port.output_pointer().closed assert vm.owner.file_budget.used.load() == 0 assert vm.owner.bounded_files.interrupted == none return vm.call(vm.lookup('saved')!, []) })!.as_integer()! == 42 assert instance.eval('(saved)')!.as_integer()! == 42 } fn test_committed_exit_cleanup_closes_owned_files_under_zero_allocation_budget() { bounded_exit_cleanup_case(true)! } fn test_pending_exit_cleanup_closes_owned_files_under_zero_allocation_budget() { bounded_exit_cleanup_case(false)! }