am.cpp 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include <array>
  6. #include <cinttypes>
  7. #include <cstring>
  8. #include "audio_core/audio_renderer.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/savedata_factory.h"
  13. #include "core/hle/ipc_helpers.h"
  14. #include "core/hle/kernel/kernel.h"
  15. #include "core/hle/kernel/process.h"
  16. #include "core/hle/kernel/readable_event.h"
  17. #include "core/hle/kernel/transfer_memory.h"
  18. #include "core/hle/kernel/writable_event.h"
  19. #include "core/hle/service/acc/profile_manager.h"
  20. #include "core/hle/service/am/am.h"
  21. #include "core/hle/service/am/applet_ae.h"
  22. #include "core/hle/service/am/applet_oe.h"
  23. #include "core/hle/service/am/applets/applets.h"
  24. #include "core/hle/service/am/applets/profile_select.h"
  25. #include "core/hle/service/am/applets/software_keyboard.h"
  26. #include "core/hle/service/am/applets/web_browser.h"
  27. #include "core/hle/service/am/idle.h"
  28. #include "core/hle/service/am/omm.h"
  29. #include "core/hle/service/am/spsm.h"
  30. #include "core/hle/service/am/tcap.h"
  31. #include "core/hle/service/apm/controller.h"
  32. #include "core/hle/service/apm/interface.h"
  33. #include "core/hle/service/bcat/backend/backend.h"
  34. #include "core/hle/service/filesystem/filesystem.h"
  35. #include "core/hle/service/ns/ns.h"
  36. #include "core/hle/service/nvflinger/nvflinger.h"
  37. #include "core/hle/service/pm/pm.h"
  38. #include "core/hle/service/set/set.h"
  39. #include "core/hle/service/sm/sm.h"
  40. #include "core/hle/service/vi/vi.h"
  41. #include "core/settings.h"
  42. namespace Service::AM {
  43. constexpr ResultCode ERR_NO_DATA_IN_CHANNEL{ErrorModule::AM, 0x2};
  44. constexpr ResultCode ERR_NO_MESSAGES{ErrorModule::AM, 0x3};
  45. constexpr ResultCode ERR_SIZE_OUT_OF_BOUNDS{ErrorModule::AM, 0x1F7};
  46. enum class LaunchParameterKind : u32 {
  47. ApplicationSpecific = 1,
  48. AccountPreselectedUser = 2,
  49. };
  50. constexpr u32 LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC = 0xC79497CA;
  51. struct LaunchParameterAccountPreselectedUser {
  52. u32_le magic;
  53. u32_le is_account_selected;
  54. u128 current_user;
  55. INSERT_PADDING_BYTES(0x70);
  56. };
  57. static_assert(sizeof(LaunchParameterAccountPreselectedUser) == 0x88);
  58. IWindowController::IWindowController(Core::System& system_)
  59. : ServiceFramework("IWindowController"), system{system_} {
  60. // clang-format off
  61. static const FunctionInfo functions[] = {
  62. {0, nullptr, "CreateWindow"},
  63. {1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"},
  64. {10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"},
  65. {11, nullptr, "ReleaseForegroundRights"},
  66. {12, nullptr, "RejectToChangeIntoBackground"},
  67. {20, nullptr, "SetAppletWindowVisibility"},
  68. {21, nullptr, "SetAppletGpuTimeSlice"},
  69. };
  70. // clang-format on
  71. RegisterHandlers(functions);
  72. }
  73. IWindowController::~IWindowController() = default;
  74. void IWindowController::GetAppletResourceUserId(Kernel::HLERequestContext& ctx) {
  75. const u64 process_id = system.CurrentProcess()->GetProcessID();
  76. LOG_DEBUG(Service_AM, "called. Process ID=0x{:016X}", process_id);
  77. IPC::ResponseBuilder rb{ctx, 4};
  78. rb.Push(RESULT_SUCCESS);
  79. rb.Push<u64>(process_id);
  80. }
  81. void IWindowController::AcquireForegroundRights(Kernel::HLERequestContext& ctx) {
  82. LOG_WARNING(Service_AM, "(STUBBED) called");
  83. IPC::ResponseBuilder rb{ctx, 2};
  84. rb.Push(RESULT_SUCCESS);
  85. }
  86. IAudioController::IAudioController() : ServiceFramework("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(Kernel::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(RESULT_SUCCESS);
  111. }
  112. void IAudioController::GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) {
  113. LOG_DEBUG(Service_AM, "called. main_applet_volume={}", main_applet_volume);
  114. IPC::ResponseBuilder rb{ctx, 3};
  115. rb.Push(RESULT_SUCCESS);
  116. rb.Push(main_applet_volume);
  117. }
  118. void IAudioController::GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) {
  119. LOG_DEBUG(Service_AM, "called. library_applet_volume={}", library_applet_volume);
  120. IPC::ResponseBuilder rb{ctx, 3};
  121. rb.Push(RESULT_SUCCESS);
  122. rb.Push(library_applet_volume);
  123. }
  124. void IAudioController::ChangeMainAppletMasterVolume(Kernel::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(RESULT_SUCCESS);
  138. }
  139. void IAudioController::SetTransparentAudioRate(Kernel::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(RESULT_SUCCESS);
  148. }
  149. IDisplayController::IDisplayController() : ServiceFramework("IDisplayController") {
  150. // clang-format off
  151. static const FunctionInfo functions[] = {
  152. {0, nullptr, "GetLastForegroundCaptureImage"},
  153. {1, nullptr, "UpdateLastForegroundCaptureImage"},
  154. {2, nullptr, "GetLastApplicationCaptureImage"},
  155. {3, nullptr, "GetCallerAppletCaptureImage"},
  156. {4, nullptr, "UpdateCallerAppletCaptureImage"},
  157. {5, nullptr, "GetLastForegroundCaptureImageEx"},
  158. {6, nullptr, "GetLastApplicationCaptureImageEx"},
  159. {7, nullptr, "GetCallerAppletCaptureImageEx"},
  160. {8, nullptr, "TakeScreenShotOfOwnLayer"}, // 2.0.0+
  161. {9, nullptr, "CopyBetweenCaptureBuffers"}, // 5.0.0+
  162. {10, nullptr, "AcquireLastApplicationCaptureBuffer"},
  163. {11, nullptr, "ReleaseLastApplicationCaptureBuffer"},
  164. {12, nullptr, "AcquireLastForegroundCaptureBuffer"},
  165. {13, nullptr, "ReleaseLastForegroundCaptureBuffer"},
  166. {14, nullptr, "AcquireCallerAppletCaptureBuffer"},
  167. {15, nullptr, "ReleaseCallerAppletCaptureBuffer"},
  168. {16, nullptr, "AcquireLastApplicationCaptureBufferEx"},
  169. {17, nullptr, "AcquireLastForegroundCaptureBufferEx"},
  170. {18, nullptr, "AcquireCallerAppletCaptureBufferEx"},
  171. // 2.0.0+
  172. {20, nullptr, "ClearCaptureBuffer"},
  173. {21, nullptr, "ClearAppletTransitionBuffer"},
  174. // 4.0.0+
  175. {22, nullptr, "AcquireLastApplicationCaptureSharedBuffer"},
  176. {23, nullptr, "ReleaseLastApplicationCaptureSharedBuffer"},
  177. {24, nullptr, "AcquireLastForegroundCaptureSharedBuffer"},
  178. {25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"},
  179. {26, nullptr, "AcquireCallerAppletCaptureSharedBuffer"},
  180. {27, nullptr, "ReleaseCallerAppletCaptureSharedBuffer"},
  181. // 6.0.0+
  182. {28, nullptr, "TakeScreenShotOfOwnLayerEx"},
  183. };
  184. // clang-format on
  185. RegisterHandlers(functions);
  186. }
  187. IDisplayController::~IDisplayController() = default;
  188. IDebugFunctions::IDebugFunctions() : ServiceFramework{"IDebugFunctions"} {
  189. // clang-format off
  190. static const FunctionInfo functions[] = {
  191. {0, nullptr, "NotifyMessageToHomeMenuForDebug"},
  192. {1, nullptr, "OpenMainApplication"},
  193. {10, nullptr, "EmulateButtonEvent"},
  194. {20, nullptr, "InvalidateTransitionLayer"},
  195. {30, nullptr, "RequestLaunchApplicationWithUserAndArgumentForDebug"},
  196. {40, nullptr, "GetAppletResourceUsageInfo"},
  197. {41, nullptr, "SetCpuBoostModeForApplet"},
  198. };
  199. // clang-format on
  200. RegisterHandlers(functions);
  201. }
  202. IDebugFunctions::~IDebugFunctions() = default;
  203. ISelfController::ISelfController(Core::System& system,
  204. std::shared_ptr<NVFlinger::NVFlinger> nvflinger)
  205. : ServiceFramework("ISelfController"), system(system), nvflinger(std::move(nvflinger)) {
  206. // clang-format off
  207. static const FunctionInfo functions[] = {
  208. {0, &ISelfController::Exit, "Exit"},
  209. {1, &ISelfController::LockExit, "LockExit"},
  210. {2, &ISelfController::UnlockExit, "UnlockExit"},
  211. {3, &ISelfController::EnterFatalSection, "EnterFatalSection"},
  212. {4, &ISelfController::LeaveFatalSection, "LeaveFatalSection"},
  213. {9, &ISelfController::GetLibraryAppletLaunchableEvent, "GetLibraryAppletLaunchableEvent"},
  214. {10, &ISelfController::SetScreenShotPermission, "SetScreenShotPermission"},
  215. {11, &ISelfController::SetOperationModeChangedNotification, "SetOperationModeChangedNotification"},
  216. {12, &ISelfController::SetPerformanceModeChangedNotification, "SetPerformanceModeChangedNotification"},
  217. {13, &ISelfController::SetFocusHandlingMode, "SetFocusHandlingMode"},
  218. {14, &ISelfController::SetRestartMessageEnabled, "SetRestartMessageEnabled"},
  219. {15, nullptr, "SetScreenShotAppletIdentityInfo"},
  220. {16, &ISelfController::SetOutOfFocusSuspendingEnabled, "SetOutOfFocusSuspendingEnabled"},
  221. {17, nullptr, "SetControllerFirmwareUpdateSection"},
  222. {18, nullptr, "SetRequiresCaptureButtonShortPressedMessage"},
  223. {19, &ISelfController::SetScreenShotImageOrientation, "SetScreenShotImageOrientation"},
  224. {20, nullptr, "SetDesirableKeyboardLayout"},
  225. {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"},
  226. {41, nullptr, "IsSystemBufferSharingEnabled"},
  227. {42, nullptr, "GetSystemSharedLayerHandle"},
  228. {43, nullptr, "GetSystemSharedBufferHandle"},
  229. {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"},
  230. {51, nullptr, "ApproveToDisplay"},
  231. {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"},
  232. {61, nullptr, "SetMediaPlaybackState"},
  233. {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"},
  234. {63, &ISelfController::GetIdleTimeDetectionExtension, "GetIdleTimeDetectionExtension"},
  235. {64, nullptr, "SetInputDetectionSourceSet"},
  236. {65, nullptr, "ReportUserIsActive"},
  237. {66, nullptr, "GetCurrentIlluminance"},
  238. {67, nullptr, "IsIlluminanceAvailable"},
  239. {68, &ISelfController::SetAutoSleepDisabled, "SetAutoSleepDisabled"},
  240. {69, &ISelfController::IsAutoSleepDisabled, "IsAutoSleepDisabled"},
  241. {70, nullptr, "ReportMultimediaError"},
  242. {71, nullptr, "GetCurrentIlluminanceEx"},
  243. {80, nullptr, "SetWirelessPriorityMode"},
  244. {90, &ISelfController::GetAccumulatedSuspendedTickValue, "GetAccumulatedSuspendedTickValue"},
  245. {91, &ISelfController::GetAccumulatedSuspendedTickChangedEvent, "GetAccumulatedSuspendedTickChangedEvent"},
  246. {100, nullptr, "SetAlbumImageTakenNotificationEnabled"},
  247. {1000, nullptr, "GetDebugStorageChannel"},
  248. };
  249. // clang-format on
  250. RegisterHandlers(functions);
  251. auto& kernel = system.Kernel();
  252. launchable_event =
  253. Kernel::WritableEvent::CreateEventPair(kernel, "ISelfController:LaunchableEvent");
  254. // This event is created by AM on the first time GetAccumulatedSuspendedTickChangedEvent() is
  255. // called. Yuzu can just create it unconditionally, since it doesn't need to support multiple
  256. // ISelfControllers. The event is signaled on creation, and on transition from suspended -> not
  257. // suspended if the event has previously been created by a call to
  258. // GetAccumulatedSuspendedTickChangedEvent.
  259. accumulated_suspended_tick_changed_event = Kernel::WritableEvent::CreateEventPair(
  260. kernel, "ISelfController:AccumulatedSuspendedTickChangedEvent");
  261. accumulated_suspended_tick_changed_event.writable->Signal();
  262. }
  263. ISelfController::~ISelfController() = default;
  264. void ISelfController::Exit(Kernel::HLERequestContext& ctx) {
  265. LOG_DEBUG(Service_AM, "called");
  266. system.Shutdown();
  267. IPC::ResponseBuilder rb{ctx, 2};
  268. rb.Push(RESULT_SUCCESS);
  269. }
  270. void ISelfController::LockExit(Kernel::HLERequestContext& ctx) {
  271. LOG_DEBUG(Service_AM, "called");
  272. system.SetExitLock(true);
  273. IPC::ResponseBuilder rb{ctx, 2};
  274. rb.Push(RESULT_SUCCESS);
  275. }
  276. void ISelfController::UnlockExit(Kernel::HLERequestContext& ctx) {
  277. LOG_DEBUG(Service_AM, "called");
  278. system.SetExitLock(false);
  279. IPC::ResponseBuilder rb{ctx, 2};
  280. rb.Push(RESULT_SUCCESS);
  281. }
  282. void ISelfController::EnterFatalSection(Kernel::HLERequestContext& ctx) {
  283. ++num_fatal_sections_entered;
  284. LOG_DEBUG(Service_AM, "called. Num fatal sections entered: {}", num_fatal_sections_entered);
  285. IPC::ResponseBuilder rb{ctx, 2};
  286. rb.Push(RESULT_SUCCESS);
  287. }
  288. void ISelfController::LeaveFatalSection(Kernel::HLERequestContext& ctx) {
  289. LOG_DEBUG(Service_AM, "called.");
  290. // Entry and exit of fatal sections must be balanced.
  291. if (num_fatal_sections_entered == 0) {
  292. IPC::ResponseBuilder rb{ctx, 2};
  293. rb.Push(ResultCode{ErrorModule::AM, 512});
  294. return;
  295. }
  296. --num_fatal_sections_entered;
  297. IPC::ResponseBuilder rb{ctx, 2};
  298. rb.Push(RESULT_SUCCESS);
  299. }
  300. void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) {
  301. LOG_WARNING(Service_AM, "(STUBBED) called");
  302. launchable_event.writable->Signal();
  303. IPC::ResponseBuilder rb{ctx, 2, 1};
  304. rb.Push(RESULT_SUCCESS);
  305. rb.PushCopyObjects(launchable_event.readable);
  306. }
  307. void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) {
  308. LOG_WARNING(Service_AM, "(STUBBED) called");
  309. IPC::ResponseBuilder rb{ctx, 2};
  310. rb.Push(RESULT_SUCCESS);
  311. }
  312. void ISelfController::SetOperationModeChangedNotification(Kernel::HLERequestContext& ctx) {
  313. IPC::RequestParser rp{ctx};
  314. bool flag = rp.Pop<bool>();
  315. LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  316. IPC::ResponseBuilder rb{ctx, 2};
  317. rb.Push(RESULT_SUCCESS);
  318. }
  319. void ISelfController::SetPerformanceModeChangedNotification(Kernel::HLERequestContext& ctx) {
  320. IPC::RequestParser rp{ctx};
  321. bool flag = rp.Pop<bool>();
  322. LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  323. IPC::ResponseBuilder rb{ctx, 2};
  324. rb.Push(RESULT_SUCCESS);
  325. }
  326. void ISelfController::SetFocusHandlingMode(Kernel::HLERequestContext& ctx) {
  327. // Takes 3 input u8s with each field located immediately after the previous
  328. // u8, these are bool flags. No output.
  329. IPC::RequestParser rp{ctx};
  330. struct FocusHandlingModeParams {
  331. u8 unknown0;
  332. u8 unknown1;
  333. u8 unknown2;
  334. };
  335. const auto flags = rp.PopRaw<FocusHandlingModeParams>();
  336. LOG_WARNING(Service_AM, "(STUBBED) called. unknown0={}, unknown1={}, unknown2={}",
  337. flags.unknown0, flags.unknown1, flags.unknown2);
  338. IPC::ResponseBuilder rb{ctx, 2};
  339. rb.Push(RESULT_SUCCESS);
  340. }
  341. void ISelfController::SetRestartMessageEnabled(Kernel::HLERequestContext& ctx) {
  342. LOG_WARNING(Service_AM, "(STUBBED) called");
  343. IPC::ResponseBuilder rb{ctx, 2};
  344. rb.Push(RESULT_SUCCESS);
  345. }
  346. void ISelfController::SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& ctx) {
  347. // Takes 3 input u8s with each field located immediately after the previous
  348. // u8, these are bool flags. No output.
  349. IPC::RequestParser rp{ctx};
  350. bool enabled = rp.Pop<bool>();
  351. LOG_WARNING(Service_AM, "(STUBBED) called enabled={}", enabled);
  352. IPC::ResponseBuilder rb{ctx, 2};
  353. rb.Push(RESULT_SUCCESS);
  354. }
  355. void ISelfController::SetScreenShotImageOrientation(Kernel::HLERequestContext& ctx) {
  356. LOG_WARNING(Service_AM, "(STUBBED) called");
  357. IPC::ResponseBuilder rb{ctx, 2};
  358. rb.Push(RESULT_SUCCESS);
  359. }
  360. void ISelfController::CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx) {
  361. LOG_WARNING(Service_AM, "(STUBBED) called");
  362. // TODO(Subv): Find out how AM determines the display to use, for now just
  363. // create the layer in the Default display.
  364. const auto display_id = nvflinger->OpenDisplay("Default");
  365. const auto layer_id = nvflinger->CreateLayer(*display_id);
  366. IPC::ResponseBuilder rb{ctx, 4};
  367. rb.Push(RESULT_SUCCESS);
  368. rb.Push(*layer_id);
  369. }
  370. void ISelfController::SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx) {
  371. LOG_WARNING(Service_AM, "(STUBBED) called");
  372. IPC::ResponseBuilder rb{ctx, 2};
  373. rb.Push(RESULT_SUCCESS);
  374. }
  375. void ISelfController::SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx) {
  376. IPC::RequestParser rp{ctx};
  377. idle_time_detection_extension = rp.Pop<u32>();
  378. LOG_WARNING(Service_AM, "(STUBBED) called idle_time_detection_extension={}",
  379. idle_time_detection_extension);
  380. IPC::ResponseBuilder rb{ctx, 2};
  381. rb.Push(RESULT_SUCCESS);
  382. }
  383. void ISelfController::GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx) {
  384. LOG_WARNING(Service_AM, "(STUBBED) called");
  385. IPC::ResponseBuilder rb{ctx, 3};
  386. rb.Push(RESULT_SUCCESS);
  387. rb.Push<u32>(idle_time_detection_extension);
  388. }
  389. void ISelfController::SetAutoSleepDisabled(Kernel::HLERequestContext& ctx) {
  390. IPC::RequestParser rp{ctx};
  391. is_auto_sleep_disabled = rp.Pop<bool>();
  392. // On the system itself, if the previous state of is_auto_sleep_disabled
  393. // differed from the current value passed in, it'd signify the internal
  394. // window manager to update (and also increment some statistics like update counts)
  395. //
  396. // It'd also indicate this change to an idle handling context.
  397. //
  398. // However, given we're emulating this behavior, most of this can be ignored
  399. // and it's sufficient to simply set the member variable for querying via
  400. // IsAutoSleepDisabled().
  401. LOG_DEBUG(Service_AM, "called. is_auto_sleep_disabled={}", is_auto_sleep_disabled);
  402. IPC::ResponseBuilder rb{ctx, 2};
  403. rb.Push(RESULT_SUCCESS);
  404. }
  405. void ISelfController::IsAutoSleepDisabled(Kernel::HLERequestContext& ctx) {
  406. LOG_DEBUG(Service_AM, "called.");
  407. IPC::ResponseBuilder rb{ctx, 3};
  408. rb.Push(RESULT_SUCCESS);
  409. rb.Push(is_auto_sleep_disabled);
  410. }
  411. void ISelfController::GetAccumulatedSuspendedTickValue(Kernel::HLERequestContext& ctx) {
  412. LOG_DEBUG(Service_AM, "called.");
  413. // This command returns the total number of system ticks since ISelfController creation
  414. // where the game was suspended. Since Yuzu doesn't implement game suspension, this command
  415. // can just always return 0 ticks.
  416. IPC::ResponseBuilder rb{ctx, 4};
  417. rb.Push(RESULT_SUCCESS);
  418. rb.Push<u64>(0);
  419. }
  420. void ISelfController::GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequestContext& ctx) {
  421. LOG_DEBUG(Service_AM, "called.");
  422. IPC::ResponseBuilder rb{ctx, 2, 1};
  423. rb.Push(RESULT_SUCCESS);
  424. rb.PushCopyObjects(accumulated_suspended_tick_changed_event.readable);
  425. }
  426. AppletMessageQueue::AppletMessageQueue(Kernel::KernelCore& kernel) {
  427. on_new_message =
  428. Kernel::WritableEvent::CreateEventPair(kernel, "AMMessageQueue:OnMessageRecieved");
  429. on_operation_mode_changed =
  430. Kernel::WritableEvent::CreateEventPair(kernel, "AMMessageQueue:OperationModeChanged");
  431. }
  432. AppletMessageQueue::~AppletMessageQueue() = default;
  433. const Kernel::SharedPtr<Kernel::ReadableEvent>& AppletMessageQueue::GetMesssageRecieveEvent()
  434. const {
  435. return on_new_message.readable;
  436. }
  437. const Kernel::SharedPtr<Kernel::ReadableEvent>& AppletMessageQueue::GetOperationModeChangedEvent()
  438. const {
  439. return on_operation_mode_changed.readable;
  440. }
  441. void AppletMessageQueue::PushMessage(AppletMessage msg) {
  442. messages.push(msg);
  443. on_new_message.writable->Signal();
  444. }
  445. AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() {
  446. if (messages.empty()) {
  447. on_new_message.writable->Clear();
  448. return AppletMessage::NoMessage;
  449. }
  450. auto msg = messages.front();
  451. messages.pop();
  452. if (messages.empty()) {
  453. on_new_message.writable->Clear();
  454. }
  455. return msg;
  456. }
  457. std::size_t AppletMessageQueue::GetMessageCount() const {
  458. return messages.size();
  459. }
  460. void AppletMessageQueue::OperationModeChanged() {
  461. PushMessage(AppletMessage::OperationModeChanged);
  462. PushMessage(AppletMessage::PerformanceModeChanged);
  463. on_operation_mode_changed.writable->Signal();
  464. }
  465. void AppletMessageQueue::RequestExit() {
  466. PushMessage(AppletMessage::ExitRequested);
  467. }
  468. ICommonStateGetter::ICommonStateGetter(Core::System& system,
  469. std::shared_ptr<AppletMessageQueue> msg_queue)
  470. : ServiceFramework("ICommonStateGetter"), system(system), msg_queue(std::move(msg_queue)) {
  471. // clang-format off
  472. static const FunctionInfo functions[] = {
  473. {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
  474. {1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"},
  475. {2, nullptr, "GetThisAppletKind"},
  476. {3, nullptr, "AllowToEnterSleep"},
  477. {4, nullptr, "DisallowToEnterSleep"},
  478. {5, &ICommonStateGetter::GetOperationMode, "GetOperationMode"},
  479. {6, &ICommonStateGetter::GetPerformanceMode, "GetPerformanceMode"},
  480. {7, nullptr, "GetCradleStatus"},
  481. {8, &ICommonStateGetter::GetBootMode, "GetBootMode"},
  482. {9, &ICommonStateGetter::GetCurrentFocusState, "GetCurrentFocusState"},
  483. {10, nullptr, "RequestToAcquireSleepLock"},
  484. {11, nullptr, "ReleaseSleepLock"},
  485. {12, nullptr, "ReleaseSleepLockTransiently"},
  486. {13, nullptr, "GetAcquiredSleepLockEvent"},
  487. {20, nullptr, "PushToGeneralChannel"},
  488. {30, nullptr, "GetHomeButtonReaderLockAccessor"},
  489. {31, nullptr, "GetReaderLockAccessorEx"},
  490. {40, nullptr, "GetCradleFwVersion"},
  491. {50, nullptr, "IsVrModeEnabled"},
  492. {51, nullptr, "SetVrModeEnabled"},
  493. {52, nullptr, "SwitchLcdBacklight"},
  494. {53, nullptr, "BeginVrModeEx"},
  495. {54, nullptr, "EndVrModeEx"},
  496. {55, nullptr, "IsInControllerFirmwareUpdateSection"},
  497. {60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"},
  498. {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, "GetDefaultDisplayResolutionChangeEvent"},
  499. {62, nullptr, "GetHdcpAuthenticationState"},
  500. {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"},
  501. {64, nullptr, "SetTvPowerStateMatchingMode"},
  502. {65, nullptr, "GetApplicationIdByContentActionName"},
  503. {66, &ICommonStateGetter::SetCpuBoostMode, "SetCpuBoostMode"},
  504. {80, nullptr, "PerformSystemButtonPressingIfInFocus"},
  505. {90, nullptr, "SetPerformanceConfigurationChangedNotification"},
  506. {91, nullptr, "GetCurrentPerformanceConfiguration"},
  507. {200, nullptr, "GetOperationModeSystemInfo"},
  508. };
  509. // clang-format on
  510. RegisterHandlers(functions);
  511. }
  512. ICommonStateGetter::~ICommonStateGetter() = default;
  513. void ICommonStateGetter::GetBootMode(Kernel::HLERequestContext& ctx) {
  514. LOG_DEBUG(Service_AM, "called");
  515. IPC::ResponseBuilder rb{ctx, 3};
  516. rb.Push(RESULT_SUCCESS);
  517. rb.Push<u8>(static_cast<u8>(Service::PM::SystemBootMode::Normal)); // Normal boot mode
  518. }
  519. void ICommonStateGetter::GetEventHandle(Kernel::HLERequestContext& ctx) {
  520. LOG_DEBUG(Service_AM, "called");
  521. IPC::ResponseBuilder rb{ctx, 2, 1};
  522. rb.Push(RESULT_SUCCESS);
  523. rb.PushCopyObjects(msg_queue->GetMesssageRecieveEvent());
  524. }
  525. void ICommonStateGetter::ReceiveMessage(Kernel::HLERequestContext& ctx) {
  526. LOG_DEBUG(Service_AM, "called");
  527. const auto message = msg_queue->PopMessage();
  528. IPC::ResponseBuilder rb{ctx, 3};
  529. if (message == AppletMessageQueue::AppletMessage::NoMessage) {
  530. LOG_ERROR(Service_AM, "Message queue is empty");
  531. rb.Push(ERR_NO_MESSAGES);
  532. rb.PushEnum<AppletMessageQueue::AppletMessage>(message);
  533. return;
  534. }
  535. rb.Push(RESULT_SUCCESS);
  536. rb.PushEnum<AppletMessageQueue::AppletMessage>(message);
  537. }
  538. void ICommonStateGetter::GetCurrentFocusState(Kernel::HLERequestContext& ctx) {
  539. LOG_WARNING(Service_AM, "(STUBBED) called");
  540. IPC::ResponseBuilder rb{ctx, 3};
  541. rb.Push(RESULT_SUCCESS);
  542. rb.Push(static_cast<u8>(FocusState::InFocus));
  543. }
  544. void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx) {
  545. LOG_DEBUG(Service_AM, "called");
  546. IPC::ResponseBuilder rb{ctx, 2, 1};
  547. rb.Push(RESULT_SUCCESS);
  548. rb.PushCopyObjects(msg_queue->GetOperationModeChangedEvent());
  549. }
  550. void ICommonStateGetter::GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx) {
  551. LOG_DEBUG(Service_AM, "called");
  552. IPC::ResponseBuilder rb{ctx, 4};
  553. rb.Push(RESULT_SUCCESS);
  554. if (Settings::values.use_docked_mode) {
  555. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedWidth) *
  556. static_cast<u32>(Settings::values.resolution_factor));
  557. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedHeight) *
  558. static_cast<u32>(Settings::values.resolution_factor));
  559. } else {
  560. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedWidth) *
  561. static_cast<u32>(Settings::values.resolution_factor));
  562. rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedHeight) *
  563. static_cast<u32>(Settings::values.resolution_factor));
  564. }
  565. }
  566. void ICommonStateGetter::SetCpuBoostMode(Kernel::HLERequestContext& ctx) {
  567. LOG_DEBUG(Service_AM, "called, forwarding to APM:SYS");
  568. const auto& sm = system.ServiceManager();
  569. const auto apm_sys = sm.GetService<APM::APM_Sys>("apm:sys");
  570. ASSERT(apm_sys != nullptr);
  571. apm_sys->SetCpuBoostMode(ctx);
  572. }
  573. IStorage::IStorage(std::vector<u8> buffer)
  574. : ServiceFramework("IStorage"), buffer(std::move(buffer)) {
  575. // clang-format off
  576. static const FunctionInfo functions[] = {
  577. {0, &IStorage::Open, "Open"},
  578. {1, nullptr, "OpenTransferStorage"},
  579. };
  580. // clang-format on
  581. RegisterHandlers(functions);
  582. }
  583. IStorage::~IStorage() = default;
  584. const std::vector<u8>& IStorage::GetData() const {
  585. return buffer;
  586. }
  587. void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) {
  588. const bool use_docked_mode{Settings::values.use_docked_mode};
  589. LOG_DEBUG(Service_AM, "called, use_docked_mode={}", use_docked_mode);
  590. IPC::ResponseBuilder rb{ctx, 3};
  591. rb.Push(RESULT_SUCCESS);
  592. rb.Push(static_cast<u8>(use_docked_mode ? OperationMode::Docked : OperationMode::Handheld));
  593. }
  594. void ICommonStateGetter::GetPerformanceMode(Kernel::HLERequestContext& ctx) {
  595. LOG_DEBUG(Service_AM, "called");
  596. IPC::ResponseBuilder rb{ctx, 3};
  597. rb.Push(RESULT_SUCCESS);
  598. rb.PushEnum(system.GetAPMController().GetCurrentPerformanceMode());
  599. }
  600. class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
  601. public:
  602. explicit ILibraryAppletAccessor(std::shared_ptr<Applets::Applet> applet)
  603. : ServiceFramework("ILibraryAppletAccessor"), applet(std::move(applet)) {
  604. // clang-format off
  605. static const FunctionInfo functions[] = {
  606. {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
  607. {1, &ILibraryAppletAccessor::IsCompleted, "IsCompleted"},
  608. {10, &ILibraryAppletAccessor::Start, "Start"},
  609. {20, nullptr, "RequestExit"},
  610. {25, nullptr, "Terminate"},
  611. {30, &ILibraryAppletAccessor::GetResult, "GetResult"},
  612. {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"},
  613. {100, &ILibraryAppletAccessor::PushInData, "PushInData"},
  614. {101, &ILibraryAppletAccessor::PopOutData, "PopOutData"},
  615. {102, nullptr, "PushExtraStorage"},
  616. {103, &ILibraryAppletAccessor::PushInteractiveInData, "PushInteractiveInData"},
  617. {104, &ILibraryAppletAccessor::PopInteractiveOutData, "PopInteractiveOutData"},
  618. {105, &ILibraryAppletAccessor::GetPopOutDataEvent, "GetPopOutDataEvent"},
  619. {106, &ILibraryAppletAccessor::GetPopInteractiveOutDataEvent, "GetPopInteractiveOutDataEvent"},
  620. {110, nullptr, "NeedsToExitProcess"},
  621. {120, nullptr, "GetLibraryAppletInfo"},
  622. {150, nullptr, "RequestForAppletToGetForeground"},
  623. {160, nullptr, "GetIndirectLayerConsumerHandle"},
  624. };
  625. // clang-format on
  626. RegisterHandlers(functions);
  627. }
  628. private:
  629. void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
  630. LOG_DEBUG(Service_AM, "called");
  631. const auto event = applet->GetBroker().GetStateChangedEvent();
  632. IPC::ResponseBuilder rb{ctx, 2, 1};
  633. rb.Push(RESULT_SUCCESS);
  634. rb.PushCopyObjects(event);
  635. }
  636. void IsCompleted(Kernel::HLERequestContext& ctx) {
  637. LOG_DEBUG(Service_AM, "called");
  638. IPC::ResponseBuilder rb{ctx, 3};
  639. rb.Push(RESULT_SUCCESS);
  640. rb.Push<u32>(applet->TransactionComplete());
  641. }
  642. void GetResult(Kernel::HLERequestContext& ctx) {
  643. LOG_DEBUG(Service_AM, "called");
  644. IPC::ResponseBuilder rb{ctx, 2};
  645. rb.Push(applet->GetStatus());
  646. }
  647. void Start(Kernel::HLERequestContext& ctx) {
  648. LOG_DEBUG(Service_AM, "called");
  649. ASSERT(applet != nullptr);
  650. applet->Initialize();
  651. applet->Execute();
  652. IPC::ResponseBuilder rb{ctx, 2};
  653. rb.Push(RESULT_SUCCESS);
  654. }
  655. void PushInData(Kernel::HLERequestContext& ctx) {
  656. LOG_DEBUG(Service_AM, "called");
  657. IPC::RequestParser rp{ctx};
  658. applet->GetBroker().PushNormalDataFromGame(*rp.PopIpcInterface<IStorage>());
  659. IPC::ResponseBuilder rb{ctx, 2};
  660. rb.Push(RESULT_SUCCESS);
  661. }
  662. void PopOutData(Kernel::HLERequestContext& ctx) {
  663. LOG_DEBUG(Service_AM, "called");
  664. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  665. const auto storage = applet->GetBroker().PopNormalDataToGame();
  666. if (storage == nullptr) {
  667. LOG_ERROR(Service_AM,
  668. "storage is a nullptr. There is no data in the current normal channel");
  669. rb.Push(ERR_NO_DATA_IN_CHANNEL);
  670. return;
  671. }
  672. rb.Push(RESULT_SUCCESS);
  673. rb.PushIpcInterface<IStorage>(std::move(*storage));
  674. }
  675. void PushInteractiveInData(Kernel::HLERequestContext& ctx) {
  676. LOG_DEBUG(Service_AM, "called");
  677. IPC::RequestParser rp{ctx};
  678. applet->GetBroker().PushInteractiveDataFromGame(*rp.PopIpcInterface<IStorage>());
  679. ASSERT(applet->IsInitialized());
  680. applet->ExecuteInteractive();
  681. applet->Execute();
  682. IPC::ResponseBuilder rb{ctx, 2};
  683. rb.Push(RESULT_SUCCESS);
  684. }
  685. void PopInteractiveOutData(Kernel::HLERequestContext& ctx) {
  686. LOG_DEBUG(Service_AM, "called");
  687. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  688. const auto storage = applet->GetBroker().PopInteractiveDataToGame();
  689. if (storage == nullptr) {
  690. LOG_ERROR(Service_AM,
  691. "storage is a nullptr. There is no data in the current interactive channel");
  692. rb.Push(ERR_NO_DATA_IN_CHANNEL);
  693. return;
  694. }
  695. rb.Push(RESULT_SUCCESS);
  696. rb.PushIpcInterface<IStorage>(std::move(*storage));
  697. }
  698. void GetPopOutDataEvent(Kernel::HLERequestContext& ctx) {
  699. LOG_DEBUG(Service_AM, "called");
  700. IPC::ResponseBuilder rb{ctx, 2, 1};
  701. rb.Push(RESULT_SUCCESS);
  702. rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent());
  703. }
  704. void GetPopInteractiveOutDataEvent(Kernel::HLERequestContext& ctx) {
  705. LOG_DEBUG(Service_AM, "called");
  706. IPC::ResponseBuilder rb{ctx, 2, 1};
  707. rb.Push(RESULT_SUCCESS);
  708. rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent());
  709. }
  710. std::shared_ptr<Applets::Applet> applet;
  711. };
  712. void IStorage::Open(Kernel::HLERequestContext& ctx) {
  713. LOG_DEBUG(Service_AM, "called");
  714. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  715. rb.Push(RESULT_SUCCESS);
  716. rb.PushIpcInterface<IStorageAccessor>(*this);
  717. }
  718. IStorageAccessor::IStorageAccessor(IStorage& storage)
  719. : ServiceFramework("IStorageAccessor"), backing(storage) {
  720. // clang-format off
  721. static const FunctionInfo functions[] = {
  722. {0, &IStorageAccessor::GetSize, "GetSize"},
  723. {10, &IStorageAccessor::Write, "Write"},
  724. {11, &IStorageAccessor::Read, "Read"},
  725. };
  726. // clang-format on
  727. RegisterHandlers(functions);
  728. }
  729. IStorageAccessor::~IStorageAccessor() = default;
  730. void IStorageAccessor::GetSize(Kernel::HLERequestContext& ctx) {
  731. LOG_DEBUG(Service_AM, "called");
  732. IPC::ResponseBuilder rb{ctx, 4};
  733. rb.Push(RESULT_SUCCESS);
  734. rb.Push(static_cast<u64>(backing.buffer.size()));
  735. }
  736. void IStorageAccessor::Write(Kernel::HLERequestContext& ctx) {
  737. IPC::RequestParser rp{ctx};
  738. const u64 offset{rp.Pop<u64>()};
  739. const std::vector<u8> data{ctx.ReadBuffer()};
  740. LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, data.size());
  741. if (data.size() > backing.buffer.size() - offset) {
  742. LOG_ERROR(Service_AM,
  743. "offset is out of bounds, backing_buffer_sz={}, data_size={}, offset={}",
  744. backing.buffer.size(), data.size(), offset);
  745. IPC::ResponseBuilder rb{ctx, 2};
  746. rb.Push(ERR_SIZE_OUT_OF_BOUNDS);
  747. return;
  748. }
  749. std::memcpy(backing.buffer.data() + offset, data.data(), data.size());
  750. IPC::ResponseBuilder rb{ctx, 2};
  751. rb.Push(RESULT_SUCCESS);
  752. }
  753. void IStorageAccessor::Read(Kernel::HLERequestContext& ctx) {
  754. IPC::RequestParser rp{ctx};
  755. const u64 offset{rp.Pop<u64>()};
  756. const std::size_t size{ctx.GetWriteBufferSize()};
  757. LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
  758. if (size > backing.buffer.size() - offset) {
  759. LOG_ERROR(Service_AM, "offset is out of bounds, backing_buffer_sz={}, size={}, offset={}",
  760. backing.buffer.size(), size, offset);
  761. IPC::ResponseBuilder rb{ctx, 2};
  762. rb.Push(ERR_SIZE_OUT_OF_BOUNDS);
  763. return;
  764. }
  765. ctx.WriteBuffer(backing.buffer.data() + offset, size);
  766. IPC::ResponseBuilder rb{ctx, 2};
  767. rb.Push(RESULT_SUCCESS);
  768. }
  769. ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_)
  770. : ServiceFramework("ILibraryAppletCreator"), system{system_} {
  771. static const FunctionInfo functions[] = {
  772. {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"},
  773. {1, nullptr, "TerminateAllLibraryApplets"},
  774. {2, nullptr, "AreAnyLibraryAppletsLeft"},
  775. {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"},
  776. {11, &ILibraryAppletCreator::CreateTransferMemoryStorage, "CreateTransferMemoryStorage"},
  777. {12, nullptr, "CreateHandleStorage"},
  778. };
  779. RegisterHandlers(functions);
  780. }
  781. ILibraryAppletCreator::~ILibraryAppletCreator() = default;
  782. void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) {
  783. IPC::RequestParser rp{ctx};
  784. const auto applet_id = rp.PopRaw<Applets::AppletId>();
  785. const auto applet_mode = rp.PopRaw<u32>();
  786. LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}",
  787. static_cast<u32>(applet_id), applet_mode);
  788. const auto& applet_manager{system.GetAppletManager()};
  789. const auto applet = applet_manager.GetApplet(applet_id);
  790. if (applet == nullptr) {
  791. LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", static_cast<u32>(applet_id));
  792. IPC::ResponseBuilder rb{ctx, 2};
  793. rb.Push(RESULT_UNKNOWN);
  794. return;
  795. }
  796. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  797. rb.Push(RESULT_SUCCESS);
  798. rb.PushIpcInterface<AM::ILibraryAppletAccessor>(applet);
  799. }
  800. void ILibraryAppletCreator::CreateStorage(Kernel::HLERequestContext& ctx) {
  801. IPC::RequestParser rp{ctx};
  802. const u64 size{rp.Pop<u64>()};
  803. LOG_DEBUG(Service_AM, "called, size={}", size);
  804. std::vector<u8> buffer(size);
  805. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  806. rb.Push(RESULT_SUCCESS);
  807. rb.PushIpcInterface<AM::IStorage>(std::move(buffer));
  808. }
  809. void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContext& ctx) {
  810. LOG_DEBUG(Service_AM, "called");
  811. IPC::RequestParser rp{ctx};
  812. rp.SetCurrentOffset(3);
  813. const auto handle{rp.Pop<Kernel::Handle>()};
  814. const auto transfer_mem =
  815. system.CurrentProcess()->GetHandleTable().Get<Kernel::TransferMemory>(handle);
  816. if (transfer_mem == nullptr) {
  817. LOG_ERROR(Service_AM, "shared_mem is a nullpr for handle={:08X}", handle);
  818. IPC::ResponseBuilder rb{ctx, 2};
  819. rb.Push(RESULT_UNKNOWN);
  820. return;
  821. }
  822. const u8* const mem_begin = transfer_mem->GetPointer();
  823. const u8* const mem_end = mem_begin + transfer_mem->GetSize();
  824. std::vector<u8> memory{mem_begin, mem_end};
  825. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  826. rb.Push(RESULT_SUCCESS);
  827. rb.PushIpcInterface(std::make_shared<IStorage>(std::move(memory)));
  828. }
  829. IApplicationFunctions::IApplicationFunctions(Core::System& system_)
  830. : ServiceFramework("IApplicationFunctions"), system{system_} {
  831. // clang-format off
  832. static const FunctionInfo functions[] = {
  833. {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
  834. {10, nullptr, "CreateApplicationAndPushAndRequestToStart"},
  835. {11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"},
  836. {12, nullptr, "CreateApplicationAndRequestToStart"},
  837. {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest, "CreateApplicationAndRequestToStartForQuest"},
  838. {14, nullptr, "CreateApplicationWithAttributeAndPushAndRequestToStartForQuest"},
  839. {15, nullptr, "CreateApplicationWithAttributeAndRequestToStartForQuest"},
  840. {20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"},
  841. {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"},
  842. {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"},
  843. {23, &IApplicationFunctions::GetDisplayVersion, "GetDisplayVersion"},
  844. {24, nullptr, "GetLaunchStorageInfoForDebug"},
  845. {25, &IApplicationFunctions::ExtendSaveData, "ExtendSaveData"},
  846. {26, &IApplicationFunctions::GetSaveDataSize, "GetSaveDataSize"},
  847. {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed, "BeginBlockingHomeButtonShortAndLongPressed"},
  848. {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed, "EndBlockingHomeButtonShortAndLongPressed"},
  849. {32, &IApplicationFunctions::BeginBlockingHomeButton, "BeginBlockingHomeButton"},
  850. {33, &IApplicationFunctions::EndBlockingHomeButton, "EndBlockingHomeButton"},
  851. {40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"},
  852. {50, &IApplicationFunctions::GetPseudoDeviceId, "GetPseudoDeviceId"},
  853. {60, nullptr, "SetMediaPlaybackStateForApplication"},
  854. {65, nullptr, "IsGamePlayRecordingSupported"},
  855. {66, &IApplicationFunctions::InitializeGamePlayRecording, "InitializeGamePlayRecording"},
  856. {67, &IApplicationFunctions::SetGamePlayRecordingState, "SetGamePlayRecordingState"},
  857. {68, nullptr, "RequestFlushGamePlayingMovieForDebug"},
  858. {70, nullptr, "RequestToShutdown"},
  859. {71, nullptr, "RequestToReboot"},
  860. {80, nullptr, "ExitAndRequestToShowThanksMessage"},
  861. {90, &IApplicationFunctions::EnableApplicationCrashReport, "EnableApplicationCrashReport"},
  862. {100, &IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer, "InitializeApplicationCopyrightFrameBuffer"},
  863. {101, &IApplicationFunctions::SetApplicationCopyrightImage, "SetApplicationCopyrightImage"},
  864. {102, &IApplicationFunctions::SetApplicationCopyrightVisibility, "SetApplicationCopyrightVisibility"},
  865. {110, &IApplicationFunctions::QueryApplicationPlayStatistics, "QueryApplicationPlayStatistics"},
  866. {111, &IApplicationFunctions::QueryApplicationPlayStatisticsByUid, "QueryApplicationPlayStatisticsByUid"},
  867. {120, nullptr, "ExecuteProgram"},
  868. {121, nullptr, "ClearUserChannel"},
  869. {122, nullptr, "UnpopToUserChannel"},
  870. {130, &IApplicationFunctions::GetGpuErrorDetectedSystemEvent, "GetGpuErrorDetectedSystemEvent"},
  871. {500, nullptr, "StartContinuousRecordingFlushForDebug"},
  872. {1000, nullptr, "CreateMovieMaker"},
  873. {1001, nullptr, "PrepareForJit"},
  874. };
  875. // clang-format on
  876. RegisterHandlers(functions);
  877. auto& kernel = system.Kernel();
  878. gpu_error_detected_event = Kernel::WritableEvent::CreateEventPair(
  879. kernel, "IApplicationFunctions:GpuErrorDetectedSystemEvent");
  880. }
  881. IApplicationFunctions::~IApplicationFunctions() = default;
  882. void IApplicationFunctions::EnableApplicationCrashReport(Kernel::HLERequestContext& ctx) {
  883. LOG_WARNING(Service_AM, "(STUBBED) called");
  884. IPC::ResponseBuilder rb{ctx, 2};
  885. rb.Push(RESULT_SUCCESS);
  886. }
  887. void IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer(
  888. Kernel::HLERequestContext& ctx) {
  889. LOG_WARNING(Service_AM, "(STUBBED) called");
  890. IPC::ResponseBuilder rb{ctx, 2};
  891. rb.Push(RESULT_SUCCESS);
  892. }
  893. void IApplicationFunctions::SetApplicationCopyrightImage(Kernel::HLERequestContext& ctx) {
  894. LOG_WARNING(Service_AM, "(STUBBED) called");
  895. IPC::ResponseBuilder rb{ctx, 2};
  896. rb.Push(RESULT_SUCCESS);
  897. }
  898. void IApplicationFunctions::SetApplicationCopyrightVisibility(Kernel::HLERequestContext& ctx) {
  899. IPC::RequestParser rp{ctx};
  900. const auto is_visible = rp.Pop<bool>();
  901. LOG_WARNING(Service_AM, "(STUBBED) called, is_visible={}", is_visible);
  902. IPC::ResponseBuilder rb{ctx, 2};
  903. rb.Push(RESULT_SUCCESS);
  904. }
  905. void IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(
  906. Kernel::HLERequestContext& ctx) {
  907. LOG_WARNING(Service_AM, "(STUBBED) called");
  908. IPC::ResponseBuilder rb{ctx, 2};
  909. rb.Push(RESULT_SUCCESS);
  910. }
  911. void IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed(
  912. Kernel::HLERequestContext& ctx) {
  913. LOG_WARNING(Service_AM, "(STUBBED) called");
  914. IPC::ResponseBuilder rb{ctx, 2};
  915. rb.Push(RESULT_SUCCESS);
  916. }
  917. void IApplicationFunctions::BeginBlockingHomeButton(Kernel::HLERequestContext& ctx) {
  918. LOG_WARNING(Service_AM, "(STUBBED) called");
  919. IPC::ResponseBuilder rb{ctx, 2};
  920. rb.Push(RESULT_SUCCESS);
  921. }
  922. void IApplicationFunctions::EndBlockingHomeButton(Kernel::HLERequestContext& ctx) {
  923. LOG_WARNING(Service_AM, "(STUBBED) called");
  924. IPC::ResponseBuilder rb{ctx, 2};
  925. rb.Push(RESULT_SUCCESS);
  926. }
  927. void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
  928. IPC::RequestParser rp{ctx};
  929. const auto kind = rp.PopEnum<LaunchParameterKind>();
  930. LOG_DEBUG(Service_AM, "called, kind={:08X}", static_cast<u8>(kind));
  931. if (kind == LaunchParameterKind::ApplicationSpecific && !launch_popped_application_specific) {
  932. const auto backend = BCAT::CreateBackendFromSettings(system, [this](u64 tid) {
  933. return system.GetFileSystemController().GetBCATDirectory(tid);
  934. });
  935. const auto build_id_full = system.GetCurrentProcessBuildID();
  936. u64 build_id{};
  937. std::memcpy(&build_id, build_id_full.data(), sizeof(u64));
  938. const auto data =
  939. backend->GetLaunchParameter({system.CurrentProcess()->GetTitleID(), build_id});
  940. if (data.has_value()) {
  941. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  942. rb.Push(RESULT_SUCCESS);
  943. rb.PushIpcInterface<AM::IStorage>(*data);
  944. launch_popped_application_specific = true;
  945. return;
  946. }
  947. } else if (kind == LaunchParameterKind::AccountPreselectedUser &&
  948. !launch_popped_account_preselect) {
  949. LaunchParameterAccountPreselectedUser params{};
  950. params.magic = LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC;
  951. params.is_account_selected = 1;
  952. Account::ProfileManager profile_manager{};
  953. const auto uuid = profile_manager.GetUser(Settings::values.current_user);
  954. ASSERT(uuid);
  955. params.current_user = uuid->uuid;
  956. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  957. rb.Push(RESULT_SUCCESS);
  958. std::vector<u8> buffer(sizeof(LaunchParameterAccountPreselectedUser));
  959. std::memcpy(buffer.data(), &params, buffer.size());
  960. rb.PushIpcInterface<AM::IStorage>(buffer);
  961. launch_popped_account_preselect = true;
  962. return;
  963. }
  964. LOG_ERROR(Service_AM, "Attempted to load launch parameter but none was found!");
  965. IPC::ResponseBuilder rb{ctx, 2};
  966. rb.Push(ERR_NO_DATA_IN_CHANNEL);
  967. }
  968. void IApplicationFunctions::CreateApplicationAndRequestToStartForQuest(
  969. Kernel::HLERequestContext& ctx) {
  970. LOG_WARNING(Service_AM, "(STUBBED) called");
  971. IPC::ResponseBuilder rb{ctx, 2};
  972. rb.Push(RESULT_SUCCESS);
  973. }
  974. void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) {
  975. IPC::RequestParser rp{ctx};
  976. u128 user_id = rp.PopRaw<u128>();
  977. LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]);
  978. FileSys::SaveDataDescriptor descriptor{};
  979. descriptor.title_id = system.CurrentProcess()->GetTitleID();
  980. descriptor.user_id = user_id;
  981. descriptor.type = FileSys::SaveDataType::SaveData;
  982. const auto res = system.GetFileSystemController().CreateSaveData(
  983. FileSys::SaveDataSpaceId::NandUser, descriptor);
  984. IPC::ResponseBuilder rb{ctx, 4};
  985. rb.Push(res.Code());
  986. rb.Push<u64>(0);
  987. }
  988. void IApplicationFunctions::SetTerminateResult(Kernel::HLERequestContext& ctx) {
  989. // Takes an input u32 Result, no output.
  990. // For example, in some cases official apps use this with error 0x2A2 then
  991. // uses svcBreak.
  992. IPC::RequestParser rp{ctx};
  993. u32 result = rp.Pop<u32>();
  994. LOG_WARNING(Service_AM, "(STUBBED) called, result=0x{:08X}", result);
  995. IPC::ResponseBuilder rb{ctx, 2};
  996. rb.Push(RESULT_SUCCESS);
  997. }
  998. void IApplicationFunctions::GetDisplayVersion(Kernel::HLERequestContext& ctx) {
  999. LOG_WARNING(Service_AM, "(STUBBED) called");
  1000. IPC::ResponseBuilder rb{ctx, 6};
  1001. rb.Push(RESULT_SUCCESS);
  1002. rb.Push<u64>(1);
  1003. rb.Push<u64>(0);
  1004. }
  1005. void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) {
  1006. // TODO(bunnei): This should be configurable
  1007. LOG_DEBUG(Service_AM, "called");
  1008. // Get supported languages from NACP, if possible
  1009. // Default to 0 (all languages supported)
  1010. u32 supported_languages = 0;
  1011. FileSys::PatchManager pm{system.CurrentProcess()->GetTitleID()};
  1012. const auto res = pm.GetControlMetadata();
  1013. if (res.first != nullptr) {
  1014. supported_languages = res.first->GetSupportedLanguages();
  1015. }
  1016. // Call IApplicationManagerInterface implementation.
  1017. auto& service_manager = system.ServiceManager();
  1018. auto ns_am2 = service_manager.GetService<NS::NS>("ns:am2");
  1019. auto app_man = ns_am2->GetApplicationManagerInterface();
  1020. // Get desired application language
  1021. const auto res_lang = app_man->GetApplicationDesiredLanguage(supported_languages);
  1022. if (res_lang.Failed()) {
  1023. IPC::ResponseBuilder rb{ctx, 2};
  1024. rb.Push(res_lang.Code());
  1025. return;
  1026. }
  1027. // Convert to settings language code.
  1028. const auto res_code = app_man->ConvertApplicationLanguageToLanguageCode(*res_lang);
  1029. if (res_code.Failed()) {
  1030. IPC::ResponseBuilder rb{ctx, 2};
  1031. rb.Push(res_code.Code());
  1032. return;
  1033. }
  1034. LOG_DEBUG(Service_AM, "got desired_language={:016X}", *res_code);
  1035. IPC::ResponseBuilder rb{ctx, 4};
  1036. rb.Push(RESULT_SUCCESS);
  1037. rb.Push(*res_code);
  1038. }
  1039. void IApplicationFunctions::InitializeGamePlayRecording(Kernel::HLERequestContext& ctx) {
  1040. LOG_WARNING(Service_AM, "(STUBBED) called");
  1041. IPC::ResponseBuilder rb{ctx, 2};
  1042. rb.Push(RESULT_SUCCESS);
  1043. }
  1044. void IApplicationFunctions::SetGamePlayRecordingState(Kernel::HLERequestContext& ctx) {
  1045. LOG_WARNING(Service_AM, "(STUBBED) called");
  1046. IPC::ResponseBuilder rb{ctx, 2};
  1047. rb.Push(RESULT_SUCCESS);
  1048. }
  1049. void IApplicationFunctions::NotifyRunning(Kernel::HLERequestContext& ctx) {
  1050. LOG_WARNING(Service_AM, "(STUBBED) called");
  1051. IPC::ResponseBuilder rb{ctx, 3};
  1052. rb.Push(RESULT_SUCCESS);
  1053. rb.Push<u8>(0); // Unknown, seems to be ignored by official processes
  1054. }
  1055. void IApplicationFunctions::GetPseudoDeviceId(Kernel::HLERequestContext& ctx) {
  1056. LOG_WARNING(Service_AM, "(STUBBED) called");
  1057. IPC::ResponseBuilder rb{ctx, 6};
  1058. rb.Push(RESULT_SUCCESS);
  1059. // Returns a 128-bit UUID
  1060. rb.Push<u64>(0);
  1061. rb.Push<u64>(0);
  1062. }
  1063. void IApplicationFunctions::ExtendSaveData(Kernel::HLERequestContext& ctx) {
  1064. IPC::RequestParser rp{ctx};
  1065. const auto type{rp.PopRaw<FileSys::SaveDataType>()};
  1066. rp.Skip(1, false);
  1067. const auto user_id{rp.PopRaw<u128>()};
  1068. const auto new_normal_size{rp.PopRaw<u64>()};
  1069. const auto new_journal_size{rp.PopRaw<u64>()};
  1070. LOG_DEBUG(Service_AM,
  1071. "called with type={:02X}, user_id={:016X}{:016X}, new_normal={:016X}, "
  1072. "new_journal={:016X}",
  1073. static_cast<u8>(type), user_id[1], user_id[0], new_normal_size, new_journal_size);
  1074. system.GetFileSystemController().WriteSaveDataSize(
  1075. type, system.CurrentProcess()->GetTitleID(), user_id, {new_normal_size, new_journal_size});
  1076. IPC::ResponseBuilder rb{ctx, 4};
  1077. rb.Push(RESULT_SUCCESS);
  1078. // The following value is used upon failure to help the system recover.
  1079. // Since we always succeed, this should be 0.
  1080. rb.Push<u64>(0);
  1081. }
  1082. void IApplicationFunctions::GetSaveDataSize(Kernel::HLERequestContext& ctx) {
  1083. IPC::RequestParser rp{ctx};
  1084. const auto type{rp.PopRaw<FileSys::SaveDataType>()};
  1085. rp.Skip(1, false);
  1086. const auto user_id{rp.PopRaw<u128>()};
  1087. LOG_DEBUG(Service_AM, "called with type={:02X}, user_id={:016X}{:016X}", static_cast<u8>(type),
  1088. user_id[1], user_id[0]);
  1089. const auto size = system.GetFileSystemController().ReadSaveDataSize(
  1090. type, system.CurrentProcess()->GetTitleID(), user_id);
  1091. IPC::ResponseBuilder rb{ctx, 6};
  1092. rb.Push(RESULT_SUCCESS);
  1093. rb.Push(size.normal);
  1094. rb.Push(size.journal);
  1095. }
  1096. void IApplicationFunctions::QueryApplicationPlayStatistics(Kernel::HLERequestContext& ctx) {
  1097. LOG_WARNING(Service_AM, "(STUBBED) called");
  1098. IPC::ResponseBuilder rb{ctx, 3};
  1099. rb.Push(RESULT_SUCCESS);
  1100. rb.Push<u32>(0);
  1101. }
  1102. void IApplicationFunctions::QueryApplicationPlayStatisticsByUid(Kernel::HLERequestContext& ctx) {
  1103. LOG_WARNING(Service_AM, "(STUBBED) called");
  1104. IPC::ResponseBuilder rb{ctx, 3};
  1105. rb.Push(RESULT_SUCCESS);
  1106. rb.Push<u32>(0);
  1107. }
  1108. void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(Kernel::HLERequestContext& ctx) {
  1109. LOG_WARNING(Service_AM, "(STUBBED) called");
  1110. IPC::ResponseBuilder rb{ctx, 2, 1};
  1111. rb.Push(RESULT_SUCCESS);
  1112. rb.PushCopyObjects(gpu_error_detected_event.readable);
  1113. }
  1114. void InstallInterfaces(SM::ServiceManager& service_manager,
  1115. std::shared_ptr<NVFlinger::NVFlinger> nvflinger, Core::System& system) {
  1116. auto message_queue = std::make_shared<AppletMessageQueue>(system.Kernel());
  1117. // Needed on game boot
  1118. message_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
  1119. std::make_shared<AppletAE>(nvflinger, message_queue, system)->InstallAsService(service_manager);
  1120. std::make_shared<AppletOE>(nvflinger, message_queue, system)->InstallAsService(service_manager);
  1121. std::make_shared<IdleSys>()->InstallAsService(service_manager);
  1122. std::make_shared<OMM>()->InstallAsService(service_manager);
  1123. std::make_shared<SPSM>()->InstallAsService(service_manager);
  1124. std::make_shared<TCAP>()->InstallAsService(service_manager);
  1125. }
  1126. IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions") {
  1127. // clang-format off
  1128. static const FunctionInfo functions[] = {
  1129. {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
  1130. {11, nullptr, "LockForeground"},
  1131. {12, nullptr, "UnlockForeground"},
  1132. {20, nullptr, "PopFromGeneralChannel"},
  1133. {21, nullptr, "GetPopFromGeneralChannelEvent"},
  1134. {30, nullptr, "GetHomeButtonWriterLockAccessor"},
  1135. {31, nullptr, "GetWriterLockAccessorEx"},
  1136. {100, nullptr, "PopRequestLaunchApplicationForDebug"},
  1137. };
  1138. // clang-format on
  1139. RegisterHandlers(functions);
  1140. }
  1141. IHomeMenuFunctions::~IHomeMenuFunctions() = default;
  1142. void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) {
  1143. LOG_WARNING(Service_AM, "(STUBBED) called");
  1144. IPC::ResponseBuilder rb{ctx, 2};
  1145. rb.Push(RESULT_SUCCESS);
  1146. }
  1147. IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStateController") {
  1148. // clang-format off
  1149. static const FunctionInfo functions[] = {
  1150. {0, nullptr, "RequestToEnterSleep"},
  1151. {1, nullptr, "EnterSleep"},
  1152. {2, nullptr, "StartSleepSequence"},
  1153. {3, nullptr, "StartShutdownSequence"},
  1154. {4, nullptr, "StartRebootSequence"},
  1155. {9, nullptr, "IsAutoPowerDownRequested"},
  1156. {10, nullptr, "LoadAndApplyIdlePolicySettings"},
  1157. {11, nullptr, "NotifyCecSettingsChanged"},
  1158. {12, nullptr, "SetDefaultHomeButtonLongPressTime"},
  1159. {13, nullptr, "UpdateDefaultDisplayResolution"},
  1160. {14, nullptr, "ShouldSleepOnBoot"},
  1161. {15, nullptr, "GetHdcpAuthenticationFailedEvent"},
  1162. };
  1163. // clang-format on
  1164. RegisterHandlers(functions);
  1165. }
  1166. IGlobalStateController::~IGlobalStateController() = default;
  1167. IApplicationCreator::IApplicationCreator() : ServiceFramework("IApplicationCreator") {
  1168. // clang-format off
  1169. static const FunctionInfo functions[] = {
  1170. {0, nullptr, "CreateApplication"},
  1171. {1, nullptr, "PopLaunchRequestedApplication"},
  1172. {10, nullptr, "CreateSystemApplication"},
  1173. {100, nullptr, "PopFloatingApplicationForDevelopment"},
  1174. };
  1175. // clang-format on
  1176. RegisterHandlers(functions);
  1177. }
  1178. IApplicationCreator::~IApplicationCreator() = default;
  1179. IProcessWindingController::IProcessWindingController()
  1180. : ServiceFramework("IProcessWindingController") {
  1181. // clang-format off
  1182. static const FunctionInfo functions[] = {
  1183. {0, nullptr, "GetLaunchReason"},
  1184. {11, nullptr, "OpenCallingLibraryApplet"},
  1185. {21, nullptr, "PushContext"},
  1186. {22, nullptr, "PopContext"},
  1187. {23, nullptr, "CancelWindingReservation"},
  1188. {30, nullptr, "WindAndDoReserved"},
  1189. {40, nullptr, "ReserveToStartAndWaitAndUnwindThis"},
  1190. {41, nullptr, "ReserveToStartAndWait"},
  1191. };
  1192. // clang-format on
  1193. RegisterHandlers(functions);
  1194. }
  1195. IProcessWindingController::~IProcessWindingController() = default;
  1196. } // namespace Service::AM