1 /* 2 * Copyright (c) 2013 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29 #ifndef _KERN_HV_SUPPORT_KEXT_H_ 30 #define _KERN_HV_SUPPORT_KEXT_H_ 31 32 #if defined(__cplusplus) 33 extern "C" { 34 #endif 35 36 #include <stdint.h> 37 #include <kern/kern_types.h> 38 #include <mach/kern_return.h> 39 #include <kern/hv_io_notifier.h> 40 41 typedef enum { 42 HV_DEBUG_STATE 43 } hv_volatile_state_t; 44 45 typedef enum { 46 HV_TASK_TRAP = 0, 47 HV_THREAD_TRAP = 1 48 } hv_trap_type_t; 49 50 typedef kern_return_t (*hv_trap_t) (void *target, uint64_t arg); 51 52 typedef struct { 53 const hv_trap_t *traps; 54 unsigned trap_count; 55 } hv_trap_table_t; 56 57 typedef struct { 58 void (*dispatch)(void *vcpu); 59 void (*preempt)(void *vcpu); 60 void (*suspend)(void); 61 void (*thread_destroy)(void *vcpu); 62 void (*task_destroy)(void *vm); 63 void (*volatile_state)(void *vcpu, int state); 64 #define HV_CALLBACKS_RESUME_DEFINED 1 65 void (*resume)(void); 66 void (*memory_pressure)(void); 67 } hv_callbacks_t; 68 69 extern hv_callbacks_t hv_callbacks; 70 extern int hv_support_available; 71 72 extern void hv_support_init(void); 73 extern int hv_get_support(void); 74 extern void hv_set_task_target(void *target); 75 extern void hv_set_thread_target(void *target); 76 extern void *hv_get_task_target(void); 77 extern void *hv_get_thread_target(void); 78 extern int hv_get_volatile_state(hv_volatile_state_t state); 79 extern kern_return_t hv_set_traps(hv_trap_type_t trap_type, 80 const hv_trap_t *traps, unsigned trap_count); 81 extern void hv_release_traps(hv_trap_type_t trap_type); 82 extern kern_return_t hv_set_callbacks(hv_callbacks_t callbacks); 83 extern void hv_release_callbacks(void); 84 extern void hv_suspend(void); 85 extern void hv_resume(void); 86 extern kern_return_t hv_task_trap(uint64_t index, uint64_t arg); 87 extern kern_return_t hv_thread_trap(uint64_t index, uint64_t arg); 88 extern boolean_t hv_ast_pending(void); 89 90 extern void hv_trace_guest_enter(uint32_t vcpu_id, uint64_t *vcpu_regs); 91 extern void hv_trace_guest_exit(uint32_t vcpu_id, uint64_t *vcpu_regs, 92 uint32_t reason); 93 extern void hv_trace_guest_error(uint32_t vcpu_id, uint64_t *vcpu_regs, 94 uint32_t failure, uint32_t error); 95 96 #if defined(__cplusplus) 97 } 98 #endif 99 100 #endif /* _KERN_HV_SUPPORT_KEXT_H_ */ 101