run file in env dir and pass env to new task
This commit is contained in:
parent
960de83bbc
commit
0b0a2afd6d
1 changed files with 14 additions and 4 deletions
|
|
@ -124,7 +124,7 @@ fn lsdir(env: &Environment<'_>) {
|
|||
print("\n");
|
||||
}
|
||||
|
||||
fn attempt_run_file(name: &str) {
|
||||
fn attempt_run_file(env: &Environment<'_>, name: &str) {
|
||||
print("\n");
|
||||
if name.len() > 11 {
|
||||
println("filename too long");
|
||||
|
|
@ -137,7 +137,7 @@ fn attempt_run_file(name: &str) {
|
|||
return;
|
||||
}
|
||||
let mut dir = DirectoryReader::empty();
|
||||
if liblbos::ktask::ktask_fsopendir(&fs, &mut dir, b"/") != 0 {
|
||||
if liblbos::ktask::ktask_fsopendir(&fs, &mut dir, env.current_directory_path) != 0 {
|
||||
println("failed to open dir");
|
||||
return;
|
||||
}
|
||||
|
|
@ -178,11 +178,17 @@ fn attempt_run_file(name: &str) {
|
|||
if liblbos::ktask::ktask_fsreadfile(&fs, &mut reader, unsafe { core::slice::from_raw_parts_mut(buf as *mut _, size) }) != 0 {
|
||||
println("failed to read file");
|
||||
}
|
||||
|
||||
let e = liblbos::Environment {
|
||||
current_directory_path: CURRENT_DIR_PATH.load(Ordering::Relaxed) as usize,
|
||||
current_directory_path_len: CURRENT_DIR_PATH_LEN.load(Ordering::Relaxed),
|
||||
};
|
||||
|
||||
let mut task_setup = liblbos::TaskSetup {
|
||||
epc: 0,
|
||||
ddi_first_addr: 0,
|
||||
ddi_size: 0,
|
||||
environment: 0,
|
||||
environment: &e as *const _ as usize,
|
||||
wait_for_task_exit: true,
|
||||
};
|
||||
|
||||
|
|
@ -196,6 +202,10 @@ fn attempt_run_file(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");
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +233,7 @@ fn execute(cmd: &str, environment: &mut Environment<'_>) {
|
|||
}
|
||||
}
|
||||
_ => {
|
||||
attempt_run_file(cmd);
|
||||
attempt_run_file(environment, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue