X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/fe8ab488e9161c46dd9885d58fc52996dc0249ff..HEAD:/libsyscall/mach/mach_vm.c diff --git a/libsyscall/mach/mach_vm.c b/libsyscall/mach/mach_vm.c index d31037398..365d9a94b 100644 --- a/libsyscall/mach/mach_vm.c +++ b/libsyscall/mach/mach_vm.c @@ -2,7 +2,7 @@ * Copyright (c) 2011 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ - * + * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in @@ -11,10 +11,10 @@ * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. - * + * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -22,7 +22,7 @@ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. - * + * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ @@ -54,15 +54,16 @@ mach_vm_allocate( rv = _kernelrpc_mach_vm_allocate_trap(target, address, size, flags); - if (rv == MACH_SEND_INVALID_DEST) + if (rv == MACH_SEND_INVALID_DEST) { rv = _kernelrpc_mach_vm_allocate(target, address, size, flags); + } - if (__syscall_logger) { - int userTagFlags = flags & VM_FLAGS_ALIAS_MASK; + int userTagFlags = flags & VM_FLAGS_ALIAS_MASK; + if (__syscall_logger && rv == KERN_SUCCESS && (userTagFlags != VM_MAKE_TAG(VM_MEMORY_STACK))) { __syscall_logger(stack_logging_type_vm_allocate | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0); } - return (rv); + return rv; } kern_return_t @@ -73,16 +74,17 @@ mach_vm_deallocate( { kern_return_t rv; + if (__syscall_logger) { + __syscall_logger(stack_logging_type_vm_deallocate, (uintptr_t)target, (uintptr_t)address, (uintptr_t)size, 0, 0); + } + rv = _kernelrpc_mach_vm_deallocate_trap(target, address, size); - if (rv == MACH_SEND_INVALID_DEST) + if (rv == MACH_SEND_INVALID_DEST) { rv = _kernelrpc_mach_vm_deallocate(target, address, size); - - if (__syscall_logger) { - __syscall_logger(stack_logging_type_vm_deallocate, (uintptr_t)target, (uintptr_t)address, (uintptr_t)size, 0, 0); } - return (rv); + return rv; } kern_return_t @@ -96,13 +98,14 @@ mach_vm_protect( kern_return_t rv; rv = _kernelrpc_mach_vm_protect_trap(task, address, size, set_maximum, - new_protection); + new_protection); - if (rv == MACH_SEND_INVALID_DEST) + if (rv == MACH_SEND_INVALID_DEST) { rv = _kernelrpc_mach_vm_protect(task, address, size, - set_maximum, new_protection); + set_maximum, new_protection); + } - return (rv); + return rv; } kern_return_t @@ -123,7 +126,7 @@ vm_allocate( *address = (vm_address_t)(mach_addr & ((vm_address_t)-1)); #endif - return (rv); + return rv; } kern_return_t @@ -136,7 +139,7 @@ vm_deallocate( rv = mach_vm_deallocate(task, address, size); - return (rv); + return rv; } kern_return_t @@ -151,7 +154,7 @@ vm_protect( rv = mach_vm_protect(task, address, size, set_maximum, new_protection); - return (rv); + return rv; } kern_return_t @@ -171,21 +174,23 @@ mach_vm_map( kern_return_t rv = MACH_SEND_INVALID_DEST; if (object == MEMORY_OBJECT_NULL && max_protection == VM_PROT_ALL && - inheritance == VM_INHERIT_DEFAULT) + inheritance == VM_INHERIT_DEFAULT) { rv = _kernelrpc_mach_vm_map_trap(target, address, size, mask, flags, - cur_protection); + cur_protection); + } - if (rv == MACH_SEND_INVALID_DEST) + if (rv == MACH_SEND_INVALID_DEST) { rv = _kernelrpc_mach_vm_map(target, address, size, mask, flags, object, - offset, copy, cur_protection, max_protection, inheritance); + offset, copy, cur_protection, max_protection, inheritance); + } - if (__syscall_logger) { + int userTagFlags = flags & VM_FLAGS_ALIAS_MASK; + if (__syscall_logger && rv == KERN_SUCCESS && (userTagFlags != VM_MAKE_TAG(VM_MEMORY_STACK))) { int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem; - int userTagFlags = flags & VM_FLAGS_ALIAS_MASK; __syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0); } - return (rv); + return rv; } kern_return_t @@ -200,21 +205,51 @@ mach_vm_remap( boolean_t copy, vm_prot_t *cur_protection, vm_prot_t *max_protection, - vm_inherit_t inheritance) + vm_inherit_t inheritance) { kern_return_t rv; rv = _kernelrpc_mach_vm_remap(target, address, size, mask, flags, - src_task, src_address, copy, cur_protection, max_protection, - inheritance); + src_task, src_address, copy, cur_protection, max_protection, + inheritance); - if (__syscall_logger) { + if (__syscall_logger && rv == KERN_SUCCESS) { int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem; int userTagFlags = flags & VM_FLAGS_ALIAS_MASK; __syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0); } - return (rv); + return rv; +} + +kern_return_t +mach_vm_remap_new( + mach_port_name_t target, + mach_vm_address_t *address, + mach_vm_size_t size, + mach_vm_offset_t mask, + int flags, + mach_port_name_t src_task, + mach_vm_address_t src_address, + boolean_t copy, + vm_prot_t *cur_protection, + vm_prot_t *max_protection, + vm_inherit_t inheritance) +{ + kern_return_t rv; + + /* {max,cur}_protection is inout */ + rv = _kernelrpc_mach_vm_remap_new(target, address, size, mask, flags, + src_task, src_address, copy, cur_protection, max_protection, + inheritance); + + if (__syscall_logger && rv == KERN_SUCCESS) { + int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem; + int userTagFlags = flags & VM_FLAGS_ALIAS_MASK; + __syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0); + } + + return rv; } kern_return_t @@ -229,14 +264,14 @@ mach_vm_read( rv = _kernelrpc_mach_vm_read(target, address, size, data, dataCnt); - if (__syscall_logger) { + if (__syscall_logger && rv == KERN_SUCCESS) { int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem; // The target argument is the remote task from which data is being read, // so pass mach_task_self() as the destination task receiving the allocation. __syscall_logger(eventTypeFlags, (uintptr_t)mach_task_self(), (uintptr_t)*dataCnt, 0, *data, 0); } - return (rv); + return rv; } kern_return_t @@ -256,15 +291,15 @@ vm_map( kern_return_t rv; rv = _kernelrpc_vm_map(target, address, size, mask, flags, object, - offset, copy, cur_protection, max_protection, inheritance); + offset, copy, cur_protection, max_protection, inheritance); - if (__syscall_logger) { + if (__syscall_logger && rv == KERN_SUCCESS) { int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem; int userTagFlags = flags & VM_FLAGS_ALIAS_MASK; __syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0); } - return (rv); + return rv; } kern_return_t @@ -279,13 +314,43 @@ vm_remap( boolean_t copy, vm_prot_t *cur_protection, vm_prot_t *max_protection, - vm_inherit_t inheritance) + vm_inherit_t inheritance) { kern_return_t rv; rv = _kernelrpc_vm_remap(target, address, size, mask, flags, - src_task, src_address, copy, cur_protection, max_protection, - inheritance); + src_task, src_address, copy, cur_protection, max_protection, + inheritance); + + if (__syscall_logger) { + int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem; + int userTagFlags = flags & VM_FLAGS_ALIAS_MASK; + __syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0); + } + + return rv; +} + +kern_return_t +vm_remap_new( + mach_port_name_t target, + vm_address_t *address, + vm_size_t size, + vm_offset_t mask, + int flags, + mach_port_name_t src_task, + vm_address_t src_address, + boolean_t copy, + vm_prot_t *cur_protection, + vm_prot_t *max_protection, + vm_inherit_t inheritance) +{ + kern_return_t rv; + + /* {max,cur}_protection is inout */ + rv = _kernelrpc_vm_remap_new(target, address, size, mask, flags, + src_task, src_address, copy, cur_protection, max_protection, + inheritance); if (__syscall_logger) { int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem; @@ -293,7 +358,7 @@ vm_remap( __syscall_logger(eventTypeFlags | userTagFlags, (uintptr_t)target, (uintptr_t)size, 0, (uintptr_t)*address, 0); } - return (rv); + return rv; } kern_return_t @@ -308,12 +373,43 @@ vm_read( rv = _kernelrpc_vm_read(target, address, size, data, dataCnt); - if (__syscall_logger) { + if (__syscall_logger && rv == KERN_SUCCESS) { int eventTypeFlags = stack_logging_type_vm_allocate | stack_logging_type_mapped_file_or_shared_mem; // The target argument is the remote task from which data is being read, // so pass mach_task_self() as the destination task receiving the allocation. __syscall_logger(eventTypeFlags, (uintptr_t)mach_task_self(), (uintptr_t)*dataCnt, 0, *data, 0); } - return (rv); + return rv; +} + +kern_return_t +mach_vm_purgable_control( + mach_port_name_t target, + mach_vm_offset_t address, + vm_purgable_t control, + int *state) +{ + kern_return_t rv; + + rv = _kernelrpc_mach_vm_purgable_control_trap(target, address, control, state); + + if (rv == MACH_SEND_INVALID_DEST) { + rv = _kernelrpc_mach_vm_purgable_control(target, address, control, state); + } + + return rv; +} + +kern_return_t +vm_purgable_control( + mach_port_name_t task, + vm_offset_t address, + vm_purgable_t control, + int *state) +{ + return mach_vm_purgable_control(task, + (mach_vm_offset_t) address, + control, + state); }