xref: /xnu-8020.140.41/osfmk/kern/hvg_hypercall.h (revision 27b03b360a988dfd3dfdf34262bb0042026747cc) !
1 /*
2  * Copyright (c) 2020 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_HVG_HYPERCALL_H_
30 #define _KERN_HVG_HYPERCALL_H_
31 
32 #include <os/base.h>
33 #include <stdint.h>
34 
35 /* Architecture-independent definitions (exported to userland) */
36 
37 /*
38  * Apple Hypercall arguments
39  */
40 typedef struct hvg_hcall_args {
41 	uint64_t args[6];
42 } hvg_hcall_args_t;
43 
44 
45 /*
46  * Apple Hypercall return output
47  */
48 typedef struct hvg_hcall_output {
49 	uint64_t regs[7];
50 } hvg_hcall_output_t;
51 
52 
53 /*
54  * Apple Hypercall return code
55  */
56 
57 OS_CLOSED_ENUM(hvg_hcall_return, uint32_t,
58     HVG_HCALL_SUCCESS             = 0x0000,       /* The call succeeded */
59     HVG_HCALL_ACCESS_DENIED       = 0x0001,       /* Invalid access right */
60     HVG_HCALL_INVALID_CODE        = 0x0002,       /* Hypercall code not recognized */
61     HVG_HCALL_INVALID_PARAMETER   = 0x0003,       /* Specified register value not valid */
62     HVG_HCALL_IO_FAILED           = 0x0004,       /* Input/output error */
63     HVG_HCALL_FEAT_DISABLED       = 0x0005,       /* Feature not available */
64     HVG_HCALL_UNSUPPORTED         = 0x0006,       /* Hypercall not supported */
65     );
66 
67 
68 /*
69  * Apple Hypercall call code
70  */
71 
72 OS_CLOSED_ENUM(hvg_hcall_code, uint32_t,
73     HVG_HCALL_TRIGGER_DUMP        = 0x0001,       /* Collect guest dump */
74     HVG_HCALL_SET_COREDUMP_DATA   = 0x0002,       /* Set necessary info for reliable coredump */
75     );
76 
77 /*
78  * Options for collecting kernel vmcore
79  */
80 
81 OS_CLOSED_OPTIONS(hvg_hcall_dump_option, uint32_t,
82     HVG_HCALL_DUMP_OPTION_REGULAR   =  0x0001     /* Regular dump-guest-memory */
83     );
84 
85 typedef struct hvg_hcall_vmcore_file {
86 	char tag[57];   /* 7 64-bit registers plus 1 byte for '\0' */
87 } hvg_hcall_vmcore_file_t;
88 
89 extern hvg_hcall_return_t
90 hvg_hcall_trigger_dump(hvg_hcall_vmcore_file_t *vmcore,
91     const hvg_hcall_dump_option_t dump_option);
92 
93 extern void
94 hvg_hcall_set_coredump_data(void);
95 
96 #ifdef XNU_KERNEL_PRIVATE
97 
98 /*
99  * For XNU kernel use only (omitted from userland headers)
100  */
101 
102 #if defined (__x86_64__)
103 #include <i386/cpuid.h>
104 #include <i386/x86_hypercall.h>
105 #else
106 #define hvg_hcall_set_coredump_data() do {} while(0)
107 #endif /* defined (__x86_64__) */
108 
109 #endif /* XNU_KERNEL_PRIVATE */
110 
111 #endif /* _KERN_HV_HYPERCALL_H_ */
112