From 1f792cd92fc99b094d57241ed75d4350ce1b36c7 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 31 Oct 2019 22:53:42 -0400 Subject: [PATCH] Various improvements/fixes and improved docs. Added nvGetServiceSession. Return an actual error when the value for determing which service to init is invalid, for services which use *ServiceType/AppletType. Improved cleanup handling. Fixed inverted logic in the spl cleanup define. --- nx/include/switch/services/acc.h | 6 +-- nx/include/switch/services/bpc.h | 5 +++ nx/include/switch/services/bsd.h | 6 ++- nx/include/switch/services/caps.h | 1 - nx/include/switch/services/clkrst.h | 8 +++- nx/include/switch/services/csrng.h | 5 +++ nx/include/switch/services/friends.h | 2 +- nx/include/switch/services/fs.h | 63 ++++++++++++---------------- nx/include/switch/services/fsldr.h | 5 +++ nx/include/switch/services/fspr.h | 5 +++ nx/include/switch/services/gpio.h | 5 +++ nx/include/switch/services/i2c.h | 5 +++ nx/include/switch/services/ldr.h | 12 ++++++ nx/include/switch/services/lr.h | 5 +++ nx/include/switch/services/ncm.h | 7 +++- nx/include/switch/services/nfc.h | 2 +- nx/include/switch/services/nv.h | 6 +++ nx/include/switch/services/pcv.h | 5 +++ nx/include/switch/services/pdm.h | 5 +++ nx/include/switch/services/pm.h | 16 +++++++ nx/include/switch/services/psc.h | 5 +++ nx/include/switch/services/psm.h | 5 +++ nx/include/switch/services/ro.h | 15 +++++++ nx/include/switch/services/smm.h | 5 ++- nx/include/switch/services/spl.h | 30 +++++++++++++ nx/include/switch/services/spsm.h | 5 +++ nx/include/switch/services/usb.h | 2 - nx/include/switch/services/wlaninf.h | 5 +++ nx/source/services/acc.c | 2 +- nx/source/services/applet.c | 6 +-- nx/source/services/audout.c | 3 -- nx/source/services/audren.c | 4 -- nx/source/services/caps.c | 6 --- nx/source/services/fsldr.c | 4 +- nx/source/services/irs.c | 14 ++++--- nx/source/services/nfc.c | 2 +- nx/source/services/nifm.c | 2 +- nx/source/services/ns.c | 8 +--- nx/source/services/nv.c | 46 ++++++++------------ nx/source/services/spl.c | 4 +- nx/source/services/usbds.c | 9 +--- nx/source/services/usbhs.c | 1 - nx/source/services/vi.c | 2 +- 43 files changed, 233 insertions(+), 126 deletions(-) diff --git a/nx/include/switch/services/acc.h b/nx/include/switch/services/acc.h index 44ba3edd..b9213947 100644 --- a/nx/include/switch/services/acc.h +++ b/nx/include/switch/services/acc.h @@ -31,9 +31,9 @@ typedef struct { typedef struct { u32 unk_x0; ///< Unknown. u32 iconID; ///< Icon ID. 0 = Mii, the rest are character icon IDs. - u8 iconBackgroundColorID; ///< Profile icon background color ID - u8 unk_x9[0x7]; ///< Unknown. - u8 miiID[0x10]; ///< Some ID related to the Mii? All zeros when a character icon is used. + u8 iconBackgroundColorID; ///< Profile icon background color ID + u8 unk_x9[0x7]; ///< Unknown. + u8 miiID[0x10]; ///< Some ID related to the Mii? All zeros when a character icon is used. u8 unk_x20[0x60]; ///< Usually zeros? } AccountUserData; diff --git a/nx/include/switch/services/bpc.h b/nx/include/switch/services/bpc.h index c3b1ab08..a724dcdc 100644 --- a/nx/include/switch/services/bpc.h +++ b/nx/include/switch/services/bpc.h @@ -13,8 +13,13 @@ typedef enum { BpcSleepButtonState_Released = 1, } BpcSleepButtonState; +/// Initialize bpc. Result bpcInitialize(void); + +/// Exit bpc. void bpcExit(void); + +/// Gets the Service object for the actual bpc service session. Service* bpcGetServiceSession(void); Result bpcShutdownSystem(void); diff --git a/nx/include/switch/services/bsd.h b/nx/include/switch/services/bsd.h index e254ddd5..c8eb03ab 100644 --- a/nx/include/switch/services/bsd.h +++ b/nx/include/switch/services/bsd.h @@ -34,10 +34,14 @@ extern __thread int g_bsdErrno; ///< Last errno, per-thread /// Fetch the default configuration for bsdInitialize. const BsdInitConfig *bsdGetDefaultInitConfig(void); + /// Initialize the BSD service. Result bsdInitialize(const BsdInitConfig *config, u32 num_sessions, u32 service_type); -/// Deinitialize the BSD service. + +/// Exit the BSD service. void bsdExit(void); + +/// Gets the Service object for the actual BSD service session. Service* bsdGetServiceSession(void); /// Creates a socket. diff --git a/nx/include/switch/services/caps.h b/nx/include/switch/services/caps.h index 9ce6458b..bfffa09c 100644 --- a/nx/include/switch/services/caps.h +++ b/nx/include/switch/services/caps.h @@ -6,7 +6,6 @@ */ #pragma once #include "../types.h" -#include "../services/sm.h" #include "../services/acc.h" /// ImageOrientation diff --git a/nx/include/switch/services/clkrst.h b/nx/include/switch/services/clkrst.h index 5b059fdf..305f20f1 100644 --- a/nx/include/switch/services/clkrst.h +++ b/nx/include/switch/services/clkrst.h @@ -10,12 +10,16 @@ #include "../services/pcv.h" typedef struct { - Service s; + Service s; } ClkrstSession; -/// Only available on [8.0.0+]. +/// Initialize clkrst. Only available on [8.0.0+]. Result clkrstInitialize(void); + +/// Exit clkrst. void clkrstExit(void); + +/// Gets the Service object for the actual clkrst service session. Service* clkrstGetServiceSession(void); /// Opens a ClkrstSession for the requested PcvModuleId, unk is set to 3 in official sysmodules. diff --git a/nx/include/switch/services/csrng.h b/nx/include/switch/services/csrng.h index b938c81b..419710d7 100644 --- a/nx/include/switch/services/csrng.h +++ b/nx/include/switch/services/csrng.h @@ -8,8 +8,13 @@ #include "../types.h" #include "../sf/service.h" +/// Initialize csrng. Result csrngInitialize(void); + +/// Exit csrng. void csrngExit(void); + +/// Gets the Service object for the actual csrng service session. Service* csrngGetServiceSession(void); Result csrngGetRandomBytes(void *out, size_t out_size); diff --git a/nx/include/switch/services/friends.h b/nx/include/switch/services/friends.h index 0c0c7d81..be769ad9 100644 --- a/nx/include/switch/services/friends.h +++ b/nx/include/switch/services/friends.h @@ -6,7 +6,7 @@ */ #pragma once #include "../types.h" -#include "../services/sm.h" +#include "../sf/service.h" /// InAppScreenName typedef struct { diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 4386c422..c9062d52 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -24,36 +24,35 @@ typedef struct { } FsRightsId; typedef struct { - Service s; + Service s; } FsFileSystem; typedef struct { - Service s; + Service s; } FsFile; typedef struct { - Service s; + Service s; } FsDir; typedef struct { - Service s; + Service s; } FsStorage; typedef struct { - Service s; + Service s; } FsSaveDataInfoReader; typedef struct { - Service s; + Service s; } FsEventNotifier; typedef struct { - Service s; + Service s; } FsDeviceOperator; /// Directory entry. -typedef struct -{ +typedef struct { char name[FS_MAX_PATH]; ///< Entry name. u8 pad[3]; s8 type; ///< See FsDirEntryType. @@ -62,8 +61,7 @@ typedef struct } FsDirectoryEntry; /// Save Struct -typedef struct -{ +typedef struct { u64 program_id; ///< ProgramId of the savedata to access when accessing other programs' savedata via SaveData, otherwise FS_SAVEDATA_CURRENT_PROGRAMID. AccountUid uid; ///< \ref AccountUid for the user-specific savedata to access, otherwise 0 for common savedata. u64 saveID; ///< saveID, 0 for SaveData. @@ -101,8 +99,7 @@ typedef struct { u8 padding[0x1A]; ///< Uninitialized for SystemSaveData. } FsSaveCreate; -typedef struct -{ +typedef struct { u64 saveID_unk; u8 saveDataSpaceId; ///< See \ref FsSaveDataSpaceId. u8 saveDataType; ///< See \ref FsSaveDataType. @@ -116,8 +113,7 @@ typedef struct u8 unk_x3b[0x25]; ///< Unknown. Usually zeros? } FsSaveDataInfo; -typedef struct -{ +typedef struct { u64 created; ///< POSIX timestamp. u64 modified; ///< POSIX timestamp. u64 accessed; ///< POSIX timestamp. @@ -132,36 +128,31 @@ typedef enum { } FsDirEntryType; /// For use with fsFsOpenFile. -typedef enum -{ +typedef enum { FsOpenMode_Read = BIT(0), ///< Open for reading. FsOpenMode_Write = BIT(1), ///< Open for writing. FsOpenMode_Append = BIT(2), ///< Append file. } FsOpenMode; /// For use with fsFsCreateFile. -typedef enum -{ +typedef enum { FsCreateOption_BigFile = BIT(0), ///< Creates a ConcatenationFile (dir with archive bit) instead of file. } FsCreateOption; /// For use with fsFsOpenDirectory. -typedef enum -{ +typedef enum { FsDirOpenMode_ReadDirs = BIT(0), ///< Enable reading directory entries. FsDirOpenMode_ReadFiles = BIT(1), ///< Enable reading file entries. FsDirOpenMode_NoFileSize = BIT(31), ///< Causes result entries to not contain filesize information (always 0). } FsDirOpenMode; /// For use with fsFileRead. -typedef enum -{ +typedef enum { FsReadOption_None = 0, ///< No option. } FsReadOption; /// For use with fsFileWrite. -typedef enum -{ +typedef enum { FsWriteOption_None = 0, ///< No option. FsWriteOption_Flush = BIT(0), ///< Forces a flush after write. } FsWriteOption; @@ -176,21 +167,18 @@ typedef enum { FsStorageId_SdCard = 5, ///< SdCard } FsStorageId; -typedef enum -{ +typedef enum { FsContentStorageId_NandSystem = 0, FsContentStorageId_NandUser = 1, FsContentStorageId_SdCard = 2, } FsContentStorageId; -typedef enum -{ +typedef enum { FsCustomStorageId_NandUser = 0, FsCustomStorageId_SdCard = 1, } FsCustomStorageId; -typedef enum -{ +typedef enum { FsSaveDataSpaceId_NandSystem = 0, FsSaveDataSpaceId_NandUser = 1, FsSaveDataSpaceId_SdCard = 2, @@ -199,8 +187,7 @@ typedef enum FsSaveDataSpaceId_All = -1, ///< Pseudo value for fsOpenSaveDataInfoReader(). } FsSaveDataSpaceId; -typedef enum -{ +typedef enum { FsSaveDataType_SystemSaveData = 0, FsSaveDataType_SaveData = 1, FsSaveDataType_BcatDeliveryCacheStorage = 2, @@ -266,8 +253,7 @@ typedef enum { FsBisStorageId_SystemProperPartition = 33, } FsBisStorageId; -typedef enum -{ +typedef enum { FsFileSystemType_Logo = 2, FsFileSystemType_ContentControl = 3, FsFileSystemType_ContentManual = 4, @@ -276,8 +262,7 @@ typedef enum FsFileSystemType_ApplicationPackage = 7, } FsFileSystemType; -typedef enum -{ +typedef enum { FsFileSystemQueryType_SetArchiveBit = 0, } FsFileSystemQueryType; @@ -288,9 +273,13 @@ typedef enum { FsPriority_Background = 3, } FsPriority; +/// Initialize fsp-srv. Used automatically during app startup. Result fsInitialize(void); + +/// Exit fsp-srv. Used automatically during app exit. void fsExit(void); +/// Gets the Service object for the actual fsp-srv service session. Service* fsGetServiceSession(void); void fsSetPriority(FsPriority prio); diff --git a/nx/include/switch/services/fsldr.h b/nx/include/switch/services/fsldr.h index 3e4a8224..03ad7d0e 100644 --- a/nx/include/switch/services/fsldr.h +++ b/nx/include/switch/services/fsldr.h @@ -9,8 +9,13 @@ #include "../sf/service.h" #include "../services/fs.h" +/// Initialize fsp-ldr. Result fsldrInitialize(void); + +/// Exit fsp-ldr. void fsldrExit(void); + +/// Gets the Service object for the actual fsp-ldr service session. Service* fsldrGetServiceSession(void); Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out); diff --git a/nx/include/switch/services/fspr.h b/nx/include/switch/services/fspr.h index 52ee37f3..aa0f60d9 100644 --- a/nx/include/switch/services/fspr.h +++ b/nx/include/switch/services/fspr.h @@ -9,8 +9,13 @@ #include "../sf/service.h" #include "../services/fs.h" +/// Initialize fsp-pr. Result fsprInitialize(void); + +/// Exit fsp-pr. void fsprExit(void); + +/// Gets the Service object for the actual fsp-pr service session. Service* fsprGetServiceSession(void); Result fsprRegisterProgram(u64 pid, u64 tid, FsStorageId sid, const void *fs_access_header, size_t fah_size, const void *fs_access_control, size_t fac_size); diff --git a/nx/include/switch/services/gpio.h b/nx/include/switch/services/gpio.h index 8d3d6263..f6129e3b 100644 --- a/nx/include/switch/services/gpio.h +++ b/nx/include/switch/services/gpio.h @@ -28,8 +28,13 @@ typedef enum { GpioValue_High = 1, } GpioValue; +/// Initialize gpio. Result gpioInitialize(void); + +/// Exit gpio. void gpioExit(void); + +/// Gets the Service object for the actual gpio service session. Service* gpioGetServiceSession(void); Result gpioOpenSession(GpioPadSession *out, GpioPadName name); diff --git a/nx/include/switch/services/i2c.h b/nx/include/switch/services/i2c.h index 9f74465c..d5b5ad49 100644 --- a/nx/include/switch/services/i2c.h +++ b/nx/include/switch/services/i2c.h @@ -55,8 +55,13 @@ typedef enum { I2cTransactionOption_All = I2cTransactionOption_Start | I2cTransactionOption_Stop, } I2cTransactionOption; +/// Initialize i2c. Result i2cInitialize(void); + +/// Exit i2c. void i2cExit(void); + +/// Gets the Service object for the actual i2c service session. Service* i2cGetServiceSession(void); Result i2cOpenSession(I2cSession *out, I2cDevice dev); diff --git a/nx/include/switch/services/ldr.h b/nx/include/switch/services/ldr.h index 1f6420cc..2d098887 100644 --- a/nx/include/switch/services/ldr.h +++ b/nx/include/switch/services/ldr.h @@ -29,19 +29,31 @@ typedef struct { u64 size; } LoaderModuleInfo; +/// Initialize ldr:shel. Result ldrShellInitialize(void); + +/// Exit ldr:shel. void ldrShellExit(void); +/// Gets the Service object for the actual ldr:shel service session. Service* ldrShellGetServiceSession(void); +/// Initialize ldr:dmnt. Result ldrDmntInitialize(void); + +/// Exit ldr:dmnt. void ldrDmntExit(void); +/// Gets the Service object for the actual ldr:dmnt service session. Service* ldrDmntGetServiceSession(void); +/// Initialize ldr:pm. Result ldrPmInitialize(void); + +/// Exit ldr:pm. void ldrPmExit(void); +/// Gets the Service object for the actual ldr:pm service session. Service* ldrPmGetServiceSession(void); Result ldrShellSetProgramArguments(u64 program_id, const void *args, size_t args_size); diff --git a/nx/include/switch/services/lr.h b/nx/include/switch/services/lr.h index dac7f60a..41df94d2 100644 --- a/nx/include/switch/services/lr.h +++ b/nx/include/switch/services/lr.h @@ -17,8 +17,13 @@ typedef struct { Service s; } LrRegisteredLocationResolver; +/// Initialize lr. Result lrInitialize(void); + +/// Exit lr. void lrExit(void); + +/// Gets the Service object for the actual lr service session. Service* lrGetServiceSession(void); Result lrOpenLocationResolver(FsStorageId storage, LrLocationResolver* out); diff --git a/nx/include/switch/services/ncm.h b/nx/include/switch/services/ncm.h index be4b2d11..f8a43946 100644 --- a/nx/include/switch/services/ncm.h +++ b/nx/include/switch/services/ncm.h @@ -7,7 +7,7 @@ #pragma once #include "../types.h" #include "../services/fs.h" -#include "../services/sm.h" +#include "../sf/service.h" /// ContentStorage typedef struct { @@ -144,8 +144,13 @@ typedef struct { u8 pad[7]; } NcmProgramLocation; +/// Initialize ncm. Result ncmInitialize(void); + +/// Exit ncm. void ncmExit(void); + +/// Gets the Service object for the actual ncm service session. Service* ncmGetServiceSession(void); Result ncmCreateContentStorage(FsStorageId storage_id); diff --git a/nx/include/switch/services/nfc.h b/nx/include/switch/services/nfc.h index 8b9e95e7..b40f940a 100644 --- a/nx/include/switch/services/nfc.h +++ b/nx/include/switch/services/nfc.h @@ -168,7 +168,7 @@ void nfpExit(void); /// Initialize nfc:*. Result nfcInitialize(void); -/// Exit nfc:*.. +/// Exit nfc:*. void nfcExit(void); /// Gets the Service object for the actual nfp:* service session. diff --git a/nx/include/switch/services/nv.h b/nx/include/switch/services/nv.h index 056cb4d0..0a2d19b7 100644 --- a/nx/include/switch/services/nv.h +++ b/nx/include/switch/services/nv.h @@ -9,9 +9,15 @@ #include "../sf/service.h" #include "../kernel/event.h" +/// Initialize nvdrv*. Result nvInitialize(void); + +/// Exit nvdrv*. void nvExit(void); +/// Gets the Service object for the actual nvdrv* service session. +Service* nvGetServiceSession(void); + typedef enum { NvEventId_Gpu_SmException_BptIntReport=1, NvEventId_Gpu_SmException_BptPauseReport=2, diff --git a/nx/include/switch/services/pcv.h b/nx/include/switch/services/pcv.h index 09271d42..3887e9ba 100644 --- a/nx/include/switch/services/pcv.h +++ b/nx/include/switch/services/pcv.h @@ -191,8 +191,13 @@ typedef enum { PcvModuleId_EXTPERIPH2 = 0x40000057, } PcvModuleId; +/// Initialize pcv. Result pcvInitialize(void); + +/// Exit pcv. void pcvExit(void); + +/// Gets the Service object for the actual pcv service session. Service* pcvGetServiceSession(void); Result pcvGetModuleId(PcvModuleId *module_id, PcvModule module); diff --git a/nx/include/switch/services/pdm.h b/nx/include/switch/services/pdm.h index 5bdfc884..c60b7b5d 100644 --- a/nx/include/switch/services/pdm.h +++ b/nx/include/switch/services/pdm.h @@ -160,8 +160,13 @@ typedef struct { u64 totalLaunches; ///< Total times the application was launched. } PdmApplicationPlayStatistics; +/// Initialize pdm:qry. Result pdmqryInitialize(void); + +/// Exit pdm:qry. void pdmqryExit(void); + +/// Gets the Service object for the actual pdm:qry service session. Service* pdmqryGetServiceSession(void); /** diff --git a/nx/include/switch/services/pm.h b/nx/include/switch/services/pm.h index 87dc51b2..5ec03d4e 100644 --- a/nx/include/switch/services/pm.h +++ b/nx/include/switch/services/pm.h @@ -57,24 +57,40 @@ typedef enum { PmBootMode_SafeMode = 2, ///< SafeMode } PmBootMode; +/// Initialize pm:dmnt. Result pmdmntInitialize(void); + +/// Exit pm:dmnt. void pmdmntExit(void); +/// Gets the Service object for the actual pm:dmnt service session. Service* pmdmntGetServiceSession(void); +/// Initialize pm:info. Result pminfoInitialize(void); + +/// Exit pm:info. void pminfoExit(void); +/// Gets the Service object for the actual pm:info service session. Service* pminfoGetServiceSession(void); +/// Initialize pm:shell. Result pmshellInitialize(void); + +/// Exit pm:shell. void pmshellExit(void); +/// Gets the Service object for the actual pm:shell service session. Service* pmshellGetServiceSession(void); +/// Initialize pm:bm. Result pmbmInitialize(); + +/// Exit pm:bm. void pmbmExit(); +/// Gets the Service object for the actual pm:bm service session. Service* pmbmGetServiceSession(void); /** diff --git a/nx/include/switch/services/psc.h b/nx/include/switch/services/psc.h index 6b9ef70a..fadf5882 100644 --- a/nx/include/switch/services/psc.h +++ b/nx/include/switch/services/psc.h @@ -85,8 +85,13 @@ typedef struct { PscPmModuleId module_id; } PscPmModule; +/// Initialize psc:m. Result pscmInitialize(void); + +/// Exit psc:m. void pscmExit(void); + +/// Gets the Service object for the actual psc:m service session. Service* pscmGetServiceSession(void); Result pscmGetPmModule(PscPmModule *out, PscPmModuleId module_id, const u16 *dependencies, size_t dependency_count, bool autoclear); diff --git a/nx/include/switch/services/psm.h b/nx/include/switch/services/psm.h index 689dec66..d5607514 100644 --- a/nx/include/switch/services/psm.h +++ b/nx/include/switch/services/psm.h @@ -28,8 +28,13 @@ typedef struct { Event StateChangeEvent; ///< autoclear=false } PsmSession; +/// Initialize psm. Result psmInitialize(void); + +/// Exit psm. void psmExit(void); + +/// Gets the Service object for the actual psm service session. Service* psmGetServiceSession(void); Result psmGetBatteryChargePercentage(u32 *out); diff --git a/nx/include/switch/services/ro.h b/nx/include/switch/services/ro.h index 4d1cc1ae..231c95af 100644 --- a/nx/include/switch/services/ro.h +++ b/nx/include/switch/services/ro.h @@ -9,16 +9,31 @@ #include "../sf/service.h" #include "../services/ldr.h" +/// Initialize ldr:ro. Result ldrRoInitialize(void); + +/// Exit ldr:ro. void ldrRoExit(void); + +/// Gets the Service object for the actual ldr:ro service session. Service* ldrRoGetServiceSession(void); +/// Initialize ro:1. Only available with [7.0.0+]. Result ro1Initialize(void); + +/// Exit ro:1. void ro1Exit(void); + +/// Gets the Service object for the actual ro:1 service session. Service* ro1GetServiceSession(void); +/// Initialize ro:dmnt. Only available with [3.0.0+]. Result roDmntInitialize(void); + +/// Exit ro:dmnt. void roDmntExit(void); + +/// Gets the Service object for the actual ro:dmnt service session. Service* roDmntGetServiceSession(void); Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); diff --git a/nx/include/switch/services/smm.h b/nx/include/switch/services/smm.h index 3dd33a26..38980ccc 100644 --- a/nx/include/switch/services/smm.h +++ b/nx/include/switch/services/smm.h @@ -7,11 +7,14 @@ #pragma once #include "../types.h" #include "../sf/service.h" -#include "../services/fs.h" +/// Initialize sm:m. Result smManagerInitialize(void); + +/// Exit sm:m. void smManagerExit(void); +/// Gets the Service object for the actual sm:m service session. Service* smManagerGetServiceSession(void); Result smManagerRegisterProcess(u64 pid, const void *acid_sac, size_t acid_sac_size, const void *aci0_sac, size_t aci0_sac_size); diff --git a/nx/include/switch/services/spl.h b/nx/include/switch/services/spl.h index 8ed557c1..4057d75b 100644 --- a/nx/include/switch/services/spl.h +++ b/nx/include/switch/services/spl.h @@ -35,28 +35,58 @@ typedef enum { RsaKeyVersion_Extended = 1, } RsaKeyVersion; +/// Initialize 'spl:'. Result splInitialize(void); + +/// Exit 'spl:'. void splExit(void); + +/// Gets the Service object for the IGeneralInterface usable with spl*(). Service* splGetServiceSession(void); +/// Initialize spl:mig. On pre-4.0.0 this just calls \ref splInitialize. Result splCryptoInitialize(void); + +/// Exit spl:mig. On pre-4.0.0 this just calls \ref splExit. void splCryptoExit(void); + +/// Gets the Service object for the IGeneralInterface usable with splCrypto*(). Service* splCryptoGetServiceSession(void); +/// Initialize spl:ssl. On pre-4.0.0 this just calls \ref splInitialize. Result splSslInitialize(void); + +/// Exit spl:ssl. On pre-4.0.0 this just calls \ref splExit. void splSslExit(void); + +/// Gets the Service object for the IGeneralInterface usable with splSsl*(). Service* splSslGetServiceSession(void); +/// Initialize spl:es. On pre-4.0.0 this just calls \ref splInitialize. Result splEsInitialize(void); + +/// Exit spl:es. On pre-4.0.0 this just calls \ref splExit. void splEsExit(void); + +/// Gets the Service object for the IGeneralInterface usable with splEs*(). Service* splEsGetServiceSession(void); +/// Initialize spl:fs. On pre-4.0.0 this just calls \ref splInitialize. Result splFsInitialize(void); + +/// Exit spl:fs. On pre-4.0.0 this just calls \ref splExit. void splFsExit(void); + +/// Gets the Service object for the IGeneralInterface usable with splFs*(). Service* splFsGetServiceSession(void); +/// Initialize spl:manu. On pre-4.0.0 this just calls \ref splInitialize. Result splManuInitialize(void); + +/// Exit spl:manu. On pre-4.0.0 this just calls \ref splExit. void splManuExit(void); + +/// Gets the Service object for the IGeneralInterface usable with splManu*(). Service* splManuGetServiceSession(void); Result splGetConfig(SplConfigItem config_item, u64 *out_config); diff --git a/nx/include/switch/services/spsm.h b/nx/include/switch/services/spsm.h index dfc67492..6bb0cd46 100644 --- a/nx/include/switch/services/spsm.h +++ b/nx/include/switch/services/spsm.h @@ -8,8 +8,13 @@ #include "../types.h" #include "../sf/service.h" +/// Initialize spsm. Result spsmInitialize(void); + +/// Exit spsm. void spsmExit(void); + +/// Gets the Service object for the actual spsm service session. Service* spsmGetServiceSession(void); Result spsmShutdown(bool reboot); diff --git a/nx/include/switch/services/usb.h b/nx/include/switch/services/usb.h index d8739f63..d1bc52d3 100644 --- a/nx/include/switch/services/usb.h +++ b/nx/include/switch/services/usb.h @@ -6,8 +6,6 @@ */ #pragma once #include "../types.h" -#include "../services/sm.h" -#include "../kernel/event.h" /// Names starting with "libusb" were changed to "usb" to avoid collision with actual libusb if it's ever used. diff --git a/nx/include/switch/services/wlaninf.h b/nx/include/switch/services/wlaninf.h index ddb4b4f6..9ee9444e 100644 --- a/nx/include/switch/services/wlaninf.h +++ b/nx/include/switch/services/wlaninf.h @@ -16,8 +16,13 @@ typedef enum { WlanInfState_Connected, ///< WLAN is connected. } WlanInfState; +/// Initialize wlan:inf. Result wlaninfInitialize(void); + +/// Exit wlan:inf. void wlaninfExit(void); + +/// Gets the Service object for the actual wlan:inf service session. Service* wlaninfGetServiceSession(void); /// Gets \ref WlanInfState. diff --git a/nx/source/services/acc.c b/nx/source/services/acc.c index e8274693..e5e57117 100644 --- a/nx/source/services/acc.c +++ b/nx/source/services/acc.c @@ -22,7 +22,7 @@ void accountSetServiceType(AccountServiceType serviceType) { } Result _accountInitialize(void) { - Result rc=0; + Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); Result rc2=0; AccountUid *userIdEnv = envGetUserIdStorage(); diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 0e6ac9d0..1f7e18a8 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -334,9 +334,6 @@ Result _appletInitialize(void) { if (R_SUCCEEDED(rc2)) g_appletInfoInitialized = true; } - if (R_FAILED(rc)) - appletExit(); - return rc; } @@ -361,8 +358,7 @@ static bool _appletIsRegularApplication(void) { return __nx_applet_type == AppletType_Application; } -void _appletCleanup(void) -{ +void _appletCleanup(void) { if (!g_appletExitProcessFlag) { if (g_appletRecordingInitialized > 0) { if (g_appletRecordingInitialized == 2) appletSetGamePlayRecordingState(0); diff --git a/nx/source/services/audout.c b/nx/source/services/audout.c index b8ff1904..b04351c3 100644 --- a/nx/source/services/audout.c +++ b/nx/source/services/audout.c @@ -39,9 +39,6 @@ Result _audoutInitialize(void) { // Register global handle for buffer events if (R_SUCCEEDED(rc)) rc = _audoutRegisterBufferEvent(&g_audoutBufferEvent); - - if (R_FAILED(rc)) - audoutExit(); return rc; } diff --git a/nx/source/services/audren.c b/nx/source/services/audren.c index 5af62c36..b9b5a29d 100644 --- a/nx/source/services/audren.c +++ b/nx/source/services/audren.c @@ -98,11 +98,7 @@ Result _audrenInitialize(const AudioRendererConfig* config) { if (R_SUCCEEDED(rc)) { // Finally, get the handle to the system event rc = _audrenQuerySystemEvent(&g_audrenEvent); - if (R_FAILED(rc)) - serviceClose(&g_audrenIAudioRenderer); } - if (R_FAILED(rc)) - tmemClose(&g_audrenWorkBuf); } } serviceClose(&audrenMgrSrv); diff --git a/nx/source/services/caps.c b/nx/source/services/caps.c index 11cef1cf..304eacad 100644 --- a/nx/source/services/caps.c +++ b/nx/source/services/caps.c @@ -1,11 +1,5 @@ -#include #include "types.h" #include "result.h" -#include "arm/atomics.h" -#include "kernel/ipc.h" -#include "kernel/event.h" -#include "kernel/tmem.h" -#include "services/sm.h" #include "services/caps.h" #include "runtime/hosversion.h" diff --git a/nx/source/services/fsldr.c b/nx/source/services/fsldr.c index f08ef7e4..9a13a367 100644 --- a/nx/source/services/fsldr.c +++ b/nx/source/services/fsldr.c @@ -34,8 +34,8 @@ Service* fsldrGetServiceSession(void) { } Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out) { - char send_path[FS_MAX_PATH + 1]; - strncpy(send_path, path, FS_MAX_PATH); + char send_path[FS_MAX_PATH]={0}; + strncpy(send_path, path, FS_MAX_PATH-1); serviceAssumeDomain(&g_fsldrSrv); return serviceDispatchIn(&g_fsldrSrv, 0, tid, diff --git a/nx/source/services/irs.c b/nx/source/services/irs.c index e0710358..8f08d0a1 100644 --- a/nx/source/services/irs.c +++ b/nx/source/services/irs.c @@ -53,13 +53,15 @@ void _irsCleanup(void) { size_t entrycount = sizeof(g_irsCameras)/sizeof(IrsCameraEntry); IrsCameraEntry *entry; - for(size_t i=0; iinitialized) continue; - irsStopImageProcessor(entry->IrCameraHandle); - } + if (serviceIsActive(&g_irsSrv)) { + for(size_t i=0; iinitialized) continue; + irsStopImageProcessor(entry->IrCameraHandle); + } - irsActivateIrsensor(0); + irsActivateIrsensor(0); + } serviceClose(&g_irsSrv); shmemClose(&g_irsSharedmem); diff --git a/nx/source/services/nfc.c b/nx/source/services/nfc.c index 3c429af9..f5904e7a 100644 --- a/nx/source/services/nfc.c +++ b/nx/source/services/nfc.c @@ -42,7 +42,7 @@ void nfcSetServiceType(NfcServiceType serviceType) { } Result _nfpInitialize(void) { - Result rc=0; + Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); u64 aruid = 0; // If this fails (for example because we're a sysmodule) aruid stays zero diff --git a/nx/source/services/nifm.c b/nx/source/services/nifm.c index b5fae588..c0d001df 100644 --- a/nx/source/services/nifm.c +++ b/nx/source/services/nifm.c @@ -17,7 +17,7 @@ void nifmSetServiceType(NifmServiceType serviceType) { } Result _nifmInitialize(void) { - Result rc = 0; + Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); switch (g_nifmServiceType) { case NifmServiceType_NotInitialized: case NifmServiceType_User: diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index 7e4a39c6..3a862746 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -30,8 +30,6 @@ Result _nsInitialize(void) { rc = _nsGetSession(&g_nsGetterSrv, &g_nsAppManSrv, 7996); - if (R_FAILED(rc)) serviceClose(&g_nsGetterSrv); - return rc; } @@ -230,16 +228,14 @@ Result nsGetSystemDeliveryInfo(NsSystemDeliveryInfo *info) { NX_GENERATE_SERVICE_GUARD(nsvm); -Result _nsvmInitialize(void) -{ +Result _nsvmInitialize(void) { if (hosversionBefore(3,0,0)) return 0; return smGetService(&g_nsvmSrv, "ns:vm"); } -void _nsvmCleanup(void) -{ +void _nsvmCleanup(void) { if (hosversionBefore(3,0,0)) return; diff --git a/nx/source/services/nv.c b/nx/source/services/nv.c index 85c43562..2c0b1373 100644 --- a/nx/source/services/nv.c +++ b/nx/source/services/nv.c @@ -19,9 +19,8 @@ static Result _nvSetClientPID(u64 AppletResourceUserId); NX_GENERATE_SERVICE_GUARD(nv); -Result _nvInitialize(void) -{ - Result rc = 0; +Result _nvInitialize(void) { + Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); u64 AppletResourceUserId = 0; switch (appletGetAppletType()) { @@ -56,8 +55,7 @@ Result _nvInitialize(void) if (R_SUCCEEDED(rc)) rc = serviceCloneEx(&g_nvSrv, 1, &g_nvSrvClone); - if (R_SUCCEEDED(rc)) - { + if (R_SUCCEEDED(rc)) { // Send aruid if available (non-fatal condition if get-aruid fails) Result aruid_rc = appletGetAppletResourceUserId(&AppletResourceUserId); if (R_SUCCEEDED(aruid_rc)) @@ -65,35 +63,31 @@ Result _nvInitialize(void) } } - if (R_FAILED(rc)) { - nvExit(); - } - return rc; } -void _nvCleanup(void) -{ +void _nvCleanup(void) { serviceClose(&g_nvSrvClone); serviceClose(&g_nvSrv); tmemClose(&g_nvTransfermem); } -static Result _nvCmdInitialize(Handle proc, Handle sharedmem, u32 transfermem_size) -{ +Service* nvGetServiceSession(void) { + return &g_nvSrv; +} + +static Result _nvCmdInitialize(Handle proc, Handle sharedmem, u32 transfermem_size) { return serviceDispatchIn(&g_nvSrv, 3, transfermem_size, .in_num_handles = 2, .in_handles = { proc, sharedmem }, ); } -static Result _nvSetClientPID(u64 AppletResourceUserId) -{ +static Result _nvSetClientPID(u64 AppletResourceUserId) { return serviceDispatchIn(&g_nvSrv, 8, AppletResourceUserId, .in_send_pid = true); } -Result nvOpen(u32 *fd, const char *devicepath) -{ +Result nvOpen(u32 *fd, const char *devicepath) { struct { u32 fd; u32 error; @@ -114,8 +108,7 @@ Result nvOpen(u32 *fd, const char *devicepath) } // Get the appropriate session for the specified request (same logic as official sw) -static inline Service* _nvGetSessionForRequest(u32 request) -{ +static inline Service* _nvGetSessionForRequest(u32 request) { if ( (request & 0xC000FFFF) == 0xC0004808 || // NVGPU_IOCTL_CHANNEL_SUBMIT_GPFIFO request == 0xC018481B || // NVGPU_IOCTL_CHANNEL_KICKOFF_PB @@ -126,8 +119,7 @@ static inline Service* _nvGetSessionForRequest(u32 request) return &g_nvSrv; } -Result nvIoctl(u32 fd, u32 request, void* argp) -{ +Result nvIoctl(u32 fd, u32 request, void* argp) { size_t bufsize = _NV_IOC_SIZE(request); u32 dir = _NV_IOC_DIR(request); @@ -167,8 +159,7 @@ Result nvIoctl(u32 fd, u32 request, void* argp) return rc; } -Result nvIoctl2(u32 fd, u32 request, void* argp, const void* inbuf, size_t inbuf_size) -{ +Result nvIoctl2(u32 fd, u32 request, void* argp, const void* inbuf, size_t inbuf_size) { size_t bufsize = _NV_IOC_SIZE(request); u32 dir = _NV_IOC_DIR(request); @@ -210,8 +201,7 @@ Result nvIoctl2(u32 fd, u32 request, void* argp, const void* inbuf, size_t inbuf return rc; } -Result nvClose(u32 fd) -{ +Result nvClose(u32 fd) { u32 error = 0; Result rc = serviceDispatchInOut(&g_nvSrv, 2, fd, error); @@ -221,8 +211,7 @@ Result nvClose(u32 fd) return rc; } -Result nvQueryEvent(u32 fd, u32 event_id, Event *event_out) -{ +Result nvQueryEvent(u32 fd, u32 event_id, Event *event_out) { const struct { u32 fd; u32 event_id; @@ -244,8 +233,7 @@ Result nvQueryEvent(u32 fd, u32 event_id, Event *event_out) return rc; } -Result nvConvertError(int rc) -{ +Result nvConvertError(int rc) { if (rc == 0) // Fast path. return 0; diff --git a/nx/source/services/spl.c b/nx/source/services/spl.c index 3fb24774..fb267182 100644 --- a/nx/source/services/spl.c +++ b/nx/source/services/spl.c @@ -113,9 +113,9 @@ static Result _spl##name##Initialize(void) { \ \ static void _spl##name##Cleanup() { \ if (hosversionAtLeast(4,0,0)) { \ - splExit(); \ - } else { \ serviceClose(&g_spl##name##Srv); \ + } else { \ + splExit(); \ } \ } \ Service* _spl##name##GetServiceSession() { \ diff --git a/nx/source/services/usbds.c b/nx/source/services/usbds.c index f6548669..9007316e 100644 --- a/nx/source/services/usbds.c +++ b/nx/source/services/usbds.c @@ -47,24 +47,17 @@ Result _usbDsInitialize(void) { if (R_SUCCEEDED(rc) && hosversionAtLeast(5,0,0)) usbDsClearDeviceData(); - if (R_FAILED(rc)) { - eventClose(&g_usbDsStateChangeEvent); - - serviceClose(&g_usbDsSrv); - } - return rc; } void _usbDsCleanup(void) { - if (hosversionAtLeast(5,0,0)) { + if (hosversionAtLeast(5,0,0) && serviceIsActive(&g_usbDsSrv)) { usbDsDisable(); } _usbDsFreeTables(); eventClose(&g_usbDsStateChangeEvent); - serviceClose(&g_usbDsSrv); } diff --git a/nx/source/services/usbhs.c b/nx/source/services/usbhs.c index 1f8b315b..4920c294 100644 --- a/nx/source/services/usbhs.c +++ b/nx/source/services/usbhs.c @@ -34,7 +34,6 @@ Result _usbHsInitialize(void) { void _usbHsCleanup(void) { eventClose(&g_usbHsInterfaceStateChangeEvent); - serviceClose(&g_usbHsSrv); } diff --git a/nx/source/services/vi.c b/nx/source/services/vi.c index 6ff8202d..367dad51 100644 --- a/nx/source/services/vi.c +++ b/nx/source/services/vi.c @@ -35,7 +35,7 @@ NX_GENERATE_SERVICE_GUARD_PARAMS(vi, (ViServiceType service_type), (service_type Result _viInitialize(ViServiceType service_type) { Service root_srv; - Result rc = 0; + Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); if (service_type == ViServiceType_Default || service_type == ViServiceType_Manager) { rc = smGetService(&root_srv, "vi:m");