mirror of
				https://git.suyu.dev/suyu/suyu
				synced 2025-11-03 16:39:01 -06:00 
			
		
		
		
	Merge pull request #2683 from DarkLordZach/lock-exit
am: Implement exit locking and self exit commands
This commit is contained in:
		@@ -232,12 +232,12 @@ IDebugFunctions::IDebugFunctions() : ServiceFramework{"IDebugFunctions"} {
 | 
			
		||||
 | 
			
		||||
IDebugFunctions::~IDebugFunctions() = default;
 | 
			
		||||
 | 
			
		||||
ISelfController::ISelfController(Core::System& system_,
 | 
			
		||||
                                 std::shared_ptr<NVFlinger::NVFlinger> nvflinger_)
 | 
			
		||||
    : ServiceFramework("ISelfController"), nvflinger(std::move(nvflinger_)) {
 | 
			
		||||
ISelfController::ISelfController(Core::System& system,
 | 
			
		||||
                                 std::shared_ptr<NVFlinger::NVFlinger> nvflinger)
 | 
			
		||||
    : ServiceFramework("ISelfController"), system(system), nvflinger(std::move(nvflinger)) {
 | 
			
		||||
    // clang-format off
 | 
			
		||||
    static const FunctionInfo functions[] = {
 | 
			
		||||
        {0, nullptr, "Exit"},
 | 
			
		||||
        {0, &ISelfController::Exit, "Exit"},
 | 
			
		||||
        {1, &ISelfController::LockExit, "LockExit"},
 | 
			
		||||
        {2, &ISelfController::UnlockExit, "UnlockExit"},
 | 
			
		||||
        {3, &ISelfController::EnterFatalSection, "EnterFatalSection"},
 | 
			
		||||
@@ -282,7 +282,7 @@ ISelfController::ISelfController(Core::System& system_,
 | 
			
		||||
 | 
			
		||||
    RegisterHandlers(functions);
 | 
			
		||||
 | 
			
		||||
    auto& kernel = system_.Kernel();
 | 
			
		||||
    auto& kernel = system.Kernel();
 | 
			
		||||
    launchable_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Manual,
 | 
			
		||||
                                                              "ISelfController:LaunchableEvent");
 | 
			
		||||
 | 
			
		||||
@@ -298,15 +298,28 @@ ISelfController::ISelfController(Core::System& system_,
 | 
			
		||||
 | 
			
		||||
ISelfController::~ISelfController() = default;
 | 
			
		||||
 | 
			
		||||
void ISelfController::Exit(Kernel::HLERequestContext& ctx) {
 | 
			
		||||
    LOG_DEBUG(Service_AM, "called");
 | 
			
		||||
 | 
			
		||||
    system.Shutdown();
 | 
			
		||||
 | 
			
		||||
    IPC::ResponseBuilder rb{ctx, 2};
 | 
			
		||||
    rb.Push(RESULT_SUCCESS);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ISelfController::LockExit(Kernel::HLERequestContext& ctx) {
 | 
			
		||||
    LOG_WARNING(Service_AM, "(STUBBED) called");
 | 
			
		||||
    LOG_DEBUG(Service_AM, "called");
 | 
			
		||||
 | 
			
		||||
    system.SetExitLock(true);
 | 
			
		||||
 | 
			
		||||
    IPC::ResponseBuilder rb{ctx, 2};
 | 
			
		||||
    rb.Push(RESULT_SUCCESS);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ISelfController::UnlockExit(Kernel::HLERequestContext& ctx) {
 | 
			
		||||
    LOG_WARNING(Service_AM, "(STUBBED) called");
 | 
			
		||||
    LOG_DEBUG(Service_AM, "called");
 | 
			
		||||
 | 
			
		||||
    system.SetExitLock(false);
 | 
			
		||||
 | 
			
		||||
    IPC::ResponseBuilder rb{ctx, 2};
 | 
			
		||||
    rb.Push(RESULT_SUCCESS);
 | 
			
		||||
@@ -550,6 +563,10 @@ void AppletMessageQueue::OperationModeChanged() {
 | 
			
		||||
    on_operation_mode_changed.writable->Signal();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AppletMessageQueue::RequestExit() {
 | 
			
		||||
    PushMessage(AppletMessage::ExitRequested);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ICommonStateGetter::ICommonStateGetter(Core::System& system,
 | 
			
		||||
                                       std::shared_ptr<AppletMessageQueue> msg_queue)
 | 
			
		||||
    : ServiceFramework("ICommonStateGetter"), system(system), msg_queue(std::move(msg_queue)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -45,6 +45,7 @@ class AppletMessageQueue {
 | 
			
		||||
public:
 | 
			
		||||
    enum class AppletMessage : u32 {
 | 
			
		||||
        NoMessage = 0,
 | 
			
		||||
        ExitRequested = 4,
 | 
			
		||||
        FocusStateChanged = 15,
 | 
			
		||||
        OperationModeChanged = 30,
 | 
			
		||||
        PerformanceModeChanged = 31,
 | 
			
		||||
@@ -59,6 +60,7 @@ public:
 | 
			
		||||
    AppletMessage PopMessage();
 | 
			
		||||
    std::size_t GetMessageCount() const;
 | 
			
		||||
    void OperationModeChanged();
 | 
			
		||||
    void RequestExit();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    std::queue<AppletMessage> messages;
 | 
			
		||||
@@ -123,6 +125,7 @@ public:
 | 
			
		||||
    ~ISelfController() override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void Exit(Kernel::HLERequestContext& ctx);
 | 
			
		||||
    void LockExit(Kernel::HLERequestContext& ctx);
 | 
			
		||||
    void UnlockExit(Kernel::HLERequestContext& ctx);
 | 
			
		||||
    void EnterFatalSection(Kernel::HLERequestContext& ctx);
 | 
			
		||||
@@ -151,6 +154,8 @@ private:
 | 
			
		||||
    u32 idle_time_detection_extension = 0;
 | 
			
		||||
    u64 num_fatal_sections_entered = 0;
 | 
			
		||||
    bool is_auto_sleep_disabled = false;
 | 
			
		||||
 | 
			
		||||
    Core::System& system;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> {
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,8 @@ class NVFlinger;
 | 
			
		||||
 | 
			
		||||
namespace AM {
 | 
			
		||||
 | 
			
		||||
class AppletMessageQueue;
 | 
			
		||||
 | 
			
		||||
class AppletAE final : public ServiceFramework<AppletAE> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit AppletAE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,8 @@ class NVFlinger;
 | 
			
		||||
 | 
			
		||||
namespace AM {
 | 
			
		||||
 | 
			
		||||
class AppletMessageQueue;
 | 
			
		||||
 | 
			
		||||
class AppletOE final : public ServiceFramework<AppletOE> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit AppletOE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user