]> git.saurik.com Git - cycript.git/blobdiff - Trampoline.t.cpp
sig::Copy should use const for source arguments.
[cycript.git] / Trampoline.t.cpp
index 297486e6df91592d9ff5390aa46beb31a7685c22..0ae088d3c0d77c90e549e56a153b6e559e5b1875 100644 (file)
 /* }}} */
 
 #include <TargetConditionals.h>
+#if defined(__arm__) || defined(__arm64__)
 #undef TARGET_IPHONE_SIMULATOR
 #define TARGET_IPHONE_SIMULATOR 1
+#endif
 #define _PTHREAD_ATTR_T
 #include <pthread_internals.h>
+#if defined(__arm__) || defined(__arm64__)
 #undef TARGET_IPHONE_SIMULATOR
-#define TARGET_IPHONE_SIMULATOR 0
+#endif
 
 #include <mach-o/dyld.h>
 #include <mach-o/dyld_images.h>
@@ -49,6 +52,18 @@ static int $strcmp(const char *lhs, const char *rhs) {
     } return *lhs < *rhs ? -1 : 1;
 }
 
+static void $strlcpy(char *dst, const char *src, size_t size) {
+    if (size == 0)
+        return;
+    size_t i(0);
+    while (i != size - 1) {
+        char value(src[i]);
+        if (value == '\0')
+            break;
+        dst[i++] = value;
+    } dst[i] = '\0';
+}
+
 #ifdef __LP64__
 typedef struct mach_header_64 mach_header_xx;
 typedef struct nlist_64 nlist_xx;
@@ -174,7 +189,7 @@ void *Routine(void *arg) {
 
     void *handle($dlopen(baton->library, RTLD_LAZY | RTLD_LOCAL));
     if (handle == NULL) {
-        $dlerror();
+        $strlcpy(baton->error, $dlerror(), sizeof(baton->error));
         return NULL;
     }
 
@@ -184,7 +199,7 @@ void *Routine(void *arg) {
     void (*CYHandleServer)(pid_t);
     CYHandleServer = reinterpret_cast<void (*)(pid_t)>($dlsym(handle, "CYHandleServer"));
     if (CYHandleServer == NULL) {
-        $dlerror();
+        $strlcpy(baton->error, $dlerror(), sizeof(baton->error));
         return NULL;
     }
 
@@ -250,6 +265,8 @@ extern "C" void Start(Baton *baton) {
     tsd = reinterpret_cast<void **>(tpid & ~3);
     if (tsd != NULL)
         tsd[0] = &self;
+#else
+    _pthread_setspecific_direct(0, &self);
 #endif
 
     int (*$pthread_join)(pthread_t, void **);