am.cpp 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047
  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. ApplicationSpecific = 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.SetExitLock(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.SetExitLock(false);
  303. IPC::ResponseBuilder rb{ctx, 2};
  304. rb.Push(ResultSuccess);
  305. }
  306. void ISelfController::EnterFatalSection(HLERequestContext& ctx) {
  307. ++num_fatal_sections_entered;
  308. LOG_DEBUG(Service_AM, "called. Num fatal sections entered: {}", num_fatal_sections_entered);
  309. IPC::ResponseBuilder rb{ctx, 2};
  310. rb.Push(ResultSuccess);
  311. }
  312. void ISelfController::LeaveFatalSection(HLERequestContext& ctx) {
  313. LOG_DEBUG(Service_AM, "called.");
  314. // Entry and exit of fatal sections must be balanced.
  315. if (num_fatal_sections_entered == 0) {
  316. IPC::ResponseBuilder rb{ctx, 2};
  317. rb.Push(Result{ErrorModule::AM, 512});
  318. return;
  319. }
  320. --num_fatal_sections_entered;
  321. IPC::ResponseBuilder rb{ctx, 2};
  322. rb.Push(ResultSuccess);
  323. }
  324. void ISelfController::GetLibraryAppletLaunchableEvent(HLERequestContext& ctx) {
  325. LOG_WARNING(Service_AM, "(STUBBED) called");
  326. launchable_event->Signal();
  327. IPC::ResponseBuilder rb{ctx, 2, 1};
  328. rb.Push(ResultSuccess);
  329. rb.PushCopyObjects(launchable_event->GetReadableEvent());
  330. }
  331. void ISelfController::SetScreenShotPermission(HLERequestContext& ctx) {
  332. IPC::RequestParser rp{ctx};
  333. const auto permission = rp.PopEnum<ScreenshotPermission>();
  334. LOG_DEBUG(Service_AM, "called, permission={}", permission);
  335. screenshot_permission = permission;
  336. IPC::ResponseBuilder rb{ctx, 2};
  337. rb.Push(ResultSuccess);
  338. }
  339. void ISelfController::SetOperationModeChangedNotification(HLERequestContext& ctx) {
  340. IPC::RequestParser rp{ctx};
  341. bool flag = rp.Pop<bool>();
  342. LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  343. IPC::ResponseBuilder rb{ctx, 2};
  344. rb.Push(ResultSuccess);
  345. }
  346. void ISelfController::SetPerformanceModeChangedNotification(HLERequestContext& ctx) {
  347. IPC::RequestParser rp{ctx};
  348. bool flag = rp.Pop<bool>();
  349. LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  350. IPC::ResponseBuilder rb{ctx, 2};
  351. rb.Push(ResultSuccess);
  352. }
  353. void ISelfController::SetFocusHandlingMode(HLERequestContext& ctx) {
  354. // Takes 3 input u8s with each field located immediately after the previous
  355. // u8, these are bool flags. No output.
  356. IPC::RequestParser rp{ctx};
  357. struct FocusHandlingModeParams {
  358. u8 unknown0;
  359. u8 unknown1;
  360. u8 unknown2;
  361. };
  362. const auto flags = rp.PopRaw<FocusHandlingModeParams>();
  363. LOG_WARNING(Service_AM, "(STUBBED) called. unknown0={}, unknown1={}, unknown2={}",
  364. flags.unknown0, flags.unknown1, flags.unknown2);
  365. IPC::ResponseBuilder rb{ctx, 2};
  366. rb.Push(ResultSuccess);
  367. }
  368. void ISelfController::SetRestartMessageEnabled(HLERequestContext& ctx) {
  369. LOG_WARNING(Service_AM, "(STUBBED) called");
  370. IPC::ResponseBuilder rb{ctx, 2};
  371. rb.Push(ResultSuccess);
  372. }
  373. void ISelfController::SetOutOfFocusSuspendingEnabled(HLERequestContext& ctx) {
  374. // Takes 3 input u8s with each field located immediately after the previous
  375. // u8, these are bool flags. No output.
  376. IPC::RequestParser rp{ctx};
  377. bool enabled = rp.Pop<bool>();
  378. LOG_WARNING(Service_AM, "(STUBBED) called enabled={}", enabled);
  379. IPC::ResponseBuilder rb{ctx, 2};
  380. rb.Push(ResultSuccess);
  381. }
  382. void ISelfController::SetAlbumImageOrientation(HLERequestContext& ctx) {
  383. LOG_WARNING(Service_AM, "(STUBBED) called");
  384. IPC::ResponseBuilder rb{ctx, 2};
  385. rb.Push(ResultSuccess);
  386. }
  387. void ISelfController::CreateManagedDisplayLayer(HLERequestContext& ctx) {
  388. LOG_WARNING(Service_AM, "(STUBBED) called");
  389. // TODO(Subv): Find out how AM determines the display to use, for now just
  390. // create the layer in the Default display.
  391. const auto display_id = nvnflinger.OpenDisplay("Default");
  392. const auto layer_id = nvnflinger.CreateLayer(*display_id);
  393. IPC::ResponseBuilder rb{ctx, 4};
  394. rb.Push(ResultSuccess);
  395. rb.Push(*layer_id);
  396. }
  397. void ISelfController::CreateManagedDisplaySeparableLayer(HLERequestContext& ctx) {
  398. LOG_WARNING(Service_AM, "(STUBBED) called");
  399. // TODO(Subv): Find out how AM determines the display to use, for now just
  400. // create the layer in the Default display.
  401. // This calls nn::vi::CreateRecordingLayer() which creates another layer.
  402. // Currently we do not support more than 1 layer per display, output 1 layer id for now.
  403. // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse
  404. // side effects.
  405. // TODO: Support multiple layers
  406. const auto display_id = nvnflinger.OpenDisplay("Default");
  407. const auto layer_id = nvnflinger.CreateLayer(*display_id);
  408. IPC::ResponseBuilder rb{ctx, 4};
  409. rb.Push(ResultSuccess);
  410. rb.Push(*layer_id);
  411. }
  412. void ISelfController::SetHandlesRequestToDisplay(HLERequestContext& ctx) {
  413. LOG_WARNING(Service_AM, "(STUBBED) called");
  414. IPC::ResponseBuilder rb{ctx, 2};
  415. rb.Push(ResultSuccess);
  416. }
  417. void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) {
  418. IPC::RequestParser rp{ctx};
  419. idle_time_detection_extension = rp.Pop<u32>();
  420. LOG_DEBUG(Service_AM, "(STUBBED) called idle_time_detection_extension={}",
  421. idle_time_detection_extension);
  422. IPC::ResponseBuilder rb{ctx, 2};
  423. rb.Push(ResultSuccess);
  424. }
  425. void ISelfController::GetIdleTimeDetectionExtension(HLERequestContext& ctx) {
  426. LOG_WARNING(Service_AM, "(STUBBED) called");
  427. IPC::ResponseBuilder rb{ctx, 3};
  428. rb.Push(ResultSuccess);
  429. rb.Push<u32>(idle_time_detection_extension);
  430. }
  431. void ISelfController::ReportUserIsActive(HLERequestContext& ctx) {
  432. LOG_WARNING(Service_AM, "(STUBBED) called");
  433. IPC::ResponseBuilder rb{ctx, 2};
  434. rb.Push(ResultSuccess);
  435. }
  436. void ISelfController::SetAutoSleepDisabled(HLERequestContext& ctx) {
  437. IPC::RequestParser rp{ctx};
  438. is_auto_sleep_disabled = rp.Pop<bool>();
  439. // On the system itself, if the previous state of is_auto_sleep_disabled
  440. // differed from the current value passed in, it'd signify the internal
  441. // window manager to update (and also increment some statistics like update counts)
  442. //
  443. // It'd also indicate this change to an idle handling context.
  444. //
  445. // However, given we're emulating this behavior, most of this can be ignored
  446. // and it's sufficient to simply set the member variable for querying via
  447. // IsAutoSleepDisabled().
  448. LOG_DEBUG(Service_AM, "called. is_auto_sleep_disabled={}", is_auto_sleep_disabled);
  449. IPC::ResponseBuilder rb{ctx, 2};
  450. rb.Push(ResultSuccess);
  451. }
  452. void ISelfController::IsAutoSleepDisabled(HLERequestContext& ctx) {
  453. LOG_DEBUG(Service_AM, "called.");
  454. IPC::ResponseBuilder rb{ctx, 3};
  455. rb.Push(ResultSuccess);
  456. rb.Push(is_auto_sleep_disabled);
  457. }
  458. void ISelfController::GetAccumulatedSuspendedTickValue(HLERequestContext& ctx) {
  459. LOG_DEBUG(Service_AM, "called.");
  460. // This command returns the total number of system ticks since ISelfController creation
  461. // where the game was suspended. Since Yuzu doesn't implement game suspension, this command
  462. // can just always return 0 ticks.
  463. IPC::ResponseBuilder rb{ctx, 4};
  464. rb.Push(ResultSuccess);
  465. rb.Push<u64>(0);
  466. }
  467. void ISelfController::GetAccumulatedSuspendedTickChangedEvent(HLERequestContext& ctx) {
  468. LOG_DEBUG(Service_AM, "called.");
  469. IPC::ResponseBuilder rb{ctx, 2, 1};
  470. rb.Push(ResultSuccess);
  471. rb.PushCopyObjects(accumulated_suspended_tick_changed_event->GetReadableEvent());
  472. }
  473. void ISelfController::SetAlbumImageTakenNotificationEnabled(HLERequestContext& ctx) {
  474. IPC::RequestParser rp{ctx};
  475. // This service call sets an internal flag whether a notification is shown when an image is
  476. // captured. Currently we do not support capturing images via the capture button, so this can be
  477. // stubbed for now.
  478. const bool album_image_taken_notification_enabled = rp.Pop<bool>();
  479. LOG_WARNING(Service_AM, "(STUBBED) called. album_image_taken_notification_enabled={}",
  480. album_image_taken_notification_enabled);
  481. IPC::ResponseBuilder rb{ctx, 2};
  482. rb.Push(ResultSuccess);
  483. }
  484. void ISelfController::SaveCurrentScreenshot(HLERequestContext& ctx) {
  485. IPC::RequestParser rp{ctx};
  486. const auto album_report_option = rp.PopEnum<Capture::AlbumReportOption>();
  487. LOG_WARNING(Service_AM, "(STUBBED) called. album_report_option={}", album_report_option);
  488. IPC::ResponseBuilder rb{ctx, 2};
  489. rb.Push(ResultSuccess);
  490. }
  491. void ISelfController::SetRecordVolumeMuted(HLERequestContext& ctx) {
  492. IPC::RequestParser rp{ctx};
  493. const auto is_record_volume_muted = rp.Pop<bool>();
  494. LOG_WARNING(Service_AM, "(STUBBED) called. is_record_volume_muted={}", is_record_volume_muted);
  495. IPC::ResponseBuilder rb{ctx, 2};
  496. rb.Push(ResultSuccess);
  497. }
  498. AppletMessageQueue::AppletMessageQueue(Core::System& system)
  499. : service_context{system, "AppletMessageQueue"} {
  500. on_new_message = service_context.CreateEvent("AMMessageQueue:OnMessageReceived");
  501. on_operation_mode_changed = service_context.CreateEvent("AMMessageQueue:OperationModeChanged");
  502. }
  503. AppletMessageQueue::~AppletMessageQueue() {
  504. service_context.CloseEvent(on_new_message);
  505. service_context.CloseEvent(on_operation_mode_changed);
  506. }
  507. Kernel::KReadableEvent& AppletMessageQueue::GetMessageReceiveEvent() {
  508. return on_new_message->GetReadableEvent();
  509. }
  510. Kernel::KReadableEvent& AppletMessageQueue::GetOperationModeChangedEvent() {
  511. return on_operation_mode_changed->GetReadableEvent();
  512. }
  513. void AppletMessageQueue::PushMessage(AppletMessage msg) {
  514. messages.push(msg);
  515. on_new_message->Signal();
  516. }
  517. AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() {
  518. if (messages.empty()) {
  519. on_new_message->Clear();
  520. return AppletMessage::None;
  521. }
  522. auto msg = messages.front();
  523. messages.pop();
  524. if (messages.empty()) {
  525. on_new_message->Clear();
  526. }
  527. return msg;
  528. }
  529. std::size_t AppletMessageQueue::GetMessageCount() const {
  530. return messages.size();
  531. }
  532. void AppletMessageQueue::RequestExit() {
  533. PushMessage(AppletMessage::Exit);
  534. }
  535. void AppletMessageQueue::RequestResume() {
  536. PushMessage(AppletMessage::Resume);
  537. }
  538. void AppletMessageQueue::FocusStateChanged() {
  539. PushMessage(AppletMessage::FocusStateChanged);
  540. }
  541. void AppletMessageQueue::OperationModeChanged() {
  542. PushMessage(AppletMessage::OperationModeChanged);
  543. PushMessage(AppletMessage::PerformanceModeChanged);
  544. on_operation_mode_changed->Signal();
  545. }
  546. ICommonStateGetter::ICommonStateGetter(Core::System& system_,
  547. std::shared_ptr<AppletMessageQueue> msg_queue_)
  548. : ServiceFramework{system_, "ICommonStateGetter"}, msg_queue{std::move(msg_queue_)} {
  549. // clang-format off
  550. static const FunctionInfo functions[] = {
  551. {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
  552. {1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"},
  553. {2, nullptr, "GetThisAppletKind"},
  554. {3, nullptr, "AllowToEnterSleep"},
  555. {4, nullptr, "DisallowToEnterSleep"},
  556. {5, &ICommonStateGetter::GetOperationMode, "GetOperationMode"},
  557. {6, &ICommonStateGetter::GetPerformanceMode, "GetPerformanceMode"},
  558. {7, nullptr, "GetCradleStatus"},
  559. {8, &ICommonStateGetter::GetBootMode, "GetBootMode"},
  560. {9, &ICommonStateGetter::GetCurrentFocusState, "GetCurrentFocusState"},
  561. {10, nullptr, "RequestToAcquireSleepLock"},
  562. {11, nullptr, "ReleaseSleepLock"},
  563. {12, nullptr, "ReleaseSleepLockTransiently"},
  564. {13, nullptr, "GetAcquiredSleepLockEvent"},
  565. {14, nullptr, "GetWakeupCount"},
  566. {20, nullptr, "PushToGeneralChannel"},
  567. {30, nullptr, "GetHomeButtonReaderLockAccessor"},
  568. {31, nullptr, "GetReaderLockAccessorEx"},
  569. {32, nullptr, "GetWriterLockAccessorEx"},
  570. {40, nullptr, "GetCradleFwVersion"},
  571. {50, &ICommonStateGetter::IsVrModeEnabled, "IsVrModeEnabled"},
  572. {51, &ICommonStateGetter::SetVrModeEnabled, "SetVrModeEnabled"},
  573. {52, &ICommonStateGetter::SetLcdBacklighOffEnabled, "SetLcdBacklighOffEnabled"},
  574. {53, &ICommonStateGetter::BeginVrModeEx, "BeginVrModeEx"},
  575. {54, &ICommonStateGetter::EndVrModeEx, "EndVrModeEx"},
  576. {55, nullptr, "IsInControllerFirmwareUpdateSection"},
  577. {59, nullptr, "SetVrPositionForDebug"},
  578. {60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"},
  579. {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, "GetDefaultDisplayResolutionChangeEvent"},
  580. {62, nullptr, "GetHdcpAuthenticationState"},
  581. {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"},
  582. {64, nullptr, "SetTvPowerStateMatchingMode"},
  583. {65, nullptr, "GetApplicationIdByContentActionName"},
  584. {66, &ICommonStateGetter::SetCpuBoostMode, "SetCpuBoostMode"},
  585. {67, nullptr, "CancelCpuBoostMode"},
  586. {68, nullptr, "GetBuiltInDisplayType"},
  587. {80, &ICommonStateGetter::PerformSystemButtonPressingIfInFocus, "PerformSystemButtonPressingIfInFocus"},
  588. {90, nullptr, "SetPerformanceConfigurationChangedNotification"},
  589. {91, nullptr, "GetCurrentPerformanceConfiguration"},
  590. {100, nullptr, "SetHandlingHomeButtonShortPressedEnabled"},
  591. {110, nullptr, "OpenMyGpuErrorHandler"},
  592. {120, nullptr, "GetAppletLaunchedHistory"},
  593. {200, nullptr, "GetOperationModeSystemInfo"},
  594. {300, nullptr, "GetSettingsPlatformRegion"},
  595. {400, nullptr, "ActivateMigrationService"},
  596. {401, nullptr, "DeactivateMigrationService"},
  597. {500, nullptr, "DisableSleepTillShutdown"},
  598. {501, nullptr, "SuppressDisablingSleepTemporarily"},
  599. {502, nullptr, "IsSleepEnabled"},
  600. {503, nullptr, "IsDisablingSleepSuppressed"},
  601. {900, &ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled, "SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled"},
  602. };
  603. // clang-format on
  604. RegisterHandlers(functions);
  605. }
  606. ICommonStateGetter::~ICommonStateGetter() = default;
  607. void ICommonStateGetter::GetBootMode(HLERequestContext& ctx) {
  608. LOG_DEBUG(Service_AM, "called");
  609. IPC::ResponseBuilder rb{ctx, 3};
  610. rb.Push(ResultSuccess);
  611. rb.Push<u8>(static_cast<u8>(Service::PM::SystemBootMode::Normal)); // Normal boot mode
  612. }
  613. void ICommonStateGetter::GetEventHandle(HLERequestContext& ctx) {
  614. LOG_DEBUG(Service_AM, "called");
  615. IPC::ResponseBuilder rb{ctx, 2, 1};
  616. rb.Push(ResultSuccess);
  617. rb.PushCopyObjects(msg_queue->GetMessageReceiveEvent());
  618. }
  619. void ICommonStateGetter::ReceiveMessage(HLERequestContext& ctx) {
  620. LOG_DEBUG(Service_AM, "called");
  621. const auto message = msg_queue->PopMessage();
  622. IPC::ResponseBuilder rb{ctx, 3};
  623. if (message == AppletMessageQueue::AppletMessage::None) {
  624. LOG_ERROR(Service_AM, "Message queue is empty");
  625. rb.Push(AM::ResultNoMessages);
  626. rb.PushEnum<AppletMessageQueue::AppletMessage>(message);
  627. return;
  628. }
  629. rb.Push(ResultSuccess);
  630. rb.PushEnum<AppletMessageQueue::AppletMessage>(message);
  631. }
  632. void ICommonStateGetter::GetCurrentFocusState(HLERequestContext& ctx) {
  633. LOG_DEBUG(Service_AM, "(STUBBED) called");
  634. IPC::ResponseBuilder rb{ctx, 3};
  635. rb.Push(ResultSuccess);
  636. rb.Push(static_cast<u8>(FocusState::InFocus));
  637. }
  638. void ICommonStateGetter::IsVrModeEnabled(HLERequestContext& ctx) {
  639. LOG_DEBUG(Service_AM, "called");
  640. IPC::ResponseBuilder rb{ctx, 3};
  641. rb.Push(ResultSuccess);
  642. rb.Push(vr_mode_state);
  643. }
  644. void ICommonStateGetter::SetVrModeEnabled(HLERequestContext& ctx) {
  645. IPC::RequestParser rp{ctx};
  646. vr_mode_state = rp.Pop<bool>();
  647. LOG_WARNING(Service_AM, "VR Mode is {}", vr_mode_state ? "on" : "off");
  648. IPC::ResponseBuilder rb{ctx, 2};
  649. rb.Push(ResultSuccess);
  650. }
  651. void ICommonStateGetter::SetLcdBacklighOffEnabled(HLERequestContext& ctx) {
  652. IPC::RequestParser rp{ctx};
  653. const auto is_lcd_backlight_off_enabled = rp.Pop<bool>();
  654. LOG_WARNING(Service_AM, "(STUBBED) called. is_lcd_backlight_off_enabled={}",
  655. is_lcd_backlight_off_enabled);
  656. IPC::ResponseBuilder rb{ctx, 2};
  657. rb.Push(ResultSuccess);
  658. }
  659. void ICommonStateGetter::BeginVrModeEx(HLERequestContext& ctx) {
  660. LOG_WARNING(Service_AM, "(STUBBED) called");
  661. IPC::ResponseBuilder rb{ctx, 2};
  662. rb.Push(ResultSuccess);
  663. }
  664. void ICommonStateGetter::EndVrModeEx(HLERequestContext& ctx) {
  665. LOG_WARNING(Service_AM, "(STUBBED) called");
  666. IPC::ResponseBuilder rb{ctx, 2};
  667. rb.Push(ResultSuccess);
  668. }
  669. void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx) {
  670. LOG_DEBUG(Service_AM, "called");
  671. IPC::ResponseBuilder rb{ctx, 2, 1};
  672. rb.Push(ResultSuccess);
  673. rb.PushCopyObjects(msg_queue->GetOperationModeChangedEvent());
  674. }
  675. void ICommonStateGetter::GetDefaultDisplayResolution(HLERequestContext& ctx) {
  676. LOG_DEBUG(Service_AM, "called");
  677. IPC::ResponseBuilder rb{ctx, 4};
  678. rb.Push(ResultSuccess);
  679. if (Settings::values.use_docked_mode.GetValue() == Settings::ConsoleMode::Docked) {
  680. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedWidth));
  681. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedHeight));
  682. } else {
  683. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedWidth));
  684. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedHeight));
  685. }
  686. }
  687. void ICommonStateGetter::SetCpuBoostMode(HLERequestContext& ctx) {
  688. LOG_DEBUG(Service_AM, "called, forwarding to APM:SYS");
  689. const auto& sm = system.ServiceManager();
  690. const auto apm_sys = sm.GetService<APM::APM_Sys>("apm:sys");
  691. ASSERT(apm_sys != nullptr);
  692. apm_sys->SetCpuBoostMode(ctx);
  693. }
  694. void ICommonStateGetter::PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx) {
  695. IPC::RequestParser rp{ctx};
  696. const auto system_button{rp.PopEnum<SystemButtonType>()};
  697. LOG_WARNING(Service_AM, "(STUBBED) called, system_button={}", system_button);
  698. IPC::ResponseBuilder rb{ctx, 2};
  699. rb.Push(ResultSuccess);
  700. }
  701. void ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(
  702. HLERequestContext& ctx) {
  703. LOG_WARNING(Service_AM, "(STUBBED) called");
  704. IPC::ResponseBuilder rb{ctx, 2};
  705. rb.Push(ResultSuccess);
  706. }
  707. IStorageImpl::~IStorageImpl() = default;
  708. class StorageDataImpl final : public IStorageImpl {
  709. public:
  710. explicit StorageDataImpl(std::vector<u8>&& buffer_) : buffer{std::move(buffer_)} {}
  711. std::vector<u8>& GetData() override {
  712. return buffer;
  713. }
  714. const std::vector<u8>& GetData() const override {
  715. return buffer;
  716. }
  717. std::size_t GetSize() const override {
  718. return buffer.size();
  719. }
  720. private:
  721. std::vector<u8> buffer;
  722. };
  723. IStorage::IStorage(Core::System& system_, std::vector<u8>&& buffer)
  724. : ServiceFramework{system_, "IStorage"}, impl{std::make_shared<StorageDataImpl>(
  725. std::move(buffer))} {
  726. Register();
  727. }
  728. void IStorage::Register() {
  729. // clang-format off
  730. static const FunctionInfo functions[] = {
  731. {0, &IStorage::Open, "Open"},
  732. {1, nullptr, "OpenTransferStorage"},
  733. };
  734. // clang-format on
  735. RegisterHandlers(functions);
  736. }
  737. IStorage::~IStorage() = default;
  738. void IStorage::Open(HLERequestContext& ctx) {
  739. LOG_DEBUG(Service_AM, "called");
  740. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  741. rb.Push(ResultSuccess);
  742. rb.PushIpcInterface<IStorageAccessor>(system, *this);
  743. }
  744. void ICommonStateGetter::GetOperationMode(HLERequestContext& ctx) {
  745. const bool use_docked_mode{Settings::values.use_docked_mode.GetValue() ==
  746. Settings::ConsoleMode::Docked};
  747. LOG_DEBUG(Service_AM, "called, use_docked_mode={}", use_docked_mode);
  748. IPC::ResponseBuilder rb{ctx, 3};
  749. rb.Push(ResultSuccess);
  750. rb.Push(static_cast<u8>(use_docked_mode ? OperationMode::Docked : OperationMode::Handheld));
  751. }
  752. void ICommonStateGetter::GetPerformanceMode(HLERequestContext& ctx) {
  753. LOG_DEBUG(Service_AM, "called");
  754. IPC::ResponseBuilder rb{ctx, 3};
  755. rb.Push(ResultSuccess);
  756. rb.PushEnum(system.GetAPMController().GetCurrentPerformanceMode());
  757. }
  758. class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
  759. public:
  760. explicit ILibraryAppletAccessor(Core::System& system_, std::shared_ptr<Applets::Applet> applet_)
  761. : ServiceFramework{system_, "ILibraryAppletAccessor"}, applet{std::move(applet_)} {
  762. // clang-format off
  763. static const FunctionInfo functions[] = {
  764. {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
  765. {1, &ILibraryAppletAccessor::IsCompleted, "IsCompleted"},
  766. {10, &ILibraryAppletAccessor::Start, "Start"},
  767. {20, &ILibraryAppletAccessor::RequestExit, "RequestExit"},
  768. {25, nullptr, "Terminate"},
  769. {30, &ILibraryAppletAccessor::GetResult, "GetResult"},
  770. {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"},
  771. {60, &ILibraryAppletAccessor::PresetLibraryAppletGpuTimeSliceZero, "PresetLibraryAppletGpuTimeSliceZero"},
  772. {100, &ILibraryAppletAccessor::PushInData, "PushInData"},
  773. {101, &ILibraryAppletAccessor::PopOutData, "PopOutData"},
  774. {102, nullptr, "PushExtraStorage"},
  775. {103, &ILibraryAppletAccessor::PushInteractiveInData, "PushInteractiveInData"},
  776. {104, &ILibraryAppletAccessor::PopInteractiveOutData, "PopInteractiveOutData"},
  777. {105, &ILibraryAppletAccessor::GetPopOutDataEvent, "GetPopOutDataEvent"},
  778. {106, &ILibraryAppletAccessor::GetPopInteractiveOutDataEvent, "GetPopInteractiveOutDataEvent"},
  779. {110, nullptr, "NeedsToExitProcess"},
  780. {120, nullptr, "GetLibraryAppletInfo"},
  781. {150, nullptr, "RequestForAppletToGetForeground"},
  782. {160, &ILibraryAppletAccessor::GetIndirectLayerConsumerHandle, "GetIndirectLayerConsumerHandle"},
  783. };
  784. // clang-format on
  785. RegisterHandlers(functions);
  786. }
  787. private:
  788. void GetAppletStateChangedEvent(HLERequestContext& ctx) {
  789. LOG_DEBUG(Service_AM, "called");
  790. IPC::ResponseBuilder rb{ctx, 2, 1};
  791. rb.Push(ResultSuccess);
  792. rb.PushCopyObjects(applet->GetBroker().GetStateChangedEvent());
  793. }
  794. void IsCompleted(HLERequestContext& ctx) {
  795. LOG_DEBUG(Service_AM, "called");
  796. IPC::ResponseBuilder rb{ctx, 3};
  797. rb.Push(ResultSuccess);
  798. rb.Push<u32>(applet->TransactionComplete());
  799. }
  800. void GetResult(HLERequestContext& ctx) {
  801. LOG_DEBUG(Service_AM, "called");
  802. IPC::ResponseBuilder rb{ctx, 2};
  803. rb.Push(applet->GetStatus());
  804. }
  805. void PresetLibraryAppletGpuTimeSliceZero(HLERequestContext& ctx) {
  806. LOG_WARNING(Service_AM, "(STUBBED) called");
  807. IPC::ResponseBuilder rb{ctx, 2};
  808. rb.Push(ResultSuccess);
  809. }
  810. void Start(HLERequestContext& ctx) {
  811. LOG_DEBUG(Service_AM, "called");
  812. ASSERT(applet != nullptr);
  813. applet->Initialize();
  814. applet->Execute();
  815. IPC::ResponseBuilder rb{ctx, 2};
  816. rb.Push(ResultSuccess);
  817. }
  818. void RequestExit(HLERequestContext& ctx) {
  819. LOG_DEBUG(Service_AM, "called");
  820. ASSERT(applet != nullptr);
  821. IPC::ResponseBuilder rb{ctx, 2};
  822. rb.Push(applet->RequestExit());
  823. }
  824. void PushInData(HLERequestContext& ctx) {
  825. LOG_DEBUG(Service_AM, "called");
  826. IPC::RequestParser rp{ctx};
  827. applet->GetBroker().PushNormalDataFromGame(rp.PopIpcInterface<IStorage>().lock());
  828. IPC::ResponseBuilder rb{ctx, 2};
  829. rb.Push(ResultSuccess);
  830. }
  831. void PopOutData(HLERequestContext& ctx) {
  832. LOG_DEBUG(Service_AM, "called");
  833. auto storage = applet->GetBroker().PopNormalDataToGame();
  834. if (storage == nullptr) {
  835. LOG_DEBUG(Service_AM,
  836. "storage is a nullptr. There is no data in the current normal channel");
  837. IPC::ResponseBuilder rb{ctx, 2};
  838. rb.Push(AM::ResultNoDataInChannel);
  839. return;
  840. }
  841. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  842. rb.Push(ResultSuccess);
  843. rb.PushIpcInterface<IStorage>(std::move(storage));
  844. }
  845. void PushInteractiveInData(HLERequestContext& ctx) {
  846. LOG_DEBUG(Service_AM, "called");
  847. IPC::RequestParser rp{ctx};
  848. applet->GetBroker().PushInteractiveDataFromGame(rp.PopIpcInterface<IStorage>().lock());
  849. ASSERT(applet->IsInitialized());
  850. applet->ExecuteInteractive();
  851. applet->Execute();
  852. IPC::ResponseBuilder rb{ctx, 2};
  853. rb.Push(ResultSuccess);
  854. }
  855. void PopInteractiveOutData(HLERequestContext& ctx) {
  856. LOG_DEBUG(Service_AM, "called");
  857. auto storage = applet->GetBroker().PopInteractiveDataToGame();
  858. if (storage == nullptr) {
  859. LOG_DEBUG(Service_AM,
  860. "storage is a nullptr. There is no data in the current interactive channel");
  861. IPC::ResponseBuilder rb{ctx, 2};
  862. rb.Push(AM::ResultNoDataInChannel);
  863. return;
  864. }
  865. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  866. rb.Push(ResultSuccess);
  867. rb.PushIpcInterface<IStorage>(std::move(storage));
  868. }
  869. void GetPopOutDataEvent(HLERequestContext& ctx) {
  870. LOG_DEBUG(Service_AM, "called");
  871. IPC::ResponseBuilder rb{ctx, 2, 1};
  872. rb.Push(ResultSuccess);
  873. rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent());
  874. }
  875. void GetPopInteractiveOutDataEvent(HLERequestContext& ctx) {
  876. LOG_DEBUG(Service_AM, "called");
  877. IPC::ResponseBuilder rb{ctx, 2, 1};
  878. rb.Push(ResultSuccess);
  879. rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent());
  880. }
  881. void GetIndirectLayerConsumerHandle(HLERequestContext& ctx) {
  882. LOG_WARNING(Service_AM, "(STUBBED) called");
  883. // We require a non-zero handle to be valid. Using 0xdeadbeef allows us to trace if this is
  884. // actually used anywhere
  885. constexpr u64 handle = 0xdeadbeef;
  886. IPC::ResponseBuilder rb{ctx, 4};
  887. rb.Push(ResultSuccess);
  888. rb.Push(handle);
  889. }
  890. std::shared_ptr<Applets::Applet> applet;
  891. };
  892. IStorageAccessor::IStorageAccessor(Core::System& system_, IStorage& backing_)
  893. : ServiceFramework{system_, "IStorageAccessor"}, backing{backing_} {
  894. // clang-format off
  895. static const FunctionInfo functions[] = {
  896. {0, &IStorageAccessor::GetSize, "GetSize"},
  897. {10, &IStorageAccessor::Write, "Write"},
  898. {11, &IStorageAccessor::Read, "Read"},
  899. };
  900. // clang-format on
  901. RegisterHandlers(functions);
  902. }
  903. IStorageAccessor::~IStorageAccessor() = default;
  904. void IStorageAccessor::GetSize(HLERequestContext& ctx) {
  905. LOG_DEBUG(Service_AM, "called");
  906. IPC::ResponseBuilder rb{ctx, 4};
  907. rb.Push(ResultSuccess);
  908. rb.Push(static_cast<u64>(backing.GetSize()));
  909. }
  910. void IStorageAccessor::Write(HLERequestContext& ctx) {
  911. IPC::RequestParser rp{ctx};
  912. const u64 offset{rp.Pop<u64>()};
  913. const auto data{ctx.ReadBuffer()};
  914. const std::size_t size{std::min<u64>(data.size(), backing.GetSize() - offset)};
  915. LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
  916. if (offset > backing.GetSize()) {
  917. LOG_ERROR(Service_AM,
  918. "offset is out of bounds, backing_buffer_sz={}, data_size={}, offset={}",
  919. backing.GetSize(), size, offset);
  920. IPC::ResponseBuilder rb{ctx, 2};
  921. rb.Push(AM::ResultInvalidOffset);
  922. return;
  923. }
  924. std::memcpy(backing.GetData().data() + offset, data.data(), size);
  925. IPC::ResponseBuilder rb{ctx, 2};
  926. rb.Push(ResultSuccess);
  927. }
  928. void IStorageAccessor::Read(HLERequestContext& ctx) {
  929. IPC::RequestParser rp{ctx};
  930. const u64 offset{rp.Pop<u64>()};
  931. const std::size_t size{std::min<u64>(ctx.GetWriteBufferSize(), backing.GetSize() - offset)};
  932. LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
  933. if (offset > backing.GetSize()) {
  934. LOG_ERROR(Service_AM, "offset is out of bounds, backing_buffer_sz={}, size={}, offset={}",
  935. backing.GetSize(), size, offset);
  936. IPC::ResponseBuilder rb{ctx, 2};
  937. rb.Push(AM::ResultInvalidOffset);
  938. return;
  939. }
  940. ctx.WriteBuffer(backing.GetData().data() + offset, size);
  941. IPC::ResponseBuilder rb{ctx, 2};
  942. rb.Push(ResultSuccess);
  943. }
  944. ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_)
  945. : ServiceFramework{system_, "ILibraryAppletCreator"} {
  946. static const FunctionInfo functions[] = {
  947. {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"},
  948. {1, nullptr, "TerminateAllLibraryApplets"},
  949. {2, nullptr, "AreAnyLibraryAppletsLeft"},
  950. {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"},
  951. {11, &ILibraryAppletCreator::CreateTransferMemoryStorage, "CreateTransferMemoryStorage"},
  952. {12, &ILibraryAppletCreator::CreateHandleStorage, "CreateHandleStorage"},
  953. };
  954. RegisterHandlers(functions);
  955. }
  956. ILibraryAppletCreator::~ILibraryAppletCreator() = default;
  957. void ILibraryAppletCreator::CreateLibraryApplet(HLERequestContext& ctx) {
  958. IPC::RequestParser rp{ctx};
  959. const auto applet_id = rp.PopRaw<Applets::AppletId>();
  960. const auto applet_mode = rp.PopRaw<Applets::LibraryAppletMode>();
  961. LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}", applet_id,
  962. applet_mode);
  963. const auto& applet_manager{system.GetAppletManager()};
  964. const auto applet = applet_manager.GetApplet(applet_id, applet_mode);
  965. if (applet == nullptr) {
  966. LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id);
  967. IPC::ResponseBuilder rb{ctx, 2};
  968. rb.Push(ResultUnknown);
  969. return;
  970. }
  971. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  972. rb.Push(ResultSuccess);
  973. rb.PushIpcInterface<ILibraryAppletAccessor>(system, applet);
  974. }
  975. void ILibraryAppletCreator::CreateStorage(HLERequestContext& ctx) {
  976. IPC::RequestParser rp{ctx};
  977. const s64 size{rp.Pop<s64>()};
  978. LOG_DEBUG(Service_AM, "called, size={}", size);
  979. if (size <= 0) {
  980. LOG_ERROR(Service_AM, "size is less than or equal to 0");
  981. IPC::ResponseBuilder rb{ctx, 2};
  982. rb.Push(ResultUnknown);
  983. return;
  984. }
  985. std::vector<u8> buffer(size);
  986. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  987. rb.Push(ResultSuccess);
  988. rb.PushIpcInterface<IStorage>(system, std::move(buffer));
  989. }
  990. void ILibraryAppletCreator::CreateTransferMemoryStorage(HLERequestContext& ctx) {
  991. IPC::RequestParser rp{ctx};
  992. struct Parameters {
  993. u8 permissions;
  994. s64 size;
  995. };
  996. const auto parameters{rp.PopRaw<Parameters>()};
  997. const auto handle{ctx.GetCopyHandle(0)};
  998. LOG_DEBUG(Service_AM, "called, permissions={}, size={}, handle={:08X}", parameters.permissions,
  999. parameters.size, handle);
  1000. if (parameters.size <= 0) {
  1001. LOG_ERROR(Service_AM, "size is less than or equal to 0");
  1002. IPC::ResponseBuilder rb{ctx, 2};
  1003. rb.Push(ResultUnknown);
  1004. return;
  1005. }
  1006. auto transfer_mem =
  1007. system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>(handle);
  1008. if (transfer_mem.IsNull()) {
  1009. LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle);
  1010. IPC::ResponseBuilder rb{ctx, 2};
  1011. rb.Push(ResultUnknown);
  1012. return;
  1013. }
  1014. std::vector<u8> memory(transfer_mem->GetSize());
  1015. system.ApplicationMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(),
  1016. memory.size());
  1017. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  1018. rb.Push(ResultSuccess);
  1019. rb.PushIpcInterface<IStorage>(system, std::move(memory));
  1020. }
  1021. void ILibraryAppletCreator::CreateHandleStorage(HLERequestContext& ctx) {
  1022. IPC::RequestParser rp{ctx};
  1023. const s64 size{rp.Pop<s64>()};
  1024. const auto handle{ctx.GetCopyHandle(0)};
  1025. LOG_DEBUG(Service_AM, "called, size={}, handle={:08X}", size, handle);
  1026. if (size <= 0) {
  1027. LOG_ERROR(Service_AM, "size is less than or equal to 0");
  1028. IPC::ResponseBuilder rb{ctx, 2};
  1029. rb.Push(ResultUnknown);
  1030. return;
  1031. }
  1032. auto transfer_mem =
  1033. system.ApplicationProcess()->GetHandleTable().GetObject<Kernel::KTransferMemory>(handle);
  1034. if (transfer_mem.IsNull()) {
  1035. LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle);
  1036. IPC::ResponseBuilder rb{ctx, 2};
  1037. rb.Push(ResultUnknown);
  1038. return;
  1039. }
  1040. std::vector<u8> memory(transfer_mem->GetSize());
  1041. system.ApplicationMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(),
  1042. memory.size());
  1043. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  1044. rb.Push(ResultSuccess);
  1045. rb.PushIpcInterface<IStorage>(system, std::move(memory));
  1046. }
  1047. ILibraryAppletSelfAccessor::ILibraryAppletSelfAccessor(Core::System& system_)
  1048. : ServiceFramework{system_, "ILibraryAppletSelfAccessor"} {
  1049. static const FunctionInfo functions[] = {
  1050. {0, nullptr, "PopInData"},
  1051. {1, nullptr, "PushOutData"},
  1052. {2, nullptr, "PopInteractiveInData"},
  1053. {3, nullptr, "PushInteractiveOutData"},
  1054. {5, nullptr, "GetPopInDataEvent"},
  1055. {6, nullptr, "GetPopInteractiveInDataEvent"},
  1056. {10, nullptr, "ExitProcessAndReturn"},
  1057. {11, nullptr, "GetLibraryAppletInfo"},
  1058. {12, nullptr, "GetMainAppletIdentityInfo"},
  1059. {13, nullptr, "CanUseApplicationCore"},
  1060. {14, nullptr, "GetCallerAppletIdentityInfo"},
  1061. {15, nullptr, "GetMainAppletApplicationControlProperty"},
  1062. {16, nullptr, "GetMainAppletStorageId"},
  1063. {17, nullptr, "GetCallerAppletIdentityInfoStack"},
  1064. {18, nullptr, "GetNextReturnDestinationAppletIdentityInfo"},
  1065. {19, nullptr, "GetDesirableKeyboardLayout"},
  1066. {20, nullptr, "PopExtraStorage"},
  1067. {25, nullptr, "GetPopExtraStorageEvent"},
  1068. {30, nullptr, "UnpopInData"},
  1069. {31, nullptr, "UnpopExtraStorage"},
  1070. {40, nullptr, "GetIndirectLayerProducerHandle"},
  1071. {50, nullptr, "ReportVisibleError"},
  1072. {51, nullptr, "ReportVisibleErrorWithErrorContext"},
  1073. {60, nullptr, "GetMainAppletApplicationDesiredLanguage"},
  1074. {70, nullptr, "GetCurrentApplicationId"},
  1075. {80, nullptr, "RequestExitToSelf"},
  1076. {90, nullptr, "CreateApplicationAndPushAndRequestToLaunch"},
  1077. {100, nullptr, "CreateGameMovieTrimmer"},
  1078. {101, nullptr, "ReserveResourceForMovieOperation"},
  1079. {102, nullptr, "UnreserveResourceForMovieOperation"},
  1080. {110, nullptr, "GetMainAppletAvailableUsers"},
  1081. {120, nullptr, "GetLaunchStorageInfoForDebug"},
  1082. {130, nullptr, "GetGpuErrorDetectedSystemEvent"},
  1083. {140, nullptr, "SetApplicationMemoryReservation"},
  1084. {150, nullptr, "ShouldSetGpuTimeSliceManually"},
  1085. };
  1086. RegisterHandlers(functions);
  1087. }
  1088. ILibraryAppletSelfAccessor::~ILibraryAppletSelfAccessor() = default;
  1089. IApplicationFunctions::IApplicationFunctions(Core::System& system_)
  1090. : ServiceFramework{system_, "IApplicationFunctions"}, service_context{system,
  1091. "IApplicationFunctions"} {
  1092. // clang-format off
  1093. static const FunctionInfo functions[] = {
  1094. {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
  1095. {10, nullptr, "CreateApplicationAndPushAndRequestToStart"},
  1096. {11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"},
  1097. {12, nullptr, "CreateApplicationAndRequestToStart"},
  1098. {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest, "CreateApplicationAndRequestToStartForQuest"},
  1099. {14, nullptr, "CreateApplicationWithAttributeAndPushAndRequestToStartForQuest"},
  1100. {15, nullptr, "CreateApplicationWithAttributeAndRequestToStartForQuest"},
  1101. {20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"},
  1102. {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"},
  1103. {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"},
  1104. {23, &IApplicationFunctions::GetDisplayVersion, "GetDisplayVersion"},
  1105. {24, nullptr, "GetLaunchStorageInfoForDebug"},
  1106. {25, &IApplicationFunctions::ExtendSaveData, "ExtendSaveData"},
  1107. {26, &IApplicationFunctions::GetSaveDataSize, "GetSaveDataSize"},
  1108. {27, &IApplicationFunctions::CreateCacheStorage, "CreateCacheStorage"},
  1109. {28, nullptr, "GetSaveDataSizeMax"},
  1110. {29, nullptr, "GetCacheStorageMax"},
  1111. {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed, "BeginBlockingHomeButtonShortAndLongPressed"},
  1112. {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed, "EndBlockingHomeButtonShortAndLongPressed"},
  1113. {32, &IApplicationFunctions::BeginBlockingHomeButton, "BeginBlockingHomeButton"},
  1114. {33, &IApplicationFunctions::EndBlockingHomeButton, "EndBlockingHomeButton"},
  1115. {34, nullptr, "SelectApplicationLicense"},
  1116. {35, nullptr, "GetDeviceSaveDataSizeMax"},
  1117. {36, nullptr, "GetLimitedApplicationLicense"},
  1118. {37, nullptr, "GetLimitedApplicationLicenseUpgradableEvent"},
  1119. {40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"},
  1120. {50, &IApplicationFunctions::GetPseudoDeviceId, "GetPseudoDeviceId"},
  1121. {60, nullptr, "SetMediaPlaybackStateForApplication"},
  1122. {65, &IApplicationFunctions::IsGamePlayRecordingSupported, "IsGamePlayRecordingSupported"},
  1123. {66, &IApplicationFunctions::InitializeGamePlayRecording, "InitializeGamePlayRecording"},
  1124. {67, &IApplicationFunctions::SetGamePlayRecordingState, "SetGamePlayRecordingState"},
  1125. {68, nullptr, "RequestFlushGamePlayingMovieForDebug"},
  1126. {70, nullptr, "RequestToShutdown"},
  1127. {71, nullptr, "RequestToReboot"},
  1128. {72, nullptr, "RequestToSleep"},
  1129. {80, nullptr, "ExitAndRequestToShowThanksMessage"},
  1130. {90, &IApplicationFunctions::EnableApplicationCrashReport, "EnableApplicationCrashReport"},
  1131. {100, &IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer, "InitializeApplicationCopyrightFrameBuffer"},
  1132. {101, &IApplicationFunctions::SetApplicationCopyrightImage, "SetApplicationCopyrightImage"},
  1133. {102, &IApplicationFunctions::SetApplicationCopyrightVisibility, "SetApplicationCopyrightVisibility"},
  1134. {110, &IApplicationFunctions::QueryApplicationPlayStatistics, "QueryApplicationPlayStatistics"},
  1135. {111, &IApplicationFunctions::QueryApplicationPlayStatisticsByUid, "QueryApplicationPlayStatisticsByUid"},
  1136. {120, &IApplicationFunctions::ExecuteProgram, "ExecuteProgram"},
  1137. {121, &IApplicationFunctions::ClearUserChannel, "ClearUserChannel"},
  1138. {122, &IApplicationFunctions::UnpopToUserChannel, "UnpopToUserChannel"},
  1139. {123, &IApplicationFunctions::GetPreviousProgramIndex, "GetPreviousProgramIndex"},
  1140. {124, nullptr, "EnableApplicationAllThreadDumpOnCrash"},
  1141. {130, &IApplicationFunctions::GetGpuErrorDetectedSystemEvent, "GetGpuErrorDetectedSystemEvent"},
  1142. {131, nullptr, "SetDelayTimeToAbortOnGpuError"},
  1143. {140, &IApplicationFunctions::GetFriendInvitationStorageChannelEvent, "GetFriendInvitationStorageChannelEvent"},
  1144. {141, &IApplicationFunctions::TryPopFromFriendInvitationStorageChannel, "TryPopFromFriendInvitationStorageChannel"},
  1145. {150, &IApplicationFunctions::GetNotificationStorageChannelEvent, "GetNotificationStorageChannelEvent"},
  1146. {151, nullptr, "TryPopFromNotificationStorageChannel"},
  1147. {160, &IApplicationFunctions::GetHealthWarningDisappearedSystemEvent, "GetHealthWarningDisappearedSystemEvent"},
  1148. {170, nullptr, "SetHdcpAuthenticationActivated"},
  1149. {180, nullptr, "GetLaunchRequiredVersion"},
  1150. {181, nullptr, "UpgradeLaunchRequiredVersion"},
  1151. {190, nullptr, "SendServerMaintenanceOverlayNotification"},
  1152. {200, nullptr, "GetLastApplicationExitReason"},
  1153. {500, nullptr, "StartContinuousRecordingFlushForDebug"},
  1154. {1000, nullptr, "CreateMovieMaker"},
  1155. {1001, &IApplicationFunctions::PrepareForJit, "PrepareForJit"},
  1156. };
  1157. // clang-format on
  1158. RegisterHandlers(functions);
  1159. gpu_error_detected_event =
  1160. service_context.CreateEvent("IApplicationFunctions:GpuErrorDetectedSystemEvent");
  1161. friend_invitation_storage_channel_event =
  1162. service_context.CreateEvent("IApplicationFunctions:FriendInvitationStorageChannelEvent");
  1163. notification_storage_channel_event =
  1164. service_context.CreateEvent("IApplicationFunctions:NotificationStorageChannelEvent");
  1165. health_warning_disappeared_system_event =
  1166. service_context.CreateEvent("IApplicationFunctions:HealthWarningDisappearedSystemEvent");
  1167. }
  1168. IApplicationFunctions::~IApplicationFunctions() {
  1169. service_context.CloseEvent(gpu_error_detected_event);
  1170. service_context.CloseEvent(friend_invitation_storage_channel_event);
  1171. service_context.CloseEvent(notification_storage_channel_event);
  1172. service_context.CloseEvent(health_warning_disappeared_system_event);
  1173. }
  1174. void IApplicationFunctions::EnableApplicationCrashReport(HLERequestContext& ctx) {
  1175. LOG_WARNING(Service_AM, "(STUBBED) called");
  1176. IPC::ResponseBuilder rb{ctx, 2};
  1177. rb.Push(ResultSuccess);
  1178. }
  1179. void IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer(HLERequestContext& ctx) {
  1180. LOG_WARNING(Service_AM, "(STUBBED) called");
  1181. IPC::ResponseBuilder rb{ctx, 2};
  1182. rb.Push(ResultSuccess);
  1183. }
  1184. void IApplicationFunctions::SetApplicationCopyrightImage(HLERequestContext& ctx) {
  1185. LOG_WARNING(Service_AM, "(STUBBED) called");
  1186. IPC::ResponseBuilder rb{ctx, 2};
  1187. rb.Push(ResultSuccess);
  1188. }
  1189. void IApplicationFunctions::SetApplicationCopyrightVisibility(HLERequestContext& ctx) {
  1190. IPC::RequestParser rp{ctx};
  1191. const auto is_visible = rp.Pop<bool>();
  1192. LOG_WARNING(Service_AM, "(STUBBED) called, is_visible={}", is_visible);
  1193. IPC::ResponseBuilder rb{ctx, 2};
  1194. rb.Push(ResultSuccess);
  1195. }
  1196. void IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx) {
  1197. LOG_WARNING(Service_AM, "(STUBBED) called");
  1198. IPC::ResponseBuilder rb{ctx, 2};
  1199. rb.Push(ResultSuccess);
  1200. }
  1201. void IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx) {
  1202. LOG_WARNING(Service_AM, "(STUBBED) called");
  1203. IPC::ResponseBuilder rb{ctx, 2};
  1204. rb.Push(ResultSuccess);
  1205. }
  1206. void IApplicationFunctions::BeginBlockingHomeButton(HLERequestContext& ctx) {
  1207. LOG_WARNING(Service_AM, "(STUBBED) called");
  1208. IPC::ResponseBuilder rb{ctx, 2};
  1209. rb.Push(ResultSuccess);
  1210. }
  1211. void IApplicationFunctions::EndBlockingHomeButton(HLERequestContext& ctx) {
  1212. LOG_WARNING(Service_AM, "(STUBBED) called");
  1213. IPC::ResponseBuilder rb{ctx, 2};
  1214. rb.Push(ResultSuccess);
  1215. }
  1216. void IApplicationFunctions::PopLaunchParameter(HLERequestContext& ctx) {
  1217. IPC::RequestParser rp{ctx};
  1218. const auto kind = rp.PopEnum<LaunchParameterKind>();
  1219. LOG_DEBUG(Service_AM, "called, kind={:08X}", kind);
  1220. if (kind == LaunchParameterKind::ApplicationSpecific && !launch_popped_application_specific) {
  1221. const auto backend = BCAT::CreateBackendFromSettings(system, [this](u64 tid) {
  1222. return system.GetFileSystemController().GetBCATDirectory(tid);
  1223. });
  1224. const auto build_id_full = system.GetApplicationProcessBuildID();
  1225. u64 build_id{};
  1226. std::memcpy(&build_id, build_id_full.data(), sizeof(u64));
  1227. auto data =
  1228. backend->GetLaunchParameter({system.GetApplicationProcessProgramID(), build_id});
  1229. if (data.has_value()) {
  1230. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  1231. rb.Push(ResultSuccess);
  1232. rb.PushIpcInterface<IStorage>(system, std::move(*data));
  1233. launch_popped_application_specific = true;
  1234. return;
  1235. }
  1236. } else if (kind == LaunchParameterKind::AccountPreselectedUser &&
  1237. !launch_popped_account_preselect) {
  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. return;
  1252. }
  1253. LOG_ERROR(Service_AM, "Attempted to load launch parameter but none was found!");
  1254. IPC::ResponseBuilder rb{ctx, 2};
  1255. rb.Push(AM::ResultNoDataInChannel);
  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_WARNING(Service_AM, "(STUBBED) called");
  1482. IPC::ResponseBuilder rb{ctx, 2};
  1483. rb.Push(ResultSuccess);
  1484. }
  1485. void IApplicationFunctions::UnpopToUserChannel(HLERequestContext& ctx) {
  1486. LOG_WARNING(Service_AM, "(STUBBED) called");
  1487. IPC::ResponseBuilder rb{ctx, 2};
  1488. rb.Push(ResultSuccess);
  1489. }
  1490. void IApplicationFunctions::GetPreviousProgramIndex(HLERequestContext& ctx) {
  1491. LOG_WARNING(Service_AM, "(STUBBED) called");
  1492. IPC::ResponseBuilder rb{ctx, 3};
  1493. rb.Push(ResultSuccess);
  1494. rb.Push<s32>(previous_program_index);
  1495. }
  1496. void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(HLERequestContext& ctx) {
  1497. LOG_WARNING(Service_AM, "(STUBBED) called");
  1498. IPC::ResponseBuilder rb{ctx, 2, 1};
  1499. rb.Push(ResultSuccess);
  1500. rb.PushCopyObjects(gpu_error_detected_event->GetReadableEvent());
  1501. }
  1502. void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(HLERequestContext& ctx) {
  1503. LOG_DEBUG(Service_AM, "called");
  1504. IPC::ResponseBuilder rb{ctx, 2, 1};
  1505. rb.Push(ResultSuccess);
  1506. rb.PushCopyObjects(friend_invitation_storage_channel_event->GetReadableEvent());
  1507. }
  1508. void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel(HLERequestContext& ctx) {
  1509. LOG_DEBUG(Service_AM, "(STUBBED) called");
  1510. IPC::ResponseBuilder rb{ctx, 2};
  1511. rb.Push(AM::ResultNoDataInChannel);
  1512. }
  1513. void IApplicationFunctions::GetNotificationStorageChannelEvent(HLERequestContext& ctx) {
  1514. LOG_DEBUG(Service_AM, "called");
  1515. IPC::ResponseBuilder rb{ctx, 2, 1};
  1516. rb.Push(ResultSuccess);
  1517. rb.PushCopyObjects(notification_storage_channel_event->GetReadableEvent());
  1518. }
  1519. void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(HLERequestContext& ctx) {
  1520. LOG_DEBUG(Service_AM, "called");
  1521. IPC::ResponseBuilder rb{ctx, 2, 1};
  1522. rb.Push(ResultSuccess);
  1523. rb.PushCopyObjects(health_warning_disappeared_system_event->GetReadableEvent());
  1524. }
  1525. void IApplicationFunctions::PrepareForJit(HLERequestContext& ctx) {
  1526. LOG_WARNING(Service_AM, "(STUBBED) called");
  1527. IPC::ResponseBuilder rb{ctx, 2};
  1528. rb.Push(ResultSuccess);
  1529. }
  1530. void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) {
  1531. auto message_queue = std::make_shared<AppletMessageQueue>(system);
  1532. // Needed on game boot
  1533. message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
  1534. auto server_manager = std::make_unique<ServerManager>(system);
  1535. server_manager->RegisterNamedService(
  1536. "appletAE", std::make_shared<AppletAE>(nvnflinger, message_queue, system));
  1537. server_manager->RegisterNamedService(
  1538. "appletOE", std::make_shared<AppletOE>(nvnflinger, message_queue, system));
  1539. server_manager->RegisterNamedService("idle:sys", std::make_shared<IdleSys>(system));
  1540. server_manager->RegisterNamedService("omm", std::make_shared<OMM>(system));
  1541. server_manager->RegisterNamedService("spsm", std::make_shared<SPSM>(system));
  1542. ServerManager::RunServer(std::move(server_manager));
  1543. }
  1544. IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_)
  1545. : ServiceFramework{system_, "IHomeMenuFunctions"}, service_context{system,
  1546. "IHomeMenuFunctions"} {
  1547. // clang-format off
  1548. static const FunctionInfo functions[] = {
  1549. {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
  1550. {11, nullptr, "LockForeground"},
  1551. {12, nullptr, "UnlockForeground"},
  1552. {20, nullptr, "PopFromGeneralChannel"},
  1553. {21, &IHomeMenuFunctions::GetPopFromGeneralChannelEvent, "GetPopFromGeneralChannelEvent"},
  1554. {30, nullptr, "GetHomeButtonWriterLockAccessor"},
  1555. {31, nullptr, "GetWriterLockAccessorEx"},
  1556. {40, nullptr, "IsSleepEnabled"},
  1557. {41, nullptr, "IsRebootEnabled"},
  1558. {50, nullptr, "LaunchSystemApplet"},
  1559. {51, nullptr, "LaunchStarter"},
  1560. {100, nullptr, "PopRequestLaunchApplicationForDebug"},
  1561. {110, nullptr, "IsForceTerminateApplicationDisabledForDebug"},
  1562. {200, nullptr, "LaunchDevMenu"},
  1563. {1000, nullptr, "SetLastApplicationExitReason"},
  1564. };
  1565. // clang-format on
  1566. RegisterHandlers(functions);
  1567. pop_from_general_channel_event =
  1568. service_context.CreateEvent("IHomeMenuFunctions:PopFromGeneralChannelEvent");
  1569. }
  1570. IHomeMenuFunctions::~IHomeMenuFunctions() {
  1571. service_context.CloseEvent(pop_from_general_channel_event);
  1572. }
  1573. void IHomeMenuFunctions::RequestToGetForeground(HLERequestContext& ctx) {
  1574. LOG_WARNING(Service_AM, "(STUBBED) called");
  1575. IPC::ResponseBuilder rb{ctx, 2};
  1576. rb.Push(ResultSuccess);
  1577. }
  1578. void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(HLERequestContext& ctx) {
  1579. LOG_WARNING(Service_AM, "(STUBBED) called");
  1580. IPC::ResponseBuilder rb{ctx, 2, 1};
  1581. rb.Push(ResultSuccess);
  1582. rb.PushCopyObjects(pop_from_general_channel_event->GetReadableEvent());
  1583. }
  1584. IGlobalStateController::IGlobalStateController(Core::System& system_)
  1585. : ServiceFramework{system_, "IGlobalStateController"} {
  1586. // clang-format off
  1587. static const FunctionInfo functions[] = {
  1588. {0, nullptr, "RequestToEnterSleep"},
  1589. {1, nullptr, "EnterSleep"},
  1590. {2, nullptr, "StartSleepSequence"},
  1591. {3, nullptr, "StartShutdownSequence"},
  1592. {4, nullptr, "StartRebootSequence"},
  1593. {9, nullptr, "IsAutoPowerDownRequested"},
  1594. {10, nullptr, "LoadAndApplyIdlePolicySettings"},
  1595. {11, nullptr, "NotifyCecSettingsChanged"},
  1596. {12, nullptr, "SetDefaultHomeButtonLongPressTime"},
  1597. {13, nullptr, "UpdateDefaultDisplayResolution"},
  1598. {14, nullptr, "ShouldSleepOnBoot"},
  1599. {15, nullptr, "GetHdcpAuthenticationFailedEvent"},
  1600. {30, nullptr, "OpenCradleFirmwareUpdater"},
  1601. };
  1602. // clang-format on
  1603. RegisterHandlers(functions);
  1604. }
  1605. IGlobalStateController::~IGlobalStateController() = default;
  1606. IApplicationCreator::IApplicationCreator(Core::System& system_)
  1607. : ServiceFramework{system_, "IApplicationCreator"} {
  1608. // clang-format off
  1609. static const FunctionInfo functions[] = {
  1610. {0, nullptr, "CreateApplication"},
  1611. {1, nullptr, "PopLaunchRequestedApplication"},
  1612. {10, nullptr, "CreateSystemApplication"},
  1613. {100, nullptr, "PopFloatingApplicationForDevelopment"},
  1614. };
  1615. // clang-format on
  1616. RegisterHandlers(functions);
  1617. }
  1618. IApplicationCreator::~IApplicationCreator() = default;
  1619. IProcessWindingController::IProcessWindingController(Core::System& system_)
  1620. : ServiceFramework{system_, "IProcessWindingController"} {
  1621. // clang-format off
  1622. static const FunctionInfo functions[] = {
  1623. {0, nullptr, "GetLaunchReason"},
  1624. {11, nullptr, "OpenCallingLibraryApplet"},
  1625. {21, nullptr, "PushContext"},
  1626. {22, nullptr, "PopContext"},
  1627. {23, nullptr, "CancelWindingReservation"},
  1628. {30, nullptr, "WindAndDoReserved"},
  1629. {40, nullptr, "ReserveToStartAndWaitAndUnwindThis"},
  1630. {41, nullptr, "ReserveToStartAndWait"},
  1631. };
  1632. // clang-format on
  1633. RegisterHandlers(functions);
  1634. }
  1635. IProcessWindingController::~IProcessWindingController() = default;
  1636. } // namespace Service::AM