| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704 |
- // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
- // SPDX-License-Identifier: GPL-2.0-or-later
- #include <algorithm>
- #include <array>
- #include <cinttypes>
- #include <cstring>
- #include "common/settings.h"
- #include "common/settings_enums.h"
- #include "core/core.h"
- #include "core/core_timing.h"
- #include "core/file_sys/control_metadata.h"
- #include "core/file_sys/patch_manager.h"
- #include "core/file_sys/registered_cache.h"
- #include "core/file_sys/savedata_factory.h"
- #include "core/hle/kernel/k_event.h"
- #include "core/hle/kernel/k_transfer_memory.h"
- #include "core/hle/result.h"
- #include "core/hle/service/acc/profile_manager.h"
- #include "core/hle/service/am/am.h"
- #include "core/hle/service/am/applet_ae.h"
- #include "core/hle/service/am/applet_oe.h"
- #include "core/hle/service/am/applets/applet_cabinet.h"
- #include "core/hle/service/am/applets/applet_controller.h"
- #include "core/hle/service/am/applets/applet_mii_edit_types.h"
- #include "core/hle/service/am/applets/applet_profile_select.h"
- #include "core/hle/service/am/applets/applet_software_keyboard_types.h"
- #include "core/hle/service/am/applets/applet_web_browser.h"
- #include "core/hle/service/am/applets/applets.h"
- #include "core/hle/service/am/idle.h"
- #include "core/hle/service/am/omm.h"
- #include "core/hle/service/am/spsm.h"
- #include "core/hle/service/apm/apm_controller.h"
- #include "core/hle/service/apm/apm_interface.h"
- #include "core/hle/service/bcat/backend/backend.h"
- #include "core/hle/service/caps/caps_su.h"
- #include "core/hle/service/caps/caps_types.h"
- #include "core/hle/service/filesystem/filesystem.h"
- #include "core/hle/service/filesystem/save_data_controller.h"
- #include "core/hle/service/ipc_helpers.h"
- #include "core/hle/service/ns/ns.h"
- #include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
- #include "core/hle/service/nvnflinger/nvnflinger.h"
- #include "core/hle/service/pm/pm.h"
- #include "core/hle/service/server_manager.h"
- #include "core/hle/service/sm/sm.h"
- #include "core/hle/service/vi/vi.h"
- #include "core/hle/service/vi/vi_results.h"
- #include "core/memory.h"
- #include "hid_core/hid_types.h"
- #include "hid_core/resources/npad/npad.h"
- namespace Service::AM {
- constexpr Result ResultNoDataInChannel{ErrorModule::AM, 2};
- constexpr Result ResultNoMessages{ErrorModule::AM, 3};
- constexpr Result ResultInvalidOffset{ErrorModule::AM, 503};
- enum class LaunchParameterKind : u32 {
- UserChannel = 1,
- AccountPreselectedUser = 2,
- };
- constexpr u32 LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC = 0xC79497CA;
- struct LaunchParameterAccountPreselectedUser {
- u32_le magic;
- u32_le is_account_selected;
- Common::UUID current_user;
- INSERT_PADDING_BYTES(0x70);
- };
- static_assert(sizeof(LaunchParameterAccountPreselectedUser) == 0x88);
- IWindowController::IWindowController(Core::System& system_)
- : ServiceFramework{system_, "IWindowController"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, nullptr, "CreateWindow"},
- {1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"},
- {2, &IWindowController::GetAppletResourceUserIdOfCallerApplet, "GetAppletResourceUserIdOfCallerApplet"},
- {10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"},
- {11, nullptr, "ReleaseForegroundRights"},
- {12, nullptr, "RejectToChangeIntoBackground"},
- {20, nullptr, "SetAppletWindowVisibility"},
- {21, nullptr, "SetAppletGpuTimeSlice"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IWindowController::~IWindowController() = default;
- void IWindowController::GetAppletResourceUserId(HLERequestContext& ctx) {
- const u64 process_id = system.ApplicationProcess()->GetProcessId();
- LOG_DEBUG(Service_AM, "called. Process ID=0x{:016X}", process_id);
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push<u64>(process_id);
- }
- void IWindowController::GetAppletResourceUserIdOfCallerApplet(HLERequestContext& ctx) {
- const u64 process_id = 0;
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push<u64>(process_id);
- }
- void IWindowController::AcquireForegroundRights(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- IAudioController::IAudioController(Core::System& system_)
- : ServiceFramework{system_, "IAudioController"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, &IAudioController::SetExpectedMasterVolume, "SetExpectedMasterVolume"},
- {1, &IAudioController::GetMainAppletExpectedMasterVolume, "GetMainAppletExpectedMasterVolume"},
- {2, &IAudioController::GetLibraryAppletExpectedMasterVolume, "GetLibraryAppletExpectedMasterVolume"},
- {3, &IAudioController::ChangeMainAppletMasterVolume, "ChangeMainAppletMasterVolume"},
- {4, &IAudioController::SetTransparentAudioRate, "SetTransparentVolumeRate"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IAudioController::~IAudioController() = default;
- void IAudioController::SetExpectedMasterVolume(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const float main_applet_volume_tmp = rp.Pop<float>();
- const float library_applet_volume_tmp = rp.Pop<float>();
- LOG_DEBUG(Service_AM, "called. main_applet_volume={}, library_applet_volume={}",
- main_applet_volume_tmp, library_applet_volume_tmp);
- // Ensure the volume values remain within the 0-100% range
- main_applet_volume = std::clamp(main_applet_volume_tmp, min_allowed_volume, max_allowed_volume);
- library_applet_volume =
- std::clamp(library_applet_volume_tmp, min_allowed_volume, max_allowed_volume);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IAudioController::GetMainAppletExpectedMasterVolume(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called. main_applet_volume={}", main_applet_volume);
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push(main_applet_volume);
- }
- void IAudioController::GetLibraryAppletExpectedMasterVolume(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called. library_applet_volume={}", library_applet_volume);
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push(library_applet_volume);
- }
- void IAudioController::ChangeMainAppletMasterVolume(HLERequestContext& ctx) {
- struct Parameters {
- float volume;
- s64 fade_time_ns;
- };
- static_assert(sizeof(Parameters) == 16);
- IPC::RequestParser rp{ctx};
- const auto parameters = rp.PopRaw<Parameters>();
- LOG_DEBUG(Service_AM, "called. volume={}, fade_time_ns={}", parameters.volume,
- parameters.fade_time_ns);
- main_applet_volume = std::clamp(parameters.volume, min_allowed_volume, max_allowed_volume);
- fade_time_ns = std::chrono::nanoseconds{parameters.fade_time_ns};
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IAudioController::SetTransparentAudioRate(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const float transparent_volume_rate_tmp = rp.Pop<float>();
- LOG_DEBUG(Service_AM, "called. transparent_volume_rate={}", transparent_volume_rate_tmp);
- // Clamp volume range to 0-100%.
- transparent_volume_rate =
- std::clamp(transparent_volume_rate_tmp, min_allowed_volume, max_allowed_volume);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- IDisplayController::IDisplayController(Core::System& system_)
- : ServiceFramework{system_, "IDisplayController"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, nullptr, "GetLastForegroundCaptureImage"},
- {1, nullptr, "UpdateLastForegroundCaptureImage"},
- {2, nullptr, "GetLastApplicationCaptureImage"},
- {3, nullptr, "GetCallerAppletCaptureImage"},
- {4, nullptr, "UpdateCallerAppletCaptureImage"},
- {5, nullptr, "GetLastForegroundCaptureImageEx"},
- {6, nullptr, "GetLastApplicationCaptureImageEx"},
- {7, &IDisplayController::GetCallerAppletCaptureImageEx, "GetCallerAppletCaptureImageEx"},
- {8, &IDisplayController::TakeScreenShotOfOwnLayer, "TakeScreenShotOfOwnLayer"},
- {9, nullptr, "CopyBetweenCaptureBuffers"},
- {10, nullptr, "AcquireLastApplicationCaptureBuffer"},
- {11, nullptr, "ReleaseLastApplicationCaptureBuffer"},
- {12, nullptr, "AcquireLastForegroundCaptureBuffer"},
- {13, nullptr, "ReleaseLastForegroundCaptureBuffer"},
- {14, nullptr, "AcquireCallerAppletCaptureBuffer"},
- {15, nullptr, "ReleaseCallerAppletCaptureBuffer"},
- {16, nullptr, "AcquireLastApplicationCaptureBufferEx"},
- {17, nullptr, "AcquireLastForegroundCaptureBufferEx"},
- {18, nullptr, "AcquireCallerAppletCaptureBufferEx"},
- {20, nullptr, "ClearCaptureBuffer"},
- {21, nullptr, "ClearAppletTransitionBuffer"},
- {22, nullptr, "AcquireLastApplicationCaptureSharedBuffer"},
- {23, nullptr, "ReleaseLastApplicationCaptureSharedBuffer"},
- {24, &IDisplayController::AcquireLastForegroundCaptureSharedBuffer, "AcquireLastForegroundCaptureSharedBuffer"},
- {25, &IDisplayController::ReleaseLastForegroundCaptureSharedBuffer, "ReleaseLastForegroundCaptureSharedBuffer"},
- {26, &IDisplayController::AcquireCallerAppletCaptureSharedBuffer, "AcquireCallerAppletCaptureSharedBuffer"},
- {27, &IDisplayController::ReleaseCallerAppletCaptureSharedBuffer, "ReleaseCallerAppletCaptureSharedBuffer"},
- {28, nullptr, "TakeScreenShotOfOwnLayerEx"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IDisplayController::~IDisplayController() = default;
- void IDisplayController::GetCallerAppletCaptureImageEx(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push(1u);
- rb.Push(0);
- }
- void IDisplayController::TakeScreenShotOfOwnLayer(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IDisplayController::AcquireLastForegroundCaptureSharedBuffer(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push(1U);
- rb.Push(0);
- }
- void IDisplayController::ReleaseLastForegroundCaptureSharedBuffer(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IDisplayController::AcquireCallerAppletCaptureSharedBuffer(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push(1U);
- rb.Push(0);
- }
- void IDisplayController::ReleaseCallerAppletCaptureSharedBuffer(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- IDebugFunctions::IDebugFunctions(Core::System& system_)
- : ServiceFramework{system_, "IDebugFunctions"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, nullptr, "NotifyMessageToHomeMenuForDebug"},
- {1, nullptr, "OpenMainApplication"},
- {10, nullptr, "PerformSystemButtonPressing"},
- {20, nullptr, "InvalidateTransitionLayer"},
- {30, nullptr, "RequestLaunchApplicationWithUserAndArgumentForDebug"},
- {31, nullptr, "RequestLaunchApplicationByApplicationLaunchInfoForDebug"},
- {40, nullptr, "GetAppletResourceUsageInfo"},
- {50, nullptr, "AddSystemProgramIdAndAppletIdForDebug"},
- {51, nullptr, "AddOperationConfirmedLibraryAppletIdForDebug"},
- {100, nullptr, "SetCpuBoostModeForApplet"},
- {101, nullptr, "CancelCpuBoostModeForApplet"},
- {110, nullptr, "PushToAppletBoundChannelForDebug"},
- {111, nullptr, "TryPopFromAppletBoundChannelForDebug"},
- {120, nullptr, "AlarmSettingNotificationEnableAppEventReserve"},
- {121, nullptr, "AlarmSettingNotificationDisableAppEventReserve"},
- {122, nullptr, "AlarmSettingNotificationPushAppEventNotify"},
- {130, nullptr, "FriendInvitationSetApplicationParameter"},
- {131, nullptr, "FriendInvitationClearApplicationParameter"},
- {132, nullptr, "FriendInvitationPushApplicationParameter"},
- {140, nullptr, "RestrictPowerOperationForSecureLaunchModeForDebug"},
- {200, nullptr, "CreateFloatingLibraryAppletAccepterForDebug"},
- {300, nullptr, "TerminateAllRunningApplicationsForDebug"},
- {900, nullptr, "GetGrcProcessLaunchedSystemEvent"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IDebugFunctions::~IDebugFunctions() = default;
- ISelfController::ISelfController(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger_)
- : ServiceFramework{system_, "ISelfController"}, nvnflinger{nvnflinger_},
- service_context{system, "ISelfController"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, &ISelfController::Exit, "Exit"},
- {1, &ISelfController::LockExit, "LockExit"},
- {2, &ISelfController::UnlockExit, "UnlockExit"},
- {3, &ISelfController::EnterFatalSection, "EnterFatalSection"},
- {4, &ISelfController::LeaveFatalSection, "LeaveFatalSection"},
- {9, &ISelfController::GetLibraryAppletLaunchableEvent, "GetLibraryAppletLaunchableEvent"},
- {10, &ISelfController::SetScreenShotPermission, "SetScreenShotPermission"},
- {11, &ISelfController::SetOperationModeChangedNotification, "SetOperationModeChangedNotification"},
- {12, &ISelfController::SetPerformanceModeChangedNotification, "SetPerformanceModeChangedNotification"},
- {13, &ISelfController::SetFocusHandlingMode, "SetFocusHandlingMode"},
- {14, &ISelfController::SetRestartMessageEnabled, "SetRestartMessageEnabled"},
- {15, nullptr, "SetScreenShotAppletIdentityInfo"},
- {16, &ISelfController::SetOutOfFocusSuspendingEnabled, "SetOutOfFocusSuspendingEnabled"},
- {17, nullptr, "SetControllerFirmwareUpdateSection"},
- {18, nullptr, "SetRequiresCaptureButtonShortPressedMessage"},
- {19, &ISelfController::SetAlbumImageOrientation, "SetAlbumImageOrientation"},
- {20, nullptr, "SetDesirableKeyboardLayout"},
- {21, nullptr, "GetScreenShotProgramId"},
- {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"},
- {41, &ISelfController::IsSystemBufferSharingEnabled, "IsSystemBufferSharingEnabled"},
- {42, &ISelfController::GetSystemSharedLayerHandle, "GetSystemSharedLayerHandle"},
- {43, &ISelfController::GetSystemSharedBufferHandle, "GetSystemSharedBufferHandle"},
- {44, &ISelfController::CreateManagedDisplaySeparableLayer, "CreateManagedDisplaySeparableLayer"},
- {45, nullptr, "SetManagedDisplayLayerSeparationMode"},
- {46, nullptr, "SetRecordingLayerCompositionEnabled"},
- {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"},
- {51, &ISelfController::ApproveToDisplay, "ApproveToDisplay"},
- {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"},
- {61, nullptr, "SetMediaPlaybackState"},
- {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"},
- {63, &ISelfController::GetIdleTimeDetectionExtension, "GetIdleTimeDetectionExtension"},
- {64, nullptr, "SetInputDetectionSourceSet"},
- {65, &ISelfController::ReportUserIsActive, "ReportUserIsActive"},
- {66, nullptr, "GetCurrentIlluminance"},
- {67, nullptr, "IsIlluminanceAvailable"},
- {68, &ISelfController::SetAutoSleepDisabled, "SetAutoSleepDisabled"},
- {69, &ISelfController::IsAutoSleepDisabled, "IsAutoSleepDisabled"},
- {70, nullptr, "ReportMultimediaError"},
- {71, nullptr, "GetCurrentIlluminanceEx"},
- {72, nullptr, "SetInputDetectionPolicy"},
- {80, nullptr, "SetWirelessPriorityMode"},
- {90, &ISelfController::GetAccumulatedSuspendedTickValue, "GetAccumulatedSuspendedTickValue"},
- {91, &ISelfController::GetAccumulatedSuspendedTickChangedEvent, "GetAccumulatedSuspendedTickChangedEvent"},
- {100, &ISelfController::SetAlbumImageTakenNotificationEnabled, "SetAlbumImageTakenNotificationEnabled"},
- {110, nullptr, "SetApplicationAlbumUserData"},
- {120, &ISelfController::SaveCurrentScreenshot, "SaveCurrentScreenshot"},
- {130, &ISelfController::SetRecordVolumeMuted, "SetRecordVolumeMuted"},
- {1000, nullptr, "GetDebugStorageChannel"},
- };
- // clang-format on
- RegisterHandlers(functions);
- launchable_event = service_context.CreateEvent("ISelfController:LaunchableEvent");
- // This event is created by AM on the first time GetAccumulatedSuspendedTickChangedEvent() is
- // called. Yuzu can just create it unconditionally, since it doesn't need to support multiple
- // ISelfControllers. The event is signaled on creation, and on transition from suspended -> not
- // suspended if the event has previously been created by a call to
- // GetAccumulatedSuspendedTickChangedEvent.
- accumulated_suspended_tick_changed_event =
- service_context.CreateEvent("ISelfController:AccumulatedSuspendedTickChangedEvent");
- accumulated_suspended_tick_changed_event->Signal();
- }
- ISelfController::~ISelfController() {
- service_context.CloseEvent(launchable_event);
- service_context.CloseEvent(accumulated_suspended_tick_changed_event);
- }
- void ISelfController::Exit(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- system.Exit();
- }
- void ISelfController::LockExit(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- system.SetExitLocked(true);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::UnlockExit(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- system.SetExitLocked(false);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- if (system.GetExitRequested()) {
- system.Exit();
- }
- }
- void ISelfController::EnterFatalSection(HLERequestContext& ctx) {
- ++num_fatal_sections_entered;
- LOG_DEBUG(Service_AM, "called. Num fatal sections entered: {}", num_fatal_sections_entered);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::LeaveFatalSection(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called.");
- // Entry and exit of fatal sections must be balanced.
- if (num_fatal_sections_entered == 0) {
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(Result{ErrorModule::AM, 512});
- return;
- }
- --num_fatal_sections_entered;
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::GetLibraryAppletLaunchableEvent(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- launchable_event->Signal();
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(launchable_event->GetReadableEvent());
- }
- void ISelfController::SetScreenShotPermission(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto permission = rp.PopEnum<ScreenshotPermission>();
- LOG_DEBUG(Service_AM, "called, permission={}", permission);
- screenshot_permission = permission;
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetOperationModeChangedNotification(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- bool flag = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetPerformanceModeChangedNotification(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- bool flag = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "(STUBBED) called flag={}", flag);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetFocusHandlingMode(HLERequestContext& ctx) {
- // Takes 3 input u8s with each field located immediately after the previous
- // u8, these are bool flags. No output.
- IPC::RequestParser rp{ctx};
- struct FocusHandlingModeParams {
- u8 unknown0;
- u8 unknown1;
- u8 unknown2;
- };
- const auto flags = rp.PopRaw<FocusHandlingModeParams>();
- LOG_WARNING(Service_AM, "(STUBBED) called. unknown0={}, unknown1={}, unknown2={}",
- flags.unknown0, flags.unknown1, flags.unknown2);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetRestartMessageEnabled(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetOutOfFocusSuspendingEnabled(HLERequestContext& ctx) {
- // Takes 3 input u8s with each field located immediately after the previous
- // u8, these are bool flags. No output.
- IPC::RequestParser rp{ctx};
- bool enabled = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "(STUBBED) called enabled={}", enabled);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetAlbumImageOrientation(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::CreateManagedDisplayLayer(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- // TODO(Subv): Find out how AM determines the display to use, for now just
- // create the layer in the Default display.
- const auto display_id = nvnflinger.OpenDisplay("Default");
- const auto layer_id = nvnflinger.CreateLayer(*display_id);
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push(*layer_id);
- }
- void ISelfController::IsSystemBufferSharingEnabled(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(this->EnsureBufferSharingEnabled());
- }
- void ISelfController::GetSystemSharedLayerHandle(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 6};
- rb.Push(this->EnsureBufferSharingEnabled());
- rb.Push<s64>(system_shared_buffer_id);
- rb.Push<s64>(system_shared_layer_id);
- }
- void ISelfController::GetSystemSharedBufferHandle(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(this->EnsureBufferSharingEnabled());
- rb.Push<s64>(system_shared_buffer_id);
- }
- Result ISelfController::EnsureBufferSharingEnabled() {
- if (buffer_sharing_enabled) {
- return ResultSuccess;
- }
- if (system.GetAppletManager().GetCurrentAppletId() <= Applets::AppletId::Application) {
- return VI::ResultOperationFailed;
- }
- const auto display_id = nvnflinger.OpenDisplay("Default");
- const auto result = nvnflinger.GetSystemBufferManager().Initialize(
- &system_shared_buffer_id, &system_shared_layer_id, *display_id);
- if (result.IsSuccess()) {
- buffer_sharing_enabled = true;
- }
- return result;
- }
- void ISelfController::CreateManagedDisplaySeparableLayer(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- // TODO(Subv): Find out how AM determines the display to use, for now just
- // create the layer in the Default display.
- // This calls nn::vi::CreateRecordingLayer() which creates another layer.
- // Currently we do not support more than 1 layer per display, output 1 layer id for now.
- // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse
- // side effects.
- // TODO: Support multiple layers
- const auto display_id = nvnflinger.OpenDisplay("Default");
- const auto layer_id = nvnflinger.CreateLayer(*display_id);
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push(*layer_id);
- }
- void ISelfController::SetHandlesRequestToDisplay(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::ApproveToDisplay(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- idle_time_detection_extension = rp.Pop<u32>();
- LOG_DEBUG(Service_AM, "(STUBBED) called idle_time_detection_extension={}",
- idle_time_detection_extension);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::GetIdleTimeDetectionExtension(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<u32>(idle_time_detection_extension);
- }
- void ISelfController::ReportUserIsActive(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetAutoSleepDisabled(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- is_auto_sleep_disabled = rp.Pop<bool>();
- // On the system itself, if the previous state of is_auto_sleep_disabled
- // differed from the current value passed in, it'd signify the internal
- // window manager to update (and also increment some statistics like update counts)
- //
- // It'd also indicate this change to an idle handling context.
- //
- // However, given we're emulating this behavior, most of this can be ignored
- // and it's sufficient to simply set the member variable for querying via
- // IsAutoSleepDisabled().
- LOG_DEBUG(Service_AM, "called. is_auto_sleep_disabled={}", is_auto_sleep_disabled);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::IsAutoSleepDisabled(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called.");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push(is_auto_sleep_disabled);
- }
- void ISelfController::GetAccumulatedSuspendedTickValue(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called.");
- // This command returns the total number of system ticks since ISelfController creation
- // where the game was suspended. Since Yuzu doesn't implement game suspension, this command
- // can just always return 0 ticks.
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push<u64>(0);
- }
- void ISelfController::GetAccumulatedSuspendedTickChangedEvent(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called.");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(accumulated_suspended_tick_changed_event->GetReadableEvent());
- }
- void ISelfController::SetAlbumImageTakenNotificationEnabled(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- // This service call sets an internal flag whether a notification is shown when an image is
- // captured. Currently we do not support capturing images via the capture button, so this can be
- // stubbed for now.
- const bool album_image_taken_notification_enabled = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "(STUBBED) called. album_image_taken_notification_enabled={}",
- album_image_taken_notification_enabled);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SaveCurrentScreenshot(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto report_option = rp.PopEnum<Capture::AlbumReportOption>();
- LOG_INFO(Service_AM, "called, report_option={}", report_option);
- const auto screenshot_service =
- system.ServiceManager().GetService<Service::Capture::IScreenShotApplicationService>(
- "caps:su");
- if (screenshot_service) {
- screenshot_service->CaptureAndSaveScreenshot(report_option);
- }
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ISelfController::SetRecordVolumeMuted(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto is_record_volume_muted = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "(STUBBED) called. is_record_volume_muted={}", is_record_volume_muted);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- AppletMessageQueue::AppletMessageQueue(Core::System& system)
- : service_context{system, "AppletMessageQueue"} {
- on_new_message = service_context.CreateEvent("AMMessageQueue:OnMessageReceived");
- on_operation_mode_changed = service_context.CreateEvent("AMMessageQueue:OperationModeChanged");
- }
- AppletMessageQueue::~AppletMessageQueue() {
- service_context.CloseEvent(on_new_message);
- service_context.CloseEvent(on_operation_mode_changed);
- }
- Kernel::KReadableEvent& AppletMessageQueue::GetMessageReceiveEvent() {
- return on_new_message->GetReadableEvent();
- }
- Kernel::KReadableEvent& AppletMessageQueue::GetOperationModeChangedEvent() {
- return on_operation_mode_changed->GetReadableEvent();
- }
- void AppletMessageQueue::PushMessage(AppletMessage msg) {
- messages.push(msg);
- on_new_message->Signal();
- }
- AppletMessageQueue::AppletMessage AppletMessageQueue::PopMessage() {
- if (messages.empty()) {
- on_new_message->Clear();
- return AppletMessage::None;
- }
- auto msg = messages.front();
- messages.pop();
- if (messages.empty()) {
- on_new_message->Clear();
- }
- return msg;
- }
- std::size_t AppletMessageQueue::GetMessageCount() const {
- return messages.size();
- }
- void AppletMessageQueue::RequestExit() {
- PushMessage(AppletMessage::Exit);
- }
- void AppletMessageQueue::RequestResume() {
- PushMessage(AppletMessage::Resume);
- }
- void AppletMessageQueue::FocusStateChanged() {
- PushMessage(AppletMessage::FocusStateChanged);
- }
- void AppletMessageQueue::OperationModeChanged() {
- PushMessage(AppletMessage::OperationModeChanged);
- PushMessage(AppletMessage::PerformanceModeChanged);
- on_operation_mode_changed->Signal();
- }
- ILockAccessor::ILockAccessor(Core::System& system_)
- : ServiceFramework{system_, "ILockAccessor"}, service_context{system_, "ILockAccessor"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {1, &ILockAccessor::TryLock, "TryLock"},
- {2, &ILockAccessor::Unlock, "Unlock"},
- {3, &ILockAccessor::GetEvent, "GetEvent"},
- {4,&ILockAccessor::IsLocked, "IsLocked"},
- };
- // clang-format on
- RegisterHandlers(functions);
- lock_event = service_context.CreateEvent("ILockAccessor::LockEvent");
- }
- ILockAccessor::~ILockAccessor() {
- service_context.CloseEvent(lock_event);
- };
- void ILockAccessor::TryLock(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto return_handle = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "(STUBBED) called, return_handle={}", return_handle);
- // TODO: When return_handle is true this function should return the lock handle
- is_locked = true;
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<u8>(is_locked);
- }
- void ILockAccessor::Unlock(HLERequestContext& ctx) {
- LOG_INFO(Service_AM, "called");
- is_locked = false;
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ILockAccessor::GetEvent(HLERequestContext& ctx) {
- LOG_INFO(Service_AM, "called");
- lock_event->Signal();
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(lock_event->GetReadableEvent());
- }
- void ILockAccessor::IsLocked(HLERequestContext& ctx) {
- LOG_INFO(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- rb.Push<u8>(is_locked);
- }
- ICommonStateGetter::ICommonStateGetter(Core::System& system_,
- std::shared_ptr<AppletMessageQueue> msg_queue_)
- : ServiceFramework{system_, "ICommonStateGetter"}, msg_queue{std::move(msg_queue_)},
- service_context{system_, "ICommonStateGetter"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
- {1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"},
- {2, nullptr, "GetThisAppletKind"},
- {3, nullptr, "AllowToEnterSleep"},
- {4, nullptr, "DisallowToEnterSleep"},
- {5, &ICommonStateGetter::GetOperationMode, "GetOperationMode"},
- {6, &ICommonStateGetter::GetPerformanceMode, "GetPerformanceMode"},
- {7, nullptr, "GetCradleStatus"},
- {8, &ICommonStateGetter::GetBootMode, "GetBootMode"},
- {9, &ICommonStateGetter::GetCurrentFocusState, "GetCurrentFocusState"},
- {10, &ICommonStateGetter::RequestToAcquireSleepLock, "RequestToAcquireSleepLock"},
- {11, nullptr, "ReleaseSleepLock"},
- {12, nullptr, "ReleaseSleepLockTransiently"},
- {13, &ICommonStateGetter::GetAcquiredSleepLockEvent, "GetAcquiredSleepLockEvent"},
- {14, nullptr, "GetWakeupCount"},
- {20, nullptr, "PushToGeneralChannel"},
- {30, nullptr, "GetHomeButtonReaderLockAccessor"},
- {31, &ICommonStateGetter::GetReaderLockAccessorEx, "GetReaderLockAccessorEx"},
- {32, nullptr, "GetWriterLockAccessorEx"},
- {40, nullptr, "GetCradleFwVersion"},
- {50, &ICommonStateGetter::IsVrModeEnabled, "IsVrModeEnabled"},
- {51, &ICommonStateGetter::SetVrModeEnabled, "SetVrModeEnabled"},
- {52, &ICommonStateGetter::SetLcdBacklighOffEnabled, "SetLcdBacklighOffEnabled"},
- {53, &ICommonStateGetter::BeginVrModeEx, "BeginVrModeEx"},
- {54, &ICommonStateGetter::EndVrModeEx, "EndVrModeEx"},
- {55, nullptr, "IsInControllerFirmwareUpdateSection"},
- {59, nullptr, "SetVrPositionForDebug"},
- {60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"},
- {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, "GetDefaultDisplayResolutionChangeEvent"},
- {62, nullptr, "GetHdcpAuthenticationState"},
- {63, nullptr, "GetHdcpAuthenticationStateChangeEvent"},
- {64, nullptr, "SetTvPowerStateMatchingMode"},
- {65, nullptr, "GetApplicationIdByContentActionName"},
- {66, &ICommonStateGetter::SetCpuBoostMode, "SetCpuBoostMode"},
- {67, nullptr, "CancelCpuBoostMode"},
- {68, &ICommonStateGetter::GetBuiltInDisplayType, "GetBuiltInDisplayType"},
- {80, &ICommonStateGetter::PerformSystemButtonPressingIfInFocus, "PerformSystemButtonPressingIfInFocus"},
- {90, nullptr, "SetPerformanceConfigurationChangedNotification"},
- {91, nullptr, "GetCurrentPerformanceConfiguration"},
- {100, nullptr, "SetHandlingHomeButtonShortPressedEnabled"},
- {110, nullptr, "OpenMyGpuErrorHandler"},
- {120, nullptr, "GetAppletLaunchedHistory"},
- {200, nullptr, "GetOperationModeSystemInfo"},
- {300, &ICommonStateGetter::GetSettingsPlatformRegion, "GetSettingsPlatformRegion"},
- {400, nullptr, "ActivateMigrationService"},
- {401, nullptr, "DeactivateMigrationService"},
- {500, nullptr, "DisableSleepTillShutdown"},
- {501, nullptr, "SuppressDisablingSleepTemporarily"},
- {502, nullptr, "IsSleepEnabled"},
- {503, nullptr, "IsDisablingSleepSuppressed"},
- {900, &ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled, "SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled"},
- };
- // clang-format on
- RegisterHandlers(functions);
- sleep_lock_event = service_context.CreateEvent("ICommonStateGetter::SleepLockEvent");
- // Configure applets to be in foreground state
- msg_queue->PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground);
- msg_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
- }
- ICommonStateGetter::~ICommonStateGetter() {
- service_context.CloseEvent(sleep_lock_event);
- };
- void ICommonStateGetter::GetBootMode(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<u8>(static_cast<u8>(Service::PM::SystemBootMode::Normal)); // Normal boot mode
- }
- void ICommonStateGetter::GetEventHandle(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(msg_queue->GetMessageReceiveEvent());
- }
- void ICommonStateGetter::ReceiveMessage(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- const auto message = msg_queue->PopMessage();
- IPC::ResponseBuilder rb{ctx, 3};
- if (message == AppletMessageQueue::AppletMessage::None) {
- LOG_ERROR(Service_AM, "Message queue is empty");
- rb.Push(AM::ResultNoMessages);
- rb.PushEnum<AppletMessageQueue::AppletMessage>(message);
- return;
- }
- rb.Push(ResultSuccess);
- rb.PushEnum<AppletMessageQueue::AppletMessage>(message);
- }
- void ICommonStateGetter::GetCurrentFocusState(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push(static_cast<u8>(FocusState::InFocus));
- }
- void ICommonStateGetter::RequestToAcquireSleepLock(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- // Sleep lock is acquired immediately.
- sleep_lock_event->Signal();
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ICommonStateGetter::GetReaderLockAccessorEx(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto unknown = rp.Pop<u32>();
- LOG_INFO(Service_AM, "called, unknown={}", unknown);
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<ILockAccessor>(system);
- }
- void ICommonStateGetter::GetAcquiredSleepLockEvent(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(sleep_lock_event->GetReadableEvent());
- }
- void ICommonStateGetter::IsVrModeEnabled(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push(vr_mode_state);
- }
- void ICommonStateGetter::SetVrModeEnabled(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- vr_mode_state = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "VR Mode is {}", vr_mode_state ? "on" : "off");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ICommonStateGetter::SetLcdBacklighOffEnabled(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto is_lcd_backlight_off_enabled = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "(STUBBED) called. is_lcd_backlight_off_enabled={}",
- is_lcd_backlight_off_enabled);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ICommonStateGetter::BeginVrModeEx(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ICommonStateGetter::EndVrModeEx(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(msg_queue->GetOperationModeChangedEvent());
- }
- void ICommonStateGetter::GetDefaultDisplayResolution(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- if (Settings::IsDockedMode()) {
- rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedWidth));
- rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedHeight));
- } else {
- rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedWidth));
- rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedHeight));
- }
- }
- void ICommonStateGetter::SetCpuBoostMode(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called, forwarding to APM:SYS");
- const auto& sm = system.ServiceManager();
- const auto apm_sys = sm.GetService<APM::APM_Sys>("apm:sys");
- ASSERT(apm_sys != nullptr);
- apm_sys->SetCpuBoostMode(ctx);
- }
- void ICommonStateGetter::GetBuiltInDisplayType(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push(0);
- }
- void ICommonStateGetter::PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto system_button{rp.PopEnum<SystemButtonType>()};
- LOG_WARNING(Service_AM, "(STUBBED) called, system_button={}", system_button);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ICommonStateGetter::GetSettingsPlatformRegion(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.PushEnum(SysPlatformRegion::Global);
- }
- void ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(
- HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- IStorageImpl::~IStorageImpl() = default;
- class StorageDataImpl final : public IStorageImpl {
- public:
- explicit StorageDataImpl(std::vector<u8>&& buffer_) : buffer{std::move(buffer_)} {}
- std::vector<u8>& GetData() override {
- return buffer;
- }
- const std::vector<u8>& GetData() const override {
- return buffer;
- }
- std::size_t GetSize() const override {
- return buffer.size();
- }
- private:
- std::vector<u8> buffer;
- };
- IStorage::IStorage(Core::System& system_, std::vector<u8>&& buffer)
- : ServiceFramework{system_, "IStorage"}, impl{std::make_shared<StorageDataImpl>(
- std::move(buffer))} {
- Register();
- }
- void IStorage::Register() {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, &IStorage::Open, "Open"},
- {1, nullptr, "OpenTransferStorage"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IStorage::~IStorage() = default;
- void IStorage::Open(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<IStorageAccessor>(system, *this);
- }
- void ICommonStateGetter::GetOperationMode(HLERequestContext& ctx) {
- const bool use_docked_mode{Settings::IsDockedMode()};
- LOG_DEBUG(Service_AM, "called, use_docked_mode={}", use_docked_mode);
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push(static_cast<u8>(use_docked_mode ? OperationMode::Docked : OperationMode::Handheld));
- }
- void ICommonStateGetter::GetPerformanceMode(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.PushEnum(system.GetAPMController().GetCurrentPerformanceMode());
- }
- class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
- public:
- explicit ILibraryAppletAccessor(Core::System& system_, std::shared_ptr<Applets::Applet> applet_)
- : ServiceFramework{system_, "ILibraryAppletAccessor"}, applet{std::move(applet_)} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
- {1, &ILibraryAppletAccessor::IsCompleted, "IsCompleted"},
- {10, &ILibraryAppletAccessor::Start, "Start"},
- {20, &ILibraryAppletAccessor::RequestExit, "RequestExit"},
- {25, nullptr, "Terminate"},
- {30, &ILibraryAppletAccessor::GetResult, "GetResult"},
- {50, nullptr, "SetOutOfFocusApplicationSuspendingEnabled"},
- {60, &ILibraryAppletAccessor::PresetLibraryAppletGpuTimeSliceZero, "PresetLibraryAppletGpuTimeSliceZero"},
- {100, &ILibraryAppletAccessor::PushInData, "PushInData"},
- {101, &ILibraryAppletAccessor::PopOutData, "PopOutData"},
- {102, nullptr, "PushExtraStorage"},
- {103, &ILibraryAppletAccessor::PushInteractiveInData, "PushInteractiveInData"},
- {104, &ILibraryAppletAccessor::PopInteractiveOutData, "PopInteractiveOutData"},
- {105, &ILibraryAppletAccessor::GetPopOutDataEvent, "GetPopOutDataEvent"},
- {106, &ILibraryAppletAccessor::GetPopInteractiveOutDataEvent, "GetPopInteractiveOutDataEvent"},
- {110, nullptr, "NeedsToExitProcess"},
- {120, nullptr, "GetLibraryAppletInfo"},
- {150, nullptr, "RequestForAppletToGetForeground"},
- {160, &ILibraryAppletAccessor::GetIndirectLayerConsumerHandle, "GetIndirectLayerConsumerHandle"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- private:
- void GetAppletStateChangedEvent(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(applet->GetBroker().GetStateChangedEvent());
- }
- void IsCompleted(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<u32>(applet->TransactionComplete());
- }
- void GetResult(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(applet->GetStatus());
- }
- void PresetLibraryAppletGpuTimeSliceZero(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void Start(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- ASSERT(applet != nullptr);
- applet->Initialize();
- applet->Execute();
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void RequestExit(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- ASSERT(applet != nullptr);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(applet->RequestExit());
- }
- void PushInData(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::RequestParser rp{ctx};
- applet->GetBroker().PushNormalDataFromGame(rp.PopIpcInterface<IStorage>().lock());
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void PopOutData(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- auto storage = applet->GetBroker().PopNormalDataToGame();
- if (storage == nullptr) {
- LOG_DEBUG(Service_AM,
- "storage is a nullptr. There is no data in the current normal channel");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(AM::ResultNoDataInChannel);
- return;
- }
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<IStorage>(std::move(storage));
- }
- void PushInteractiveInData(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::RequestParser rp{ctx};
- applet->GetBroker().PushInteractiveDataFromGame(rp.PopIpcInterface<IStorage>().lock());
- ASSERT(applet->IsInitialized());
- applet->ExecuteInteractive();
- applet->Execute();
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void PopInteractiveOutData(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- auto storage = applet->GetBroker().PopInteractiveDataToGame();
- if (storage == nullptr) {
- LOG_DEBUG(Service_AM,
- "storage is a nullptr. There is no data in the current interactive channel");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(AM::ResultNoDataInChannel);
- return;
- }
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<IStorage>(std::move(storage));
- }
- void GetPopOutDataEvent(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(applet->GetBroker().GetNormalDataEvent());
- }
- void GetPopInteractiveOutDataEvent(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(applet->GetBroker().GetInteractiveDataEvent());
- }
- void GetIndirectLayerConsumerHandle(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- // We require a non-zero handle to be valid. Using 0xdeadbeef allows us to trace if this is
- // actually used anywhere
- constexpr u64 handle = 0xdeadbeef;
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push(handle);
- }
- std::shared_ptr<Applets::Applet> applet;
- };
- IStorageAccessor::IStorageAccessor(Core::System& system_, IStorage& backing_)
- : ServiceFramework{system_, "IStorageAccessor"}, backing{backing_} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, &IStorageAccessor::GetSize, "GetSize"},
- {10, &IStorageAccessor::Write, "Write"},
- {11, &IStorageAccessor::Read, "Read"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IStorageAccessor::~IStorageAccessor() = default;
- void IStorageAccessor::GetSize(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push(static_cast<u64>(backing.GetSize()));
- }
- void IStorageAccessor::Write(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const u64 offset{rp.Pop<u64>()};
- const auto data{ctx.ReadBuffer()};
- const std::size_t size{std::min<u64>(data.size(), backing.GetSize() - offset)};
- LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
- if (offset > backing.GetSize()) {
- LOG_ERROR(Service_AM,
- "offset is out of bounds, backing_buffer_sz={}, data_size={}, offset={}",
- backing.GetSize(), size, offset);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(AM::ResultInvalidOffset);
- return;
- }
- std::memcpy(backing.GetData().data() + offset, data.data(), size);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IStorageAccessor::Read(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const u64 offset{rp.Pop<u64>()};
- const std::size_t size{std::min<u64>(ctx.GetWriteBufferSize(), backing.GetSize() - offset)};
- LOG_DEBUG(Service_AM, "called, offset={}, size={}", offset, size);
- if (offset > backing.GetSize()) {
- LOG_ERROR(Service_AM, "offset is out of bounds, backing_buffer_sz={}, size={}, offset={}",
- backing.GetSize(), size, offset);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(AM::ResultInvalidOffset);
- return;
- }
- ctx.WriteBuffer(backing.GetData().data() + offset, size);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_)
- : ServiceFramework{system_, "ILibraryAppletCreator"} {
- static const FunctionInfo functions[] = {
- {0, &ILibraryAppletCreator::CreateLibraryApplet, "CreateLibraryApplet"},
- {1, nullptr, "TerminateAllLibraryApplets"},
- {2, nullptr, "AreAnyLibraryAppletsLeft"},
- {10, &ILibraryAppletCreator::CreateStorage, "CreateStorage"},
- {11, &ILibraryAppletCreator::CreateTransferMemoryStorage, "CreateTransferMemoryStorage"},
- {12, &ILibraryAppletCreator::CreateHandleStorage, "CreateHandleStorage"},
- };
- RegisterHandlers(functions);
- }
- ILibraryAppletCreator::~ILibraryAppletCreator() = default;
- void ILibraryAppletCreator::CreateLibraryApplet(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto applet_id = rp.PopRaw<Applets::AppletId>();
- const auto applet_mode = rp.PopRaw<Applets::LibraryAppletMode>();
- LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}", applet_id,
- applet_mode);
- const auto& applet_manager{system.GetAppletManager()};
- const auto applet = applet_manager.GetApplet(applet_id, applet_mode);
- if (applet == nullptr) {
- LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultUnknown);
- return;
- }
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<ILibraryAppletAccessor>(system, applet);
- }
- void ILibraryAppletCreator::CreateStorage(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const s64 size{rp.Pop<s64>()};
- LOG_DEBUG(Service_AM, "called, size={}", size);
- if (size <= 0) {
- LOG_ERROR(Service_AM, "size is less than or equal to 0");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultUnknown);
- return;
- }
- std::vector<u8> buffer(size);
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<IStorage>(system, std::move(buffer));
- }
- void ILibraryAppletCreator::CreateTransferMemoryStorage(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- struct Parameters {
- u8 permissions;
- s64 size;
- };
- const auto parameters{rp.PopRaw<Parameters>()};
- const auto handle{ctx.GetCopyHandle(0)};
- LOG_DEBUG(Service_AM, "called, permissions={}, size={}, handle={:08X}", parameters.permissions,
- parameters.size, handle);
- if (parameters.size <= 0) {
- LOG_ERROR(Service_AM, "size is less than or equal to 0");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultUnknown);
- return;
- }
- auto transfer_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(handle);
- if (transfer_mem.IsNull()) {
- LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultUnknown);
- return;
- }
- std::vector<u8> memory(transfer_mem->GetSize());
- ctx.GetMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(), memory.size());
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<IStorage>(system, std::move(memory));
- }
- void ILibraryAppletCreator::CreateHandleStorage(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const s64 size{rp.Pop<s64>()};
- const auto handle{ctx.GetCopyHandle(0)};
- LOG_DEBUG(Service_AM, "called, size={}, handle={:08X}", size, handle);
- if (size <= 0) {
- LOG_ERROR(Service_AM, "size is less than or equal to 0");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultUnknown);
- return;
- }
- auto transfer_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(handle);
- if (transfer_mem.IsNull()) {
- LOG_ERROR(Service_AM, "transfer_mem is a nullptr for handle={:08X}", handle);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultUnknown);
- return;
- }
- std::vector<u8> memory(transfer_mem->GetSize());
- ctx.GetMemory().ReadBlock(transfer_mem->GetSourceAddress(), memory.data(), memory.size());
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<IStorage>(system, std::move(memory));
- }
- ILibraryAppletSelfAccessor::ILibraryAppletSelfAccessor(Core::System& system_)
- : ServiceFramework{system_, "ILibraryAppletSelfAccessor"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, &ILibraryAppletSelfAccessor::PopInData, "PopInData"},
- {1, &ILibraryAppletSelfAccessor::PushOutData, "PushOutData"},
- {2, nullptr, "PopInteractiveInData"},
- {3, nullptr, "PushInteractiveOutData"},
- {5, nullptr, "GetPopInDataEvent"},
- {6, nullptr, "GetPopInteractiveInDataEvent"},
- {10, &ILibraryAppletSelfAccessor::ExitProcessAndReturn, "ExitProcessAndReturn"},
- {11, &ILibraryAppletSelfAccessor::GetLibraryAppletInfo, "GetLibraryAppletInfo"},
- {12, &ILibraryAppletSelfAccessor::GetMainAppletIdentityInfo, "GetMainAppletIdentityInfo"},
- {13, nullptr, "CanUseApplicationCore"},
- {14, &ILibraryAppletSelfAccessor::GetCallerAppletIdentityInfo, "GetCallerAppletIdentityInfo"},
- {15, nullptr, "GetMainAppletApplicationControlProperty"},
- {16, nullptr, "GetMainAppletStorageId"},
- {17, nullptr, "GetCallerAppletIdentityInfoStack"},
- {18, nullptr, "GetNextReturnDestinationAppletIdentityInfo"},
- {19, &ILibraryAppletSelfAccessor::GetDesirableKeyboardLayout, "GetDesirableKeyboardLayout"},
- {20, nullptr, "PopExtraStorage"},
- {25, nullptr, "GetPopExtraStorageEvent"},
- {30, nullptr, "UnpopInData"},
- {31, nullptr, "UnpopExtraStorage"},
- {40, nullptr, "GetIndirectLayerProducerHandle"},
- {50, nullptr, "ReportVisibleError"},
- {51, nullptr, "ReportVisibleErrorWithErrorContext"},
- {60, nullptr, "GetMainAppletApplicationDesiredLanguage"},
- {70, nullptr, "GetCurrentApplicationId"},
- {80, nullptr, "RequestExitToSelf"},
- {90, nullptr, "CreateApplicationAndPushAndRequestToLaunch"},
- {100, nullptr, "CreateGameMovieTrimmer"},
- {101, nullptr, "ReserveResourceForMovieOperation"},
- {102, nullptr, "UnreserveResourceForMovieOperation"},
- {110, &ILibraryAppletSelfAccessor::GetMainAppletAvailableUsers, "GetMainAppletAvailableUsers"},
- {120, nullptr, "GetLaunchStorageInfoForDebug"},
- {130, nullptr, "GetGpuErrorDetectedSystemEvent"},
- {140, nullptr, "SetApplicationMemoryReservation"},
- {150, &ILibraryAppletSelfAccessor::ShouldSetGpuTimeSliceManually, "ShouldSetGpuTimeSliceManually"},
- };
- // clang-format on
- RegisterHandlers(functions);
- switch (system.GetAppletManager().GetCurrentAppletId()) {
- case Applets::AppletId::Cabinet:
- PushInShowCabinetData();
- break;
- case Applets::AppletId::MiiEdit:
- PushInShowMiiEditData();
- break;
- case Applets::AppletId::PhotoViewer:
- PushInShowAlbum();
- break;
- case Applets::AppletId::SoftwareKeyboard:
- PushInShowSoftwareKeyboard();
- break;
- case Applets::AppletId::Controller:
- PushInShowController();
- break;
- default:
- break;
- }
- }
- ILibraryAppletSelfAccessor::~ILibraryAppletSelfAccessor() = default;
- void ILibraryAppletSelfAccessor::PopInData(HLERequestContext& ctx) {
- LOG_INFO(Service_AM, "called");
- if (queue_data.empty()) {
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultNoDataInChannel);
- return;
- }
- auto data = queue_data.front();
- queue_data.pop_front();
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<IStorage>(system, std::move(data));
- }
- void ILibraryAppletSelfAccessor::PushOutData(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ILibraryAppletSelfAccessor::ExitProcessAndReturn(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- system.Exit();
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void ILibraryAppletSelfAccessor::GetLibraryAppletInfo(HLERequestContext& ctx) {
- struct LibraryAppletInfo {
- Applets::AppletId applet_id;
- Applets::LibraryAppletMode library_applet_mode;
- };
- LOG_WARNING(Service_AM, "(STUBBED) called");
- const LibraryAppletInfo applet_info{
- .applet_id = system.GetAppletManager().GetCurrentAppletId(),
- .library_applet_mode = Applets::LibraryAppletMode::AllForeground,
- };
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.PushRaw(applet_info);
- }
- void ILibraryAppletSelfAccessor::GetMainAppletIdentityInfo(HLERequestContext& ctx) {
- struct AppletIdentityInfo {
- Applets::AppletId applet_id;
- INSERT_PADDING_BYTES(0x4);
- u64 application_id;
- };
- static_assert(sizeof(AppletIdentityInfo) == 0x10, "AppletIdentityInfo has incorrect size.");
- LOG_WARNING(Service_AM, "(STUBBED) called");
- const AppletIdentityInfo applet_info{
- .applet_id = Applets::AppletId::QLaunch,
- .application_id = 0x0100000000001000ull,
- };
- IPC::ResponseBuilder rb{ctx, 6};
- rb.Push(ResultSuccess);
- rb.PushRaw(applet_info);
- }
- void ILibraryAppletSelfAccessor::GetCallerAppletIdentityInfo(HLERequestContext& ctx) {
- struct AppletIdentityInfo {
- Applets::AppletId applet_id;
- INSERT_PADDING_BYTES(0x4);
- u64 application_id;
- };
- static_assert(sizeof(AppletIdentityInfo) == 0x10, "AppletIdentityInfo has incorrect size.");
- LOG_WARNING(Service_AM, "(STUBBED) called");
- const AppletIdentityInfo applet_info{
- .applet_id = Applets::AppletId::QLaunch,
- .application_id = 0x0100000000001000ull,
- };
- IPC::ResponseBuilder rb{ctx, 6};
- rb.Push(ResultSuccess);
- rb.PushRaw(applet_info);
- }
- void ILibraryAppletSelfAccessor::GetDesirableKeyboardLayout(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<u32>(0);
- }
- void ILibraryAppletSelfAccessor::GetMainAppletAvailableUsers(HLERequestContext& ctx) {
- const Service::Account::ProfileManager manager{};
- bool is_empty{true};
- s32 user_count{-1};
- LOG_INFO(Service_AM, "called");
- if (manager.GetUserCount() > 0) {
- is_empty = false;
- user_count = static_cast<s32>(manager.GetUserCount());
- ctx.WriteBuffer(manager.GetAllUsers());
- }
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push<u8>(is_empty);
- rb.Push(user_count);
- }
- void ILibraryAppletSelfAccessor::ShouldSetGpuTimeSliceManually(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- rb.Push<u8>(0);
- }
- void ILibraryAppletSelfAccessor::PushInShowAlbum() {
- const Applets::CommonArguments arguments{
- .arguments_version = Applets::CommonArgumentVersion::Version3,
- .size = Applets::CommonArgumentSize::Version3,
- .library_version = 1,
- .theme_color = Applets::ThemeColor::BasicBlack,
- .play_startup_sound = true,
- .system_tick = system.CoreTiming().GetClockTicks(),
- };
- std::vector<u8> argument_data(sizeof(arguments));
- std::vector<u8> settings_data{2};
- std::memcpy(argument_data.data(), &arguments, sizeof(arguments));
- queue_data.emplace_back(std::move(argument_data));
- queue_data.emplace_back(std::move(settings_data));
- }
- void ILibraryAppletSelfAccessor::PushInShowController() {
- const Applets::CommonArguments common_args = {
- .arguments_version = Applets::CommonArgumentVersion::Version3,
- .size = Applets::CommonArgumentSize::Version3,
- .library_version = static_cast<u32>(Applets::ControllerAppletVersion::Version8),
- .theme_color = Applets::ThemeColor::BasicBlack,
- .play_startup_sound = true,
- .system_tick = system.CoreTiming().GetClockTicks(),
- };
- Applets::ControllerSupportArgNew user_args = {
- .header = {.player_count_min = 1,
- .player_count_max = 4,
- .enable_take_over_connection = true,
- .enable_left_justify = false,
- .enable_permit_joy_dual = true,
- .enable_single_mode = false,
- .enable_identification_color = false},
- .identification_colors = {},
- .enable_explain_text = false,
- .explain_text = {},
- };
- Applets::ControllerSupportArgPrivate private_args = {
- .arg_private_size = sizeof(Applets::ControllerSupportArgPrivate),
- .arg_size = sizeof(Applets::ControllerSupportArgNew),
- .is_home_menu = true,
- .flag_1 = true,
- .mode = Applets::ControllerSupportMode::ShowControllerSupport,
- .caller = Applets::ControllerSupportCaller::
- Application, // switchbrew: Always zero except with
- // ShowControllerFirmwareUpdateForSystem/ShowControllerKeyRemappingForSystem,
- // which sets this to the input param
- .style_set = Core::HID::NpadStyleSet::None,
- .joy_hold_type = 0,
- };
- std::vector<u8> common_args_data(sizeof(common_args));
- std::vector<u8> private_args_data(sizeof(private_args));
- std::vector<u8> user_args_data(sizeof(user_args));
- std::memcpy(common_args_data.data(), &common_args, sizeof(common_args));
- std::memcpy(private_args_data.data(), &private_args, sizeof(private_args));
- std::memcpy(user_args_data.data(), &user_args, sizeof(user_args));
- queue_data.emplace_back(std::move(common_args_data));
- queue_data.emplace_back(std::move(private_args_data));
- queue_data.emplace_back(std::move(user_args_data));
- }
- void ILibraryAppletSelfAccessor::PushInShowCabinetData() {
- const Applets::CommonArguments arguments{
- .arguments_version = Applets::CommonArgumentVersion::Version3,
- .size = Applets::CommonArgumentSize::Version3,
- .library_version = static_cast<u32>(Applets::CabinetAppletVersion::Version1),
- .theme_color = Applets::ThemeColor::BasicBlack,
- .play_startup_sound = true,
- .system_tick = system.CoreTiming().GetClockTicks(),
- };
- const Applets::StartParamForAmiiboSettings amiibo_settings{
- .param_1 = 0,
- .applet_mode = system.GetAppletManager().GetCabinetMode(),
- .flags = Applets::CabinetFlags::None,
- .amiibo_settings_1 = 0,
- .device_handle = 0,
- .tag_info{},
- .register_info{},
- .amiibo_settings_3{},
- };
- std::vector<u8> argument_data(sizeof(arguments));
- std::vector<u8> settings_data(sizeof(amiibo_settings));
- std::memcpy(argument_data.data(), &arguments, sizeof(arguments));
- std::memcpy(settings_data.data(), &amiibo_settings, sizeof(amiibo_settings));
- queue_data.emplace_back(std::move(argument_data));
- queue_data.emplace_back(std::move(settings_data));
- }
- void ILibraryAppletSelfAccessor::PushInShowMiiEditData() {
- struct MiiEditV3 {
- Applets::MiiEditAppletInputCommon common;
- Applets::MiiEditAppletInputV3 input;
- };
- static_assert(sizeof(MiiEditV3) == 0x100, "MiiEditV3 has incorrect size.");
- MiiEditV3 mii_arguments{
- .common =
- {
- .version = Applets::MiiEditAppletVersion::Version3,
- .applet_mode = Applets::MiiEditAppletMode::ShowMiiEdit,
- },
- .input{},
- };
- std::vector<u8> argument_data(sizeof(mii_arguments));
- std::memcpy(argument_data.data(), &mii_arguments, sizeof(mii_arguments));
- queue_data.emplace_back(std::move(argument_data));
- }
- void ILibraryAppletSelfAccessor::PushInShowSoftwareKeyboard() {
- const Applets::CommonArguments arguments{
- .arguments_version = Applets::CommonArgumentVersion::Version3,
- .size = Applets::CommonArgumentSize::Version3,
- .library_version = static_cast<u32>(Applets::SwkbdAppletVersion::Version524301),
- .theme_color = Applets::ThemeColor::BasicBlack,
- .play_startup_sound = true,
- .system_tick = system.CoreTiming().GetClockTicks(),
- };
- std::vector<char16_t> initial_string(0);
- const Applets::SwkbdConfigCommon swkbd_config{
- .type = Applets::SwkbdType::Qwerty,
- .ok_text{},
- .left_optional_symbol_key{},
- .right_optional_symbol_key{},
- .use_prediction = false,
- .key_disable_flags{},
- .initial_cursor_position = Applets::SwkbdInitialCursorPosition::Start,
- .header_text{},
- .sub_text{},
- .guide_text{},
- .max_text_length = 500,
- .min_text_length = 0,
- .password_mode = Applets::SwkbdPasswordMode::Disabled,
- .text_draw_type = Applets::SwkbdTextDrawType::Box,
- .enable_return_button = true,
- .use_utf8 = false,
- .use_blur_background = true,
- .initial_string_offset{},
- .initial_string_length = static_cast<u32>(initial_string.size()),
- .user_dictionary_offset{},
- .user_dictionary_entries{},
- .use_text_check = false,
- };
- Applets::SwkbdConfigNew swkbd_config_new{};
- std::vector<u8> argument_data(sizeof(arguments));
- std::vector<u8> swkbd_data(sizeof(swkbd_config) + sizeof(swkbd_config_new));
- std::vector<u8> work_buffer(swkbd_config.initial_string_length * sizeof(char16_t));
- std::memcpy(argument_data.data(), &arguments, sizeof(arguments));
- std::memcpy(swkbd_data.data(), &swkbd_config, sizeof(swkbd_config));
- std::memcpy(swkbd_data.data() + sizeof(swkbd_config), &swkbd_config_new,
- sizeof(Applets::SwkbdConfigNew));
- std::memcpy(work_buffer.data(), initial_string.data(),
- swkbd_config.initial_string_length * sizeof(char16_t));
- queue_data.emplace_back(std::move(argument_data));
- queue_data.emplace_back(std::move(swkbd_data));
- queue_data.emplace_back(std::move(work_buffer));
- }
- IAppletCommonFunctions::IAppletCommonFunctions(Core::System& system_)
- : ServiceFramework{system_, "IAppletCommonFunctions"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, nullptr, "SetTerminateResult"},
- {10, nullptr, "ReadThemeStorage"},
- {11, nullptr, "WriteThemeStorage"},
- {20, nullptr, "PushToAppletBoundChannel"},
- {21, nullptr, "TryPopFromAppletBoundChannel"},
- {40, nullptr, "GetDisplayLogicalResolution"},
- {42, nullptr, "SetDisplayMagnification"},
- {50, nullptr, "SetHomeButtonDoubleClickEnabled"},
- {51, nullptr, "GetHomeButtonDoubleClickEnabled"},
- {52, nullptr, "IsHomeButtonShortPressedBlocked"},
- {60, nullptr, "IsVrModeCurtainRequired"},
- {61, nullptr, "IsSleepRequiredByHighTemperature"},
- {62, nullptr, "IsSleepRequiredByLowBattery"},
- {70, &IAppletCommonFunctions::SetCpuBoostRequestPriority, "SetCpuBoostRequestPriority"},
- {80, nullptr, "SetHandlingCaptureButtonShortPressedMessageEnabledForApplet"},
- {81, nullptr, "SetHandlingCaptureButtonLongPressedMessageEnabledForApplet"},
- {90, nullptr, "OpenNamedChannelAsParent"},
- {91, nullptr, "OpenNamedChannelAsChild"},
- {100, nullptr, "SetApplicationCoreUsageMode"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IAppletCommonFunctions::~IAppletCommonFunctions() = default;
- void IAppletCommonFunctions::SetCpuBoostRequestPriority(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- IApplicationFunctions::IApplicationFunctions(Core::System& system_)
- : ServiceFramework{system_, "IApplicationFunctions"}, service_context{system,
- "IApplicationFunctions"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
- {10, nullptr, "CreateApplicationAndPushAndRequestToStart"},
- {11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"},
- {12, nullptr, "CreateApplicationAndRequestToStart"},
- {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest, "CreateApplicationAndRequestToStartForQuest"},
- {14, nullptr, "CreateApplicationWithAttributeAndPushAndRequestToStartForQuest"},
- {15, nullptr, "CreateApplicationWithAttributeAndRequestToStartForQuest"},
- {20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"},
- {21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"},
- {22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"},
- {23, &IApplicationFunctions::GetDisplayVersion, "GetDisplayVersion"},
- {24, nullptr, "GetLaunchStorageInfoForDebug"},
- {25, &IApplicationFunctions::ExtendSaveData, "ExtendSaveData"},
- {26, &IApplicationFunctions::GetSaveDataSize, "GetSaveDataSize"},
- {27, &IApplicationFunctions::CreateCacheStorage, "CreateCacheStorage"},
- {28, &IApplicationFunctions::GetSaveDataSizeMax, "GetSaveDataSizeMax"},
- {29, nullptr, "GetCacheStorageMax"},
- {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed, "BeginBlockingHomeButtonShortAndLongPressed"},
- {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed, "EndBlockingHomeButtonShortAndLongPressed"},
- {32, &IApplicationFunctions::BeginBlockingHomeButton, "BeginBlockingHomeButton"},
- {33, &IApplicationFunctions::EndBlockingHomeButton, "EndBlockingHomeButton"},
- {34, nullptr, "SelectApplicationLicense"},
- {35, nullptr, "GetDeviceSaveDataSizeMax"},
- {36, nullptr, "GetLimitedApplicationLicense"},
- {37, nullptr, "GetLimitedApplicationLicenseUpgradableEvent"},
- {40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"},
- {50, &IApplicationFunctions::GetPseudoDeviceId, "GetPseudoDeviceId"},
- {60, nullptr, "SetMediaPlaybackStateForApplication"},
- {65, &IApplicationFunctions::IsGamePlayRecordingSupported, "IsGamePlayRecordingSupported"},
- {66, &IApplicationFunctions::InitializeGamePlayRecording, "InitializeGamePlayRecording"},
- {67, &IApplicationFunctions::SetGamePlayRecordingState, "SetGamePlayRecordingState"},
- {68, nullptr, "RequestFlushGamePlayingMovieForDebug"},
- {70, nullptr, "RequestToShutdown"},
- {71, nullptr, "RequestToReboot"},
- {72, nullptr, "RequestToSleep"},
- {80, nullptr, "ExitAndRequestToShowThanksMessage"},
- {90, &IApplicationFunctions::EnableApplicationCrashReport, "EnableApplicationCrashReport"},
- {100, &IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer, "InitializeApplicationCopyrightFrameBuffer"},
- {101, &IApplicationFunctions::SetApplicationCopyrightImage, "SetApplicationCopyrightImage"},
- {102, &IApplicationFunctions::SetApplicationCopyrightVisibility, "SetApplicationCopyrightVisibility"},
- {110, &IApplicationFunctions::QueryApplicationPlayStatistics, "QueryApplicationPlayStatistics"},
- {111, &IApplicationFunctions::QueryApplicationPlayStatisticsByUid, "QueryApplicationPlayStatisticsByUid"},
- {120, &IApplicationFunctions::ExecuteProgram, "ExecuteProgram"},
- {121, &IApplicationFunctions::ClearUserChannel, "ClearUserChannel"},
- {122, &IApplicationFunctions::UnpopToUserChannel, "UnpopToUserChannel"},
- {123, &IApplicationFunctions::GetPreviousProgramIndex, "GetPreviousProgramIndex"},
- {124, nullptr, "EnableApplicationAllThreadDumpOnCrash"},
- {130, &IApplicationFunctions::GetGpuErrorDetectedSystemEvent, "GetGpuErrorDetectedSystemEvent"},
- {131, nullptr, "SetDelayTimeToAbortOnGpuError"},
- {140, &IApplicationFunctions::GetFriendInvitationStorageChannelEvent, "GetFriendInvitationStorageChannelEvent"},
- {141, &IApplicationFunctions::TryPopFromFriendInvitationStorageChannel, "TryPopFromFriendInvitationStorageChannel"},
- {150, &IApplicationFunctions::GetNotificationStorageChannelEvent, "GetNotificationStorageChannelEvent"},
- {151, nullptr, "TryPopFromNotificationStorageChannel"},
- {160, &IApplicationFunctions::GetHealthWarningDisappearedSystemEvent, "GetHealthWarningDisappearedSystemEvent"},
- {170, nullptr, "SetHdcpAuthenticationActivated"},
- {180, nullptr, "GetLaunchRequiredVersion"},
- {181, nullptr, "UpgradeLaunchRequiredVersion"},
- {190, nullptr, "SendServerMaintenanceOverlayNotification"},
- {200, nullptr, "GetLastApplicationExitReason"},
- {500, nullptr, "StartContinuousRecordingFlushForDebug"},
- {1000, nullptr, "CreateMovieMaker"},
- {1001, &IApplicationFunctions::PrepareForJit, "PrepareForJit"},
- };
- // clang-format on
- RegisterHandlers(functions);
- gpu_error_detected_event =
- service_context.CreateEvent("IApplicationFunctions:GpuErrorDetectedSystemEvent");
- friend_invitation_storage_channel_event =
- service_context.CreateEvent("IApplicationFunctions:FriendInvitationStorageChannelEvent");
- notification_storage_channel_event =
- service_context.CreateEvent("IApplicationFunctions:NotificationStorageChannelEvent");
- health_warning_disappeared_system_event =
- service_context.CreateEvent("IApplicationFunctions:HealthWarningDisappearedSystemEvent");
- }
- IApplicationFunctions::~IApplicationFunctions() {
- service_context.CloseEvent(gpu_error_detected_event);
- service_context.CloseEvent(friend_invitation_storage_channel_event);
- service_context.CloseEvent(notification_storage_channel_event);
- service_context.CloseEvent(health_warning_disappeared_system_event);
- }
- void IApplicationFunctions::EnableApplicationCrashReport(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::SetApplicationCopyrightImage(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::SetApplicationCopyrightVisibility(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto is_visible = rp.Pop<bool>();
- LOG_WARNING(Service_AM, "(STUBBED) called, is_visible={}", is_visible);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::BeginBlockingHomeButton(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::EndBlockingHomeButton(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::PopLaunchParameter(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const auto kind = rp.PopEnum<LaunchParameterKind>();
- LOG_INFO(Service_AM, "called, kind={:08X}", kind);
- if (kind == LaunchParameterKind::UserChannel) {
- auto channel = system.GetUserChannel();
- if (channel.empty()) {
- LOG_ERROR(Service_AM, "Attempted to load launch parameter but none was found!");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(AM::ResultNoDataInChannel);
- return;
- }
- auto data = channel.back();
- channel.pop_back();
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<IStorage>(system, std::move(data));
- } else if (kind == LaunchParameterKind::AccountPreselectedUser &&
- !launch_popped_account_preselect) {
- // TODO: Verify this is hw-accurate
- LaunchParameterAccountPreselectedUser params{};
- params.magic = LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC;
- params.is_account_selected = 1;
- Account::ProfileManager profile_manager{};
- const auto uuid = profile_manager.GetUser(static_cast<s32>(Settings::values.current_user));
- ASSERT(uuid.has_value() && uuid->IsValid());
- params.current_user = *uuid;
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- std::vector<u8> buffer(sizeof(LaunchParameterAccountPreselectedUser));
- std::memcpy(buffer.data(), ¶ms, buffer.size());
- rb.PushIpcInterface<IStorage>(system, std::move(buffer));
- launch_popped_account_preselect = true;
- } else {
- LOG_ERROR(Service_AM, "Unknown launch parameter kind.");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(AM::ResultNoDataInChannel);
- }
- }
- void IApplicationFunctions::CreateApplicationAndRequestToStartForQuest(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::EnsureSaveData(HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- u128 user_id = rp.PopRaw<u128>();
- LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]);
- FileSys::SaveDataAttribute attribute{};
- attribute.title_id = system.GetApplicationProcessProgramID();
- attribute.user_id = user_id;
- attribute.type = FileSys::SaveDataType::SaveData;
- FileSys::VirtualDir save_data{};
- const auto res = system.GetFileSystemController().OpenSaveDataController()->CreateSaveData(
- &save_data, FileSys::SaveDataSpaceId::NandUser, attribute);
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(res);
- rb.Push<u64>(0);
- }
- void IApplicationFunctions::SetTerminateResult(HLERequestContext& ctx) {
- // Takes an input u32 Result, no output.
- // For example, in some cases official apps use this with error 0x2A2 then
- // uses svcBreak.
- IPC::RequestParser rp{ctx};
- u32 result = rp.Pop<u32>();
- LOG_WARNING(Service_AM, "(STUBBED) called, result=0x{:08X}", result);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::GetDisplayVersion(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- std::array<u8, 0x10> version_string{};
- const auto res = [this] {
- const auto title_id = system.GetApplicationProcessProgramID();
- const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
- system.GetContentProvider()};
- auto metadata = pm.GetControlMetadata();
- if (metadata.first != nullptr) {
- return metadata;
- }
- const FileSys::PatchManager pm_update{FileSys::GetUpdateTitleID(title_id),
- system.GetFileSystemController(),
- system.GetContentProvider()};
- return pm_update.GetControlMetadata();
- }();
- if (res.first != nullptr) {
- const auto& version = res.first->GetVersionString();
- std::copy(version.begin(), version.end(), version_string.begin());
- } else {
- static constexpr char default_version[]{"1.0.0"};
- std::memcpy(version_string.data(), default_version, sizeof(default_version));
- }
- IPC::ResponseBuilder rb{ctx, 6};
- rb.Push(ResultSuccess);
- rb.PushRaw(version_string);
- }
- void IApplicationFunctions::GetDesiredLanguage(HLERequestContext& ctx) {
- // TODO(bunnei): This should be configurable
- LOG_DEBUG(Service_AM, "called");
- // Get supported languages from NACP, if possible
- // Default to 0 (all languages supported)
- u32 supported_languages = 0;
- const auto res = [this] {
- const auto title_id = system.GetApplicationProcessProgramID();
- const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
- system.GetContentProvider()};
- auto metadata = pm.GetControlMetadata();
- if (metadata.first != nullptr) {
- return metadata;
- }
- const FileSys::PatchManager pm_update{FileSys::GetUpdateTitleID(title_id),
- system.GetFileSystemController(),
- system.GetContentProvider()};
- return pm_update.GetControlMetadata();
- }();
- if (res.first != nullptr) {
- supported_languages = res.first->GetSupportedLanguages();
- }
- // Call IApplicationManagerInterface implementation.
- auto& service_manager = system.ServiceManager();
- auto ns_am2 = service_manager.GetService<NS::NS>("ns:am2");
- auto app_man = ns_am2->GetApplicationManagerInterface();
- // Get desired application language
- u8 desired_language{};
- const auto res_lang =
- app_man->GetApplicationDesiredLanguage(&desired_language, supported_languages);
- if (res_lang != ResultSuccess) {
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(res_lang);
- return;
- }
- // Convert to settings language code.
- u64 language_code{};
- const auto res_code =
- app_man->ConvertApplicationLanguageToLanguageCode(&language_code, desired_language);
- if (res_code != ResultSuccess) {
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(res_code);
- return;
- }
- LOG_DEBUG(Service_AM, "got desired_language={:016X}", language_code);
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- rb.Push(language_code);
- }
- void IApplicationFunctions::IsGamePlayRecordingSupported(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- constexpr bool gameplay_recording_supported = false;
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push(gameplay_recording_supported);
- }
- void IApplicationFunctions::InitializeGamePlayRecording(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::SetGamePlayRecordingState(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::NotifyRunning(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<u8>(0); // Unknown, seems to be ignored by official processes
- }
- void IApplicationFunctions::GetPseudoDeviceId(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 6};
- rb.Push(ResultSuccess);
- // Returns a 128-bit UUID
- rb.Push<u64>(0);
- rb.Push<u64>(0);
- }
- void IApplicationFunctions::ExtendSaveData(HLERequestContext& ctx) {
- struct Parameters {
- FileSys::SaveDataType type;
- u128 user_id;
- u64 new_normal_size;
- u64 new_journal_size;
- };
- static_assert(sizeof(Parameters) == 40);
- IPC::RequestParser rp{ctx};
- const auto [type, user_id, new_normal_size, new_journal_size] = rp.PopRaw<Parameters>();
- LOG_DEBUG(Service_AM,
- "called with type={:02X}, user_id={:016X}{:016X}, new_normal={:016X}, "
- "new_journal={:016X}",
- static_cast<u8>(type), user_id[1], user_id[0], new_normal_size, new_journal_size);
- system.GetFileSystemController().OpenSaveDataController()->WriteSaveDataSize(
- type, system.GetApplicationProcessProgramID(), user_id,
- {new_normal_size, new_journal_size});
- IPC::ResponseBuilder rb{ctx, 4};
- rb.Push(ResultSuccess);
- // The following value is used upon failure to help the system recover.
- // Since we always succeed, this should be 0.
- rb.Push<u64>(0);
- }
- void IApplicationFunctions::GetSaveDataSize(HLERequestContext& ctx) {
- struct Parameters {
- FileSys::SaveDataType type;
- u128 user_id;
- };
- static_assert(sizeof(Parameters) == 24);
- IPC::RequestParser rp{ctx};
- const auto [type, user_id] = rp.PopRaw<Parameters>();
- LOG_DEBUG(Service_AM, "called with type={:02X}, user_id={:016X}{:016X}", type, user_id[1],
- user_id[0]);
- const auto size = system.GetFileSystemController().OpenSaveDataController()->ReadSaveDataSize(
- type, system.GetApplicationProcessProgramID(), user_id);
- IPC::ResponseBuilder rb{ctx, 6};
- rb.Push(ResultSuccess);
- rb.Push(size.normal);
- rb.Push(size.journal);
- }
- void IApplicationFunctions::CreateCacheStorage(HLERequestContext& ctx) {
- struct InputParameters {
- u16 index;
- s64 size;
- s64 journal_size;
- };
- static_assert(sizeof(InputParameters) == 24);
- struct OutputParameters {
- u32 storage_target;
- u64 required_size;
- };
- static_assert(sizeof(OutputParameters) == 16);
- IPC::RequestParser rp{ctx};
- const auto params = rp.PopRaw<InputParameters>();
- LOG_WARNING(Service_AM, "(STUBBED) called with index={}, size={:#x}, journal_size={:#x}",
- params.index, params.size, params.journal_size);
- const OutputParameters resp{
- .storage_target = 1,
- .required_size = 0,
- };
- IPC::ResponseBuilder rb{ctx, 6};
- rb.Push(ResultSuccess);
- rb.PushRaw(resp);
- }
- void IApplicationFunctions::GetSaveDataSizeMax(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- constexpr u64 size_max_normal = 0xFFFFFFF;
- constexpr u64 size_max_journal = 0xFFFFFFF;
- IPC::ResponseBuilder rb{ctx, 6};
- rb.Push(ResultSuccess);
- rb.Push(size_max_normal);
- rb.Push(size_max_journal);
- }
- void IApplicationFunctions::QueryApplicationPlayStatistics(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<u32>(0);
- }
- void IApplicationFunctions::QueryApplicationPlayStatisticsByUid(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<u32>(0);
- }
- void IApplicationFunctions::ExecuteProgram(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::RequestParser rp{ctx};
- [[maybe_unused]] const auto unk_1 = rp.Pop<u32>();
- [[maybe_unused]] const auto unk_2 = rp.Pop<u32>();
- const auto program_index = rp.Pop<u64>();
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- system.ExecuteProgram(program_index);
- }
- void IApplicationFunctions::ClearUserChannel(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- system.GetUserChannel().clear();
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::UnpopToUserChannel(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::RequestParser rp{ctx};
- const auto storage = rp.PopIpcInterface<IStorage>().lock();
- if (storage) {
- system.GetUserChannel().push_back(storage->GetData());
- }
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IApplicationFunctions::GetPreviousProgramIndex(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.Push<s32>(previous_program_index);
- }
- void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(gpu_error_detected_event->GetReadableEvent());
- }
- void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(friend_invitation_storage_channel_event->GetReadableEvent());
- }
- void IApplicationFunctions::TryPopFromFriendInvitationStorageChannel(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(AM::ResultNoDataInChannel);
- }
- void IApplicationFunctions::GetNotificationStorageChannelEvent(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(notification_storage_channel_event->GetReadableEvent());
- }
- void IApplicationFunctions::GetHealthWarningDisappearedSystemEvent(HLERequestContext& ctx) {
- LOG_DEBUG(Service_AM, "called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(health_warning_disappeared_system_event->GetReadableEvent());
- }
- void IApplicationFunctions::PrepareForJit(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) {
- auto message_queue = std::make_shared<AppletMessageQueue>(system);
- auto server_manager = std::make_unique<ServerManager>(system);
- server_manager->RegisterNamedService(
- "appletAE", std::make_shared<AppletAE>(nvnflinger, message_queue, system));
- server_manager->RegisterNamedService(
- "appletOE", std::make_shared<AppletOE>(nvnflinger, message_queue, system));
- server_manager->RegisterNamedService("idle:sys", std::make_shared<IdleSys>(system));
- server_manager->RegisterNamedService("omm", std::make_shared<OMM>(system));
- server_manager->RegisterNamedService("spsm", std::make_shared<SPSM>(system));
- ServerManager::RunServer(std::move(server_manager));
- }
- IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_)
- : ServiceFramework{system_, "IHomeMenuFunctions"}, service_context{system,
- "IHomeMenuFunctions"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
- {11, nullptr, "LockForeground"},
- {12, nullptr, "UnlockForeground"},
- {20, nullptr, "PopFromGeneralChannel"},
- {21, &IHomeMenuFunctions::GetPopFromGeneralChannelEvent, "GetPopFromGeneralChannelEvent"},
- {30, nullptr, "GetHomeButtonWriterLockAccessor"},
- {31, nullptr, "GetWriterLockAccessorEx"},
- {40, nullptr, "IsSleepEnabled"},
- {41, nullptr, "IsRebootEnabled"},
- {50, nullptr, "LaunchSystemApplet"},
- {51, nullptr, "LaunchStarter"},
- {100, nullptr, "PopRequestLaunchApplicationForDebug"},
- {110, nullptr, "IsForceTerminateApplicationDisabledForDebug"},
- {200, nullptr, "LaunchDevMenu"},
- {1000, nullptr, "SetLastApplicationExitReason"},
- };
- // clang-format on
- RegisterHandlers(functions);
- pop_from_general_channel_event =
- service_context.CreateEvent("IHomeMenuFunctions:PopFromGeneralChannelEvent");
- }
- IHomeMenuFunctions::~IHomeMenuFunctions() {
- service_context.CloseEvent(pop_from_general_channel_event);
- }
- void IHomeMenuFunctions::RequestToGetForeground(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultSuccess);
- }
- void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 2, 1};
- rb.Push(ResultSuccess);
- rb.PushCopyObjects(pop_from_general_channel_event->GetReadableEvent());
- }
- IGlobalStateController::IGlobalStateController(Core::System& system_)
- : ServiceFramework{system_, "IGlobalStateController"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, nullptr, "RequestToEnterSleep"},
- {1, nullptr, "EnterSleep"},
- {2, nullptr, "StartSleepSequence"},
- {3, nullptr, "StartShutdownSequence"},
- {4, nullptr, "StartRebootSequence"},
- {9, nullptr, "IsAutoPowerDownRequested"},
- {10, nullptr, "LoadAndApplyIdlePolicySettings"},
- {11, nullptr, "NotifyCecSettingsChanged"},
- {12, nullptr, "SetDefaultHomeButtonLongPressTime"},
- {13, nullptr, "UpdateDefaultDisplayResolution"},
- {14, nullptr, "ShouldSleepOnBoot"},
- {15, nullptr, "GetHdcpAuthenticationFailedEvent"},
- {30, nullptr, "OpenCradleFirmwareUpdater"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IGlobalStateController::~IGlobalStateController() = default;
- IApplicationCreator::IApplicationCreator(Core::System& system_)
- : ServiceFramework{system_, "IApplicationCreator"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, nullptr, "CreateApplication"},
- {1, nullptr, "PopLaunchRequestedApplication"},
- {10, nullptr, "CreateSystemApplication"},
- {100, nullptr, "PopFloatingApplicationForDevelopment"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IApplicationCreator::~IApplicationCreator() = default;
- IProcessWindingController::IProcessWindingController(Core::System& system_)
- : ServiceFramework{system_, "IProcessWindingController"} {
- // clang-format off
- static const FunctionInfo functions[] = {
- {0, &IProcessWindingController::GetLaunchReason, "GetLaunchReason"},
- {11, &IProcessWindingController::OpenCallingLibraryApplet, "OpenCallingLibraryApplet"},
- {21, nullptr, "PushContext"},
- {22, nullptr, "PopContext"},
- {23, nullptr, "CancelWindingReservation"},
- {30, nullptr, "WindAndDoReserved"},
- {40, nullptr, "ReserveToStartAndWaitAndUnwindThis"},
- {41, nullptr, "ReserveToStartAndWait"},
- };
- // clang-format on
- RegisterHandlers(functions);
- }
- IProcessWindingController::~IProcessWindingController() = default;
- void IProcessWindingController::GetLaunchReason(HLERequestContext& ctx) {
- LOG_WARNING(Service_AM, "(STUBBED) called");
- struct AppletProcessLaunchReason {
- u8 flag;
- INSERT_PADDING_BYTES(3);
- };
- static_assert(sizeof(AppletProcessLaunchReason) == 0x4,
- "AppletProcessLaunchReason is an invalid size");
- AppletProcessLaunchReason reason{
- .flag = 0,
- };
- IPC::ResponseBuilder rb{ctx, 3};
- rb.Push(ResultSuccess);
- rb.PushRaw(reason);
- }
- void IProcessWindingController::OpenCallingLibraryApplet(HLERequestContext& ctx) {
- const auto applet_id = system.GetAppletManager().GetCurrentAppletId();
- const auto applet_mode = Applets::LibraryAppletMode::AllForeground;
- LOG_WARNING(Service_AM, "(STUBBED) called with applet_id={:08X}, applet_mode={:08X}", applet_id,
- applet_mode);
- const auto& applet_manager{system.GetAppletManager()};
- const auto applet = applet_manager.GetApplet(applet_id, applet_mode);
- if (applet == nullptr) {
- LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id);
- IPC::ResponseBuilder rb{ctx, 2};
- rb.Push(ResultUnknown);
- return;
- }
- IPC::ResponseBuilder rb{ctx, 2, 0, 1};
- rb.Push(ResultSuccess);
- rb.PushIpcInterface<ILibraryAppletAccessor>(system, applet);
- }
- } // namespace Service::AM
|