2011-02-12 00:22:29 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
#include "syscall.h"
|
2011-02-18 19:52:42 -05:00
|
|
|
#include "libc.h"
|
2011-03-09 20:23:44 -05:00
|
|
|
#include "pthread_impl.h"
|
2011-02-12 00:22:29 -05:00
|
|
|
|
|
|
|
pid_t fork(void)
|
|
|
|
{
|
2011-02-18 19:52:42 -05:00
|
|
|
pid_t ret;
|
|
|
|
if (libc.fork_handler) libc.fork_handler(-1);
|
2011-03-20 00:16:43 -04:00
|
|
|
ret = syscall(SYS_fork);
|
2011-04-20 21:41:45 -04:00
|
|
|
if (libc.main_thread && !ret) {
|
2011-03-09 20:23:44 -05:00
|
|
|
pthread_t self = __pthread_self();
|
2011-04-12 17:52:14 -04:00
|
|
|
self->tid = self->pid = syscall(SYS_getpid);
|
2011-07-16 23:17:17 -04:00
|
|
|
memset(&self->robust_list, 0, sizeof self->robust_list);
|
2011-03-09 20:23:44 -05:00
|
|
|
libc.threads_minus_1 = 0;
|
2011-04-20 21:41:45 -04:00
|
|
|
libc.main_thread = self;
|
2011-03-09 20:23:44 -05:00
|
|
|
}
|
2011-02-18 19:52:42 -05:00
|
|
|
if (libc.fork_handler) libc.fork_handler(!ret);
|
|
|
|
return ret;
|
2011-02-12 00:22:29 -05:00
|
|
|
}
|