am.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cinttypes>
  5. #include "core/file_sys/filesystem.h"
  6. #include "core/hle/ipc_helpers.h"
  7. #include "core/hle/kernel/event.h"
  8. #include "core/hle/service/am/am.h"
  9. #include "core/hle/service/am/applet_ae.h"
  10. #include "core/hle/service/am/applet_oe.h"
  11. #include "core/hle/service/apm/apm.h"
  12. #include "core/hle/service/filesystem/filesystem.h"
  13. #include "core/hle/service/nvflinger/nvflinger.h"
  14. #include "core/hle/service/set/set.h"
  15. #include "core/settings.h"
  16. namespace Service::AM {
  17. IWindowController::IWindowController() : ServiceFramework("IWindowController") {
  18. static const FunctionInfo functions[] = {
  19. {0, nullptr, "CreateWindow"},
  20. {1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"},
  21. {10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"},
  22. {11, nullptr, "ReleaseForegroundRights"},
  23. {12, nullptr, "RejectToChangeIntoBackground"},
  24. };
  25. RegisterHandlers(functions);
  26. }
  27. void IWindowController::GetAppletResourceUserId(Kernel::HLERequestContext& ctx) {
  28. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  29. IPC::ResponseBuilder rb{ctx, 4};
  30. rb.Push(RESULT_SUCCESS);
  31. rb.Push<u64>(0);
  32. }
  33. void IWindowController::AcquireForegroundRights(Kernel::HLERequestContext& ctx) {
  34. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  35. IPC::ResponseBuilder rb{ctx, 2};
  36. rb.Push(RESULT_SUCCESS);
  37. }
  38. IAudioController::IAudioController() : ServiceFramework("IAudioController") {
  39. static const FunctionInfo functions[] = {
  40. {0, &IAudioController::SetExpectedMasterVolume, "SetExpectedMasterVolume"},
  41. {1, &IAudioController::GetMainAppletExpectedMasterVolume,
  42. "GetMainAppletExpectedMasterVolume"},
  43. {2, &IAudioController::GetLibraryAppletExpectedMasterVolume,
  44. "GetLibraryAppletExpectedMasterVolume"},
  45. {3, nullptr, "ChangeMainAppletMasterVolume"},
  46. {4, nullptr, "SetTransparentVolumeRate"},
  47. };
  48. RegisterHandlers(functions);
  49. }
  50. void IAudioController::SetExpectedMasterVolume(Kernel::HLERequestContext& ctx) {
  51. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  52. IPC::ResponseBuilder rb{ctx, 2};
  53. rb.Push(RESULT_SUCCESS);
  54. }
  55. void IAudioController::GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) {
  56. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  57. IPC::ResponseBuilder rb{ctx, 3};
  58. rb.Push(RESULT_SUCCESS);
  59. rb.Push(volume);
  60. }
  61. void IAudioController::GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx) {
  62. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  63. IPC::ResponseBuilder rb{ctx, 3};
  64. rb.Push(RESULT_SUCCESS);
  65. rb.Push(volume);
  66. }
  67. IDisplayController::IDisplayController() : ServiceFramework("IDisplayController") {
  68. static const FunctionInfo functions[] = {
  69. {0, nullptr, "GetLastForegroundCaptureImage"},
  70. {1, nullptr, "UpdateLastForegroundCaptureImage"},
  71. {2, nullptr, "GetLastApplicationCaptureImage"},
  72. {3, nullptr, "GetCallerAppletCaptureImage"},
  73. {4, nullptr, "UpdateCallerAppletCaptureImage"},
  74. {5, nullptr, "GetLastForegroundCaptureImageEx"},
  75. {6, nullptr, "GetLastApplicationCaptureImageEx"},
  76. {7, nullptr, "GetCallerAppletCaptureImageEx"},
  77. {8, nullptr, "TakeScreenShotOfOwnLayer"}, // 2.0.0+
  78. {9, nullptr, "CopyBetweenCaptureBuffers"}, // 5.0.0+
  79. {10, nullptr, "AcquireLastApplicationCaptureBuffer"},
  80. {11, nullptr, "ReleaseLastApplicationCaptureBuffer"},
  81. {12, nullptr, "AcquireLastForegroundCaptureBuffer"},
  82. {13, nullptr, "ReleaseLastForegroundCaptureBuffer"},
  83. {14, nullptr, "AcquireCallerAppletCaptureBuffer"},
  84. {15, nullptr, "ReleaseCallerAppletCaptureBuffer"},
  85. {16, nullptr, "AcquireLastApplicationCaptureBufferEx"},
  86. {17, nullptr, "AcquireLastForegroundCaptureBufferEx"},
  87. {18, nullptr, "AcquireCallerAppletCaptureBufferEx"},
  88. // 2.0.0+
  89. {20, nullptr, "ClearCaptureBuffer"},
  90. {21, nullptr, "ClearAppletTransitionBuffer"},
  91. // 4.0.0+
  92. {22, nullptr, "AcquireLastApplicationCaptureSharedBuffer"},
  93. {23, nullptr, "ReleaseLastApplicationCaptureSharedBuffer"},
  94. {24, nullptr, "AcquireLastForegroundCaptureSharedBuffer"},
  95. {25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"},
  96. {26, nullptr, "AcquireCallerAppletCaptureSharedBuffer"},
  97. {27, nullptr, "ReleaseCallerAppletCaptureSharedBuffer"},
  98. };
  99. RegisterHandlers(functions);
  100. }
  101. IDebugFunctions::IDebugFunctions() : ServiceFramework("IDebugFunctions") {}
  102. ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger)
  103. : ServiceFramework("ISelfController"), nvflinger(std::move(nvflinger)) {
  104. static const FunctionInfo functions[] = {
  105. {0, nullptr, "Exit"},
  106. {1, &ISelfController::LockExit, "LockExit"},
  107. {2, &ISelfController::UnlockExit, "UnlockExit"},
  108. {3, nullptr, "EnterFatalSection"},
  109. {4, nullptr, "LeaveFatalSection"},
  110. {9, &ISelfController::GetLibraryAppletLaunchableEvent, "GetLibraryAppletLaunchableEvent"},
  111. {10, &ISelfController::SetScreenShotPermission, "SetScreenShotPermission"},
  112. {11, &ISelfController::SetOperationModeChangedNotification,
  113. "SetOperationModeChangedNotification"},
  114. {12, &ISelfController::SetPerformanceModeChangedNotification,
  115. "SetPerformanceModeChangedNotification"},
  116. {13, &ISelfController::SetFocusHandlingMode, "SetFocusHandlingMode"},
  117. {14, &ISelfController::SetRestartMessageEnabled, "SetRestartMessageEnabled"},
  118. {15, nullptr, "SetScreenShotAppletIdentityInfo"},
  119. {16, &ISelfController::SetOutOfFocusSuspendingEnabled, "SetOutOfFocusSuspendingEnabled"},
  120. {17, nullptr, "SetControllerFirmwareUpdateSection"},
  121. {18, nullptr, "SetRequiresCaptureButtonShortPressedMessage"},
  122. {19, nullptr, "SetScreenShotImageOrientation"},
  123. {20, nullptr, "SetDesirableKeyboardLayout"},
  124. {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"},
  125. {41, nullptr, "IsSystemBufferSharingEnabled"},
  126. {42, nullptr, "GetSystemSharedLayerHandle"},
  127. {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"},
  128. {51, nullptr, "ApproveToDisplay"},
  129. {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"},
  130. {61, nullptr, "SetMediaPlaybackState"},
  131. {62, nullptr, "SetIdleTimeDetectionExtension"},
  132. {63, nullptr, "GetIdleTimeDetectionExtension"},
  133. {64, nullptr, "SetInputDetectionSourceSet"},
  134. {65, nullptr, "ReportUserIsActive"},
  135. {66, nullptr, "GetCurrentIlluminance"},
  136. {67, nullptr, "IsIlluminanceAvailable"},
  137. {68, nullptr, "SetAutoSleepDisabled"},
  138. {69, nullptr, "IsAutoSleepDisabled"},
  139. {70, nullptr, "ReportMultimediaError"},
  140. {80, nullptr, "SetWirelessPriorityMode"},
  141. };
  142. RegisterHandlers(functions);
  143. launchable_event =
  144. Kernel::Event::Create(Kernel::ResetType::OneShot, "ISelfController:LaunchableEvent");
  145. }
  146. void ISelfController::SetFocusHandlingMode(Kernel::HLERequestContext& ctx) {
  147. // Takes 3 input u8s with each field located immediately after the previous u8, these are
  148. // bool flags. No output.
  149. IPC::RequestParser rp{ctx};
  150. struct FocusHandlingModeParams {
  151. u8 unknown0;
  152. u8 unknown1;
  153. u8 unknown2;
  154. };
  155. auto flags = rp.PopRaw<FocusHandlingModeParams>();
  156. IPC::ResponseBuilder rb{ctx, 2};
  157. rb.Push(RESULT_SUCCESS);
  158. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  159. }
  160. void ISelfController::SetRestartMessageEnabled(Kernel::HLERequestContext& ctx) {
  161. IPC::ResponseBuilder rb{ctx, 2};
  162. rb.Push(RESULT_SUCCESS);
  163. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  164. }
  165. void ISelfController::SetPerformanceModeChangedNotification(Kernel::HLERequestContext& ctx) {
  166. IPC::RequestParser rp{ctx};
  167. bool flag = rp.Pop<bool>();
  168. IPC::ResponseBuilder rb{ctx, 2};
  169. rb.Push(RESULT_SUCCESS);
  170. NGLOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  171. }
  172. void ISelfController::SetScreenShotPermission(Kernel::HLERequestContext& ctx) {
  173. IPC::ResponseBuilder rb{ctx, 2};
  174. rb.Push(RESULT_SUCCESS);
  175. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  176. }
  177. void ISelfController::SetOperationModeChangedNotification(Kernel::HLERequestContext& ctx) {
  178. IPC::RequestParser rp{ctx};
  179. bool flag = rp.Pop<bool>();
  180. IPC::ResponseBuilder rb{ctx, 2};
  181. rb.Push(RESULT_SUCCESS);
  182. NGLOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
  183. }
  184. void ISelfController::SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& ctx) {
  185. // Takes 3 input u8s with each field located immediately after the previous u8, these are
  186. // bool flags. No output.
  187. IPC::RequestParser rp{ctx};
  188. bool enabled = rp.Pop<bool>();
  189. IPC::ResponseBuilder rb{ctx, 2};
  190. rb.Push(RESULT_SUCCESS);
  191. NGLOG_WARNING(Service_AM, "(STUBBED) called enabled={}", enabled);
  192. }
  193. void ISelfController::LockExit(Kernel::HLERequestContext& ctx) {
  194. IPC::ResponseBuilder rb{ctx, 2};
  195. rb.Push(RESULT_SUCCESS);
  196. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  197. }
  198. void ISelfController::UnlockExit(Kernel::HLERequestContext& ctx) {
  199. IPC::ResponseBuilder rb{ctx, 2};
  200. rb.Push(RESULT_SUCCESS);
  201. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  202. }
  203. void ISelfController::GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx) {
  204. launchable_event->Signal();
  205. IPC::ResponseBuilder rb{ctx, 2, 1};
  206. rb.Push(RESULT_SUCCESS);
  207. rb.PushCopyObjects(launchable_event);
  208. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  209. }
  210. void ISelfController::CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx) {
  211. // TODO(Subv): Find out how AM determines the display to use, for now just create the layer
  212. // in the Default display.
  213. u64 display_id = nvflinger->OpenDisplay("Default");
  214. u64 layer_id = nvflinger->CreateLayer(display_id);
  215. IPC::ResponseBuilder rb{ctx, 4};
  216. rb.Push(RESULT_SUCCESS);
  217. rb.Push(layer_id);
  218. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  219. }
  220. void ISelfController::SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx) {
  221. IPC::ResponseBuilder rb{ctx, 2};
  222. rb.Push(RESULT_SUCCESS);
  223. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  224. }
  225. ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter") {
  226. static const FunctionInfo functions[] = {
  227. {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
  228. {1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"},
  229. {2, nullptr, "GetThisAppletKind"},
  230. {3, nullptr, "AllowToEnterSleep"},
  231. {4, nullptr, "DisallowToEnterSleep"},
  232. {5, &ICommonStateGetter::GetOperationMode, "GetOperationMode"},
  233. {6, &ICommonStateGetter::GetPerformanceMode, "GetPerformanceMode"},
  234. {7, nullptr, "GetCradleStatus"},
  235. {8, nullptr, "GetBootMode"},
  236. {9, &ICommonStateGetter::GetCurrentFocusState, "GetCurrentFocusState"},
  237. {10, nullptr, "RequestToAcquireSleepLock"},
  238. {11, nullptr, "ReleaseSleepLock"},
  239. {12, nullptr, "ReleaseSleepLockTransiently"},
  240. {13, nullptr, "GetAcquiredSleepLockEvent"},
  241. {20, nullptr, "PushToGeneralChannel"},
  242. {30, nullptr, "GetHomeButtonReaderLockAccessor"},
  243. {31, nullptr, "GetReaderLockAccessorEx"},
  244. {40, nullptr, "GetCradleFwVersion"},
  245. {50, nullptr, "IsVrModeEnabled"},
  246. {51, nullptr, "SetVrModeEnabled"},
  247. {52, nullptr, "SwitchLcdBacklight"},
  248. {55, nullptr, "IsInControllerFirmwareUpdateSection"},
  249. {60, nullptr, "GetDefaultDisplayResolution"},
  250. {61, nullptr, "GetDefaultDisplayResolutionChangeEvent"},
  251. {62, nullptr, "GetHdcpAuthenticationState"},
  252. {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"},
  253. };
  254. RegisterHandlers(functions);
  255. event = Kernel::Event::Create(Kernel::ResetType::OneShot, "ICommonStateGetter:Event");
  256. }
  257. void ICommonStateGetter::GetEventHandle(Kernel::HLERequestContext& ctx) {
  258. event->Signal();
  259. IPC::ResponseBuilder rb{ctx, 2, 1};
  260. rb.Push(RESULT_SUCCESS);
  261. rb.PushCopyObjects(event);
  262. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  263. }
  264. void ICommonStateGetter::ReceiveMessage(Kernel::HLERequestContext& ctx) {
  265. IPC::ResponseBuilder rb{ctx, 3};
  266. rb.Push(RESULT_SUCCESS);
  267. rb.Push<u32>(15);
  268. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  269. }
  270. void ICommonStateGetter::GetCurrentFocusState(Kernel::HLERequestContext& ctx) {
  271. IPC::ResponseBuilder rb{ctx, 3};
  272. rb.Push(RESULT_SUCCESS);
  273. rb.Push(static_cast<u8>(FocusState::InFocus));
  274. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  275. }
  276. void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) {
  277. const bool use_docked_mode{Settings::values.use_docked_mode};
  278. IPC::ResponseBuilder rb{ctx, 3};
  279. rb.Push(RESULT_SUCCESS);
  280. rb.Push(static_cast<u8>(use_docked_mode ? OperationMode::Docked : OperationMode::Handheld));
  281. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  282. }
  283. void ICommonStateGetter::GetPerformanceMode(Kernel::HLERequestContext& ctx) {
  284. const bool use_docked_mode{Settings::values.use_docked_mode};
  285. IPC::ResponseBuilder rb{ctx, 3};
  286. rb.Push(RESULT_SUCCESS);
  287. rb.Push(static_cast<u32>(use_docked_mode ? APM::PerformanceMode::Docked
  288. : APM::PerformanceMode::Handheld));
  289. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  290. }
  291. class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
  292. public:
  293. explicit ILibraryAppletAccessor() : ServiceFramework("ILibraryAppletAccessor") {
  294. static const FunctionInfo functions[] = {
  295. {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
  296. {1, nullptr, "IsCompleted"},
  297. {10, nullptr, "Start"},
  298. {20, nullptr, "RequestExit"},
  299. {25, nullptr, "Terminate"},
  300. {30, nullptr, "GetResult"},
  301. {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"},
  302. {100, nullptr, "PushInData"},
  303. {101, nullptr, "PopOutData"},
  304. {102, nullptr, "PushExtraStorage"},
  305. {103, nullptr, "PushInteractiveInData"},
  306. {104, nullptr, "PopInteractiveOutData"},
  307. {105, nullptr, "GetPopOutDataEvent"},
  308. {106, nullptr, "GetPopInteractiveOutDataEvent"},
  309. {110, nullptr, "NeedsToExitProcess"},
  310. {120, nullptr, "GetLibraryAppletInfo"},
  311. {150, nullptr, "RequestForAppletToGetForeground"},
  312. {160, nullptr, "GetIndirectLayerConsumerHandle"},
  313. };
  314. RegisterHandlers(functions);
  315. state_changed_event = Kernel::Event::Create(Kernel::ResetType::OneShot,
  316. "ILibraryAppletAccessor:StateChangedEvent");
  317. }
  318. private:
  319. void GetAppletStateChangedEvent(Kernel::HLERequestContext& ctx) {
  320. state_changed_event->Signal();
  321. IPC::ResponseBuilder rb{ctx, 2, 1};
  322. rb.Push(RESULT_SUCCESS);
  323. rb.PushCopyObjects(state_changed_event);
  324. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  325. }
  326. Kernel::SharedPtr<Kernel::Event> state_changed_event;
  327. };
  328. ILibraryAppletCreator::ILibraryAppletCreator() : ServiceFramework("ILibraryAppletCreator") {
  329. static const FunctionInfo functions[] = {
  330. {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"},
  331. {1, nullptr, "TerminateAllLibraryApplets"},
  332. {2, nullptr, "AreAnyLibraryAppletsLeft"},
  333. {10, nullptr, "CreateStorage"},
  334. {11, nullptr, "CreateTransferMemoryStorage"},
  335. {12, nullptr, "CreateHandleStorage"},
  336. };
  337. RegisterHandlers(functions);
  338. }
  339. void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx) {
  340. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  341. rb.Push(RESULT_SUCCESS);
  342. rb.PushIpcInterface<AM::ILibraryAppletAccessor>();
  343. NGLOG_DEBUG(Service_AM, "called");
  344. }
  345. class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
  346. public:
  347. explicit IStorageAccessor(std::vector<u8> buffer)
  348. : ServiceFramework("IStorageAccessor"), buffer(std::move(buffer)) {
  349. static const FunctionInfo functions[] = {
  350. {0, &IStorageAccessor::GetSize, "GetSize"},
  351. {10, nullptr, "Write"},
  352. {11, &IStorageAccessor::Read, "Read"},
  353. };
  354. RegisterHandlers(functions);
  355. }
  356. private:
  357. std::vector<u8> buffer;
  358. void GetSize(Kernel::HLERequestContext& ctx) {
  359. IPC::ResponseBuilder rb{ctx, 4};
  360. rb.Push(RESULT_SUCCESS);
  361. rb.Push(static_cast<u64>(buffer.size()));
  362. NGLOG_DEBUG(Service_AM, "called");
  363. }
  364. void Read(Kernel::HLERequestContext& ctx) {
  365. IPC::RequestParser rp{ctx};
  366. u64 offset = rp.Pop<u64>();
  367. const size_t size{ctx.GetWriteBufferSize()};
  368. ASSERT(offset + size <= buffer.size());
  369. ctx.WriteBuffer(buffer.data() + offset, size);
  370. IPC::ResponseBuilder rb{ctx, 2};
  371. rb.Push(RESULT_SUCCESS);
  372. NGLOG_DEBUG(Service_AM, "called");
  373. }
  374. };
  375. class IStorage final : public ServiceFramework<IStorage> {
  376. public:
  377. explicit IStorage(std::vector<u8> buffer)
  378. : ServiceFramework("IStorage"), buffer(std::move(buffer)) {
  379. static const FunctionInfo functions[] = {
  380. {0, &IStorage::Open, "Open"},
  381. {1, nullptr, "OpenTransferStorage"},
  382. };
  383. RegisterHandlers(functions);
  384. }
  385. private:
  386. std::vector<u8> buffer;
  387. void Open(Kernel::HLERequestContext& ctx) {
  388. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  389. rb.Push(RESULT_SUCCESS);
  390. rb.PushIpcInterface<AM::IStorageAccessor>(buffer);
  391. NGLOG_DEBUG(Service_AM, "called");
  392. }
  393. };
  394. IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationFunctions") {
  395. static const FunctionInfo functions[] = {
  396. {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
  397. {10, nullptr, "CreateApplicationAndPushAndRequestToStart"},
  398. {11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"},
  399. {12, nullptr, "CreateApplicationAndRequestToStart"},
  400. {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest,
  401. "CreateApplicationAndRequestToStartForQuest"},
  402. {20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"},
  403. {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"},
  404. {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"},
  405. {23, &IApplicationFunctions::GetDisplayVersion, "GetDisplayVersion"},
  406. {24, nullptr, "GetLaunchStorageInfoForDebug"},
  407. {25, nullptr, "ExtendSaveData"},
  408. {26, nullptr, "GetSaveDataSize"},
  409. {30, nullptr, "BeginBlockingHomeButtonShortAndLongPressed"},
  410. {31, nullptr, "EndBlockingHomeButtonShortAndLongPressed"},
  411. {32, nullptr, "BeginBlockingHomeButton"},
  412. {33, nullptr, "EndBlockingHomeButton"},
  413. {40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"},
  414. {50, nullptr, "GetPseudoDeviceId"},
  415. {60, nullptr, "SetMediaPlaybackStateForApplication"},
  416. {65, nullptr, "IsGamePlayRecordingSupported"},
  417. {66, &IApplicationFunctions::InitializeGamePlayRecording, "InitializeGamePlayRecording"},
  418. {67, &IApplicationFunctions::SetGamePlayRecordingState, "SetGamePlayRecordingState"},
  419. {68, nullptr, "RequestFlushGamePlayingMovieForDebug"},
  420. {70, nullptr, "RequestToShutdown"},
  421. {71, nullptr, "RequestToReboot"},
  422. {80, nullptr, "ExitAndRequestToShowThanksMessage"},
  423. {90, nullptr, "EnableApplicationCrashReport"},
  424. {100, nullptr, "InitializeApplicationCopyrightFrameBuffer"},
  425. {101, nullptr, "SetApplicationCopyrightImage"},
  426. {102, nullptr, "SetApplicationCopyrightVisibility"},
  427. {110, nullptr, "QueryApplicationPlayStatistics"},
  428. {120, nullptr, "ExecuteProgram"},
  429. {121, nullptr, "ClearUserChannel"},
  430. {122, nullptr, "UnpopToUserChannel"},
  431. {500, nullptr, "StartContinuousRecordingFlushForDebug"},
  432. {1000, nullptr, "CreateMovieMaker"},
  433. {1001, nullptr, "PrepareForJit"},
  434. };
  435. RegisterHandlers(functions);
  436. }
  437. void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
  438. constexpr u8 data[0x88] = {
  439. 0xca, 0x97, 0x94, 0xc7, // Magic
  440. 1, 0, 0, 0, // IsAccountSelected (bool)
  441. 1, 0, 0, 0, // User Id (word 0)
  442. 0, 0, 0, 0, // User Id (word 1)
  443. 0, 0, 0, 0, // User Id (word 2)
  444. 0, 0, 0, 0 // User Id (word 3)
  445. };
  446. std::vector<u8> buffer(data, data + sizeof(data));
  447. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  448. rb.Push(RESULT_SUCCESS);
  449. rb.PushIpcInterface<AM::IStorage>(buffer);
  450. NGLOG_DEBUG(Service_AM, "called");
  451. }
  452. void IApplicationFunctions::CreateApplicationAndRequestToStartForQuest(
  453. Kernel::HLERequestContext& ctx) {
  454. IPC::ResponseBuilder rb{ctx, 2};
  455. rb.Push(RESULT_SUCCESS);
  456. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  457. }
  458. void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) {
  459. IPC::RequestParser rp{ctx};
  460. u128 uid = rp.PopRaw<u128>();
  461. NGLOG_WARNING(Service, "(STUBBED) called uid = {:016X}{:016X}", uid[1], uid[0]);
  462. IPC::ResponseBuilder rb{ctx, 4};
  463. FileSys::Path unused;
  464. auto savedata = FileSystem::OpenFileSystem(FileSystem::Type::SaveData, unused);
  465. if (savedata.Failed()) {
  466. // Create the save data and return an error indicating that the operation was performed.
  467. FileSystem::FormatFileSystem(FileSystem::Type::SaveData);
  468. // TODO(Subv): Find out the correct error code for this.
  469. rb.Push(ResultCode(ErrorModule::FS, 40));
  470. } else {
  471. rb.Push(RESULT_SUCCESS);
  472. }
  473. rb.Push<u64>(0);
  474. }
  475. void IApplicationFunctions::SetTerminateResult(Kernel::HLERequestContext& ctx) {
  476. // Takes an input u32 Result, no output.
  477. // For example, in some cases official apps use this with error 0x2A2 then uses svcBreak.
  478. IPC::RequestParser rp{ctx};
  479. u32 result = rp.Pop<u32>();
  480. IPC::ResponseBuilder rb{ctx, 2};
  481. rb.Push(RESULT_SUCCESS);
  482. NGLOG_WARNING(Service_AM, "(STUBBED) called, result=0x{:08X}", result);
  483. }
  484. void IApplicationFunctions::GetDisplayVersion(Kernel::HLERequestContext& ctx) {
  485. IPC::ResponseBuilder rb{ctx, 6};
  486. rb.Push(RESULT_SUCCESS);
  487. rb.Push<u64>(1);
  488. rb.Push<u64>(0);
  489. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  490. }
  491. void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) {
  492. // TODO(bunnei): This should be configurable
  493. IPC::ResponseBuilder rb{ctx, 4};
  494. rb.Push(RESULT_SUCCESS);
  495. rb.Push(static_cast<u64>(Service::Set::LanguageCode::EN_US));
  496. NGLOG_DEBUG(Service_AM, "called");
  497. }
  498. void IApplicationFunctions::InitializeGamePlayRecording(Kernel::HLERequestContext& ctx) {
  499. IPC::ResponseBuilder rb{ctx, 2};
  500. rb.Push(RESULT_SUCCESS);
  501. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  502. }
  503. void IApplicationFunctions::SetGamePlayRecordingState(Kernel::HLERequestContext& ctx) {
  504. IPC::ResponseBuilder rb{ctx, 2};
  505. rb.Push(RESULT_SUCCESS);
  506. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  507. }
  508. void IApplicationFunctions::NotifyRunning(Kernel::HLERequestContext& ctx) {
  509. IPC::ResponseBuilder rb{ctx, 3};
  510. rb.Push(RESULT_SUCCESS);
  511. rb.Push<u8>(0); // Unknown, seems to be ignored by official processes
  512. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  513. }
  514. void InstallInterfaces(SM::ServiceManager& service_manager,
  515. std::shared_ptr<NVFlinger::NVFlinger> nvflinger) {
  516. std::make_shared<AppletAE>(nvflinger)->InstallAsService(service_manager);
  517. std::make_shared<AppletOE>(nvflinger)->InstallAsService(service_manager);
  518. }
  519. IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions") {
  520. static const FunctionInfo functions[] = {
  521. {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
  522. {11, nullptr, "LockForeground"},
  523. {12, nullptr, "UnlockForeground"},
  524. {20, nullptr, "PopFromGeneralChannel"},
  525. {21, nullptr, "GetPopFromGeneralChannelEvent"},
  526. {30, nullptr, "GetHomeButtonWriterLockAccessor"},
  527. {31, nullptr, "GetWriterLockAccessorEx"},
  528. };
  529. RegisterHandlers(functions);
  530. }
  531. void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx) {
  532. IPC::ResponseBuilder rb{ctx, 2};
  533. rb.Push(RESULT_SUCCESS);
  534. NGLOG_WARNING(Service_AM, "(STUBBED) called");
  535. }
  536. IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStateController") {
  537. static const FunctionInfo functions[] = {
  538. {0, nullptr, "RequestToEnterSleep"},
  539. {1, nullptr, "EnterSleep"},
  540. {2, nullptr, "StartSleepSequence"},
  541. {3, nullptr, "StartShutdownSequence"},
  542. {4, nullptr, "StartRebootSequence"},
  543. {10, nullptr, "LoadAndApplyIdlePolicySettings"},
  544. {11, nullptr, "NotifyCecSettingsChanged"},
  545. {12, nullptr, "SetDefaultHomeButtonLongPressTime"},
  546. {13, nullptr, "UpdateDefaultDisplayResolution"},
  547. {14, nullptr, "ShouldSleepOnBoot"},
  548. {15, nullptr, "GetHdcpAuthenticationFailedEvent"},
  549. };
  550. RegisterHandlers(functions);
  551. }
  552. IApplicationCreator::IApplicationCreator() : ServiceFramework("IApplicationCreator") {
  553. static const FunctionInfo functions[] = {
  554. {0, nullptr, "CreateApplication"},
  555. {1, nullptr, "PopLaunchRequestedApplication"},
  556. {10, nullptr, "CreateSystemApplication"},
  557. {100, nullptr, "PopFloatingApplicationForDevelopment"},
  558. };
  559. RegisterHandlers(functions);
  560. }
  561. IProcessWindingController::IProcessWindingController()
  562. : ServiceFramework("IProcessWindingController") {
  563. static const FunctionInfo functions[] = {
  564. {0, nullptr, "GetLaunchReason"},
  565. {11, nullptr, "OpenCallingLibraryApplet"},
  566. {21, nullptr, "PushContext"},
  567. {22, nullptr, "PopContext"},
  568. {23, nullptr, "CancelWindingReservation"},
  569. {30, nullptr, "WindAndDoReserved"},
  570. {40, nullptr, "ReserveToStartAndWaitAndUnwindThis"},
  571. {41, nullptr, "ReserveToStartAndWait"},
  572. };
  573. RegisterHandlers(functions);
  574. }
  575. } // namespace Service::AM