am.cpp 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <algorithm>
  4. #include <array>
  5. #include <cinttypes>
  6. #include <cstring>
  7. #include "common/settings.h"
  8. #include "core/core.h"
  9. #include "core/file_sys/control_metadata.h"
  10. #include "core/file_sys/patch_manager.h"
  11. #include "core/file_sys/registered_cache.h"
  12. #include "core/file_sys/savedata_factory.h"
  13. #include "core/hle/kernel/k_event.h"
  14. #include "core/hle/kernel/k_transfer_memory.h"
  15. #include "core/hle/result.h"
  16. #include "core/hle/service/acc/profile_manager.h"
  17. #include "core/hle/service/am/am.h"
  18. #include "core/hle/service/am/applet_ae.h"
  19. #include "core/hle/service/am/applet_oe.h"
  20. #include "core/hle/service/am/applets/applet_profile_select.h"
  21. #include "core/hle/service/am/applets/applet_web_browser.h"
  22. #include "core/hle/service/am/applets/applets.h"
  23. #include "core/hle/service/am/idle.h"
  24. #include "core/hle/service/am/omm.h"
  25. #include "core/hle/service/am/spsm.h"
  26. #include "core/hle/service/apm/apm_controller.h"
  27. #include "core/hle/service/apm/apm_interface.h"
  28. #include "core/hle/service/bcat/backend/backend.h"
  29. #include "core/hle/service/caps/caps.h"
  30. #include "core/hle/service/filesystem/filesystem.h"
  31. #include "core/hle/service/ipc_helpers.h"
  32. #include "core/hle/service/ns/ns.h"
  33. #include "core/hle/service/nvnflinger/nvnflinger.h"
  34. #include "core/hle/service/pm/pm.h"
  35. #include "core/hle/service/server_manager.h"
  36. #include "core/hle/service/sm/sm.h"
  37. #include "core/hle/service/vi/vi.h"
  38. #include "core/memory.h"
  39. namespace Service::AM {
  40. constexpr Result ResultNoDataInChannel{ErrorModule::AM, 2};
  41. constexpr Result ResultNoMessages{ErrorModule::AM, 3};
  42. constexpr Result ResultInvalidOffset{ErrorModule::AM, 503};
  43. enum class LaunchParameterKind : u32 {
  44. ApplicationSpecific = 1,
  45. AccountPreselectedUser = 2,
  46. };
  47. constexpr u32 LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC = 0xC79497CA;
  48. struct LaunchParameterAccountPreselectedUser {
  49. u32_le magic;
  50. u32_le is_account_selected;
  51. Common::UUID current_user;
  52. INSERT_PADDING_BYTES(0x70);
  53. };
  54. static_assert(sizeof(LaunchParameterAccountPreselectedUser) == 0x88);
  55. IWindowController::IWindowController(Core::System& system_)
  56. : ServiceFramework{system_, "IWindowController"} {
  57. // clang-format off
  58. static const FunctionInfo functions[] = {
  59. {0, nullptr, "CreateWindow"},
  60. {1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"},
  61. {2, nullptr, "GetAppletResourceUserIdOfCallerApplet"},
  62. {10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"},
  63. {11, nullptr, "ReleaseForegroundRights"},
  64. {12, nullptr, "RejectToChangeIntoBackground"},
  65. {20, nullptr, "SetAppletWindowVisibility"},
  66. {21, nullptr, "SetAppletGpuTimeSlice"},
  67. };
  68. // clang-format on
  69. RegisterHandlers(functions);
  70. }
  71. IWindowController::~IWindowController() = default;
  72. void IWindowController::GetAppletResourceUserId(HLERequestContext& ctx) {
  73. const u64 process_id = system.ApplicationProcess()->GetProcessId();
  74. LOG_DEBUG(Service_AM, "called. Process ID=0x{:016X}", process_id);
  75. IPC::ResponseBuilder rb{ctx, 4};
  76. rb.Push(ResultSuccess);
  77. rb.Push<u64>(process_id);
  78. }
  79. void IWindowController::AcquireForegroundRights(HLERequestContext& ctx) {
  80. LOG_WARNING(Service_AM, "(STUBBED) called");
  81. IPC::ResponseBuilder rb{ctx, 2};
  82. rb.Push(ResultSuccess);
  83. }
  84. IAudioController::IAudioController(Core::System& system_)
  85. : ServiceFramework{system_, "IAudioController"} {
  86. // clang-format off
  87. static const FunctionInfo functions[] = {
  88. {0, &IAudioController::SetExpectedMasterVolume, "SetExpectedMasterVolume"},
  89. {1, &IAudioController::GetMainAppletExpectedMasterVolume, "GetMainAppletExpectedMasterVolume"},
  90. {2, &IAudioController::GetLibraryAppletExpectedMasterVolume, "GetLibraryAppletExpectedMasterVolume"},
  91. {3, &IAudioController::ChangeMainAppletMasterVolume, "ChangeMainAppletMasterVolume"},
  92. {4, &IAudioController::SetTransparentAudioRate, "SetTransparentVolumeRate"},
  93. };
  94. // clang-format on
  95. RegisterHandlers(functions);
  96. }
  97. IAudioController::~IAudioController() = default;
  98. void IAudioController::SetExpectedMasterVolume(HLERequestContext& ctx) {
  99. IPC::RequestParser rp{ctx};
  100. const float main_applet_volume_tmp = rp.Pop<float>();
  101. const float library_applet_volume_tmp = rp.Pop<float>();
  102. LOG_DEBUG(Service_AM, "called. main_applet_volume={}, library_applet_volume={}",
  103. main_applet_volume_tmp, library_applet_volume_tmp);
  104. // Ensure the volume values remain within the 0-100% range
  105. main_applet_volume = std::clamp(main_applet_volume_tmp, min_allowed_volume, max_allowed_volume);
  106. library_applet_volume =
  107. std::clamp(library_applet_volume_tmp, min_allowed_volume, max_allowed_volume);
  108. IPC::ResponseBuilder rb{ctx, 2};
  109. rb.Push(ResultSuccess);
  110. }
  111. void IAudioController::GetMainAppletExpectedMasterVolume(HLERequestContext& ctx) {
  112. LOG_DEBUG(Service_AM, "called. main_applet_volume={}", main_applet_volume);
  113. IPC::ResponseBuilder rb{ctx, 3};
  114. rb.Push(ResultSuccess);
  115. rb.Push(main_applet_volume);
  116. }
  117. void IAudioController::GetLibraryAppletExpectedMasterVolume(HLERequestContext& ctx) {
  118. LOG_DEBUG(Service_AM, "called. library_applet_volume={}", library_applet_volume);
  119. IPC::ResponseBuilder rb{ctx, 3};
  120. rb.Push(ResultSuccess);
  121. rb.Push(library_applet_volume);
  122. }
  123. void IAudioController::ChangeMainAppletMasterVolume(HLERequestContext& ctx) {
  124. struct Parameters {
  125. float volume;
  126. s64 fade_time_ns;
  127. };
  128. static_assert(sizeof(Parameters) == 16);
  129. IPC::RequestParser rp{ctx};
  130. const auto parameters = rp.PopRaw<Parameters>();
  131. LOG_DEBUG(Service_AM, "called. volume={}, fade_time_ns={}", parameters.volume,
  132. parameters.fade_time_ns);
  133. main_applet_volume = std::clamp(parameters.volume, min_allowed_volume, max_allowed_volume);
  134. fade_time_ns = std::chrono::nanoseconds{parameters.fade_time_ns};
  135. IPC::ResponseBuilder rb{ctx, 2};
  136. rb.Push(ResultSuccess);
  137. }
  138. void IAudioController::SetTransparentAudioRate(HLERequestContext& ctx) {
  139. IPC::RequestParser rp{ctx};
  140. const float transparent_volume_rate_tmp = rp.Pop<float>();
  141. LOG_DEBUG(Service_AM, "called. transparent_volume_rate={}", transparent_volume_rate_tmp);
  142. // Clamp volume range to 0-100%.
  143. transparent_volume_rate =
  144. std::clamp(transparent_volume_rate_tmp, min_allowed_volume, max_allowed_volume);
  145. IPC::ResponseBuilder rb{ctx, 2};
  146. rb.Push(ResultSuccess);
  147. }
  148. IDisplayController::IDisplayController(Core::System& system_)
  149. : ServiceFramework{system_, "IDisplayController"} {
  150. // clang-format off
  151. static const FunctionInfo functions[] = {
  152. {0, nullptr, "GetLastForegroundCaptureImage"},
  153. {1, nullptr, "UpdateLastForegroundCaptureImage"},
  154. {2, nullptr, "GetLastApplicationCaptureImage"},
  155. {3, nullptr, "GetCallerAppletCaptureImage"},
  156. {4, nullptr, "UpdateCallerAppletCaptureImage"},
  157. {5, nullptr, "GetLastForegroundCaptureImageEx"},
  158. {6, nullptr, "GetLastApplicationCaptureImageEx"},
  159. {7, nullptr, "GetCallerAppletCaptureImageEx"},
  160. {8, nullptr, "TakeScreenShotOfOwnLayer"},
  161. {9, nullptr, "CopyBetweenCaptureBuffers"},
  162. {10, nullptr, "AcquireLastApplicationCaptureBuffer"},
  163. {11, nullptr, "ReleaseLastApplicationCaptureBuffer"},
  164. {12, nullptr, "AcquireLastForegroundCaptureBuffer"},
  165. {13, nullptr, "ReleaseLastForegroundCaptureBuffer"},
  166. {14, nullptr, "AcquireCallerAppletCaptureBuffer"},
  167. {15, nullptr, "ReleaseCallerAppletCaptureBuffer"},
  168. {16, nullptr, "AcquireLastApplicationCaptureBufferEx"},
  169. {17, nullptr, "AcquireLastForegroundCaptureBufferEx"},
  170. {18, nullptr, "AcquireCallerAppletCaptureBufferEx"},
  171. {20, nullptr, "ClearCaptureBuffer"},
  172. {21, nullptr, "ClearAppletTransitionBuffer"},
  173. {22, nullptr, "AcquireLastApplicationCaptureSharedBuffer"},
  174. {23, nullptr, "ReleaseLastApplicationCaptureSharedBuffer"},
  175. {24, nullptr, "AcquireLastForegroundCaptureSharedBuffer"},
  176. {25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"},
  177. {26, nullptr, "AcquireCallerAppletCaptureSharedBuffer"},
  178. {27, nullptr, "ReleaseCallerAppletCaptureSharedBuffer"},
  179. {28, nullptr, "TakeScreenShotOfOwnLayerEx"},
  180. };
  181. // clang-format on
  182. RegisterHandlers(functions);
  183. }
  184. IDisplayController::~IDisplayController() = default;
  185. IDebugFunctions::IDebugFunctions(Core::System& system_)
  186. : ServiceFramework{system_, "IDebugFunctions"} {
  187. // clang-format off
  188. static const FunctionInfo functions[] = {
  189. {0, nullptr, "NotifyMessageToHomeMenuForDebug"},
  190. {1, nullptr, "OpenMainApplication"},
  191. {10, nullptr, "PerformSystemButtonPressing"},
  192. {20, nullptr, "InvalidateTransitionLayer"},
  193. {30, nullptr, "RequestLaunchApplicationWithUserAndArgumentForDebug"},
  194. {31, nullptr, "RequestLaunchApplicationByApplicationLaunchInfoForDebug"},
  195. {40, nullptr, "GetAppletResourceUsageInfo"},
  196. {50, nullptr, "AddSystemProgramIdAndAppletIdForDebug"},
  197. {51, nullptr, "AddOperationConfirmedLibraryAppletIdForDebug"},
  198. {100, nullptr, "SetCpuBoostModeForApplet"},
  199. {101, nullptr, "CancelCpuBoostModeForApplet"},
  200. {110, nullptr, "PushToAppletBoundChannelForDebug"},
  201. {111, nullptr, "TryPopFromAppletBoundChannelForDebug"},
  202. {120, nullptr, "AlarmSettingNotificationEnableAppEventReserve"},
  203. {121, nullptr, "AlarmSettingNotificationDisableAppEventReserve"},
  204. {122, nullptr, "AlarmSettingNotificationPushAppEventNotify"},
  205. {130, nullptr, "FriendInvitationSetApplicationParameter"},
  206. {131, nullptr, "FriendInvitationClearApplicationParameter"},
  207. {132, nullptr, "FriendInvitationPushApplicationParameter"},
  208. {140, nullptr, "RestrictPowerOperationForSecureLaunchModeForDebug"},
  209. {200, nullptr, "CreateFloatingLibraryAppletAccepterForDebug"},
  210. {300, nullptr, "TerminateAllRunningApplicationsForDebug"},
  211. {900, nullptr, "GetGrcProcessLaunchedSystemEvent"},
  212. };
  213. // clang-format on
  214. RegisterHandlers(functions);
  215. }
  216. IDebugFunctions::~IDebugFunctions() = default;
  217. ISelfController::ISelfController(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger_)
  218. : ServiceFramework{system_, "ISelfController"}, nvnflinger{nvnflinger_},
  219. service_context{system, "ISelfController"} {
  220. // clang-format off
  221. static const FunctionInfo functions[] = {
  222. {0, &ISelfController::Exit, "Exit"},
  223. {1, &ISelfController::LockExit, "LockExit"},
  224. {2, &ISelfController::UnlockExit, "UnlockExit"},
  225. {3, &ISelfController::EnterFatalSection, "EnterFatalSection"},
  226. {4, &ISelfController::LeaveFatalSection, "LeaveFatalSection"},
  227. {9, &ISelfController::GetLibraryAppletLaunchableEvent, "GetLibraryAppletLaunchableEvent"},
  228. {10, &ISelfController::SetScreenShotPermission, "SetScreenShotPermission"},
  229. {11, &ISelfController::SetOperationModeChangedNotification, "SetOperationModeChangedNotification"},
  230. {12, &ISelfController::SetPerformanceModeChangedNotification, "SetPerformanceModeChangedNotification"},
  231. {13, &ISelfController::SetFocusHandlingMode, "SetFocusHandlingMode"},
  232. {14, &ISelfController::SetRestartMessageEnabled, "SetRestartMessageEnabled"},
  233. {15, nullptr, "SetScreenShotAppletIdentityInfo"},
  234. {16, &ISelfController::SetOutOfFocusSuspendingEnabled, "SetOutOfFocusSuspendingEnabled"},
  235. {17, nullptr, "SetControllerFirmwareUpdateSection"},
  236. {18, nullptr, "SetRequiresCaptureButtonShortPressedMessage"},
  237. {19, &ISelfController::SetAlbumImageOrientation, "SetAlbumImageOrientation"},
  238. {20, nullptr, "SetDesirableKeyboardLayout"},
  239. {21, nullptr, "GetScreenShotProgramId"},
  240. {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"},
  241. {41, nullptr, "IsSystemBufferSharingEnabled"},
  242. {42, nullptr, "GetSystemSharedLayerHandle"},
  243. {43, nullptr, "GetSystemSharedBufferHandle"},
  244. {44, &ISelfController::CreateManagedDisplaySeparableLayer, "CreateManagedDisplaySeparableLayer"},
  245. {45, nullptr, "SetManagedDisplayLayerSeparationMode"},
  246. {46, nullptr, "SetRecordingLayerCompositionEnabled"},
  247. {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"},
  248. {51, nullptr, "ApproveToDisplay"},
  249. {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"},
  250. {61, nullptr, "SetMediaPlaybackState"},
  251. {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"},
  252. {63, &ISelfController::GetIdleTimeDetectionExtension, "GetIdleTimeDetectionExtension"},
  253. {64, nullptr, "SetInputDetectionSourceSet"},
  254. {65, &ISelfController::ReportUserIsActive, "ReportUserIsActive"},
  255. {66, nullptr, "GetCurrentIlluminance"},
  256. {67, nullptr, "IsIlluminanceAvailable"},
  257. {68, &ISelfController::SetAutoSleepDisabled, "SetAutoSleepDisabled"},
  258. {69, &ISelfController::IsAutoSleepDisabled, "IsAutoSleepDisabled"},
  259. {70, nullptr, "ReportMultimediaError"},
  260. {71, nullptr, "GetCurrentIlluminanceEx"},
  261. {72, nullptr, "SetInputDetectionPolicy"},
  262. {80, nullptr, "SetWirelessPriorityMode"},
  263. {90, &ISelfController::GetAccumulatedSuspendedTickValue, "GetAccumulatedSuspendedTickValue"},
  264. {91, &ISelfController::GetAccumulatedSuspendedTickChangedEvent, "GetAccumulatedSuspendedTickChangedEvent"},
  265. {100, &ISelfController::SetAlbumImageTakenNotificationEnabled, "SetAlbumImageTakenNotificationEnabled"},
  266. {110, nullptr, "SetApplicationAlbumUserData"},
  267. {120, &ISelfController::SaveCurrentScreenshot, "SaveCurrentScreenshot"},
  268. {130, &ISelfController::SetRecordVolumeMuted, "SetRecordVolumeMuted"},
  269. {1000, nullptr, "GetDebugStorageChannel"},
  270. };
  271. // clang-format on
  272. RegisterHandlers(functions);
  273. launchable_event = service_context.CreateEvent("ISelfController:LaunchableEvent");
  274. // This event is created by AM on the first time GetAccumulatedSuspendedTickChangedEvent() is
  275. // called. Yuzu can just create it unconditionally, since it doesn't need to support multiple
  276. // ISelfControllers. The event is signaled on creation, and on transition from suspended -> not
  277. // suspended if the event has previously been created by a call to
  278. // GetAccumulatedSuspendedTickChangedEvent.
  279. accumulated_suspended_tick_changed_event =
  280. service_context.CreateEvent("ISelfController:AccumulatedSuspendedTickChangedEvent");
  281. accumulated_suspended_tick_changed_event->Signal();
  282. }
  283. ISelfController::~ISelfController() {
  284. service_context.CloseEvent(launchable_event);
  285. service_context.CloseEvent(accumulated_suspended_tick_changed_event);
  286. }
  287. void ISelfController::Exit(HLERequestContext& ctx) {
  288. LOG_DEBUG(Service_AM, "called");
  289. IPC::ResponseBuilder rb{ctx, 2};
  290. rb.Push(ResultSuccess);
  291. system.Exit();
  292. }
  293. void ISelfController::LockExit(HLERequestContext& ctx) {
  294. LOG_DEBUG(Service_AM, "called");
  295. system.SetExitLock(true);
  296. IPC::ResponseBuilder rb{ctx, 2};
  297. rb.Push(ResultSuccess);
  298. }
  299. void ISelfController::UnlockExit(HLERequestContext& ctx) {
  300. LOG_DEBUG(Service_AM, "called");
  301. system.SetExitLock(false);
  302. IPC::ResponseBuilder rb{ctx, 2};
  303. rb.Push(ResultSuccess);
  304. }
  305. void ISelfController::EnterFatalSection(HLERequestContext& ctx) {
  306. ++num_fatal_sections_entered;
  307. LOG_DEBUG(Service_AM, "called. Num fatal sections entered: {}", num_fatal_sections_entered);
  308. IPC::ResponseBuilder rb{ctx, 2};
  309. rb.Push(ResultSuccess);
  310. }
  311. void ISelfController::LeaveFatalSection(HLERequestContext& ctx) {
  312. LOG_DEBUG(Service_AM, "called.");
  313. // Entry and exit of fatal sections must be balanced.
  314. if (num_fatal_sections_entered == 0) {
  315. IPC::ResponseBuilder rb{ctx, 2};
  316. rb.Push(Result{ErrorModule::AM, 512});
  317. return;
  318. }
  319. --num_fatal_sections_entered;
  320. IPC::ResponseBuilder rb{ctx, 2};
  321. rb.Push(ResultSuccess);
  322. }
  323. void ISelfController::GetLibraryAppletLaunchableEvent(HLERequestContext& ctx) {
  324. LOG_WARNING(Service_AM, "(STUBBED) called");
  325. launchable_event->Signal();
  326. IPC::ResponseBuilder rb{ctx, 2, 1};
  327. rb.Push(ResultSuccess);
  328. rb.PushCopyObjects(launchable_event->GetReadableEvent());
  329. }
  330. void ISelfController::SetScreenShotPermission(HLERequestContext& ctx) {
  331. IPC::RequestParser rp{ctx};
  332. const auto permission = rp.PopEnum<ScreenshotPermission>();
  333. LOG_DEBUG(Service_AM, "called, permission={}", permission);
  334. screenshot_permission = permission;
  335. IPC::ResponseBuilder rb{ctx, 2};
  336. rb.Push(ResultSuccess);
  337. }
  338. void ISelfController::SetOperationModeChangedNotification(HLERequestContext& ctx) {
  339. IPC::RequestParser rp{ctx};
  340. bool flag = rp.Pop<bool>();
  341. LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  342. IPC::ResponseBuilder rb{ctx, 2};
  343. rb.Push(ResultSuccess);
  344. }
  345. void ISelfController::SetPerformanceModeChangedNotification(HLERequestContext& ctx) {
  346. IPC::RequestParser rp{ctx};
  347. bool flag = rp.Pop<bool>();
  348. LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  349. IPC::ResponseBuilder rb{ctx, 2};
  350. rb.Push(ResultSuccess);
  351. }
  352. void ISelfController::SetFocusHandlingMode(HLERequestContext& ctx) {
  353. // Takes 3 input u8s with each field located immediately after the previous
  354. // u8, these are bool flags. No output.
  355. IPC::RequestParser rp{ctx};
  356. struct FocusHandlingModeParams {
  357. u8 unknown0;
  358. u8 unknown1;
  359. u8 unknown2;
  360. };
  361. const auto flags = rp.PopRaw<FocusHandlingModeParams>();
  362. LOG_WARNING(Service_AM, "(STUBBED) called. unknown0={}, unknown1={}, unknown2={}",
  363. flags.unknown0, flags.unknown1, flags.unknown2);
  364. IPC::ResponseBuilder rb{ctx, 2};
  365. rb.Push(ResultSuccess);
  366. }
  367. void ISelfController::SetRestartMessageEnabled(HLERequestContext& ctx) {
  368. LOG_WARNING(Service_AM, "(STUBBED) called");
  369. IPC::ResponseBuilder rb{ctx, 2};
  370. rb.Push(ResultSuccess);
  371. }
  372. void ISelfController::SetOutOfFocusSuspendingEnabled(HLERequestContext& ctx) {
  373. // Takes 3 input u8s with each field located immediately after the previous
  374. // u8, these are bool flags. No output.
  375. IPC::RequestParser rp{ctx};
  376. bool enabled = rp.Pop<bool>();
  377. LOG_WARNING(Service_AM, "(STUBBED) called enabled={}", enabled);
  378. IPC::ResponseBuilder rb{ctx, 2};
  379. rb.Push(ResultSuccess);
  380. }
  381. void ISelfController::SetAlbumImageOrientation(HLERequestContext& ctx) {
  382. LOG_WARNING(Service_AM, "(STUBBED) called");
  383. IPC::ResponseBuilder rb{ctx, 2};
  384. rb.Push(ResultSuccess);
  385. }
  386. void ISelfController::CreateManagedDisplayLayer(HLERequestContext& ctx) {
  387. LOG_WARNING(Service_AM, "(STUBBED) called");
  388. // TODO(Subv): Find out how AM determines the display to use, for now just
  389. // create the layer in the Default display.
  390. const auto display_id = nvnflinger.OpenDisplay("Default");
  391. const auto layer_id = nvnflinger.CreateLayer(*display_id);
  392. IPC::ResponseBuilder rb{ctx, 4};
  393. rb.Push(ResultSuccess);
  394. rb.Push(*layer_id);
  395. }
  396. void ISelfController::CreateManagedDisplaySeparableLayer(HLERequestContext& ctx) {
  397. LOG_WARNING(Service_AM, "(STUBBED) called");
  398. // TODO(Subv): Find out how AM determines the display to use, for now just
  399. // create the layer in the Default display.
  400. // This calls nn::vi::CreateRecordingLayer() which creates another layer.
  401. // Currently we do not support more than 1 layer per display, output 1 layer id for now.
  402. // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse
  403. // side effects.
  404. // TODO: Support multiple layers
  405. const auto display_id = nvnflinger.OpenDisplay("Default");
  406. const auto layer_id = nvnflinger.CreateLayer(*display_id);
  407. IPC::ResponseBuilder rb{ctx, 4};
  408. rb.Push(ResultSuccess);
  409. rb.Push(*layer_id);
  410. }
  411. void ISelfController::SetHandlesRequestToDisplay(HLERequestContext& ctx) {
  412. LOG_WARNING(Service_AM, "(STUBBED) called");
  413. IPC::ResponseBuilder rb{ctx, 2};
  414. rb.Push(ResultSuccess);
  415. }
  416. void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) {
  417. IPC::RequestParser rp{ctx};
  418. idle_time_detection_extension = rp.Pop<u32>();
  419. LOG_DEBUG(Service_AM, "(STUBBED) called idle_time_detection_extension={}",
  420. idle_time_detection_extension);
  421. IPC::ResponseBuilder rb{ctx, 2};
  422. rb.Push(ResultSuccess);
  423. }
  424. void ISelfController::GetIdleTimeDetectionExtension(HLERequestContext& ctx) {
  425. LOG_WARNING(Service_AM, "(STUBBED) called");
  426. IPC::ResponseBuilder rb{ctx, 3};
  427. rb.Push(ResultSuccess);
  428. rb.Push<u32>(idle_time_detection_extension);
  429. }
  430. void ISelfController::ReportUserIsActive(HLERequestContext& ctx) {
  431. LOG_WARNING(Service_AM, "(STUBBED) called");
  432. IPC::ResponseBuilder rb{ctx, 2};
  433. rb.Push(ResultSuccess);
  434. }
  435. void ISelfController::SetAutoSleepDisabled(HLERequestContext& ctx) {
  436. IPC::RequestParser rp{ctx};
  437. is_auto_sleep_disabled = rp.Pop<bool>();
  438. // On the system itself, if the previous state of is_auto_sleep_disabled
  439. // differed from the current value passed in, it'd signify the internal
  440. // window manager to update (and also increment some statistics like update counts)
  441. //
  442. // It'd also indicate this change to an idle handling context.
  443. //
  444. // However, given we're emulating this behavior, most of this can be ignored
  445. // and it's sufficient to simply set the member variable for querying via
  446. // IsAutoSleepDisabled().
  447. LOG_DEBUG(Service_AM, "called. is_auto_sleep_disabled={}", is_auto_sleep_disabled);
  448. IPC::ResponseBuilder rb{ctx, 2};
  449. rb.Push(ResultSuccess);
  450. }
  451. void ISelfController::IsAutoSleepDisabled(HLERequestContext& ctx) {
  452. LOG_DEBUG(Service_AM, "called.");
  453. IPC::ResponseBuilder rb{ctx, 3};
  454. rb.Push(ResultSuccess);
  455. rb.Push(is_auto_sleep_disabled);
  456. }
  457. void ISelfController::GetAccumulatedSuspendedTickValue(HLERequestContext& ctx) {
  458. LOG_DEBUG(Service_AM, "called.");
  459. // This command returns the total number of system ticks since ISelfController creation
  460. // where the game was suspended. Since Yuzu doesn't implement game suspension, this command
  461. // can just always return 0 ticks.
  462. IPC::ResponseBuilder rb{ctx, 4};
  463. rb.Push(ResultSuccess);
  464. rb.Push<u64>(0);
  465. }
  466. void ISelfController::GetAccumulatedSuspendedTickChangedEvent(HLERequestContext& ctx) {
  467. LOG_DEBUG(Service_AM, "called.");
  468. IPC::ResponseBuilder rb{ctx, 2, 1};
  469. rb.Push(ResultSuccess);
  470. rb.PushCopyObjects(accumulated_suspended_tick_changed_event->GetReadableEvent());
  471. }
  472. void ISelfController::SetAlbumImageTakenNotificationEnabled(HLERequestContext& ctx) {
  473. IPC::RequestParser rp{ctx};
  474. // This service call sets an internal flag whether a notification is shown when an image is
  475. // captured. Currently we do not support capturing images via the capture button, so this can be
  476. // stubbed for now.
  477. const bool album_image_taken_notification_enabled = rp.Pop<bool>();
  478. LOG_WARNING(Service_AM, "(STUBBED) called. album_image_taken_notification_enabled={}",
  479. album_image_taken_notification_enabled);
  480. IPC::ResponseBuilder rb{ctx, 2};
  481. rb.Push(ResultSuccess);
  482. }
  483. void ISelfController::SaveCurrentScreenshot(HLERequestContext& ctx) {
  484. IPC::RequestParser rp{ctx};
  485. const auto album_report_option = rp.PopEnum<Capture::AlbumReportOption>();
  486. LOG_WARNING(Service_AM, "(STUBBED) called. album_report_option={}", album_report_option);
  487. IPC::ResponseBuilder rb{ctx, 2};
  488. rb.Push(ResultSuccess);
  489. }
  490. void ISelfController::SetRecordVolumeMuted(HLERequestContext& ctx) {
  491. IPC::RequestParser rp{ctx};
  492. const auto is_record_volume_muted = rp.Pop<bool>();
  493. LOG_WARNING(Service_AM, "(STUBBED) called. is_record_volume_muted={}", is_record_volume_muted);
  494. IPC::ResponseBuilder rb{ctx, 2};
  495. rb.Push(ResultSuccess);
  496. }
  497. AppletMessageQueue::AppletMessageQueue(Core::System& system)
  498. : service_context{system, "AppletMessageQueue"} {
  499. on_new_message = service_context.CreateEvent("AMMessageQueue:OnMessageReceived");
  500. on_operation_mode_changed = service_context.CreateEvent("AMMessageQueue:OperationModeChanged");
  501. }
  502. AppletMessageQueue::~AppletMessageQueue() {
  503. service_context.CloseEvent(on_new_message);
  504. service_context.CloseEvent(on_operation_mode_changed);
  505. }
  506. Kernel::KReadableEvent& AppletMessageQueue::GetMessageReceiveEvent() {
  507. return on_new_message->GetReadableEvent();
  508. }
  509. Kernel::KReadableEvent& AppletMessageQueue::GetOperationModeChangedEvent() {
  510. return on_operation_mode_changed->GetReadableEvent();
  511. }
  512. void AppletMessageQueue::PushMessage(AppletMessage msg) {
  513. messages.push(msg);
  514. on_new_message->Signal();
  515. }
  516. AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() {
  517. if (messages.empty()) {
  518. on_new_message->Clear();
  519. return AppletMessage::None;
  520. }
  521. auto msg = messages.front();
  522. messages.pop();
  523. if (messages.empty()) {
  524. on_new_message->Clear();
  525. }
  526. return msg;
  527. }
  528. std::size_t AppletMessageQueue::GetMessageCount() const {
  529. return messages.size();
  530. }
  531. void AppletMessageQueue::RequestExit() {
  532. PushMessage(AppletMessage::Exit);
  533. }
  534. void AppletMessageQueue::RequestResume() {
  535. PushMessage(AppletMessage::Resume);
  536. }
  537. void AppletMessageQueue::FocusStateChanged() {
  538. PushMessage(AppletMessage::FocusStateChanged);
  539. }
  540. void AppletMessageQueue::OperationModeChanged() {
  541. PushMessage(AppletMessage::OperationModeChanged);
  542. PushMessage(AppletMessage::PerformanceModeChanged);
  543. on_operation_mode_changed->Signal();
  544. }
  545. ICommonStateGetter::ICommonStateGetter(Core::System& system_,
  546. std::shared_ptr<AppletMessageQueue> msg_queue_)
  547. : ServiceFramework{system_, "ICommonStateGetter"}, msg_queue{std::move(msg_queue_)} {
  548. // clang-format off
  549. static const FunctionInfo functions[] = {
  550. {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
  551. {1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"},
  552. {2, nullptr, "GetThisAppletKind"},
  553. {3, nullptr, "AllowToEnterSleep"},
  554. {4, nullptr, "DisallowToEnterSleep"},
  555. {5, &ICommonStateGetter::GetOperationMode, "GetOperationMode"},
  556. {6, &ICommonStateGetter::GetPerformanceMode, "GetPerformanceMode"},
  557. {7, nullptr, "GetCradleStatus"},
  558. {8, &ICommonStateGetter::GetBootMode, "GetBootMode"},
  559. {9, &ICommonStateGetter::GetCurrentFocusState, "GetCurrentFocusState"},
  560. {10, nullptr, "RequestToAcquireSleepLock"},
  561. {11, nullptr, "ReleaseSleepLock"},
  562. {12, nullptr, "ReleaseSleepLockTransiently"},
  563. {13, nullptr, "GetAcquiredSleepLockEvent"},
  564. {14, nullptr, "GetWakeupCount"},
  565. {20, nullptr, "PushToGeneralChannel"},
  566. {30, nullptr, "GetHomeButtonReaderLockAccessor"},
  567. {31, nullptr, "GetReaderLockAccessorEx"},
  568. {32, nullptr, "GetWriterLockAccessorEx"},
  569. {40, nullptr, "GetCradleFwVersion"},
  570. {50, &ICommonStateGetter::IsVrModeEnabled, "IsVrModeEnabled"},
  571. {51, &ICommonStateGetter::SetVrModeEnabled, "SetVrModeEnabled"},
  572. {52, &ICommonStateGetter::SetLcdBacklighOffEnabled, "SetLcdBacklighOffEnabled"},
  573. {53, &ICommonStateGetter::BeginVrModeEx, "BeginVrModeEx"},
  574. {54, &ICommonStateGetter::EndVrModeEx, "EndVrModeEx"},
  575. {55, nullptr, "IsInControllerFirmwareUpdateSection"},
  576. {59, nullptr, "SetVrPositionForDebug"},
  577. {60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"},
  578. {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, "GetDefaultDisplayResolutionChangeEvent"},
  579. {62, nullptr, "GetHdcpAuthenticationState"},
  580. {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"},
  581. {64, nullptr, "SetTvPowerStateMatchingMode"},
  582. {65, nullptr, "GetApplicationIdByContentActionName"},
  583. {66, &ICommonStateGetter::SetCpuBoostMode, "SetCpuBoostMode"},
  584. {67, nullptr, "CancelCpuBoostMode"},
  585. {68, nullptr, "GetBuiltInDisplayType"},
  586. {80, &ICommonStateGetter::PerformSystemButtonPressingIfInFocus, "PerformSystemButtonPressingIfInFocus"},
  587. {90, nullptr, "SetPerformanceConfigurationChangedNotification"},
  588. {91, nullptr, "GetCurrentPerformanceConfiguration"},
  589. {100, nullptr, "SetHandlingHomeButtonShortPressedEnabled"},
  590. {110, nullptr, "OpenMyGpuErrorHandler"},
  591. {120, nullptr, "GetAppletLaunchedHistory"},
  592. {200, nullptr, "GetOperationModeSystemInfo"},
  593. {300, nullptr, "GetSettingsPlatformRegion"},
  594. {400, nullptr, "ActivateMigrationService"},
  595. {401, nullptr, "DeactivateMigrationService"},
  596. {500, nullptr, "DisableSleepTillShutdown"},
  597. {501, nullptr, "SuppressDisablingSleepTemporarily"},
  598. {502, nullptr, "IsSleepEnabled"},
  599. {503, nullptr, "IsDisablingSleepSuppressed"},
  600. {900, &ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled, "SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled"},
  601. };
  602. // clang-format on
  603. RegisterHandlers(functions);
  604. }
  605. ICommonStateGetter::~ICommonStateGetter() = default;
  606. void ICommonStateGetter::GetBootMode(HLERequestContext& ctx) {
  607. LOG_DEBUG(Service_AM, "called");
  608. IPC::ResponseBuilder rb{ctx, 3};
  609. rb.Push(ResultSuccess);
  610. rb.Push<u8>(static_cast<u8>(Service::PM::SystemBootMode::Normal)); // Normal boot mode
  611. }
  612. void ICommonStateGetter::GetEventHandle(HLERequestContext& ctx) {
  613. LOG_DEBUG(Service_AM, "called");
  614. IPC::ResponseBuilder rb{ctx, 2, 1};
  615. rb.Push(ResultSuccess);
  616. rb.PushCopyObjects(msg_queue->GetMessageReceiveEvent());
  617. }
  618. void ICommonStateGetter::ReceiveMessage(HLERequestContext& ctx) {
  619. LOG_DEBUG(Service_AM, "called");
  620. const auto message = msg_queue->PopMessage();
  621. IPC::ResponseBuilder rb{ctx, 3};
  622. if (message == AppletMessageQueue::AppletMessage::None) {
  623. LOG_ERROR(Service_AM, "Message queue is empty");
  624. rb.Push(AM::ResultNoMessages);
  625. rb.PushEnum<AppletMessageQueue::AppletMessage>(message);
  626. return;
  627. }
  628. rb.Push(ResultSuccess);
  629. rb.PushEnum<AppletMessageQueue::AppletMessage>(message);
  630. }
  631. void ICommonStateGetter::GetCurrentFocusState(HLERequestContext& ctx) {
  632. LOG_DEBUG(Service_AM, "(STUBBED) called");
  633. IPC::ResponseBuilder rb{ctx, 3};
  634. rb.Push(ResultSuccess);
  635. rb.Push(static_cast<u8>(FocusState::InFocus));
  636. }
  637. void ICommonStateGetter::IsVrModeEnabled(HLERequestContext& ctx) {
  638. LOG_DEBUG(Service_AM, "called");
  639. IPC::ResponseBuilder rb{ctx, 3};
  640. rb.Push(ResultSuccess);
  641. rb.Push(vr_mode_state);
  642. }
  643. void ICommonStateGetter::SetVrModeEnabled(HLERequestContext& ctx) {
  644. IPC::RequestParser rp{ctx};
  645. vr_mode_state = rp.Pop<bool>();
  646. LOG_WARNING(Service_AM, "VR Mode is {}", vr_mode_state ? "on" : "off");
  647. IPC::ResponseBuilder rb{ctx, 2};
  648. rb.Push(ResultSuccess);
  649. }
  650. void ICommonStateGetter::SetLcdBacklighOffEnabled(HLERequestContext& ctx) {
  651. IPC::RequestParser rp{ctx};
  652. const auto is_lcd_backlight_off_enabled = rp.Pop<bool>();
  653. LOG_WARNING(Service_AM, "(STUBBED) called. is_lcd_backlight_off_enabled={}",
  654. is_lcd_backlight_off_enabled);
  655. IPC::ResponseBuilder rb{ctx, 2};
  656. rb.Push(ResultSuccess);
  657. }
  658. void ICommonStateGetter::BeginVrModeEx(HLERequestContext& ctx) {
  659. LOG_WARNING(Service_AM, "(STUBBED) called");
  660. IPC::ResponseBuilder rb{ctx, 2};
  661. rb.Push(ResultSuccess);
  662. }
  663. void ICommonStateGetter::EndVrModeEx(HLERequestContext& ctx) {
  664. LOG_WARNING(Service_AM, "(STUBBED) called");
  665. IPC::ResponseBuilder rb{ctx, 2};
  666. rb.Push(ResultSuccess);
  667. }
  668. void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx) {
  669. LOG_DEBUG(Service_AM, "called");
  670. IPC::ResponseBuilder rb{ctx, 2, 1};
  671. rb.Push(ResultSuccess);
  672. rb.PushCopyObjects(msg_queue->GetOperationModeChangedEvent());
  673. }
  674. void ICommonStateGetter::GetDefaultDisplayResolution(HLERequestContext& ctx) {
  675. LOG_DEBUG(Service_AM, "called");
  676. IPC::ResponseBuilder rb{ctx, 4};
  677. rb.Push(ResultSuccess);
  678. if (Settings::values.use_docked_mode.GetValue()) {
  679. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedWidth));
  680. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedHeight));
  681. } else {
  682. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedWidth));
  683. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedHeight));
  684. }
  685. }
  686. void ICommonStateGetter::SetCpuBoostMode(HLERequestContext& ctx) {
  687. LOG_DEBUG(Service_AM, "called, forwarding to APM:SYS");
  688. const auto& sm = system.ServiceManager();
  689. const auto apm_sys = sm.GetService<APM::APM_Sys>("apm:sys");
  690. ASSERT(apm_sys != nullptr);
  691. apm_sys->SetCpuBoostMode(ctx);
  692. }
  693. void ICommonStateGetter::PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx) {
  694. IPC::RequestParser rp{ctx};
  695. const auto system_button{rp.PopEnum<SystemButtonType>()};
  696. LOG_WARNING(Service_AM, "(STUBBED) called, system_button={}", system_button);
  697. IPC::ResponseBuilder rb{ctx, 2};
  698. rb.Push(ResultSuccess);
  699. }
  700. void ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(
  701. HLERequestContext& ctx) {
  702. LOG_WARNING(Service_AM, "(STUBBED) called");
  703. IPC::ResponseBuilder rb{ctx, 2};
  704. rb.Push(ResultSuccess);
  705. }
  706. IStorageImpl::~IStorageImpl() = default;
  707. class StorageDataImpl final : public IStorageImpl {
  708. public:
  709. explicit StorageDataImpl(std::vector<u8>&& buffer_) : buffer{std::move(buffer_)} {}
  710. std::vector<u8>& GetData() override {
  711. return buffer;
  712. }
  713. const std::vector<u8>& GetData() const override {
  714. return buffer;
  715. }
  716. std::size_t GetSize() const override {
  717. return buffer.size();
  718. }
  719. private:
  720. std::vector<u8> buffer;
  721. };
  722. IStorage::IStorage(Core::System& system_, std::vector<u8>&& buffer)
  723. : ServiceFramework{system_, "IStorage"}, impl{std::make_shared<StorageDataImpl>(
  724. std::move(buffer))} {
  725. Register();
  726. }
  727. void IStorage::Register() {
  728. // clang-format off
  729. static const FunctionInfo functions[] = {
  730. {0, &IStorage::Open, "Open"},
  731. {1, nullptr, "OpenTransferStorage"},
  732. };
  733. // clang-format on
  734. RegisterHandlers(functions);
  735. }
  736. IStorage::~IStorage() = default;
  737. void IStorage::Open(HLERequestContext& ctx) {
  738. LOG_DEBUG(Service_AM, "called");
  739. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  740. rb.Push(ResultSuccess);
  741. rb.PushIpcInterface<IStorageAccessor>(system, *this);
  742. }
  743. void ICommonStateGetter::GetOperationMode(HLERequestContext& ctx) {
  744. const bool use_docked_mode{Settings::values.use_docked_mode.GetValue()};
  745. LOG_DEBUG(Service_AM, "called, use_docked_mode={}", use_docked_mode);
  746. IPC::ResponseBuilder rb{ctx, 3};
  747. rb.Push(ResultSuccess);
  748. rb.Push(static_cast<u8>(use_docked_mode ? OperationMode::Docked : OperationMode::Handheld));
  749. }
  750. void ICommonStateGetter::GetPerformanceMode(HLERequestContext& ctx) {
  751. LOG_DEBUG(Service_AM, "called");
  752. IPC::ResponseBuilder rb{ctx, 3};
  753. rb.Push(ResultSuccess);
  754. rb.PushEnum(system.GetAPMController().GetCurrentPerformanceMode());
  755. }
  756. class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
  757. public:
  758. explicit ILibraryAppletAccessor(Core::System& system_, std::shared_ptr<Applets::Applet> applet_)
  759. : ServiceFramework{system_, "ILibraryAppletAccessor"}, applet{std::move(applet_)} {
  760. // clang-format off
  761. static const FunctionInfo functions[] = {
  762. {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
  763. {1, &ILibraryAppletAccessor::IsCompleted, "IsCompleted"},
  764. {10, &ILibraryAppletAccessor::Start, "Start"},
  765. {20, &ILibraryAppletAccessor::RequestExit, "RequestExit"},
  766. {25, nullptr, "Terminate"},
  767. {30, &ILibraryAppletAccessor::GetResult, "GetResult"},
  768. {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"},
  769. {60, &ILibraryAppletAccessor::PresetLibraryAppletGpuTimeSliceZero, "PresetLibraryAppletGpuTimeSliceZero"},
  770. {100, &ILibraryAppletAccessor::PushInData, "PushInData"},
  771. {101, &ILibraryAppletAccessor::PopOutData, "PopOutData"},
  772. {102, nullptr, "PushExtraStorage"},
  773. {103, &ILibraryAppletAccessor::PushInteractiveInData, "PushInteractiveInData"},
  774. {104, &ILibraryAppletAccessor::PopInteractiveOutData, "PopInteractiveOutData"},
  775. {105, &ILibraryAppletAccessor::GetPopOutDataEvent, "GetPopOutDataEvent"},
  776. {106, &ILibraryAppletAccessor::GetPopInteractiveOutDataEvent, "GetPopInteractiveOutDataEvent"},
  777. {110, nullptr, "NeedsToExitProcess"},
  778. {120, nullptr, "GetLibraryAppletInfo"},
  779. {150, nullptr, "RequestForAppletToGetForeground"},
  780. {160, &ILibraryAppletAccessor::GetIndirectLayerConsumerHandle, "GetIndirectLayerConsumerHandle"},
  781. };
  782. // clang-format on
  783. RegisterHandlers(functions);
  784. }
  785. private:
  786. void GetAppletStateChangedEvent(HLERequestContext& ctx) {
  787. LOG_DEBUG(Service_AM, "called");
  788. IPC::ResponseBuilder rb{ctx, 2, 1};
  789. rb.Push(ResultSuccess);
  790. rb.PushCopyObjects(applet->GetBroker().GetStateChangedEvent());
  791. }
  792. void IsCompleted(HLERequestContext& ctx) {
  793. LOG_DEBUG(Service_AM, "called");
  794. IPC::ResponseBuilder rb{ctx, 3};
  795. rb.Push(ResultSuccess);
  796. rb.Push<u32>(applet->TransactionComplete());
  797. }
  798. void GetResult(HLERequestContext& ctx) {
  799. LOG_DEBUG(Service_AM, "called");
  800. IPC::ResponseBuilder rb{ctx, 2};
  801. rb.Push(applet->GetStatus());
  802. }
  803. void PresetLibraryAppletGpuTimeSliceZero(HLERequestContext& ctx) {
  804. LOG_WARNING(Service_AM, "(STUBBED) called");
  805. IPC::ResponseBuilder rb{ctx, 2};
  806. rb.Push(ResultSuccess);
  807. }
  808. void Start(HLERequestContext& ctx) {
  809. LOG_DEBUG(Service_AM, "called");
  810. ASSERT(applet != nullptr);
  811. applet->Initialize();
  812. applet->Execute();
  813. IPC::ResponseBuilder rb{ctx, 2};
  814. rb.Push(ResultSuccess);
  815. }
  816. void RequestExit(HLERequestContext& ctx) {
  817. LOG_DEBUG(Service_AM, "called");
  818. ASSERT(applet != nullptr);
  819. IPC::ResponseBuilder rb{ctx, 2};
  820. rb.Push(applet->RequestExit());
  821. }
  822. void PushInData(HLERequestContext& ctx) {
  823. LOG_DEBUG(Service_AM, "called");
  824. IPC::RequestParser rp{ctx};
  825. applet->GetBroker().PushNormalDataFromGame(rp.PopIpcInterface<IStorage>().lock());
  826. IPC::ResponseBuilder rb{ctx, 2};
  827. rb.Push(ResultSuccess);
  828. }
  829. void PopOutData(HLERequestContext& ctx) {
  830. LOG_DEBUG(Service_AM, "called");
  831. auto storage = applet->GetBroker().PopNormalDataToGame();
  832. if (storage == nullptr) {
  833. LOG_DEBUG(Service_AM,
  834. "storage is a nullptr. There is no data in the current normal channel");
  835. IPC::ResponseBuilder rb{ctx, 2};
  836. rb.Push(AM::ResultNoDataInChannel);
  837. return;
  838. }
  839. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  840. rb.Push(ResultSuccess);
  841. rb.PushIpcInterface<IStorage>(std::move(storage));
  842. }
  843. void PushInteractiveInData(HLERequestContext& ctx) {
  844. LOG_DEBUG(Service_AM, "called");
  845. IPC::RequestParser rp{ctx};
  846. applet->GetBroker().PushInteractiveDataFromGame(rp.PopIpcInterface<IStorage>().lock());
  847. ASSERT(applet->IsInitialized());
  848. applet->ExecuteInteractive();
  849. applet->Execute();
  850. IPC::ResponseBuilder rb{ctx, 2};
  851. rb.Push(ResultSuccess);
  852. }
  853. void PopInteractiveOutData(HLERequestContext& ctx) {
  854. LOG_DEBUG(Service_AM, "called");
  855. auto storage = applet->GetBroker().PopInteractiveDataToGame();
  856. if (storage == nullptr) {
  857. LOG_DEBUG(Service_AM,
  858. "storage is a nullptr. There is no data in the current interactive channel");
  859. IPC::ResponseBuilder rb{ctx, 2};
  860. rb.Push(AM::ResultNoDataInChannel);
  861. return;
  862. }
  863. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  864. rb.Push(ResultSuccess);
  865. rb.PushIpcInterface<IStorage>(std::move(storage));
  866. }
  867. void GetPopOutDataEvent(HLERequestContext& ctx) {
  868. LOG_DEBUG(Service_AM, "called");
  869. IPC::ResponseBuilder rb{ctx, 2, 1};
  870. rb.Push(ResultSuccess);
  871. rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent());
  872. }
  873. void GetPopInteractiveOutDataEvent(HLERequestContext& ctx) {
  874. LOG_DEBUG(Service_AM, "called");
  875. IPC::ResponseBuilder rb{ctx, 2, 1};
  876. rb.Push(ResultSuccess);
  877. rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent());
  878. }
  879. void GetIndirectLayerConsumerHandle(HLERequestContext& ctx) {
  880. LOG_WARNING(Service_AM, "(STUBBED) called");
  881. // We require a non-zero handle to be valid. Using 0xdeadbeef allows us to trace if this is
  882. // actually used anywhere
  883. constexpr u64 handle = 0xdeadbeef;
  884. IPC::ResponseBuilder rb{ctx, 4};
  885. rb.Push(ResultSuccess);
  886. rb.Push(handle);
  887. }
  888. std::shared_ptr<Applets::Applet> applet;
  889. };
  890. IStorageAccessor::IStorageAccessor(Core::System& system_, IStorage& backing_)
  891. : ServiceFramework{system_, "IStorageAccessor"}, backing{backing_} {
  892. // clang-format off
  893. static const FunctionInfo functions[] = {
  894. {0, &IStorageAccessor::GetSize, "GetSize"},
  895. {10, &IStorageAccessor::Write, "Write"},
  896. {11, &IStorageAccessor::Read, "Read"},
  897. };
  898. // clang-format on
  899. RegisterHandlers(functions);
  900. }
  901. IStorageAccessor::~IStorageAccessor() = default;
  902. void IStorageAccessor::GetSize(HLERequestContext& ctx) {
  903. LOG_DEBUG(Service_AM, "called");
  904. IPC::ResponseBuilder rb{ctx, 4};
  905. rb.Push(ResultSuccess);
  906. rb.Push(static_cast<u64>(backing.GetSize()));
  907. }
  908. void IStorageAccessor::Write(HLERequestContext& ctx) {
  909. IPC::RequestParser rp{ctx};
  910. const u64 offset{rp.Pop<u64>()};
  911. const auto data{ctx.ReadBuffer()};
  912. const std::size_t size{std::min<u64>(data.size(), backing.GetSize() - offset)};
  913. LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
  914. if (offset > backing.GetSize()) {
  915. LOG_ERROR(Service_AM,
  916. "offset is out of bounds, backing_buffer_sz={}, data_size={}, offset={}",
  917. backing.GetSize(), size, offset);
  918. IPC::ResponseBuilder rb{ctx, 2};
  919. rb.Push(AM::ResultInvalidOffset);
  920. return;
  921. }
  922. std::memcpy(backing.GetData().data() + offset, data.data(), size);
  923. IPC::ResponseBuilder rb{ctx, 2};
  924. rb.Push(ResultSuccess);
  925. }
  926. void IStorageAccessor::Read(HLERequestContext& ctx) {
  927. IPC::RequestParser rp{ctx};
  928. const u64 offset{rp.Pop<u64>()};
  929. const std::size_t size{std::min<u64>(ctx.GetWriteBufferSize(), backing.GetSize() - offset)};
  930. LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
  931. if (offset > backing.GetSize()) {
  932. LOG_ERROR(Service_AM, "offset is out of bounds, backing_buffer_sz={}, size={}, offset={}",
  933. backing.GetSize(), size, offset);
  934. IPC::ResponseBuilder rb{ctx, 2};
  935. rb.Push(AM::ResultInvalidOffset);
  936. return;
  937. }
  938. ctx.WriteBuffer(backing.GetData().data() + offset, size);
  939. IPC::ResponseBuilder rb{ctx, 2};
  940. rb.Push(ResultSuccess);
  941. }
  942. ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_)
  943. : ServiceFramework{system_, "ILibraryAppletCreator"} {
  944. static const FunctionInfo functions[] = {
  945. {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"},
  946. {1, nullptr, "TerminateAllLibraryApplets"},
  947. {2, nullptr, "AreAnyLibraryAppletsLeft"},
  948. {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"},
  949. {11, &ILibraryAppletCreator::CreateTransferMemoryStorage, "CreateTransferMemoryStorage"},
  950. {12, &ILibraryAppletCreator::CreateHandleStorage, "CreateHandleStorage"},
  951. };
  952. RegisterHandlers(functions);
  953. }
  954. ILibraryAppletCreator::~ILibraryAppletCreator() = default;
  955. void ILibraryAppletCreator::CreateLibraryApplet(HLERequestContext& ctx) {
  956. IPC::RequestParser rp{ctx};
  957. const auto applet_id = rp.PopRaw<Applets::AppletId>();
  958. const auto applet_mode = rp.PopRaw<Applets::LibraryAppletMode>();
  959. LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}", applet_id,
  960. applet_mode);
  961. const auto& applet_manager{system.GetAppletManager()};
  962. const auto applet = applet_manager.GetApplet(applet_id, applet_mode);
  963. if (applet == nullptr) {
  964. LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id);
  965. IPC::ResponseBuilder rb{ctx, 2};
  966. rb.Push(ResultUnknown);
  967. return;
  968. }
  969. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  970. rb.Push(ResultSuccess);
  971. rb.PushIpcInterface<ILibraryAppletAccessor>(system, applet);
  972. }
  973. void ILibraryAppletCreator::CreateStorage(HLERequestContext& ctx) {
  974. IPC::RequestParser rp{ctx};
  975. const s64 size{rp.Pop<s64>()};
  976. LOG_DEBUG(Service_AM, "called, size={}", size);
  977. if (size <= 0) {
  978. LOG_ERROR(Service_AM, "size is less than or equal to 0");
  979. IPC::ResponseBuilder rb{ctx, 2};
  980. rb.Push(ResultUnknown);
  981. return;
  982. }
  983. std::vector<u8> buffer(size);
  984. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  985. rb.Push(ResultSuccess);
  986. rb.PushIpcInterface<IStorage>(system, std::move(buffer));
  987. }
  988. void ILibraryAppletCreator::CreateTransferMemoryStorage(HLERequestContext& ctx) {
  989. IPC::RequestParser rp{ctx};
  990. struct Parameters {
  991. u8 permissions;
  992. s64 size;
  993. };
  994. const auto parameters{rp.PopRaw<Parameters>()};
  995. const auto handle{ctx.GetCopyHandle(0)};
  996. LOG_DEBUG(Service_AM, "called, permissions={}, size={}, handle={:08X}", parameters.permissions,
  997. parameters.size, handle);
  998. if (parameters.size <= 0) {
  999. LOG_ERROR(Service_AM, "size is less than or equal to 0");
  1000. IPC::ResponseBuilder rb{ctx, 2};
  1001. rb.Push(ResultUnknown);
  1002. return;
  1003. }
  1004. auto transfer_mem =
  1005. system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>(handle);
  1006. if (transfer_mem.IsNull()) {
  1007. LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle);
  1008. IPC::ResponseBuilder rb{ctx, 2};
  1009. rb.Push(ResultUnknown);
  1010. return;
  1011. }
  1012. std::vector<u8> memory(transfer_mem->GetSize());
  1013. system.ApplicationMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(),
  1014. memory.size());
  1015. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  1016. rb.Push(ResultSuccess);
  1017. rb.PushIpcInterface<IStorage>(system, std::move(memory));
  1018. }
  1019. void ILibraryAppletCreator::CreateHandleStorage(HLERequestContext& ctx) {
  1020. IPC::RequestParser rp{ctx};
  1021. const s64 size{rp.Pop<s64>()};
  1022. const auto handle{ctx.GetCopyHandle(0)};
  1023. LOG_DEBUG(Service_AM, "called, size={}, handle={:08X}", size, handle);
  1024. if (size <= 0) {
  1025. LOG_ERROR(Service_AM, "size is less than or equal to 0");
  1026. IPC::ResponseBuilder rb{ctx, 2};
  1027. rb.Push(ResultUnknown);
  1028. return;
  1029. }
  1030. auto transfer_mem =
  1031. system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>(handle);
  1032. if (transfer_mem.IsNull()) {
  1033. LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle);
  1034. IPC::ResponseBuilder rb{ctx, 2};
  1035. rb.Push(ResultUnknown);
  1036. return;
  1037. }
  1038. std::vector<u8> memory(transfer_mem->GetSize());
  1039. system.ApplicationMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(),
  1040. memory.size());
  1041. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  1042. rb.Push(ResultSuccess);
  1043. rb.PushIpcInterface<IStorage>(system, std::move(memory));
  1044. }
  1045. IApplicationFunctions::IApplicationFunctions(Core::System& system_)
  1046. : ServiceFramework{system_, "IApplicationFunctions"}, service_context{system,
  1047. "IApplicationFunctions"} {
  1048. // clang-format off
  1049. static const FunctionInfo functions[] = {
  1050. {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
  1051. {10, nullptr, "CreateApplicationAndPushAndRequestToStart"},
  1052. {11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"},
  1053. {12, nullptr, "CreateApplicationAndRequestToStart"},
  1054. {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest, "CreateApplicationAndRequestToStartForQuest"},
  1055. {14, nullptr, "CreateApplicationWithAttributeAndPushAndRequestToStartForQuest"},
  1056. {15, nullptr, "CreateApplicationWithAttributeAndRequestToStartForQuest"},
  1057. {20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"},
  1058. {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"},
  1059. {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"},
  1060. {23, &IApplicationFunctions::GetDisplayVersion, "GetDisplayVersion"},
  1061. {24, nullptr, "GetLaunchStorageInfoForDebug"},
  1062. {25, &IApplicationFunctions::ExtendSaveData, "ExtendSaveData"},
  1063. {26, &IApplicationFunctions::GetSaveDataSize, "GetSaveDataSize"},
  1064. {27, &IApplicationFunctions::CreateCacheStorage, "CreateCacheStorage"},
  1065. {28, nullptr, "GetSaveDataSizeMax"},
  1066. {29, nullptr, "GetCacheStorageMax"},
  1067. {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed, "BeginBlockingHomeButtonShortAndLongPressed"},
  1068. {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed, "EndBlockingHomeButtonShortAndLongPressed"},
  1069. {32, &IApplicationFunctions::BeginBlockingHomeButton, "BeginBlockingHomeButton"},
  1070. {33, &IApplicationFunctions::EndBlockingHomeButton, "EndBlockingHomeButton"},
  1071. {34, nullptr, "SelectApplicationLicense"},
  1072. {35, nullptr, "GetDeviceSaveDataSizeMax"},
  1073. {36, nullptr, "GetLimitedApplicationLicense"},
  1074. {37, nullptr, "GetLimitedApplicationLicenseUpgradableEvent"},
  1075. {40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"},
  1076. {50, &IApplicationFunctions::GetPseudoDeviceId, "GetPseudoDeviceId"},
  1077. {60, nullptr, "SetMediaPlaybackStateForApplication"},
  1078. {65, &IApplicationFunctions::IsGamePlayRecordingSupported, "IsGamePlayRecordingSupported"},
  1079. {66, &IApplicationFunctions::InitializeGamePlayRecording, "InitializeGamePlayRecording"},
  1080. {67, &IApplicationFunctions::SetGamePlayRecordingState, "SetGamePlayRecordingState"},
  1081. {68, nullptr, "RequestFlushGamePlayingMovieForDebug"},
  1082. {70, nullptr, "RequestToShutdown"},
  1083. {71, nullptr, "RequestToReboot"},
  1084. {72, nullptr, "RequestToSleep"},
  1085. {80, nullptr, "ExitAndRequestToShowThanksMessage"},
  1086. {90, &IApplicationFunctions::EnableApplicationCrashReport, "EnableApplicationCrashReport"},
  1087. {100, &IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer, "InitializeApplicationCopyrightFrameBuffer"},
  1088. {101, &IApplicationFunctions::SetApplicationCopyrightImage, "SetApplicationCopyrightImage"},
  1089. {102, &IApplicationFunctions::SetApplicationCopyrightVisibility, "SetApplicationCopyrightVisibility"},
  1090. {110, &IApplicationFunctions::QueryApplicationPlayStatistics, "QueryApplicationPlayStatistics"},
  1091. {111, &IApplicationFunctions::QueryApplicationPlayStatisticsByUid, "QueryApplicationPlayStatisticsByUid"},
  1092. {120, &IApplicationFunctions::ExecuteProgram, "ExecuteProgram"},
  1093. {121, &IApplicationFunctions::ClearUserChannel, "ClearUserChannel"},
  1094. {122, &IApplicationFunctions::UnpopToUserChannel, "UnpopToUserChannel"},
  1095. {123, &IApplicationFunctions::GetPreviousProgramIndex, "GetPreviousProgramIndex"},
  1096. {124, nullptr, "EnableApplicationAllThreadDumpOnCrash"},
  1097. {130, &IApplicationFunctions::GetGpuErrorDetectedSystemEvent, "GetGpuErrorDetectedSystemEvent"},
  1098. {131, nullptr, "SetDelayTimeToAbortOnGpuError"},
  1099. {140, &IApplicationFunctions::GetFriendInvitationStorageChannelEvent, "GetFriendInvitationStorageChannelEvent"},
  1100. {141, &IApplicationFunctions::TryPopFromFriendInvitationStorageChannel, "TryPopFromFriendInvitationStorageChannel"},
  1101. {150, &IApplicationFunctions::GetNotificationStorageChannelEvent, "GetNotificationStorageChannelEvent"},
  1102. {151, nullptr, "TryPopFromNotificationStorageChannel"},
  1103. {160, &IApplicationFunctions::GetHealthWarningDisappearedSystemEvent, "GetHealthWarningDisappearedSystemEvent"},
  1104. {170, nullptr, "SetHdcpAuthenticationActivated"},
  1105. {180, nullptr, "GetLaunchRequiredVersion"},
  1106. {181, nullptr, "UpgradeLaunchRequiredVersion"},
  1107. {190, nullptr, "SendServerMaintenanceOverlayNotification"},
  1108. {200, nullptr, "GetLastApplicationExitReason"},
  1109. {500, nullptr, "StartContinuousRecordingFlushForDebug"},
  1110. {1000, nullptr, "CreateMovieMaker"},
  1111. {1001, &IApplicationFunctions::PrepareForJit, "PrepareForJit"},
  1112. };
  1113. // clang-format on
  1114. RegisterHandlers(functions);
  1115. gpu_error_detected_event =
  1116. service_context.CreateEvent("IApplicationFunctions:GpuErrorDetectedSystemEvent");
  1117. friend_invitation_storage_channel_event =
  1118. service_context.CreateEvent("IApplicationFunctions:FriendInvitationStorageChannelEvent");
  1119. notification_storage_channel_event =
  1120. service_context.CreateEvent("IApplicationFunctions:NotificationStorageChannelEvent");
  1121. health_warning_disappeared_system_event =
  1122. service_context.CreateEvent("IApplicationFunctions:HealthWarningDisappearedSystemEvent");
  1123. }
  1124. IApplicationFunctions::~IApplicationFunctions() {
  1125. service_context.CloseEvent(gpu_error_detected_event);
  1126. service_context.CloseEvent(friend_invitation_storage_channel_event);
  1127. service_context.CloseEvent(notification_storage_channel_event);
  1128. service_context.CloseEvent(health_warning_disappeared_system_event);
  1129. }
  1130. void IApplicationFunctions::EnableApplicationCrashReport(HLERequestContext& ctx) {
  1131. LOG_WARNING(Service_AM, "(STUBBED) called");
  1132. IPC::ResponseBuilder rb{ctx, 2};
  1133. rb.Push(ResultSuccess);
  1134. }
  1135. void IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer(HLERequestContext& ctx) {
  1136. LOG_WARNING(Service_AM, "(STUBBED) called");
  1137. IPC::ResponseBuilder rb{ctx, 2};
  1138. rb.Push(ResultSuccess);
  1139. }
  1140. void IApplicationFunctions::SetApplicationCopyrightImage(HLERequestContext& ctx) {
  1141. LOG_WARNING(Service_AM, "(STUBBED) called");
  1142. IPC::ResponseBuilder rb{ctx, 2};
  1143. rb.Push(ResultSuccess);
  1144. }
  1145. void IApplicationFunctions::SetApplicationCopyrightVisibility(HLERequestContext& ctx) {
  1146. IPC::RequestParser rp{ctx};
  1147. const auto is_visible = rp.Pop<bool>();
  1148. LOG_WARNING(Service_AM, "(STUBBED) called, is_visible={}", is_visible);
  1149. IPC::ResponseBuilder rb{ctx, 2};
  1150. rb.Push(ResultSuccess);
  1151. }
  1152. void IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx) {
  1153. LOG_WARNING(Service_AM, "(STUBBED) called");
  1154. IPC::ResponseBuilder rb{ctx, 2};
  1155. rb.Push(ResultSuccess);
  1156. }
  1157. void IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx) {
  1158. LOG_WARNING(Service_AM, "(STUBBED) called");
  1159. IPC::ResponseBuilder rb{ctx, 2};
  1160. rb.Push(ResultSuccess);
  1161. }
  1162. void IApplicationFunctions::BeginBlockingHomeButton(HLERequestContext& ctx) {
  1163. LOG_WARNING(Service_AM, "(STUBBED) called");
  1164. IPC::ResponseBuilder rb{ctx, 2};
  1165. rb.Push(ResultSuccess);
  1166. }
  1167. void IApplicationFunctions::EndBlockingHomeButton(HLERequestContext& ctx) {
  1168. LOG_WARNING(Service_AM, "(STUBBED) called");
  1169. IPC::ResponseBuilder rb{ctx, 2};
  1170. rb.Push(ResultSuccess);
  1171. }
  1172. void IApplicationFunctions::PopLaunchParameter(HLERequestContext& ctx) {
  1173. IPC::RequestParser rp{ctx};
  1174. const auto kind = rp.PopEnum<LaunchParameterKind>();
  1175. LOG_DEBUG(Service_AM, "called, kind={:08X}", kind);
  1176. if (kind == LaunchParameterKind::ApplicationSpecific && !launch_popped_application_specific) {
  1177. const auto backend = BCAT::CreateBackendFromSettings(system, [this](u64 tid) {
  1178. return system.GetFileSystemController().GetBCATDirectory(tid);
  1179. });
  1180. const auto build_id_full = system.GetApplicationProcessBuildID();
  1181. u64 build_id{};
  1182. std::memcpy(&build_id, build_id_full.data(), sizeof(u64));
  1183. auto data =
  1184. backend->GetLaunchParameter({system.GetApplicationProcessProgramID(), build_id});
  1185. if (data.has_value()) {
  1186. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  1187. rb.Push(ResultSuccess);
  1188. rb.PushIpcInterface<IStorage>(system, std::move(*data));
  1189. launch_popped_application_specific = true;
  1190. return;
  1191. }
  1192. } else if (kind == LaunchParameterKind::AccountPreselectedUser &&
  1193. !launch_popped_account_preselect) {
  1194. LaunchParameterAccountPreselectedUser params{};
  1195. params.magic = LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC;
  1196. params.is_account_selected = 1;
  1197. Account::ProfileManager profile_manager{};
  1198. const auto uuid = profile_manager.GetUser(static_cast<s32>(Settings::values.current_user));
  1199. ASSERT(uuid.has_value() && uuid->IsValid());
  1200. params.current_user = *uuid;
  1201. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  1202. rb.Push(ResultSuccess);
  1203. std::vector<u8> buffer(sizeof(LaunchParameterAccountPreselectedUser));
  1204. std::memcpy(buffer.data(), &params, buffer.size());
  1205. rb.PushIpcInterface<IStorage>(system, std::move(buffer));
  1206. launch_popped_account_preselect = true;
  1207. return;
  1208. }
  1209. LOG_ERROR(Service_AM, "Attempted to load launch parameter but none was found!");
  1210. IPC::ResponseBuilder rb{ctx, 2};
  1211. rb.Push(AM::ResultNoDataInChannel);
  1212. }
  1213. void IApplicationFunctions::CreateApplicationAndRequestToStartForQuest(HLERequestContext& ctx) {
  1214. LOG_WARNING(Service_AM, "(STUBBED) called");
  1215. IPC::ResponseBuilder rb{ctx, 2};
  1216. rb.Push(ResultSuccess);
  1217. }
  1218. void IApplicationFunctions::EnsureSaveData(HLERequestContext& ctx) {
  1219. IPC::RequestParser rp{ctx};
  1220. u128 user_id = rp.PopRaw<u128>();
  1221. LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]);
  1222. FileSys::SaveDataAttribute attribute{};
  1223. attribute.title_id = system.GetApplicationProcessProgramID();
  1224. attribute.user_id = user_id;
  1225. attribute.type = FileSys::SaveDataType::SaveData;
  1226. const auto res = system.GetFileSystemController().CreateSaveData(
  1227. FileSys::SaveDataSpaceId::NandUser, attribute);
  1228. IPC::ResponseBuilder rb{ctx, 4};
  1229. rb.Push(res.Code());
  1230. rb.Push<u64>(0);
  1231. }
  1232. void IApplicationFunctions::SetTerminateResult(HLERequestContext& ctx) {
  1233. // Takes an input u32 Result, no output.
  1234. // For example, in some cases official apps use this with error 0x2A2 then
  1235. // uses svcBreak.
  1236. IPC::RequestParser rp{ctx};
  1237. u32 result = rp.Pop<u32>();
  1238. LOG_WARNING(Service_AM, "(STUBBED) called, result=0x{:08X}", result);
  1239. IPC::ResponseBuilder rb{ctx, 2};
  1240. rb.Push(ResultSuccess);
  1241. }
  1242. void IApplicationFunctions::GetDisplayVersion(HLERequestContext& ctx) {
  1243. LOG_DEBUG(Service_AM, "called");
  1244. std::array<u8, 0x10> version_string{};
  1245. const auto res = [this] {
  1246. const auto title_id = system.GetApplicationProcessProgramID();
  1247. const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
  1248. system.GetContentProvider()};
  1249. auto metadata = pm.GetControlMetadata();
  1250. if (metadata.first != nullptr) {
  1251. return metadata;
  1252. }
  1253. const FileSys::PatchManager pm_update{FileSys::GetUpdateTitleID(title_id),
  1254. system.GetFileSystemController(),
  1255. system.GetContentProvider()};
  1256. return pm_update.GetControlMetadata();
  1257. }();
  1258. if (res.first != nullptr) {
  1259. const auto& version = res.first->GetVersionString();
  1260. std::copy(version.begin(), version.end(), version_string.begin());
  1261. } else {
  1262. static constexpr char default_version[]{"1.0.0"};
  1263. std::memcpy(version_string.data(), default_version, sizeof(default_version));
  1264. }
  1265. IPC::ResponseBuilder rb{ctx, 6};
  1266. rb.Push(ResultSuccess);
  1267. rb.PushRaw(version_string);
  1268. }
  1269. void IApplicationFunctions::GetDesiredLanguage(HLERequestContext& ctx) {
  1270. // TODO(bunnei): This should be configurable
  1271. LOG_DEBUG(Service_AM, "called");
  1272. // Get supported languages from NACP, if possible
  1273. // Default to 0 (all languages supported)
  1274. u32 supported_languages = 0;
  1275. const auto res = [this] {
  1276. const auto title_id = system.GetApplicationProcessProgramID();
  1277. const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
  1278. system.GetContentProvider()};
  1279. auto metadata = pm.GetControlMetadata();
  1280. if (metadata.first != nullptr) {
  1281. return metadata;
  1282. }
  1283. const FileSys::PatchManager pm_update{FileSys::GetUpdateTitleID(title_id),
  1284. system.GetFileSystemController(),
  1285. system.GetContentProvider()};
  1286. return pm_update.GetControlMetadata();
  1287. }();
  1288. if (res.first != nullptr) {
  1289. supported_languages = res.first->GetSupportedLanguages();
  1290. }
  1291. // Call IApplicationManagerInterface implementation.
  1292. auto& service_manager = system.ServiceManager();
  1293. auto ns_am2 = service_manager.GetService<NS::NS>("ns:am2");
  1294. auto app_man = ns_am2->GetApplicationManagerInterface();
  1295. // Get desired application language
  1296. const auto res_lang = app_man->GetApplicationDesiredLanguage(supported_languages);
  1297. if (res_lang.Failed()) {
  1298. IPC::ResponseBuilder rb{ctx, 2};
  1299. rb.Push(res_lang.Code());
  1300. return;
  1301. }
  1302. // Convert to settings language code.
  1303. const auto res_code = app_man->ConvertApplicationLanguageToLanguageCode(*res_lang);
  1304. if (res_code.Failed()) {
  1305. IPC::ResponseBuilder rb{ctx, 2};
  1306. rb.Push(res_code.Code());
  1307. return;
  1308. }
  1309. LOG_DEBUG(Service_AM, "got desired_language={:016X}", *res_code);
  1310. IPC::ResponseBuilder rb{ctx, 4};
  1311. rb.Push(ResultSuccess);
  1312. rb.Push(*res_code);
  1313. }
  1314. void IApplicationFunctions::IsGamePlayRecordingSupported(HLERequestContext& ctx) {
  1315. LOG_WARNING(Service_AM, "(STUBBED) called");
  1316. constexpr bool gameplay_recording_supported = false;
  1317. IPC::ResponseBuilder rb{ctx, 3};
  1318. rb.Push(ResultSuccess);
  1319. rb.Push(gameplay_recording_supported);
  1320. }
  1321. void IApplicationFunctions::InitializeGamePlayRecording(HLERequestContext& ctx) {
  1322. LOG_WARNING(Service_AM, "(STUBBED) called");
  1323. IPC::ResponseBuilder rb{ctx, 2};
  1324. rb.Push(ResultSuccess);
  1325. }
  1326. void IApplicationFunctions::SetGamePlayRecordingState(HLERequestContext& ctx) {
  1327. LOG_WARNING(Service_AM, "(STUBBED) called");
  1328. IPC::ResponseBuilder rb{ctx, 2};
  1329. rb.Push(ResultSuccess);
  1330. }
  1331. void IApplicationFunctions::NotifyRunning(HLERequestContext& ctx) {
  1332. LOG_WARNING(Service_AM, "(STUBBED) called");
  1333. IPC::ResponseBuilder rb{ctx, 3};
  1334. rb.Push(ResultSuccess);
  1335. rb.Push<u8>(0); // Unknown, seems to be ignored by official processes
  1336. }
  1337. void IApplicationFunctions::GetPseudoDeviceId(HLERequestContext& ctx) {
  1338. LOG_WARNING(Service_AM, "(STUBBED) called");
  1339. IPC::ResponseBuilder rb{ctx, 6};
  1340. rb.Push(ResultSuccess);
  1341. // Returns a 128-bit UUID
  1342. rb.Push<u64>(0);
  1343. rb.Push<u64>(0);
  1344. }
  1345. void IApplicationFunctions::ExtendSaveData(HLERequestContext& ctx) {
  1346. struct Parameters {
  1347. FileSys::SaveDataType type;
  1348. u128 user_id;
  1349. u64 new_normal_size;
  1350. u64 new_journal_size;
  1351. };
  1352. static_assert(sizeof(Parameters) == 40);
  1353. IPC::RequestParser rp{ctx};
  1354. const auto [type, user_id, new_normal_size, new_journal_size] = rp.PopRaw<Parameters>();
  1355. LOG_DEBUG(Service_AM,
  1356. "called with type={:02X}, user_id={:016X}{:016X}, new_normal={:016X}, "
  1357. "new_journal={:016X}",
  1358. static_cast<u8>(type), user_id[1], user_id[0], new_normal_size, new_journal_size);
  1359. system.GetFileSystemController().WriteSaveDataSize(
  1360. type, system.GetApplicationProcessProgramID(), user_id,
  1361. {new_normal_size, new_journal_size});
  1362. IPC::ResponseBuilder rb{ctx, 4};
  1363. rb.Push(ResultSuccess);
  1364. // The following value is used upon failure to help the system recover.
  1365. // Since we always succeed, this should be 0.
  1366. rb.Push<u64>(0);
  1367. }
  1368. void IApplicationFunctions::GetSaveDataSize(HLERequestContext& ctx) {
  1369. struct Parameters {
  1370. FileSys::SaveDataType type;
  1371. u128 user_id;
  1372. };
  1373. static_assert(sizeof(Parameters) == 24);
  1374. IPC::RequestParser rp{ctx};
  1375. const auto [type, user_id] = rp.PopRaw<Parameters>();
  1376. LOG_DEBUG(Service_AM, "called with type={:02X}, user_id={:016X}{:016X}", type, user_id[1],
  1377. user_id[0]);
  1378. const auto size = system.GetFileSystemController().ReadSaveDataSize(
  1379. type, system.GetApplicationProcessProgramID(), user_id);
  1380. IPC::ResponseBuilder rb{ctx, 6};
  1381. rb.Push(ResultSuccess);
  1382. rb.Push(size.normal);
  1383. rb.Push(size.journal);
  1384. }
  1385. void IApplicationFunctions::CreateCacheStorage(HLERequestContext& ctx) {
  1386. struct InputParameters {
  1387. u16 index;
  1388. s64 size;
  1389. s64 journal_size;
  1390. };
  1391. static_assert(sizeof(InputParameters) == 24);
  1392. struct OutputParameters {
  1393. u32 storage_target;
  1394. u64 required_size;
  1395. };
  1396. static_assert(sizeof(OutputParameters) == 16);
  1397. IPC::RequestParser rp{ctx};
  1398. const auto params = rp.PopRaw<InputParameters>();
  1399. LOG_WARNING(Service_AM, "(STUBBED) called with index={}, size={:#x}, journal_size={:#x}",
  1400. params.index, params.size, params.journal_size);
  1401. const OutputParameters resp{
  1402. .storage_target = 1,
  1403. .required_size = 0,
  1404. };
  1405. IPC::ResponseBuilder rb{ctx, 6};
  1406. rb.Push(ResultSuccess);
  1407. rb.PushRaw(resp);
  1408. }
  1409. void IApplicationFunctions::QueryApplicationPlayStatistics(HLERequestContext& ctx) {
  1410. LOG_WARNING(Service_AM, "(STUBBED) called");
  1411. IPC::ResponseBuilder rb{ctx, 3};
  1412. rb.Push(ResultSuccess);
  1413. rb.Push<u32>(0);
  1414. }
  1415. void IApplicationFunctions::QueryApplicationPlayStatisticsByUid(HLERequestContext& ctx) {
  1416. LOG_WARNING(Service_AM, "(STUBBED) called");
  1417. IPC::ResponseBuilder rb{ctx, 3};
  1418. rb.Push(ResultSuccess);
  1419. rb.Push<u32>(0);
  1420. }
  1421. void IApplicationFunctions::ExecuteProgram(HLERequestContext& ctx) {
  1422. LOG_WARNING(Service_AM, "(STUBBED) called");
  1423. IPC::RequestParser rp{ctx};
  1424. [[maybe_unused]] const auto unk_1 = rp.Pop<u32>();
  1425. [[maybe_unused]] const auto unk_2 = rp.Pop<u32>();
  1426. const auto program_index = rp.Pop<u64>();
  1427. IPC::ResponseBuilder rb{ctx, 2};
  1428. rb.Push(ResultSuccess);
  1429. system.ExecuteProgram(program_index);
  1430. }
  1431. void IApplicationFunctions::ClearUserChannel(HLERequestContext& ctx) {
  1432. LOG_WARNING(Service_AM, "(STUBBED) called");
  1433. IPC::ResponseBuilder rb{ctx, 2};
  1434. rb.Push(ResultSuccess);
  1435. }
  1436. void IApplicationFunctions::UnpopToUserChannel(HLERequestContext& ctx) {
  1437. LOG_WARNING(Service_AM, "(STUBBED) called");
  1438. IPC::ResponseBuilder rb{ctx, 2};
  1439. rb.Push(ResultSuccess);
  1440. }
  1441. void IApplicationFunctions::GetPreviousProgramIndex(HLERequestContext& ctx) {
  1442. LOG_WARNING(Service_AM, "(STUBBED) called");
  1443. IPC::ResponseBuilder rb{ctx, 3};
  1444. rb.Push(ResultSuccess);
  1445. rb.Push<s32>(previous_program_index);
  1446. }
  1447. void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(HLERequestContext& ctx) {
  1448. LOG_WARNING(Service_AM, "(STUBBED) called");
  1449. IPC::ResponseBuilder rb{ctx, 2, 1};
  1450. rb.Push(ResultSuccess);
  1451. rb.PushCopyObjects(gpu_error_detected_event->GetReadableEvent());
  1452. }
  1453. void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(HLERequestContext& ctx) {
  1454. LOG_DEBUG(Service_AM, "called");
  1455. IPC::ResponseBuilder rb{ctx, 2, 1};
  1456. rb.Push(ResultSuccess);
  1457. rb.PushCopyObjects(friend_invitation_storage_channel_event->GetReadableEvent());
  1458. }
  1459. void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel(HLERequestContext& ctx) {
  1460. LOG_DEBUG(Service_AM, "(STUBBED) called");
  1461. IPC::ResponseBuilder rb{ctx, 2};
  1462. rb.Push(AM::ResultNoDataInChannel);
  1463. }
  1464. void IApplicationFunctions::GetNotificationStorageChannelEvent(HLERequestContext& ctx) {
  1465. LOG_DEBUG(Service_AM, "called");
  1466. IPC::ResponseBuilder rb{ctx, 2, 1};
  1467. rb.Push(ResultSuccess);
  1468. rb.PushCopyObjects(notification_storage_channel_event->GetReadableEvent());
  1469. }
  1470. void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(HLERequestContext& ctx) {
  1471. LOG_DEBUG(Service_AM, "called");
  1472. IPC::ResponseBuilder rb{ctx, 2, 1};
  1473. rb.Push(ResultSuccess);
  1474. rb.PushCopyObjects(health_warning_disappeared_system_event->GetReadableEvent());
  1475. }
  1476. void IApplicationFunctions::PrepareForJit(HLERequestContext& ctx) {
  1477. LOG_WARNING(Service_AM, "(STUBBED) called");
  1478. IPC::ResponseBuilder rb{ctx, 2};
  1479. rb.Push(ResultSuccess);
  1480. }
  1481. void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) {
  1482. auto message_queue = std::make_shared<AppletMessageQueue>(system);
  1483. // Needed on game boot
  1484. message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
  1485. auto server_manager = std::make_unique<ServerManager>(system);
  1486. server_manager->RegisterNamedService(
  1487. "appletAE", std::make_shared<AppletAE>(nvnflinger, message_queue, system));
  1488. server_manager->RegisterNamedService(
  1489. "appletOE", std::make_shared<AppletOE>(nvnflinger, message_queue, system));
  1490. server_manager->RegisterNamedService("idle:sys", std::make_shared<IdleSys>(system));
  1491. server_manager->RegisterNamedService("omm", std::make_shared<OMM>(system));
  1492. server_manager->RegisterNamedService("spsm", std::make_shared<SPSM>(system));
  1493. ServerManager::RunServer(std::move(server_manager));
  1494. }
  1495. IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_)
  1496. : ServiceFramework{system_, "IHomeMenuFunctions"}, service_context{system,
  1497. "IHomeMenuFunctions"} {
  1498. // clang-format off
  1499. static const FunctionInfo functions[] = {
  1500. {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
  1501. {11, nullptr, "LockForeground"},
  1502. {12, nullptr, "UnlockForeground"},
  1503. {20, nullptr, "PopFromGeneralChannel"},
  1504. {21, &IHomeMenuFunctions::GetPopFromGeneralChannelEvent, "GetPopFromGeneralChannelEvent"},
  1505. {30, nullptr, "GetHomeButtonWriterLockAccessor"},
  1506. {31, nullptr, "GetWriterLockAccessorEx"},
  1507. {40, nullptr, "IsSleepEnabled"},
  1508. {41, nullptr, "IsRebootEnabled"},
  1509. {50, nullptr, "LaunchSystemApplet"},
  1510. {51, nullptr, "LaunchStarter"},
  1511. {100, nullptr, "PopRequestLaunchApplicationForDebug"},
  1512. {110, nullptr, "IsForceTerminateApplicationDisabledForDebug"},
  1513. {200, nullptr, "LaunchDevMenu"},
  1514. {1000, nullptr, "SetLastApplicationExitReason"},
  1515. };
  1516. // clang-format on
  1517. RegisterHandlers(functions);
  1518. pop_from_general_channel_event =
  1519. service_context.CreateEvent("IHomeMenuFunctions:PopFromGeneralChannelEvent");
  1520. }
  1521. IHomeMenuFunctions::~IHomeMenuFunctions() {
  1522. service_context.CloseEvent(pop_from_general_channel_event);
  1523. }
  1524. void IHomeMenuFunctions::RequestToGetForeground(HLERequestContext& ctx) {
  1525. LOG_WARNING(Service_AM, "(STUBBED) called");
  1526. IPC::ResponseBuilder rb{ctx, 2};
  1527. rb.Push(ResultSuccess);
  1528. }
  1529. void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(HLERequestContext& ctx) {
  1530. LOG_WARNING(Service_AM, "(STUBBED) called");
  1531. IPC::ResponseBuilder rb{ctx, 2, 1};
  1532. rb.Push(ResultSuccess);
  1533. rb.PushCopyObjects(pop_from_general_channel_event->GetReadableEvent());
  1534. }
  1535. IGlobalStateController::IGlobalStateController(Core::System& system_)
  1536. : ServiceFramework{system_, "IGlobalStateController"} {
  1537. // clang-format off
  1538. static const FunctionInfo functions[] = {
  1539. {0, nullptr, "RequestToEnterSleep"},
  1540. {1, nullptr, "EnterSleep"},
  1541. {2, nullptr, "StartSleepSequence"},
  1542. {3, nullptr, "StartShutdownSequence"},
  1543. {4, nullptr, "StartRebootSequence"},
  1544. {9, nullptr, "IsAutoPowerDownRequested"},
  1545. {10, nullptr, "LoadAndApplyIdlePolicySettings"},
  1546. {11, nullptr, "NotifyCecSettingsChanged"},
  1547. {12, nullptr, "SetDefaultHomeButtonLongPressTime"},
  1548. {13, nullptr, "UpdateDefaultDisplayResolution"},
  1549. {14, nullptr, "ShouldSleepOnBoot"},
  1550. {15, nullptr, "GetHdcpAuthenticationFailedEvent"},
  1551. {30, nullptr, "OpenCradleFirmwareUpdater"},
  1552. };
  1553. // clang-format on
  1554. RegisterHandlers(functions);
  1555. }
  1556. IGlobalStateController::~IGlobalStateController() = default;
  1557. IApplicationCreator::IApplicationCreator(Core::System& system_)
  1558. : ServiceFramework{system_, "IApplicationCreator"} {
  1559. // clang-format off
  1560. static const FunctionInfo functions[] = {
  1561. {0, nullptr, "CreateApplication"},
  1562. {1, nullptr, "PopLaunchRequestedApplication"},
  1563. {10, nullptr, "CreateSystemApplication"},
  1564. {100, nullptr, "PopFloatingApplicationForDevelopment"},
  1565. };
  1566. // clang-format on
  1567. RegisterHandlers(functions);
  1568. }
  1569. IApplicationCreator::~IApplicationCreator() = default;
  1570. IProcessWindingController::IProcessWindingController(Core::System& system_)
  1571. : ServiceFramework{system_, "IProcessWindingController"} {
  1572. // clang-format off
  1573. static const FunctionInfo functions[] = {
  1574. {0, nullptr, "GetLaunchReason"},
  1575. {11, nullptr, "OpenCallingLibraryApplet"},
  1576. {21, nullptr, "PushContext"},
  1577. {22, nullptr, "PopContext"},
  1578. {23, nullptr, "CancelWindingReservation"},
  1579. {30, nullptr, "WindAndDoReserved"},
  1580. {40, nullptr, "ReserveToStartAndWaitAndUnwindThis"},
  1581. {41, nullptr, "ReserveToStartAndWait"},
  1582. };
  1583. // clang-format on
  1584. RegisterHandlers(functions);
  1585. }
  1586. IProcessWindingController::~IProcessWindingController() = default;
  1587. } // namespace Service::AM