_krncall(mach_port_deallocate(self, thread));
+ mach_vm_size_t error(sizeof(baton->error));
+ _krncall(mach_vm_read_overwrite(task, data + offsetof(Baton, error), sizeof(baton->error), reinterpret_cast<mach_vm_address_t>(&baton->error), &error));
+ _assert(error == sizeof(baton->error));
+ if (baton->error[0] != '\0')
+ CYThrow("%s", baton->error);
+
_krncall(mach_vm_deallocate(task, code, trampoline->size_));
_krncall(mach_vm_deallocate(task, stack, size));
#define mach_vm_protect(a, b, c, d, e) \
cy_vm_protect(broken, a, b, c, d, e)
+static kern_return_t cy_vm_read_overwrite(bool broken, vm_map_t target_task, mach_vm_address_t address, mach_vm_size_t size, mach_vm_address_t data, mach_vm_size_t *outsize) {
+ if (!broken)
+ return mach_vm_read_overwrite(target_task, address, size, data, outsize);
+ vm_size_t outsize32(*outsize);
+ kern_return_t value(vm_read_overwrite(target_task, address, data, size, &outsize32));
+ *outsize = outsize32;
+ return value;
+}
+
+#define mach_vm_read_overwrite(a, b, c, d, e) \
+ cy_vm_read_overwrite(broken, a, b, c, d, e)
+
static kern_return_t cy_vm_write(bool broken, vm_map_t target_task, mach_vm_address_t address, vm_offset_t data, mach_msg_type_number_t dataCnt) {
if (!broken)
return mach_vm_write(target_task, address, data, dataCnt);
} 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;
void *handle($dlopen(baton->library, RTLD_LAZY | RTLD_LOCAL));
if (handle == NULL) {
- $dlerror();
+ $strlcpy(baton->error, $dlerror(), sizeof(baton->error));
return NULL;
}
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;
}