]> git.saurik.com Git - apple/dyld.git/blame - dyld3/RootsChecker.h
dyld-851.27.tar.gz
[apple/dyld.git] / dyld3 / RootsChecker.h
CommitLineData
bc3b7c8c
A
1/*
2 * Copyright (c) 2020 Apple Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25
26#ifndef __DYLD_ROOTS_CHECKER_H__
27#define __DYLD_ROOTS_CHECKER_H__
28
29#include <TargetConditionals.h>
30
31#if TARGET_OS_OSX && (BUILDING_DYLD || BUILDING_CLOSURE_UTIL) && !TARGET_OS_SIMULATOR
32#define DYLD_SIMULATOR_ROOTS_SUPPORT 1
33#else
34#define DYLD_SIMULATOR_ROOTS_SUPPORT 0
35#endif
36
37class DyldSharedCache;
38
39namespace dyld3 {
40
41namespace closure {
42class FileSystem;
43struct Image;
44}
45
46#define VIS_HIDDEN __attribute__((visibility("hidden")))
47
48class VIS_HIDDEN RootsChecker
49{
50public:
51 RootsChecker() = default;
52
53 // Does a on-disk binary represent a root.
54 // If the cache expects dylibs on disk, then so long as the dylib matches
55 // the mod time and inode in the cache, it is not a root.
56 // For the macOS simulator support dylibs, which are on disk, whether they
57 // are roots depends on the state we are tracking in the comm page.
58 // For all other dylibs and all other platforms, on-disk dylibs are always roots
59 bool onDiskFileIsRoot(const char* path, const DyldSharedCache* cache, const closure::Image* image,
60 const closure::FileSystem* fileSystem,
61 uint64_t inode, uint64_t modtime) const;
62
63#if DYLD_SIMULATOR_ROOTS_SUPPORT
64 static bool uuidMatchesSharedCache(const char* path, const closure::FileSystem* fileSystem,
65 const DyldSharedCache* cache);
66
67 void setLibsystemKernelIsRoot(bool v) {
68 libsystemKernelIsRoot = v;
69 }
70 void setLibsystemPlatformIsRoot(bool v) {
71 libsystemPlatformIsRoot = v;
72 }
73 void setLibsystemPThreadIsRoot(bool v) {
74 libsystemPThreadIsRoot = v;
75 }
76 void setFileSystemCanBeModified(bool v) {
77 fileSystemCanBeModified = v;
78 }
79#endif
80
81private:
82 // By default, assume nothing is a root, but that the file system is writable.
83 // This should be conservatively correct.
84#if DYLD_SIMULATOR_ROOTS_SUPPORT
85 bool libsystemKernelIsRoot = false;
86 bool libsystemPlatformIsRoot = false;
87 bool libsystemPThreadIsRoot = false;
88 bool fileSystemCanBeModified = true;
89#endif
90};
91
92} // namespace dyld3
93
94#endif // __DYLD_ROOTS_CHECKER_H__