am.cpp 72 KB

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