am.cpp 75 KB

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