Skip to content

Commit

Permalink
tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-efremov committed Jun 17, 2017
1 parent c5b0056 commit 1a7a05e
Show file tree
Hide file tree
Showing 21 changed files with 575 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Expand Up @@ -48,7 +48,7 @@
url = git://github.com/mono/roslyn-binaries.git
[submodule "external/corert"]
path = external/corert
url = git://github.com/mono/corert.git
url = git://github.com/dampir/corert.git
[submodule "external/xunit-binaries"]
path = external/xunit-binaries
url = git://github.com/mono/xunit-binaries.git
Expand Down
72 changes: 72 additions & 0 deletions configure.ac
Expand Up @@ -3348,6 +3348,77 @@ if test "x$host" != "x$target"; then
esac
fi

CORERT_PAL_SUPPORTED=no
CORERT_PAL_ARCH=
CORERT_PAL_OS=

case "$host" in
i*86-*-linux*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=x86
CORERT_PAL_OS=Linux
;;
i*86-*-darwin*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=x86
CORERT_PAL_OS=OSX
;;
i*86-*-freebsd*|i*86-*-kfreebsd-gnu*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=x86
CORERT_PAL_OS=FreeBSD
;;
x86_64-*-linux*|amd64-*-linux*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=x64
CORERT_PAL_OS=Linux
;;
x86_64-*-darwin*|amd64-*-darwin*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=x64
CORERT_PAL_OS=OSX
;;
x86_64-*-freebsd*|amd64-*-freebsd*|x86_64-*-kfreebsd-gnu*|amd64-*-kfreebsd-gnu*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=x64
CORERT_PAL_OS=FreeBSD
;;
arm*-*-darwin*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=arm
CORERT_PAL_OS=OSX
;;
arm*-*-linux*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=arm
CORERT_PAL_OS=Linux
;;
arm*-*-freebsd*|arm*-*-kfreebsd-gnu*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=arm
CORERT_PAL_OS=FreeBSD
;;
aarch64-*-darwin*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=arm64
CORERT_PAL_OS=OSX
;;
aarch64-*-linux*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=arm64
CORERT_PAL_OS=Linux
;;
aarch64-*-freebsd*|aarch64-*-kfreebsd-gnu*)
CORERT_PAL_SUPPORTED=yes
CORERT_PAL_ARCH=arm64
CORERT_PAL_OS=FreeBSD
;;
esac

AM_CONDITIONAL(CORERT_PAL_SUPPORTED, [test x$CORERT_PAL_SUPPORTED = xyes])
AC_SUBST(CORERT_PAL_ARCH)
AC_SUBST(CORERT_PAL_OS)

case "$TARGET" in
X86)
AC_DEFINE(TARGET_X86, 1, [...])
Expand Down Expand Up @@ -4335,6 +4406,7 @@ scripts/mono-find-provides
scripts/mono-find-requires
mono/Makefile
mono/btls/Makefile
mono/pal/Makefile
mono/utils/Makefile
mono/metadata/Makefile
mono/dis/Makefile
Expand Down
1 change: 1 addition & 0 deletions data/config.in
Expand Up @@ -13,6 +13,7 @@
<dllmap dll="MonoPosixHelper" target="$mono_libdir/libMonoPosixHelper@libsuffix@" os="!windows" />
<dllmap dll="libmono-btls-shared" target="$mono_libdir/libmono-btls-shared@libsuffix@" os="!windows" />
<dllmap dll="i:msvcrt" target="@LIBC@" os="!windows"/>
<dllmap dll="System.Native" target="$mono_libdir/System.Native@libsuffix@" os="!windows"/>
<dllmap dll="i:msvcrt.dll" target="@LIBC@" os="!windows"/>
<dllmap dll="sqlite" target="@SQLITE@" os="!windows"/>
<dllmap dll="sqlite3" target="@SQLITE3@" os="!windows"/>
Expand Down
2 changes: 1 addition & 1 deletion external/corert
Submodule corert updated from 48dba7 to 8c0e2c
2 changes: 1 addition & 1 deletion mcs/class/Mono.Debugger.Soft/Test/dtest.cs
Expand Up @@ -4150,7 +4150,7 @@ Event step_out_await (string method, Event e)
Assert.Fail ("Known limitation - can't get info from m2n frames");
} catch (AbsentInformationException) {}

frame = frames [3];
frame = frames [4];
Assert.IsFalse (frame.IsNativeTransition, "#12.1");
var wait_one_this = frame.GetThis ();
Assert.IsNotNull (wait_one_this, "#12.2");
Expand Down
Expand Up @@ -23,7 +23,7 @@ namespace System.ComponentModel.Composition.Hosting
/// </summary>
internal class ComposablePartCatalogCollection : ICollection<ComposablePartCatalog>, INotifyComposablePartCatalogChanged, IDisposable
{
private readonly Lock _lock = new Lock();
private readonly Microsoft.Internal.Lock _lock = new Microsoft.Internal.Lock();
private Action<ComposablePartCatalogChangeEventArgs> _onChanged;
private Action<ComposablePartCatalogChangeEventArgs> _onChanging;
private List<ComposablePartCatalog> _catalogs = new List<ComposablePartCatalog>();
Expand Down
Expand Up @@ -29,7 +29,7 @@ namespace System.ComponentModel.Composition.Hosting
internal sealed class CompositionLock : IDisposable
{
// narrow lock
private readonly Lock _stateLock = null;
private readonly Microsoft.Internal.Lock _stateLock = null;
// wide lock
private static object _compositionLock = new object();

Expand All @@ -43,7 +43,7 @@ public CompositionLock(bool isThreadSafe)
this._isThreadSafe = isThreadSafe;
if (isThreadSafe)
{
this._stateLock = new Lock();
this._stateLock = new Microsoft.Internal.Lock();
}
}

Expand Down
Expand Up @@ -63,7 +63,7 @@ internal static class MetadataViewGenerator
public const string MetadataItemSourceType = "MetadataItemSourceType";
public const string MetadataItemValue = "MetadataItemValue";

private static Lock _lock = new Lock();
private static Microsoft.Internal.Lock _lock = new Microsoft.Internal.Lock();
private static Dictionary<Type, Type> _proxies = new Dictionary<Type, Type>();
private static AssemblyName ProxyAssemblyName = new AssemblyName(string.Format(CultureInfo.InvariantCulture, "MetadataViewProxies_{0}", Guid.NewGuid()));
#if FEATURE_CAS_APTCA
Expand Down
71 changes: 71 additions & 0 deletions mcs/class/corlib/System.Runtime.InteropServices/SafeHandle.cs
Expand Up @@ -163,6 +163,77 @@ void InternalFinalize ()
DangerousReleaseInternal (true);
}

// Do not call this directly - only call through the extension method SafeHandleExtensions.DangerousAddRef.
internal void DangerousAddRef_WithNoNullCheck()
{
// To prevent handle recycling security attacks we must enforce the
// following invariant: we cannot successfully AddRef a handle on which
// we've committed to the process of releasing.

// We ensure this by never AddRef'ing a handle that is marked closed and
// never marking a handle as closed while the ref count is non-zero. For
// this to be thread safe we must perform inspection/updates of the two
// values as a single atomic operation. We achieve this by storing them both
// in a single aligned DWORD and modifying the entire state via interlocked
// compare exchange operations.

// Additionally we have to deal with the problem of the Dispose operation.
// We must assume that this operation is directly exposed to untrusted
// callers and that malicious callers will try and use what is basically a
// Release call to decrement the ref count to zero and free the handle while
// it's still in use (the other way a handle recycling attack can be
// mounted). We combat this by allowing only one Dispose to operate against
// a given safe handle (which balances the creation operation given that
// Dispose suppresses finalization). We record the fact that a Dispose has
// been requested in the same state field as the ref count and closed state.

// So the state field ends up looking like this:
//
// 31 2 1 0
// +-----------------------------------------------------------+---+---+
// | Ref count | D | C |
// +-----------------------------------------------------------+---+---+
//
// Where D = 1 means a Dispose has been performed and C = 1 means the
// underlying handle has (or will be shortly) released.


// Might have to perform the following steps multiple times due to
// interference from other AddRef's and Release's.
int oldState, newState;
do
{
// First step is to read the current handle state. We use this as a
// basis to decide whether an AddRef is legal and, if so, to propose an
// update predicated on the initial state (a conditional write).
oldState = _state;

// Check for closed state.
if ((oldState & StateBits.Closed) != 0)
{
throw new ObjectDisposedException("SafeHandle");
}

// Not closed, let's propose an update (to the ref count, just add
// StateBits.RefCountOne to the state to effectively add 1 to the ref count).
// Continue doing this until the update succeeds (because nobody
// modifies the state field between the read and write operations) or
// the state moves to closed.
newState = oldState + StateBits.RefCountOne;
} while (Interlocked.CompareExchange(ref _state, newState, oldState) != oldState);
// If we got here we managed to update the ref count while the state
// remained non closed. So we're done.
}

// Bitmasks for the _state field above.
private static class StateBits
{
public const int Closed = 0x00000001;
public const int Disposed = 0x00000002;
public const int RefCount = unchecked((int)0xfffffffc);
public const int RefCountOne = 4; // Amount to increment state field to yield a ref count increment of 1
};

void DangerousReleaseInternal (bool dispose)
{
try {}
Expand Down

0 comments on commit 1a7a05e

Please sign in to comment.