diff --git a/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheDirectoryMetaAccessor.cs b/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheDirectoryMetaAccessor.cs index b8d6428a..5fa8f5f9 100644 --- a/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheDirectoryMetaAccessor.cs +++ b/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheDirectoryMetaAccessor.cs @@ -32,11 +32,12 @@ namespace LibHac.Bcat.Detail.Service.Core public Result GetEntry(out DeliveryCacheDirectoryMetaEntry entry, int index) { + UnsafeHelpers.SkipParamInit(out entry); + lock (Locker) { if (index >= Count) { - entry = default; return ResultBcat.NotFound.Log(); } diff --git a/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheFileMetaAccessor.cs b/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheFileMetaAccessor.cs index c7f54c82..605757d9 100644 --- a/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheFileMetaAccessor.cs +++ b/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheFileMetaAccessor.cs @@ -34,11 +34,12 @@ namespace LibHac.Bcat.Detail.Service.Core public Result GetEntry(out DeliveryCacheFileMetaEntry entry, int index) { + UnsafeHelpers.SkipParamInit(out entry); + lock (Locker) { if (index >= Count) { - entry = default; return ResultBcat.NotFound.Log(); } @@ -49,6 +50,8 @@ namespace LibHac.Bcat.Detail.Service.Core public Result FindEntry(out DeliveryCacheFileMetaEntry entry, ref FileName fileName) { + UnsafeHelpers.SkipParamInit(out entry); + lock (Locker) { for (int i = 0; i < Count; i++) @@ -60,7 +63,6 @@ namespace LibHac.Bcat.Detail.Service.Core } } - entry = default; return ResultBcat.NotFound.Log(); } } diff --git a/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheStorageManager.cs b/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheStorageManager.cs index f8304241..bdbda87f 100644 --- a/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheStorageManager.cs +++ b/src/LibHac/Bcat/Detail/Service/Core/DeliveryCacheStorageManager.cs @@ -288,6 +288,8 @@ namespace LibHac.Bcat.Detail.Service.Core private Result FindOrGetUnusedEntry(out int entryIndex, ulong applicationId) { + UnsafeHelpers.SkipParamInit(out entryIndex); + // Try to find an existing entry for (int i = 0; i < Entries.Length; i++) { @@ -308,7 +310,6 @@ namespace LibHac.Bcat.Detail.Service.Core } } - entryIndex = default; return ResultBcat.StorageOpenLimitReached.Log(); } diff --git a/src/LibHac/Bcat/Detail/Service/DeliveryCacheDirectoryService.cs b/src/LibHac/Bcat/Detail/Service/DeliveryCacheDirectoryService.cs index 17416413..3feefa5c 100644 --- a/src/LibHac/Bcat/Detail/Service/DeliveryCacheDirectoryService.cs +++ b/src/LibHac/Bcat/Detail/Service/DeliveryCacheDirectoryService.cs @@ -1,6 +1,7 @@ using System; using LibHac.Bcat.Detail.Ipc; using LibHac.Bcat.Detail.Service.Core; +using LibHac.Common; namespace LibHac.Bcat.Detail.Service { @@ -50,10 +51,10 @@ namespace LibHac.Bcat.Detail.Service public Result Read(out int entriesRead, Span entryBuffer) { + UnsafeHelpers.SkipParamInit(out entriesRead); + lock (Locker) { - entriesRead = default; - if (!IsDirectoryOpen) return ResultBcat.NotOpen.Log(); @@ -84,11 +85,12 @@ namespace LibHac.Bcat.Detail.Service public Result GetCount(out int count) { + UnsafeHelpers.SkipParamInit(out count); + lock (Locker) { if (!IsDirectoryOpen) { - count = default; return ResultBcat.NotOpen.Log(); } diff --git a/src/LibHac/Bcat/Detail/Service/DeliveryCacheFileService.cs b/src/LibHac/Bcat/Detail/Service/DeliveryCacheFileService.cs index 57d63c65..2b4b884e 100644 --- a/src/LibHac/Bcat/Detail/Service/DeliveryCacheFileService.cs +++ b/src/LibHac/Bcat/Detail/Service/DeliveryCacheFileService.cs @@ -81,11 +81,12 @@ namespace LibHac.Bcat.Detail.Service public Result GetSize(out long size) { + UnsafeHelpers.SkipParamInit(out size); + lock (Locker) { if (!IsFileOpen) { - size = default; return ResultBcat.NotOpen.Log(); } @@ -95,11 +96,12 @@ namespace LibHac.Bcat.Detail.Service public Result GetDigest(out Digest digest) { + UnsafeHelpers.SkipParamInit(out digest); + lock (Locker) { if (!IsFileOpen) { - digest = default; return ResultBcat.NotOpen.Log(); } diff --git a/src/LibHac/Bcat/Detail/Service/DeliveryCacheStorageService.cs b/src/LibHac/Bcat/Detail/Service/DeliveryCacheStorageService.cs index 65aee83f..cdbd1a4b 100644 --- a/src/LibHac/Bcat/Detail/Service/DeliveryCacheStorageService.cs +++ b/src/LibHac/Bcat/Detail/Service/DeliveryCacheStorageService.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using LibHac.Bcat.Detail.Ipc; using LibHac.Bcat.Detail.Service.Core; +using LibHac.Common; using LibHac.Util; namespace LibHac.Bcat.Detail.Service @@ -28,7 +29,7 @@ namespace LibHac.Bcat.Detail.Service { lock (Locker) { - service = default; + UnsafeHelpers.SkipParamInit(out service); if (FileServiceOpenCount >= MaxOpenCount) return ResultBcat.ServiceOpenLimitReached.Log(); @@ -44,7 +45,7 @@ namespace LibHac.Bcat.Detail.Service { lock (Locker) { - service = default; + UnsafeHelpers.SkipParamInit(out service); if (DirectoryServiceOpenCount >= MaxOpenCount) return ResultBcat.ServiceOpenLimitReached.Log(); @@ -58,10 +59,10 @@ namespace LibHac.Bcat.Detail.Service public Result EnumerateDeliveryCacheDirectory(out int namesRead, Span nameBuffer) { + UnsafeHelpers.SkipParamInit(out namesRead); + lock (Locker) { - namesRead = default; - var metaReader = new DeliveryCacheDirectoryMetaAccessor(Server); Result rc = metaReader.ReadApplicationDirectoryMeta(ApplicationId, true); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Bcat/Detail/Service/ServiceCreator.cs b/src/LibHac/Bcat/Detail/Service/ServiceCreator.cs index 423e08ad..cb9ace1c 100644 --- a/src/LibHac/Bcat/Detail/Service/ServiceCreator.cs +++ b/src/LibHac/Bcat/Detail/Service/ServiceCreator.cs @@ -1,5 +1,6 @@ using LibHac.Arp; using LibHac.Bcat.Detail.Ipc; +using LibHac.Common; namespace LibHac.Bcat.Detail.Service { @@ -25,7 +26,7 @@ namespace LibHac.Bcat.Detail.Service if (rc.IsFailure()) { - service = default; + UnsafeHelpers.SkipParamInit(out service); return ResultBcat.NotFound.LogConverted(rc); } @@ -37,7 +38,7 @@ namespace LibHac.Bcat.Detail.Service { if (!AccessControl.HasFlag(AccessControl.MountOthersDeliveryCacheStorage)) { - service = default; + UnsafeHelpers.SkipParamInit(out service); return ResultBcat.PermissionDenied.Log(); } @@ -47,7 +48,7 @@ namespace LibHac.Bcat.Detail.Service private Result CreateDeliveryCacheStorageServiceImpl(out IDeliveryCacheStorageService service, ApplicationId applicationId) { - service = default; + UnsafeHelpers.SkipParamInit(out service); Result rc = Server.GetStorageManager().Open(applicationId.Value); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Boot/Package2StorageReader.cs b/src/LibHac/Boot/Package2StorageReader.cs index 78b34710..c23a02e1 100644 --- a/src/LibHac/Boot/Package2StorageReader.cs +++ b/src/LibHac/Boot/Package2StorageReader.cs @@ -53,7 +53,7 @@ namespace LibHac.Boot /// The of the operation. public Result OpenPayload(out IStorage payloadStorage, int index) { - payloadStorage = default; + UnsafeHelpers.SkipParamInit(out payloadStorage); if ((uint)index >= Package2Header.PayloadCount) return ResultLibHac.ArgumentOutOfRange.Log(); @@ -100,7 +100,7 @@ namespace LibHac.Boot } // Ini is embedded in the kernel - iniStorage = default; + UnsafeHelpers.SkipParamInit(out iniStorage); Result rc = OpenKernel(out IStorage kernelStorage); if (rc.IsFailure()) return rc; @@ -242,7 +242,7 @@ namespace LibHac.Boot Result rc = OpenPayload(out IStorage payloadStorage, i); if (rc.IsFailure()) { - packageStorage = default; + UnsafeHelpers.SkipParamInit(out packageStorage); return rc; } diff --git a/src/LibHac/Common/Keys/ExternalKeyReader.cs b/src/LibHac/Common/Keys/ExternalKeyReader.cs index dafeec0a..242ab16d 100644 --- a/src/LibHac/Common/Keys/ExternalKeyReader.cs +++ b/src/LibHac/Common/Keys/ExternalKeyReader.cs @@ -571,6 +571,8 @@ namespace LibHac.Common.Keys private static bool TryGetKeyInfo(out SpecificKeyInfo info, List keyList, ReadOnlySpan keyName) { + UnsafeHelpers.SkipParamInit(out info); + for (int i = 0; i < keyList.Count; i++) { if (keyList[i].Matches(keyName, out int keyIndex, out bool isDev)) @@ -580,7 +582,6 @@ namespace LibHac.Common.Keys } } - info = default; return false; } } diff --git a/src/LibHac/Common/UnsafeHelpers.cs b/src/LibHac/Common/UnsafeHelpers.cs new file mode 100644 index 00000000..216fc6e1 --- /dev/null +++ b/src/LibHac/Common/UnsafeHelpers.cs @@ -0,0 +1,67 @@ +using System.Runtime.CompilerServices; + +namespace LibHac.Common +{ + public static class UnsafeHelpers + { + /// + /// Bypasses definite assignment rules for a given unmanaged value, + /// or zeros a managed value to avoid having invalid references. + ///
Used in instances where an out value in the original code isn't set due to an error condition. + ///
Behaves the same as , except it zeros managed values. + ///
+ /// The type of the object. + /// The object. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void SkipParamInit(out T value) + { + if (!RuntimeHelpers.IsReferenceOrContainsReferences()) + { + Unsafe.SkipInit(out value); + } + else + { + value = default; + } + } + + /// + /// Bypasses definite assignment rules for the given unmanaged values, + /// zeroing any managed values to avoid having invalid references. + ///
Used in instances where out values in the original code aren't set due to an error condition. + ///
Behaves the same as calling + /// on each value, except managed values will be zeroed. + ///
+ /// The type of the first object. + /// The type of the second object. + /// The first object. + /// The second object. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void SkipParamInit(out T1 value1, out T2 value2) + { + SkipParamInit(out value1); + SkipParamInit(out value2); + } + + /// + /// Bypasses definite assignment rules for the given unmanaged values, + /// zeroing any managed values to avoid having invalid references. + ///
Used in instances where out values in the original code aren't set due to an error condition. + ///
Behaves the same as calling + /// on each value, except managed values will be zeroed. + ///
+ /// The type of the first object. + /// The type of the second object. + /// The type of the third object. + /// The first object. + /// The second object. + /// The third object. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void SkipParamInit(out T1 value1, out T2 value2, out T3 value3) + { + SkipParamInit(out value1); + SkipParamInit(out value2); + SkipParamInit(out value3); + } + } +} diff --git a/src/LibHac/Fs/ApplicationSaveDataManagement.cs b/src/LibHac/Fs/ApplicationSaveDataManagement.cs index aa65dee6..34e1616b 100644 --- a/src/LibHac/Fs/ApplicationSaveDataManagement.cs +++ b/src/LibHac/Fs/ApplicationSaveDataManagement.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; using LibHac.Account; +using LibHac.Common; using LibHac.Fs.Shim; using LibHac.Ncm; using LibHac.Ns; @@ -13,7 +14,7 @@ namespace LibHac.Fs public static Result EnsureApplicationSaveData(FileSystemClient fs, out long requiredSize, Ncm.ApplicationId applicationId, ref ApplicationControlProperty nacp, ref Uid uid) { - requiredSize = default; + UnsafeHelpers.SkipParamInit(out requiredSize); long requiredSizeSum = 0; // Create local variable for use in closures @@ -214,7 +215,7 @@ namespace LibHac.Fs return Result.Success; } - requiredSize = default; + UnsafeHelpers.SkipParamInit(out requiredSize); long requiredSizeBcat = 0; var filter = new SaveDataFilter(); @@ -236,7 +237,7 @@ namespace LibHac.Fs out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId, ulong saveDataOwnerId, ushort index, long dataSize, long journalSize, bool allowExisting) { - requiredSize = default; + UnsafeHelpers.SkipParamInit(out requiredSize); target = CacheStorageTargetMedia.SdCard; Result rc = fs.GetCacheStorageTargetMediaImpl(out CacheStorageTargetMedia targetMedia, applicationId); @@ -317,12 +318,10 @@ namespace LibHac.Fs public static Result EnsureApplicationCacheStorage(this FileSystemClient fs, out long requiredSize, out CacheStorageTargetMedia target, Ncm.ApplicationId applicationId, ref ApplicationControlProperty nacp) { + UnsafeHelpers.SkipParamInit(out requiredSize, out target); + if (nacp.CacheStorageSize <= 0) - { - requiredSize = default; - target = default; return Result.Success; - } return EnsureApplicationCacheStorageImpl(fs, out requiredSize, out target, applicationId, nacp.SaveDataOwnerId.Value, 0, nacp.CacheStorageSize, nacp.CacheStorageJournalSize, true); @@ -338,7 +337,7 @@ namespace LibHac.Fs SaveDataSpaceId spaceId, Ncm.ApplicationId applicationId, ulong saveDataOwnerId, ushort index, long dataSize, long journalSize, bool allowExisting) { - requiredSize = default; + UnsafeHelpers.SkipParamInit(out requiredSize); long requiredSizeLocal = 0; var filter = new SaveDataFilter(); diff --git a/src/LibHac/Fs/FileHandleStorage.cs b/src/LibHac/Fs/FileHandleStorage.cs index a6b751ee..04218f7f 100644 --- a/src/LibHac/Fs/FileHandleStorage.cs +++ b/src/LibHac/Fs/FileHandleStorage.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Fs.Fsa; namespace LibHac.Fs @@ -66,7 +67,7 @@ namespace LibHac.Fs protected override Result DoGetSize(out long size) { - size = default; + UnsafeHelpers.SkipParamInit(out size); Result rc = UpdateSize(); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Fs/FileStorage2.cs b/src/LibHac/Fs/FileStorage2.cs index 5b014653..7963e503 100644 --- a/src/LibHac/Fs/FileStorage2.cs +++ b/src/LibHac/Fs/FileStorage2.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; +using LibHac.Common; using LibHac.Fs.Fsa; namespace LibHac.Fs @@ -75,12 +76,10 @@ namespace LibHac.Fs protected override Result DoGetSize(out long size) { + UnsafeHelpers.SkipParamInit(out size); + Result rc = UpdateSize(); - if (rc.IsFailure()) - { - size = default; - return rc; - } + if (rc.IsFailure()) return rc; size = FileSize; return Result.Success; diff --git a/src/LibHac/Fs/Fsa/FileAccessor.cs b/src/LibHac/Fs/Fsa/FileAccessor.cs index a8321b7f..8e2e5328 100644 --- a/src/LibHac/Fs/Fsa/FileAccessor.cs +++ b/src/LibHac/Fs/Fsa/FileAccessor.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Diag; using LibHac.Fs.Fsa; @@ -84,7 +83,7 @@ namespace LibHac.Fs.Impl public Result Read(out long bytesRead, long offset, Span destination, in ReadOption option) { - Unsafe.SkipInit(out bytesRead); + UnsafeHelpers.SkipParamInit(out bytesRead); Result rc; Span logBuffer = stackalloc byte[0x50]; @@ -208,7 +207,7 @@ namespace LibHac.Fs.Impl public Result GetSize(out long size) { - Unsafe.SkipInit(out size); + UnsafeHelpers.SkipParamInit(out size); if (_lastResult.IsFailure()) return _lastResult; diff --git a/src/LibHac/Fs/Fsa/FileSystemAccessor.cs b/src/LibHac/Fs/Fsa/FileSystemAccessor.cs index 95a79236..2eac29d0 100644 --- a/src/LibHac/Fs/Fsa/FileSystemAccessor.cs +++ b/src/LibHac/Fs/Fsa/FileSystemAccessor.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Diag; using LibHac.Fs.Fsa; @@ -234,7 +233,7 @@ namespace LibHac.Fs.Impl public Result GetEntryType(out DirectoryEntryType entryType, U8Span path) { - Unsafe.SkipInit(out entryType); + UnsafeHelpers.SkipParamInit(out entryType); Result rc = CheckPath(new U8Span(_mountName.Name), path); if (rc.IsFailure()) return rc; @@ -244,7 +243,7 @@ namespace LibHac.Fs.Impl public Result GetFreeSpaceSize(out long freeSpace, U8Span path) { - Unsafe.SkipInit(out freeSpace); + UnsafeHelpers.SkipParamInit(out freeSpace); Result rc = CheckPath(new U8Span(_mountName.Name), path); if (rc.IsFailure()) return rc; @@ -254,7 +253,7 @@ namespace LibHac.Fs.Impl public Result GetTotalSpaceSize(out long totalSpace, U8Span path) { - Unsafe.SkipInit(out totalSpace); + UnsafeHelpers.SkipParamInit(out totalSpace); Result rc = CheckPath(new U8Span(_mountName.Name), path); if (rc.IsFailure()) return rc; @@ -264,7 +263,7 @@ namespace LibHac.Fs.Impl public Result OpenFile(out FileAccessor file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Result rc = CheckPath(new U8Span(_mountName.Name), path); if (rc.IsFailure()) return rc; @@ -305,7 +304,7 @@ namespace LibHac.Fs.Impl public Result OpenDirectory(out DirectoryAccessor directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); Result rc = CheckPath(new U8Span(_mountName.Name), path); if (rc.IsFailure()) return rc; @@ -370,7 +369,7 @@ namespace LibHac.Fs.Impl public Result GetSaveDataAttribute(out SaveDataAttribute attribute) { - Unsafe.SkipInit(out attribute); + UnsafeHelpers.SkipParamInit(out attribute); if (_saveDataAttributeGetter is null) return ResultFs.PreconditionViolation.Log(); diff --git a/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs b/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs index 7e2af4b6..85f0bc39 100644 --- a/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs +++ b/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs @@ -15,11 +15,10 @@ namespace LibHac.Fs.Fsa public Result GetFileAttributes(out NxFileAttributes attributes, U8Span path) { + UnsafeHelpers.SkipParamInit(out attributes); + if (path.IsNull()) - { - attributes = default; return ResultFs.NullptrArgument.Log(); - } return DoGetFileAttributes(out attributes, path); } @@ -34,11 +33,10 @@ namespace LibHac.Fs.Fsa public Result GetFileSize(out long fileSize, U8Span path) { + UnsafeHelpers.SkipParamInit(out fileSize); + if (path.IsNull()) - { - fileSize = default; return ResultFs.NullptrArgument.Log(); - } return DoGetFileSize(out fileSize, path); } diff --git a/src/LibHac/Fs/Fsa/IFile.cs b/src/LibHac/Fs/Fsa/IFile.cs index 0e9de69e..68b43a3a 100644 --- a/src/LibHac/Fs/Fsa/IFile.cs +++ b/src/LibHac/Fs/Fsa/IFile.cs @@ -1,4 +1,6 @@ using System; +using System.Runtime.CompilerServices; +using LibHac.Common; using LibHac.Diag; namespace LibHac.Fs.Fsa @@ -32,6 +34,11 @@ namespace LibHac.Fs.Fsa /// The of the requested operation. public Result Read(out long bytesRead, long offset, Span destination, in ReadOption option) { + UnsafeHelpers.SkipParamInit(out bytesRead); + + if (Unsafe.IsNullRef(ref bytesRead)) + return ResultFs.NullptrArgument.Log(); + if (destination.IsEmpty) { bytesRead = 0; @@ -39,16 +46,10 @@ namespace LibHac.Fs.Fsa } if (offset < 0) - { - bytesRead = 0; return ResultFs.OutOfRange.Log(); - } if (long.MaxValue - offset < destination.Length) - { - bytesRead = 0; return ResultFs.OutOfRange.Log(); - } return DoRead(out bytesRead, offset, destination, in option); } @@ -157,26 +158,18 @@ namespace LibHac.Fs.Fsa protected Result DryRead(out long readableBytes, long offset, long size, in ReadOption option, OpenMode openMode) { + UnsafeHelpers.SkipParamInit(out readableBytes); + // Check that we can read. if (!openMode.HasFlag(OpenMode.Read)) - { - readableBytes = default; return ResultFs.ReadUnpermitted.Log(); - } // Get the file size, and validate our offset. Result rc = GetSize(out long fileSize); - if (rc.IsFailure()) - { - readableBytes = default; - return rc; - } + if (rc.IsFailure()) return rc; if (offset > fileSize) - { - readableBytes = default; return ResultFs.OutOfRange.Log(); - } readableBytes = Math.Min(fileSize - offset, size); return Result.Success; @@ -196,28 +189,20 @@ namespace LibHac.Fs.Fsa protected Result DryWrite(out bool needsAppend, long offset, long size, in WriteOption option, OpenMode openMode) { + UnsafeHelpers.SkipParamInit(out needsAppend); + // Check that we can write. if (!openMode.HasFlag(OpenMode.Write)) - { - needsAppend = default; return ResultFs.WriteUnpermitted.Log(); - } // Get the file size. Result rc = GetSize(out long fileSize); - if (rc.IsFailure()) - { - needsAppend = default; - return rc; - } + if (rc.IsFailure()) return rc; if (fileSize < offset + size) { if (!openMode.HasFlag(OpenMode.AllowAppend)) - { - needsAppend = default; return ResultFs.FileExtensionWithoutOpenModeAllowAppend.Log(); - } needsAppend = true; } diff --git a/src/LibHac/Fs/Fsa/IFileSystem.cs b/src/LibHac/Fs/Fsa/IFileSystem.cs index 01a1452a..9eb3f479 100644 --- a/src/LibHac/Fs/Fsa/IFileSystem.cs +++ b/src/LibHac/Fs/Fsa/IFileSystem.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.FsSystem; @@ -214,11 +213,10 @@ namespace LibHac.Fs.Fsa /// The of the requested operation. public Result GetEntryType(out DirectoryEntryType entryType, U8Span path) { + UnsafeHelpers.SkipParamInit(out entryType); + if (path.IsNull()) - { - entryType = default; return ResultFs.NullptrArgument.Log(); - } return DoGetEntryType(out entryType, path); } @@ -231,11 +229,10 @@ namespace LibHac.Fs.Fsa /// The of the requested operation. public Result GetFreeSpaceSize(out long freeSpace, U8Span path) { + UnsafeHelpers.SkipParamInit(out freeSpace); + if (path.IsNull()) - { - freeSpace = default; return ResultFs.NullptrArgument.Log(); - } return DoGetFreeSpaceSize(out freeSpace, path); } @@ -248,11 +245,10 @@ namespace LibHac.Fs.Fsa /// The of the requested operation. public Result GetTotalSpaceSize(out long totalSpace, U8Span path) { + UnsafeHelpers.SkipParamInit(out totalSpace); + if (path.IsNull()) - { - totalSpace = default; return ResultFs.NullptrArgument.Log(); - } return DoGetTotalSpaceSize(out totalSpace, path); } @@ -274,19 +270,19 @@ namespace LibHac.Fs.Fsa { if (path.IsNull()) { - file = default; + UnsafeHelpers.SkipParamInit(out file); return ResultFs.NullptrArgument.Log(); } if ((mode & OpenMode.ReadWrite) == 0) { - file = default; + UnsafeHelpers.SkipParamInit(out file); return ResultFs.InvalidOpenMode.Log(); } if ((mode & ~OpenMode.All) != 0) { - file = default; + UnsafeHelpers.SkipParamInit(out file); return ResultFs.InvalidOpenMode.Log(); } @@ -310,19 +306,19 @@ namespace LibHac.Fs.Fsa { if (path.IsNull()) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); return ResultFs.NullptrArgument.Log(); } if ((mode & OpenDirectoryMode.All) == 0) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); return ResultFs.InvalidOpenMode.Log(); } if ((mode & ~(OpenDirectoryMode.All | OpenDirectoryMode.NoFileSize)) != 0) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); return ResultFs.InvalidOpenMode.Log(); } @@ -358,7 +354,7 @@ namespace LibHac.Fs.Fsa { if (path.IsNull()) { - timeStamp = default; + UnsafeHelpers.SkipParamInit(out timeStamp); return ResultFs.NullptrArgument.Log(); } @@ -397,13 +393,13 @@ namespace LibHac.Fs.Fsa protected virtual Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) { - freeSpace = default; + UnsafeHelpers.SkipParamInit(out freeSpace); return ResultFs.NotImplemented.Log(); } protected virtual Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) { - totalSpace = default; + UnsafeHelpers.SkipParamInit(out totalSpace); return ResultFs.NotImplemented.Log(); } @@ -417,7 +413,7 @@ namespace LibHac.Fs.Fsa protected virtual Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) { - Unsafe.SkipInit(out timeStamp); + UnsafeHelpers.SkipParamInit(out timeStamp); return ResultFs.NotImplemented.Log(); } diff --git a/src/LibHac/Fs/Fsa/MountTable.cs b/src/LibHac/Fs/Fsa/MountTable.cs index b6f895f2..2db1f565 100644 --- a/src/LibHac/Fs/Fsa/MountTable.cs +++ b/src/LibHac/Fs/Fsa/MountTable.cs @@ -33,7 +33,7 @@ namespace LibHac.Fs.Impl public Result Find(out FileSystemAccessor accessor, U8Span name) { - accessor = default; + UnsafeHelpers.SkipParamInit(out accessor); using ScopedLock lk = ScopedLock.Lock(ref _mutex); for (LinkedListNode currentNode = _fileSystemList.First; diff --git a/src/LibHac/Fs/Fsa/MountUtility.cs b/src/LibHac/Fs/Fsa/MountUtility.cs index 1c523ccc..a588b933 100644 --- a/src/LibHac/Fs/Fsa/MountUtility.cs +++ b/src/LibHac/Fs/Fsa/MountUtility.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Diag; using LibHac.Fs.Impl; @@ -14,7 +13,7 @@ namespace LibHac.Fs.Fsa { internal static Result GetMountNameAndSubPath(out MountName mountName, out U8Span subPath, U8Span path) { - Unsafe.SkipInit(out mountName); + UnsafeHelpers.SkipParamInit(out mountName); subPath = default; int mountLen = 0; @@ -94,7 +93,7 @@ namespace LibHac.Fs.Fsa internal static Result FindFileSystem(this FileSystemClientImpl fs, out FileSystemAccessor fileSystem, out U8Span subPath, U8Span path) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); subPath = default; if (path.IsNull()) @@ -153,7 +152,7 @@ namespace LibHac.Fs.Fsa public static Result IsMounted(this FileSystemClientImpl fs, out bool isMounted, U8Span mountName) { - Unsafe.SkipInit(out isMounted); + UnsafeHelpers.SkipParamInit(out isMounted); Result rc = fs.Find(out _, mountName); if (rc.IsFailure()) diff --git a/src/LibHac/Fs/Fsa/UserFile.cs b/src/LibHac/Fs/Fsa/UserFile.cs index fe028476..e7d00fb7 100644 --- a/src/LibHac/Fs/Fsa/UserFile.cs +++ b/src/LibHac/Fs/Fsa/UserFile.cs @@ -206,7 +206,7 @@ namespace LibHac.Fs.Fsa public static Result QueryRange(this FileSystemClient fs, out QueryRangeInfo rangeInfo, FileHandle handle, long offset, long size) { - Unsafe.SkipInit(out rangeInfo); + UnsafeHelpers.SkipParamInit(out rangeInfo); Result rc = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref rangeInfo), OperationId.QueryRange, offset, size, ReadOnlySpan.Empty); diff --git a/src/LibHac/Fs/Fsa/UserFileSystem.cs b/src/LibHac/Fs/Fsa/UserFileSystem.cs index 0895cccd..dab41e8f 100644 --- a/src/LibHac/Fs/Fsa/UserFileSystem.cs +++ b/src/LibHac/Fs/Fsa/UserFileSystem.cs @@ -362,7 +362,7 @@ namespace LibHac.Fs.Fsa public static Result GetEntryType(this FileSystemClient fs, out DirectoryEntryType type, U8Span path) { - Unsafe.SkipInit(out type); + UnsafeHelpers.SkipParamInit(out type); Result rc; U8Span subPath; @@ -414,7 +414,7 @@ namespace LibHac.Fs.Fsa public static Result GetFreeSpaceSize(this FileSystemClient fs, out long freeSpace, U8Span path) { - Unsafe.SkipInit(out freeSpace); + UnsafeHelpers.SkipParamInit(out freeSpace); Result rc; var subPath = U8Span.Empty; @@ -482,7 +482,7 @@ namespace LibHac.Fs.Fsa public static Result OpenFile(this FileSystemClient fs, out FileHandle handle, U8Span path, OpenMode mode) { - handle = default; + UnsafeHelpers.SkipParamInit(out handle); Result rc; U8Span subPath; @@ -539,7 +539,7 @@ namespace LibHac.Fs.Fsa public static Result OpenDirectory(this FileSystemClient fs, out DirectoryHandle handle, U8Span path, OpenDirectoryMode mode) { - handle = default; + UnsafeHelpers.SkipParamInit(out handle); Result rc; U8Span subPath; diff --git a/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs b/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs index c4d2f0f5..f32afd5a 100644 --- a/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs +++ b/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Fs.Impl; using LibHac.Os; @@ -57,7 +56,7 @@ namespace LibHac.Fs.Fsa public static Result GetTotalSpaceSize(this FileSystemClient fs, out long totalSpace, U8Span path) { - Unsafe.SkipInit(out totalSpace); + UnsafeHelpers.SkipParamInit(out totalSpace); Result rc = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span subPath, path); fs.Impl.AbortIfNeeded(rc); diff --git a/src/LibHac/Fs/IStorage.cs b/src/LibHac/Fs/IStorage.cs index f4d1885c..af59691d 100644 --- a/src/LibHac/Fs/IStorage.cs +++ b/src/LibHac/Fs/IStorage.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.CompilerServices; using System.Threading; +using LibHac.Common; namespace LibHac.Fs { @@ -84,11 +85,10 @@ namespace LibHac.Fs [MethodImpl(MethodImplOptions.AggressiveInlining)] public Result GetSize(out long size) { + UnsafeHelpers.SkipParamInit(out size); + if (IsDisposed) - { - size = default; return ResultFs.PreconditionViolation.Log(); - } return DoGetSize(out size); } diff --git a/src/LibHac/Fs/Impl/FileSystemServiceObjectAdapter.cs b/src/LibHac/Fs/Impl/FileSystemServiceObjectAdapter.cs index dbc38408..f324527f 100644 --- a/src/LibHac/Fs/Impl/FileSystemServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Impl/FileSystemServiceObjectAdapter.cs @@ -95,7 +95,7 @@ namespace LibHac.Fs.Impl protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { - Unsafe.SkipInit(out entryType); + UnsafeHelpers.SkipParamInit(out entryType); Result rc = GetPathForServiceObject(out Path sfPath, path); if (rc.IsFailure()) return rc; @@ -107,7 +107,7 @@ namespace LibHac.Fs.Impl protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) { - Unsafe.SkipInit(out freeSpace); + UnsafeHelpers.SkipParamInit(out freeSpace); Result rc = GetPathForServiceObject(out Path sfPath, path); if (rc.IsFailure()) return rc; @@ -117,7 +117,7 @@ namespace LibHac.Fs.Impl protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) { - Unsafe.SkipInit(out totalSpace); + UnsafeHelpers.SkipParamInit(out totalSpace); Result rc = GetPathForServiceObject(out Path sfPath, path); if (rc.IsFailure()) return rc; @@ -127,7 +127,7 @@ namespace LibHac.Fs.Impl protected override Result DoOpenFile(out Fsa.IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Result rc = GetPathForServiceObject(out Path sfPath, path); if (rc.IsFailure()) return rc; @@ -149,7 +149,7 @@ namespace LibHac.Fs.Impl protected override Result DoOpenDirectory(out Fsa.IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); Result rc = GetPathForServiceObject(out Path sfPath, path); if (rc.IsFailure()) return rc; @@ -176,7 +176,7 @@ namespace LibHac.Fs.Impl protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) { - Unsafe.SkipInit(out timeStamp); + UnsafeHelpers.SkipParamInit(out timeStamp); Result rc = GetPathForServiceObject(out Path sfPath, path); if (rc.IsFailure()) return rc; @@ -211,7 +211,7 @@ namespace LibHac.Fs.Impl private Result GetPathForServiceObject(out Path sfPath, U8Span path) { // This is the function used to create Sf.Path structs. Get an unsafe byte span for init only. - Unsafe.SkipInit(out sfPath); + UnsafeHelpers.SkipParamInit(out sfPath); Span outPath = SpanHelpers.AsByteSpan(ref sfPath); // Copy and null terminate diff --git a/src/LibHac/Fs/Impl/IFileDataCache.cs b/src/LibHac/Fs/Impl/IFileDataCache.cs index 136c908d..50a6d3ff 100644 --- a/src/LibHac/Fs/Impl/IFileDataCache.cs +++ b/src/LibHac/Fs/Impl/IFileDataCache.cs @@ -1,5 +1,5 @@ using System; -using System.Runtime.CompilerServices; +using LibHac.Common; using LibHac.Common.FixedArrays; using LibHac.Diag; using LibHac.Fs.Fsa; @@ -19,7 +19,7 @@ namespace LibHac.Fs.Impl public Result Read(IFile file, out long bytesRead, long offset, Span destination, in ReadOption option, ref FileDataCacheAccessResult cacheAccessResult) { - Unsafe.SkipInit(out bytesRead); + UnsafeHelpers.SkipParamInit(out bytesRead); if (destination.Length == 0) { diff --git a/src/LibHac/Fs/Impl/SaveDataMetaPolicy.cs b/src/LibHac/Fs/Impl/SaveDataMetaPolicy.cs index a3c9a394..28cf0fee 100644 --- a/src/LibHac/Fs/Impl/SaveDataMetaPolicy.cs +++ b/src/LibHac/Fs/Impl/SaveDataMetaPolicy.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using LibHac.Common; namespace LibHac.Fs.Impl { @@ -14,7 +14,7 @@ namespace LibHac.Fs.Impl public void GenerateMetaInfo(out SaveDataMetaInfo metaInfo) { - Unsafe.SkipInit(out metaInfo); + UnsafeHelpers.SkipParamInit(out metaInfo); if (_type == SaveDataType.Account || _type == SaveDataType.Device) { diff --git a/src/LibHac/Fs/InMemoryFileSystem.cs b/src/LibHac/Fs/InMemoryFileSystem.cs index 986fc15f..fde1e1b9 100644 --- a/src/LibHac/Fs/InMemoryFileSystem.cs +++ b/src/LibHac/Fs/InMemoryFileSystem.cs @@ -70,7 +70,7 @@ namespace LibHac.Fs protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); Result rs = FsTable.GetDirectory(new U8Span(path), out DirectoryNode dirNode); if (rs.IsFailure()) return rs; @@ -81,7 +81,7 @@ namespace LibHac.Fs protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Result rc = FsTable.GetFile(path, out FileNode fileNode); if (rc.IsFailure()) return rc; @@ -103,6 +103,8 @@ namespace LibHac.Fs protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { + UnsafeHelpers.SkipParamInit(out entryType); + if (FsTable.GetFile(path, out _).IsSuccess()) { entryType = DirectoryEntryType.File; @@ -115,7 +117,6 @@ namespace LibHac.Fs return Result.Success; } - entryType = default; return ResultFs.PathNotFound.Log(); } @@ -126,6 +127,8 @@ namespace LibHac.Fs protected override Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path) { + UnsafeHelpers.SkipParamInit(out attributes); + if (FsTable.GetFile(path, out FileNode file).IsSuccess()) { attributes = file.Attributes; @@ -138,7 +141,6 @@ namespace LibHac.Fs return Result.Success; } - attributes = default; return ResultFs.PathNotFound.Log(); } @@ -161,12 +163,13 @@ namespace LibHac.Fs protected override Result DoGetFileSize(out long fileSize, U8Span path) { + UnsafeHelpers.SkipParamInit(out fileSize); + if (FsTable.GetFile(path, out FileNode file).IsSuccess()) { return file.File.GetSize(out fileSize); } - fileSize = default; return ResultFs.PathNotFound.Log(); } @@ -346,7 +349,7 @@ namespace LibHac.Fs { if (offset > BaseStream.Length) { - bytesRead = default; + bytesRead = 0; return ResultFs.OutOfRange.Log(); } @@ -626,7 +629,7 @@ namespace LibHac.Fs Result rc = FindDirectory(parentPath, out DirectoryNode parentNode); if (rc.IsFailure()) { - file = default; + UnsafeHelpers.SkipParamInit(out file); return rc; } @@ -654,7 +657,7 @@ namespace LibHac.Fs if (!TryFindChildDirectory(currentDir, current, out DirectoryNode child)) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); return ResultFs.PathNotFound.Log(); } @@ -680,7 +683,7 @@ namespace LibHac.Fs currentChild = currentChild.Next; } - child = default; + UnsafeHelpers.SkipParamInit(out child); return false; } @@ -699,7 +702,7 @@ namespace LibHac.Fs currentChild = currentChild.Next; } - child = default; + UnsafeHelpers.SkipParamInit(out child); return false; } diff --git a/src/LibHac/Fs/PathTool.cs b/src/LibHac/Fs/PathTool.cs index 82a4b0d4..6e088f18 100644 --- a/src/LibHac/Fs/PathTool.cs +++ b/src/LibHac/Fs/PathTool.cs @@ -120,7 +120,7 @@ namespace LibHac.Fs public static Result Normalize(Span outputBuffer, out long normalizedLength, U8Span path, bool preserveUnc, bool hasMountName) { - normalizedLength = default; + UnsafeHelpers.SkipParamInit(out normalizedLength); U8Span path2 = path; int prefixLength = 0; @@ -318,7 +318,7 @@ namespace LibHac.Fs public static Result IsNormalized(out bool isNormalized, U8Span path, bool preserveUnc, bool hasMountName) { - isNormalized = default; + UnsafeHelpers.SkipParamInit(out isNormalized); U8Span path2 = path; bool isUncPath = false; @@ -478,7 +478,7 @@ namespace LibHac.Fs out long mountNameLength, U8Span path) { pathAfterMount = default; - mountNameLength = default; + UnsafeHelpers.SkipParamInit(out mountNameLength); int mountStart = IsSeparator(path.GetOrNull(0)) ? 1 : 0; int mountEnd; diff --git a/src/LibHac/Fs/SaveDataStructs.cs b/src/LibHac/Fs/SaveDataStructs.cs index bd1adae6..6c754a23 100644 --- a/src/LibHac/Fs/SaveDataStructs.cs +++ b/src/LibHac/Fs/SaveDataStructs.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; using LibHac.FsSrv.Impl; @@ -52,7 +51,7 @@ namespace LibHac.Fs public static Result Make(out SaveDataAttribute attribute, ProgramId programId, SaveDataType type, UserId userId, ulong staticSaveDataId, ushort index, SaveDataRank rank) { - Unsafe.SkipInit(out attribute); + UnsafeHelpers.SkipParamInit(out attribute); SaveDataAttribute tempAttribute = default; tempAttribute.ProgramId = programId; @@ -124,7 +123,7 @@ namespace LibHac.Fs public static Result Make(out SaveDataCreationInfo creationInfo, long size, long journalSize, ulong ownerId, SaveDataFlags flags, SaveDataSpaceId spaceId) { - Unsafe.SkipInit(out creationInfo); + UnsafeHelpers.SkipParamInit(out creationInfo); SaveDataCreationInfo tempCreationInfo = default; tempCreationInfo.Size = size; @@ -194,7 +193,7 @@ namespace LibHac.Fs public static Result Make(out SaveDataFilter filter, Optional programId, Optional saveType, Optional userId, Optional saveDataId, Optional index, SaveDataRank rank) { - Unsafe.SkipInit(out filter); + UnsafeHelpers.SkipParamInit(out filter); SaveDataFilter tempFilter = Make(programId, saveType, userId, saveDataId, index, rank); diff --git a/src/LibHac/Fs/Shim/Bis.cs b/src/LibHac/Fs/Shim/Bis.cs index e62cefdf..5ba8fd60 100644 --- a/src/LibHac/Fs/Shim/Bis.cs +++ b/src/LibHac/Fs/Shim/Bis.cs @@ -49,7 +49,8 @@ namespace LibHac.Fs.Shim } } - private static Result MountBis(this FileSystemClientImpl fs, U8Span mountName, BisPartitionId partitionId, U8Span rootPath) + private static Result MountBis(this FileSystemClientImpl fs, U8Span mountName, BisPartitionId partitionId, + U8Span rootPath) { Result rc; @@ -73,6 +74,7 @@ namespace LibHac.Fs.Shim { rc = Mount(fs, mountName, partitionId); } + fs.AbortIfNeeded(rc); if (rc.IsFailure()) return rc; @@ -192,7 +194,7 @@ namespace LibHac.Fs.Shim public static Result OpenBisPartition(this FileSystemClient fs, out IStorage partitionStorage, BisPartitionId partitionId) { - partitionStorage = default; + UnsafeHelpers.SkipParamInit(out partitionStorage); ReferenceCountedDisposable storage = null; try diff --git a/src/LibHac/Fs/Shim/Code.cs b/src/LibHac/Fs/Shim/Code.cs index 2502f1d9..eb69cadf 100644 --- a/src/LibHac/Fs/Shim/Code.cs +++ b/src/LibHac/Fs/Shim/Code.cs @@ -48,7 +48,7 @@ namespace LibHac.Fs.Shim static Result Mount(FileSystemClient fs, out CodeVerificationData verificationData, U8Span mountName, U8Span path, ProgramId programId) { - Unsafe.SkipInit(out verificationData); + UnsafeHelpers.SkipParamInit(out verificationData); Result rc = fs.Impl.CheckMountName(mountName); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Fs/Shim/GameCard.cs b/src/LibHac/Fs/Shim/GameCard.cs index 87b5f78a..17f9674b 100644 --- a/src/LibHac/Fs/Shim/GameCard.cs +++ b/src/LibHac/Fs/Shim/GameCard.cs @@ -70,7 +70,7 @@ namespace LibHac.Fs.Shim public static Result GetGameCardHandle(this FileSystemClient fs, out GameCardHandle handle) { - Unsafe.SkipInit(out handle); + UnsafeHelpers.SkipParamInit(out handle); using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); @@ -175,7 +175,7 @@ namespace LibHac.Fs.Shim public static Result OpenGameCardPartition(this FileSystemClient fs, out IStorage storage, GameCardHandle handle, GameCardPartitionRaw partitionType) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); diff --git a/src/LibHac/Fs/Shim/Host.cs b/src/LibHac/Fs/Shim/Host.cs index 0eb00010..ce0de63f 100644 --- a/src/LibHac/Fs/Shim/Host.cs +++ b/src/LibHac/Fs/Shim/Host.cs @@ -38,7 +38,7 @@ namespace LibHac.Fs.Shim private static Result OpenHostFileSystemImpl(FileSystemClient fs, out IFileSystem fileSystem, in FspPath path, MountHostOption option) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); @@ -130,7 +130,7 @@ namespace LibHac.Fs.Shim private static Result OpenHostFileSystem(FileSystemClient fs, out IFileSystem fileSystem, U8Span mountName, U8Span path, MountHostOption option) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); if (mountName.IsNull()) return ResultFs.NullptrArgument.Log(); @@ -196,7 +196,7 @@ namespace LibHac.Fs.Shim private static Result PreMountHost(FileSystemClient fs, out HostCommonMountNameGenerator nameGenerator, U8Span mountName, U8Span path) { - nameGenerator = default; + UnsafeHelpers.SkipParamInit(out nameGenerator); Result rc = fs.Impl.CheckMountName(mountName); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Fs/Shim/RightsId.cs b/src/LibHac/Fs/Shim/RightsId.cs index 0d8c1981..32cc0c94 100644 --- a/src/LibHac/Fs/Shim/RightsId.cs +++ b/src/LibHac/Fs/Shim/RightsId.cs @@ -18,7 +18,7 @@ namespace LibHac.Fs.Shim public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, U8Span path) { - rightsId = default; + UnsafeHelpers.SkipParamInit(out rightsId); using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); @@ -30,8 +30,7 @@ namespace LibHac.Fs.Shim public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, out byte keyGeneration, U8Span path) { - rightsId = default; - keyGeneration = default; + UnsafeHelpers.SkipParamInit(out rightsId, out keyGeneration); using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index d7b27149..752c72f0 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -65,7 +65,6 @@ namespace LibHac.Fs.Shim [SkipLocalsInit] public static class SaveDataManagement { - internal static Result ReadSaveDataFileSystemExtraData(this FileSystemClientImpl fs, out SaveDataExtraData extraData, ulong saveDataId) { @@ -112,7 +111,7 @@ namespace LibHac.Fs.Shim internal static Result FindSaveDataWithFilter(this FileSystemClientImpl fs, out SaveDataInfo saveInfo, SaveDataSpaceId spaceId, in SaveDataFilter filter) { - saveInfo = default; + UnsafeHelpers.SkipParamInit(out saveInfo); using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); @@ -285,7 +284,7 @@ namespace LibHac.Fs.Shim public static Result OpenSaveDataIterator(this FileSystemClientImpl fs, out SaveDataIterator iterator, SaveDataSpaceId spaceId) { - iterator = default; + UnsafeHelpers.SkipParamInit(out iterator); using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); @@ -308,7 +307,7 @@ namespace LibHac.Fs.Shim public static Result OpenSaveDataIterator(this FileSystemClientImpl fs, out SaveDataIterator iterator, SaveDataSpaceId spaceId, in SaveDataFilter filter) { - iterator = default; + UnsafeHelpers.SkipParamInit(out iterator); using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); @@ -725,7 +724,7 @@ namespace LibHac.Fs.Shim public static Result QuerySaveDataTotalSize(this FileSystemClientImpl fs, out long totalSize, long size, long journalSize) { - Unsafe.SkipInit(out totalSize); + UnsafeHelpers.SkipParamInit(out totalSize); using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); diff --git a/src/LibHac/Fs/Shim/SdCard.cs b/src/LibHac/Fs/Shim/SdCard.cs index 94c198f4..cc8e0036 100644 --- a/src/LibHac/Fs/Shim/SdCard.cs +++ b/src/LibHac/Fs/Shim/SdCard.cs @@ -24,7 +24,7 @@ namespace LibHac.Fs.Shim static Result OpenFileSystem(FileSystemClient fs, ReferenceCountedDisposable fsProxy, out ReferenceCountedDisposable fileSystem) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); // Retry a few times if the storage device isn't ready yet const int maxRetries = 10; @@ -153,7 +153,7 @@ namespace LibHac.Fs.Shim static Result CheckIfInserted(FileSystemClient fs, ReferenceCountedDisposable deviceOperator, out bool isInserted) { - Unsafe.SkipInit(out isInserted); + UnsafeHelpers.SkipParamInit(out isInserted); // Retry a few times if the storage device isn't ready yet const int maxRetries = 10; diff --git a/src/LibHac/Fs/SubStorage.cs b/src/LibHac/Fs/SubStorage.cs index 388a686b..06852146 100644 --- a/src/LibHac/Fs/SubStorage.cs +++ b/src/LibHac/Fs/SubStorage.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Diag; namespace LibHac.Fs @@ -194,7 +195,7 @@ namespace LibHac.Fs protected override Result DoGetSize(out long size) { - size = default; + UnsafeHelpers.SkipParamInit(out size); if (!IsValid()) return ResultFs.NotInitialized.Log(); diff --git a/src/LibHac/FsSrv/AccessFailureManagementService.cs b/src/LibHac/FsSrv/AccessFailureManagementService.cs index 5ffe1c24..fc273680 100644 --- a/src/LibHac/FsSrv/AccessFailureManagementService.cs +++ b/src/LibHac/FsSrv/AccessFailureManagementService.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Impl; using LibHac.FsSrv.Sf; @@ -25,7 +25,7 @@ namespace LibHac.FsSrv public Result OpenAccessFailureDetectionEventNotifier(out ReferenceCountedDisposable notifier, ulong processId, bool notifyOnDeepRetry) { - notifier = default; + UnsafeHelpers.SkipParamInit(out notifier); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -42,7 +42,7 @@ namespace LibHac.FsSrv public Result GetAccessFailureDetectionEvent(out NativeHandle eventHandle) { - eventHandle = default; + UnsafeHelpers.SkipParamInit(out eventHandle); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -58,7 +58,7 @@ namespace LibHac.FsSrv public Result IsAccessFailureDetected(out bool isDetected, ulong processId) { - Unsafe.SkipInit(out isDetected); + UnsafeHelpers.SkipParamInit(out isDetected); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSrv/BaseFileSystemService.cs b/src/LibHac/FsSrv/BaseFileSystemService.cs index 43371e76..d5492012 100644 --- a/src/LibHac/FsSrv/BaseFileSystemService.cs +++ b/src/LibHac/FsSrv/BaseFileSystemService.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Impl; using LibHac.FsSrv.Sf; @@ -57,7 +58,7 @@ namespace LibHac.FsSrv public Result OpenBaseFileSystem(out ReferenceCountedDisposable fileSystem, BaseFileSystemId fileSystemId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = CheckCapabilityById(fileSystemId, _processId); if (rc.IsFailure()) return rc; @@ -84,7 +85,7 @@ namespace LibHac.FsSrv public Result OpenBisFileSystem(out ReferenceCountedDisposable fileSystem, in FspPath rootPath, BisPartitionId partitionId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -170,7 +171,7 @@ namespace LibHac.FsSrv public Result OpenGameCardFileSystem(out ReferenceCountedDisposable fileSystem, GameCardHandle handle, GameCardPartition partitionId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -198,7 +199,7 @@ namespace LibHac.FsSrv public Result OpenSdCardFileSystem(out ReferenceCountedDisposable fileSystem) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -256,7 +257,7 @@ namespace LibHac.FsSrv public Result OpenImageDirectoryFileSystem(out ReferenceCountedDisposable fileSystem, ImageDirectoryId directoryId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); // Caller must have the MountImageAndVideoStorage permission Result rc = GetProgramInfo(out ProgramInfo programInfo); @@ -301,7 +302,7 @@ namespace LibHac.FsSrv public Result OpenBisWiper(out ReferenceCountedDisposable bisWiper, NativeHandle transferMemoryHandle, ulong transferMemorySize) { - bisWiper = default; + UnsafeHelpers.SkipParamInit(out bisWiper); // Caller must have the OpenBisWiper permission Result rc = GetProgramInfo(out ProgramInfo programInfo); diff --git a/src/LibHac/FsSrv/BaseFileSystemServiceImpl.cs b/src/LibHac/FsSrv/BaseFileSystemServiceImpl.cs index 431b27b3..678f77aa 100644 --- a/src/LibHac/FsSrv/BaseFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/BaseFileSystemServiceImpl.cs @@ -50,7 +50,7 @@ namespace LibHac.FsSrv public Result OpenBisFileSystem(out ReferenceCountedDisposable fileSystem, U8Span rootPath, BisPartitionId partitionId, bool caseSensitive) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = _config.BisFileSystemCreator.Create(out IFileSystem fs, rootPath.ToString(), partitionId); if (rc.IsFailure()) return rc; @@ -95,7 +95,7 @@ namespace LibHac.FsSrv public Result OpenSdCardProxyFileSystem(out ReferenceCountedDisposable fileSystem, bool openCaseSensitive) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); // Todo: Shared Result rc = _config.SdCardFileSystemCreator.Create(out IFileSystem fs, openCaseSensitive); diff --git a/src/LibHac/FsSrv/BaseStorageService.cs b/src/LibHac/FsSrv/BaseStorageService.cs index 56f9f301..e3428adf 100644 --- a/src/LibHac/FsSrv/BaseStorageService.cs +++ b/src/LibHac/FsSrv/BaseStorageService.cs @@ -1,5 +1,5 @@ using System; -using System.Runtime.CompilerServices; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Creators; using LibHac.FsSrv.Impl; @@ -23,7 +23,7 @@ namespace LibHac.FsSrv public Result OpenBisStorage(out ReferenceCountedDisposable storage, BisPartitionId id) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); var storageFlag = StorageType.Bis; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); @@ -73,7 +73,7 @@ namespace LibHac.FsSrv public Result OpenGameCardStorage(out ReferenceCountedDisposable storage, GameCardHandle handle, GameCardPartitionRaw partitionId) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -111,7 +111,7 @@ namespace LibHac.FsSrv public Result OpenSdCardDetectionEventNotifier(out ReferenceCountedDisposable eventNotifier) { - eventNotifier = default; + UnsafeHelpers.SkipParamInit(out eventNotifier); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -124,7 +124,7 @@ namespace LibHac.FsSrv public Result OpenGameCardDetectionEventNotifier(out ReferenceCountedDisposable eventNotifier) { - eventNotifier = default; + UnsafeHelpers.SkipParamInit(out eventNotifier); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -155,7 +155,7 @@ namespace LibHac.FsSrv private static Result GetAccessibilityForOpenBisPartition(out Accessibility accessibility, ProgramInfo programInfo, BisPartitionId partitionId) { - Unsafe.SkipInit(out accessibility); + UnsafeHelpers.SkipParamInit(out accessibility); AccessibilityType type = partitionId switch { @@ -228,7 +228,7 @@ namespace LibHac.FsSrv case GameCardPartitionRaw.RootWriteOnly: return Config.GameCardStorageCreator.CreateWriteOnly(handle, out storage); default: - storage = default; + UnsafeHelpers.SkipParamInit(out storage); return ResultFs.InvalidArgument.Log(); } } diff --git a/src/LibHac/FsSrv/Creators/EmulatedBisFileSystemCreator.cs b/src/LibHac/FsSrv/Creators/EmulatedBisFileSystemCreator.cs index 66575804..cafce4a6 100644 --- a/src/LibHac/FsSrv/Creators/EmulatedBisFileSystemCreator.cs +++ b/src/LibHac/FsSrv/Creators/EmulatedBisFileSystemCreator.cs @@ -56,7 +56,7 @@ namespace LibHac.FsSrv.Creators public Result Create(out IFileSystem fileSystem, string rootPath, BisPartitionId partitionId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); if (!IsValidPartitionId(partitionId)) return ResultFs.InvalidArgument.Log(); if (rootPath == null) return ResultFs.NullptrArgument.Log(); @@ -91,7 +91,7 @@ namespace LibHac.FsSrv.Creators public Result Create(out ReferenceCountedDisposable fileSystem, U8Span rootPath, BisPartitionId partitionId, bool caseSensitive) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); if (!IsValidPartitionId(partitionId)) return ResultFs.InvalidArgument.Log(); if (rootPath.IsNull()) return ResultFs.NullptrArgument.Log(); @@ -136,7 +136,7 @@ namespace LibHac.FsSrv.Creators public Result CreateFatFileSystem(out IFileSystem fileSystem, BisPartitionId partitionId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return ResultFs.NotImplemented.Log(); } diff --git a/src/LibHac/FsSrv/Creators/EmulatedBisFileSystemCreatorConfig.cs b/src/LibHac/FsSrv/Creators/EmulatedBisFileSystemCreatorConfig.cs index 64172069..a21760b2 100644 --- a/src/LibHac/FsSrv/Creators/EmulatedBisFileSystemCreatorConfig.cs +++ b/src/LibHac/FsSrv/Creators/EmulatedBisFileSystemCreatorConfig.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -41,7 +42,7 @@ namespace LibHac.FsSrv.Creators { if (!IsValidPartitionId(partitionId)) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return false; } @@ -54,7 +55,7 @@ namespace LibHac.FsSrv.Creators { if (!IsValidPartitionId(partitionId)) { - path = default; + UnsafeHelpers.SkipParamInit(out path); return false; } diff --git a/src/LibHac/FsSrv/Creators/EmulatedGameCardFsCreator.cs b/src/LibHac/FsSrv/Creators/EmulatedGameCardFsCreator.cs index 39312d05..1ed4f3e2 100644 --- a/src/LibHac/FsSrv/Creators/EmulatedGameCardFsCreator.cs +++ b/src/LibHac/FsSrv/Creators/EmulatedGameCardFsCreator.cs @@ -1,4 +1,5 @@ -using LibHac.Fs; +using LibHac.Common; +using LibHac.Fs; using LibHac.Fs.Fsa; namespace LibHac.FsSrv.Creators @@ -19,7 +20,7 @@ namespace LibHac.FsSrv.Creators { // Use the old xci code temporarily - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GameCard.GetXci(out Xci xci, handle); if (rc.IsFailure()) return rc; @@ -37,7 +38,7 @@ namespace LibHac.FsSrv.Creators { // Use the old xci code temporarily - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GameCard.GetXci(out Xci xci, handle); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSrv/Creators/EmulatedGameCardStorageCreator.cs b/src/LibHac/FsSrv/Creators/EmulatedGameCardStorageCreator.cs index 893b43b1..e5f1be57 100644 --- a/src/LibHac/FsSrv/Creators/EmulatedGameCardStorageCreator.cs +++ b/src/LibHac/FsSrv/Creators/EmulatedGameCardStorageCreator.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Fs; namespace LibHac.FsSrv.Creators @@ -14,7 +15,7 @@ namespace LibHac.FsSrv.Creators public Result CreateReadOnly(GameCardHandle handle, out ReferenceCountedDisposable storage) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); if (GameCard.IsGameCardHandleInvalid(handle)) { @@ -33,7 +34,7 @@ namespace LibHac.FsSrv.Creators public Result CreateSecureReadOnly(GameCardHandle handle, out ReferenceCountedDisposable storage) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); if (GameCard.IsGameCardHandleInvalid(handle)) { @@ -82,7 +83,8 @@ namespace LibHac.FsSrv.Creators Handle = handle; } - public ReadOnlyGameCardStorage(EmulatedGameCard gameCard, GameCardHandle handle, ReadOnlySpan deviceId, ReadOnlySpan imageHash) + public ReadOnlyGameCardStorage(EmulatedGameCard gameCard, GameCardHandle handle, + ReadOnlySpan deviceId, ReadOnlySpan imageHash) { GameCard = gameCard; Handle = handle; @@ -116,7 +118,7 @@ namespace LibHac.FsSrv.Creators protected override Result DoGetSize(out long size) { - size = 0; + UnsafeHelpers.SkipParamInit(out size); Result rc = GameCard.GetCardInfo(out GameCardInfo info, Handle); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSrv/Creators/EmulatedSdCardFileSystemCreator.cs b/src/LibHac/FsSrv/Creators/EmulatedSdCardFileSystemCreator.cs index 15935d0a..d7140fb0 100644 --- a/src/LibHac/FsSrv/Creators/EmulatedSdCardFileSystemCreator.cs +++ b/src/LibHac/FsSrv/Creators/EmulatedSdCardFileSystemCreator.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -29,7 +30,7 @@ namespace LibHac.FsSrv.Creators public Result Create(out IFileSystem fileSystem, bool isCaseSensitive) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); if (!SdCard.IsSdCardInserted()) { diff --git a/src/LibHac/FsSrv/Creators/EncryptedFileSystemCreator.cs b/src/LibHac/FsSrv/Creators/EncryptedFileSystemCreator.cs index c3d2798c..1cbf9330 100644 --- a/src/LibHac/FsSrv/Creators/EncryptedFileSystemCreator.cs +++ b/src/LibHac/FsSrv/Creators/EncryptedFileSystemCreator.cs @@ -1,4 +1,5 @@ -using LibHac.Common.Keys; +using LibHac.Common; +using LibHac.Common.Keys; using LibHac.Fs; using LibHac.Fs.Fsa; using LibHac.FsSystem; @@ -17,7 +18,7 @@ namespace LibHac.FsSrv.Creators public Result Create(out ReferenceCountedDisposable encryptedFileSystem, ReferenceCountedDisposable baseFileSystem, EncryptedFsKeyId keyId, in EncryptionSeed encryptionSeed) { - encryptedFileSystem = default; + UnsafeHelpers.SkipParamInit(out encryptedFileSystem); if (keyId < EncryptedFsKeyId.Save || keyId > EncryptedFsKeyId.CustomStorage) { diff --git a/src/LibHac/FsSrv/Creators/PartitionFileSystemCreator.cs b/src/LibHac/FsSrv/Creators/PartitionFileSystemCreator.cs index d6506994..aee3c74a 100644 --- a/src/LibHac/FsSrv/Creators/PartitionFileSystemCreator.cs +++ b/src/LibHac/FsSrv/Creators/PartitionFileSystemCreator.cs @@ -1,4 +1,5 @@ -using LibHac.Fs; +using LibHac.Common; +using LibHac.Fs; using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.Detail; @@ -14,7 +15,7 @@ namespace LibHac.FsSrv.Creators Result rc = partitionFs.Initialize(pFsStorage); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -29,7 +30,7 @@ namespace LibHac.FsSrv.Creators Result rc = partitionFs.Initialize(pFsStorage); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } diff --git a/src/LibHac/FsSrv/Creators/SaveDataFileSystemCreator.cs b/src/LibHac/FsSrv/Creators/SaveDataFileSystemCreator.cs index 6bcc3d01..86503fda 100644 --- a/src/LibHac/FsSrv/Creators/SaveDataFileSystemCreator.cs +++ b/src/LibHac/FsSrv/Creators/SaveDataFileSystemCreator.cs @@ -27,8 +27,7 @@ namespace LibHac.FsSrv.Creators ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac, SaveDataType type, ITimeStampGenerator timeStampGenerator) { - fileSystem = default; - extraDataAccessor = default; + UnsafeHelpers.SkipParamInit(out fileSystem, out extraDataAccessor); var saveDataPath = $"/{saveDataId:x16}".ToU8String(); diff --git a/src/LibHac/FsSrv/Creators/StorageOnNcaCreator.cs b/src/LibHac/FsSrv/Creators/StorageOnNcaCreator.cs index d8b5b49c..f51d4eb8 100644 --- a/src/LibHac/FsSrv/Creators/StorageOnNcaCreator.cs +++ b/src/LibHac/FsSrv/Creators/StorageOnNcaCreator.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Common.Keys; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -23,8 +24,7 @@ namespace LibHac.FsSrv.Creators public Result Create(out ReferenceCountedDisposable storage, out NcaFsHeader fsHeader, Nca nca, int fsIndex, bool isCodeFs) { - storage = default; - fsHeader = default; + UnsafeHelpers.SkipParamInit(out storage, out fsHeader); Result rc = OpenStorage(out IStorage storageTemp, nca, fsIndex); if (rc.IsFailure()) return rc; @@ -67,7 +67,7 @@ namespace LibHac.FsSrv.Creators private Result OpenStorage(out IStorage storage, Nca nca, int fsIndex) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); if (!nca.SectionExists(fsIndex)) return ResultFs.PartitionNotFound.Log(); diff --git a/src/LibHac/FsSrv/Creators/SubDirectoryFileSystemCreator.cs b/src/LibHac/FsSrv/Creators/SubDirectoryFileSystemCreator.cs index 3d837daf..26774529 100644 --- a/src/LibHac/FsSrv/Creators/SubDirectoryFileSystemCreator.cs +++ b/src/LibHac/FsSrv/Creators/SubDirectoryFileSystemCreator.cs @@ -15,7 +15,7 @@ namespace LibHac.FsSrv.Creators public Result Create(out ReferenceCountedDisposable subDirFileSystem, ref ReferenceCountedDisposable baseFileSystem, U8Span path, bool preserveUnc) { - subDirFileSystem = default; + UnsafeHelpers.SkipParamInit(out subDirFileSystem); // Verify the sub-path exists Result rc = baseFileSystem.Target.OpenDirectory(out IDirectory _, path, OpenDirectoryMode.Directory); diff --git a/src/LibHac/FsSrv/EmulatedDeviceOperator.cs b/src/LibHac/FsSrv/EmulatedDeviceOperator.cs index 1870e2eb..1c195108 100644 --- a/src/LibHac/FsSrv/EmulatedDeviceOperator.cs +++ b/src/LibHac/FsSrv/EmulatedDeviceOperator.cs @@ -1,4 +1,5 @@ -using LibHac.Fs; +using LibHac.Common; +using LibHac.Fs; using LibHac.FsSrv.Sf; namespace LibHac.FsSrv @@ -30,11 +31,10 @@ namespace LibHac.FsSrv public Result GetGameCardHandle(out GameCardHandle handle) { + UnsafeHelpers.SkipParamInit(out handle); + if (!GameCard.IsGameCardInserted()) - { - handle = default; return ResultFs.GameCardNotInsertedOnGetHandle.Log(); - } handle = GameCard.GetGameCardHandle(); return Result.Success; diff --git a/src/LibHac/FsSrv/EmulatedGameCard.cs b/src/LibHac/FsSrv/EmulatedGameCard.cs index 2c22a7ae..63f602bd 100644 --- a/src/LibHac/FsSrv/EmulatedGameCard.cs +++ b/src/LibHac/FsSrv/EmulatedGameCard.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Common.Keys; using LibHac.Fs; @@ -51,10 +52,10 @@ namespace LibHac.FsSrv Handle++; } } - + internal Result GetXci(out Xci xci, GameCardHandle handle) { - xci = default; + UnsafeHelpers.SkipParamInit(out xci); if (IsGameCardHandleInvalid(handle)) return ResultFs.InvalidGameCardHandleOnRead.Log(); if (!IsGameCardInserted()) return ResultFs.GameCardNotInserted.Log(); @@ -93,7 +94,7 @@ namespace LibHac.FsSrv internal Result GetCardInfo(out GameCardInfo cardInfo, GameCardHandle handle) { - cardInfo = default; + UnsafeHelpers.SkipParamInit(out cardInfo); if (IsGameCardHandleInvalid(handle)) return ResultFs.InvalidGameCardHandleOnGetCardInfo.Log(); if (!IsGameCardInserted()) return ResultFs.GameCardNotInserted.Log(); diff --git a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs index ae25841f..08da2129 100644 --- a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs @@ -29,7 +29,7 @@ namespace LibHac.FsSrv public Result OpenCustomStorageFileSystem(out ReferenceCountedDisposable fileSystem, CustomStorageId storageId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); ReferenceCountedDisposable tempFs = null; ReferenceCountedDisposable encryptedFs = null; @@ -91,7 +91,7 @@ namespace LibHac.FsSrv public Result OpenHostFileSystem(out ReferenceCountedDisposable fileSystem, U8Span path, bool openCaseSensitive) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc; if (!path.IsEmpty()) diff --git a/src/LibHac/FsSrv/FileSystemProxyImpl.cs b/src/LibHac/FsSrv/FileSystemProxyImpl.cs index 7d805f7e..3b590ad9 100644 --- a/src/LibHac/FsSrv/FileSystemProxyImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyImpl.cs @@ -1,5 +1,4 @@ -using System.Runtime.CompilerServices; -using LibHac.Common; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Impl; using LibHac.FsSrv.Sf; @@ -85,7 +84,7 @@ namespace LibHac.FsSrv { if (NcaFsService is null) { - ncaFsService = null; + UnsafeHelpers.SkipParamInit(out ncaFsService); return ResultFs.PreconditionViolation.Log(); } @@ -97,7 +96,7 @@ namespace LibHac.FsSrv { if (SaveFsService is null) { - saveFsService = null; + UnsafeHelpers.SkipParamInit(out saveFsService); return ResultFs.PreconditionViolation.Log(); } @@ -146,7 +145,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -159,7 +158,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -169,12 +168,12 @@ namespace LibHac.FsSrv public Result OpenCodeFileSystem(out ReferenceCountedDisposable fileSystem, out CodeVerificationData verificationData, in FspPath path, ProgramId programId) { - Unsafe.SkipInit(out verificationData); + UnsafeHelpers.SkipParamInit(out verificationData); Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -194,7 +193,7 @@ namespace LibHac.FsSrv public Result GetFreeSpaceSizeForSaveData(out long freeSpaceSize, SaveDataSpaceId spaceId) { - Unsafe.SkipInit(out freeSpaceSize); + UnsafeHelpers.SkipParamInit(out freeSpaceSize); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -207,7 +206,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -220,7 +219,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -232,7 +231,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); return rc; } @@ -245,7 +244,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); return rc; } @@ -258,7 +257,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); return rc; } @@ -267,7 +266,7 @@ namespace LibHac.FsSrv public Result OpenPatchDataStorageByCurrentProcess(out ReferenceCountedDisposable storage) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); return ResultFs.TargetNotFound.Log(); } @@ -277,7 +276,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -290,7 +289,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); return rc; } @@ -381,7 +380,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -394,7 +393,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -407,7 +406,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -516,7 +515,7 @@ namespace LibHac.FsSrv public Result OpenHostFileSystemWithOption(out ReferenceCountedDisposable fileSystem, in FspPath path, MountHostOption option) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -599,7 +598,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - eventNotifier = null; + UnsafeHelpers.SkipParamInit(out eventNotifier); return rc; } @@ -619,7 +618,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - infoReader = default; + UnsafeHelpers.SkipParamInit(out infoReader); return rc; } @@ -632,7 +631,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - infoReader = default; + UnsafeHelpers.SkipParamInit(out infoReader); return rc; } @@ -645,7 +644,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - infoReader = default; + UnsafeHelpers.SkipParamInit(out infoReader); return rc; } @@ -655,7 +654,7 @@ namespace LibHac.FsSrv public Result FindSaveDataWithFilter(out long count, OutBuffer saveDataInfoBuffer, SaveDataSpaceId spaceId, in SaveDataFilter filter) { - Unsafe.SkipInit(out count); + UnsafeHelpers.SkipParamInit(out count); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -669,7 +668,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -678,7 +677,7 @@ namespace LibHac.FsSrv public Result QuerySaveDataInternalStorageTotalSize(out long size, SaveDataSpaceId spaceId, ulong saveDataId) { - Unsafe.SkipInit(out size); + UnsafeHelpers.SkipParamInit(out size); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -688,7 +687,7 @@ namespace LibHac.FsSrv public Result GetSaveDataCommitId(out long commitId, SaveDataSpaceId spaceId, ulong saveDataId) { - Unsafe.SkipInit(out commitId); + UnsafeHelpers.SkipParamInit(out commitId); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -702,7 +701,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - infoReader = default; + UnsafeHelpers.SkipParamInit(out infoReader); return rc; } @@ -715,7 +714,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - file = default; + UnsafeHelpers.SkipParamInit(out file); return rc; } @@ -732,8 +731,7 @@ namespace LibHac.FsSrv public Result GetCacheStorageSize(out long dataSize, out long journalSize, ushort index) { - Unsafe.SkipInit(out dataSize); - Unsafe.SkipInit(out journalSize); + UnsafeHelpers.SkipParamInit(out dataSize, out journalSize); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -743,7 +741,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataTransferManager(out ReferenceCountedDisposable manager) { - manager = default; + UnsafeHelpers.SkipParamInit(out manager); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -754,7 +752,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataTransferManagerVersion2( out ReferenceCountedDisposable manager) { - manager = default; + UnsafeHelpers.SkipParamInit(out manager); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -765,7 +763,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataTransferManagerForSaveDataRepair( out ReferenceCountedDisposable manager) { - manager = default; + UnsafeHelpers.SkipParamInit(out manager); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -776,7 +774,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataTransferManagerForRepair( out ReferenceCountedDisposable manager) { - manager = default; + UnsafeHelpers.SkipParamInit(out manager); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -787,7 +785,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataTransferProhibiter( out ReferenceCountedDisposable prohibiter, Ncm.ApplicationId applicationId) { - prohibiter = default; + UnsafeHelpers.SkipParamInit(out prohibiter); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -798,7 +796,7 @@ namespace LibHac.FsSrv public Result ListAccessibleSaveDataOwnerId(out int readCount, OutBuffer idBuffer, ProgramId programId, int startIndex, int bufferIdCount) { - Unsafe.SkipInit(out readCount); + UnsafeHelpers.SkipParamInit(out readCount); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -814,7 +812,7 @@ namespace LibHac.FsSrv Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) { - saveMover = default; + UnsafeHelpers.SkipParamInit(out saveMover); return rc; } @@ -849,7 +847,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - fileSystem = null; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -859,7 +857,7 @@ namespace LibHac.FsSrv public Result OpenCloudBackupWorkStorageFileSystem(out ReferenceCountedDisposable fileSystem, CloudBackupWorkStorageId storageId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); var storageFlag = StorageType.NonGameCard; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); @@ -893,7 +891,7 @@ namespace LibHac.FsSrv public Result OpenCustomStorageFileSystem(out ReferenceCountedDisposable fileSystem, CustomStorageId storageId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); var storageFlag = StorageType.NonGameCard; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); @@ -935,7 +933,7 @@ namespace LibHac.FsSrv public Result IsArchivedProgram(out bool isArchived, ulong processId) { - Unsafe.SkipInit(out isArchived); + UnsafeHelpers.SkipParamInit(out isArchived); Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) return rc; @@ -945,7 +943,7 @@ namespace LibHac.FsSrv public Result QuerySaveDataTotalSize(out long totalSize, long dataSize, long journalSize) { - Unsafe.SkipInit(out totalSize); + UnsafeHelpers.SkipParamInit(out totalSize); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -960,7 +958,7 @@ namespace LibHac.FsSrv public Result GetRightsId(out RightsId rightsId, ProgramId programId, StorageId storageId) { - Unsafe.SkipInit(out rightsId); + UnsafeHelpers.SkipParamInit(out rightsId); Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) return rc; @@ -975,8 +973,7 @@ namespace LibHac.FsSrv public Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in FspPath path) { - Unsafe.SkipInit(out rightsId); - Unsafe.SkipInit(out keyGeneration); + UnsafeHelpers.SkipParamInit(out rightsId, out keyGeneration); Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) return rc; @@ -1146,7 +1143,7 @@ namespace LibHac.FsSrv Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (rc.IsFailure()) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); return rc; } @@ -1181,7 +1178,7 @@ namespace LibHac.FsSrv public Result IsSdCardAccessible(out bool isAccessible) { - Unsafe.SkipInit(out isAccessible); + UnsafeHelpers.SkipParamInit(out isAccessible); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; @@ -1218,7 +1215,7 @@ namespace LibHac.FsSrv public Result OpenMultiCommitManager(out ReferenceCountedDisposable commitManager) { - commitManager = null; + UnsafeHelpers.SkipParamInit(out commitManager); Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSrv/Impl/DirectoryInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/DirectoryInterfaceAdapter.cs index 8f17291e..51c64467 100644 --- a/src/LibHac/FsSrv/Impl/DirectoryInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/DirectoryInterfaceAdapter.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using LibHac.Common; using LibHac.Fs; using LibHac.Sf; using IDirectory = LibHac.Fs.Fsa.IDirectory; @@ -23,7 +24,7 @@ namespace LibHac.FsSrv.Impl public Result Read(out long entriesRead, OutBuffer entryBuffer) { const int maxTryCount = 2; - entriesRead = default; + UnsafeHelpers.SkipParamInit(out entriesRead); Span entries = MemoryMarshal.Cast(entryBuffer.Buffer); @@ -47,7 +48,7 @@ namespace LibHac.FsSrv.Impl public Result GetEntryCount(out long entryCount) { - entryCount = default; + UnsafeHelpers.SkipParamInit(out entryCount); Result rc = BaseDirectory.GetEntryCount(out long tmpEntryCount); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSrv/Impl/FileInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/FileInterfaceAdapter.cs index 56a574f5..5394d0ec 100644 --- a/src/LibHac/FsSrv/Impl/FileInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/FileInterfaceAdapter.cs @@ -23,7 +23,7 @@ namespace LibHac.FsSrv.Impl public Result Read(out long bytesRead, long offset, Span destination, ReadOption option) { const int maxTryCount = 2; - bytesRead = default; + UnsafeHelpers.SkipParamInit(out bytesRead); if (offset < 0) return ResultFs.InvalidOffset.Log(); @@ -78,7 +78,7 @@ namespace LibHac.FsSrv.Impl public Result GetSize(out long size) { const int maxTryCount = 2; - size = default; + UnsafeHelpers.SkipParamInit(out size); Result rc = Result.Success; long tmpSize = 0; @@ -100,7 +100,8 @@ namespace LibHac.FsSrv.Impl public Result OperateRange(out QueryRangeInfo rangeInfo, int operationId, long offset, long size) { - rangeInfo = new QueryRangeInfo(); + UnsafeHelpers.SkipParamInit(out rangeInfo); + rangeInfo.Clear(); if (operationId == (int)OperationId.InvalidateCache) { diff --git a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs index 585ae865..851d7464 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs @@ -163,7 +163,7 @@ namespace LibHac.FsSrv.Impl public Result GetEntryType(out uint entryType, in Path path) { - entryType = default; + UnsafeHelpers.SkipParamInit(out entryType); var normalizer = new PathNormalizer(new U8Span(path.Str), GetPathNormalizerOption()); if (normalizer.Result.IsFailure()) return normalizer.Result; @@ -176,7 +176,7 @@ namespace LibHac.FsSrv.Impl public Result OpenFile(out ReferenceCountedDisposable file, in Path path, uint mode) { const int maxTryCount = 2; - file = default; + UnsafeHelpers.SkipParamInit(out file); var normalizer = new PathNormalizer(new U8Span(path.Str), GetPathNormalizerOption()); if (normalizer.Result.IsFailure()) return normalizer.Result; @@ -205,7 +205,7 @@ namespace LibHac.FsSrv.Impl public Result OpenDirectory(out ReferenceCountedDisposable directory, in Path path, uint mode) { const int maxTryCount = 2; - directory = default; + UnsafeHelpers.SkipParamInit(out directory); var normalizer = new PathNormalizer(new U8Span(path.Str), GetPathNormalizerOption()); if (normalizer.Result.IsFailure()) return normalizer.Result; @@ -238,7 +238,7 @@ namespace LibHac.FsSrv.Impl public Result GetFreeSpaceSize(out long freeSpace, in Path path) { - freeSpace = default; + UnsafeHelpers.SkipParamInit(out freeSpace); var normalizer = new PathNormalizer(new U8Span(path.Str), GetPathNormalizerOption()); if (normalizer.Result.IsFailure()) return normalizer.Result; @@ -248,7 +248,7 @@ namespace LibHac.FsSrv.Impl public Result GetTotalSpaceSize(out long totalSpace, in Path path) { - totalSpace = default; + UnsafeHelpers.SkipParamInit(out totalSpace); var normalizer = new PathNormalizer(new U8Span(path.Str), GetPathNormalizerOption()); if (normalizer.Result.IsFailure()) return normalizer.Result; @@ -266,7 +266,7 @@ namespace LibHac.FsSrv.Impl public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) { - timeStamp = default; + UnsafeHelpers.SkipParamInit(out timeStamp); var normalizer = new PathNormalizer(new U8Span(path.Str), GetPathNormalizerOption()); if (normalizer.Result.IsFailure()) return normalizer.Result; diff --git a/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs b/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs index 5d9a5bd7..bf98f713 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs @@ -1,4 +1,4 @@ -using System.Runtime.CompilerServices; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Sf; using LibHac.Ncm; @@ -44,7 +44,7 @@ namespace LibHac.FsSrv.Impl public Result IsArchivedProgram(out bool isArchived, ulong processId) { - Unsafe.SkipInit(out isArchived); + UnsafeHelpers.SkipParamInit(out isArchived); return ResultFs.PortAcceptableCountLimited.Log(); } @@ -52,8 +52,7 @@ namespace LibHac.FsSrv.Impl public Result OpenCodeFileSystem(out ReferenceCountedDisposable fileSystem, out CodeVerificationData verificationData, in FspPath path, ProgramId programId) { - fileSystem = default; - Unsafe.SkipInit(out verificationData); + UnsafeHelpers.SkipParamInit(out fileSystem, out verificationData); return ResultFs.PortAcceptableCountLimited.Log(); } diff --git a/src/LibHac/FsSrv/Impl/LocationResolverSet.cs b/src/LibHac/FsSrv/Impl/LocationResolverSet.cs index 9a454c33..7e721d65 100644 --- a/src/LibHac/FsSrv/Impl/LocationResolverSet.cs +++ b/src/LibHac/FsSrv/Impl/LocationResolverSet.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Diag; using LibHac.Fs; using LibHac.Lr; @@ -27,7 +28,7 @@ namespace LibHac.FsSrv.Impl private Result GetLocationResolver(out LocationResolver resolver, StorageId storageId) { - resolver = default; + UnsafeHelpers.SkipParamInit(out resolver); if (!IsValidStorageId(storageId)) return ResultLr.LocationResolverNotFound.Log(); @@ -52,7 +53,7 @@ namespace LibHac.FsSrv.Impl if (rc.IsFailure()) { lr?.Dispose(); - resolver = default; + UnsafeHelpers.SkipParamInit(out resolver); return rc; } @@ -69,7 +70,7 @@ namespace LibHac.FsSrv.Impl Result rc = Hos.Lr.OpenAddOnContentLocationResolver(out AddOnContentLocationResolver lr); if (rc.IsFailure()) { - resolver = default; + UnsafeHelpers.SkipParamInit(out resolver); return rc; } diff --git a/src/LibHac/FsSrv/Impl/ProgramRegistryManager.cs b/src/LibHac/FsSrv/Impl/ProgramRegistryManager.cs index f81b9ab9..f872c83d 100644 --- a/src/LibHac/FsSrv/Impl/ProgramRegistryManager.cs +++ b/src/LibHac/FsSrv/Impl/ProgramRegistryManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using LibHac.Common; using LibHac.Fs; using LibHac.Ncm; @@ -119,7 +120,7 @@ namespace LibHac.FsSrv.Impl } } - programInfo = default; + UnsafeHelpers.SkipParamInit(out programInfo); return ResultFs.TargetProgramNotFound.Log(); } } @@ -145,7 +146,7 @@ namespace LibHac.FsSrv.Impl } } - programInfo = default; + UnsafeHelpers.SkipParamInit(out programInfo); return ResultFs.TargetProgramNotFound.Log(); } } diff --git a/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs index fb838295..d59b50cd 100644 --- a/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs @@ -84,7 +84,8 @@ namespace LibHac.FsSrv.Impl public Result OperateRange(out QueryRangeInfo rangeInfo, int operationId, long offset, long size) { - rangeInfo = new QueryRangeInfo(); + UnsafeHelpers.SkipParamInit(out rangeInfo); + rangeInfo.Clear(); if (operationId == (int)OperationId.InvalidateCache) { diff --git a/src/LibHac/FsSrv/Impl/Utility.cs b/src/LibHac/FsSrv/Impl/Utility.cs index 88f96915..e105a43e 100644 --- a/src/LibHac/FsSrv/Impl/Utility.cs +++ b/src/LibHac/FsSrv/Impl/Utility.cs @@ -124,7 +124,7 @@ namespace LibHac.FsSrv.Impl public static Result CreateSubDirectoryFileSystem(out ReferenceCountedDisposable subDirFileSystem, ref ReferenceCountedDisposable baseFileSystem, U8Span subPath, bool preserveUnc = false) { - subDirFileSystem = default; + UnsafeHelpers.SkipParamInit(out subDirFileSystem); // Check if the directory exists Result rc = baseFileSystem.Target.OpenDirectory(out IDirectory dir, subPath, OpenDirectoryMode.Directory); @@ -146,7 +146,7 @@ namespace LibHac.FsSrv.Impl public static Result WrapSubDirectory(out ReferenceCountedDisposable fileSystem, ref ReferenceCountedDisposable baseFileSystem, U8Span path, bool createIfMissing) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); // The path must already exist if we're not automatically creating it if (!createIfMissing) diff --git a/src/LibHac/FsSrv/NcaFileSystemService.cs b/src/LibHac/FsSrv/NcaFileSystemService.cs index 172f9378..71dde3fc 100644 --- a/src/LibHac/FsSrv/NcaFileSystemService.cs +++ b/src/LibHac/FsSrv/NcaFileSystemService.cs @@ -60,7 +60,7 @@ namespace LibHac.FsSrv public Result OpenFileSystemWithPatch(out ReferenceCountedDisposable fileSystem, ProgramId programId, FileSystemProxyType fsType) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); const StorageType storageFlag = StorageType.All; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); @@ -202,7 +202,7 @@ namespace LibHac.FsSrv public Result OpenFileSystemWithId(out ReferenceCountedDisposable fileSystem, in FspPath path, ulong id, FileSystemProxyType fsType) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -287,7 +287,7 @@ namespace LibHac.FsSrv public Result OpenDataFileSystemWithProgramIndex(out ReferenceCountedDisposable fileSystem, byte programIndex) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -335,7 +335,7 @@ namespace LibHac.FsSrv public Result GetRightsId(out RightsId rightsId, ProgramId programId, StorageId storageId) { - Unsafe.SkipInit(out rightsId); + UnsafeHelpers.SkipParamInit(out rightsId); using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.All); @@ -360,8 +360,7 @@ namespace LibHac.FsSrv public Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in FspPath path) { - Unsafe.SkipInit(out rightsId); - Unsafe.SkipInit(out keyGeneration); + UnsafeHelpers.SkipParamInit(out rightsId, out keyGeneration); using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.All); @@ -386,8 +385,7 @@ namespace LibHac.FsSrv private Result OpenDataFileSystemCore(out ReferenceCountedDisposable fileSystem, out bool isHostFs, ulong programId, StorageId storageId) { - fileSystem = default; - Unsafe.SkipInit(out isHostFs); + UnsafeHelpers.SkipParamInit(out fileSystem, out isHostFs); if (Unsafe.IsNullRef(ref isHostFs)) return ResultFs.NullptrArgument.Log(); @@ -424,7 +422,7 @@ namespace LibHac.FsSrv public Result OpenContentStorageFileSystem(out ReferenceCountedDisposable fileSystem, ContentStorageId contentStorageId) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); StorageType storageFlag = contentStorageId == ContentStorageId.System ? StorageType.Bis : StorageType.All; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); @@ -511,7 +509,7 @@ namespace LibHac.FsSrv public Result OpenRegisteredUpdatePartition(out ReferenceCountedDisposable fileSystem) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); var storageFlag = StorageType.All; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); diff --git a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs index fd7e94c8..2415c381 100644 --- a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs @@ -75,9 +75,8 @@ namespace LibHac.FsSrv out CodeVerificationData verificationData, U8Span path, FileSystemProxyType type, bool canMountSystemDataPrivate, ulong id) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem, out verificationData); - Unsafe.SkipInit(out verificationData); if (!Unsafe.IsNullRef(ref verificationData)) verificationData.IsValid = false; @@ -201,7 +200,7 @@ namespace LibHac.FsSrv public Result OpenFileSystemWithPatch(out ReferenceCountedDisposable fileSystem, U8Span originalNcaPath, U8Span currentNcaPath, FileSystemProxyType fsType, ulong id) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); ReferenceCountedDisposable romFsStorage = null; try @@ -223,12 +222,11 @@ namespace LibHac.FsSrv { const int storagePathMaxLen = 0x40; - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); ReferenceCountedDisposable baseFileSystem = null; ReferenceCountedDisposable subDirFileSystem = null; ReferenceCountedDisposable encryptedFileSystem = null; - try { Result rc; @@ -341,7 +339,7 @@ namespace LibHac.FsSrv private Result ParseMountName(ref U8Span path, out ReferenceCountedDisposable fileSystem, out bool shouldContinue, out MountInfo info) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); info = new MountInfo(); shouldContinue = true; @@ -505,7 +503,7 @@ namespace LibHac.FsSrv private Result CheckDirOrNcaOrNsp(ref U8Span path, out bool isDirectory) { - isDirectory = default; + UnsafeHelpers.SkipParamInit(out isDirectory); ReadOnlySpan mountSeparator = new[] { (byte)':', (byte)'/' }; @@ -546,7 +544,7 @@ namespace LibHac.FsSrv out ReferenceCountedDisposable contentFileSystem, ref ReferenceCountedDisposable baseFileSystem, FileSystemProxyType fsType, bool preserveUnc) { - contentFileSystem = default; + UnsafeHelpers.SkipParamInit(out contentFileSystem); ReferenceCountedDisposable subDirFs = null; try @@ -566,7 +564,7 @@ namespace LibHac.FsSrv out ReferenceCountedDisposable contentFileSystem, ref ReferenceCountedDisposable baseFileSystem, U8Span path) { - contentFileSystem = default; + UnsafeHelpers.SkipParamInit(out contentFileSystem); Unsafe.SkipInit(out FsPath fullPath); var sb = new U8StringBuilder(fullPath.Str); @@ -594,7 +592,7 @@ namespace LibHac.FsSrv private Result ParseNsp(ref U8Span path, out ReferenceCountedDisposable fileSystem, ReferenceCountedDisposable baseFileSystem) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); ReadOnlySpan nspExtension = new[] { (byte)'.', (byte)'n', (byte)'s', (byte)'p' }; @@ -653,7 +651,7 @@ namespace LibHac.FsSrv private Result ParseNca(ref U8Span path, out Nca nca, ReferenceCountedDisposable baseFileSystem, ulong ncaId) { - nca = default; + UnsafeHelpers.SkipParamInit(out nca); // Todo: Create ref-counted storage var ncaFileStorage = new FileStorageBasedFileSystem(); @@ -681,7 +679,7 @@ namespace LibHac.FsSrv private Result ParseContentTypeForDirectory(out ReferenceCountedDisposable fileSystem, ref ReferenceCountedDisposable baseFileSystem, FileSystemProxyType fsType) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); ReadOnlySpan dirName; // Get the name of the subdirectory for the filesystem type @@ -751,8 +749,7 @@ namespace LibHac.FsSrv private Result OpenStorageByContentType(out ReferenceCountedDisposable ncaStorage, Nca nca, out NcaFormatType fsType, FileSystemProxyType fsProxyType, bool isGameCard, bool canMountSystemDataPrivate) { - ncaStorage = default; - fsType = default; + UnsafeHelpers.SkipParamInit(out ncaStorage, out fsType); NcaContentType contentType = nca.Header.ContentType; @@ -821,7 +818,7 @@ namespace LibHac.FsSrv public Result ResolveRomReferenceProgramId(out ProgramId targetProgramId, ProgramId programId, byte programIndex) { - Unsafe.SkipInit(out targetProgramId); + UnsafeHelpers.SkipParamInit(out targetProgramId); ProgramId mainProgramId = _config.ProgramRegistryService.GetProgramIdByIndex(programId, programIndex); if (mainProgramId == ProgramId.InvalidId) @@ -914,7 +911,7 @@ namespace LibHac.FsSrv public Result OpenHostFileSystem(out ReferenceCountedDisposable fileSystem, U8Span path, bool openCaseSensitive) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc; if (!path.IsEmpty()) @@ -987,7 +984,7 @@ namespace LibHac.FsSrv index = 2; return Result.Success; default: - index = default; + UnsafeHelpers.SkipParamInit(out index); return ResultFs.InvalidArgument.Log(); } } diff --git a/src/LibHac/FsSrv/ProgramIndexRegistryService.cs b/src/LibHac/FsSrv/ProgramIndexRegistryService.cs index e5f14143..792b58b6 100644 --- a/src/LibHac/FsSrv/ProgramIndexRegistryService.cs +++ b/src/LibHac/FsSrv/ProgramIndexRegistryService.cs @@ -1,6 +1,6 @@ using System; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Impl; using LibHac.Sf; @@ -73,8 +73,7 @@ namespace LibHac.FsSrv /// in the program registry. Something's wrong with Loader if this happens. public Result GetProgramIndex(out int programIndex, out int programCount) { - Unsafe.SkipInit(out programIndex); - Unsafe.SkipInit(out programCount); + UnsafeHelpers.SkipParamInit(out programIndex, out programCount); // No permissions are needed to call this method Result rc = GetProgramInfo(out ProgramInfo programInfo, ProcessId); diff --git a/src/LibHac/FsSrv/SaveDataFileSystemService.cs b/src/LibHac/FsSrv/SaveDataFileSystemService.cs index 37a124f2..0bc1d22c 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemService.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemService.cs @@ -321,7 +321,7 @@ namespace LibHac.FsSrv private static Result GetAccessibilityForSaveData(out Accessibility accessibility, ProgramInfo programInfo, ExtraDataGetter extraDataGetter) { - Unsafe.SkipInit(out accessibility); + UnsafeHelpers.SkipParamInit(out accessibility); Result rc = extraDataGetter(out SaveDataExtraData extraData); if (rc.IsFailure()) @@ -797,7 +797,7 @@ namespace LibHac.FsSrv public Result GetSaveDataInfo(out SaveDataInfo info, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - Unsafe.SkipInit(out info); + UnsafeHelpers.SkipParamInit(out info); using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard); @@ -816,7 +816,7 @@ namespace LibHac.FsSrv public Result QuerySaveDataTotalSize(out long totalSize, long dataSize, long journalSize) { - Unsafe.SkipInit(out totalSize); + UnsafeHelpers.SkipParamInit(out totalSize); if (dataSize < 0 || journalSize < 0) return ResultFs.InvalidSize.Log(); @@ -827,7 +827,7 @@ namespace LibHac.FsSrv public Result CreateSaveDataFileSystem(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo, in SaveDataMetaInfo metaInfo) { - Optional hashSalt = default; + var hashSalt = new Optional(); return CreateSaveDataFileSystemWithHashSaltImpl(in attribute, in creationInfo, in metaInfo, in hashSalt); } @@ -930,8 +930,7 @@ namespace LibHac.FsSrv out ulong saveDataId, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, bool openReadOnly, bool cacheExtraData) { - Unsafe.SkipInit(out saveDataId); - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem, out saveDataId); SaveDataIndexerAccessor accessor = null; @@ -1028,7 +1027,7 @@ namespace LibHac.FsSrv private Result OpenUserSaveDataFileSystemCore(out ReferenceCountedDisposable fileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, ProgramInfo programInfo, bool openReadOnly) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); IUniqueLock mountCountSemaphore = null; ReferenceCountedDisposable tempFileSystem = null; ReferenceCountedDisposable saveService = null; @@ -1089,7 +1088,7 @@ namespace LibHac.FsSrv private Result OpenUserSaveDataFileSystem(out ReferenceCountedDisposable fileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, bool openReadOnly) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -1132,7 +1131,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataFileSystemBySystemSaveDataId(out ReferenceCountedDisposable fileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); if (!IsStaticSaveDataIdValueRange(attribute.StaticSaveDataId)) return ResultFs.InvalidArgument.Log(); @@ -1262,7 +1261,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataInfoReader(out ReferenceCountedDisposable infoReader) { - infoReader = default; + UnsafeHelpers.SkipParamInit(out infoReader); using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.Bis); @@ -1299,7 +1298,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataInfoReaderBySaveDataSpaceId( out ReferenceCountedDisposable infoReader, SaveDataSpaceId spaceId) { - infoReader = default; + UnsafeHelpers.SkipParamInit(out infoReader); using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard); @@ -1338,7 +1337,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataInfoReaderWithFilter(out ReferenceCountedDisposable infoReader, SaveDataSpaceId spaceId, in SaveDataFilter filter) { - infoReader = default; + UnsafeHelpers.SkipParamInit(out infoReader); using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard); @@ -1379,8 +1378,7 @@ namespace LibHac.FsSrv private Result FindSaveDataWithFilterImpl(out long count, out SaveDataInfo info, SaveDataSpaceId spaceId, in SaveDataInfoFilter infoFilter) { - Unsafe.SkipInit(out count); - Unsafe.SkipInit(out info); + UnsafeHelpers.SkipParamInit(out count, out info); SaveDataIndexerAccessor accessor = null; ReferenceCountedDisposable reader = null; @@ -1409,7 +1407,7 @@ namespace LibHac.FsSrv public Result FindSaveDataWithFilter(out long count, OutBuffer saveDataInfoBuffer, SaveDataSpaceId spaceId, in SaveDataFilter filter) { - Unsafe.SkipInit(out count); + UnsafeHelpers.SkipParamInit(out count); if (saveDataInfoBuffer.Size != Unsafe.SizeOf()) return ResultFs.InvalidArgument.Log(); @@ -1467,7 +1465,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataInfoReaderOnlyCacheStorage( out ReferenceCountedDisposable infoReader) { - infoReader = null; + UnsafeHelpers.SkipParamInit(out infoReader); using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard); @@ -1505,7 +1503,7 @@ namespace LibHac.FsSrv private Result GetCacheStorageSpaceId(out SaveDataSpaceId spaceId) { - Unsafe.SkipInit(out spaceId); + UnsafeHelpers.SkipParamInit(out spaceId); Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; @@ -1516,7 +1514,7 @@ namespace LibHac.FsSrv private Result GetCacheStorageSpaceId(out SaveDataSpaceId spaceId, ulong programId) { - Unsafe.SkipInit(out spaceId); + UnsafeHelpers.SkipParamInit(out spaceId); Result rc; // Cache storage on the SD card will always take priority over case storage in NAND @@ -1545,7 +1543,7 @@ namespace LibHac.FsSrv Result SaveExists(out bool exists, SaveDataSpaceId saveSpaceId) { - Unsafe.SkipInit(out exists); + UnsafeHelpers.SkipParamInit(out exists); var infoFilter = new SaveDataInfoFilter(saveSpaceId, new ProgramId(programId), SaveDataType.Cache, default, default, default, 0); @@ -1716,7 +1714,7 @@ namespace LibHac.FsSrv public Result OpenMultiCommitManager(out ReferenceCountedDisposable commitManager) { - commitManager = default; + UnsafeHelpers.SkipParamInit(out commitManager); ReferenceCountedDisposable saveService = null; ReferenceCountedDisposable commitInterface = null; @@ -1797,7 +1795,7 @@ namespace LibHac.FsSrv private Result TryAcquireSaveDataEntryOpenCountSemaphore(out IUniqueLock semaphoreLock) { - semaphoreLock = null; + UnsafeHelpers.SkipParamInit(out semaphoreLock); ReferenceCountedDisposable saveService = null; IUniqueLock uniqueLock = null; @@ -1821,7 +1819,7 @@ namespace LibHac.FsSrv private Result TryAcquireSaveDataMountCountSemaphore(out IUniqueLock semaphoreLock) { - semaphoreLock = null; + UnsafeHelpers.SkipParamInit(out semaphoreLock); ReferenceCountedDisposable saveService = null; IUniqueLock uniqueLock = null; @@ -1868,9 +1866,9 @@ namespace LibHac.FsSrv private Result OpenSaveDataIndexerAccessor(out SaveDataIndexerAccessor accessor, SaveDataSpaceId spaceId) { - accessor = default; - SaveDataIndexerAccessor accessorTemp = null; + UnsafeHelpers.SkipParamInit(out accessor); + SaveDataIndexerAccessor accessorTemp = null; try { Result rc = ServiceImpl.OpenSaveDataIndexerAccessor(out accessorTemp, out bool neededInit, spaceId); diff --git a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs index 3bfd45ae..6ad04da3 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs @@ -59,7 +59,7 @@ namespace LibHac.FsSrv public Result DoesSaveDataEntityExist(out bool exists, SaveDataSpaceId spaceId, ulong saveDataId) { - Unsafe.SkipInit(out exists); + UnsafeHelpers.SkipParamInit(out exists); ReferenceCountedDisposable fileSystem = null; try @@ -99,7 +99,7 @@ namespace LibHac.FsSrv SaveDataSpaceId spaceId, ulong saveDataId, U8Span saveDataRootPath, bool openReadOnly, SaveDataType type, bool cacheExtraData) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); ReferenceCountedDisposable saveDirectoryFs = null; ReferenceCountedDisposable cachedSaveDataFs = null; @@ -279,7 +279,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataMeta(out IFile metaFile, ulong saveDataId, SaveDataSpaceId spaceId, SaveDataMetaType metaType) { - metaFile = default; + UnsafeHelpers.SkipParamInit(out metaFile); ReferenceCountedDisposable metaDirFs = null; try @@ -386,7 +386,7 @@ namespace LibHac.FsSrv ulong saveDataId, SaveDataType type, U8Span saveDataRootPath) { // Todo: Find a way to store extra data for directory save data - extraData = default; + extraData = new SaveDataExtraData(); return Result.Success; } @@ -412,7 +412,7 @@ namespace LibHac.FsSrv { if (allowEmulatedSave && IsAllowedDirectorySaveData(spaceId, saveDataRootPath)) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); ReferenceCountedDisposable tmFs = null; try @@ -469,7 +469,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataDirectoryFileSystemImpl(out ReferenceCountedDisposable fileSystem, SaveDataSpaceId spaceId, U8Span basePath, bool createIfMissing) { - fileSystem = default; + UnsafeHelpers.SkipParamInit(out fileSystem); ReferenceCountedDisposable tempFs = null; ReferenceCountedDisposable tempSubFs = null; @@ -614,7 +614,7 @@ namespace LibHac.FsSrv public Result GetSaveDataIndexCount(out int count) { - Unsafe.SkipInit(out count); + UnsafeHelpers.SkipParamInit(out count); SaveDataIndexerAccessor accessor = null; try diff --git a/src/LibHac/FsSrv/SaveDataIndexer.cs b/src/LibHac/FsSrv/SaveDataIndexer.cs index 26c359c5..1d7bbf84 100644 --- a/src/LibHac/FsSrv/SaveDataIndexer.cs +++ b/src/LibHac/FsSrv/SaveDataIndexer.cs @@ -218,7 +218,7 @@ namespace LibHac.FsSrv public Result Publish(out ulong saveDataId, in SaveDataAttribute key) { - saveDataId = default; + UnsafeHelpers.SkipParamInit(out saveDataId); lock (Locker) { @@ -261,7 +261,7 @@ namespace LibHac.FsSrv public Result Get(out SaveDataIndexerValue value, in SaveDataAttribute key) { - Unsafe.SkipInit(out value); + UnsafeHelpers.SkipParamInit(out value); lock (Locker) { @@ -429,7 +429,7 @@ namespace LibHac.FsSrv public Result GetKey(out SaveDataAttribute key, ulong saveDataId) { - Unsafe.SkipInit(out key); + UnsafeHelpers.SkipParamInit(out key); Result rc = TryInitializeDatabase(); if (rc.IsFailure()) return rc; @@ -455,7 +455,7 @@ namespace LibHac.FsSrv public Result GetValue(out SaveDataIndexerValue value, ulong saveDataId) { - Unsafe.SkipInit(out value); + UnsafeHelpers.SkipParamInit(out value); Result rc = TryInitializeDatabase(); if (rc.IsFailure()) return rc; @@ -509,7 +509,7 @@ namespace LibHac.FsSrv public Result OpenSaveDataInfoReader(out ReferenceCountedDisposable infoReader) { - infoReader = default; + UnsafeHelpers.SkipParamInit(out infoReader); lock (Locker) { @@ -821,7 +821,7 @@ namespace LibHac.FsSrv public Result Read(out long readCount, OutBuffer saveDataInfoBuffer) { - Unsafe.SkipInit(out readCount); + UnsafeHelpers.SkipParamInit(out readCount); lock (_indexer.Locker) { diff --git a/src/LibHac/FsSrv/SaveDataIndexerLite.cs b/src/LibHac/FsSrv/SaveDataIndexerLite.cs index a0d1d6d6..a67af87b 100644 --- a/src/LibHac/FsSrv/SaveDataIndexerLite.cs +++ b/src/LibHac/FsSrv/SaveDataIndexerLite.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Sf; using LibHac.Sf; @@ -19,6 +20,8 @@ namespace LibHac.FsSrv { private object Locker { get; } = new object(); private ulong CurrentSaveDataId { get; set; } = 0x4000000000000000; + + // Todo: Use Optional private bool IsKeyValueSet { get; set; } private SaveDataAttribute _key; @@ -45,13 +48,12 @@ namespace LibHac.FsSrv public Result Publish(out ulong saveDataId, in SaveDataAttribute key) { + UnsafeHelpers.SkipParamInit(out saveDataId); + lock (Locker) { if (IsKeyValueSet && _key == key) - { - saveDataId = default; return ResultFs.SaveDataPathAlreadyExists.Log(); - } _key = key; IsKeyValueSet = true; @@ -66,6 +68,8 @@ namespace LibHac.FsSrv public Result Get(out SaveDataIndexerValue value, in SaveDataAttribute key) { + UnsafeHelpers.SkipParamInit(out value); + lock (Locker) { if (IsKeyValueSet && _key == key) @@ -74,7 +78,6 @@ namespace LibHac.FsSrv return Result.Success; } - value = default; return ResultFs.TargetNotFound.Log(); } } @@ -84,15 +87,12 @@ namespace LibHac.FsSrv lock (Locker) { if (IsKeyValueSet && _key == key) - { return ResultFs.SaveDataPathAlreadyExists.Log(); - } _key = key; IsKeyValueSet = true; _value = new SaveDataIndexerValue(); - return Result.Success; } } @@ -162,6 +162,8 @@ namespace LibHac.FsSrv public Result GetKey(out SaveDataAttribute key, ulong saveDataId) { + UnsafeHelpers.SkipParamInit(out key); + lock (Locker) { if (IsKeyValueSet && _value.SaveDataId == saveDataId) @@ -170,13 +172,14 @@ namespace LibHac.FsSrv return Result.Success; } - key = default; return ResultFs.TargetNotFound.Log(); } } public Result GetValue(out SaveDataIndexerValue value, ulong saveDataId) { + UnsafeHelpers.SkipParamInit(out value); + lock (Locker) { if (IsKeyValueSet && _value.SaveDataId == saveDataId) @@ -185,7 +188,6 @@ namespace LibHac.FsSrv return Result.Success; } - value = default; return ResultFs.TargetNotFound.Log(); } } @@ -215,7 +217,7 @@ namespace LibHac.FsSrv if (IsKeyValueSet) { - reader = new SaveDataIndexerLiteInfoReader(ref _key, ref _value); + reader = new SaveDataIndexerLiteInfoReader(in _key, in _value); } else { @@ -237,7 +239,7 @@ namespace LibHac.FsSrv _finishedIterating = true; } - public SaveDataIndexerLiteInfoReader(ref SaveDataAttribute key, ref SaveDataIndexerValue value) + public SaveDataIndexerLiteInfoReader(in SaveDataAttribute key, in SaveDataIndexerValue value) { SaveDataIndexer.GenerateSaveDataInfo(out _info, in key, in value); } diff --git a/src/LibHac/FsSrv/SaveDataIndexerManager.cs b/src/LibHac/FsSrv/SaveDataIndexerManager.cs index faa92853..c19f73e8 100644 --- a/src/LibHac/FsSrv/SaveDataIndexerManager.cs +++ b/src/LibHac/FsSrv/SaveDataIndexerManager.cs @@ -57,14 +57,14 @@ namespace LibHac.FsSrv public Result OpenSaveDataIndexerAccessor(out SaveDataIndexerAccessor accessor, out bool neededInit, SaveDataSpaceId spaceId) { - neededInit = false; - UniqueLock indexerLock = default; + UnsafeHelpers.SkipParamInit(out neededInit); if (IsBisUserRedirectionEnabled && spaceId == SaveDataSpaceId.User) { spaceId = SaveDataSpaceId.ProperSystem; } + UniqueLock indexerLock = default; try { ISaveDataIndexer indexer; diff --git a/src/LibHac/FsSrv/SaveDataInfoFilterReader.cs b/src/LibHac/FsSrv/SaveDataInfoFilterReader.cs index 5b2a63a5..9e128ed9 100644 --- a/src/LibHac/FsSrv/SaveDataInfoFilterReader.cs +++ b/src/LibHac/FsSrv/SaveDataInfoFilterReader.cs @@ -23,7 +23,7 @@ namespace LibHac.FsSrv public Result Read(out long readCount, OutBuffer saveDataInfoBuffer) { - readCount = default; + UnsafeHelpers.SkipParamInit(out readCount); Span outInfo = MemoryMarshal.Cast(saveDataInfoBuffer.Buffer); diff --git a/src/LibHac/FsSrv/Sf/FspPath.cs b/src/LibHac/FsSrv/Sf/FspPath.cs index 761507c0..172560bf 100644 --- a/src/LibHac/FsSrv/Sf/FspPath.cs +++ b/src/LibHac/FsSrv/Sf/FspPath.cs @@ -25,7 +25,7 @@ namespace LibHac.FsSrv.Sf public static Result FromSpan(out FspPath fspPath, ReadOnlySpan path) { - Unsafe.SkipInit(out fspPath); + UnsafeHelpers.SkipParamInit(out fspPath); Span str = SpanHelpers.AsByteSpan(ref fspPath); @@ -40,7 +40,7 @@ namespace LibHac.FsSrv.Sf public static void CreateEmpty(out FspPath fspPath) { - Unsafe.SkipInit(out fspPath); + UnsafeHelpers.SkipParamInit(out fspPath); SpanHelpers.AsByteSpan(ref fspPath)[0] = 0; } diff --git a/src/LibHac/FsSrv/Storage/MmcService.cs b/src/LibHac/FsSrv/Storage/MmcService.cs index eb6acf5f..f933adeb 100644 --- a/src/LibHac/FsSrv/Storage/MmcService.cs +++ b/src/LibHac/FsSrv/Storage/MmcService.cs @@ -22,7 +22,7 @@ namespace LibHac.FsSrv.Storage private static Result GetMmcManagerOperator(this StorageService service, out ReferenceCountedDisposable deviceOperator) { - deviceOperator = null; + UnsafeHelpers.SkipParamInit(out deviceOperator); ReferenceCountedDisposable deviceManager = null; try @@ -40,7 +40,7 @@ namespace LibHac.FsSrv.Storage private static Result GetAttribute(out ulong attribute, MmcPartition partition) { - Unsafe.SkipInit(out attribute); + UnsafeHelpers.SkipParamInit(out attribute); switch (partition) { @@ -66,7 +66,7 @@ namespace LibHac.FsSrv.Storage private static Result GetMmcOperator(this StorageService service, out ReferenceCountedDisposable mmcOperator, MmcPartition partition) { - mmcOperator = null; + UnsafeHelpers.SkipParamInit(out mmcOperator); ReferenceCountedDisposable deviceManager = null; try @@ -109,7 +109,7 @@ namespace LibHac.FsSrv.Storage public static Result OpenMmcStorage(this StorageService service, out ReferenceCountedDisposable storage, MmcPartition partition) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); ReferenceCountedDisposable deviceManager = null; try @@ -153,7 +153,7 @@ namespace LibHac.FsSrv.Storage public static Result GetMmcSpeedMode(this StorageService service, out MmcSpeedMode speedMode) { - Unsafe.SkipInit(out speedMode); + UnsafeHelpers.SkipParamInit(out speedMode); ReferenceCountedDisposable mmcOperator = null; try @@ -224,7 +224,7 @@ namespace LibHac.FsSrv.Storage public static Result GetMmcPartitionSize(this StorageService service, out long size, MmcPartition partition) { - Unsafe.SkipInit(out size); + UnsafeHelpers.SkipParamInit(out size); ReferenceCountedDisposable mmcOperator = null; try @@ -245,7 +245,7 @@ namespace LibHac.FsSrv.Storage public static Result GetMmcPatrolCount(this StorageService service, out uint count) { - Unsafe.SkipInit(out count); + UnsafeHelpers.SkipParamInit(out count); ReferenceCountedDisposable mmcOperator = null; try @@ -267,8 +267,7 @@ namespace LibHac.FsSrv.Storage public static Result GetAndClearMmcErrorInfo(this StorageService service, out StorageErrorInfo errorInfo, out long logSize, Span logBuffer) { - Unsafe.SkipInit(out errorInfo); - Unsafe.SkipInit(out logSize); + UnsafeHelpers.SkipParamInit(out errorInfo, out logSize); ReferenceCountedDisposable mmcOperator = null; try @@ -347,8 +346,7 @@ namespace LibHac.FsSrv.Storage public static Result GetAndClearPatrolReadAllocateBufferCount(this StorageService service, out long successCount, out long failureCount) { - Unsafe.SkipInit(out successCount); - Unsafe.SkipInit(out failureCount); + UnsafeHelpers.SkipParamInit(out successCount, out failureCount); ReferenceCountedDisposable mmcOperator = null; try diff --git a/src/LibHac/FsSrv/Storage/SdCardService.cs b/src/LibHac/FsSrv/Storage/SdCardService.cs index 258c7627..86ddee79 100644 --- a/src/LibHac/FsSrv/Storage/SdCardService.cs +++ b/src/LibHac/FsSrv/Storage/SdCardService.cs @@ -25,7 +25,7 @@ namespace LibHac.FsSrv.Storage private static Result GetSdCardManagerOperator(this StorageService service, out ReferenceCountedDisposable deviceOperator) { - deviceOperator = null; + UnsafeHelpers.SkipParamInit(out deviceOperator); ReferenceCountedDisposable deviceManager = null; try @@ -44,7 +44,7 @@ namespace LibHac.FsSrv.Storage private static Result GetSdCardOperator(this StorageService service, out ReferenceCountedDisposable sdCardOperator) { - sdCardOperator = null; + UnsafeHelpers.SkipParamInit(out sdCardOperator); ReferenceCountedDisposable deviceManager = null; try @@ -84,7 +84,7 @@ namespace LibHac.FsSrv.Storage public static Result OpenSdStorage(this StorageService service, out ReferenceCountedDisposable storage) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); ReferenceCountedDisposable deviceManager = null; try @@ -123,7 +123,7 @@ namespace LibHac.FsSrv.Storage public static Result GetCurrentSdCardHandle(this StorageService service, out StorageDeviceHandle handle) { - Unsafe.SkipInit(out handle); + UnsafeHelpers.SkipParamInit(out handle); ReferenceCountedDisposable deviceManager = null; try @@ -157,7 +157,7 @@ namespace LibHac.FsSrv.Storage public static Result IsSdCardHandleValid(this StorageService service, out bool isValid, in StorageDeviceHandle handle) { - Unsafe.SkipInit(out isValid); + UnsafeHelpers.SkipParamInit(out isValid); ReferenceCountedDisposable deviceManager = null; try @@ -192,7 +192,7 @@ namespace LibHac.FsSrv.Storage public static Result IsSdCardInserted(this StorageService service, out bool isInserted) { - Unsafe.SkipInit(out isInserted); + UnsafeHelpers.SkipParamInit(out isInserted); ReferenceCountedDisposable deviceManager = null; try @@ -210,7 +210,7 @@ namespace LibHac.FsSrv.Storage public static Result GetSdCardSpeedMode(this StorageService service, out SdCardSpeedMode speedMode) { - Unsafe.SkipInit(out speedMode); + UnsafeHelpers.SkipParamInit(out speedMode); ReferenceCountedDisposable sdCardOperator = null; try @@ -270,7 +270,7 @@ namespace LibHac.FsSrv.Storage public static Result GetSdCardUserAreaNumSectors(this StorageService service, out uint count) { - Unsafe.SkipInit(out count); + UnsafeHelpers.SkipParamInit(out count); ReferenceCountedDisposable sdCardOperator = null; try @@ -294,7 +294,7 @@ namespace LibHac.FsSrv.Storage public static Result GetSdCardUserAreaSize(this StorageService service, out long size) { - Unsafe.SkipInit(out size); + UnsafeHelpers.SkipParamInit(out size); ReferenceCountedDisposable sdCardOperator = null; try @@ -318,7 +318,7 @@ namespace LibHac.FsSrv.Storage public static Result GetSdCardProtectedAreaNumSectors(this StorageService service, out uint count) { - Unsafe.SkipInit(out count); + UnsafeHelpers.SkipParamInit(out count); ReferenceCountedDisposable sdCardOperator = null; try @@ -342,7 +342,7 @@ namespace LibHac.FsSrv.Storage public static Result GetSdCardProtectedAreaSize(this StorageService service, out long size) { - Unsafe.SkipInit(out size); + UnsafeHelpers.SkipParamInit(out size); ReferenceCountedDisposable sdCardOperator = null; try @@ -367,8 +367,7 @@ namespace LibHac.FsSrv.Storage public static Result GetAndClearSdCardErrorInfo(this StorageService service, out StorageErrorInfo errorInfo, out long logSize, Span logBuffer) { - Unsafe.SkipInit(out errorInfo); - Unsafe.SkipInit(out logSize); + UnsafeHelpers.SkipParamInit(out errorInfo, out logSize); ReferenceCountedDisposable sdCardOperator = null; try @@ -395,7 +394,7 @@ namespace LibHac.FsSrv.Storage public static Result OpenSdCardDetectionEvent(this StorageService service, out ReferenceCountedDisposable eventNotifier) { - eventNotifier = default; + UnsafeHelpers.SkipParamInit(out eventNotifier); ReferenceCountedDisposable deviceManager = null; try diff --git a/src/LibHac/FsSrv/TimeService.cs b/src/LibHac/FsSrv/TimeService.cs index cf057e24..5d20243c 100644 --- a/src/LibHac/FsSrv/TimeService.cs +++ b/src/LibHac/FsSrv/TimeService.cs @@ -1,4 +1,5 @@ using System.Runtime.CompilerServices; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Impl; using LibHac.Os; @@ -66,8 +67,7 @@ namespace LibHac.FsSrv public Result GetCurrentPosixTimeWithTimeDifference(out long currentTime, out int timeDifference) { - Unsafe.SkipInit(out currentTime); - Unsafe.SkipInit(out timeDifference); + UnsafeHelpers.SkipParamInit(out currentTime, out timeDifference); using ScopedLock lk = ScopedLock.Lock(ref _mutex); diff --git a/src/LibHac/FsSrv/Util.cs b/src/LibHac/FsSrv/Util.cs index 3e2c9641..51fd0c2f 100644 --- a/src/LibHac/FsSrv/Util.cs +++ b/src/LibHac/FsSrv/Util.cs @@ -10,7 +10,7 @@ namespace LibHac.FsSrv public static Result CreateSubFileSystem(out IFileSystem subFileSystem, IFileSystem baseFileSystem, string path, bool createPathIfMissing) { - subFileSystem = default; + UnsafeHelpers.SkipParamInit(out subFileSystem); Result rc; if (!createPathIfMissing) @@ -33,7 +33,7 @@ namespace LibHac.FsSrv public static Result CreateSubFileSystemImpl(out IFileSystem subFileSystem, IFileSystem baseFileSystem, string path) { - subFileSystem = default; + UnsafeHelpers.SkipParamInit(out subFileSystem); if (path == null) return ResultFs.NullptrArgument.Log(); diff --git a/src/LibHac/FsSystem/AesCbcStorage.cs b/src/LibHac/FsSystem/AesCbcStorage.cs index 0e27753b..732b6381 100644 --- a/src/LibHac/FsSystem/AesCbcStorage.cs +++ b/src/LibHac/FsSystem/AesCbcStorage.cs @@ -1,6 +1,7 @@ using LibHac.Crypto; using LibHac.Fs; using System; +using LibHac.Common; namespace LibHac.FsSystem { @@ -64,8 +65,8 @@ namespace LibHac.FsSystem decryptor = Aes.CreateCbcDecryptor(_key, _iv); return Result.Success; } - - decryptor = default; + + UnsafeHelpers.SkipParamInit(out decryptor); // Need to get the output of the previous block Span prevBlock = stackalloc byte[BlockSize]; diff --git a/src/LibHac/FsSystem/AesXtsFile.cs b/src/LibHac/FsSystem/AesXtsFile.cs index 83ea8f7f..55395261 100644 --- a/src/LibHac/FsSystem/AesXtsFile.cs +++ b/src/LibHac/FsSystem/AesXtsFile.cs @@ -61,7 +61,7 @@ namespace LibHac.FsSystem protected override Result DoRead(out long bytesRead, long offset, Span destination, in ReadOption option) { - bytesRead = default; + UnsafeHelpers.SkipParamInit(out bytesRead); Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/AesXtsFileSystem.cs b/src/LibHac/FsSystem/AesXtsFileSystem.cs index 1cf16fc2..55702af7 100644 --- a/src/LibHac/FsSystem/AesXtsFileSystem.cs +++ b/src/LibHac/FsSystem/AesXtsFileSystem.cs @@ -104,7 +104,7 @@ namespace LibHac.FsSystem protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); Result rc = BaseFileSystem.OpenDirectory(out IDirectory baseDir, path, mode); if (rc.IsFailure()) return rc; @@ -115,7 +115,7 @@ namespace LibHac.FsSystem protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Result rc = BaseFileSystem.OpenFile(out IFile baseFile, path, mode | OpenMode.Read); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/BucketTree.cs b/src/LibHac/FsSystem/BucketTree.cs index dae079f2..ff31205c 100644 --- a/src/LibHac/FsSystem/BucketTree.cs +++ b/src/LibHac/FsSystem/BucketTree.cs @@ -594,7 +594,7 @@ namespace LibHac.FsSystem private Result FindEntrySetWithBuffer(out int outIndex, long virtualAddress, int nodeIndex, Span buffer) { - outIndex = default; + UnsafeHelpers.SkipParamInit(out outIndex); // Calculate node extents. long nodeSize = Tree.NodeSize; diff --git a/src/LibHac/FsSystem/Buffers/BufferManagerUtility.cs b/src/LibHac/FsSystem/Buffers/BufferManagerUtility.cs index fd256106..c8081a83 100644 --- a/src/LibHac/FsSystem/Buffers/BufferManagerUtility.cs +++ b/src/LibHac/FsSystem/Buffers/BufferManagerUtility.cs @@ -98,8 +98,8 @@ namespace LibHac.FsSystem.Buffers Assert.NotNull(callerName); // Clear the output. - outBuffer = default; - Buffer tempBuffer = default; + outBuffer = new Buffer(); + var tempBuffer = new Buffer(); // Get the context. ref BufferManagerContext context = ref GetBufferManagerContext(); diff --git a/src/LibHac/FsSystem/Buffers/FileSystemBufferManager.cs b/src/LibHac/FsSystem/Buffers/FileSystemBufferManager.cs index d4ae2b81..336eb099 100644 --- a/src/LibHac/FsSystem/Buffers/FileSystemBufferManager.cs +++ b/src/LibHac/FsSystem/Buffers/FileSystemBufferManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using LibHac.Common; using LibHac.Diag; using LibHac.Fs; using LibHac.Util; @@ -127,7 +128,7 @@ namespace LibHac.FsSystem public bool Register(out CacheHandle handle, Buffer buffer, BufferAttribute attr) { - Unsafe.SkipInit(out handle); + UnsafeHelpers.SkipParamInit(out handle); // Validate pre-conditions. Assert.True(Entries != null); @@ -162,12 +163,13 @@ namespace LibHac.FsSystem public bool Unregister(out Buffer buffer, CacheHandle handle) { - Unsafe.SkipInit(out buffer); - // Validate pre-conditions. + Unsafe.SkipInit(out buffer); Assert.True(Entries != null); Assert.True(!Unsafe.IsNullRef(ref buffer)); + UnsafeHelpers.SkipParamInit(out buffer); + // Find the lower bound for the entry. for (int i = 0; i < EntryCount; i++) { @@ -185,12 +187,13 @@ namespace LibHac.FsSystem public bool UnregisterOldest(out Buffer buffer, BufferAttribute attr, int requiredSize = 0) // ReSharper restore UnusedParameter.Local { - Unsafe.SkipInit(out buffer); - // Validate pre-conditions. + Unsafe.SkipInit(out buffer); Assert.True(Entries != null); Assert.True(!Unsafe.IsNullRef(ref buffer)); + UnsafeHelpers.SkipParamInit(out buffer); + // If we have no entries, we can't unregister any. if (EntryCount == 0) { @@ -231,9 +234,9 @@ namespace LibHac.FsSystem private void UnregisterCore(out Buffer buffer, ref Entry entry) { - Unsafe.SkipInit(out buffer); // Validate pre-conditions. + Unsafe.SkipInit(out buffer); Assert.True(Entries != null); Assert.True(!Unsafe.IsNullRef(ref buffer)); Assert.True(!Unsafe.IsNullRef(ref entry)); diff --git a/src/LibHac/FsSystem/ConcatenationFile.cs b/src/LibHac/FsSystem/ConcatenationFile.cs index 6fbfb658..7794e0e5 100644 --- a/src/LibHac/FsSystem/ConcatenationFile.cs +++ b/src/LibHac/FsSystem/ConcatenationFile.cs @@ -40,7 +40,7 @@ namespace LibHac.FsSystem protected override Result DoRead(out long bytesRead, long offset, Span destination, in ReadOption option) { - bytesRead = default; + UnsafeHelpers.SkipParamInit(out bytesRead); long inPos = offset; int outPos = 0; @@ -124,7 +124,7 @@ namespace LibHac.FsSystem protected override Result DoGetSize(out long size) { - size = default; + UnsafeHelpers.SkipParamInit(out size); foreach (IFile file in Sources) { diff --git a/src/LibHac/FsSystem/ConcatenationFileSystem.cs b/src/LibHac/FsSystem/ConcatenationFileSystem.cs index c90bdc97..1b4bc777 100644 --- a/src/LibHac/FsSystem/ConcatenationFileSystem.cs +++ b/src/LibHac/FsSystem/ConcatenationFileSystem.cs @@ -208,7 +208,7 @@ namespace LibHac.FsSystem protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); if (IsConcatenationFile(path)) { @@ -224,7 +224,7 @@ namespace LibHac.FsSystem protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); if (!IsConcatenationFile(path)) { @@ -326,7 +326,7 @@ namespace LibHac.FsSystem private Result GetSubFileCount(out int fileCount, U8Span dirPath) { - fileCount = default; + UnsafeHelpers.SkipParamInit(out fileCount); Unsafe.SkipInit(out FsPath buffer); @@ -376,8 +376,7 @@ namespace LibHac.FsSystem internal Result GetConcatenationFileSize(out long size, ReadOnlySpan path) { - size = default; - + UnsafeHelpers.SkipParamInit(out size); Unsafe.SkipInit(out FsPath buffer); int pathLen = StringUtils.Copy(buffer.Str, path); diff --git a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs index e0a40398..1203a43b 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs @@ -46,7 +46,7 @@ namespace LibHac.FsSystem } obj.Dispose(); - created = default; + UnsafeHelpers.SkipParamInit(out created); return rc; } @@ -185,7 +185,7 @@ namespace LibHac.FsSystem Result rc = ResolveFullPath(fullPath.Str, path); if (rc.IsFailure()) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); return rc; } @@ -197,7 +197,7 @@ namespace LibHac.FsSystem protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Unsafe.SkipInit(out FsPath fullPath); @@ -261,7 +261,7 @@ namespace LibHac.FsSystem Result rc = ResolveFullPath(fullPath.Str, path); if (rc.IsFailure()) { - entryType = default; + UnsafeHelpers.SkipParamInit(out entryType); return rc; } @@ -324,7 +324,7 @@ namespace LibHac.FsSystem protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) { - freeSpace = default; + UnsafeHelpers.SkipParamInit(out freeSpace); Unsafe.SkipInit(out FsPath fullPath); @@ -339,7 +339,7 @@ namespace LibHac.FsSystem protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) { - totalSpace = default; + UnsafeHelpers.SkipParamInit(out totalSpace); Unsafe.SkipInit(out FsPath fullPath); diff --git a/src/LibHac/FsSystem/DirectoryUtils.cs b/src/LibHac/FsSystem/DirectoryUtils.cs index 95ccb02b..260eb9ae 100644 --- a/src/LibHac/FsSystem/DirectoryUtils.cs +++ b/src/LibHac/FsSystem/DirectoryUtils.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -43,7 +44,8 @@ namespace LibHac.FsSystem Result rc = sourceFs.OpenFile(out srcFile, new U8Span(sourcePath), OpenMode.Read); if (rc.IsFailure()) return rc; - FsPath dstPath = default; + Unsafe.SkipInit(out FsPath dstPath); + dstPath.Str[0] = 0; int dstPathLen = StringUtils.Concat(dstPath.Str, destParentPath); dstPathLen = StringUtils.Concat(dstPath.Str, dirEntry.Name, dstPathLen); diff --git a/src/LibHac/FsSystem/FileSystemExtensions.cs b/src/LibHac/FsSystem/FileSystemExtensions.cs index 33be725c..e184af4d 100644 --- a/src/LibHac/FsSystem/FileSystemExtensions.cs +++ b/src/LibHac/FsSystem/FileSystemExtensions.cs @@ -2,6 +2,7 @@ using System.Buffers; using System.Collections.Generic; using System.IO; +using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -86,7 +87,7 @@ namespace LibHac.FsSystem while (true) { - DirectoryEntry dirEntry = default; + Unsafe.SkipInit(out DirectoryEntry dirEntry); directory.Read(out long entriesRead, SpanHelpers.AsSpan(ref dirEntry)).ThrowIfFailure(); if (entriesRead == 0) break; diff --git a/src/LibHac/FsSystem/LayeredFileSystem.cs b/src/LibHac/FsSystem/LayeredFileSystem.cs index d536ab17..f53059c3 100644 --- a/src/LibHac/FsSystem/LayeredFileSystem.cs +++ b/src/LibHac/FsSystem/LayeredFileSystem.cs @@ -39,7 +39,7 @@ namespace LibHac.FsSystem protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); // Open directories from all layers so they can be merged // Only allocate the list for multiple sources if needed @@ -110,7 +110,7 @@ namespace LibHac.FsSystem protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); foreach (IFileSystem fs in Sources) { @@ -139,6 +139,8 @@ namespace LibHac.FsSystem protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { + UnsafeHelpers.SkipParamInit(out entryType); + foreach (IFileSystem fs in Sources) { Result getEntryResult = fs.GetEntryType(out DirectoryEntryType type, path); @@ -150,12 +152,13 @@ namespace LibHac.FsSystem } } - entryType = default; return ResultFs.PathNotFound.Log(); } protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) { + UnsafeHelpers.SkipParamInit(out timeStamp); + foreach (IFileSystem fs in Sources) { Result getEntryResult = fs.GetEntryType(out _, path); @@ -166,7 +169,6 @@ namespace LibHac.FsSystem } } - timeStamp = default; return ResultFs.PathNotFound.Log(); } diff --git a/src/LibHac/FsSystem/LocalFile.cs b/src/LibHac/FsSystem/LocalFile.cs index 22f3b7a2..a3e7fe1c 100644 --- a/src/LibHac/FsSystem/LocalFile.cs +++ b/src/LibHac/FsSystem/LocalFile.cs @@ -61,13 +61,14 @@ namespace LibHac.FsSystem protected override Result DoGetSize(out long size) { + UnsafeHelpers.SkipParamInit(out size); + try { return File.GetSize(out size); } catch (Exception ex) when (ex.HResult < 0) { - size = default; return ResultFs.UnexpectedErrorInHostFileGetSize.Log(); } } diff --git a/src/LibHac/FsSystem/LocalFileSystem.cs b/src/LibHac/FsSystem/LocalFileSystem.cs index 562521f5..5e4ba88d 100644 --- a/src/LibHac/FsSystem/LocalFileSystem.cs +++ b/src/LibHac/FsSystem/LocalFileSystem.cs @@ -35,7 +35,7 @@ namespace LibHac.FsSystem private Result ResolveFullPath(out string fullPath, U8Span path) { - fullPath = default; + UnsafeHelpers.SkipParamInit(out fullPath); Unsafe.SkipInit(out FsPath normalizedPath); @@ -67,7 +67,7 @@ namespace LibHac.FsSystem protected override Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path) { - attributes = default; + UnsafeHelpers.SkipParamInit(out attributes); Result rc = ResolveFullPath(out string fullPath, path); if (rc.IsFailure()) return rc; @@ -77,7 +77,6 @@ namespace LibHac.FsSystem if (info.Attributes == (FileAttributes)(-1)) { - attributes = default; return ResultFs.PathNotFound.Log(); } @@ -115,7 +114,7 @@ namespace LibHac.FsSystem protected override Result DoGetFileSize(out long fileSize, U8Span path) { - fileSize = default; + UnsafeHelpers.SkipParamInit(out fileSize); Result rc = ResolveFullPath(out string fullPath, path); if (rc.IsFailure()) return rc; @@ -241,7 +240,7 @@ namespace LibHac.FsSystem protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); Result rc = ResolveFullPath(out string fullPath, path); if (rc.IsFailure()) return rc; @@ -268,7 +267,7 @@ namespace LibHac.FsSystem protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Result rc = ResolveFullPath(out string fullPath, path); if (rc.IsFailure()) return rc; @@ -333,7 +332,7 @@ namespace LibHac.FsSystem protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { - entryType = default; + UnsafeHelpers.SkipParamInit(out entryType); Result rc = ResolveFullPath(out string fullPath, path); if (rc.IsFailure()) return rc; @@ -356,13 +355,12 @@ namespace LibHac.FsSystem return Result.Success; } - entryType = default; return ResultFs.PathNotFound.Log(); } protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) { - timeStamp = default; + UnsafeHelpers.SkipParamInit(out timeStamp); Result rc = ResolveFullPath(out string fullPath, path); if (rc.IsFailure()) return rc; @@ -422,13 +420,15 @@ namespace LibHac.FsSystem } catch (Exception ex) when (ex.HResult < 0) { - stream = default; + UnsafeHelpers.SkipParamInit(out stream); return HResult.HResultToHorizonResult(ex.HResult).Log(); } } private static Result GetSizeInternal(out long fileSize, FileInfo file) { + UnsafeHelpers.SkipParamInit(out fileSize); + try { fileSize = file.Length; @@ -436,14 +436,13 @@ namespace LibHac.FsSystem } catch (Exception ex) when (ex.HResult < 0) { - fileSize = default; return HResult.HResultToHorizonResult(ex.HResult).Log(); } } private static Result CreateFileInternal(out FileStream file, FileInfo fileInfo) { - file = default; + UnsafeHelpers.SkipParamInit(out file); try { @@ -564,6 +563,8 @@ namespace LibHac.FsSystem // GetFileInfo and GetDirInfo detect invalid paths private static Result GetFileInfo(out FileInfo fileInfo, string path) { + UnsafeHelpers.SkipParamInit(out fileInfo); + try { fileInfo = new FileInfo(path); @@ -571,13 +572,14 @@ namespace LibHac.FsSystem } catch (Exception ex) when (ex.HResult < 0) { - fileInfo = default; return HResult.HResultToHorizonResult(ex.HResult).Log(); } } private static Result GetDirInfo(out DirectoryInfo directoryInfo, string path) { + UnsafeHelpers.SkipParamInit(out directoryInfo); + try { directoryInfo = new DirectoryInfo(path); @@ -585,7 +587,6 @@ namespace LibHac.FsSystem } catch (Exception ex) when (ex.HResult < 0) { - directoryInfo = default; return HResult.HResultToHorizonResult(ex.HResult).Log(); } } diff --git a/src/LibHac/FsSystem/NcaUtils/Nca.cs b/src/LibHac/FsSystem/NcaUtils/Nca.cs index 959738ab..ebe3ad34 100644 --- a/src/LibHac/FsSystem/NcaUtils/Nca.cs +++ b/src/LibHac/FsSystem/NcaUtils/Nca.cs @@ -500,7 +500,7 @@ namespace LibHac.FsSystem.NcaUtils type = NcaSectionType.Data; return true; default: - type = default; + UnsafeHelpers.SkipParamInit(out type); return false; } } diff --git a/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs b/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs index 75a29f94..ce254b7d 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs +++ b/src/LibHac/FsSystem/NcaUtils/NcaHeader.cs @@ -296,7 +296,7 @@ namespace LibHac.FsSystem.NcaUtils // Key areas using fixed, unencrypted keys always use the same keys. // Check for these keys by comparing the key area with the known hash of the fixed body keys. - Buffer32 hash = default; + Unsafe.SkipInit(out Buffer32 hash); Sha256.GenerateSha256Hash(keyArea.Slice(0, 0x20), hash); if (Nca0FixedBodyKeySha256Hash.SequenceEqual(hash)) diff --git a/src/LibHac/FsSystem/PartitionFileSystem.cs b/src/LibHac/FsSystem/PartitionFileSystem.cs index 7745b40c..f453c642 100644 --- a/src/LibHac/FsSystem/PartitionFileSystem.cs +++ b/src/LibHac/FsSystem/PartitionFileSystem.cs @@ -59,7 +59,7 @@ namespace LibHac.FsSystem protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { - entryType = default; + UnsafeHelpers.SkipParamInit(out entryType); if (path.ToString() == "/") { diff --git a/src/LibHac/FsSystem/PartitionFileSystemCore.cs b/src/LibHac/FsSystem/PartitionFileSystemCore.cs index bd6a6f62..a985cdd2 100644 --- a/src/LibHac/FsSystem/PartitionFileSystemCore.cs +++ b/src/LibHac/FsSystem/PartitionFileSystemCore.cs @@ -55,7 +55,7 @@ namespace LibHac.FsSystem protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); if (!IsInitialized) return ResultFs.PreconditionViolation.Log(); @@ -72,7 +72,7 @@ namespace LibHac.FsSystem protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); if (!IsInitialized) return ResultFs.PreconditionViolation.Log(); @@ -92,7 +92,7 @@ namespace LibHac.FsSystem protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { - entryType = default; + UnsafeHelpers.SkipParamInit(out entryType); if (!IsInitialized) return ResultFs.PreconditionViolation.Log(); @@ -148,7 +148,7 @@ namespace LibHac.FsSystem protected override Result DoRead(out long bytesRead, long offset, Span destination, in ReadOption option) { - bytesRead = default; + UnsafeHelpers.SkipParamInit(out bytesRead); Result rc = DryRead(out long bytesToRead, offset, destination.Length, in option, Mode); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/PathTools.cs b/src/LibHac/FsSystem/PathTools.cs index d930fea8..39aee040 100644 --- a/src/LibHac/FsSystem/PathTools.cs +++ b/src/LibHac/FsSystem/PathTools.cs @@ -461,7 +461,7 @@ namespace LibHac.FsSystem if (rc.IsFailure()) { - mountName = default; + UnsafeHelpers.SkipParamInit(out mountName); return rc; } @@ -471,6 +471,8 @@ namespace LibHac.FsSystem public static Result GetMountNameLength(string path, out int length) { + UnsafeHelpers.SkipParamInit(out length); + int maxLen = Math.Min(path.Length, MountNameLengthMax); for (int i = 0; i < maxLen; i++) @@ -482,7 +484,6 @@ namespace LibHac.FsSystem } } - length = default; return ResultFs.InvalidMountName.Log(); } diff --git a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs index c726ee99..80fed8ba 100644 --- a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs +++ b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs @@ -35,7 +35,7 @@ namespace LibHac.FsSystem protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Result rc = BaseFs.OpenFile(out IFile baseFile, path, mode); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/RomFs/HierarchicalRomFileTable.cs b/src/LibHac/FsSystem/RomFs/HierarchicalRomFileTable.cs index 361ed3ef..19a01057 100644 --- a/src/LibHac/FsSystem/RomFs/HierarchicalRomFileTable.cs +++ b/src/LibHac/FsSystem/RomFs/HierarchicalRomFileTable.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using LibHac.Common; using LibHac.Fs; using LibHac.Util; @@ -92,7 +93,7 @@ namespace LibHac.FsSystem.RomFs return true; } - fileInfo = default; + UnsafeHelpers.SkipParamInit(out fileInfo); return false; } @@ -104,7 +105,7 @@ namespace LibHac.FsSystem.RomFs return true; } - fileInfo = default; + UnsafeHelpers.SkipParamInit(out fileInfo); return false; } @@ -125,7 +126,7 @@ namespace LibHac.FsSystem.RomFs return true; } - position = default; + UnsafeHelpers.SkipParamInit(out position); return false; } @@ -144,7 +145,7 @@ namespace LibHac.FsSystem.RomFs return true; } - position = default; + UnsafeHelpers.SkipParamInit(out position); return false; } @@ -161,8 +162,7 @@ namespace LibHac.FsSystem.RomFs { if (position.NextFile == -1) { - info = default; - name = default; + UnsafeHelpers.SkipParamInit(out info, out name); return false; } @@ -187,7 +187,7 @@ namespace LibHac.FsSystem.RomFs { if (position.NextDirectory == -1) { - name = default; + UnsafeHelpers.SkipParamInit(out name); return false; } diff --git a/src/LibHac/FsSystem/RomFs/RomFsFile.cs b/src/LibHac/FsSystem/RomFs/RomFsFile.cs index 4f4b8f96..a399875e 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsFile.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsFile.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -20,7 +21,7 @@ namespace LibHac.FsSystem.RomFs protected override Result DoRead(out long bytesRead, long offset, Span destination, in ReadOption option) { - bytesRead = default; + UnsafeHelpers.SkipParamInit(out bytesRead); Result rc = DryRead(out long toRead, offset, destination.Length, in option, OpenMode.Read); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs index df7abb63..81bc9d8f 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs @@ -27,7 +27,7 @@ namespace LibHac.FsSystem.RomFs protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { - entryType = default; + UnsafeHelpers.SkipParamInit(out entryType); if (FileTable.TryOpenFile(path.ToString(), out RomFileInfo _)) { @@ -51,7 +51,7 @@ namespace LibHac.FsSystem.RomFs protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); if (!FileTable.TryOpenDirectory(path.ToString(), out FindPosition position)) { @@ -64,7 +64,7 @@ namespace LibHac.FsSystem.RomFs protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); if (!FileTable.TryOpenFile(path.ToString(), out RomFileInfo info)) { @@ -104,7 +104,7 @@ namespace LibHac.FsSystem.RomFs protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) { - totalSpace = default; + UnsafeHelpers.SkipParamInit(out totalSpace); return ResultFs.UnsupportedGetTotalSpaceSizeForRomFsFileSystem.Log(); } } diff --git a/src/LibHac/FsSystem/Save/HierarchicalSaveFileTable.cs b/src/LibHac/FsSystem/Save/HierarchicalSaveFileTable.cs index a79ee565..aab406cb 100644 --- a/src/LibHac/FsSystem/Save/HierarchicalSaveFileTable.cs +++ b/src/LibHac/FsSystem/Save/HierarchicalSaveFileTable.cs @@ -22,7 +22,7 @@ namespace LibHac.FsSystem.Save { if (!FindPathRecursive(path, out SaveEntryKey key)) { - fileInfo = default; + UnsafeHelpers.SkipParamInit(out fileInfo); return false; } @@ -40,8 +40,7 @@ namespace LibHac.FsSystem.Save { if (position.NextFile == 0) { - info = default; - name = default; + UnsafeHelpers.SkipParamInit(out info, out name); return false; } @@ -52,8 +51,7 @@ namespace LibHac.FsSystem.Save // todo error message if (!success) { - info = default; - name = default; + UnsafeHelpers.SkipParamInit(out info, out name); return false; } @@ -69,7 +67,7 @@ namespace LibHac.FsSystem.Save { if (position.NextDirectory == 0) { - name = default; + UnsafeHelpers.SkipParamInit(out name); return false; } @@ -80,7 +78,7 @@ namespace LibHac.FsSystem.Save // todo error message if (!success) { - name = default; + UnsafeHelpers.SkipParamInit(out name); return false; } @@ -113,7 +111,7 @@ namespace LibHac.FsSystem.Save int parentIndex = CreateParentDirectoryRecursive(ref parser, ref key); int index = FileTable.GetIndexFromKey(ref key).Index; - TableEntry fileEntry = default; + var fileEntry = new TableEntry(); // File already exists. Update file info. if (index >= 0) @@ -138,7 +136,7 @@ namespace LibHac.FsSystem.Save int parentIndex = CreateParentDirectoryRecursive(ref parser, ref key); int index = DirectoryTable.GetIndexFromKey(ref key).Index; - TableEntry dirEntry = default; + var dirEntry = new TableEntry(); // Directory already exists. Do nothing. if (index >= 0) return; @@ -363,9 +361,10 @@ namespace LibHac.FsSystem.Save public bool TryOpenDirectory(U8Span path, out SaveFindPosition position) { + UnsafeHelpers.SkipParamInit(out position); + if (!FindPathRecursive(path, out SaveEntryKey key)) { - position = default; return false; } @@ -375,7 +374,6 @@ namespace LibHac.FsSystem.Save return true; } - position = default; return false; } diff --git a/src/LibHac/FsSystem/Save/SaveDataFile.cs b/src/LibHac/FsSystem/Save/SaveDataFile.cs index 9a990712..de1a002d 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFile.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFile.cs @@ -26,7 +26,7 @@ namespace LibHac.FsSystem.Save protected override Result DoRead(out long bytesRead, long offset, Span destination, in ReadOption option) { - bytesRead = default; + UnsafeHelpers.SkipParamInit(out bytesRead); Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs index 3b561c83..d6ec8512 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs @@ -137,7 +137,7 @@ namespace LibHac.FsSystem.Save protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); Unsafe.SkipInit(out FsPath normalizedPath); @@ -156,7 +156,7 @@ namespace LibHac.FsSystem.Save protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Unsafe.SkipInit(out FsPath normalizedPath); @@ -207,7 +207,7 @@ namespace LibHac.FsSystem.Save protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { - entryType = default; + UnsafeHelpers.SkipParamInit(out entryType); Unsafe.SkipInit(out FsPath normalizedPath); @@ -226,7 +226,6 @@ namespace LibHac.FsSystem.Save return Result.Success; } - entryType = default; return ResultFs.PathNotFound.Log(); } diff --git a/src/LibHac/FsSystem/Save/SaveFsList.cs b/src/LibHac/FsSystem/Save/SaveFsList.cs index 8af53db0..6d61de10 100644 --- a/src/LibHac/FsSystem/Save/SaveFsList.cs +++ b/src/LibHac/FsSystem/Save/SaveFsList.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using LibHac.Common; using LibHac.Fs; using LibHac.Util; @@ -137,27 +138,24 @@ namespace LibHac.FsSystem.Save public bool TryGetValue(ref SaveEntryKey key, out T value) { + UnsafeHelpers.SkipParamInit(out value); + int index = GetIndexFromKey(ref key).Index; if (index < 0) - { - value = default; return false; - } return TryGetValue(index, out value); } public bool TryGetValue(int index, out T value) { + UnsafeHelpers.SkipParamInit(out value); + if (index < 0 || index >= GetListCapacity()) - { - value = default; return false; - } GetValue(index, out value); - return true; } @@ -178,16 +176,13 @@ namespace LibHac.FsSystem.Save /// the specified key; otherwise, . public bool TryGetValue(int index, out T value, ref Span name) { + UnsafeHelpers.SkipParamInit(out value); Debug.Assert(name.Length >= MaxNameLength); if (index < 0 || index >= GetListCapacity()) - { - value = default; return false; - } GetValue(index, out value, ref name); - return true; } @@ -272,7 +267,7 @@ namespace LibHac.FsSystem.Save ReadEntry(index, out entry); entry.Parent = 0; - entry.Value = default; + entry.Value = new T(); name.Fill(SaveDataFileSystem.TrimFillValue); WriteEntry(index, ref entry); diff --git a/src/LibHac/FsSystem/StorageFile.cs b/src/LibHac/FsSystem/StorageFile.cs index b18051cd..c9b28a61 100644 --- a/src/LibHac/FsSystem/StorageFile.cs +++ b/src/LibHac/FsSystem/StorageFile.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -18,7 +19,7 @@ namespace LibHac.FsSystem protected override Result DoRead(out long bytesRead, long offset, Span destination, in ReadOption option) { - bytesRead = default; + UnsafeHelpers.SkipParamInit(out bytesRead); Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/StreamFile.cs b/src/LibHac/FsSystem/StreamFile.cs index b0b8ddf4..1e2e80db 100644 --- a/src/LibHac/FsSystem/StreamFile.cs +++ b/src/LibHac/FsSystem/StreamFile.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -25,7 +26,7 @@ namespace LibHac.FsSystem protected override Result DoRead(out long bytesRead, long offset, Span destination, in ReadOption option) { - bytesRead = default; + UnsafeHelpers.SkipParamInit(out bytesRead); Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs index 68f90157..3acf365b 100644 --- a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs +++ b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs @@ -27,7 +27,7 @@ namespace LibHac.FsSystem } obj.Dispose(); - created = default; + UnsafeHelpers.SkipParamInit(out created); return rc; } @@ -149,7 +149,7 @@ namespace LibHac.FsSystem protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode) { - directory = default; + UnsafeHelpers.SkipParamInit(out directory); Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -160,7 +160,7 @@ namespace LibHac.FsSystem protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode) { - file = default; + UnsafeHelpers.SkipParamInit(out file); Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -199,7 +199,7 @@ namespace LibHac.FsSystem protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path) { - entryType = default; + UnsafeHelpers.SkipParamInit(out entryType); Unsafe.SkipInit(out FsPath fullPath); @@ -226,7 +226,7 @@ namespace LibHac.FsSystem protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path) { - freeSpace = default; + UnsafeHelpers.SkipParamInit(out freeSpace); Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -237,7 +237,7 @@ namespace LibHac.FsSystem protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path) { - totalSpace = default; + UnsafeHelpers.SkipParamInit(out totalSpace); Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); @@ -248,7 +248,7 @@ namespace LibHac.FsSystem protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path) { - timeStamp = default; + UnsafeHelpers.SkipParamInit(out timeStamp); Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; Result rc = ResolveFullPath(fullPath, path); diff --git a/src/LibHac/FsSystem/Utility.cs b/src/LibHac/FsSystem/Utility.cs index 65a18152..2fc3a4cf 100644 --- a/src/LibHac/FsSystem/Utility.cs +++ b/src/LibHac/FsSystem/Utility.cs @@ -45,7 +45,7 @@ namespace LibHac.FsSystem public static Result IterateDirectoryRecursively(IFileSystem fs, U8Span rootPath, FsIterationTask onEnterDir, FsIterationTask onExitDir, FsIterationTask onFile) { - DirectoryEntry entry = default; + var entry = new DirectoryEntry(); Span workPath = stackalloc byte[PathTools.MaxPathLength + 1]; return IterateDirectoryRecursively(fs, rootPath, workPath, ref entry, onEnterDir, onExitDir, @@ -234,7 +234,7 @@ namespace LibHac.FsSystem if (!tempUniqueLock.TryLock()) { - uniqueLock = default; + UnsafeHelpers.SkipParamInit(out uniqueLock); return ResultFs.OpenCountLimit.Log(); } @@ -250,7 +250,7 @@ namespace LibHac.FsSystem public static Result MakeUniqueLockWithPin(out IUniqueLock uniqueLock, SemaphoreAdaptor semaphore, ref ReferenceCountedDisposable objectToPin) where T : class, IDisposable { - uniqueLock = default; + UnsafeHelpers.SkipParamInit(out uniqueLock); UniqueLockSemaphore tempUniqueLock = default; try diff --git a/src/LibHac/Kernel/InitialProcessBinaryReader.cs b/src/LibHac/Kernel/InitialProcessBinaryReader.cs index d6a2dd68..dc53891e 100644 --- a/src/LibHac/Kernel/InitialProcessBinaryReader.cs +++ b/src/LibHac/Kernel/InitialProcessBinaryReader.cs @@ -51,7 +51,7 @@ namespace LibHac.Kernel public Result OpenKipStorage(out IStorage storage, int index) { - storage = default; + UnsafeHelpers.SkipParamInit(out storage); if ((uint)index >= _header.ProcessCount) return ResultLibHac.ArgumentOutOfRange.Log(); @@ -66,7 +66,7 @@ namespace LibHac.Kernel { Assert.True(processCount <= MaxProcessCount); - kipOffsets = default; + UnsafeHelpers.SkipParamInit(out kipOffsets); var offsets = new (int offset, int size)[processCount]; int offset = Unsafe.SizeOf(); diff --git a/src/LibHac/Kernel/KipReader.cs b/src/LibHac/Kernel/KipReader.cs index bf1ad5a5..a7d2b693 100644 --- a/src/LibHac/Kernel/KipReader.cs +++ b/src/LibHac/Kernel/KipReader.cs @@ -64,7 +64,7 @@ namespace LibHac.Kernel /// The of the operation. public Result GetRawData(out IStorage kipData) { - kipData = default; + UnsafeHelpers.SkipParamInit(out kipData); int kipFileSize = GetFileSize(); @@ -81,6 +81,8 @@ namespace LibHac.Kernel public Result GetSegmentSize(SegmentType segment, out int size) { + UnsafeHelpers.SkipParamInit(out size); + switch (segment) { case SegmentType.Text: @@ -92,7 +94,6 @@ namespace LibHac.Kernel size = _header.Segments[(int)segment].Size; return Result.Success; default: - size = default; return ResultLibHac.ArgumentOutOfRange.Log(); } } diff --git a/src/LibHac/Kvdb/FlatMapKeyValueStore.cs b/src/LibHac/Kvdb/FlatMapKeyValueStore.cs index 42622991..55bdc945 100644 --- a/src/LibHac/Kvdb/FlatMapKeyValueStore.cs +++ b/src/LibHac/Kvdb/FlatMapKeyValueStore.cs @@ -157,7 +157,7 @@ namespace LibHac.Kvdb /// The specified key was not found in the . public Result Get(out int valueSize, in TKey key, Span valueBuffer) { - Unsafe.SkipInit(out valueSize); + UnsafeHelpers.SkipParamInit(out valueSize); // Find entry. ConstIterator iterator = _index.GetLowerBoundConstIterator(in key); @@ -292,7 +292,7 @@ namespace LibHac.Kvdb try { // Read key and value. - TKey key = default; + Unsafe.SkipInit(out TKey key); rc = reader.ReadKeyValue(SpanHelpers.AsByteSpan(ref key), newValue.Get()); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Kvdb/KeyValueArchive.cs b/src/LibHac/Kvdb/KeyValueArchive.cs index 50585b29..3f08a10a 100644 --- a/src/LibHac/Kvdb/KeyValueArchive.cs +++ b/src/LibHac/Kvdb/KeyValueArchive.cs @@ -72,7 +72,7 @@ namespace LibHac.Kvdb public Result ReadEntryCount(out int count) { - Unsafe.SkipInit(out count); + UnsafeHelpers.SkipParamInit(out count); // This should only be called at the start of reading stream. Assert.True(_offset == 0); @@ -92,14 +92,13 @@ namespace LibHac.Kvdb public Result GetKeyValueSize(out int keySize, out int valueSize) { - Unsafe.SkipInit(out keySize); - Unsafe.SkipInit(out valueSize); + UnsafeHelpers.SkipParamInit(out keySize, out valueSize); // This should only be called after ReadEntryCount. Assert.NotEqual(_offset, 0); // Peek the next entry header. - KeyValueArchiveEntryHeader header = default; + Unsafe.SkipInit(out KeyValueArchiveEntryHeader header); Result rc = Peek(SpanHelpers.AsByteSpan(ref header)); if (rc.IsFailure()) return rc; @@ -119,7 +118,7 @@ namespace LibHac.Kvdb Assert.NotEqual(_offset, 0); // Read the next entry header. - KeyValueArchiveEntryHeader header = default; + Unsafe.SkipInit(out KeyValueArchiveEntryHeader header); Result rc = Read(SpanHelpers.AsByteSpan(ref header)); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Loader/NsoReader.cs b/src/LibHac/Loader/NsoReader.cs index 4266d17a..7523418b 100644 --- a/src/LibHac/Loader/NsoReader.cs +++ b/src/LibHac/Loader/NsoReader.cs @@ -26,6 +26,8 @@ namespace LibHac.Loader public Result GetSegmentSize(SegmentType segment, out uint size) { + UnsafeHelpers.SkipParamInit(out size); + switch (segment) { case SegmentType.Text: @@ -34,7 +36,6 @@ namespace LibHac.Loader size = Header.Segments[(int)segment].Size; return Result.Success; default: - size = default; return ResultLibHac.ArgumentOutOfRange.Log(); } } @@ -88,7 +89,7 @@ namespace LibHac.Loader // Check hash if necessary. if (checkHash) { - Buffer32 hash = default; + var hash = new Buffer32(); Crypto.Sha256.GenerateSha256Hash(buffer.Slice(0, (int)segment.Size), hash.Bytes); if (hash.Bytes.SequenceCompareTo(fileHash.Bytes) != 0) diff --git a/src/LibHac/Lr/LrClient.cs b/src/LibHac/Lr/LrClient.cs index 77c62907..c27bdaaa 100644 --- a/src/LibHac/Lr/LrClient.cs +++ b/src/LibHac/Lr/LrClient.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; using LibHac.Ncm; namespace LibHac.Lr @@ -17,7 +18,7 @@ namespace LibHac.Lr public Result OpenLocationResolver(out LocationResolver resolver, StorageId storageId) { - resolver = default; + UnsafeHelpers.SkipParamInit(out resolver); EnsureInitialized(); Result rc = LrManager.OpenLocationResolver(out ReferenceCountedDisposable baseResolver, @@ -33,7 +34,7 @@ namespace LibHac.Lr public Result OpenRegisteredLocationResolver(out RegisteredLocationResolver resolver) { - resolver = default; + UnsafeHelpers.SkipParamInit(out resolver); EnsureInitialized(); Result rc = LrManager.OpenRegisteredLocationResolver( @@ -49,7 +50,7 @@ namespace LibHac.Lr public Result OpenAddOnContentLocationResolver(out AddOnContentLocationResolver resolver) { - resolver = default; + UnsafeHelpers.SkipParamInit(out resolver); EnsureInitialized(); Result rc = LrManager.OpenAddOnContentLocationResolver( diff --git a/src/LibHac/MemoryResource.cs b/src/LibHac/MemoryResource.cs index 0e8da0ea..bff51c8c 100644 --- a/src/LibHac/MemoryResource.cs +++ b/src/LibHac/MemoryResource.cs @@ -18,7 +18,7 @@ namespace LibHac DoDeallocate(buffer, alignment); // Clear the references to the deallocated buffer. - buffer = default; + buffer = new Buffer(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/LibHac/Result.cs b/src/LibHac/Result.cs index 463cecc6..f1831aa0 100644 --- a/src/LibHac/Result.cs +++ b/src/LibHac/Result.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; - +using LibHac.Common; using BaseType = System.UInt32; namespace LibHac @@ -116,7 +116,7 @@ namespace LibHac if (resolver == null) { - name = default; + UnsafeHelpers.SkipParamInit(out name); return false; } diff --git a/src/LibHac/Sm/ServiceManager.cs b/src/LibHac/Sm/ServiceManager.cs index 23872cb6..4d8d29d2 100644 --- a/src/LibHac/Sm/ServiceManager.cs +++ b/src/LibHac/Sm/ServiceManager.cs @@ -15,7 +15,7 @@ namespace LibHac.Sm internal Result GetService(out object serviceObject, ServiceName serviceName) { - serviceObject = default; + UnsafeHelpers.SkipParamInit(out serviceObject); Result rc = ValidateServiceName(serviceName); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Sm/ServiceManagerClient.cs b/src/LibHac/Sm/ServiceManagerClient.cs index b5f77934..ccb8bca8 100644 --- a/src/LibHac/Sm/ServiceManagerClient.cs +++ b/src/LibHac/Sm/ServiceManagerClient.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Common; namespace LibHac.Sm { @@ -16,7 +17,7 @@ namespace LibHac.Sm Result rc = Server.GetService(out object service, ServiceName.Encode(name)); if (rc.IsFailure()) { - serviceObject = default; + UnsafeHelpers.SkipParamInit(out serviceObject); return rc; }