MCPcopy Create free account
hub / github.com/Starry-OS/StarryOS / run_initproc

Function run_initproc

src/entry.rs:17–70  ·  view source on GitHub ↗
(args: &[String], envs: &[String])

Source from the content-addressed store, hash-verified

15use starry_process::{Pid, Process};
16
17pub fn run_initproc(args: &[String], envs: &[String]) -> i32 {
18 let mut uspace = new_user_aspace_empty()
19 .and_then(|mut it| {
20 copy_from_kernel(&mut it)?;
21 Ok(it)
22 })
23 .expect("Failed to create user address space");
24
25 let loc = FS_CONTEXT
26 .lock()
27 .resolve(&args[0])
28 .expect("Failed to resolve executable path");
29 let path = loc
30 .absolute_path()
31 .expect("Failed to get executable absolute path");
32 let name = loc.name();
33
34 let (entry_vaddr, ustack_top) = load_user_app(&mut uspace, None, args, envs)
35 .unwrap_or_else(|e| panic!("Failed to load user app: {}", e));
36
37 let uctx = UserContext::new(entry_vaddr.into(), ustack_top, 0);
38
39 let mut task = new_user_task(name, uctx, 0);
40 task.ctx_mut().set_page_table_root(uspace.page_table_root());
41
42 let pid = task.id().as_u64() as Pid;
43 let proc = Process::new_init(pid);
44 proc.add_thread(pid);
45
46 N_TTY.bind_to(&proc).expect("Failed to bind ntty");
47
48 let proc_data = ProcessData::new(
49 proc,
50 path.to_string(),
51 Arc::new(args.to_vec()),
52 Arc::new(Mutex::new(uspace)),
53 Arc::default(),
54 None,
55 );
56 {
57 let mut scope = proc_data.scope.write();
58 starry_api::file::add_stdio(&mut FD_TABLE.scope_mut(&mut scope).write())
59 .expect("Failed to add stdio");
60 }
61 let thr = Thread::new(pid, proc_data);
62
63 *task.task_ext_mut() = Some(unsafe { AxTaskExt::from_impl(thr) });
64
65 let task = spawn_task(task);
66 add_task_to_table(&task);
67
68 // TODO: wait for all processes to finish
69 task.join()
70}

Callers 1

mainFunction · 0.85

Calls 9

new_user_aspace_emptyFunction · 0.85
copy_from_kernelFunction · 0.85
load_user_appFunction · 0.85
new_user_taskFunction · 0.85
add_stdioFunction · 0.85
add_task_to_tableFunction · 0.85
bind_toMethod · 0.80
nameMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected