Unify time limits for all three archs. Remove rlimits/setitimer
diff --git a/linux/arch.c b/linux/arch.c
index 83502d3..51e1e91 100644
--- a/linux/arch.c
+++ b/linux/arch.c
@@ -228,18 +228,6 @@
     return true;
 }
 
-static void arch_checkTimeLimit(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
-{
-    int64_t curMillis = util_timeNowMillis();
-    int64_t diffMillis = curMillis - fuzzer->timeStartedMillis;
-    if (diffMillis > (hfuzz->tmOut * 1000)) {
-        LOG_W("PID %d took too much time (limit %ld s). Sending SIGKILL",
-              fuzzer->pid, hfuzz->tmOut);
-        kill(fuzzer->pid, SIGKILL);
-        ATOMIC_POST_INC(hfuzz->timeoutedCnt);
-    }
-}
-
 void arch_prepareChild(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
 {
     pid_t ptracePid = (hfuzz->linux.pid > 0) ? hfuzz->linux.pid : fuzzer->pid;
@@ -300,9 +288,7 @@
         int status;
         pid_t pid = wait4(-1, &status, __WALL | __WNOTHREAD, NULL);
         if (pid == -1 && errno == EINTR) {
-            if (hfuzz->tmOut) {
-                arch_checkTimeLimit(hfuzz, fuzzer);
-            }
+            subproc_checkTimeLimit(hfuzz, fuzzer);
             continue;
         }
         if (pid == -1 && errno == ECHILD) {
diff --git a/mac/arch.c b/mac/arch.c
index 8369ef1..5a620ab 100644
--- a/mac/arch.c
+++ b/mac/arch.c
@@ -362,31 +362,12 @@
     return false;
 }
 
-static void arch_checkTimeLimit(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
-{
-    if (!hfuzz->tmOut) {
-        return;
-    }
-    int64_t curMillis = util_timeNowMillis();
-    int64_t diffMillis = curMillis - fuzzer->timeStartedMillis;
-    if (diffMillis > ((hfuzz->tmOut + 2) * 1000)) {
-        LOG_W("PID %d took too much time (limit %ld s). Sending SIGKILL",
-              fuzzer->pid, hfuzz->tmOut);
-        kill(fuzzer->pid, SIGKILL);
-    }
-}
-
-void arch_prepareChild(honggfuzz_t * hfuzz UNUSED, fuzzer_t * fuzzer UNUSED)
-{
-
-}
-
 void arch_reapChild(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
 {
     /*
      * First check manually if we have expired children
      */
-    arch_checkTimeLimit(hfuzz, fuzzer);
+    subproc_checkTimeLimit(hfuzz, fuzzer);
 
     /*
      * Now check for signals using wait4
@@ -400,7 +381,7 @@
         int status = 0;
         while (wait4(fuzzer->pid, &status, options, NULL) != fuzzer->pid) {
             if (hfuzz->tmOut) {
-                arch_checkTimeLimit(hfuzz, fuzzer);
+                subproc_checkTimeLimit(hfuzz, fuzzer);
                 usleep(0.20 * 1000000);
             }
         }
diff --git a/posix/arch.c b/posix/arch.c
index 7d4c769..90dbc6f 100644
--- a/posix/arch.c
+++ b/posix/arch.c
@@ -180,6 +180,8 @@
 void arch_reapChild(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
 {
     for (;;) {
+        subproc_checkTimeLimit(hfuzz, fuzzer);
+
         if (hfuzz->persistent) {
             struct pollfd pfd = {
                 .fd = fuzzer->persistentSock,
diff --git a/subproc.c b/subproc.c
index a267c86..5d6e4a5 100644
--- a/subproc.c
+++ b/subproc.c
@@ -127,51 +127,6 @@
 bool subproc_PrepareExecv(honggfuzz_t * hfuzz, fuzzer_t * fuzzer, const char *fileName)
 {
     /*
-     * Set timeout (prof), real timeout (2*prof), and rlimit_cpu (2*prof)
-     */
-    if (hfuzz->persistent == false && hfuzz->tmOut) {
-        struct itimerval it;
-
-        /*
-         * The hfuzz->tmOut is real CPU usage time...
-         */
-        it.it_value.tv_sec = hfuzz->tmOut;
-        it.it_value.tv_usec = 0;
-        it.it_interval.tv_sec = 0;
-        it.it_interval.tv_usec = 0;
-        if (setitimer(ITIMER_PROF, &it, NULL) == -1) {
-            PLOG_D("Couldn't set the ITIMER_PROF timer");
-        }
-
-        /*
-         * ...so, if a process sleeps, this one should
-         * trigger a signal...
-         */
-        it.it_value.tv_sec = hfuzz->tmOut;
-        it.it_value.tv_usec = 0;
-        it.it_interval.tv_sec = 0;
-        it.it_interval.tv_usec = 0;
-        if (setitimer(ITIMER_REAL, &it, NULL) == -1) {
-            PLOG_E("Couldn't set the ITIMER_REAL timer");
-            return false;
-        }
-
-        /*
-         * ..if a process sleeps and catches SIGPROF/SIGALRM
-         * rlimits won't help either. However, arch_checkTimeLimit
-         * will send a SIGKILL at tmOut + 2 seconds. That should
-         * do it :)
-         */
-        struct rlimit rl;
-
-        rl.rlim_cur = hfuzz->tmOut + 1;
-        rl.rlim_max = hfuzz->tmOut + 1;
-        if (setrlimit(RLIMIT_CPU, &rl) == -1) {
-            PLOG_D("Couldn't enforce the RLIMIT_CPU resource limit");
-        }
-    }
-
-    /*
      * The address space limit. If big enough - roughly the size of RAM used
      */
     if (hfuzz->asLimit) {
@@ -362,3 +317,19 @@
 
     return 0U;
 }
+
+void subproc_checkTimeLimit(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
+{
+    if (hfuzz->tmOut == 0) {
+        return;
+    }
+
+    int64_t curMillis = util_timeNowMillis();
+    int64_t diffMillis = curMillis - fuzzer->timeStartedMillis;
+    if (diffMillis > (hfuzz->tmOut * 1000)) {
+        LOG_W("PID %d took too much time (limit %ld s). Sending SIGKILL",
+              fuzzer->pid, hfuzz->tmOut);
+        kill(fuzzer->pid, SIGKILL);
+        ATOMIC_POST_INC(hfuzz->timeoutedCnt);
+    }
+}
diff --git a/subproc.h b/subproc.h
index f683f20..8f1a81d 100644
--- a/subproc.h
+++ b/subproc.h
@@ -46,4 +46,6 @@
 
 extern uint8_t subproc_System(const char *const argv[]);
 
+extern void subproc_checkTimeLimit(honggfuzz_t * hfuzz, fuzzer_t * fuzzer);
+
 #endif