Merge "misc: Merge branch 'release-staging-v21-1' into develop" into develop

This commit is contained in:
Jason Lowe-Power
2021-07-30 04:44:09 +00:00
15 changed files with 377 additions and 50 deletions

View File

@@ -174,6 +174,9 @@ Process::clone(ThreadContext *otc, ThreadContext *ntc,
#endif
#ifndef CLONE_THREAD
#define CLONE_THREAD 0
#endif
#ifndef CLONE_VFORK
#define CLONE_VFORK 0
#endif
if (CLONE_VM & flags) {
/**
@@ -249,6 +252,10 @@ Process::clone(ThreadContext *otc, ThreadContext *ntc,
np->exitGroup = exitGroup;
}
if (CLONE_VFORK & flags) {
np->vforkContexts.push_back(otc->contextId());
}
np->argv.insert(np->argv.end(), argv.begin(), argv.end());
np->envp.insert(np->envp.end(), envp.begin(), envp.end());
}

View File

@@ -284,6 +284,9 @@ class Process : public SimObject
// Process was forked with SIGCHLD set.
bool *sigchld;
// Contexts to wake up when this thread exits or calls execve
std::vector<ContextID> vforkContexts;
// Track how many system calls are executed
statistics::Scalar numSyscalls;
};

View File

@@ -194,6 +194,16 @@ exitImpl(SyscallDesc *desc, ThreadContext *tc, bool group, int status)
}
}
/**
* If we were a thread created by a clone with vfork set, wake up
* the thread that created us
*/
if (!p->vforkContexts.empty()) {
ThreadContext *vtc = sys->threads[p->vforkContexts.front()];
assert(vtc->status() == ThreadContext::Suspended);
vtc->activate();
}
tc->halt();
/**

View File

@@ -1453,6 +1453,7 @@ cloneFunc(SyscallDesc *desc, ThreadContext *tc, RegVal flags, RegVal newStack,
pp->euid = p->euid();
pp->gid = p->gid();
pp->egid = p->egid();
pp->release = p->release;
/* Find the first free PID that's less than the maximum */
std::set<int> const& pids = p->system->PIDs;
@@ -1521,6 +1522,10 @@ cloneFunc(SyscallDesc *desc, ThreadContext *tc, RegVal flags, RegVal newStack,
ctc->pcState(cpc);
ctc->activate();
if (flags & OS::TGT_CLONE_VFORK) {
tc->suspend();
}
return cp->pid();
}
@@ -1997,6 +2002,16 @@ execveFunc(SyscallDesc *desc, ThreadContext *tc,
}
};
/**
* If we were a thread created by a clone with vfork set, wake up
* the thread that created us
*/
if (!p->vforkContexts.empty()) {
ThreadContext *vtc = p->system->threads[p->vforkContexts.front()];
assert(vtc->status() == ThreadContext::Suspended);
vtc->activate();
}
/**
* Note that ProcessParams is generated by swig and there are no other
* examples of how to create anything but this default constructor. The
@@ -2018,6 +2033,7 @@ execveFunc(SyscallDesc *desc, ThreadContext *tc,
pp->errout.assign("cerr");
pp->cwd.assign(p->tgtCwd);
pp->system = p->system;
pp->release = p->release;
/**
* Prevent process object creation with identical PIDs (which will trip
* a fatal check in Process constructor). The execve call is supposed to
@@ -2028,7 +2044,9 @@ execveFunc(SyscallDesc *desc, ThreadContext *tc,
*/
p->system->PIDs.erase(p->pid());
Process *new_p = pp->create();
delete pp;
// TODO: there is no way to know when the Process SimObject is done with
// the params pointer. Both the params pointer (pp) and the process
// pointer (p) are normally managed in python and are never cleaned up.
/**
* Work through the file descriptor array and close any files marked
@@ -2043,10 +2061,10 @@ execveFunc(SyscallDesc *desc, ThreadContext *tc,
*new_p->sigchld = true;
delete p;
tc->clearArchRegs();
tc->setProcessPtr(new_p);
new_p->assignThreadContext(tc->contextId());
new_p->init();
new_p->initState();
tc->activate();
TheISA::PCState pcState = tc->pcState();