31 [SupportedOSPlatform(
"windows")]
37 [SupportedOSPlatform(
"windows")]
43 [SupportedOSPlatform(
"windows")]
50 if (mapName.Length == 0)
54 if (inheritability < HandleInheritability.None || inheritability >
HandleInheritability.Inheritable)
58 if (((uint)desiredAccessRights & 0xFEF0FFF0u) != 0)
92 if (mapName !=
null && mapName.Length == 0)
137 return new MemoryMappedFile(safeMemoryMappedFileHandle, fileStream, leaveOpen:
false);
144 if (fileStream ==
null)
148 if (mapName !=
null && mapName.Length == 0)
172 if (inheritability < HandleInheritability.None || inheritability >
HandleInheritability.Inheritable)
199 if (mapName !=
null && mapName.Length == 0)
223 if (((uint)
options & 0xFBFFFFFFu) != 0)
227 if (inheritability < HandleInheritability.None || inheritability >
HandleInheritability.Inheritable)
237 [SupportedOSPlatform(
"windows")]
243 [SupportedOSPlatform(
"windows")]
249 [SupportedOSPlatform(
"windows")]
256 if (mapName.Length == 0)
272 if (((uint)
options & 0xFBFFFFFFu) != 0)
276 if (inheritability < HandleInheritability.None || inheritability >
HandleInheritability.Inheritable)
354 protected virtual void Dispose(
bool disposing)
412 global::Interop.Kernel32.SECURITY_ATTRIBUTES securityAttributes =
GetSecAttrs(inheritability);
413 if (fileStream !=
null)
419 if (!safeMemoryMappedFileHandle.
IsInvalid)
421 if (lastPInvokeError == 183)
423 safeMemoryMappedFileHandle.
Dispose();
426 return safeMemoryMappedFileHandle;
428 safeMemoryMappedFileHandle.
Dispose();
445 global::Interop.Kernel32.SECURITY_ATTRIBUTES securityAttributes =
GetSecAttrs(inheritability);
451 if (!safeMemoryMappedFileHandle.
IsInvalid)
455 safeMemoryMappedFileHandle.
Dispose();
457 if (lastPInvokeError != 5)
462 if (!safeMemoryMappedFileHandle.
IsInvalid)
466 safeMemoryMappedFileHandle.
Dispose();
468 if (lastPInvokeError2 != 2)
481 if (safeMemoryMappedFileHandle ==
null || safeMemoryMappedFileHandle.
IsInvalid)
485 return safeMemoryMappedFileHandle;
497 MemoryMappedFileAccess.Read => 4,
498 MemoryMappedFileAccess.Write => 2,
499 MemoryMappedFileAccess.ReadWrite => 6,
500 MemoryMappedFileAccess.CopyOnWrite => 1,
501 MemoryMappedFileAccess.ReadExecute => 36,
510 MemoryMappedFileAccess.Read => 2,
511 MemoryMappedFileAccess.ReadWrite => 4,
512 MemoryMappedFileAccess.CopyOnWrite => 8,
513 MemoryMappedFileAccess.ReadExecute => 32,
522 if (safeMemoryMappedFileHandle.
IsInvalid)
524 safeMemoryMappedFileHandle.
Dispose();
525 if (createOrOpen && lastWin32Error == 2)
531 return safeMemoryMappedFileHandle;
536 global::Interop.Kernel32.SECURITY_ATTRIBUTES result =
default(global::Interop.Kernel32.SECURITY_ATTRIBUTES);
539 result =
default(global::Interop.Kernel32.SECURITY_ATTRIBUTES);
540 result.nLength = (uint)
sizeof(global::Interop.Kernel32.SECURITY_ATTRIBUTES);
541 result.bInheritHandle = global::Interop.BOOL.TRUE;
static void SuppressFinalize(object obj)
virtual SafeFileHandle SafeFileHandle
override void Dispose(bool disposing)
static bool Exists([NotNullWhen(true)] string? path)
static void Delete(string path)
readonly FileStream _fileStream
static MemoryMappedFile CreateFromFile(string path, FileMode mode)
static SafeMemoryMappedFileHandle CreateOrOpenCore(string mapName, HandleInheritability inheritability, MemoryMappedFileAccess access, MemoryMappedFileOptions options, long capacity)
static SafeMemoryMappedFileHandle OpenCore(string mapName, HandleInheritability inheritability, MemoryMappedFileAccess access, bool createOrOpen)
static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights)
static void VerifyMemoryMappedFileAccess(MemoryMappedFileAccess access, long capacity, FileStream fileStream)
MemoryMappedViewAccessor CreateViewAccessor(long offset, long size, MemoryMappedFileAccess access)
MemoryMappedViewAccessor CreateViewAccessor(long offset, long size)
static MemoryMappedFile OpenExisting(string mapName)
static int GetFileMapAccess(MemoryMappedFileRights rights)
static MemoryMappedFile CreateOrOpen(string mapName, long capacity, MemoryMappedFileAccess access)
static MemoryMappedFile CreateOrOpen(string mapName, long capacity)
static MemoryMappedFile CreateOrOpen(string mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, HandleInheritability inheritability)
MemoryMappedViewStream CreateViewStream()
static MemoryMappedFile OpenExisting(string mapName, MemoryMappedFileRights desiredAccessRights, HandleInheritability inheritability)
static SafeMemoryMappedFileHandle OpenCore(string mapName, HandleInheritability inheritability, int desiredAccessRights, bool createOrOpen)
virtual void Dispose(bool disposing)
static MemoryMappedFile CreateFromFile(FileStream fileStream, string? mapName, long capacity, MemoryMappedFileAccess access, HandleInheritability inheritability, bool leaveOpen)
static MemoryMappedFile CreateNew(string? mapName, long capacity, MemoryMappedFileAccess access)
MemoryMappedViewStream CreateViewStream(long offset, long size)
static unsafe global::Interop.Kernel32.SECURITY_ATTRIBUTES GetSecAttrs(HandleInheritability inheritability)
MemoryMappedFile(SafeMemoryMappedFileHandle handle)
static int GetFileMapAccess(MemoryMappedFileAccess access)
static void CleanupFile(FileStream fileStream, bool existed, string path)
static SafeMemoryMappedFileHandle CreateCore(FileStream fileStream, string mapName, HandleInheritability inheritability, MemoryMappedFileAccess access, MemoryMappedFileOptions options, long capacity)
static MemoryMappedFile CreateNew(string? mapName, long capacity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, HandleInheritability inheritability)
static FileAccess GetFileAccess(MemoryMappedFileAccess access)
MemoryMappedFile(SafeMemoryMappedFileHandle handle, FileStream fileStream, bool leaveOpen)
MemoryMappedViewAccessor CreateViewAccessor()
static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName, long capacity, MemoryMappedFileAccess access)
static int GetPageAccess(MemoryMappedFileAccess access)
MemoryMappedViewStream CreateViewStream(long offset, long size, MemoryMappedFileAccess access)
readonly SafeMemoryMappedFileHandle _handle
static SafeMemoryMappedFileHandle OpenCore(string mapName, HandleInheritability inheritability, MemoryMappedFileRights rights, bool createOrOpen)
static MemoryMappedFile CreateNew(string? mapName, long capacity)
static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName)
static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName, long capacity)
static MemoryMappedFile CreateFromFile(string path)
static MemoryMappedView CreateView(SafeMemoryMappedFileHandle memMappedFileHandle, MemoryMappedFileAccess access, long offset, long size)
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static int GetLastPInvokeError()
static int GetLastWin32Error()
static string InvalidOperation_CantCreateFileMapping
static string Argument_NewMMFWriteAccessNotAllowed
static string Argument_ReadAccessWithLargeCapacity
static string ArgumentNull_FileStream
static string ArgumentOutOfRange_PositiveOrDefaultSizeRequired
static string Argument_NewMMFTruncateModeNotAllowed
static string Argument_MapNameEmptyString
static string ArgumentOutOfRange_PositiveOrDefaultCapacityRequired
static string ArgumentOutOfRange_CapacityLargerThanLogicalAddressSpaceNotAllowed
static string ArgumentNull_MapName
static string Argument_NewMMFAppendModeNotAllowed
static string ArgumentOutOfRange_CapacityGEFileSizeRequired
static string ArgumentOutOfRange_NeedNonNegNum
static string ArgumentOutOfRange_NeedPositiveNumber
static string Argument_EmptyFile
static void Sleep(int millisecondsTimeout)