]> xenbits.xensource.com Git - people/liuw/freebsd.git/commitdiff
Add a way to distinguish between forking and thread creation in schedtail.
authored <ed@FreeBSD.org>
Thu, 22 Oct 2015 09:33:34 +0000 (09:33 +0000)
committered <ed@FreeBSD.org>
Thu, 22 Oct 2015 09:33:34 +0000 (09:33 +0000)
For CloudABI we need to initialize the registers of new threads
differently based on whether the thread got created through a fork or
through simple thread creation.

Add a flag, TDP_FORKING, that is set by do_fork() and cleared by
fork_exit(). This can be tested against in schedtail.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D3973

sys/kern/kern_fork.c
sys/kern/subr_syscall.c
sys/sys/proc.h

index bb35b9b25d8ffb8b48c6ff2f89465fae650ba746..1b556be41d016f90a4989a0c523ea2befcc27e82 100644 (file)
@@ -586,7 +586,7 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2,
         * been preserved.
         */
        p2->p_flag |= p1->p_flag & P_SUGID;
-       td2->td_pflags |= td->td_pflags & TDP_ALTSTACK;
+       td2->td_pflags |= (td->td_pflags & TDP_ALTSTACK) | TDP_FORKING;
        SESS_LOCK(p1->p_session);
        if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
                p2->p_flag |= P_CONTROLT;
@@ -1023,6 +1023,7 @@ fork_exit(void (*callout)(void *, struct trapframe *), void *arg,
 
        if (p->p_sysent->sv_schedtail != NULL)
                (p->p_sysent->sv_schedtail)(td);
+       td->td_pflags &= ~TDP_FORKING;
 }
 
 /*
index 71f3d599836758f6fb34900d5dd6f06ea80d543f..c0763262f74ba504206b14c2d3bf3a7b3d46b8e4 100644 (file)
@@ -176,6 +176,9 @@ syscallret(struct thread *td, int error, struct syscall_args *sa)
        struct proc *p, *p2;
        int traced;
 
+       KASSERT((td->td_pflags & TDP_FORKING) == 0,
+           ("fork() did not clear TDP_FORKING upon completion"));
+
        p = td->td_proc;
 
        /*
index 5e8acc6147caba46498bac52d3fb775d3b45d966..eff28b40365bed4fc34fca43fe02b4ad4b642001 100644 (file)
@@ -446,7 +446,7 @@ do {                                                                        \
 #define        TDP_RESETSPUR   0x04000000 /* Reset spurious page fault history. */
 #define        TDP_NERRNO      0x08000000 /* Last errno is already in td_errno */
 #define        TDP_UIOHELD     0x10000000 /* Current uio has pages held in td_ma */
-#define        TDP_UNUSED29    0x20000000 /* --available-- */
+#define        TDP_FORKING     0x20000000 /* Thread is being created through fork() */
 #define        TDP_EXECVMSPC   0x40000000 /* Execve destroyed old vmspace */
 
 /*