pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Import coreclr-1.0.0 as wip/coreclr.



Module Name:	pkgsrc-wip
Committed By:	Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By:	kamil
Date:		Thu Jun 30 13:40:46 2016 +0200
Changeset:	d368affe9514ae23af9592559ab0e64fe49c0fba

Added Files:
	coreclr/DESCR
	coreclr/Makefile
	coreclr/PLIST
	coreclr/README
	coreclr/buildlink3.mk
	coreclr/distinfo
	coreclr/patches/patch-src_debug_debug-pal_unix_twowaypipe.cpp
	coreclr/patches/patch-src_debug_ee_debugger.cpp
	coreclr/patches/patch-src_debug_inc_twowaypipe.h
	coreclr/patches/patch-src_debug_shared_dbgtransportsession.cpp
	coreclr/patches/patch-src_inc_clrconfigvalues.h
	coreclr/patches/patch-src_pal_inc_pal.h
	coreclr/patches/patch-src_pal_src_config.h.in
	coreclr/patches/patch-src_pal_src_configure.cmake
	coreclr/patches/patch-src_pal_src_thread_process.cpp

Log Message:
Import coreclr-1.0.0 as wip/coreclr.

This repo contains the .NET Core runtime, called CoreCLR, and the base library,
called mscorlib. It includes the garbage collector, JIT compiler, base .NET
data types and many low-level classes.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=d368affe9514ae23af9592559ab0e64fe49c0fba

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 coreclr/DESCR                                      |   3 +
 coreclr/Makefile                                   |  79 +++
 coreclr/PLIST                                      |  75 +++
 coreclr/README                                     |  14 +
 coreclr/buildlink3.mk                              |  30 ++
 coreclr/distinfo                                   |  15 +
 .../patch-src_debug_debug-pal_unix_twowaypipe.cpp  |  74 +++
 coreclr/patches/patch-src_debug_ee_debugger.cpp    |  33 ++
 coreclr/patches/patch-src_debug_inc_twowaypipe.h   |  35 ++
 .../patch-src_debug_shared_dbgtransportsession.cpp |  36 ++
 coreclr/patches/patch-src_inc_clrconfigvalues.h    |  22 +
 coreclr/patches/patch-src_pal_inc_pal.h            |  45 ++
 coreclr/patches/patch-src_pal_src_config.h.in      |  32 ++
 coreclr/patches/patch-src_pal_src_configure.cmake  | 102 ++++
 .../patches/patch-src_pal_src_thread_process.cpp   | 552 +++++++++++++++++++++
 15 files changed, 1147 insertions(+)

diffs:
diff --git a/coreclr/DESCR b/coreclr/DESCR
new file mode 100644
index 0000000..9e69cfc
--- /dev/null
+++ b/coreclr/DESCR
@@ -0,0 +1,3 @@
+This repo contains the .NET Core runtime, called CoreCLR, and the base library,
+called mscorlib. It includes the garbage collector, JIT compiler, base .NET
+data types and many low-level classes.
diff --git a/coreclr/Makefile b/coreclr/Makefile
new file mode 100644
index 0000000..a973c1d
--- /dev/null
+++ b/coreclr/Makefile
@@ -0,0 +1,79 @@
+# $NetBSD: Makefile,v 1.3 2015/04/25 10:01:54 krytarowski Exp $
+
+DISTNAME=	coreclr-1.0.0
+CATEGORIES=	devel
+MASTER_SITES=	${MASTER_SITE_GITHUB:=dotnet/}
+GITHUB_TAG=	v${PKGVERSION_NOREV}
+
+MAINTAINER=	kamil%NetBSD.org@localhost
+HOMEPAGE=	https://dotnet.github.io/
+COMMENT=	The .NET Core runtime and the base library
+LICENSE=	mit
+
+DEPENDS+=	${PYPKGPREFIX}-expat-[0-9]*:../../textproc/py-expat
+
+USE_LANGUAGES=	c c++
+USE_TOOLS+=	bash pax
+# We need to set CMake this way to get defined CMAKE_ARGS
+USE_CMAKE=	yes
+CMAKE_ARGS+=	-DCORECLR_SET_RPATH:BOOL=OFF
+
+REPLACE_BASH+=	build.sh src/pal/tests/palsuite/runpaltests.sh
+
+CORECLR_PREFIX=	${PREFIX}/CoreCLR
+
+.include "../../mk/bsd.prefs.mk"
+
+.if ${MACHINE_ARCH} == "x86_64"
+CORECLR_ARCH=	x64
+.endif
+
+CORECLR_OBJDIR=		${WRKSRC}/bin/obj/${OPSYS}.${CORECLR_ARCH}.Debug
+CORECLR_PRODUCTDIR=	${WRKSRC}/bin/Product/${OPSYS}.${CORECLR_ARCH}.Debug
+
+# Handle subprefix
+LDFLAGS+=	${COMPILER_RPATH_FLAG}${CORECLR_PREFIX:Q}
+LDFLAGS+=	${COMPILER_RPATH_FLAG}${CORECLR_PREFIX:Q}/Loader/NativeLibs
+LDFLAGS+=	${COMPILER_RPATH_FLAG}${CORECLR_PREFIX:Q}/bin
+
+BUILDLINK_PASSTHRU_DIRS+=	${CORECLR_PREFIX:Q}
+BUILDLINK_PASSTHRU_RPATHDIRS+=	${CORECLR_PREFIX:Q}
+
+# DOTNET targets only LLVM
+PKGSRC_COMPILER=	clang
+PKG_CC=			clang
+PKG_CXX=		clang++
+_WRAP_EXTRA_ARGS.CXX+=	-Wno-unused-function -Wno-self-assign
+CWRAPPERS_APPEND.cxx+=	-Wno-unused-function -Wno-self-assign
+
+
+TEST_ENV+=	LD_LIBRARY_PATH=${WRKSRC}/bin/obj/${OPSYS}.x64.Debug/src/pal/tests/palsuite/exception_handling/pal_sxs/test1
+
+do-configure:
+	${RUN} ${ECHO} Skip configure and call CMake via build.sh
+
+do-build:
+	${RUN} cd ${WRKSRC} && \
+	${PKGSRC_SETENV} ${MAKE_ENV} PYTHON=${PYTHONBIN:Q} \
+		./build.sh skipmscorlib cmakeargs ${CMAKE_ARGS:Q}
+
+# Currently there is no unix-like install target.
+# Put all produced files under subprefix.
+do-install:
+	${INSTALL_DATA_DIR} ${DESTDIR}${CORECLR_PREFIX:Q}
+	cd ${CORECLR_PRODUCTDIR} && ${PAX} -rw . ${DESTDIR}${CORECLR_PREFIX:Q}
+
+do-test:
+	${RUN} cd ${WRKSRC} && \
+	${SETENV} ${TEST_ENV} src/pal/tests/palsuite/runpaltests.sh \
+		${CORECLR_OBJDIR} ${WRKSRC}/paltestout
+
+.include "../../textproc/icu/buildlink3.mk"
+.include "../../lang/llvm/buildlink3.mk"
+.include "../../devel/lldb/buildlink3.mk"
+.include "../../lang/clang/buildlink3.mk"
+.include "../../lang/libunwind/buildlink3.mk"
+.include "../../lang/python/extension.mk"
+.include "../../lang/python/application.mk"
+.include "../../lang/python/tool.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/coreclr/PLIST b/coreclr/PLIST
new file mode 100644
index 0000000..f0f6b2f
--- /dev/null
+++ b/coreclr/PLIST
@@ -0,0 +1,75 @@
+@comment $NetBSD$
+CoreCLR/Loader/NativeLibs/FromNativePaths_lib.so
+CoreCLR/System.Globalization.Native.so
+CoreCLR/bin/hfa_nested_f32_native_cpp.so
+CoreCLR/bin/hfa_nested_f64_native_cpp.so
+CoreCLR/bin/hfa_simple_f32_native_cpp.so
+CoreCLR/bin/hfa_simple_f64_native_cpp.so
+CoreCLR/bin/jitstructtests_lib.so
+CoreCLR/bin/libBestFitMappingNative.so
+CoreCLR/bin/libBoolNative.so
+CoreCLR/bin/libForeignThreadExceptionsNative.so
+CoreCLR/bin/libFuncPtrAsDelegateParamNative.so
+CoreCLR/bin/libFunctionPointerNative.so
+CoreCLR/bin/libIUnknownNative.so
+CoreCLR/bin/libLPSTRTestNative.so
+CoreCLR/bin/libLPTSTRTestNative.so
+CoreCLR/bin/libMarshalArrayByValNative.so
+CoreCLR/bin/libMarshalBoolArrayNative.so
+CoreCLR/bin/libMarshalEnumNative.so
+CoreCLR/bin/libMarshalStructAsParam.so
+CoreCLR/bin/libNativeCallableDll.so
+CoreCLR/bin/libRefCharArrayNative.so
+CoreCLR/bin/libRefIntNative.so
+CoreCLR/bin/libSimpleStructNative.so
+CoreCLR/bin/libStructABILib.so
+CoreCLR/bin/libUIntPtrNative.so
+CoreCLR/bin/libUTF8TestNative.so
+CoreCLR/bin/libVector3TestNative.so
+CoreCLR/bin/mirror.so
+CoreCLR/bin/native_i0c.so
+CoreCLR/bin/native_i0s.so
+CoreCLR/bin/native_i1c.so
+CoreCLR/bin/native_i1s.so
+CoreCLR/bin/native_i3c.so
+CoreCLR/bin/native_i3s.so
+CoreCLR/bin/native_i5c.so
+CoreCLR/bin/native_i5s.so
+CoreCLR/bin/native_i6c.so
+CoreCLR/bin/native_i6s.so
+CoreCLR/bin/native_i7c.so
+CoreCLR/bin/native_i7s.so
+CoreCLR/bin/native_i8c.so
+CoreCLR/bin/native_i8s.so
+CoreCLR/bin/test2.so
+CoreCLR/coreconsole
+CoreCLR/corerun
+CoreCLR/crossgen
+CoreCLR/gcinfo/gcinfoencoder.cpp
+CoreCLR/ilasm
+CoreCLR/ildasm
+CoreCLR/inc/cfi.h
+CoreCLR/inc/cor.h
+CoreCLR/inc/cordebuginfo.h
+CoreCLR/inc/coredistools.h
+CoreCLR/inc/corerror.h
+CoreCLR/inc/corhdr.h
+CoreCLR/inc/corinfo.h
+CoreCLR/inc/corjit.h
+CoreCLR/inc/corjithost.h
+CoreCLR/inc/corprof.h
+CoreCLR/inc/gcinfoencoder.h
+CoreCLR/inc/gcinfotypes.h
+CoreCLR/inc/opcode.def
+CoreCLR/inc/openum.h
+CoreCLR/lib/libcoreclrpal.a
+CoreCLR/lib/libcorguids.a
+CoreCLR/lib/libpalrt.a
+CoreCLR/libclrjit.so
+CoreCLR/libcoreclr.so
+CoreCLR/libdbgshim.so
+CoreCLR/libmscordaccore.so
+CoreCLR/libmscordbi.so
+CoreCLR/libsos.so
+CoreCLR/libsosplugin.so
+CoreCLR/sosdocsunix.txt
diff --git a/coreclr/README b/coreclr/README
new file mode 100644
index 0000000..d04a38b
--- /dev/null
+++ b/coreclr/README
@@ -0,0 +1,14 @@
+Running tests:
+
+I PAL (Platform Abstraction Layer)
+
+Done in the package's Makefile:
+
+$ bmake test
+
+II Managed code tests
+
+Fetch tests from:
+http://dotnet-ci.cloudapp.net/job/dotnet_coreclr/job/master/job/debug_windows_nt/lastSuccessfulBuild/artifact/bin/tests/tests.zip
+
+In directory: tests/
diff --git a/coreclr/buildlink3.mk b/coreclr/buildlink3.mk
new file mode 100644
index 0000000..b3701e2
--- /dev/null
+++ b/coreclr/buildlink3.mk
@@ -0,0 +1,30 @@
+# $NetBSD$
+
+BUILDLINK_TREE+=	coreclr
+
+.if !defined(CORECLR_BUILDLINK3_MK)
+CORECLR_BUILDLINK3_MK:=
+
+BUILDLINK_API_DEPENDS.coreclr+=	coreclr>=0.0.0nb20160222
+BUILDLINK_PKGSRCDIR.coreclr?=	../../wip/coreclr-git
+
+BUILDLINK_INCDIRS.coreclr+=	CoreCLR/inc
+BUILDLINK_INCDIRS.coreclr+=	CoreCLR/gcinfo
+BUILDLINK_FILES.coreclr+=	CoreCLR/gcinfo/gcinfoencoder.cpp
+BUILDLINK_FILES.coreclr+=	CoreCLR/inc/*.h
+BUILDLINK_FILES.coreclr+=	CoreCLR/inc/*.def
+
+.include "../../textproc/icu/buildlink3.mk"
+# Stable LLVM
+#.include "../../lang/llvm/buildlink3.mk"
+#.include "../../devel/lldb/buildlink3.mk"
+#.include "../../lang/clang/buildlink3.mk"
+#.include "../../lang/libunwind/buildlink3.mk"
+# Devel LLVM
+.include "../../wip/llvm-git/buildlink3.mk"
+.include "../../wip/lldb-git/buildlink3.mk"
+.include "../../wip/clang-git/buildlink3.mk"
+.include "../../wip/libunwind-git/buildlink3.mk"
+.endif	# CORECLR_BUILDLINK3_MK
+
+BUILDLINK_TREE+=	-coreclr
diff --git a/coreclr/distinfo b/coreclr/distinfo
new file mode 100644
index 0000000..f678c2b
--- /dev/null
+++ b/coreclr/distinfo
@@ -0,0 +1,15 @@
+$NetBSD$
+
+SHA1 (coreclr-1.0.0.tar.gz) = 0e9d7c8f78376c087abd0d83f959c8d1b8d3045c
+RMD160 (coreclr-1.0.0.tar.gz) = c275c337106f30f8050bd534e707b681c89f012b
+SHA512 (coreclr-1.0.0.tar.gz) = f4500fbc470044139e3dbb1a03e466b522546bba2b0964ec2506e1d002be7e78cf75592c4c42f2b09940881173b2305785b7499fb2967a32c4b72c03cc1bd8a9
+Size (coreclr-1.0.0.tar.gz) = 34303728 bytes
+SHA1 (patch-src_debug_debug-pal_unix_twowaypipe.cpp) = d514b087cf091e3a95c04dc4d7e22846b179a04b
+SHA1 (patch-src_debug_ee_debugger.cpp) = fe5df4646f063d19db3466f7b36b862f50d4f060
+SHA1 (patch-src_debug_inc_twowaypipe.h) = aea06d9e5d764cee3b7132e72b02b678b87c3d72
+SHA1 (patch-src_debug_shared_dbgtransportsession.cpp) = 487a595dd8bd1855056171f0d3ba5b99c092f576
+SHA1 (patch-src_inc_clrconfigvalues.h) = 8ca7841a24a7af459a9c26e737ef1ee2ece90be2
+SHA1 (patch-src_pal_inc_pal.h) = b29f2adbbdc07418dd6c269d9d4d9444c43f4ca3
+SHA1 (patch-src_pal_src_config.h.in) = fb8a262308f46707c083c7471be87ba0ac79947f
+SHA1 (patch-src_pal_src_configure.cmake) = 72865c6fd355901862192280a727351de62f5ac5
+SHA1 (patch-src_pal_src_thread_process.cpp) = fdb7b548da9989f352ad69e459d23e82d63a13a6
diff --git a/coreclr/patches/patch-src_debug_debug-pal_unix_twowaypipe.cpp b/coreclr/patches/patch-src_debug_debug-pal_unix_twowaypipe.cpp
new file mode 100644
index 0000000..78615b9
--- /dev/null
+++ b/coreclr/patches/patch-src_debug_debug-pal_unix_twowaypipe.cpp
@@ -0,0 +1,74 @@
+$NetBSD$
+
+Revert:
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/debug/debug-pal/unix/twowaypipe.cpp.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/debug/debug-pal/unix/twowaypipe.cpp
+@@ -3,14 +3,31 @@
+ // See the LICENSE file in the project root for more information.
+ 
+ #include <pal.h>
++
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <limits.h>
+ #include <pal_assert.h>
++
+ #include "twowaypipe.h"
+ 
++static const char* PipeNameFormat = "/tmp/clr-debug-pipe-%d-%llu-%s";
++
++void TwoWayPipe::GetPipeName(char *name, DWORD id, const char *suffix)
++{
++    BOOL ret = GetProcessIdDisambiguationKey(id, &m_disambiguationKey);
++
++    // If GetProcessIdDisambiguationKey failed for some reason, it should set the value 
++    // to 0. We expect that anyone else making the pipe name will also fail and thus will
++    // also try to use 0 as the value.
++    _ASSERTE(ret == TRUE || m_disambiguationKey == 0);
++
++    int chars = _snprintf(name, MaxPipeNameLength, PipeNameFormat, id, m_disambiguationKey, suffix);
++    _ASSERTE(chars > 0 && chars < MaxPipeNameLength);
++}
++
+ // Creates a server side of the pipe. 
+ // Id is used to create pipes names and uniquely identify the pipe on the machine. 
+ // true - success, false - failure (use GetLastError() for more details)
+@@ -21,8 +38,8 @@ bool TwoWayPipe::CreateServer(DWORD id)
+         return false;
+ 
+     m_id = id;
+-    PAL_GetTransportPipeName(m_inPipeName, id, "in");
+-    PAL_GetTransportPipeName(m_outPipeName, id, "out");
++    GetPipeName(m_inPipeName, id, "in");
++    GetPipeName(m_outPipeName, id, "out");
+ 
+     if (mkfifo(m_inPipeName, S_IRWXU) == -1)
+     {
+@@ -50,8 +67,8 @@ bool TwoWayPipe::Connect(DWORD id)
+ 
+     m_id = id;
+     //"in" and "out" are switched deliberately, because we're on the client
+-    PAL_GetTransportPipeName(m_inPipeName, id, "out");
+-    PAL_GetTransportPipeName(m_outPipeName, id, "in");
++    GetPipeName(m_inPipeName, id, "out");
++    GetPipeName(m_outPipeName, id, "in");
+ 
+     // Pipe opening order is reversed compared to WaitForConnection()
+     // in order to avaid deadlock.
+@@ -190,4 +207,5 @@ void TwoWayPipe::CleanupTargetProcess()
+ {
+     unlink(m_inPipeName);
+     unlink(m_outPipeName);
++    PAL_CleanupTargetProcess(m_id, m_disambiguationKey);
+ }
diff --git a/coreclr/patches/patch-src_debug_ee_debugger.cpp b/coreclr/patches/patch-src_debug_ee_debugger.cpp
new file mode 100644
index 0000000..43021ba
--- /dev/null
+++ b/coreclr/patches/patch-src_debug_ee_debugger.cpp
@@ -0,0 +1,33 @@
+$NetBSD$
+
+Revert:                                                         
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/debug/ee/debugger.cpp.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/debug/ee/debugger.cpp
+@@ -2113,9 +2113,18 @@ HRESULT Debugger::Startup(void)
+             ShutdownTransport();
+             ThrowHR(hr);
+         }
++
+     #ifdef FEATURE_PAL
+         PAL_SetShutdownCallback(AbortTransport);
+     #endif // FEATURE_PAL
++
++         bool waitForAttach = CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_DbgWaitForDebuggerAttach) != 0;
++         if (waitForAttach)
++         {
++             // Mark this process as launched by the debugger and the debugger as attached.
++             g_CORDebuggerControlFlags |= DBCF_GENERATE_DEBUG_CODE;
++             MarkDebuggerAttachedInternal();
++         }
+     #endif // FEATURE_DBGIPC_TRANSPORT_VM
+ 
+         RaiseStartupNotification();
diff --git a/coreclr/patches/patch-src_debug_inc_twowaypipe.h b/coreclr/patches/patch-src_debug_inc_twowaypipe.h
new file mode 100644
index 0000000..3cd5f1b
--- /dev/null
+++ b/coreclr/patches/patch-src_debug_inc_twowaypipe.h
@@ -0,0 +1,35 @@
+$NetBSD$
+
+Revert:                                                         
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/debug/inc/twowaypipe.h.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/debug/inc/twowaypipe.h
+@@ -81,12 +81,18 @@ private:
+ 
+     State m_state;
+ 
++
+ #ifdef FEATURE_PAL
+ 
++    static const int MaxPipeNameLength = 64;
++
++    void GetPipeName(char *name, DWORD id, const char *suffix);
++
+     int m_id;                               // id that was passed to CreateServer() or Connect()
+     int m_inboundPipe, m_outboundPipe;      // two one sided pipes used for communication
+-    char m_inPipeName[MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH];   // filename of the inbound pipe
+-    char m_outPipeName[MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH];  // filename of the outbound pipe
++    UINT64 m_disambiguationKey;             // key to make the names more unique
++    char m_inPipeName[MaxPipeNameLength];   // filename of the inbound pipe
++    char m_outPipeName[MaxPipeNameLength];  // filename of the outbound pipe
+ 
+ #else
+     // Connects to a one sided pipe previously created by CreateOneWayPipe.
diff --git a/coreclr/patches/patch-src_debug_shared_dbgtransportsession.cpp b/coreclr/patches/patch-src_debug_shared_dbgtransportsession.cpp
new file mode 100644
index 0000000..e416887
--- /dev/null
+++ b/coreclr/patches/patch-src_debug_shared_dbgtransportsession.cpp
@@ -0,0 +1,36 @@
+$NetBSD$
+
+Revert:                                                         
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/debug/shared/dbgtransportsession.cpp.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/debug/shared/dbgtransportsession.cpp
+@@ -130,11 +130,6 @@ HRESULT DbgTransportSession::Init(Debugg
+     m_hSessionOpenEvent = WszCreateEvent(NULL, TRUE, FALSE, NULL); // Manual reset, not signalled
+     if (m_hSessionOpenEvent == NULL)
+         return E_OUTOFMEMORY;
+-#else // RIGHT_SIDE_COMPILE
+-    DWORD pid = GetCurrentProcessId(); 
+-    if (!m_pipe.CreateServer(pid)) {
+-        return E_OUTOFMEMORY;
+-    }
+ #endif // RIGHT_SIDE_COMPILE
+ 
+     // Allocate some buffers to receive incoming events. The initial number is chosen arbitrarily, tune as
+@@ -1350,8 +1345,7 @@ void DbgTransportSession::TransportWorke
+         else
+         {
+             DWORD pid = GetCurrentProcessId(); 
+-            if ((m_pipe.GetState() == TwoWayPipe::Created || m_pipe.CreateServer(pid)) && 
+-                 m_pipe.WaitForConnection())
++            if (m_pipe.CreateServer(pid) && m_pipe.WaitForConnection())
+             {
+                 eStatus = SCS_Success;
+             }
diff --git a/coreclr/patches/patch-src_inc_clrconfigvalues.h b/coreclr/patches/patch-src_inc_clrconfigvalues.h
new file mode 100644
index 0000000..04d3164
--- /dev/null
+++ b/coreclr/patches/patch-src_inc_clrconfigvalues.h
@@ -0,0 +1,22 @@
+$NetBSD$
+
+Revert:                                                         
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/inc/clrconfigvalues.h.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/inc/clrconfigvalues.h
+@@ -249,6 +249,7 @@ CONFIG_DWORD_INFO_DIRECT_ACCESS(INTERNAL
+ CONFIG_DWORD_INFO_DIRECT_ACCESS(INTERNAL_DbgTransportLogClass, W("DbgTransportLogClass"), "mask to control what is logged in DbgTransportLog")
+ RETAIL_CONFIG_STRING_INFO_EX(UNSUPPORTED_DbgTransportProxyAddress, W("DbgTransportProxyAddress"), "allows specifying the transport proxy address", CLRConfig::REGUTIL_default)
+ CONFIG_DWORD_INFO_EX(INTERNAL_DbgTrapOnSkip, W("DbgTrapOnSkip"), 0, "allows breaking when we skip a breakpoint", CLRConfig::REGUTIL_default)
++RETAIL_CONFIG_DWORD_INFO(UNSUPPORTED_DbgWaitForDebuggerAttach, W("DbgWaitForDebuggerAttach"), 0, "Makes CoreCLR wait for a managed debugger to attach on process start (1) or regular process start (0)")
+ CONFIG_DWORD_INFO_EX(INTERNAL_DbgWaitTimeout, W("DbgWaitTimeout"), 1, "specifies the timeout value for waits", CLRConfig::REGUTIL_default)
+ RETAIL_CONFIG_DWORD_INFO_EX(UNSUPPORTED_DbgWFDETimeout, W("DbgWFDETimeout"), 25, "specifies the timeout value for wait when waiting for a debug event", CLRConfig::REGUTIL_default)
+ CONFIG_DWORD_INFO_EX(INTERNAL_RaiseExceptionOnAssert, W("RaiseExceptionOnAssert"), 0, "Raise a first chance (if set to 1) or second chance (if set to 2) exception on asserts.", CLRConfig::REGUTIL_default)
diff --git a/coreclr/patches/patch-src_pal_inc_pal.h b/coreclr/patches/patch-src_pal_inc_pal.h
new file mode 100644
index 0000000..3c30b78
--- /dev/null
+++ b/coreclr/patches/patch-src_pal_inc_pal.h
@@ -0,0 +1,45 @@
+$NetBSD$
+
+Revert:                                                         
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/pal/inc/pal.h.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/pal/inc/pal.h
+@@ -583,12 +583,12 @@ BOOL
+ PALAPI
+ PAL_NotifyRuntimeStarted();
+ 
+-static const int MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH = 64;
+-
+ PALIMPORT
+-void
++VOID
+ PALAPI
+-PAL_GetTransportPipeName(char *name, DWORD id, const char *suffix);
++PAL_CleanupTargetProcess(
++    IN int pid, 
++    IN UINT64 disambiguationKey);
+ 
+ PALIMPORT
+ void
+@@ -1690,6 +1690,13 @@ GetProcessTimes(
+         OUT LPFILETIME lpKernelTime,
+         OUT LPFILETIME lpUserTime);
+ 
++PALIMPORT
++BOOL
++PALAPI
++GetProcessIdDisambiguationKey(
++        IN DWORD processId,
++        OUT UINT64 *disambiguationKey);
++
+ #define MAXIMUM_WAIT_OBJECTS  64
+ #define WAIT_OBJECT_0 0
+ #define WAIT_ABANDONED   0x00000080
diff --git a/coreclr/patches/patch-src_pal_src_config.h.in b/coreclr/patches/patch-src_pal_src_config.h.in
new file mode 100644
index 0000000..965274a
--- /dev/null
+++ b/coreclr/patches/patch-src_pal_src_config.h.in
@@ -0,0 +1,32 @@
+$NetBSD$
+
+Revert:                                                         
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/pal/src/config.h.in.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/pal/src/config.h.in
+@@ -101,9 +101,6 @@
+ #cmakedefine01 PTHREAD_CREATE_MODIFIES_ERRNO
+ #cmakedefine01 SEM_INIT_MODIFIES_ERRNO
+ #cmakedefine01 HAVE_PROCFS_CTL
+-#cmakedefine01 HAVE_PROCFS_MAPS
+-#cmakedefine01 HAVE_PROCFS_STAT
+-#cmakedefine01 HAVE_PROCFS_STATUS
+ #cmakedefine01 HAVE_COMPATIBLE_ACOS
+ #cmakedefine01 HAVE_COMPATIBLE_ASIN
+ #cmakedefine01 HAVE_COMPATIBLE_POW
+@@ -139,6 +136,7 @@
+ #cmakedefine01 HAVE_SCHED_OTHER_ASSIGNABLE
+ 
+ #define CHECK_TRACE_SPECIFIERS 0
++#define PROCFS_MEM_NAME ""
+ #define HAVE_GETHRTIME 0
+ #define HAVE_LOWERCASE_ISO_NAME 0
+ #define HAVE_READ_REAL_TIME 0
diff --git a/coreclr/patches/patch-src_pal_src_configure.cmake b/coreclr/patches/patch-src_pal_src_configure.cmake
new file mode 100644
index 0000000..040a85c
--- /dev/null
+++ b/coreclr/patches/patch-src_pal_src_configure.cmake
@@ -0,0 +1,102 @@
+$NetBSD$
+
+Revert:                                                         
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/pal/src/configure.cmake.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/pal/src/configure.cmake
+@@ -665,85 +665,13 @@ int main(void) {
+   char path[1024];
+ #endif
+ 
+-  sprintf(path, \"/proc/%u/ctl\", getpid());
+-  fd = open(path, O_WRONLY);
++  sprintf(path, \"/proc/%u/$1\", getpid());
++  fd = open(path, $2);
+   if (fd == -1) {
+     exit(1);
+   }
+   exit(0);
+ }" HAVE_PROCFS_CTL)
+-set(CMAKE_REQUIRED_LIBRARIES)
+-check_cxx_source_runs("
+-#include <fcntl.h>
+-#include <stdlib.h>
+-#include <stdio.h>
+-#include <unistd.h>
+-
+-int main(void) {
+-  int fd;
+-#ifdef PATH_MAX
+-  char path[PATH_MAX];
+-#elif defined(MAXPATHLEN)
+-  char path[MAXPATHLEN];
+-#else
+-  char path[1024];
+-#endif
+-
+-  sprintf(path, \"/proc/%u/maps\", getpid());
+-  fd = open(path, O_RDONLY);
+-  if (fd == -1) {
+-    exit(1);
+-  }
+-  exit(0);
+-}" HAVE_PROCFS_MAPS)
+-set(CMAKE_REQUIRED_LIBRARIES)
+-check_cxx_source_runs("
+-#include <fcntl.h>
+-#include <stdlib.h>
+-#include <stdio.h>
+-#include <unistd.h>
+-
+-int main(void) {
+-  int fd;
+-#ifdef PATH_MAX
+-  char path[PATH_MAX];
+-#elif defined(MAXPATHLEN)
+-  char path[MAXPATHLEN];
+-#else
+-  char path[1024];
+-#endif
+-
+-  sprintf(path, \"/proc/%u/stat\", getpid());
+-  fd = open(path, O_RDONLY);
+-  if (fd == -1) {
+-    exit(1);
+-  }
+-  exit(0);
+-}" HAVE_PROCFS_STAT)
+-set(CMAKE_REQUIRED_LIBRARIES)
+-check_cxx_source_runs("
+-#include <fcntl.h>
+-#include <stdlib.h>
+-#include <stdio.h>
+-#include <unistd.h>
+-
+-int main(void) {
+-  int fd;
+-#ifdef PATH_MAX
+-  char path[PATH_MAX];
+-#elif defined(MAXPATHLEN)
+-  char path[MAXPATHLEN];
+-#else
+-  char path[1024];
+-#endif
+-
+-  sprintf(path, \"/proc/%u/status\", getpid());
+-  fd = open(path, O_RDONLY);
+-  if (fd == -1) {
+-    exit(1);
+-  }
+-  exit(0);
+-}" HAVE_PROCFS_STATUS)
+ set(CMAKE_REQUIRED_LIBRARIES m)
+ check_cxx_source_runs("
+ #include <math.h>
diff --git a/coreclr/patches/patch-src_pal_src_thread_process.cpp b/coreclr/patches/patch-src_pal_src_thread_process.cpp
new file mode 100644
index 0000000..009ef4d
--- /dev/null
+++ b/coreclr/patches/patch-src_pal_src_thread_process.cpp
@@ -0,0 +1,552 @@
+$NetBSD$
+
+Revert:                                                         
+
+commit 5ac6af932fe2a3f4b285b6dcc79010caf807ea9d
+Author: Mike McLaughlin <mikem%microsoft.com@localhost>
+Date:   Fri May 27 20:03:32 2016 -0700
+
+    Fix the named semaphore leak on OSX (and Linux) (#5269)
+
+It broke NetBSD.
+
+--- src/pal/src/thread/process.cpp.orig	2016-06-14 01:12:15.000000000 +0000
++++ src/pal/src/thread/process.cpp
+@@ -28,7 +28,6 @@ Abstract:
+ #include "pal/process.h"
+ #include "pal/init.h"
+ #include "pal/critsect.h"
+-#include "pal/debug.h"
+ #include "pal/dbgmsg.h"
+ #include "pal/utils.h"
+ #include "pal/environ.h"
+@@ -42,10 +41,8 @@ Abstract:
+ #include "pal/fakepoll.h"
+ #endif  // HAVE_POLL
+ 
+-#include <unistd.h>
+ #include <sys/mman.h>
+ #include <sys/types.h>
+-#include <sys/stat.h>
+ #include <signal.h>
+ #include <sys/wait.h>
+ #include <sys/time.h>
+@@ -93,12 +90,6 @@ PALAPI
+ StartupHelperThread(
+     LPVOID p);
+ 
+-static 
+-BOOL 
+-GetProcessIdDisambiguationKey(
+-    IN DWORD processId, 
+-    OUT UINT64 *disambiguationKey);
+-
+ //
+ // Helper memory page used by the FlushProcessWriteBuffers
+ //
+@@ -150,6 +141,10 @@ DWORD gSID = (DWORD) -1;
+ #define CLR_SEM_MAX_NAMELEN (NAME_MAX - 4)
+ #endif
+ 
++// The runtime waits on this semaphore if the dbgshim startup semaphore exists
++Volatile<sem_t *> g_continueSem = SEM_FAILED;
++char g_continueSemName[CLR_SEM_MAX_NAMELEN];
++
+ // Function to call during PAL/process shutdown/abort
+ Volatile<PSHUTDOWN_CALLBACK> g_shutdownCallback = nullptr;
+ 
+@@ -1438,9 +1433,11 @@ static bool IsCoreClrModule(const char* 
+ // Keep 31 length for Core 1.0 RC2 compatibility
+ #if defined(__NetBSD__)
+ static const char* RuntimeStartupSemaphoreName = "/clrst%08llx";
++static const char* RuntimeOldContinueSemaphoreName = "/clrco%08llx";
+ static const char* RuntimeContinueSemaphoreName = "/clrco%08llx";
+ #else
+ static const char* RuntimeStartupSemaphoreName = "/clrst%08x%016llx";
++static const char* RuntimeOldContinueSemaphoreName = "/clrco%08x%016llx";
+ static const char* RuntimeContinueSemaphoreName = "/clrco%08x%016llx";
+ #endif
+ 
+@@ -1453,8 +1450,6 @@ static uint64_t HashSemaphoreName(uint64
+ #define HashSemaphoreName(a,b) a,b
+ #endif
+ 
+-static const char* PipeNameFormat = "/tmp/clr-debug-pipe-%d-%llu-%s";
+-
+ class PAL_RuntimeStartupHelper
+ {
+     LONG m_ref;
+@@ -1463,6 +1458,7 @@ class PAL_RuntimeStartupHelper
+     PVOID m_parameter;
+     DWORD m_threadId;
+     HANDLE m_threadHandle;
++
+     DWORD m_processId;
+ 
+     // A value that, used in conjunction with the process ID, uniquely identifies a process.
+@@ -1472,10 +1468,6 @@ class PAL_RuntimeStartupHelper
+     // Debugger waits on this semaphore and the runtime signals it on startup.
+     sem_t *m_startupSem;
+ 
+-    // Debuggee waits on this semaphore and the debugger signals it after the startup callback 
+-    // registered (m_callback) returns.
+-    sem_t *m_continueSem;
+-
+ public:
+     PAL_RuntimeStartupHelper(DWORD dwProcessId, PPAL_STARTUP_CALLBACK pfnCallback, PVOID parameter) :
+         m_ref(1),
+@@ -1485,8 +1477,7 @@ public:
+         m_threadId(0),
+         m_threadHandle(NULL),
+         m_processId(dwProcessId),
+-        m_startupSem(SEM_FAILED),
+-        m_continueSem(SEM_FAILED)
++        m_startupSem(SEM_FAILED)
+     {
+     }
+ 
+@@ -1505,19 +1496,6 @@ public:
+             sem_unlink(startupSemName);
+         }
+ 
+-        if (m_continueSem != SEM_FAILED)
+-        {
+-            char continueSemName[CLR_SEM_MAX_NAMELEN];
+-            sprintf_s(continueSemName,
+-                      sizeof(continueSemName),
+-                      RuntimeContinueSemaphoreName,
+-                      HashSemaphoreName(m_processId,
+-                                        m_processIdDisambiguationKey));
+-
+-            sem_close(m_continueSem);
+-            sem_unlink(continueSemName);
+-        }
+-
+         if (m_threadHandle != NULL)
+         {
+             CloseHandle(m_threadHandle);
+@@ -1575,7 +1553,6 @@ public:
+     {
+         CPalThread *pThread = InternalGetCurrentThread();
+         char startupSemName[CLR_SEM_MAX_NAMELEN];
+-        char continueSemName[CLR_SEM_MAX_NAMELEN];
+         PAL_ERROR pe = NO_ERROR;
+ 
+         // See semaphore name format for details about this value. We store it so that
+@@ -1590,23 +1567,7 @@ public:
+                   HashSemaphoreName(m_processId,
+                                     m_processIdDisambiguationKey));
+ 
+-        sprintf_s(continueSemName,
+-                  sizeof(continueSemName),
+-                  RuntimeContinueSemaphoreName,
+-                  HashSemaphoreName(m_processId,
+-                                    m_processIdDisambiguationKey));
+-
+-        TRACE("PAL_RuntimeStartupHelper.Register creating startup '%s' continue '%s'\n", startupSemName, continueSemName);
+-
+-        // Create the continue semaphore first so we don't race with PAL_NotifyRuntimeStarted. This open will fail if another 
+-        // debugger is trying to attach to this process because the name will already exist.
+-        m_continueSem = sem_open(continueSemName, O_CREAT | O_EXCL, S_IRWXU, 0);
+-        if (m_continueSem == SEM_FAILED)
+-        {
+-            TRACE("sem_open(continue) failed: errno is %d (%s)\n", errno, strerror(errno));
+-            pe = GetSemError();
+-            goto exit;
+-        }
++        TRACE("PAL_RuntimeStartupHelper.Register startup sem '%s'\n", startupSemName);
+ 
+         // Create the debuggee startup semaphore so the runtime (debuggee) knows to wait for a debugger connection.
+         m_startupSem = sem_open(startupSemName, O_CREAT | O_EXCL, S_IRWXU, 0);
+@@ -1646,12 +1607,6 @@ public:
+     {
+         m_canceled = true;
+ 
+-        // Tell the runtime to continue
+-        if (sem_post(m_continueSem) != 0)
+-        {
+-            ASSERT("sem_post(continueSem) failed: errno is %d (%s)\n", errno, strerror(errno));
+-        }
+-
+         // Tell the worker thread to continue
+         if (sem_post(m_startupSem) != 0)
+         {
+@@ -1669,109 +1624,113 @@ public:
+         }
+     }
+ 
+-    //
+-    // There are a couple race conditions that need to be considered here:
+-    //
+-    // * On launch, between the fork and execv in the PAL's CreateProcess where the target process 
+-    //   may contain a coreclr module image if the debugger process is running managed code. This 
+-    //   makes just checking if the coreclr module exists not enough.
+-    //
+-    // * On launch (after the execv) or attach when the coreclr is loaded but before the DAC globals 
+-    //   table is initialized where it is too soon to use/initialize the DAC on the debugger side.
+-    //
+-    // They are both fixed by check if the one of transport pipe files has been created.
+-    //
+-    bool IsCoreClrProcessReady()
+-    {
+-        char pipeName[MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH];  
+-
+-        PAL_GetTransportPipeName(pipeName, m_processId, "in");
+-
+-        struct stat buf;
+-        if (stat(pipeName, &buf) == 0) 
+-        {
+-            TRACE("IsCoreClrProcessReady: stat(%s) SUCCEEDED\n", pipeName);
+-            return true;
+-        }
+-        TRACE("IsCoreClrProcessReady: stat(%s) FAILED: errno is %d (%s)\n", pipeName, errno, strerror(errno));
+-        return false;
+-    }
+-
+     PAL_ERROR InvokeStartupCallback()
+     {
+-        ProcessModules *listHead = NULL;
+         PAL_ERROR pe = NO_ERROR;
+-        DWORD count;
+ 
+-        if (m_canceled)
++        if (!m_canceled)
+         {
+-            goto exit;
+-        }
+-
+-        // Enumerate all the modules in the process and invoke the callback 
+-        // for the coreclr module if found.
+-        listHead = CreateProcessModules(m_processId, &count);
+-        if (listHead == NULL)
+-        {
+-            TRACE("CreateProcessModules failed for pid %d\n", m_processId);
+-            pe = ERROR_INVALID_PARAMETER;
+-            goto exit;
+-        }
++            // Enumerate all the modules in the process and invoke the callback 
++            // for the coreclr module if found.
++            DWORD count;
++            ProcessModules *listHead = CreateProcessModules(m_processId, &count);
++            if (listHead == NULL)
++            {
++                TRACE("CreateProcessModules failed for pid %d\n", m_processId);
++                pe = ERROR_INVALID_PARAMETER;
++                goto exit;
++            }
+ 
+-        for (ProcessModules *entry = listHead; entry != NULL; entry = entry->Next)
+-        {
+-            if (IsCoreClrModule(entry->Name))
++            for (ProcessModules *entry = listHead; entry != NULL; entry = entry->Next)
+             {
+-                PAL_CPP_TRY
+-                {
+-                    TRACE("InvokeStartupCallback executing callback %p %s\n", entry->BaseAddress, entry->Name);
+-                    m_callback(entry->Name, entry->BaseAddress, m_parameter);
+-                }
+-                PAL_CPP_CATCH_ALL
++                if (IsCoreClrModule(entry->Name))
+                 {
++                    PAL_CPP_TRY
++                    {
++                        TRACE("InvokeStartupCallback executing callback %p %s\n", entry->BaseAddress, entry->Name);
++                        m_callback(entry->Name, entry->BaseAddress, m_parameter);
++                    }
++                        PAL_CPP_CATCH_ALL
++                    {
++                    }
++                    PAL_CPP_ENDTRY
++
++                        // Currently only the first coreclr module in a process is supported
++                        break;
+                 }
+-                PAL_CPP_ENDTRY
++            }
+ 
+-                // Currently only the first coreclr module in a process is supported
+-                break;
++        exit:
++            if (listHead != NULL)
++            {
++                DestroyProcessModules(listHead);
+             }
+         }
+ 
+-    exit:
+-        // Wake up the runtime 
+-        if (sem_post(m_continueSem) != 0)
+-        {
+-            ASSERT("sem_post(continueSem) failed: errno is %d (%s)\n", errno, strerror(errno));
+-        }
+-        if (listHead != NULL)
+-        {
+-            DestroyProcessModules(listHead);
+-        }
+         return pe;
+     }
+ 
+     void StartupHelperThread()
+     {
++        char continueSemName[CLR_SEM_MAX_NAMELEN];
++        sem_t *continueSem = SEM_FAILED;
+         PAL_ERROR pe = NO_ERROR;
+ 
+-        if (IsCoreClrProcessReady())
++        sprintf_s(continueSemName,
++                  sizeof(continueSemName),
++                  RuntimeContinueSemaphoreName,
++                  HashSemaphoreName(m_processId,
++                                    m_processIdDisambiguationKey));
++
++        TRACE("StartupHelperThread continue sem '%s'\n", continueSemName);
++
++        // Does the continue semaphore exists? If it does, the runtime is ready to be debugged.
++        continueSem = sem_open(continueSemName, 0);
++        if (continueSem != SEM_FAILED)
+         {
++            TRACE("StartupHelperThread continue sem exists - invoking callback\n");
+             pe = InvokeStartupCallback();
+         }
+-        else {
+-            TRACE("sem_wait(startup)\n");
+-
++        else if (errno == ENOENT)
++        {
+             // Wait until the coreclr runtime (debuggee) starts up
+             if (sem_wait(m_startupSem) == 0)
+             {
+-                pe = InvokeStartupCallback();
++                // The continue semaphore should exists now and is needed to wake up the runtimes below
++                continueSem = sem_open(continueSemName, 0);
++                if (continueSem != SEM_FAILED) 
++                {
++                    TRACE("StartupHelperThread continue sem exists after wait - invoking callback\n");
++                    pe = InvokeStartupCallback();
++                }
++                else
++                {
++                    TRACE("sem_open(continue) failed: errno is %d (%s)\n", errno, strerror(errno));
++                    pe = GetSemError();
++                }
+             }
+-            else
++            else 
+             {
+                 TRACE("sem_wait(startup) failed: errno is %d (%s)\n", errno, strerror(errno));
+                 pe = GetSemError();
+             }
+         }
++        else
++        {
++            pe = GetSemError();
++        }
++
++        // Wake up the runtime even on error and cancelation
++        if (continueSem != SEM_FAILED)
++        {
++            if (sem_post(continueSem) != 0)
++            {
++                TRACE("sem_post(continueSem) failed: errno is %d (%s)\n", errno, strerror(errno));
++                pe = GetSemError();
++            }
++
++            sem_close(continueSem);
++        }
+ 
+         // Invoke the callback on errors
+         if (pe != NO_ERROR && !m_canceled)
+@@ -1886,19 +1845,35 @@ PALAPI
+ PAL_NotifyRuntimeStarted()
+ {
+     char startupSemName[CLR_SEM_MAX_NAMELEN];
+-    char continueSemName[CLR_SEM_MAX_NAMELEN];
+     sem_t *startupSem = SEM_FAILED;
+-    sem_t *continueSem = SEM_FAILED;
+     BOOL result = TRUE;
+ 
+     UINT64 processIdDisambiguationKey = 0;
+     GetProcessIdDisambiguationKey(gPID, &processIdDisambiguationKey);
+ 
+     sprintf_s(startupSemName, sizeof(startupSemName), RuntimeStartupSemaphoreName, HashSemaphoreName(gPID, processIdDisambiguationKey));
+-    sprintf_s(continueSemName, sizeof(continueSemName), RuntimeContinueSemaphoreName, HashSemaphoreName(gPID, processIdDisambiguationKey));
++    sprintf_s(g_continueSemName, sizeof(g_continueSemName), RuntimeOldContinueSemaphoreName, HashSemaphoreName(gPID, processIdDisambiguationKey));
+ 
+-    TRACE("PAL_NotifyRuntimeStarted opening continue '%s' startup '%s'\n", continueSemName, startupSemName);
++    TRACE("PAL_NotifyRuntimeStarted opening continue (old) '%s' startup '%s'\n", g_continueSemName, startupSemName);
+ 
++    // For backwards compatibility with RC2 (see issue #4410) first OPEN the continue semaphore with the old name "clrcoXXXX".
++    g_continueSem = sem_open(g_continueSemName, 0);
++    if (g_continueSem == SEM_FAILED)
++    {
++        // Create the new continue semaphore name "clrctXXXX"
++        sprintf_s(g_continueSemName, sizeof(g_continueSemName), RuntimeContinueSemaphoreName, HashSemaphoreName(gPID, processIdDisambiguationKey));
++
++        TRACE("PAL_NotifyRuntimeStarted creating continue '%s'\n", g_continueSemName);
++
++        // Create the continue semaphore. This tells dbgshim that coreclr is initialized and ready.
++        g_continueSem = sem_open(g_continueSemName, O_CREAT | O_EXCL, S_IRWXU, 0);
++        if (g_continueSem == SEM_FAILED)
++        {
++            ASSERT("sem_open(%s) failed: %d (%s)\n", g_continueSemName, errno, strerror(errno));
++            result = FALSE;
++            goto exit;
++        }
++    }
+ 
+     // Open the debugger startup semaphore. If it doesn't exists, then we do nothing and
+     // the function is successful.
+@@ -1909,14 +1884,6 @@ PAL_NotifyRuntimeStarted()
+         goto exit;
+     }
+ 
+-    continueSem = sem_open(continueSemName, 0);
+-    if (continueSem == SEM_FAILED)
+-    {
+-        ASSERT("sem_open(%s) failed: %d (%s)\n", continueSemName, errno, strerror(errno));
+-        result = FALSE;
+-        goto exit;
+-    }
+-
+     // Wake up the debugger waiting for startup
+     if (sem_post(startupSem) != 0)
+     {
+@@ -1926,7 +1893,7 @@ PAL_NotifyRuntimeStarted()
+     }
+ 
+     // Now wait until the debugger's runtime startup notification is finished
+-    if (sem_wait(continueSem) != 0)
++    if (sem_wait(g_continueSem) != 0)
+     {
+         ASSERT("sem_wait(continueSem) failed: errno is %d (%s)\n", errno, strerror(errno));
+         result = FALSE;
+@@ -1938,14 +1905,41 @@ exit:
+     {
+         sem_close(startupSem);
+     }
+-    if (continueSem != SEM_FAILED)
+-    {
+-        sem_close(continueSem);
+-    }
+     return result;
+ }
+ 
+ /*++
++    PAL_CleanupTargetProcess
++
++    Cleanup the target process's name continue semaphore
++    on the debugger side when the debugger detects the
++    process termination.
++
++Parameters:
++    pid - process id
++    disambiguationKey - key to make process id unique
++
++Return value:
++    None
++--*/
++VOID
++PALAPI
++PAL_CleanupTargetProcess(
++    IN int pid,
++    IN UINT64 disambiguationKey)
++{
++    char continueSemName[NAME_MAX - 4];
++
++    sprintf_s(continueSemName,
++              sizeof(continueSemName),
++              RuntimeContinueSemaphoreName,
++              pid,
++              disambiguationKey);
++
++    sem_unlink(continueSemName);
++}
++
++/*++
+  Function:
+   GetProcessIdDisambiguationKey
+ 
+@@ -2018,7 +2012,7 @@ GetProcessIdDisambiguationKey(DWORD proc
+ 
+     return TRUE;
+ 
+-#elif HAVE_PROCFS_STAT
++#elif defined(HAVE_PROCFS_CTL)
+ 
+     // Here we read /proc/<pid>/stat file to get the start time for the process.
+     // We return this value (which is expressed in jiffies since boot time).
+@@ -2072,34 +2066,12 @@ GetProcessIdDisambiguationKey(DWORD proc
+ 
+ #else
+     // If this is not OS X and we don't have /proc, we just return FALSE.
+-    WARN("GetProcessIdDisambiguationKey was called but is not implemented on this platform!");
++    WARN(!"GetProcessIdDisambiguationKey was called but is not implemented on this platform!");
+     return FALSE;
+ #endif
+ }
+ 
+ /*++
+- Function:
+-  PAL_GetTransportPipeName 
+-
+-  Builds the transport pipe names from the process id.
+---*/
+-void 
+-PALAPI
+-PAL_GetTransportPipeName(char *name, DWORD id, const char *suffix)
+-{
+-    UINT64 disambiguationKey = 0;
+-    BOOL ret = GetProcessIdDisambiguationKey(id, &disambiguationKey);
+-
+-    // If GetProcessIdDisambiguationKey failed for some reason, it should set the value 
+-    // to 0. We expect that anyone else making the pipe name will also fail and thus will
+-    // also try to use 0 as the value.
+-    _ASSERTE(ret == TRUE || disambiguationKey == 0);
+-
+-    int chars = _snprintf(name, MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH, PipeNameFormat, id, disambiguationKey, suffix);
+-    _ASSERTE(chars > 0 && chars < MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH);
+-}
+-
+-/*++
+ Function:
+   GetProcessTimes
+ 
+@@ -2726,9 +2698,8 @@ CreateProcessModules(
+ 
+     free(line); // We didn't allocate line, but as per contract of getline we should free it
+     pclose(vmmapFile);
+-exit:
+ 
+-#elif HAVE_PROCFS_MAPS 
++#elif defined(HAVE_PROCFS_CTL)
+ 
+     // Here we read /proc/<pid>/maps file in order to parse it and figure out what it says 
+     // about a library we are looking for. This file looks something like this:
+@@ -2807,11 +2778,10 @@ exit:
+ 
+     free(line); // We didn't allocate line, but as per contract of getline we should free it
+     fclose(mapsFile);
+-exit:
+-
+ #else
+     _ASSERTE(!"Not implemented on this platform");
+ #endif
++exit:
+     return listHead;
+ }
+ 
+@@ -2855,6 +2825,14 @@ void PROCNotifyProcessShutdown()
+     {
+         callback();
+     }
++
++    // Cleanup the name continue semaphore on exit and abormal terminatation
++    sem_t *continueSem = InterlockedExchangePointer(&g_continueSem, SEM_FAILED);
++    if (continueSem != SEM_FAILED)
++    {
++        sem_close(continueSem);
++        sem_unlink(g_continueSemName);
++    }
+ }
+ 
+ /*++



Home | Main Index | Thread Index | Old Index