Closed KarthikNedunchezhiyan closed 3 years ago
It's safe. clone
creates process with virtual copy of memory. Then calls our function. That function eventually calls execve
which replaces the whole process's memory, and don't need the stack any more. The only case where that piece is deallocated is when this function exits, and this happens only in parent process (where this new stack is not used at all).
yeah, I missed noticing CLONE_VM
is not added in the clone
syscall. as like you said child is not sharing the parent VM so, it should not be an issue if the memory dropped in the parent.
In this line https://github.com/tailhook/unshare/blob/b441eff3ba78ee5078d4aead186c6ea043ac4fd3/src/run.rs#L228 part of current stack memory is allocated to child stack. Is this operation is safe? the current stack will be dropped at the end of the function call right? I am noob here, let me know if I misunderstood anything.