Skip to content

Commit 6149bc7

Browse files
committed
feat(clone): add SIGHAND
1 parent ddf0c2e commit 6149bc7

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/src/imp/signal.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,13 @@ pub fn sys_rt_sigaction(
116116
}
117117

118118
let curr = current();
119-
curr.task_ext()
120-
.process_data()
121-
.signal
122-
.with_action_mut::<LinuxResult<_>>(signo, |action| {
123-
if let Some(oldact) = oldact.nullable(UserPtr::get)? {
124-
action.to_ctype(unsafe { &mut *oldact });
125-
}
126-
if let Some(act) = act.nullable(UserConstPtr::get)? {
127-
*action = unsafe { (*act).try_into()? };
128-
}
129-
Ok(())
130-
})?;
131-
119+
let mut actions = curr.task_ext().process_data().signal.actions.lock();
120+
if let Some(oldact) = oldact.nullable(UserPtr::get)? {
121+
actions[signo].to_ctype(unsafe { &mut *oldact });
122+
}
123+
if let Some(act) = act.nullable(UserConstPtr::get)? {
124+
actions[signo] = unsafe { (*act).try_into()? };
125+
}
132126
Ok(0)
133127
}
134128

api/src/imp/task/clone.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ bitflags! {
8383
}
8484
}
8585

86+
// TODO: CLEAR_SIGHAND in clone3
87+
8688
#[apply(syscall_instrument)]
8789
pub fn sys_clone(
8890
flags: u32,
@@ -151,17 +153,16 @@ pub fn sys_clone(
151153

152154
curr.task_ext().thread.process()
153155
} else {
154-
// create a new process
155-
let builder = if flags.contains(CloneFlags::PARENT) {
156+
let parent = if flags.contains(CloneFlags::PARENT) {
156157
curr.task_ext()
157158
.thread
158159
.process()
159160
.parent()
160161
.ok_or(LinuxError::EINVAL)?
161-
.fork(tid)
162162
} else {
163-
curr.task_ext().thread.process().fork(tid)
163+
curr.task_ext().thread.process().clone()
164164
};
165+
let builder = parent.fork(tid);
165166

166167
let aspace = if flags.contains(CloneFlags::VM) {
167168
curr.task_ext().process_data().aspace.clone()
@@ -175,9 +176,17 @@ pub fn sys_clone(
175176
.ctx_mut()
176177
.set_page_table_root(aspace.lock().page_table_root());
177178

179+
let signal_actions = if flags.contains(CloneFlags::SIGHAND) {
180+
parent
181+
.data::<ProcessData>()
182+
.map_or_else(Arc::default, |it| it.signal.actions.clone())
183+
} else {
184+
Arc::default()
185+
};
178186
let process_data = ProcessData::new(
179187
curr.task_ext().process_data().exe_path.read().clone(),
180188
aspace,
189+
signal_actions,
181190
exit_signal,
182191
);
183192

core/src/task.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use axns::{AxNamespace, AxNamespaceIf};
2020
use axprocess::{Pid, Process, ProcessGroup, Session, Thread};
2121
use axsignal::{
2222
Signo,
23-
api::{ProcessSignalManager, ThreadSignalManager},
23+
api::{ProcessSignalManager, SignalActions, ThreadSignalManager},
2424
};
2525
use axsync::{Mutex, RawMutex};
2626
use axtask::{TaskExtRef, TaskInner, WaitQueue, current};
@@ -196,7 +196,12 @@ pub struct ProcessData {
196196
}
197197

198198
impl ProcessData {
199-
pub fn new(exe_path: String, aspace: Arc<Mutex<AddrSpace>>, exit_signal: Option<Signo>) -> Self {
199+
pub fn new(
200+
exe_path: String,
201+
aspace: Arc<Mutex<AddrSpace>>,
202+
signal_actions: Arc<Mutex<SignalActions>>,
203+
exit_signal: Option<Signo>,
204+
) -> Self {
200205
Self {
201206
exe_path: RwLock::new(exe_path),
202207
aspace,
@@ -207,7 +212,10 @@ impl ProcessData {
207212
child_exit_wq: WaitQueue::new(),
208213
exit_signal,
209214

210-
signal: Arc::new(ProcessSignalManager::new(axconfig::plat::SIGNAL_TRAMPOLINE)),
215+
signal: Arc::new(ProcessSignalManager::new(
216+
signal_actions,
217+
axconfig::plat::SIGNAL_TRAMPOLINE,
218+
)),
211219
}
212220
}
213221

src/entry.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ pub fn run_user_app(args: &[String], envs: &[String]) -> Option<i32> {
3131
let mut task = new_user_task(name, uctx, None);
3232
task.ctx_mut().set_page_table_root(uspace.page_table_root());
3333

34-
let process_data =
35-
ProcessData::new(exe_path, Arc::new(Mutex::new(uspace)), Some(Signo::SIGCHLD));
34+
let process_data = ProcessData::new(
35+
exe_path,
36+
Arc::new(Mutex::new(uspace)),
37+
Arc::default(),
38+
Some(Signo::SIGCHLD),
39+
);
3640

3741
FD_TABLE
3842
.deref_from(&process_data.ns)

0 commit comments

Comments
 (0)