subproc: comments
This commit is contained in:
parent
c3462e2529
commit
b1ca8dd1b5
18
subproc.c
18
subproc.c
@ -298,7 +298,11 @@ static int subprocCloneFunc(void *arg)
|
||||
longjmp(*env_ptr, 1);
|
||||
}
|
||||
|
||||
// Avoid problem with caching of PID/TID in glibc
|
||||
/*
|
||||
* Avoid problems with caching of PID/TID in glibc - when using syscall(__NR_clone) glibc will
|
||||
* not update internal PID/TID caches, which can lead to invalid values returned by getpid(),
|
||||
* or wrong PID/TIDs being used in raise()/abort() functions
|
||||
*/
|
||||
pid_t subprocClone(uintptr_t flags)
|
||||
{
|
||||
if (flags & CLONE_VM) {
|
||||
@ -308,11 +312,15 @@ pid_t subprocClone(uintptr_t flags)
|
||||
|
||||
jmp_buf env;
|
||||
if (setjmp(env) == 0) {
|
||||
void *stack_mid = &subprocCloneStack[sizeof(subprocCloneStack) / 2];
|
||||
// Parent
|
||||
return clone(subprocCloneFunc, stack_mid, flags, &env, NULL, NULL);
|
||||
/*
|
||||
* Avoid the problem of the stack growing up/down under different CPU architectures, by using
|
||||
* middle of the static stack buffer (which is temporary, and used only inside of subprocCloneFunc
|
||||
*/
|
||||
void *stack = &subprocCloneStack[sizeof(subprocCloneStack) / 2];
|
||||
/* Parent */
|
||||
return clone(subprocCloneFunc, stack, flags, &env, NULL, NULL);
|
||||
}
|
||||
// Child
|
||||
/* Child */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user