dyld-732.8.tar.gz
[apple/dyld.git] / dyld3 / BootArgs.cpp
1 //
2 // BootArgs.cpp
3 // dyld
4 //
5 // Created by Louis Gerbarg on 11/14/18.
6 //
7
8 #include <sys/types.h>
9 #include <sys/sysctl.h>
10 #include <TargetConditionals.h>
11
12 #include "Loading.h" // For internalInstall()
13 #include "BootArgs.h"
14
15 namespace dyld3 {
16 /*
17 * Checks to see if there are any args that impact dyld. These args
18 * can be set sevaral ways. These will only be honored on development
19 * and Apple Internal builds.
20 */
21 bool BootArgs::contains(const char* arg)
22 {
23 //FIXME: Use strnstr(). Unfortunately we are missing an imp in libc.a
24 #if TARGET_OS_SIMULATOR
25 return false;
26 #else
27 // don't check for boot-args on customer installs
28 if ( !internalInstall() )
29 return false;
30
31 // get length of full boot-args string
32 size_t len;
33 if ( sysctlbyname("kern.bootargs", NULL, &len, NULL, 0) != 0 )
34 return false;
35
36 // get copy of boot-args string
37 char bootArgsBuffer[len];
38 if ( sysctlbyname("kern.bootargs", bootArgsBuffer, &len, NULL, 0) != 0 )
39 return false;
40
41 // return true if 'arg' is a sub-string of boot-args
42 return (strstr(bootArgsBuffer, arg) != nullptr);
43 #endif
44 }
45
46 uint64_t BootArgs::_flags = 0;
47
48 bool BootArgs::forceCustomerCache() {
49 return (_flags & kForceCustomerCacheMask);
50 }
51
52 bool BootArgs::forceDyld2() {
53 // If both force dyld2 and dyld3 are set then use dyld3
54 if (_flags & kForceDyld3CacheMask) { return false; }
55 if (_flags & kForceDyld2CacheMask) { return true; }
56 if (contains("force_dyld2=1")) { return true; }
57 return false;
58 }
59
60 bool BootArgs::forceDyld3() {
61 return ((_flags & kForceDyld3CacheMask) || contains("force_dyld3=1"));
62 }
63
64 bool BootArgs::enableDyldTestMode() {
65 return (_flags & kDyldTestModeMask);
66 }
67
68 bool BootArgs::enableCompactImageInfo() {
69 return (_flags & kEnableCompactImageInfoMask);
70 }
71
72 void BootArgs::setFlags(uint64_t flags) {
73 #if TARGET_IPHONE_SIMULATOR
74 return;
75 #else
76 // don't check for boot-args on customer installs
77 if ( !internalInstall() )
78 return;
79 _flags = flags;
80 #endif
81 }
82 };