// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
int flProtect,
int dwMaximumSizeHigh,
int dwMaximumSizeLow,
- string lpName);
+ string? lpName);
[DllImport(Libraries.Kernel32, EntryPoint = "CreateFileMappingW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern SafeMemoryMappedFileHandle CreateFileMapping(
int flProtect,
int dwMaximumSizeHigh,
int dwMaximumSizeLow,
- string lpName);
+ string? lpName);
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
// See the LICENSE file in the project root for more information.
using Microsoft.Win32.SafeHandles;
-using System;
using System.Runtime.InteropServices;
internal partial class Interop
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
{
internal MemoryMappedFile() { }
public Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle SafeMemoryMappedFileHandle { get { throw null; } }
- public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(System.IO.FileStream fileStream, string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.HandleInheritability inheritability, bool leaveOpen) { throw null; }
+ public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(System.IO.FileStream fileStream, string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.HandleInheritability inheritability, bool leaveOpen) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode) { throw null; }
- public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string mapName) { throw null; }
- public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string mapName, long capacity) { throw null; }
- public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
- public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string mapName, long capacity) { throw null; }
- public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
- public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability) { throw null; }
+ public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string? mapName) { throw null; }
+ public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string? mapName, long capacity) { throw null; }
+ public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
+ public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string? mapName, long capacity) { throw null; }
+ public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
+ public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen(string mapName, long capacity) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen(string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen(string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability) { throw null; }
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
+ <Nullable>enable</Nullable>
<Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
</PropertyGroup>
<ItemGroup>
using System.Diagnostics;
using System.IO;
using System.IO.MemoryMappedFiles;
-using System.Runtime.InteropServices;
-using System.Security;
using System.Threading;
namespace Microsoft.Win32.SafeHandles
/// onto the underlying handle to ensure that logic associated with disposing the stream
/// (e.g. deleting the file for DeleteOnClose) happens at the appropriate time.
/// </summary>
- internal readonly FileStream _fileStream;
+ internal readonly FileStream? _fileStream;
/// <summary>Whether this SafeHandle owns the _fileStream and should Dispose it when disposed.</summary>
internal readonly bool _ownsFileStream;
/// <param name="options">The options for the memory-mapped file.</param>
/// <param name="capacity">The capacity of the memory-mapped file.</param>
internal SafeMemoryMappedFileHandle(
- FileStream fileStream, bool ownsFileStream, HandleInheritability inheritability,
+ FileStream? fileStream, bool ownsFileStream, HandleInheritability inheritability,
MemoryMappedFileAccess access, MemoryMappedFileOptions options,
long capacity)
: base(ownsHandle: true)
if (disposing && _ownsFileStream)
{
// Clean up the file descriptor (either for a file on disk or a shared memory object) if we created it
- _fileStream.Dispose();
+ _fileStream!.Dispose();
}
base.Dispose(disposing);
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Runtime.InteropServices;
-using System.Security;
-
namespace Microsoft.Win32.SafeHandles
{
public sealed partial class SafeMemoryMappedFileHandle : SafeHandleZeroOrMinusOneIsInvalid
// See the LICENSE file in the project root for more information.
using System;
-using System.Runtime.InteropServices;
namespace Microsoft.Win32.SafeHandles
{
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.Runtime.InteropServices;
-using System.Security;
namespace Microsoft.Win32.SafeHandles
{
<PropertyGroup>
<AssemblyName>System.IO.MemoryMappedFiles</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <Nullable>enable</Nullable>
<Configurations>netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release</Configurations>
</PropertyGroup>
<!-- Compiled Source Files -->
ref Kernel32.SECURITY_ATTRIBUTES securityAttributes,
int pageProtection,
long maximumSize,
- string name)
+ string? name)
{
// split the long into two ints
int capacityHigh, capacityLow;
ref Kernel32.SECURITY_ATTRIBUTES securityAttributes,
int pageProtection,
long maximumSize,
- string name)
+ string? name)
{
// split the long into two ints
int capacityHigh, capacityLow;
// See the LICENSE file in the project root for more information.
using Microsoft.Win32.SafeHandles;
-using System.Security;
namespace System.IO.MemoryMappedFiles
{
/// out empty).
/// </summary>
private static unsafe SafeMemoryMappedFileHandle CreateCore(
- FileStream fileStream, string mapName,
+ FileStream? fileStream, string? mapName,
HandleInheritability inheritability, MemoryMappedFileAccess access,
MemoryMappedFileOptions options, long capacity)
{
// ---- PAL layer ends here ----
// -----------------------------
- private static FileStream CreateSharedBackingObjectUsingMemory(
+ private static FileStream? CreateSharedBackingObjectUsingMemory(
Interop.Sys.MemoryMappedProtections protections, long capacity, HandleInheritability inheritability)
{
// The POSIX shared memory object name must begin with '/'. After that we just want something short and unique.
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Runtime.InteropServices;
-using System.Security;
using System.Threading;
namespace System.IO.MemoryMappedFiles
/// </summary>
private static SafeMemoryMappedFileHandle CreateCore(
- FileStream fileStream, string mapName, HandleInheritability inheritability,
+ FileStream? fileStream, string? mapName, HandleInheritability inheritability,
MemoryMappedFileAccess access, MemoryMappedFileOptions options, long capacity)
{
- SafeFileHandle fileHandle = fileStream != null ? fileStream.SafeFileHandle : null;
+ SafeFileHandle? fileHandle = fileStream != null ? fileStream.SafeFileHandle : null;
Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability);
Debug.Assert(access != MemoryMappedFileAccess.Write, "Callers requesting write access shouldn't try to create a mmf");
- SafeMemoryMappedFileHandle handle = null;
+ SafeMemoryMappedFileHandle? handle = null;
Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability);
int waitRetries = 14; //((2^13)-1)*10ms == approximately 1.4mins
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
-using System.Security;
namespace System.IO.MemoryMappedFiles
{
{
private readonly SafeMemoryMappedFileHandle _handle;
private readonly bool _leaveOpen;
- private readonly FileStream _fileStream;
+ private readonly FileStream? _fileStream;
internal const int DefaultSize = 0;
// Private constructors to be used by the factory methods.
return CreateFromFile(path, mode, null, DefaultSize, MemoryMappedFileAccess.ReadWrite);
}
- public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string mapName)
+ public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName)
{
return CreateFromFile(path, mode, mapName, DefaultSize, MemoryMappedFileAccess.ReadWrite);
}
- public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string mapName, long capacity)
+ public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName, long capacity)
{
return CreateFromFile(path, mode, mapName, capacity, MemoryMappedFileAccess.ReadWrite);
}
- public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string mapName, long capacity,
+ public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName, long capacity,
MemoryMappedFileAccess access)
{
if (path == null)
throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_CapacityGEFileSizeRequired);
}
- SafeMemoryMappedFileHandle handle = null;
+ SafeMemoryMappedFileHandle? handle = null;
try
{
handle = CreateCore(fileStream, mapName, HandleInheritability.None,
return new MemoryMappedFile(handle, fileStream, false);
}
- public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity,
+ public static MemoryMappedFile CreateFromFile(FileStream fileStream, string? mapName, long capacity,
MemoryMappedFileAccess access,
HandleInheritability inheritability, bool leaveOpen)
{
// Factory Method Group #3: Creates a new empty memory mapped file. Such memory mapped files are ideal
// for IPC, when mapName != null.
- public static MemoryMappedFile CreateNew(string mapName, long capacity)
+ public static MemoryMappedFile CreateNew(string? mapName, long capacity)
{
return CreateNew(mapName, capacity, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None,
HandleInheritability.None);
}
- public static MemoryMappedFile CreateNew(string mapName, long capacity, MemoryMappedFileAccess access)
+ public static MemoryMappedFile CreateNew(string? mapName, long capacity, MemoryMappedFileAccess access)
{
return CreateNew(mapName, capacity, access, MemoryMappedFileOptions.None,
HandleInheritability.None);
}
- public static MemoryMappedFile CreateNew(string mapName, long capacity, MemoryMappedFileAccess access,
+ public static MemoryMappedFile CreateNew(string? mapName, long capacity, MemoryMappedFileAccess access,
MemoryMappedFileOptions options,
HandleInheritability inheritability)
{
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Security;
namespace System.IO.MemoryMappedFiles
{
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Runtime.InteropServices;
-using System.Security;
using System.Threading;
-using System.Threading.Tasks;
namespace System.IO.MemoryMappedFiles
{
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
-using System.Security;
namespace System.IO.MemoryMappedFiles
{
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
-using System.Security;
namespace System.IO.MemoryMappedFiles
{
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
-using System.Security;
namespace System.IO.MemoryMappedFiles
{
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Diagnostics;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using System.Text;
using Xunit;
namespace System.IO.MemoryMappedFiles.Tests
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
-using Microsoft.Win32.SafeHandles;
internal static partial class Interop
{
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.Runtime.InteropServices;
internal static partial class Interop