]> git.saurik.com Git - apple/xnu.git/blob - osfmk/arm64/pgtrace.h
xnu-6153.61.1.tar.gz
[apple/xnu.git] / osfmk / arm64 / pgtrace.h
1 /*
2 * Copyright (c) 2015 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 #pragma once
30
31 #ifdef CONFIG_PGTRACE
32 #include <stdbool.h>
33 #include <mach/vm_types.h>
34 #include <mach/mach_types.h>
35
36 #define RR_NUM_MAX 2
37 #define PGTRACE_STACK_DEPTH 8
38
39 typedef enum {
40 PGTRACE_RW_LOAD,
41 PGTRACE_RW_STORE,
42 PGTRACE_RW_PREFETCH
43 } pgtrace_rw_t;
44
45 typedef struct {
46 vm_offset_t ad_addr;
47 uint64_t ad_data;
48 } pgtrace_addr_data_t;
49
50 typedef struct {
51 uint64_t rr_time;
52 pgtrace_rw_t rr_rw;
53 uint8_t rr_num;
54 pgtrace_addr_data_t rr_addrdata[RR_NUM_MAX];
55 } pgtrace_run_result_t;
56
57 #ifdef CONFIG_PGTRACE_NONKEXT
58 #ifdef XNU_KERNEL_PRIVATE
59 #define PGTRACE_OPTION_KPRINTF 0x1
60 #define PGTRACE_OPTION_STACK 0x2
61 #define PGTRACE_OPTION_SPIN 0x4
62
63 typedef struct {
64 struct {
65 uint32_t sl_bytes;
66 } stat_logger;
67
68 struct {
69 uint64_t sd_ldr;
70 uint64_t sd_str;
71 uint64_t sd_ldrs;
72 uint64_t sd_ldtr;
73 uint64_t sd_sttr;
74 uint64_t sd_ldtrs;
75 uint64_t sd_ldp;
76 uint64_t sd_stp;
77 uint64_t sd_ldpsw;
78 uint64_t sd_prfm;
79
80 uint64_t sd_c335;
81 uint64_t sd_c336;
82 uint64_t sd_c337;
83 uint64_t sd_c338;
84 uint64_t sd_c339;
85 uint64_t sd_c3310;
86 uint64_t sd_c3311;
87 uint64_t sd_c3312;
88 uint64_t sd_c3313;
89 uint64_t sd_c3314;
90 uint64_t sd_c3315;
91 uint64_t sd_c3316;
92 } stat_decoder;
93 } pgtrace_stats_t;
94
95 void pgtrace_init(void);
96 int pgtrace_add_probe(thread_t thread, vm_offset_t start, vm_offset_t end);
97 void pgtrace_clear_probe(void);
98 void pgtrace_start(void);
99 void pgtrace_stop(void);
100 uint32_t pgtrace_get_size(void);
101 bool pgtrace_set_size(uint32_t);
102 void pgtrace_clear_trace(void);
103 boolean_t pgtrace_active(void);
104 uint32_t pgtrace_get_option(void);
105 void pgtrace_set_option(uint32_t option);
106 int64_t pgtrace_read_log(uint8_t *buf, uint32_t size);
107 void pgtrace_write_log(pgtrace_run_result_t res);
108 int pgtrace_get_stats(pgtrace_stats_t *stats);
109 #endif
110 #else // CONFIG_PGTRACE_NONKEXT
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114 typedef struct {
115 vm_offset_t addr;
116 uint64_t bytes;
117 } pgtrace_instruction_info_t;
118
119 typedef struct {
120 uint64_t id;
121 pgtrace_run_result_t res;
122 void *stack[PGTRACE_STACK_DEPTH];
123 } log_t;
124
125 typedef int (*run_func_t)(uint32_t inst, vm_offset_t pa, vm_offset_t va, void *ss, pgtrace_run_result_t *res);
126 typedef bool (*decode_func_t)(uint32_t inst, void *ss, pgtrace_instruction_info_t *info);
127 typedef void (*write_func_t)(pgtrace_run_result_t res);
128
129 typedef struct {
130 uint64_t magic;
131 char *arch;
132 char *desc;
133 decode_func_t decode;
134 run_func_t run;
135 } decoder_t;
136
137 typedef struct {
138 uint64_t magic;
139 char *arch;
140 char *desc;
141 write_func_t write;
142 } logger_t;
143
144 //------------------------------------
145 // for pmap fault handler
146 //------------------------------------
147 int pgtrace_decode_and_run(uint32_t inst, vm_offset_t fva, vm_map_offset_t *cva_page, arm_saved_state_t *ss, pgtrace_run_result_t *res);
148 int pgtrace_write_log(pgtrace_run_result_t res);
149
150 //------------------------------------
151 // for kext
152 //------------------------------------
153 int pgtrace_init(decoder_t *decoder, logger_t *logger);
154 int pgtrace_add_probe(thread_t thread, vm_offset_t start, vm_offset_t end);
155 void pgtrace_clear_probe(void);
156 void pgtrace_start(void);
157 void pgtrace_stop(void);
158 bool pgtrace_active(void);
159 #ifdef __cplusplus
160 }
161 #endif
162 #endif // CONFIG_PGTRACE_NONKEXT
163 #endif