Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Jan 17, 2015
2 parents 34d28bd + d0ff7a4 commit 64e6519
Show file tree
Hide file tree
Showing 19 changed files with 741 additions and 573 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading;

internal static partial class Interop
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.InteropServices;
using System.Security;

namespace Microsoft.Win32.SafeHandles
{
public sealed partial class SafeMemoryMappedFileHandle : SafeHandle
{
private const int DefaultInvalidHandleValue = -1; // TODO: Implement this

protected override bool ReleaseHandle()
{
throw NotImplemented.ByDesign; // TODO: Implement this
}

public override bool IsInvalid
{
[SecurityCritical]
get { throw NotImplemented.ByDesign; } // TODO: Implement this
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.InteropServices;
using System.Security;

namespace Microsoft.Win32.SafeHandles
{
public sealed partial class SafeMemoryMappedFileHandle : SafeHandle
{
private const int DefaultInvalidHandleValue = 0;

protected override bool ReleaseHandle()
{
return Interop.mincore.CloseHandle(handle);
}

public override bool IsInvalid
{
[SecurityCritical]
get
{
return handle == IntPtr.Zero || handle == new IntPtr(-1);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,18 @@

namespace Microsoft.Win32.SafeHandles
{
// Reliability notes:
// ReleaseHandle has reliability guarantee of Cer.Success, as defined by SafeHandle.
// It gets prepared as a CER at instance construction time.

[SecurityCritical]
public sealed class SafeMemoryMappedFileHandle : SafeHandle
public sealed partial class SafeMemoryMappedFileHandle : SafeHandle
{
internal SafeMemoryMappedFileHandle() : base(IntPtr.Zero, true) { }

internal SafeMemoryMappedFileHandle(IntPtr handle, bool ownsHandle)
: base(IntPtr.Zero, ownsHandle)
internal SafeMemoryMappedFileHandle()
: base(new IntPtr(DefaultInvalidHandleValue), true)
{
SetHandle(handle);
}

override protected bool ReleaseHandle()
{
return Interop.mincore.CloseHandle(handle);
}

public override bool IsInvalid
internal SafeMemoryMappedFileHandle(IntPtr handle, bool ownsHandle)
: base(new IntPtr(DefaultInvalidHandleValue), ownsHandle)
{
[SecurityCritical]
get
{
return handle == IntPtr.Zero || handle == new IntPtr(-1);
}
SetHandle(handle);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.InteropServices;

namespace Microsoft.Win32.SafeHandles
{
public sealed partial class SafeMemoryMappedViewHandle
{
protected override bool ReleaseHandle()
{
throw NotImplemented.ByDesign; // TODO: Implement this
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Runtime.InteropServices;

namespace Microsoft.Win32.SafeHandles
{
public sealed partial class SafeMemoryMappedViewHandle
{
protected override bool ReleaseHandle()
{
if (Interop.mincore.UnmapViewOfFile(handle) != 0)
{
handle = IntPtr.Zero;
return true;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,20 @@

namespace Microsoft.Win32.SafeHandles
{
// Reliability notes:
// ReleaseHandle has reliability guarantee of Cer.Success, as defined by SafeHandle.
// It gets prepared as a CER at instance construction time.

[SecurityCritical]
#pragma warning disable 0618 // SafeBuffer is obsolete
public sealed class SafeMemoryMappedViewHandle : SafeBuffer
public sealed partial class SafeMemoryMappedViewHandle : SafeBuffer
#pragma warning restore
{
internal SafeMemoryMappedViewHandle() : base(true) { }

internal SafeMemoryMappedViewHandle(IntPtr handle, bool ownsHandle) : base(ownsHandle)
internal SafeMemoryMappedViewHandle()
: base(true)
{
base.SetHandle(handle);
}

override protected bool ReleaseHandle()
internal SafeMemoryMappedViewHandle(IntPtr handle, bool ownsHandle)
: base(ownsHandle)
{
if (Interop.mincore.UnmapViewOfFile(handle) != 0)
{
handle = IntPtr.Zero;
return true;
}
return false;
base.SetHandle(handle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,50 @@
<!-- References are resolved from packages.config -->
<!-- Compiled Source Files -->
<ItemGroup>
<Compile Include="..\..\Common\src\System\IO\__Error.cs">
<Link>System\IO\__Error.cs</Link>
</Compile>
<Compile Include="..\..\Common\src\System\SR.cs">
<Link>System\SR.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="Interop\Interop.Manual.cs" />
<Compile Include="Microsoft\Win32\SafeMemoryMappedFileHandle.cs" />
<Compile Include="Microsoft\Win32\SafeMemoryMappedViewHandle.cs" />
<Compile Include="System\IO\MemoryMappedFiles\Enums.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedFileOptions.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedFileAccess.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedFile.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedView.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedViewAccessor.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedViewStream.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedFileRights.cs" />
</ItemGroup>
<!-- Common files -->
<ItemGroup>
<Compile Include="..\..\Common\src\System\IO\__Error.cs">
<Link>System\IO\__Error.cs</Link>
</Compile>

<ItemGroup Condition=" '$(OS)' == 'Windows_NT' ">
<Compile Include="..\..\Common\src\System\IO\Win32Marshal.cs">
<Link>System\IO\Win32Marshal.cs</Link>
</Compile>
<Compile Include="..\..\Common\src\System\SR.cs">
<Link>System\SR.cs</Link>
</Compile>
<Compile Include="..\..\Common\src\System\ArrayT.cs">
<Link>System\ArrayT.cs</Link>
<Compile Include="Interop\Interop.Windows.cs" />
<Compile Include="Microsoft\Win32\SafeMemoryMappedFileHandle.Windows.cs" />
<Compile Include="Microsoft\Win32\SafeMemoryMappedViewHandle.Windows.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedFile.Windows.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedView.Windows.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(OS)' == 'Unix' ">
<Compile Include="..\..\Common\src\System\NotImplemented.cs"> <!-- TODO: Remove once implemented -->
<Link>System\NotImplemented.cs</Link>
</Compile>
<Compile Include="Microsoft\Win32\SafeMemoryMappedFileHandle.Unix.cs" />
<Compile Include="Microsoft\Win32\SafeMemoryMappedViewHandle.Unix.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedFile.Unix.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedView.Unix.cs" />
</ItemGroup>

<!-- Resource files -->
<ItemGroup>
<EmbeddedResource Include="Resources\Strings.resx">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Win32.SafeHandles;
using System.Security;

namespace System.IO.MemoryMappedFiles
{
public partial class MemoryMappedFile
{
/// <summary>
/// Used by the 2 Create factory method groups. A -1 fileHandle specifies that the
/// memory mapped file should not be associated with an exsiting file on disk (ie start
/// out empty).
/// </summary>
[SecurityCritical]
private static SafeMemoryMappedFileHandle CreateCore(
SafeFileHandle fileHandle, String mapName, HandleInheritability inheritability,
MemoryMappedFileAccess access, MemoryMappedFileOptions options, Int64 capacity)
{
throw NotImplemented.ByDesign; // TODO: Implement this
}

/// <summary>
/// Used by the OpenExisting factory method group and by CreateOrOpen if access is write.
/// We'll throw an ArgumentException if the file mapping object didn't exist and the
/// caller used CreateOrOpen since Create isn't valid with Write access
/// </summary>
[SecurityCritical]
private static SafeMemoryMappedFileHandle OpenCore(
String mapName, HandleInheritability inheritability, MemoryMappedFileAccess access, bool createOrOpen)
{
throw NotImplemented.ByDesign; // TODO: Implement this
}

/// <summary>
/// Used by the OpenExisting factory method group and by CreateOrOpen if access is write.
/// We'll throw an ArgumentException if the file mapping object didn't exist and the
/// caller used CreateOrOpen since Create isn't valid with Write access
/// </summary>
[SecurityCritical]
private static SafeMemoryMappedFileHandle OpenCore(
String mapName, HandleInheritability inheritability, MemoryMappedFileRights rights, bool createOrOpen)
{
throw NotImplemented.ByDesign; // TODO: Implement this
}

/// <summary>
/// Used by the CreateOrOpen factory method groups. A -1 fileHandle specifies that the
/// memory mapped file should not be associated with an existing file on disk (ie start
/// out empty).
///
/// Try to open the file if it exists -- this requires a bit more work. Loop until we can
/// either create or open a memory mapped file up to a timeout. CreateFileMapping may fail
/// if the file exists and we have non-null security attributes, in which case we need to
/// use OpenFileMapping. But, there exists a race condition because the memory mapped file
/// may have closed inbetween the two calls -- hence the loop.
///
/// This uses similar retry/timeout logic as in performance counter. It increases the wait
/// time each pass through the loop and times out in approximately 1.4 minutes. If after
/// retrying, a MMF handle still hasn't been opened, throw an InvalidOperationException.
/// </summary>
[SecurityCritical]
private static SafeMemoryMappedFileHandle CreateOrOpenCore(
SafeFileHandle fileHandle, String mapName, HandleInheritability inheritability,
MemoryMappedFileAccess access, MemoryMappedFileOptions options, Int64 capacity)
{
throw NotImplemented.ByDesign; // TODO: Implement this
}

// -----------------------------
// ---- PAL layer ends here ----
// -----------------------------

}
}
Loading

0 comments on commit 64e6519

Please sign in to comment.