Skip to content

Commit 759a887

Browse files
fix: inherit heap on fork and reset set_child_tid on execve (#93)
Co-authored-by: sunhaosheng <sunhaosheng@kylinos.cn>
1 parent 6a4e0be commit 759a887

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

api/src/syscall/task/clone.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ pub fn sys_clone(
182182
exit_signal,
183183
);
184184
proc_data.set_umask(old_proc_data.umask());
185+
// Inherit heap pointers from parent to ensure child's heap state is consistent after fork
186+
proc_data.set_heap_bottom(old_proc_data.get_heap_bottom());
187+
proc_data.set_heap_top(old_proc_data.get_heap_top());
185188

186189
{
187190
let mut scope = proc_data.scope.write();

api/src/syscall/task/execve.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ pub fn sys_execve(
6565

6666
*proc_data.signal.actions.lock() = Default::default();
6767

68+
// Clear set_child_tid after exec since the original address is no longer valid
69+
curr.as_thread().set_clear_child_tid(0);
70+
6871
// Close CLOEXEC file descriptors
6972
let mut fd_table = FD_TABLE.write();
7073
let cloexec_fds = fd_table

api/src/task.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn new_user_task(
3333
TaskInner::new(
3434
move || {
3535
let curr = axtask::current();
36+
3637
access_user_memory(|| {
3738
if let Some(tid) = set_child_tid {
3839
*tid = curr.id().as_u64() as Pid;

0 commit comments

Comments
 (0)