- vm_address_t code;
- _krncall(vm_allocate(task, &code, trampoline->size_, true));
- _krncall(vm_write(task, code, reinterpret_cast<vm_address_t>(trampoline->data_), trampoline->size_));
- _krncall(vm_protect(task, code, trampoline->size_, false, VM_PROT_READ | VM_PROT_EXECUTE));
+ 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();
+ 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));
+
+ mach_vm_address_t code;
+ _krncall(mach_vm_allocate(task, &code, trampoline->size_, true));
+ _krncall(mach_vm_write(task, code, reinterpret_cast<mach_vm_address_t>(trampoline->data_), trampoline->size_));
+ _krncall(mach_vm_protect(task, code, trampoline->size_, false, VM_PROT_READ | VM_PROT_EXECUTE));