Skip to content

Commit

Permalink
Fixed seldom boot slowdown when disabling the plugins via boot arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Oct 7, 2017
1 parent 459a876 commit 4cf198d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Lilu Changelog
- Fixed a number of potential memory issues in mach parsing code
- Fixed debug and development kextcache loading issues
- Fixed shutdown issues in `-lilulowmem` mode
- Fixed seldom boot slowdown when disabling the plugins via boot arguments

#### v1.1.7
- Merged advanced disassembly API (thx Pb and others)
Expand Down
3 changes: 3 additions & 0 deletions Lilu/Headers/plugin_start.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct PluginConfiguration {

extern PluginConfiguration ADDPR(config);

extern bool ADDPR(startSuccess);

#endif /* LILU_CUSTOM_KMOD_INIT */

#ifndef LILU_CUSTOM_IOKIT_INIT
Expand All @@ -40,6 +42,7 @@ class EXPORT PRODUCT_NAME : public IOService {
OSDeclareDefaultStructors(PRODUCT_NAME)
public:
bool init(OSDictionary *dict) override;
IOService *probe(IOService *provider, SInt32 *score) override;
bool start(IOService *provider) override;
void stop(IOService *provider) override;
};
Expand Down
32 changes: 22 additions & 10 deletions Lilu/Library/plugin_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
#include <Headers/kern_api.hpp>
#include <Headers/kern_util.hpp>

#ifndef LILU_CUSTOM_KMOD_INIT
bool ADDPR(startSuccess) = false;
#else
// Workaround custom kmod code and enable by default
bool ADDPR(startSuccess) = true;
#endif

bool ADDPR(debugEnabled) = false;

#ifndef LILU_CUSTOM_IOKIT_INIT

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

IOService *PRODUCT_NAME::probe(IOService *provider, SInt32 *score) {
auto service = IOService::probe(provider, score);
return ADDPR(startSuccess) ? service : nullptr;
}

bool PRODUCT_NAME::start(IOService *provider) {
if (!IOService::start(provider)) {
SYSLOG("init", "failed to start the parent");
return false;
}

return true;
return ADDPR(startSuccess);
}

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

#endif /* LILU_CUSTOM_IOKIT_INIT */

bool ADDPR(debugEnabled) = false;

#ifndef LILU_CUSTOM_KMOD_INIT

EXPORT extern "C" kern_return_t ADDPR(kern_start)(kmod_info_t *, void *) {
kern_return_t ret = KERN_FAILURE;
LiluAPI::Error error = lilu.requestAccess();

if (error == LiluAPI::Error::NoError) {
error = lilu.shouldLoad(ADDPR(config).product, ADDPR(config).version, ADDPR(config).runmode, ADDPR(config).disableArg, ADDPR(config).disableArgNum,
ADDPR(config).debugArg, ADDPR(config).debugArgNum, ADDPR(config).betaArg, ADDPR(config).betaArgNum, ADDPR(config).minKernel,
ADDPR(config).maxKernel, ADDPR(debugEnabled));

if (error == LiluAPI::Error::NoError) {
ADDPR(startSuccess) = true;
ADDPR(config).pluginStart();
ret = KERN_SUCCESS;
} else {
SYSLOG("init", "parent said we should not continue %d", error);
}
Expand All @@ -61,13 +71,15 @@ EXPORT extern "C" kern_return_t ADDPR(kern_start)(kmod_info_t *, void *) {
} else {
SYSLOG("init", "failed to call parent %d", error);
}

return ret;

// Report success but actually do not start and let I/O Kit unload us.
// This works better and increases boot speed in some cases.
return KERN_SUCCESS;
}

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

#endif /* LILU_CUSTOM_KMOD_INIT */

0 comments on commit 4cf198d

Please sign in to comment.