]> git.saurik.com Git - apple/system_cmds.git/blob - gcore.tproj/sparse.h
system_cmds-790.tar.gz
[apple/system_cmds.git] / gcore.tproj / sparse.h
1 /*
2 * Copyright (c) 2016 Apple Inc. All rights reserved.
3 */
4
5 #include "region.h"
6 #include "dyld.h"
7
8 #ifndef _SPARSE_H
9 #define _SPARSE_H
10
11 struct subregion {
12 struct vm_range s_range;
13 native_segment_command_t s_segcmd;
14 const struct libent *s_libent;
15 bool s_isuuidref;
16 };
17
18 #define S_RANGE(s) (&(s)->s_range)
19
20 static __inline void S_SETADDR(struct subregion *s, mach_vm_offset_t a) {
21 V_SETADDR(S_RANGE(s), a);
22 }
23
24 static __inline void S_SETSIZE(struct subregion *s, mach_vm_offset_t sz) {
25 V_SETSIZE(S_RANGE(s), sz);
26 }
27
28 static __inline const mach_vm_offset_t S_ADDR(const struct subregion *s) {
29 return V_ADDR(S_RANGE(s));
30 }
31
32 static __inline const mach_vm_offset_t S_SIZE(const struct subregion *s) {
33 return V_SIZE(S_RANGE(s));
34 }
35
36 static __inline const mach_vm_offset_t S_ENDADDR(const struct subregion *s) {
37 return S_ADDR(s) + S_SIZE(s);
38 }
39
40 static __inline const char *S_MACHO_TYPE(const struct subregion *s) {
41 return s->s_segcmd.segname;
42 }
43
44 static __inline off_t S_MACHO_FILEOFF(const struct subregion *s) {
45 return s->s_segcmd.fileoff;
46 }
47
48 static __inline off_t S_MACHO_FILESIZE(const struct subregion *s) {
49 return s->s_segcmd.filesize;
50 }
51
52 static __inline const struct libent *S_LIBENT(const struct subregion *s) {
53 return s->s_libent;
54 }
55
56 static __inline const char *S_PATHNAME(const struct subregion *s) {
57 const struct libent *le = S_LIBENT(s);
58 return le ? le->le_pathname : "(unknown)";
59 }
60
61 static __inline const char *S_FILENAME(const struct subregion *s) {
62 const struct libent *le = S_LIBENT(s);
63 return le ? le->le_filename : S_PATHNAME(s);
64 }
65
66 extern bool issubregiontype(const struct subregion *, const char *);
67
68 extern walk_region_cbfn_t decorate_memory_region;
69 extern walk_region_cbfn_t undecorate_memory_region;
70 extern walk_region_cbfn_t sparse_region_optimization;
71
72 #endif /* _SPARSE_H */