+#if defined(__i386__) || defined(__x86_64__)
+ switch (state.tsh.flavor) {
+ case i386_THREAD_STATE:
+ trampoline = &Trampoline_i386_;
+ align = 4;
+ push = 5;
+ break;
+ case x86_THREAD_STATE64:
+ trampoline = &Trampoline_x86_64_;
+ align = 8;
+ push = 2;
+ break;
+ default:
+ _assert(false);
+ }
+#elif defined(__arm__) || defined(__arm64__)
+ switch (state.ash.flavor) {
+ case ARM_THREAD_STATE32:
+ trampoline = &Trampoline_armv6_;
+ align = 4;
+ push = 0;
+ break;
+ case ARM_THREAD_STATE64:
+ trampoline = &Trampoline_arm64_;
+ align = 8;
+ push = 0;
+ break;
+ default:
+ _assert(false);
+ }
+#else
+ #error XXX: implement
+#endif
+
+ static const size_t Stack_(8 * 1024);
+ size_t length(strlen(library) + 1), depth(sizeof(Baton) + length);
+ depth = (depth + align + 1) / align * align;
+
+ CYPool pool;
+ uint8_t *local(pool.malloc<uint8_t>(depth));
+ Baton *baton(reinterpret_cast<Baton *>(local));
+
+ baton->dyld = info.all_image_info_addr;
+ baton->pid = getpid();
+ memset(baton->error, 0, sizeof(baton->error));
+ memcpy(baton->library, library, length);
+
+ mach_vm_size_t size(depth + Stack_);
+ mach_vm_address_t stack;
+ _krncall(mach_vm_allocate(task, &stack, size, true));
+
+ mach_vm_address_t data(stack + Stack_);
+ _krncall(mach_vm_write(task, data, reinterpret_cast<mach_vm_address_t>(baton), depth));