am.cpp 73 KB

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