]> git.cameronkatri.com Git - apple_cmds.git/blob - system_cmds/gcore.tproj/region.h
Merge branch 'apple'
[apple_cmds.git] / system_cmds / gcore.tproj / region.h
1 /*
2 * Copyright (c) 2016 Apple Inc. All rights reserved.
3 */
4
5 #include <sys/queue.h>
6 #include <sys/types.h>
7 #include <mach/mach.h>
8 #include <uuid/uuid.h>
9
10 #ifndef _REGION_H
11 #define _REGION_H
12
13 /*
14 * A range of virtual memory
15 */
16 struct vm_range {
17 mach_vm_offset_t addr;
18 mach_vm_offset_t size;
19 };
20
21 #define _V_ADDR(g) ((g)->addr)
22 #define _V_SIZE(g) ((g)->size)
23 #define V_SETADDR(g, a) ((g)->addr = (a))
24 #define V_SETSIZE(g, z) ((g)->size = (z))
25 #define V_ENDADDR(g) (_V_ADDR(g) + _V_SIZE(g))
26
27 static __inline const mach_vm_offset_t V_ADDR(const struct vm_range *vr) {
28 return _V_ADDR(vr);
29 }
30 static __inline const mach_vm_offset_t V_SIZE(const struct vm_range *vr) {
31 return _V_SIZE(vr);
32 }
33 static __inline const size_t V_SIZEOF(const struct vm_range *vr) {
34 assert((typeof (vr->size))(size_t)_V_SIZE(vr) == _V_SIZE(vr));
35 return (size_t)_V_SIZE(vr);
36 }
37
38 /*
39 * A range of offsets into a file
40 */
41 struct file_range {
42 off_t off;
43 off_t size;
44 };
45
46 #define F_OFF(f) ((f)->off)
47 #define F_SIZE(f) ((f)->size)
48
49 struct regionop;
50 struct subregion;
51
52 struct region {
53 STAILQ_ENTRY(region) r_linkage;
54
55 struct vm_range r_range;
56
57 #define R_RANGE(r) (&(r)->r_range)
58 #define _R_ADDR(r) _V_ADDR(R_RANGE(r))
59 #define _R_SIZE(r) _V_SIZE(R_RANGE(r))
60 #define R_SIZEOF(r) V_SIZEOF(R_RANGE(r))
61 #define R_SETADDR(r, a) V_SETADDR(R_RANGE(r), (a))
62 #define R_SETSIZE(r, z) V_SETSIZE(R_RANGE(r), (z))
63 #define R_ENDADDR(r) (_R_ADDR(r) + _R_SIZE(r))
64
65 vm_region_submap_info_data_64_t r_info;
66 vm_page_info_basic_data_t r_pageinfo;
67
68 int r_purgable;
69
70 #ifdef CONFIG_SUBMAP
71 int r_depth;
72 #endif
73 boolean_t r_insharedregion, r_inzfodregion, r_incommregion;
74
75 /*
76 * This field may be non-NULL if the region is a read-only part
77 * of a mapped file (i.e. the shared cache) and thus
78 * doesn't need to be copied.
79 */
80 struct {
81 const struct libent *fr_libent;
82 const char *fr_pathname;
83 off_t fr_offset;
84 } *r_fileref;
85
86 /*
87 * These (optional) fields are filled in after we parse the information
88 * about the dylibs we've mapped, as provided by dyld.
89 */
90 struct subregion **r_subregions;
91 unsigned r_nsubregions;
92
93 const struct regionop *r_op;
94 };
95
96 static __inline const mach_vm_offset_t R_ADDR(const struct region *r) {
97 return _R_ADDR(r);
98 }
99 static __inline const mach_vm_offset_t R_SIZE(const struct region *r) {
100 return _R_SIZE(r);
101 }
102
103 /*
104 * Describes the disposition of the region after a walker returns
105 */
106 typedef enum {
107 WALK_CONTINUE, // press on ..
108 WALK_DELETE_REGION, // discard this region, then continue
109 WALK_TERMINATE, // early termination, no error
110 WALK_ERROR, // early termination, error
111 } walk_return_t;
112
113 struct size_core;
114 struct write_segment_data;
115
116 typedef walk_return_t walk_region_cbfn_t(struct region *, void *);
117
118 struct regionop {
119 void (*rop_print)(const struct region *);
120 walk_return_t (*rop_write)(const struct region *, struct write_segment_data *);
121 void (*rop_delete)(struct region *);
122 };
123
124 #define ROP_PRINT(r) (((r)->r_op->rop_print)(r))
125 #define ROP_WRITE(r, w) (((r)->r_op->rop_write)(r, w))
126 #define ROP_DELETE(r) (((r)->r_op->rop_delete)(r))
127
128 extern const struct regionop vanilla_ops, sparse_ops, zfod_ops;
129 extern const struct regionop fileref_ops;
130
131 struct regionhead;
132
133 #endif /* _REGION_H */