From 8bfe43427dcbe15a18e538f300a7998d4a02e10b Mon Sep 17 00:00:00 2001 From: husky Date: Fri, 12 Sep 2025 20:51:50 -0700 Subject: [PATCH] turntbl now exits upon running a new program this should allow for users to take advantage of more system memory --- turntable/src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/turntable/src/main.rs b/turntable/src/main.rs index f8b613a..3e92f80 100644 --- a/turntable/src/main.rs +++ b/turntable/src/main.rs @@ -187,14 +187,16 @@ fn attempt_run_file(env: &Environment<'_>, name: &str) { current_directory_path: CURRENT_DIR_PATH.load(Ordering::Relaxed) as usize, current_directory_path_len: CURRENT_DIR_PATH_LEN.load(Ordering::Relaxed), }; + // fixme: turntable task needs to exit, but it owns the environment memory. + // fixme: we need to somehow pass the environment to the task, and have it free the memory let mut task_setup = liblbos::TaskSetup { epc: 0, stack_block_count: 8, ddi_first_addr: 0, ddi_size: 0, - environment: &e as *const _ as usize, - wait_for_task_exit: true, + environment: 0, + wait_for_task_exit: false, }; if liblbos::ktask::ktask_loadddifile(buf, size, &mut task_setup as *mut _ as usize) != 0 { @@ -207,11 +209,11 @@ fn attempt_run_file(env: &Environment<'_>, name: &str) { liblbos::syscalls::create_task(task_setup); - // yeah we're extending its lifetime - #[allow(clippy::drop_non_drop)] - drop(e); - - println("\ntask exited\n"); + if CURRENT_DIR_PATH.load(Ordering::Relaxed) as usize != 0 { + // free + liblbos::syscalls::free_blocks(CURRENT_DIR_PATH.load(Ordering::Relaxed) as usize, CURRENT_DIR_PATH_LEN.load(Ordering::Relaxed).div_ceil(512)); + } + liblbos::syscalls::exit(); } fn execute(cmd: &str, environment: &mut Environment<'_>) {