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.

This commit is contained in:
yellows8 2019-10-31 22:53:42 -04:00
parent 4981ea02c0
commit 1f792cd92f
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
43 changed files with 233 additions and 126 deletions

View File

@ -13,8 +13,13 @@ typedef enum {
BpcSleepButtonState_Released = 1, BpcSleepButtonState_Released = 1,
} BpcSleepButtonState; } BpcSleepButtonState;
/// Initialize bpc.
Result bpcInitialize(void); Result bpcInitialize(void);
/// Exit bpc.
void bpcExit(void); void bpcExit(void);
/// Gets the Service object for the actual bpc service session.
Service* bpcGetServiceSession(void); Service* bpcGetServiceSession(void);
Result bpcShutdownSystem(void); Result bpcShutdownSystem(void);

View File

@ -34,10 +34,14 @@ extern __thread int g_bsdErrno; ///< Last errno, per-thread
/// Fetch the default configuration for bsdInitialize. /// Fetch the default configuration for bsdInitialize.
const BsdInitConfig *bsdGetDefaultInitConfig(void); const BsdInitConfig *bsdGetDefaultInitConfig(void);
/// Initialize the BSD service. /// Initialize the BSD service.
Result bsdInitialize(const BsdInitConfig *config, u32 num_sessions, u32 service_type); Result bsdInitialize(const BsdInitConfig *config, u32 num_sessions, u32 service_type);
/// Deinitialize the BSD service.
/// Exit the BSD service.
void bsdExit(void); void bsdExit(void);
/// Gets the Service object for the actual BSD service session.
Service* bsdGetServiceSession(void); Service* bsdGetServiceSession(void);
/// Creates a socket. /// Creates a socket.

View File

@ -6,7 +6,6 @@
*/ */
#pragma once #pragma once
#include "../types.h" #include "../types.h"
#include "../services/sm.h"
#include "../services/acc.h" #include "../services/acc.h"
/// ImageOrientation /// ImageOrientation

View File

@ -13,9 +13,13 @@ typedef struct {
Service s; Service s;
} ClkrstSession; } ClkrstSession;
/// Only available on [8.0.0+]. /// Initialize clkrst. Only available on [8.0.0+].
Result clkrstInitialize(void); Result clkrstInitialize(void);
/// Exit clkrst.
void clkrstExit(void); void clkrstExit(void);
/// Gets the Service object for the actual clkrst service session.
Service* clkrstGetServiceSession(void); Service* clkrstGetServiceSession(void);
/// Opens a ClkrstSession for the requested PcvModuleId, unk is set to 3 in official sysmodules. /// Opens a ClkrstSession for the requested PcvModuleId, unk is set to 3 in official sysmodules.

View File

@ -8,8 +8,13 @@
#include "../types.h" #include "../types.h"
#include "../sf/service.h" #include "../sf/service.h"
/// Initialize csrng.
Result csrngInitialize(void); Result csrngInitialize(void);
/// Exit csrng.
void csrngExit(void); void csrngExit(void);
/// Gets the Service object for the actual csrng service session.
Service* csrngGetServiceSession(void); Service* csrngGetServiceSession(void);
Result csrngGetRandomBytes(void *out, size_t out_size); Result csrngGetRandomBytes(void *out, size_t out_size);

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "../types.h" #include "../types.h"
#include "../services/sm.h" #include "../sf/service.h"
/// InAppScreenName /// InAppScreenName
typedef struct { typedef struct {

View File

@ -52,8 +52,7 @@ typedef struct {
} FsDeviceOperator; } FsDeviceOperator;
/// Directory entry. /// Directory entry.
typedef struct typedef struct {
{
char name[FS_MAX_PATH]; ///< Entry name. char name[FS_MAX_PATH]; ///< Entry name.
u8 pad[3]; u8 pad[3];
s8 type; ///< See FsDirEntryType. s8 type; ///< See FsDirEntryType.
@ -62,8 +61,7 @@ typedef struct
} FsDirectoryEntry; } FsDirectoryEntry;
/// Save Struct /// 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. 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. AccountUid uid; ///< \ref AccountUid for the user-specific savedata to access, otherwise 0 for common savedata.
u64 saveID; ///< saveID, 0 for SaveData. u64 saveID; ///< saveID, 0 for SaveData.
@ -101,8 +99,7 @@ typedef struct {
u8 padding[0x1A]; ///< Uninitialized for SystemSaveData. u8 padding[0x1A]; ///< Uninitialized for SystemSaveData.
} FsSaveCreate; } FsSaveCreate;
typedef struct typedef struct {
{
u64 saveID_unk; u64 saveID_unk;
u8 saveDataSpaceId; ///< See \ref FsSaveDataSpaceId. u8 saveDataSpaceId; ///< See \ref FsSaveDataSpaceId.
u8 saveDataType; ///< See \ref FsSaveDataType. u8 saveDataType; ///< See \ref FsSaveDataType.
@ -116,8 +113,7 @@ typedef struct
u8 unk_x3b[0x25]; ///< Unknown. Usually zeros? u8 unk_x3b[0x25]; ///< Unknown. Usually zeros?
} FsSaveDataInfo; } FsSaveDataInfo;
typedef struct typedef struct {
{
u64 created; ///< POSIX timestamp. u64 created; ///< POSIX timestamp.
u64 modified; ///< POSIX timestamp. u64 modified; ///< POSIX timestamp.
u64 accessed; ///< POSIX timestamp. u64 accessed; ///< POSIX timestamp.
@ -132,36 +128,31 @@ typedef enum {
} FsDirEntryType; } FsDirEntryType;
/// For use with fsFsOpenFile. /// For use with fsFsOpenFile.
typedef enum typedef enum {
{
FsOpenMode_Read = BIT(0), ///< Open for reading. FsOpenMode_Read = BIT(0), ///< Open for reading.
FsOpenMode_Write = BIT(1), ///< Open for writing. FsOpenMode_Write = BIT(1), ///< Open for writing.
FsOpenMode_Append = BIT(2), ///< Append file. FsOpenMode_Append = BIT(2), ///< Append file.
} FsOpenMode; } FsOpenMode;
/// For use with fsFsCreateFile. /// For use with fsFsCreateFile.
typedef enum typedef enum {
{
FsCreateOption_BigFile = BIT(0), ///< Creates a ConcatenationFile (dir with archive bit) instead of file. FsCreateOption_BigFile = BIT(0), ///< Creates a ConcatenationFile (dir with archive bit) instead of file.
} FsCreateOption; } FsCreateOption;
/// For use with fsFsOpenDirectory. /// For use with fsFsOpenDirectory.
typedef enum typedef enum {
{
FsDirOpenMode_ReadDirs = BIT(0), ///< Enable reading directory entries. FsDirOpenMode_ReadDirs = BIT(0), ///< Enable reading directory entries.
FsDirOpenMode_ReadFiles = BIT(1), ///< Enable reading file entries. FsDirOpenMode_ReadFiles = BIT(1), ///< Enable reading file entries.
FsDirOpenMode_NoFileSize = BIT(31), ///< Causes result entries to not contain filesize information (always 0). FsDirOpenMode_NoFileSize = BIT(31), ///< Causes result entries to not contain filesize information (always 0).
} FsDirOpenMode; } FsDirOpenMode;
/// For use with fsFileRead. /// For use with fsFileRead.
typedef enum typedef enum {
{
FsReadOption_None = 0, ///< No option. FsReadOption_None = 0, ///< No option.
} FsReadOption; } FsReadOption;
/// For use with fsFileWrite. /// For use with fsFileWrite.
typedef enum typedef enum {
{
FsWriteOption_None = 0, ///< No option. FsWriteOption_None = 0, ///< No option.
FsWriteOption_Flush = BIT(0), ///< Forces a flush after write. FsWriteOption_Flush = BIT(0), ///< Forces a flush after write.
} FsWriteOption; } FsWriteOption;
@ -176,21 +167,18 @@ typedef enum {
FsStorageId_SdCard = 5, ///< SdCard FsStorageId_SdCard = 5, ///< SdCard
} FsStorageId; } FsStorageId;
typedef enum typedef enum {
{
FsContentStorageId_NandSystem = 0, FsContentStorageId_NandSystem = 0,
FsContentStorageId_NandUser = 1, FsContentStorageId_NandUser = 1,
FsContentStorageId_SdCard = 2, FsContentStorageId_SdCard = 2,
} FsContentStorageId; } FsContentStorageId;
typedef enum typedef enum {
{
FsCustomStorageId_NandUser = 0, FsCustomStorageId_NandUser = 0,
FsCustomStorageId_SdCard = 1, FsCustomStorageId_SdCard = 1,
} FsCustomStorageId; } FsCustomStorageId;
typedef enum typedef enum {
{
FsSaveDataSpaceId_NandSystem = 0, FsSaveDataSpaceId_NandSystem = 0,
FsSaveDataSpaceId_NandUser = 1, FsSaveDataSpaceId_NandUser = 1,
FsSaveDataSpaceId_SdCard = 2, FsSaveDataSpaceId_SdCard = 2,
@ -199,8 +187,7 @@ typedef enum
FsSaveDataSpaceId_All = -1, ///< Pseudo value for fsOpenSaveDataInfoReader(). FsSaveDataSpaceId_All = -1, ///< Pseudo value for fsOpenSaveDataInfoReader().
} FsSaveDataSpaceId; } FsSaveDataSpaceId;
typedef enum typedef enum {
{
FsSaveDataType_SystemSaveData = 0, FsSaveDataType_SystemSaveData = 0,
FsSaveDataType_SaveData = 1, FsSaveDataType_SaveData = 1,
FsSaveDataType_BcatDeliveryCacheStorage = 2, FsSaveDataType_BcatDeliveryCacheStorage = 2,
@ -266,8 +253,7 @@ typedef enum {
FsBisStorageId_SystemProperPartition = 33, FsBisStorageId_SystemProperPartition = 33,
} FsBisStorageId; } FsBisStorageId;
typedef enum typedef enum {
{
FsFileSystemType_Logo = 2, FsFileSystemType_Logo = 2,
FsFileSystemType_ContentControl = 3, FsFileSystemType_ContentControl = 3,
FsFileSystemType_ContentManual = 4, FsFileSystemType_ContentManual = 4,
@ -276,8 +262,7 @@ typedef enum
FsFileSystemType_ApplicationPackage = 7, FsFileSystemType_ApplicationPackage = 7,
} FsFileSystemType; } FsFileSystemType;
typedef enum typedef enum {
{
FsFileSystemQueryType_SetArchiveBit = 0, FsFileSystemQueryType_SetArchiveBit = 0,
} FsFileSystemQueryType; } FsFileSystemQueryType;
@ -288,9 +273,13 @@ typedef enum {
FsPriority_Background = 3, FsPriority_Background = 3,
} FsPriority; } FsPriority;
/// Initialize fsp-srv. Used automatically during app startup.
Result fsInitialize(void); Result fsInitialize(void);
/// Exit fsp-srv. Used automatically during app exit.
void fsExit(void); void fsExit(void);
/// Gets the Service object for the actual fsp-srv service session.
Service* fsGetServiceSession(void); Service* fsGetServiceSession(void);
void fsSetPriority(FsPriority prio); void fsSetPriority(FsPriority prio);

View File

@ -9,8 +9,13 @@
#include "../sf/service.h" #include "../sf/service.h"
#include "../services/fs.h" #include "../services/fs.h"
/// Initialize fsp-ldr.
Result fsldrInitialize(void); Result fsldrInitialize(void);
/// Exit fsp-ldr.
void fsldrExit(void); void fsldrExit(void);
/// Gets the Service object for the actual fsp-ldr service session.
Service* fsldrGetServiceSession(void); Service* fsldrGetServiceSession(void);
Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out); Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out);

View File

@ -9,8 +9,13 @@
#include "../sf/service.h" #include "../sf/service.h"
#include "../services/fs.h" #include "../services/fs.h"
/// Initialize fsp-pr.
Result fsprInitialize(void); Result fsprInitialize(void);
/// Exit fsp-pr.
void fsprExit(void); void fsprExit(void);
/// Gets the Service object for the actual fsp-pr service session.
Service* fsprGetServiceSession(void); 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); 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);

View File

@ -28,8 +28,13 @@ typedef enum {
GpioValue_High = 1, GpioValue_High = 1,
} GpioValue; } GpioValue;
/// Initialize gpio.
Result gpioInitialize(void); Result gpioInitialize(void);
/// Exit gpio.
void gpioExit(void); void gpioExit(void);
/// Gets the Service object for the actual gpio service session.
Service* gpioGetServiceSession(void); Service* gpioGetServiceSession(void);
Result gpioOpenSession(GpioPadSession *out, GpioPadName name); Result gpioOpenSession(GpioPadSession *out, GpioPadName name);

View File

@ -55,8 +55,13 @@ typedef enum {
I2cTransactionOption_All = I2cTransactionOption_Start | I2cTransactionOption_Stop, I2cTransactionOption_All = I2cTransactionOption_Start | I2cTransactionOption_Stop,
} I2cTransactionOption; } I2cTransactionOption;
/// Initialize i2c.
Result i2cInitialize(void); Result i2cInitialize(void);
/// Exit i2c.
void i2cExit(void); void i2cExit(void);
/// Gets the Service object for the actual i2c service session.
Service* i2cGetServiceSession(void); Service* i2cGetServiceSession(void);
Result i2cOpenSession(I2cSession *out, I2cDevice dev); Result i2cOpenSession(I2cSession *out, I2cDevice dev);

View File

@ -29,19 +29,31 @@ typedef struct {
u64 size; u64 size;
} LoaderModuleInfo; } LoaderModuleInfo;
/// Initialize ldr:shel.
Result ldrShellInitialize(void); Result ldrShellInitialize(void);
/// Exit ldr:shel.
void ldrShellExit(void); void ldrShellExit(void);
/// Gets the Service object for the actual ldr:shel service session.
Service* ldrShellGetServiceSession(void); Service* ldrShellGetServiceSession(void);
/// Initialize ldr:dmnt.
Result ldrDmntInitialize(void); Result ldrDmntInitialize(void);
/// Exit ldr:dmnt.
void ldrDmntExit(void); void ldrDmntExit(void);
/// Gets the Service object for the actual ldr:dmnt service session.
Service* ldrDmntGetServiceSession(void); Service* ldrDmntGetServiceSession(void);
/// Initialize ldr:pm.
Result ldrPmInitialize(void); Result ldrPmInitialize(void);
/// Exit ldr:pm.
void ldrPmExit(void); void ldrPmExit(void);
/// Gets the Service object for the actual ldr:pm service session.
Service* ldrPmGetServiceSession(void); Service* ldrPmGetServiceSession(void);
Result ldrShellSetProgramArguments(u64 program_id, const void *args, size_t args_size); Result ldrShellSetProgramArguments(u64 program_id, const void *args, size_t args_size);

View File

@ -17,8 +17,13 @@ typedef struct {
Service s; Service s;
} LrRegisteredLocationResolver; } LrRegisteredLocationResolver;
/// Initialize lr.
Result lrInitialize(void); Result lrInitialize(void);
/// Exit lr.
void lrExit(void); void lrExit(void);
/// Gets the Service object for the actual lr service session.
Service* lrGetServiceSession(void); Service* lrGetServiceSession(void);
Result lrOpenLocationResolver(FsStorageId storage, LrLocationResolver* out); Result lrOpenLocationResolver(FsStorageId storage, LrLocationResolver* out);

View File

@ -7,7 +7,7 @@
#pragma once #pragma once
#include "../types.h" #include "../types.h"
#include "../services/fs.h" #include "../services/fs.h"
#include "../services/sm.h" #include "../sf/service.h"
/// ContentStorage /// ContentStorage
typedef struct { typedef struct {
@ -144,8 +144,13 @@ typedef struct {
u8 pad[7]; u8 pad[7];
} NcmProgramLocation; } NcmProgramLocation;
/// Initialize ncm.
Result ncmInitialize(void); Result ncmInitialize(void);
/// Exit ncm.
void ncmExit(void); void ncmExit(void);
/// Gets the Service object for the actual ncm service session.
Service* ncmGetServiceSession(void); Service* ncmGetServiceSession(void);
Result ncmCreateContentStorage(FsStorageId storage_id); Result ncmCreateContentStorage(FsStorageId storage_id);

View File

@ -168,7 +168,7 @@ void nfpExit(void);
/// Initialize nfc:*. /// Initialize nfc:*.
Result nfcInitialize(void); Result nfcInitialize(void);
/// Exit nfc:*.. /// Exit nfc:*.
void nfcExit(void); void nfcExit(void);
/// Gets the Service object for the actual nfp:* service session. /// Gets the Service object for the actual nfp:* service session.

View File

@ -9,9 +9,15 @@
#include "../sf/service.h" #include "../sf/service.h"
#include "../kernel/event.h" #include "../kernel/event.h"
/// Initialize nvdrv*.
Result nvInitialize(void); Result nvInitialize(void);
/// Exit nvdrv*.
void nvExit(void); void nvExit(void);
/// Gets the Service object for the actual nvdrv* service session.
Service* nvGetServiceSession(void);
typedef enum { typedef enum {
NvEventId_Gpu_SmException_BptIntReport=1, NvEventId_Gpu_SmException_BptIntReport=1,
NvEventId_Gpu_SmException_BptPauseReport=2, NvEventId_Gpu_SmException_BptPauseReport=2,

View File

@ -191,8 +191,13 @@ typedef enum {
PcvModuleId_EXTPERIPH2 = 0x40000057, PcvModuleId_EXTPERIPH2 = 0x40000057,
} PcvModuleId; } PcvModuleId;
/// Initialize pcv.
Result pcvInitialize(void); Result pcvInitialize(void);
/// Exit pcv.
void pcvExit(void); void pcvExit(void);
/// Gets the Service object for the actual pcv service session.
Service* pcvGetServiceSession(void); Service* pcvGetServiceSession(void);
Result pcvGetModuleId(PcvModuleId *module_id, PcvModule module); Result pcvGetModuleId(PcvModuleId *module_id, PcvModule module);

View File

@ -160,8 +160,13 @@ typedef struct {
u64 totalLaunches; ///< Total times the application was launched. u64 totalLaunches; ///< Total times the application was launched.
} PdmApplicationPlayStatistics; } PdmApplicationPlayStatistics;
/// Initialize pdm:qry.
Result pdmqryInitialize(void); Result pdmqryInitialize(void);
/// Exit pdm:qry.
void pdmqryExit(void); void pdmqryExit(void);
/// Gets the Service object for the actual pdm:qry service session.
Service* pdmqryGetServiceSession(void); Service* pdmqryGetServiceSession(void);
/** /**

View File

@ -57,24 +57,40 @@ typedef enum {
PmBootMode_SafeMode = 2, ///< SafeMode PmBootMode_SafeMode = 2, ///< SafeMode
} PmBootMode; } PmBootMode;
/// Initialize pm:dmnt.
Result pmdmntInitialize(void); Result pmdmntInitialize(void);
/// Exit pm:dmnt.
void pmdmntExit(void); void pmdmntExit(void);
/// Gets the Service object for the actual pm:dmnt service session.
Service* pmdmntGetServiceSession(void); Service* pmdmntGetServiceSession(void);
/// Initialize pm:info.
Result pminfoInitialize(void); Result pminfoInitialize(void);
/// Exit pm:info.
void pminfoExit(void); void pminfoExit(void);
/// Gets the Service object for the actual pm:info service session.
Service* pminfoGetServiceSession(void); Service* pminfoGetServiceSession(void);
/// Initialize pm:shell.
Result pmshellInitialize(void); Result pmshellInitialize(void);
/// Exit pm:shell.
void pmshellExit(void); void pmshellExit(void);
/// Gets the Service object for the actual pm:shell service session.
Service* pmshellGetServiceSession(void); Service* pmshellGetServiceSession(void);
/// Initialize pm:bm.
Result pmbmInitialize(); Result pmbmInitialize();
/// Exit pm:bm.
void pmbmExit(); void pmbmExit();
/// Gets the Service object for the actual pm:bm service session.
Service* pmbmGetServiceSession(void); Service* pmbmGetServiceSession(void);
/** /**

View File

@ -85,8 +85,13 @@ typedef struct {
PscPmModuleId module_id; PscPmModuleId module_id;
} PscPmModule; } PscPmModule;
/// Initialize psc:m.
Result pscmInitialize(void); Result pscmInitialize(void);
/// Exit psc:m.
void pscmExit(void); void pscmExit(void);
/// Gets the Service object for the actual psc:m service session.
Service* pscmGetServiceSession(void); Service* pscmGetServiceSession(void);
Result pscmGetPmModule(PscPmModule *out, PscPmModuleId module_id, const u16 *dependencies, size_t dependency_count, bool autoclear); Result pscmGetPmModule(PscPmModule *out, PscPmModuleId module_id, const u16 *dependencies, size_t dependency_count, bool autoclear);

View File

@ -28,8 +28,13 @@ typedef struct {
Event StateChangeEvent; ///< autoclear=false Event StateChangeEvent; ///< autoclear=false
} PsmSession; } PsmSession;
/// Initialize psm.
Result psmInitialize(void); Result psmInitialize(void);
/// Exit psm.
void psmExit(void); void psmExit(void);
/// Gets the Service object for the actual psm service session.
Service* psmGetServiceSession(void); Service* psmGetServiceSession(void);
Result psmGetBatteryChargePercentage(u32 *out); Result psmGetBatteryChargePercentage(u32 *out);

View File

@ -9,16 +9,31 @@
#include "../sf/service.h" #include "../sf/service.h"
#include "../services/ldr.h" #include "../services/ldr.h"
/// Initialize ldr:ro.
Result ldrRoInitialize(void); Result ldrRoInitialize(void);
/// Exit ldr:ro.
void ldrRoExit(void); void ldrRoExit(void);
/// Gets the Service object for the actual ldr:ro service session.
Service* ldrRoGetServiceSession(void); Service* ldrRoGetServiceSession(void);
/// Initialize ro:1. Only available with [7.0.0+].
Result ro1Initialize(void); Result ro1Initialize(void);
/// Exit ro:1.
void ro1Exit(void); void ro1Exit(void);
/// Gets the Service object for the actual ro:1 service session.
Service* ro1GetServiceSession(void); Service* ro1GetServiceSession(void);
/// Initialize ro:dmnt. Only available with [3.0.0+].
Result roDmntInitialize(void); Result roDmntInitialize(void);
/// Exit ro:dmnt.
void roDmntExit(void); void roDmntExit(void);
/// Gets the Service object for the actual ro:dmnt service session.
Service* roDmntGetServiceSession(void); Service* roDmntGetServiceSession(void);
Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size);

View File

@ -7,11 +7,14 @@
#pragma once #pragma once
#include "../types.h" #include "../types.h"
#include "../sf/service.h" #include "../sf/service.h"
#include "../services/fs.h"
/// Initialize sm:m.
Result smManagerInitialize(void); Result smManagerInitialize(void);
/// Exit sm:m.
void smManagerExit(void); void smManagerExit(void);
/// Gets the Service object for the actual sm:m service session.
Service* smManagerGetServiceSession(void); 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); Result smManagerRegisterProcess(u64 pid, const void *acid_sac, size_t acid_sac_size, const void *aci0_sac, size_t aci0_sac_size);

View File

@ -35,28 +35,58 @@ typedef enum {
RsaKeyVersion_Extended = 1, RsaKeyVersion_Extended = 1,
} RsaKeyVersion; } RsaKeyVersion;
/// Initialize 'spl:'.
Result splInitialize(void); Result splInitialize(void);
/// Exit 'spl:'.
void splExit(void); void splExit(void);
/// Gets the Service object for the IGeneralInterface usable with spl*().
Service* splGetServiceSession(void); Service* splGetServiceSession(void);
/// Initialize spl:mig. On pre-4.0.0 this just calls \ref splInitialize.
Result splCryptoInitialize(void); Result splCryptoInitialize(void);
/// Exit spl:mig. On pre-4.0.0 this just calls \ref splExit.
void splCryptoExit(void); void splCryptoExit(void);
/// Gets the Service object for the IGeneralInterface usable with splCrypto*().
Service* splCryptoGetServiceSession(void); Service* splCryptoGetServiceSession(void);
/// Initialize spl:ssl. On pre-4.0.0 this just calls \ref splInitialize.
Result splSslInitialize(void); Result splSslInitialize(void);
/// Exit spl:ssl. On pre-4.0.0 this just calls \ref splExit.
void splSslExit(void); void splSslExit(void);
/// Gets the Service object for the IGeneralInterface usable with splSsl*().
Service* splSslGetServiceSession(void); Service* splSslGetServiceSession(void);
/// Initialize spl:es. On pre-4.0.0 this just calls \ref splInitialize.
Result splEsInitialize(void); Result splEsInitialize(void);
/// Exit spl:es. On pre-4.0.0 this just calls \ref splExit.
void splEsExit(void); void splEsExit(void);
/// Gets the Service object for the IGeneralInterface usable with splEs*().
Service* splEsGetServiceSession(void); Service* splEsGetServiceSession(void);
/// Initialize spl:fs. On pre-4.0.0 this just calls \ref splInitialize.
Result splFsInitialize(void); Result splFsInitialize(void);
/// Exit spl:fs. On pre-4.0.0 this just calls \ref splExit.
void splFsExit(void); void splFsExit(void);
/// Gets the Service object for the IGeneralInterface usable with splFs*().
Service* splFsGetServiceSession(void); Service* splFsGetServiceSession(void);
/// Initialize spl:manu. On pre-4.0.0 this just calls \ref splInitialize.
Result splManuInitialize(void); Result splManuInitialize(void);
/// Exit spl:manu. On pre-4.0.0 this just calls \ref splExit.
void splManuExit(void); void splManuExit(void);
/// Gets the Service object for the IGeneralInterface usable with splManu*().
Service* splManuGetServiceSession(void); Service* splManuGetServiceSession(void);
Result splGetConfig(SplConfigItem config_item, u64 *out_config); Result splGetConfig(SplConfigItem config_item, u64 *out_config);

View File

@ -8,8 +8,13 @@
#include "../types.h" #include "../types.h"
#include "../sf/service.h" #include "../sf/service.h"
/// Initialize spsm.
Result spsmInitialize(void); Result spsmInitialize(void);
/// Exit spsm.
void spsmExit(void); void spsmExit(void);
/// Gets the Service object for the actual spsm service session.
Service* spsmGetServiceSession(void); Service* spsmGetServiceSession(void);
Result spsmShutdown(bool reboot); Result spsmShutdown(bool reboot);

View File

@ -6,8 +6,6 @@
*/ */
#pragma once #pragma once
#include "../types.h" #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. /// Names starting with "libusb" were changed to "usb" to avoid collision with actual libusb if it's ever used.

View File

@ -16,8 +16,13 @@ typedef enum {
WlanInfState_Connected, ///< WLAN is connected. WlanInfState_Connected, ///< WLAN is connected.
} WlanInfState; } WlanInfState;
/// Initialize wlan:inf.
Result wlaninfInitialize(void); Result wlaninfInitialize(void);
/// Exit wlan:inf.
void wlaninfExit(void); void wlaninfExit(void);
/// Gets the Service object for the actual wlan:inf service session.
Service* wlaninfGetServiceSession(void); Service* wlaninfGetServiceSession(void);
/// Gets \ref WlanInfState. /// Gets \ref WlanInfState.

View File

@ -22,7 +22,7 @@ void accountSetServiceType(AccountServiceType serviceType) {
} }
Result _accountInitialize(void) { Result _accountInitialize(void) {
Result rc=0; Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
Result rc2=0; Result rc2=0;
AccountUid *userIdEnv = envGetUserIdStorage(); AccountUid *userIdEnv = envGetUserIdStorage();

View File

@ -334,9 +334,6 @@ Result _appletInitialize(void) {
if (R_SUCCEEDED(rc2)) g_appletInfoInitialized = true; if (R_SUCCEEDED(rc2)) g_appletInfoInitialized = true;
} }
if (R_FAILED(rc))
appletExit();
return rc; return rc;
} }
@ -361,8 +358,7 @@ static bool _appletIsRegularApplication(void) {
return __nx_applet_type == AppletType_Application; return __nx_applet_type == AppletType_Application;
} }
void _appletCleanup(void) void _appletCleanup(void) {
{
if (!g_appletExitProcessFlag) { if (!g_appletExitProcessFlag) {
if (g_appletRecordingInitialized > 0) { if (g_appletRecordingInitialized > 0) {
if (g_appletRecordingInitialized == 2) appletSetGamePlayRecordingState(0); if (g_appletRecordingInitialized == 2) appletSetGamePlayRecordingState(0);

View File

@ -40,9 +40,6 @@ Result _audoutInitialize(void) {
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
rc = _audoutRegisterBufferEvent(&g_audoutBufferEvent); rc = _audoutRegisterBufferEvent(&g_audoutBufferEvent);
if (R_FAILED(rc))
audoutExit();
return rc; return rc;
} }

View File

@ -98,11 +98,7 @@ Result _audrenInitialize(const AudioRendererConfig* config) {
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
// Finally, get the handle to the system event // Finally, get the handle to the system event
rc = _audrenQuerySystemEvent(&g_audrenEvent); rc = _audrenQuerySystemEvent(&g_audrenEvent);
if (R_FAILED(rc))
serviceClose(&g_audrenIAudioRenderer);
} }
if (R_FAILED(rc))
tmemClose(&g_audrenWorkBuf);
} }
} }
serviceClose(&audrenMgrSrv); serviceClose(&audrenMgrSrv);

View File

@ -1,11 +1,5 @@
#include <string.h>
#include "types.h" #include "types.h"
#include "result.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 "services/caps.h"
#include "runtime/hosversion.h" #include "runtime/hosversion.h"

View File

@ -34,8 +34,8 @@ Service* fsldrGetServiceSession(void) {
} }
Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out) { Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out) {
char send_path[FS_MAX_PATH + 1]; char send_path[FS_MAX_PATH]={0};
strncpy(send_path, path, FS_MAX_PATH); strncpy(send_path, path, FS_MAX_PATH-1);
serviceAssumeDomain(&g_fsldrSrv); serviceAssumeDomain(&g_fsldrSrv);
return serviceDispatchIn(&g_fsldrSrv, 0, tid, return serviceDispatchIn(&g_fsldrSrv, 0, tid,

View File

@ -53,6 +53,7 @@ void _irsCleanup(void) {
size_t entrycount = sizeof(g_irsCameras)/sizeof(IrsCameraEntry); size_t entrycount = sizeof(g_irsCameras)/sizeof(IrsCameraEntry);
IrsCameraEntry *entry; IrsCameraEntry *entry;
if (serviceIsActive(&g_irsSrv)) {
for(size_t i=0; i<entrycount; i++) { for(size_t i=0; i<entrycount; i++) {
entry = &g_irsCameras[i]; entry = &g_irsCameras[i];
if (!entry->initialized) continue; if (!entry->initialized) continue;
@ -60,6 +61,7 @@ void _irsCleanup(void) {
} }
irsActivateIrsensor(0); irsActivateIrsensor(0);
}
serviceClose(&g_irsSrv); serviceClose(&g_irsSrv);
shmemClose(&g_irsSharedmem); shmemClose(&g_irsSharedmem);

View File

@ -42,7 +42,7 @@ void nfcSetServiceType(NfcServiceType serviceType) {
} }
Result _nfpInitialize(void) { Result _nfpInitialize(void) {
Result rc=0; Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
u64 aruid = 0; u64 aruid = 0;
// If this fails (for example because we're a sysmodule) aruid stays zero // If this fails (for example because we're a sysmodule) aruid stays zero

View File

@ -17,7 +17,7 @@ void nifmSetServiceType(NifmServiceType serviceType) {
} }
Result _nifmInitialize(void) { Result _nifmInitialize(void) {
Result rc = 0; Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
switch (g_nifmServiceType) { switch (g_nifmServiceType) {
case NifmServiceType_NotInitialized: case NifmServiceType_NotInitialized:
case NifmServiceType_User: case NifmServiceType_User:

View File

@ -30,8 +30,6 @@ Result _nsInitialize(void) {
rc = _nsGetSession(&g_nsGetterSrv, &g_nsAppManSrv, 7996); rc = _nsGetSession(&g_nsGetterSrv, &g_nsAppManSrv, 7996);
if (R_FAILED(rc)) serviceClose(&g_nsGetterSrv);
return rc; return rc;
} }
@ -230,16 +228,14 @@ Result nsGetSystemDeliveryInfo(NsSystemDeliveryInfo *info) {
NX_GENERATE_SERVICE_GUARD(nsvm); NX_GENERATE_SERVICE_GUARD(nsvm);
Result _nsvmInitialize(void) Result _nsvmInitialize(void) {
{
if (hosversionBefore(3,0,0)) if (hosversionBefore(3,0,0))
return 0; return 0;
return smGetService(&g_nsvmSrv, "ns:vm"); return smGetService(&g_nsvmSrv, "ns:vm");
} }
void _nsvmCleanup(void) void _nsvmCleanup(void) {
{
if (hosversionBefore(3,0,0)) if (hosversionBefore(3,0,0))
return; return;

View File

@ -19,9 +19,8 @@ static Result _nvSetClientPID(u64 AppletResourceUserId);
NX_GENERATE_SERVICE_GUARD(nv); NX_GENERATE_SERVICE_GUARD(nv);
Result _nvInitialize(void) Result _nvInitialize(void) {
{ Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
Result rc = 0;
u64 AppletResourceUserId = 0; u64 AppletResourceUserId = 0;
switch (appletGetAppletType()) { switch (appletGetAppletType()) {
@ -56,8 +55,7 @@ Result _nvInitialize(void)
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
rc = serviceCloneEx(&g_nvSrv, 1, &g_nvSrvClone); 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) // Send aruid if available (non-fatal condition if get-aruid fails)
Result aruid_rc = appletGetAppletResourceUserId(&AppletResourceUserId); Result aruid_rc = appletGetAppletResourceUserId(&AppletResourceUserId);
if (R_SUCCEEDED(aruid_rc)) if (R_SUCCEEDED(aruid_rc))
@ -65,35 +63,31 @@ Result _nvInitialize(void)
} }
} }
if (R_FAILED(rc)) {
nvExit();
}
return rc; return rc;
} }
void _nvCleanup(void) void _nvCleanup(void) {
{
serviceClose(&g_nvSrvClone); serviceClose(&g_nvSrvClone);
serviceClose(&g_nvSrv); serviceClose(&g_nvSrv);
tmemClose(&g_nvTransfermem); 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, return serviceDispatchIn(&g_nvSrv, 3, transfermem_size,
.in_num_handles = 2, .in_num_handles = 2,
.in_handles = { proc, sharedmem }, .in_handles = { proc, sharedmem },
); );
} }
static Result _nvSetClientPID(u64 AppletResourceUserId) static Result _nvSetClientPID(u64 AppletResourceUserId) {
{
return serviceDispatchIn(&g_nvSrv, 8, AppletResourceUserId, .in_send_pid = true); 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 { struct {
u32 fd; u32 fd;
u32 error; 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) // 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 ( if (
(request & 0xC000FFFF) == 0xC0004808 || // NVGPU_IOCTL_CHANNEL_SUBMIT_GPFIFO (request & 0xC000FFFF) == 0xC0004808 || // NVGPU_IOCTL_CHANNEL_SUBMIT_GPFIFO
request == 0xC018481B || // NVGPU_IOCTL_CHANNEL_KICKOFF_PB request == 0xC018481B || // NVGPU_IOCTL_CHANNEL_KICKOFF_PB
@ -126,8 +119,7 @@ static inline Service* _nvGetSessionForRequest(u32 request)
return &g_nvSrv; 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); size_t bufsize = _NV_IOC_SIZE(request);
u32 dir = _NV_IOC_DIR(request); u32 dir = _NV_IOC_DIR(request);
@ -167,8 +159,7 @@ Result nvIoctl(u32 fd, u32 request, void* argp)
return rc; 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); size_t bufsize = _NV_IOC_SIZE(request);
u32 dir = _NV_IOC_DIR(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; return rc;
} }
Result nvClose(u32 fd) Result nvClose(u32 fd) {
{
u32 error = 0; u32 error = 0;
Result rc = serviceDispatchInOut(&g_nvSrv, 2, fd, error); Result rc = serviceDispatchInOut(&g_nvSrv, 2, fd, error);
@ -221,8 +211,7 @@ Result nvClose(u32 fd)
return rc; return rc;
} }
Result nvQueryEvent(u32 fd, u32 event_id, Event *event_out) Result nvQueryEvent(u32 fd, u32 event_id, Event *event_out) {
{
const struct { const struct {
u32 fd; u32 fd;
u32 event_id; u32 event_id;
@ -244,8 +233,7 @@ Result nvQueryEvent(u32 fd, u32 event_id, Event *event_out)
return rc; return rc;
} }
Result nvConvertError(int rc) Result nvConvertError(int rc) {
{
if (rc == 0) // Fast path. if (rc == 0) // Fast path.
return 0; return 0;

View File

@ -113,9 +113,9 @@ static Result _spl##name##Initialize(void) { \
\ \
static void _spl##name##Cleanup() { \ static void _spl##name##Cleanup() { \
if (hosversionAtLeast(4,0,0)) { \ if (hosversionAtLeast(4,0,0)) { \
splExit(); \
} else { \
serviceClose(&g_spl##name##Srv); \ serviceClose(&g_spl##name##Srv); \
} else { \
splExit(); \
} \ } \
} \ } \
Service* _spl##name##GetServiceSession() { \ Service* _spl##name##GetServiceSession() { \

View File

@ -47,24 +47,17 @@ Result _usbDsInitialize(void) {
if (R_SUCCEEDED(rc) && hosversionAtLeast(5,0,0)) if (R_SUCCEEDED(rc) && hosversionAtLeast(5,0,0))
usbDsClearDeviceData(); usbDsClearDeviceData();
if (R_FAILED(rc)) {
eventClose(&g_usbDsStateChangeEvent);
serviceClose(&g_usbDsSrv);
}
return rc; return rc;
} }
void _usbDsCleanup(void) { void _usbDsCleanup(void) {
if (hosversionAtLeast(5,0,0)) { if (hosversionAtLeast(5,0,0) && serviceIsActive(&g_usbDsSrv)) {
usbDsDisable(); usbDsDisable();
} }
_usbDsFreeTables(); _usbDsFreeTables();
eventClose(&g_usbDsStateChangeEvent); eventClose(&g_usbDsStateChangeEvent);
serviceClose(&g_usbDsSrv); serviceClose(&g_usbDsSrv);
} }

View File

@ -34,7 +34,6 @@ Result _usbHsInitialize(void) {
void _usbHsCleanup(void) { void _usbHsCleanup(void) {
eventClose(&g_usbHsInterfaceStateChangeEvent); eventClose(&g_usbHsInterfaceStateChangeEvent);
serviceClose(&g_usbHsSrv); serviceClose(&g_usbHsSrv);
} }

View File

@ -35,7 +35,7 @@ NX_GENERATE_SERVICE_GUARD_PARAMS(vi, (ViServiceType service_type), (service_type
Result _viInitialize(ViServiceType service_type) { Result _viInitialize(ViServiceType service_type) {
Service root_srv; Service root_srv;
Result rc = 0; Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput);
if (service_type == ViServiceType_Default || service_type == ViServiceType_Manager) { if (service_type == ViServiceType_Default || service_type == ViServiceType_Manager) {
rc = smGetService(&root_srv, "vi:m"); rc = smGetService(&root_srv, "vi:m");