Loading...
testing/lib/test_support.cpp dyld-1042.1 dyld-852
--- dyld/dyld-1042.1/testing/lib/test_support.cpp
+++ dyld/dyld-852/testing/lib/test_support.cpp
@@ -27,10 +27,6 @@
 #include <utility>
 #include <algorithm>
 
-#ifndef _POSIX_SPAWN_FORCE_4K_PAGES
-#define _POSIX_SPAWN_FORCE_4K_PAGES 0x1000
-#endif /* _POSIX_SPAWN_FORCE_4K_PAGES */
-
 extern "C" {
 #include "execserverServer.h"
 
@@ -131,9 +127,9 @@
 struct TestState {
     TestState();
     static TestState* getState();
-    void _PASSV(const char* file, unsigned line, const char* format, va_list args) __attribute__ ((noreturn, format(printf, 4, 0)));
-    void _FAILV(const char* file, unsigned line, const char* format, va_list args) __attribute__ ((noreturn, format(printf, 4, 0)));
-    void _LOGV(const char* file, unsigned line, const char* format, va_list args) __attribute__ ((format(printf, 4, 0)));
+    void _PASSV(const char* file, unsigned line, const char* format, va_list args) __attribute__ ((noreturn));
+    void _FAILV(const char* file, unsigned line, const char* format, va_list args) __attribute__ ((noreturn));
+    void _LOGV(const char* file, unsigned line, const char* format, va_list args);
     GrowableArray<std::pair<mach_port_t, _dyld_test_crash_handler_t>>& getCrashHandlers();
 private:
     enum OutputStyle {
@@ -230,7 +226,7 @@
 }
 
 _process::_process() :  executablePath(nullptr), args(nullptr), env(nullptr), stdoutHandler(nullptr), stderrHandler(nullptr),
-                        crashHandler(nullptr), exitHandler(nullptr), arch(currentArch), suspended(false), altPageSize(false), pid(0) {}
+                        crashHandler(nullptr), exitHandler(nullptr), pid(0), arch(currentArch), suspended(false) {}
 _process::~_process() {
     if (stdoutHandler) { Block_release(stdoutHandler);}
     if (stderrHandler) { Block_release(stderrHandler);}
@@ -246,30 +242,22 @@
 void _process::set_exit_handler(_dyld_test_exit_handler_t EH) { exitHandler = Block_copy(EH); }
 void _process::set_crash_handler(_dyld_test_crash_handler_t CH) { crashHandler = Block_copy(CH); }
 void _process::set_launch_suspended(bool S) { suspended = S; }
-void _process::set_alt_page_size(bool PS) { altPageSize = PS; }
 void _process::set_launch_arch(cpu_type_t A) { arch = A; }
-pid_t _process::get_pid() const { return pid; }
 
 pid_t _process::launch() {
     dispatch_queue_t queue = dispatch_queue_create("com.apple.dyld.test.launch", NULL);
-    dispatch_block_t oneShotSemaphoreBlock = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{});
     posix_spawn_file_actions_t fileActions = NULL;
     posix_spawnattr_t attr = NULL;
     dispatch_source_t stdoutSource = NULL;
     dispatch_source_t stderrSource = NULL;
     int stdoutPipe[2];
     int stderrPipe[2];
-    int flags = POSIX_SPAWN_START_SUSPENDED;
-
-    if (altPageSize) {
-        flags |= _POSIX_SPAWN_FORCE_4K_PAGES;
-    }
 
     if (posix_spawn_file_actions_init(&fileActions) != 0) {
         FAIL("Setting up spawn filea actions");
     }
     if (posix_spawnattr_init(&attr) != 0) { FAIL("Setting up spawn attr"); }
-    if (posix_spawnattr_setflags(&attr, flags) != 0) {
+    if (posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED) != 0) {
         FAIL("Setting up spawn attr: POSIX_SPAWN_START_SUSPENDED");
     }
 
@@ -341,6 +329,7 @@
         dispatch_resume(crashSource);
     }
 
+    pid_t pid;
     uint32_t argc = 0;
     if (args) {
         for (argc = 0; args[argc] != NULL; ++argc) {}
@@ -370,7 +359,6 @@
         if (stderrSource) {
             dispatch_source_cancel(stderrSource);
         }
-        oneShotSemaphoreBlock();
         dispatch_source_cancel(exitSource);
     });
     dispatch_resume(exitSource);
@@ -388,7 +376,6 @@
     if (!suspended) {
         kill(pid, SIGCONT);
     }
-    Block_release(oneShotSemaphoreBlock);
     dispatch_release(queue);
     return pid;
 }
@@ -513,7 +500,7 @@
         if (checkForLeaks) {
             printf(" MallocStackLogging=1 MallocDebugReport=none");
         }
-        forEachEnvVar(environ, [](const char* env, const char* val) {
+        forEachEnvVar(environ, [this](const char* env, const char* val) {
             if ((strncmp(env, "DYLD_", 5) == 0) || (strncmp(env, "TEST_", 5) == 0)) {
                 printf(" %s=%s", env, val);
             }
@@ -561,18 +548,18 @@
                 }
             }
             sState.store(*state);
-            break; // don't print [BEGIN] if a second main executeable is dlopen()ed
         }
     }
     assert(sState != nullptr);
     return sState;
 }
+
 __attribute__((noreturn))
 void TestState::runLeaks(void) {
     auto testState = TestState::getState();
-    pid_t currentPid = getpid();
+    pid_t pid = getpid();
     char pidString[32];
-    snprintf(&pidString[0], sizeof(pidString), "%d", currentPid);
+    sprintf(&pidString[0], "%d", pid);
     if (getuid() != 0) {
         printf("Insufficient priviledges, skipping Leak check: %s\n", testState->testName);
         exit(0);
@@ -609,7 +596,7 @@
                 const void * buffer;
                 size_t size;
                 __unused dispatch_data_t map = dispatch_data_create_map(leaksOutput, &buffer, &size);
-                FAIL("Found Leaks:\n\n%s", (char*)buffer);
+                FAIL("Found Leaks:\n\n%s", buffer);
             }
         }
     });
@@ -626,7 +613,7 @@
     if (checkForLeaks) {
         runLeaks();
     } else {
-        _IOlock.withLock([this,&format,&args](){
+        _IOlock.withLock([this,&format,&args,&file,&line](){
             if (output == Console) {
                 printf("[\033[0;32mPASS\033[0m] %s: ", testName);
                 vprintf(format, args);