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

@ -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;

View File

@ -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);

View File

@ -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.

View File

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

View File

@ -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.

View File

@ -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);

View File

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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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.

View File

@ -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,

View File

@ -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);

View File

@ -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);
/**

View File

@ -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);
/**

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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.

View File

@ -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.

View File

@ -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();

View File

@ -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);

View File

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

View File

@ -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);

View File

@ -1,11 +1,5 @@
#include <string.h>
#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"

View File

@ -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,

View File

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

View File

@ -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

View File

@ -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:

View File

@ -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;

View File

@ -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;

View File

@ -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() { \

View File

@ -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);
}

View File

@ -34,7 +34,6 @@ Result _usbHsInitialize(void) {
void _usbHsCleanup(void) {
eventClose(&g_usbHsInterfaceStateChangeEvent);
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) {
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");