int madvise(__unused proc_t p, struct madvise_args *uap, __unused register_t *retval) { vm_map_t user_map; mach_vm_offset_t start; mach_vm_size_t size; vm_behavior_t new_behavior; kern_return_t result; /* * Since this routine is only advisory, we default to conservative * behavior. */ switch (uap->behav) { case MADV_RANDOM: new_behavior = VM_BEHAVIOR_RANDOM; break; case MADV_SEQUENTIAL: new_behavior = VM_BEHAVIOR_SEQUENTIAL; break; case MADV_NORMAL: new_behavior = VM_BEHAVIOR_DEFAULT; break; case MADV_WILLNEED: new_behavior = VM_BEHAVIOR_WILLNEED; break; case MADV_DONTNEED: new_behavior = VM_BEHAVIOR_DONTNEED; break; default: return(EINVAL); } start = (mach_vm_offset_t) uap->addr; size = (mach_vm_size_t) uap->len; user_map = current_map(); result = mach_vm_behavior_set(user_map, start, size, new_behavior); switch (result) { case KERN_SUCCESS: return (0); case KERN_INVALID_ADDRESS: return (ENOMEM); } return (EINVAL); }
"failing madvise(0x%llx,0x%llx,%s)\n", p->p_pid, p->p_comm, start, size, ((uap->behav == MADV_FREE_REUSABLE) ? "MADV_FREE_REUSABLE" : "MADV_FREE")); DTRACE_VM3(fourk_compat_madvise, uint64_t, start, uint64_t, size, int, uap->behav); return EINVAL; } #endif /* __arm64__ */ user_map = current_map(); result = mach_vm_behavior_set(user_map, start, size, new_behavior); switch (result) { case KERN_SUCCESS: return 0; case KERN_INVALID_ADDRESS: return EINVAL; case KERN_NO_SPACE: return ENOMEM; } return EINVAL; } int mincore(__unused proc_t p, struct mincore_args *uap, __unused int32_t *retval) {
int madvise(__unused proc_t p, struct madvise_args *uap, __unused int32_t *retval) { vm_map_t user_map; mach_vm_offset_t start; mach_vm_size_t size; vm_behavior_t new_behavior; kern_return_t result; /* * Since this routine is only advisory, we default to conservative * behavior. */ switch (uap->behav) { case MADV_RANDOM: new_behavior = VM_BEHAVIOR_RANDOM; break; case MADV_SEQUENTIAL: new_behavior = VM_BEHAVIOR_SEQUENTIAL; break; case MADV_NORMAL: new_behavior = VM_BEHAVIOR_DEFAULT; break; case MADV_WILLNEED: new_behavior = VM_BEHAVIOR_WILLNEED; break; case MADV_DONTNEED: new_behavior = VM_BEHAVIOR_DONTNEED; break; case MADV_FREE: new_behavior = VM_BEHAVIOR_FREE; break; case MADV_ZERO_WIRED_PAGES: new_behavior = VM_BEHAVIOR_ZERO_WIRED_PAGES; break; case MADV_FREE_REUSABLE: new_behavior = VM_BEHAVIOR_REUSABLE; break; case MADV_FREE_REUSE: new_behavior = VM_BEHAVIOR_REUSE; break; case MADV_CAN_REUSE: new_behavior = VM_BEHAVIOR_CAN_REUSE; break; case MADV_PAGEOUT: #if MACH_ASSERT new_behavior = VM_BEHAVIOR_PAGEOUT; break; #else /* MACH_ASSERT */ return ENOTSUP; #endif /* MACH_ASSERT */ default: return(EINVAL); } start = (mach_vm_offset_t) uap->addr; size = (mach_vm_size_t) uap->len; user_map = current_map(); result = mach_vm_behavior_set(user_map, start, size, new_behavior); switch (result) { case KERN_SUCCESS: return 0; case KERN_INVALID_ADDRESS: return EINVAL; case KERN_NO_SPACE: return ENOMEM; } return EINVAL; }