Skip to content

Commit 4cf198d

Browse files
committed
Fixed seldom boot slowdown when disabling the plugins via boot arguments
1 parent 459a876 commit 4cf198d

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Lilu Changelog
2323
- Fixed a number of potential memory issues in mach parsing code
2424
- Fixed debug and development kextcache loading issues
2525
- Fixed shutdown issues in `-lilulowmem` mode
26+
- Fixed seldom boot slowdown when disabling the plugins via boot arguments
2627

2728
#### v1.1.7
2829
- Merged advanced disassembly API (thx Pb and others)

Lilu/Headers/plugin_start.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct PluginConfiguration {
3232

3333
extern PluginConfiguration ADDPR(config);
3434

35+
extern bool ADDPR(startSuccess);
36+
3537
#endif /* LILU_CUSTOM_KMOD_INIT */
3638

3739
#ifndef LILU_CUSTOM_IOKIT_INIT
@@ -40,6 +42,7 @@ class EXPORT PRODUCT_NAME : public IOService {
4042
OSDeclareDefaultStructors(PRODUCT_NAME)
4143
public:
4244
bool init(OSDictionary *dict) override;
45+
IOService *probe(IOService *provider, SInt32 *score) override;
4346
bool start(IOService *provider) override;
4447
void stop(IOService *provider) override;
4548
};

Lilu/Library/plugin_start.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
#include <Headers/kern_api.hpp>
1010
#include <Headers/kern_util.hpp>
1111

12+
#ifndef LILU_CUSTOM_KMOD_INIT
13+
bool ADDPR(startSuccess) = false;
14+
#else
15+
// Workaround custom kmod code and enable by default
16+
bool ADDPR(startSuccess) = true;
17+
#endif
18+
19+
bool ADDPR(debugEnabled) = false;
20+
1221
#ifndef LILU_CUSTOM_IOKIT_INIT
1322

1423
OSDefineMetaClassAndStructors(PRODUCT_NAME, IOService)
@@ -22,13 +31,18 @@ bool PRODUCT_NAME::init(OSDictionary *dict) {
2231
return true;
2332
}
2433

34+
IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) {
35+
auto service = IOService::probe(provider, score);
36+
return ADDPR(startSuccess) ? service : nullptr;
37+
}
38+
2539
bool PRODUCT_NAME::start(IOService *provider) {
2640
if (!IOService::start(provider)) {
2741
SYSLOG("init", "failed to start the parent");
2842
return false;
2943
}
3044

31-
return true;
45+
return ADDPR(startSuccess);
3246
}
3347

3448
void PRODUCT_NAME::stop(IOService *provider) {
@@ -37,22 +51,18 @@ void PRODUCT_NAME::stop(IOService *provider) {
3751

3852
#endif /* LILU_CUSTOM_IOKIT_INIT */
3953

40-
bool ADDPR(debugEnabled) = false;
41-
4254
#ifndef LILU_CUSTOM_KMOD_INIT
4355

4456
EXPORT extern "C" kern_return_t ADDPR(kern_start)(kmod_info_t *, void *) {
45-
kern_return_t ret = KERN_FAILURE;
4657
LiluAPI::Error error = lilu.requestAccess();
47-
4858
if (error == LiluAPI::Error::NoError) {
4959
error = lilu.shouldLoad(ADDPR(config).product, ADDPR(config).version, ADDPR(config).runmode, ADDPR(config).disableArg, ADDPR(config).disableArgNum,
5060
ADDPR(config).debugArg, ADDPR(config).debugArgNum, ADDPR(config).betaArg, ADDPR(config).betaArgNum, ADDPR(config).minKernel,
5161
ADDPR(config).maxKernel, ADDPR(debugEnabled));
5262

5363
if (error == LiluAPI::Error::NoError) {
64+
ADDPR(startSuccess) = true;
5465
ADDPR(config).pluginStart();
55-
ret = KERN_SUCCESS;
5666
} else {
5767
SYSLOG("init", "parent said we should not continue %d", error);
5868
}
@@ -61,13 +71,15 @@ EXPORT extern "C" kern_return_t ADDPR(kern_start)(kmod_info_t *, void *) {
6171
} else {
6272
SYSLOG("init", "failed to call parent %d", error);
6373
}
64-
65-
return ret;
74+
75+
// Report success but actually do not start and let I/O Kit unload us.
76+
// This works better and increases boot speed in some cases.
77+
return KERN_SUCCESS;
6678
}
6779

6880
EXPORT extern "C" kern_return_t ADDPR(kern_stop)(kmod_info_t *, void *) {
69-
// It is not safe to unload Lilu plugins!
70-
return KERN_FAILURE;
81+
// It is not safe to unload Lilu plugins unless they were disabled!
82+
return ADDPR(startSuccess) ? KERN_FAILURE : KERN_SUCCESS;
7183
}
7284

7385
#endif /* LILU_CUSTOM_KMOD_INIT */

0 commit comments

Comments
 (0)