1
0
Fork 0

fix EINTR drop on child pipe read, publish active after memoryMap is populated

This commit is contained in:
3rdit 2026-04-16 01:32:29 +01:00
parent 44126f7709
commit 717650d514
No known key found for this signature in database
GPG Key ID: 7DD8A35AE190E434
3 changed files with 16 additions and 2 deletions

View File

@ -165,9 +165,9 @@ protected:
void cbCreateProcessEvent(const pid_t pid, const ElfBug::ptr ep) override
{
activePid.store(pid, std::memory_order_release);
active.store(true, std::memory_order_release);
entryPoint = ep;
refreshMemoryMap();
active.store(true, std::memory_order_release);
if(cb.onCreateProcess)
cb.onCreateProcess(pid, ep, cb.userdata);
}

View File

@ -34,6 +34,7 @@ namespace ElfBug
if(mStepPending.load(std::memory_order_acquire) && mThread)
{
mStepPending.store(false, std::memory_order_release);
// TODO: mPendingSignal is dropped here, decide the policy
mThread->StepInto();
}
else

View File

@ -4,6 +4,7 @@
#include <sys/personality.h>
#include <unistd.h>
#include <fcntl.h>
#include <cerrno>
#include <csignal>
#include <cstring>
@ -114,9 +115,21 @@ namespace ElfBug
close(pipeFds[1]);
char errBuf[256] = {};
const ssize_t n = read(pipeFds[0], errBuf, sizeof(errBuf) - 1);
ssize_t n;
do
{
n = read(pipeFds[0], errBuf, sizeof(errBuf) - 1);
} while(n == -1 && errno == EINTR);
close(pipeFds[0]);
if(n == -1)
{
const std::string err = strerror(errno);
waitpid(pid, nullptr, 0);
cbInternalError("read() from child pipe failed: " + err);
return false;
}
if(n > 0)
{
waitpid(pid, nullptr, 0);