From ce5484e41f123e17239ff086516f46ccda5e8e38 Mon Sep 17 00:00:00 2001 From: Lubos Dolezel Date: Sat, 15 Feb 2020 14:12:46 +0100 Subject: [PATCH] powerd service stubs --- CMakeLists.txt | 3 + org.darlinghq.iokitd.plist | 4 +- powermanagement.defs | 1 + src/main.mm | 35 +- src/stubs-powermanagement.c | 629 ++++++++++++++++++++++++++++++++++++ 5 files changed, 668 insertions(+), 4 deletions(-) create mode 120000 powermanagement.defs create mode 100644 src/stubs-powermanagement.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e3ab55..c89b43b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,12 +23,14 @@ include_directories( include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/libcxx/include ${CMAKE_CURRENT_BINARY_DIR}) mig(iokitmig.defs) +mig(powermanagement.defs) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") set(iokitd_sources src/main.mm src/stubs.c + src/stubs-powermanagement.c src/iokitd.cpp src/ServiceRegistry.mm src/IOObject.cpp @@ -38,6 +40,7 @@ set(iokitd_sources src/IODisplayConnect.mm src/IODisplayConnectX11.mm ${CMAKE_CURRENT_BINARY_DIR}/iokitmigServer.c + ${CMAKE_CURRENT_BINARY_DIR}/powermanagementServer.c ${CMAKE_CURRENT_SOURCE_DIR}/../IOKitUser/IOCFSerialize.c ${CMAKE_CURRENT_SOURCE_DIR}/../IOKitUser/IOCFUnserialize.tab.c ) diff --git a/org.darlinghq.iokitd.plist b/org.darlinghq.iokitd.plist index 6b03943..ad3cd78 100644 --- a/org.darlinghq.iokitd.plist +++ b/org.darlinghq.iokitd.plist @@ -12,9 +12,9 @@ org.darlinghq.iokitd + com.apple.PowerManagement.control + - RunAtLoad - KeepAlive diff --git a/powermanagement.defs b/powermanagement.defs new file mode 120000 index 0000000..cd0f14d --- /dev/null +++ b/powermanagement.defs @@ -0,0 +1 @@ +../IOKitUser/pwr_mgt.subproj/powermanagement.defs \ No newline at end of file diff --git a/src/main.mm b/src/main.mm index b740416..e66bd12 100644 --- a/src/main.mm +++ b/src/main.mm @@ -12,10 +12,11 @@ extern "C" { #include "iokitmigServer.h" +#include "powermanagementServer.h" } static const char* SERVICE_NAME = "org.darlinghq.iokitd"; -mach_port_t g_masterPort, g_deathPort; +mach_port_t g_masterPort, g_deathPort, g_powerManagementPort; static void discoverAllDevices(); @@ -28,7 +29,15 @@ int main(int argc, const char** argv) if (ret != KERN_SUCCESS) { - os_log_error(OS_LOG_DEFAULT, "%d bootstrap_check_in() failed with error %d", getpid(), ret); + os_log_error(OS_LOG_DEFAULT, "%d bootstrap_check_in(%s) failed with error %d", getpid(), SERVICE_NAME, ret); + return 1; + } + + ret = bootstrap_check_in(bootstrap_port, SERVICE_NAME, &g_powerManagementPort); + + if (ret != KERN_SUCCESS) + { + os_log_error(OS_LOG_DEFAULT, "%d bootstrap_check_in(%s) failed with error %d", getpid(), SERVICE_NAME, ret); return 1; } @@ -43,6 +52,10 @@ int main(int argc, const char** argv) discoverAllDevices(); dispatch_queue_t queue = dispatch_get_main_queue(); + + //////////////////////////////// + // IOKit main port // + //////////////////////////////// dispatch_source_t portSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, g_masterPort, 0, queue); if (!portSource) @@ -55,6 +68,24 @@ int main(int argc, const char** argv) dispatch_mig_server(portSource, is_iokit_subsystem.maxsize, iokit_server); }); + //////////////////////////////// + // powerd main port // + //////////////////////////////// + dispatch_source_t pwrMgmtPortSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, g_powerManagementPort, 0, queue); + + if (!pwrMgmtPortSource) + { + os_log_error(OS_LOG_DEFAULT, "%d dispatch_source_create() failed for pwr mgmt main port", getpid()); + return 1; + } + + dispatch_source_set_event_handler(pwrMgmtPortSource, ^{ + dispatch_mig_server(pwrMgmtPortSource, _powermanagement_subsystem.maxsize, powermanagement_server); // FIXME + }); + + //////////////////////////////// + // unused port notifications // + //////////////////////////////// dispatch_source_t deathSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, g_deathPort, 0, queue); if (!deathSource) diff --git a/src/stubs-powermanagement.c b/src/stubs-powermanagement.c new file mode 100644 index 0000000..7825543 --- /dev/null +++ b/src/stubs-powermanagement.c @@ -0,0 +1,629 @@ +#include "powermanagementServer.h" +#include + +#define STUB() os_log(OS_LOG_DEFAULT, "%d STUB called: %s", getpid(), __FUNCTION__); printf("STUB called: %s\n", __FUNCTION__) + +/* Routine io_pm_get_value_int */ + +kern_return_t _io_pm_get_value_int +( + mach_port_t server, + audit_token_t token, + int selector, + int *value +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_set_value_int */ + +kern_return_t _io_pm_set_value_int +( + mach_port_t server, + audit_token_t token, + int selector, + int value, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_force_active_settings */ + +kern_return_t _io_pm_force_active_settings +( + mach_port_t server, + audit_token_t token, + vm_offset_t profiles, + mach_msg_type_number_t profilesCnt, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_set_active_profile */ + +kern_return_t _io_pm_set_active_profile +( + mach_port_t server, + audit_token_t token, + vm_offset_t profiles, + mach_msg_type_number_t profilesCnt, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_schedule_power_event */ + +kern_return_t _io_pm_schedule_power_event +( + mach_port_t server, + audit_token_t token, + vm_offset_t package, + mach_msg_type_number_t packageCnt, + int action, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_schedule_repeat_event */ + +kern_return_t _io_pm_schedule_repeat_event +( + mach_port_t server, + audit_token_t token, + vm_offset_t package, + mach_msg_type_number_t packageCnt, + int action, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_cancel_repeat_events */ + +kern_return_t _io_pm_cancel_repeat_events +( + mach_port_t server, + audit_token_t token, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_last_wake_time */ + +kern_return_t _io_pm_last_wake_time +( + mach_port_t server, + vm_offset_t *wakeData, + mach_msg_type_number_t *wakeDataCnt, + vm_offset_t *deltaData, + mach_msg_type_number_t *deltaDataCnt, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_assertion_create */ + +kern_return_t _io_pm_assertion_create +( + mach_port_t server, + audit_token_t token, + vm_offset_t props, + mach_msg_type_number_t propsCnt, + int *assertion_id, + int *disableAppSleep, + int *enTrIntensity, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_assertion_set_properties */ + +kern_return_t _io_pm_assertion_set_properties +( + mach_port_t server, + audit_token_t token, + int assertion_id, + vm_offset_t props, + mach_msg_type_number_t propsCnt, + int *disableAppSleep, + int *enableAppSleep, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_assertion_retain_release */ + +kern_return_t _io_pm_assertion_retain_release +( + mach_port_t server, + audit_token_t token, + int assertion_id, + int action, + int *retainCnt, + int *disableAppSleep, + int *enableAppSleep, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_assertion_copy_details */ + +kern_return_t _io_pm_assertion_copy_details +( + mach_port_t server, + audit_token_t token, + int assertion_id, + int whichData, + vm_offset_t props, + mach_msg_type_number_t propsCnt, + vm_offset_t *assertions, + mach_msg_type_number_t *assertionsCnt, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_declare_system_active */ + +kern_return_t _io_pm_declare_system_active +( + mach_port_t server, + audit_token_t token, + int *state, + vm_offset_t props, + mach_msg_type_number_t propsCnt, + int *assertion_id, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_declare_user_active */ + +kern_return_t _io_pm_declare_user_active +( + mach_port_t server, + audit_token_t token, + int user_type, + vm_offset_t props, + mach_msg_type_number_t propsCnt, + int *assertion_id, + int *disableAppSleep, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_declare_network_client_active */ + +kern_return_t _io_pm_declare_network_client_active +( + mach_port_t server, + audit_token_t token, + vm_offset_t props, + mach_msg_type_number_t propsCnt, + int *assertion_id, + int *disableAppSleep, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_get_uuid */ + +kern_return_t _io_pm_get_uuid +( + mach_port_t server, + int selector, + string_t out_uuid, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_connection_create */ + +kern_return_t _io_pm_connection_create +( + mach_port_t server, + mach_port_t task_in, + string_t name, + int interests, + uint32_t *connection_id, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_connection_schedule_notification */ + +kern_return_t _io_pm_connection_schedule_notification +( + mach_port_t server, + uint32_t connection_id, + mach_port_t notify_port, + int disable, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_connection_release */ + +kern_return_t _io_pm_connection_release +( + mach_port_t server, + uint32_t connection_id, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_connection_acknowledge_event */ + +kern_return_t _io_pm_connection_acknowledge_event +( + mach_port_t server, + uint32_t connection_id, + int messageToken, + vm_offset_t options, + mach_msg_type_number_t optionsCnt, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_connection_copy_status */ + +kern_return_t _io_pm_connection_copy_status +( + mach_port_t server, + int status_index, + vm_offset_t *status_data, + mach_msg_type_number_t *status_dataCnt, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_ps_new_pspowersource */ + +kern_return_t _io_ps_new_pspowersource +( + mach_port_t server, + audit_token_t token, + int *psid, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_ps_update_pspowersource */ + +kern_return_t _io_ps_update_pspowersource +( + mach_port_t server, + audit_token_t token, + int psid, + vm_offset_t psdetails, + mach_msg_type_number_t psdetailsCnt, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_ps_release_pspowersource */ + +kern_return_t _io_ps_release_pspowersource +( + mach_port_t server, + audit_token_t token, + int psid +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_ps_copy_powersources_info */ + +kern_return_t _io_ps_copy_powersources_info +( + mach_port_t server, + int pstype, + vm_offset_t *powersources, + mach_msg_type_number_t *powersourcesCnt, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_ps_copy_chargelog */ + +kern_return_t _io_ps_copy_chargelog +( + mach_port_t server, + audit_token_t token, + double time, + vm_offset_t *log, + mach_msg_type_number_t *logCnt, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_hid_event_report_activity */ + +kern_return_t _io_pm_hid_event_report_activity +( + mach_port_t server, + audit_token_t token, + int _action, + int *allow +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_hid_event_copy_history */ + +kern_return_t _io_pm_hid_event_copy_history +( + mach_port_t server, + vm_offset_t *eventArray, + mach_msg_type_number_t *eventArrayCnt, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_set_debug_flags */ + +kern_return_t _io_pm_set_debug_flags +( + mach_port_t server, + audit_token_t token, + uint32_t newFlags, + uint32_t setMode, + uint32_t *oldFlags, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_set_bt_wake_interval */ + +kern_return_t _io_pm_set_bt_wake_interval +( + mach_port_t server, + audit_token_t token, + uint32_t newInterval, + uint32_t *oldInterval, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_set_dw_linger_interval */ + +kern_return_t _io_pm_set_dw_linger_interval +( + mach_port_t server, + audit_token_t token, + uint32_t newInterval, + uint32_t *oldInterval, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_change_sa_assertion_behavior */ + +kern_return_t _io_pm_change_sa_assertion_behavior +( + mach_port_t server, + audit_token_t token, + uint32_t newFlags, + uint32_t *oldFlags, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_set_sleepservice_wake_time_cap */ + +kern_return_t _io_pm_set_sleepservice_wake_time_cap +( + mach_port_t server, + audit_token_t token, + int cap_time, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_get_capability_bits */ + +kern_return_t _io_pm_get_capability_bits +( + mach_port_t server, + audit_token_t token, + uint32_t *capBits, + int *return_val +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_ctl_assertion_type */ + +kern_return_t _io_pm_ctl_assertion_type +( + mach_port_t server, + audit_token_t token, + string_t assertion, + int action, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_assertion_notify */ + +kern_return_t _io_pm_assertion_notify +( + mach_port_t server, + audit_token_t token, + string_t name, + int req_type, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_assertion_activity_log */ + +kern_return_t _io_pm_assertion_activity_log +( + mach_port_t server, + audit_token_t token, + vm_offset_t *log, + mach_msg_type_number_t *logCnt, + uint32_t *entryCnt, + uint32_t *overflow, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} + + +/* Routine io_pm_assertion_activity_aggregate */ + +kern_return_t _io_pm_assertion_activity_aggregate +( + mach_port_t server, + audit_token_t token, + vm_offset_t *statsData, + mach_msg_type_number_t *statsDataCnt, + int *return_code +) +{ + STUB(); + return KERN_NOT_SUPPORTED; +} +