- if (copyout(&map_addr, va, sizeof (map_addr))) {
- (void) vm_map_remove(
- my_map,
- map_addr, map_addr + map_size,
- VM_MAP_NO_FLAGS);
- return (KERN_INVALID_ADDRESS);
+ return EINVAL;
+ }
+
+#if 0
+ kprintf("%s vpath %s cryptid 0x%08x cputype 0x%08x cpusubtype 0x%08x range 0x%016llx size 0x%016llx\n",
+ __FUNCTION__, vpath, cryptid, cputype, cpusubtype, (uint64_t)user_addr, (uint64_t)user_size);
+#endif
+
+ /* set up decrypter first */
+ crypt_file_data_t crypt_data = {
+ .filename = vpath,
+ .cputype = cputype,
+ .cpusubtype = cpusubtype
+ };
+ result = text_crypter_create(&crypt_info, cryptname, (void*)&crypt_data);
+#if VM_MAP_DEBUG_APPLE_PROTECT
+ if (vm_map_debug_apple_protect) {
+ printf("APPLE_PROTECT: %d[%s] map %p [0x%llx:0x%llx] %s(%s) -> 0x%x\n",
+ p->p_pid, p->p_comm,
+ user_map,
+ (uint64_t) user_addr,
+ (uint64_t) (user_addr + user_size),
+ __FUNCTION__, vpath, result);
+ }
+#endif /* VM_MAP_DEBUG_APPLE_PROTECT */
+ zfree(ZV_NAMEI, vpath);
+
+ if (result) {
+ printf("%s: unable to create decrypter %s, kr=%d\n",
+ __FUNCTION__, cryptname, result);
+ if (result == kIOReturnNotPrivileged) {
+ /* text encryption returned decryption failure */
+ return EPERM;
+ } else {
+ return ENOMEM;