diff options
author | Robert Swiecki <robert@swiecki.net> | 2019-01-30 19:09:41 +0100 |
---|---|---|
committer | Robert Swiecki <robert@swiecki.net> | 2019-01-30 19:09:41 +0100 |
commit | f6e0f9278d048a3b7bf43f0b277f1ea703cee4d1 (patch) | |
tree | 884aa0733c637510c745df5d7a15b1e0bf5ffc8d /netbsd | |
parent | 4bea130997ad2e28712e71881351db52c0a29df1 (diff) | |
download | honggfuzz-f6e0f9278d048a3b7bf43f0b277f1ea703cee4d1.tar.gz |
netbsd: some fixes for netbsd 8
Diffstat (limited to 'netbsd')
-rw-r--r-- | netbsd/arch.c | 10 | ||||
-rw-r--r-- | netbsd/trace.c | 23 |
2 files changed, 23 insertions, 10 deletions
diff --git a/netbsd/arch.c b/netbsd/arch.c index ed891358..7d79bd96 100644 --- a/netbsd/arch.c +++ b/netbsd/arch.c @@ -137,7 +137,9 @@ static bool arch_checkWait(run_t* run) { /* All queued wait events must be tested when SIGCHLD was delivered */ for (;;) { int status; - pid_t pid = TEMP_FAILURE_RETRY(waitpid(run->pid, &status, WALLSIG | WNOHANG)); + /* Wait for the whole process group of run->pid */ + pid_t pid = + TEMP_FAILURE_RETRY(wait4(-(run->pid), &status, WALLSIG | WNOHANG | WTRAPPED, NULL)); if (pid == 0) { return false; } @@ -146,7 +148,7 @@ static bool arch_checkWait(run_t* run) { return true; } if (pid == -1) { - PLOG_F("waitpid() failed"); + PLOG_F("wait4(pid=-%d) failed", (int)run->pid); } arch_traceAnalyze(run, status, pid); @@ -157,15 +159,13 @@ static bool arch_checkWait(run_t* run) { if (pid == run->pid && (WIFEXITED(status) || WIFSIGNALED(status))) { if (run->global->exe.persistent) { - if (fuzz_isTerminating() == false) { + if (!fuzz_isTerminating()) { LOG_W("Persistent mode: PID %d exited with status: %s", pid, subproc_StatusToStr(status, statusStr, sizeof(statusStr))); } } return true; } - - arch_traceAnalyze(run, status, pid); } } diff --git a/netbsd/trace.c b/netbsd/trace.c index 8d6537f9..fdb0a7dd 100644 --- a/netbsd/trace.c +++ b/netbsd/trace.c @@ -644,9 +644,11 @@ void arch_traceAnalyze(run_t* run, int status, pid_t pid) { } bool arch_traceWaitForPidStop(pid_t pid) { + LOG_D("Waiting for pid=%d to stop", (int)pid); + for (;;) { int status; - pid_t ret = wait4(pid, &status, __WALL | WUNTRACED, NULL); + pid_t ret = wait4(pid, &status, __WALL | WUNTRACED | WTRAPPED, NULL); if (ret == -1 && errno == EINTR) { continue; } @@ -658,20 +660,31 @@ bool arch_traceWaitForPidStop(pid_t pid) { LOG_W("PID %d not in a stopped state - status:%d", pid, status); return false; } + + LOG_D("pid=%d stopped", (int)pid); return true; } } bool arch_traceAttach(run_t* run) { - ptrace_event_t event; - + if (!arch_traceWaitForPidStop(run->pid)) { + return false; + } if (ptrace(PT_ATTACH, run->pid, NULL, 0) == -1) { PLOG_W("Couldn't ptrace(PT_ATTACH) to pid: %d", (int)run->pid); return false; } + if (!arch_traceWaitForPidStop(run->pid)) { + return false; + } - event.pe_set_event = PTRACE_FORK | PTRACE_VFORK | PTRACE_VFORK_DONE; - + ptrace_event_t event = { + /* + * NetBSD 8.0 seems to support PTRACE_FORK only: + * .pe_set_event = PTRACE_FORK | PTRACE_VFORK | PTRACE_VFORK_DONE, + */ + .pe_set_event = PTRACE_FORK, + }; if (ptrace(PT_SET_EVENT_MASK, run->pid, &event, sizeof(event)) == -1) { PLOG_W("Couldn't ptrace(PT_SET_EVENT_MASK) to pid: %d", (int)run->pid); return false; |