MCPcopy Create free account
hub / github.com/chyyuu/os_kernel_lab / sys_thread_create

Function sys_thread_create

os/src/syscall/thread.rs:8–43  ·  view source on GitHub ↗
(entry: usize, arg: usize)

Source from the content-addressed store, hash-verified

6use alloc::sync::Arc;
7
8pub fn sys_thread_create(entry: usize, arg: usize) -> isize {
9 let task = current_task().unwrap();
10 let process = task.process.upgrade().unwrap();
11 // create a new thread
12 let new_task = Arc::new(TaskControlBlock::new(
13 Arc::clone(&process),
14 task.inner_exclusive_access()
15 .res
16 .as_ref()
17 .unwrap()
18 .ustack_base,
19 true,
20 ));
21 // add new task to scheduler
22 add_task(Arc::clone(&new_task));
23 let new_task_inner = new_task.inner_exclusive_access();
24 let new_task_res = new_task_inner.res.as_ref().unwrap();
25 let new_task_tid = new_task_res.tid;
26 let mut process_inner = process.inner_exclusive_access();
27 // add new thread to current process
28 let tasks = &mut process_inner.tasks;
29 while tasks.len() < new_task_tid + 1 {
30 tasks.push(None);
31 }
32 tasks[new_task_tid] = Some(Arc::clone(&new_task));
33 let new_task_trap_cx = new_task_inner.get_trap_cx();
34 *new_task_trap_cx = TrapContext::app_init_context(
35 entry,
36 new_task_res.ustack_top(),
37 kernel_token(),
38 new_task.kstack.get_top(),
39 trap_handler as usize,
40 );
41 (*new_task_trap_cx).x[10] = arg;
42 new_task_tid as isize
43}
44
45pub fn sys_gettid() -> isize {
46 current_task()

Callers 1

syscallFunction · 0.70

Calls 10

current_taskFunction · 0.85
cloneFunction · 0.85
add_taskFunction · 0.85
kernel_tokenFunction · 0.85
lenMethod · 0.80
get_trap_cxMethod · 0.80
ustack_topMethod · 0.80
get_topMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected