1212#include < Headers/kern_user.hpp>
1313#include < Headers/kern_policy.hpp>
1414#include < Headers/kern_util.hpp>
15+ #include < kern/thread_call.h>
1516
1617class Configuration {
1718 /* *
1819 * Possible boot arguments
1920 */
20- static constexpr const char *bootargOff {" -liluoff" }; // Disable the kext
21- static constexpr const char *bootargUserOff {" -liluuseroff" }; // Disable kext user patcher
22- static constexpr const char *bootargBeta {" -lilubeta" }; // Force enable the kext on unsupported os
23- static constexpr const char *bootargBetaAll {" -lilubetaall" }; // Force enable the kext and all plugins on unsupported os
24- static constexpr const char *bootargForce {" -liluforce" }; // Force enable the kext (including single user mode)
25- static constexpr const char *bootargDebug {" -liludbg" }; // Enable debug logging
26- static constexpr const char *bootargDebugAll {" -liludbgall" }; // Enable debug logging (for Lilu and all the plugins)
27- static constexpr const char *bootargSlow {" -liluslow" }; // Prefer less destructive userspace measures
28- static constexpr const char *bootargFast {" -lilufast" }; // Prefer faster userspace measures
29- static constexpr const char *bootargLowMem {" -lilulowmem" }; // Disable decompression
30- static constexpr const char *bootargDelay {" liludelay" }; // Extra delay timeout after each printed message
31-
21+ static constexpr const char *bootargOff {" -liluoff" }; // Disable the kext
22+ static constexpr const char *bootargUserOff {" -liluuseroff" }; // Disable kext user patcher
23+ static constexpr const char *bootargBeta {" -lilubeta" }; // Force enable the kext on unsupported os
24+ static constexpr const char *bootargBetaAll {" -lilubetaall" }; // Force enable the kext and all plugins on unsupported os
25+ static constexpr const char *bootargForce {" -liluforce" }; // Force enable the kext (including single user mode)
26+ static constexpr const char *bootargDebug {" -liludbg" }; // Enable debug logging
27+ static constexpr const char *bootargDebugAll {" -liludbgall" }; // Enable debug logging (for Lilu and all the plugins)
28+ static constexpr const char *bootargSlow {" -liluslow" }; // Prefer less destructive userspace measures
29+ static constexpr const char *bootargFast {" -lilufast" }; // Prefer faster userspace measures
30+ static constexpr const char *bootargLowMem {" -lilulowmem" }; // Disable decompression
31+ static constexpr const char *bootargDelay {" liludelay" }; // Extra delay timeout after each printed message
32+ static constexpr const char *bootargDump {" liludump" }; // Dump lilu log to /Lilu...txt after N seconds
33+
34+ public:
35+ /* *
36+ * Externally handled boot arguments
37+ */
38+ static constexpr const char *bootargCpu {" lilucpu" }; // Simulate this CPU generation, handled in kern_cpu.cpp
39+
40+ private:
3241 /* *
3342 * Minimal required kernel version
3443 */
@@ -38,19 +47,19 @@ class Configuration {
3847 * Maxmimum supported kernel version
3948 */
4049 static constexpr KernelVersion maxKernel {KernelVersion::Mojave};
41-
50+
4251 /* *
4352 * Set once the arguments are parsed
4453 */
4554 bool readArguments {false };
46-
55+
4756 /* *
4857 * Initialise kernel and user patchers if necessary
4958 *
5059 * @return true on success
5160 */
5261 bool performInit ();
53-
62+
5463 /* *
5564 * TrustedBSD policy called at exec
5665 *
@@ -60,8 +69,7 @@ class Configuration {
6069 * @return 0 on success
6170 */
6271 static int policyCredCheckLabelUpdateExecve (kauth_cred_t old, vnode_t vp, ...);
63-
64-
72+
6573 /* *
6674 * TrustedBSD policy called before remounting
6775 *
@@ -70,22 +78,48 @@ class Configuration {
7078 * @param mlabel mount point label
7179 */
7280 static int policyCheckRemount (kauth_cred_t cred, mount *mp, label *mlabel);
73-
81+
7482 /* *
7583 * TrustedBSD policy options
7684 */
7785 mac_policy_ops policyOps {
7886 .mpo_policy_initbsd = Policy::dummyPolicyInitBSD
7987 };
80-
88+
89+ #ifdef DEBUG
90+ /* *
91+ * Debug buffer dump timeout in seconds
92+ */
93+ uint32_t debugDumpTimeout {0 };
94+
95+ /* *
96+ * Debug buffer dump thread call
97+ */
98+ thread_call_t debugDumpCall {nullptr };
99+
100+ /* *
101+ * Initialise log to custom buffer support
102+ * You may call it from a debugger if you need to save the log once again.
103+ */
104+ void initCustomDebugSupport ();
105+
106+ /* *
107+ * Stores debug log on disk
108+ *
109+ * @param param0 unused
110+ * @param param1 unused
111+ */
112+ static void saveCustomDebugOnDisk (thread_call_param_t param0, thread_call_param_t param1);
113+ #endif
114+
81115public:
82116 /* *
83117 * Retrieve boot arguments
84118 *
85119 * @return true if allowed to continue
86120 */
87121 bool getBootArguments ();
88-
122+
89123 /* *
90124 * Disable the extension by default
91125 */
@@ -95,17 +129,17 @@ class Configuration {
95129 * User patcher is disabled on request
96130 */
97131 bool isUserDisabled {false };
98-
132+
99133 /* *
100134 * Do not patch dyld shared cache unless asked
101135 */
102136 bool preferSlowMode {false };
103-
137+
104138 /* *
105139 * Allow decompression
106140 */
107141 bool allowDecompress {true };
108-
142+
109143 /* *
110144 * Install or recovery
111145 */
@@ -115,7 +149,7 @@ class Configuration {
115149 * Safe mode
116150 */
117151 bool safeMode {false };
118-
152+
119153 /* *
120154 * Beta for all plugins and Lilu itself
121155 */
@@ -140,23 +174,52 @@ class Configuration {
140174 * User patcher
141175 */
142176 UserPatcher userPatcher;
143-
177+
144178 /* *
145179 * Kernel patcher
146180 */
147181 KernelPatcher kernelPatcher;
148-
182+
149183 /* *
150184 * Policy controller
151185 */
152186 Policy policy;
153-
187+
154188#ifdef DEBUG
189+ /* *
190+ * Full policy name
191+ */
155192 static constexpr const char *fullName {xStringify (PRODUCT_NAME) " Kernel Extension " xStringify (MODULE_VERSION) " DEBUG build" };
193+
194+ /* *
195+ * Maximum amount of data we can via the internal buffer (8 MB)
196+ */
197+ static constexpr size_t MaxDebugBufferSize {1024 *1024 *8 };
198+
199+ /* *
200+ * Custom logging lock
201+ */
202+ IOSimpleLock *debugLock {nullptr };
203+
204+ /* *
205+ * Debug buffer with logged data, intentionally disabled in RELEASE mode
206+ * to avoid sensitive information leak.
207+ * Contains debugBufferLength symbols, not null-terminated.
208+ */
209+ uint8_t *debugBuffer {nullptr };
210+
211+ /* *
212+ * Debug buffer current length
213+ */
214+ size_t debugBufferLength {0 };
156215#else
216+
217+ /* *
218+ * Full policy name
219+ */
157220 static constexpr const char *fullName {xStringify (PRODUCT_NAME) " Kernel Extension " xStringify (MODULE_VERSION)};
158221#endif
159-
222+
160223 Configuration () : policy(xStringify(PRODUCT_NAME), fullName, &policyOps) {}
161224};
162225
0 commit comments