Merge pull request #5444 from hifi/fix-tds-inputoutput
authorEgor Bogatov <egorbo@gmail.com>
Fri, 1 Sep 2017 08:41:49 +0000 (11:41 +0300)
committerGitHub <noreply@github.com>
Fri, 1 Sep 2017 08:41:49 +0000 (11:41 +0300)
[System] Fix TDS 7.0 prepared InputOutput parameter info

85 files changed:
Makefile.am
configure.ac
external/api-snapshot
external/cecil
external/linker
external/nunit-lite
man/mono.1
mcs/build/tests.make
mcs/class/Mono.Debugger.Soft/Test/dtest-excfilter.il
mcs/class/Mono.Debugger.Soft/Test/dtest.cs
mcs/class/Mono.Security/Mono.Security.Interface/MonoTlsProvider.cs
mcs/class/Mono.Security/Mono.Security.Interface/MonoTlsSettings.cs
mcs/class/PEAPI/Metadata.cs
mcs/class/System.Net.Http/System.Net.Http_test.dll.sources
mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs
mcs/class/System.Runtime.Remoting/System.Runtime.Remoting_test.dll.sources
mcs/class/System.Runtime.Remoting/Test/ActivationTests.cs
mcs/class/System.Runtime.Remoting/Test/GenericTest.cs
mcs/class/System.Runtime.Remoting/Test/HttpBugTests.cs
mcs/class/System.Runtime.Remoting/Test/RemotingServicesTest.cs
mcs/class/System.Runtime.Remoting/Test/System.Runtime.Remoting.Channels.Tcp/TcpChannelTest.cs
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Activation/WebScriptServiceHostFactoryTest.cs
mcs/class/System.ServiceModel/System.ServiceModel.PeerResolvers/CustomPeerResolverService.cs
mcs/class/System.ServiceModel/Test/FeatureBased/TestFixtureBase.cs
mcs/class/System.ServiceModel/Test/System.ServiceModel.PeerResolvers/CustomPeerResolverServiceTest.cs
mcs/class/System/Mono.AppleTls/AppleTlsContext.cs
mcs/class/System/Mono.AppleTls/AppleTlsProvider.cs
mcs/class/System/Mono.Btls/MonoBtlsContext.cs
mcs/class/System/Mono.Btls/MonoBtlsProvider.cs
mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs
mcs/class/System/Mono.Net.Security/LegacyTlsProvider.cs
mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs
mcs/class/System/Mono.Net.Security/MobileTlsContext.cs
mcs/class/System/Mono.Net.Security/MonoTlsProviderFactory.cs
mcs/class/System/System-bare-net_4_x.csproj
mcs/class/System/System-net_4_x.csproj
mcs/class/System/System-secxml-net_4_x.csproj
mcs/class/System/System.Net.Sockets/Socket.cs
mcs/class/System/Test/System.Net.Sockets/SocketTest.cs
mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs
mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs
mcs/class/System/Test/System.Net/HttpListenerPrefixCollectionTest.cs
mcs/class/corlib/Test/System.Runtime.Remoting/RemotingServicesTest.cs [deleted file]
mcs/class/corlib/testing_aot_full_corlib_test.dll.exclude.sources
mcs/class/test-helpers/NetworkHelpers.cs
mcs/ilasm/Driver.cs
mcs/ilasm/codegen/CodeGen.cs
mcs/ilasm/codegen/TypeDef.cs
mcs/ilasm/ilasm.csproj
mcs/ilasm/parser/ILParser.jay
mcs/ilasm/scanner/ILTables.cs
mcs/tools/mkbundle/mkbundle.cs
mcs/tools/nunit-lite/NUnitLite/nunitlite.dll.sources
mono/eglib/gfile-unix.c
mono/eglib/gstr.c
mono/metadata/boehm-gc.c
mono/metadata/cominterop.c
mono/metadata/cominterop.h
mono/metadata/icall-def.h
mono/metadata/marshal.c
mono/metadata/sgen-mono.c
mono/metadata/w32file-unix.c
mono/metadata/w32socket-internals.h
mono/metadata/w32socket.c
mono/metadata/w32socket.h
mono/mini/cpu-amd64.md
mono/mini/debugger-agent.c
mono/mini/llvm-jit.cpp
mono/mini/mini-amd64.c
mono/mini/mini-amd64.h
mono/mini/mini-llvm-cpp.cpp
mono/mini/mini-llvm-cpp.h
mono/mini/mini-llvm.c
mono/mini/mini-runtime.c
mono/mini/mini-trampolines.c
mono/mini/tramp-amd64.c
mono/profiler/log-args.c
mono/sgen/sgen-gc.c
mono/sgen/sgen-gc.h
mono/sgen/sgen-gchandles.c
mono/utils/mono-threads-state-machine.c
mono/utils/mono-threads.h
mono/utils/strenc.c
scripts/ci/clang-thread-sanitizer-blacklist
support/supportw.c

index 8cb099618a19551ee5e4f95c45d0f55e43db84ff..c322d249127837da530f6c936ee1f98df0ed6540 100644 (file)
@@ -109,23 +109,6 @@ monotouch-do-clean:
 
 endif
 
-win32getdeps:
-       wget http://www.go-mono.com/archive/pkgconfig-0.11-20020310.zip
-       wget http://www.go-mono.com/archive/glib-2.0.4-20020703.zip 
-       wget http://www.go-mono.com/archive/glib-dev-2.0.4-20020703.zip 
-       wget http://www.go-mono.com/archive/libiconv-1.7.zip 
-       wget http://www.go-mono.com/archive/libiconv-dev-1.7.zip 
-       wget http://www.go-mono.com/archive/libintl-0.10.40-20020101.zip
-       unzip -n -d / pkgconfig-0.11-20020310.zip
-       unzip -n -d / glib-2.0.4-20020703.zip
-       unzip -n -d / glib-dev-2.0.4-20020703.zip
-       unzip -n -d / libiconv-1.7.zip
-       unzip -n -d / libiconv-dev-1.7.zip
-       unzip -n -d / libintl-0.10.40-20020101.zip
-
-win32setup:
-       makensis /DMILESTONE=$(VERSION) /DSOURCE_INSTALL_DIR=$(SOURCE_INSTALL_DIR) /DBUILDNUM=$(BUILDNUM) monowiz.win32.nsi
-
 update-csproj:
        -rm msvc/scripts/order 
        -rm msvc/scripts/order.xml
index c3000129cfc00d37b5a7afe38fc1f658d2d3e734..2c5e83eb768c35d4926a5bd84e6461187b1dee40 100644 (file)
@@ -40,8 +40,8 @@ MONO_VERSION_BUILD=`echo $VERSION | cut -d . -f 3`
 # This can be reset to 0 when Mono's version number is bumped
 # since it's part of the corlib version (the prefix '1' in the full
 # version number is to ensure the number isn't treated as octal in C)
-MONO_CORLIB_COUNTER=0
-MONO_CORLIB_VERSION=`printf "1%02d%02d%02d%03d" $MONO_VERSION_MAJOR $MONO_VERSION_MINOR $MONO_VERSION_BUILD $MONO_CORLIB_COUNTER`
+MONO_CORLIB_COUNTER=1
+MONO_CORLIB_VERSION=`printf "1%02d%02d%02d%03d" $MONO_VERSION_MAJOR $MONO_VERSION_MINOR 0 $MONO_CORLIB_COUNTER`
 
 AC_DEFINE_UNQUOTED(MONO_CORLIB_VERSION,$MONO_CORLIB_VERSION,[Version of the corlib-runtime interface])
 AC_SUBST(MONO_CORLIB_VERSION)
@@ -1502,6 +1502,8 @@ if test x$host_win32 = xno; then
                AC_CHECK_FUNCS(getpwuid_r)
        fi
 
+       AC_FUNC_STRERROR_R()
+
        dnl ****************************************************************
        dnl *** Check for sched_setaffinity from glibc versions before   ***
        dnl *** 2.3.4. The older versions of the function only take 2    ***
index bf03a7c5cf6b692fa662f1568ad66de35166b8ea..4dfe97ec246b7ebd2f7b4af378817abf436cf102 160000 (submodule)
@@ -1 +1 @@
-Subproject commit bf03a7c5cf6b692fa662f1568ad66de35166b8ea
+Subproject commit 4dfe97ec246b7ebd2f7b4af378817abf436cf102
index 14e17dfbebf5651b5ce70c7fb317e388f8a3a271..bc11f472954694ebd92ae4956f110c1036a7c2e0 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 14e17dfbebf5651b5ce70c7fb317e388f8a3a271
+Subproject commit bc11f472954694ebd92ae4956f110c1036a7c2e0
index 305e0f60533d164676099c918fa4dd09c718017b..99354bf5c13b8055209cb082cddc50c8047ab088 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 305e0f60533d164676099c918fa4dd09c718017b
+Subproject commit 99354bf5c13b8055209cb082cddc50c8047ab088
index 690603bea98aae69fca9a65130d88591bc6cabee..5b29e610f4ac95afcb8108fdd6d0bb1936f6cc83 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 690603bea98aae69fca9a65130d88591bc6cabee
+Subproject commit 5b29e610f4ac95afcb8108fdd6d0bb1936f6cc83
index 7bacf5bcb0d41a5a6703097885a3dc06542d5c84..7d2f14c151e5a42709de29d68df5022822d01667 100644 (file)
@@ -908,52 +908,8 @@ your profiler.
 For a sample of how to write your own custom profiler look in the
 Mono source tree for in the samples/profiler.c.
 .SH CODE COVERAGE
-Mono ships with a code coverage module.  This module is activated by
-using the Mono --profile=cov option.  The format is:
-\fB--profile=cov[:assembly-name[/namespace]] test-suite.exe\fR
-.PP
-By default code coverage will default to all the assemblies loaded,
-you can limit this by specifying the assembly name, for example to
-perform code coverage in the routines of your program use, for example
-the following command line limits the code coverage to routines in the
-"demo" assembly:
-.nf
-
-       mono --profile=cov:demo demo.exe
-
-.fi
-.PP
-Notice that the 
-.I assembly-name
-does not include the extension.
-.PP
-You can further restrict the code coverage output by specifying a
-namespace:
-.nf
-
-       mono --profile=cov:demo/My.Utilities demo.exe
-
-.fi
-.PP
-Which will only perform code coverage in the given assembly and
-namespace.  
-.PP
-Typical output looks like this:
-.nf
-
-       Not covered: Class:.ctor ()
-       Not covered: Class:A ()
-       Not covered: Driver:.ctor ()
-       Not covered: Driver:method ()
-       Partial coverage: Driver:Main ()
-               offset 0x000a
-
-.fi
-.PP
-The offsets displayed are IL offsets.
-.PP
-A more powerful coverage tool is available in the module `monocov'.
-See the monocov(1) man page for details.
+Mono ships with a code coverage module in the \f[I]log\f[] profiler.
+Check the `coverage' option on the mprof-report(1) page for more details.
 .SH AOT PROFILING
 You can improve startup performance by using the AOT profiler.
 .PP
@@ -2049,7 +2005,7 @@ http://www.mono-project.com/community/help/mailing-lists/
 http://www.mono-project.com
 .SH SEE ALSO
 .PP
-certmgr(1), cert-sync(1), csharp(1), gacutil(1), mcs(1), mdb(1), monocov(1), monodis(1),
+certmgr(1), cert-sync(1), csharp(1), gacutil(1), mcs(1), mdb(1), monodis(1),
 mono-config(5), mprof-report(1), pdb2mdb(1), xsp(1), mod_mono(8).
 .PP
 For more information on AOT:
index 8ffa784a23aeff1661c912461451be8e75a5445e..5a8bc7d0e481fc39c498d5a72fd1e9748f5897fa 100644 (file)
@@ -212,9 +212,9 @@ run-xunit-test: run-xunit-test-local
 xunit-test-local: $(xunit_test_lib)
 run-xunit-test-local: run-xunit-test-lib
 
-# ln -s is a HACK for xunit runner to require xunit.execution.desktop.dll file in local folder on .net only
+# cp -rf is a HACK for xunit runner to require xunit.execution.desktop.dll file in local folder on .net only
 run-xunit-test-lib: xunit-test-local
-       @ln -fs $(XTEST_HARNESS_PATH)/xunit.execution.desktop.dll xunit.execution.desktop.dll
+       @cp -rf $(XTEST_HARNESS_PATH)/xunit.execution.desktop.dll xunit.execution.desktop.dll
        ok=:; \
        PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(AOT_RUN_FLAGS) $(XTEST_HARNESS) $(xunit_test_lib) $(XTEST_HARNESS_FLAGS) $(XTEST_TRAIT) || ok=false; \
        $$ok
index 3d435fda1e11aa741a7c93873e2c592c15a3f644..43f15d0023539197ffb364ac4072e52a7b0d7b32 100644 (file)
 
                        leave end
                } filter {
+                   castclass [mscorlib]System.Exception
                        call int32 class ExceptionFilterTest::Filter([mscorlib]System.Exception)
                        endfilter
                } {
+                   castclass [mscorlib]System.Exception
                        call void class ExceptionFilterTest::Handler([mscorlib]System.Exception)
                        leave end
                }
index 671293df18574599f9d98298adaabbb04fed78b2..94316e7e9644e47a94a5d9b28932a0377d822191 100644 (file)
@@ -3385,8 +3385,8 @@ public class DebuggerTests
                Assert.AreEqual (0, frames [0].Location.ILOffset);
 
                Assert.AreEqual (test_method.Name, frames [1].Location.Method.Name);
-               Assert.AreEqual (37, frames [1].Location.LineNumber);
-               Assert.AreEqual (0x0b, frames [1].Location.ILOffset);
+               Assert.AreEqual (38, frames [1].Location.LineNumber);
+               Assert.AreEqual (0x10, frames [1].Location.ILOffset);
 
                Assert.AreEqual (test_method.Name, frames [2].Location.Method.Name);
                Assert.AreEqual (33, frames [2].Location.LineNumber);
index 05f507a852eb93b0436aec44faf77e6ce190d270..5a03262e229f281a0ce751f4a28c6ed160902969 100644 (file)
@@ -163,5 +163,14 @@ namespace Mono.Security.Interface
                        X509CertificateCollection certificates, bool wantsChain, ref X509Chain chain,
                        ref MonoSslPolicyErrors errors, ref int status11);
 #endregion
+
+#region Misc
+
+               internal abstract bool SupportsCleanShutdown {
+                       get;
+               }
+
+#endregion
+
        }
 }
index 6a1bf86ed1fae893c05082843b554ae1db4fae7b..ee7e216cc2103ee31a529f16105bfeb6f7ab09c9 100644 (file)
@@ -86,6 +86,13 @@ namespace Mono.Security.Interface
                        get; set;
                }
 
+               /*
+                * This is only supported if MonoTlsProvider.SupportsCleanShutdown is true.
+                */
+               internal bool SendCloseNotify {
+                       get; set;
+               }
+
                /*
                 * If you set this here, then it will override 'ServicePointManager.SecurityProtocol'.
                 */
@@ -173,6 +180,7 @@ namespace Mono.Security.Interface
                        EnabledProtocols = other.EnabledProtocols;
                        EnabledCiphers = other.EnabledCiphers;
                        CertificateValidationTime = other.CertificateValidationTime;
+                       SendCloseNotify = other.SendCloseNotify;
                        if (other.TrustAnchors != null)
                                TrustAnchors = new X509CertificateCollection (other.TrustAnchors);
                        if (other.CertificateSearchPaths != null) {
index 35693efd7fcb650878edbc15e1b15dec0ebed94b..eca297380bcdc92386e6067a43e5b686447f67dd 100644 (file)
@@ -92,7 +92,9 @@ namespace PEAPI {
        /// </summary>
        public enum ImplAttr { IL, Native, Runtime = 0x03, Unmanaged = 0x04,
                ForwardRef = 0x10, PreserveSig = 0x0080, InternalCall = 0x1000, 
-               Synchronised = 0x0020, Synchronized = 0x0020, NoInLining = 0x0008, NoOptimization = 0x0040, Optil = 0x0002}
+               Synchronised = 0x0020, Synchronized = 0x0020, NoInLining = 0x0008, NoOptimization = 0x0040, Optil = 0x0002,
+               AggressiveInlining = 0x0100
+       }
 
        /// <summary>
        /// Storage location for initial field data
@@ -1639,6 +1641,7 @@ namespace PEAPI {
        public class ClassDef : Class {
 
                Class superType;
+               bool setSuperType;
                ArrayList fields = new ArrayList();
                ArrayList methods = new ArrayList();
                ArrayList events;
@@ -1654,9 +1657,6 @@ namespace PEAPI {
                                MetaData md) : base(nsName, name, md) 
                {
                        metaData = md;
-                       if (! ((nsName == "" && name == "<Module>") || (nsName == "System" && name == "Object")) ) {
-                               superType = metaData.mscorlib.GetSpecialSystemClass(PrimitiveType.Object);
-                       }
                        flags = (uint)attrSet;
                        tabIx = MDTable.TypeDef;
                }
@@ -1664,6 +1664,7 @@ namespace PEAPI {
                internal void SetSuper(Class sClass) 
                {
                        superType = sClass;
+                       setSuperType = true;
                        if (! (sClass is GenericTypeInst))
                                typeIndexChecked = false;
                }
@@ -1675,12 +1676,13 @@ namespace PEAPI {
                        else  
                                superType = metaData.mscorlib.ValueType();
 
+                       setSuperType = true;
                        typeIndex = PrimitiveType.ValueType.GetTypeIndex ();
                }
 
                public void SpecialNoSuper() 
                {
-                       superType = null;
+                       setSuperType = true;
                }
 
                /// <summary>
@@ -1922,8 +1924,13 @@ namespace PEAPI {
 
                internal sealed override void BuildTables(MetaData md) 
                {
-                       if (done) return;
-                       if ((flags & (uint)TypeAttr.Interface) != 0) { superType = null; }
+                       if (done) 
+                               return;
+                       
+                       if ((flags & (uint)TypeAttr.Interface) != 0) {
+                               superType = null;
+                               setSuperType = true;
+                       }
                        // Console.WriteLine("Building tables for " + name);
                        if (layout != null) md.AddToTable(MDTable.ClassLayout,layout);
                        // Console.WriteLine("adding methods " + methods.Count);
@@ -1956,6 +1963,10 @@ namespace PEAPI {
                                                        ((Property)properties[0]).Row,MDTable.Property));
                        }
                        // Console.WriteLine("End of building tables");
+
+                       if (!setSuperType)
+                               superType = metaData.mscorlib.GetSpecialSystemClass(PrimitiveType.Object);
+
                        done = true;
                }
 
@@ -5050,7 +5061,7 @@ namespace PEAPI {
                private byte heapSizes = 0;
                MetaDataElement entryPoint;
                BinaryWriter output;
-               public MSCorLib mscorlib;
+               MSCorLib _mscorlib;
                private TypeSpec[] systemTypeSpecs = new TypeSpec[PrimitiveType.NumSystemTypes];
                long mdStart;
                private ArrayList cattr_list;
@@ -5075,9 +5086,15 @@ namespace PEAPI {
                        for (int i=0; i < lgeCIx.Length; i++) {
                                lgeCIx[i] = false;
                        }
-                       mscorlib = new MSCorLib(this);
                }
 
+               public MSCorLib mscorlib {
+                       get {
+                               return _mscorlib ?? (_mscorlib = new MSCorLib (this));
+                       }
+               }
+
+
                internal TypeSpec GetPrimitiveTypeSpec(int ix) 
                {
                        return systemTypeSpecs[ix];
index 9aa6dcb02e43db6d6ae467e091f454c8f6021df9..a623a96cef487e799d3c2721cbedae73a58ad5ab 100644 (file)
@@ -1,3 +1,4 @@
+../../test-helpers/NetworkHelpers.cs
 System.Net.Http/DelegatingHandlerTest.cs
 System.Net.Http/ByteArrayContentTest.cs
 System.Net.Http/FormUrlEncodedContentTest.cs
index 72508c4883349ae19ada77271c939bfe18c04264..8344c26cc68687b585f7be3a8ef3dd08c2f36328 100644 (file)
@@ -38,6 +38,8 @@ using System.Net;
 using System.Linq;
 using System.IO;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.System.Net.Http
 {
        [TestFixture]
@@ -175,22 +177,6 @@ namespace MonoTests.System.Net.Http
 
                const int WaitTimeout = 5000;
 
-               string TestHost, LocalServer;
-               int port;
-
-               [SetUp]
-               public void SetupFixture ()
-               {
-                       if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
-                               port = 810;
-                       } else {
-                               port = 8810;
-                       }
-
-                       TestHost = "localhost:" + port;
-                       LocalServer = string.Format ("http://{0}/", TestHost);
-               }
-
                [Test]
                public void Ctor_Default ()
                {
@@ -410,6 +396,7 @@ namespace MonoTests.System.Net.Http
                public void Send_Complete_Default ()
                {
                        bool? failed = null;
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                try {
                                        var request = l.Request;
@@ -419,7 +406,7 @@ namespace MonoTests.System.Net.Http
                                        Assert.IsNull (request.ContentType, "#3");
                                        Assert.AreEqual (0, request.Cookies.Count, "#4");
                                        Assert.IsFalse (request.HasEntityBody, "#5");
-                                       Assert.AreEqual (TestHost, request.Headers["Host"], "#6b");
+                                       Assert.AreEqual ($"localhost:{port}", request.Headers["Host"], "#6b");
                                        Assert.AreEqual ("GET", request.HttpMethod, "#7");
                                        Assert.IsFalse (request.IsAuthenticated, "#8");
                                        Assert.IsTrue (request.IsLocal, "#9");
@@ -435,11 +422,11 @@ namespace MonoTests.System.Net.Http
                                } catch {
                                        failed = true;
                                }
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
 
                                Assert.AreEqual ("", response.Content.ReadAsStringAsync ().Result, "#100");
@@ -458,6 +445,7 @@ namespace MonoTests.System.Net.Http
                {
                        bool? failed = null;
                        
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                try {
                                        var request = l.Request;
@@ -468,7 +456,7 @@ namespace MonoTests.System.Net.Http
                                        Assert.AreEqual (0, request.Cookies.Count, "#4");
                                        Assert.IsFalse (request.HasEntityBody, "#5");
                                        Assert.AreEqual (1, request.Headers.Count, "#6");
-                                       Assert.AreEqual (TestHost, request.Headers["Host"], "#6a");
+                                       Assert.AreEqual ($"localhost:{port}", request.Headers["Host"], "#6a");
                                        Assert.AreEqual ("GET", request.HttpMethod, "#7");
                                        Assert.IsFalse (request.IsAuthenticated, "#8");
                                        Assert.IsTrue (request.IsLocal, "#9");
@@ -484,11 +472,11 @@ namespace MonoTests.System.Net.Http
                                } catch {
                                        failed = true;
                                }
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                request.Version = HttpVersion.Version10;
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
 
@@ -508,6 +496,7 @@ namespace MonoTests.System.Net.Http
                {
                        bool? failed = null;
                        
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                
@@ -519,7 +508,7 @@ namespace MonoTests.System.Net.Http
                                        Assert.AreEqual (new Cookie ("mycookie", "vv"), request.Cookies[0], "#4a");
                                        Assert.IsFalse (request.HasEntityBody, "#5");
                                        Assert.AreEqual (4, request.Headers.Count, "#6");
-                                       Assert.AreEqual (TestHost, request.Headers["Host"], "#6a");
+                                       Assert.AreEqual ($"localhost:{port}", request.Headers["Host"], "#6a");
                                        Assert.AreEqual ("gzip", request.Headers["Accept-Encoding"], "#6b");
                                        Assert.AreEqual ("mycookie=vv", request.Headers["Cookie"], "#6c");
                                        Assert.AreEqual ("GET", request.HttpMethod, "#7");
@@ -537,7 +526,7 @@ namespace MonoTests.System.Net.Http
                                } catch {
                                        failed = true;
                                }
-                       });
+                       }, port);
 
                        try {
                                var chandler = new HttpClientHandler ();
@@ -546,14 +535,14 @@ namespace MonoTests.System.Net.Http
                                chandler.MaxAutomaticRedirections = 33;
                                chandler.MaxRequestContentBufferSize = 5555;
                                chandler.PreAuthenticate = true;
-                               chandler.CookieContainer.Add (new Uri (LocalServer), new Cookie ( "mycookie", "vv"));
+                               chandler.CookieContainer.Add (new Uri ($"http://localhost:{port}/"), new Cookie ( "mycookie", "vv"));
                                chandler.UseCookies = true;
                                chandler.UseDefaultCredentials = true;
                                chandler.Proxy = new WebProxy ("ee");
                                chandler.UseProxy = true;
 
                                var client = new HttpClient (chandler);
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                request.Version = HttpVersion.Version10;
                                request.Headers.Add ("Keep-Alive", "false");
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
@@ -575,6 +564,7 @@ namespace MonoTests.System.Net.Http
                {
                        bool? failed = null;
                        
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                try {
@@ -595,11 +585,11 @@ namespace MonoTests.System.Net.Http
                                } catch {
                                        failed = true;
                                }
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                Assert.IsTrue (request.Headers.TryAddWithoutValidation ("aa", "vv"), "#0");
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
 
@@ -642,6 +632,7 @@ namespace MonoTests.System.Net.Http
                {
                        bool? failed = null;
 
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
 
@@ -651,14 +642,14 @@ namespace MonoTests.System.Net.Http
                                } catch {
                                        failed = true;
                                }
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
 
                                client.DefaultRequestHeaders.Add("User-Agent", "MLK Android Phone 1.1.9");
 
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
 
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
 
@@ -678,6 +669,7 @@ namespace MonoTests.System.Net.Http
                public void Send_Complete_CustomHeaders_Host ()
                {
                        bool? failed = null;
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
 
@@ -687,14 +679,14 @@ namespace MonoTests.System.Net.Http
                                } catch {
                                        failed = true;
                                }
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
 
                                client.DefaultRequestHeaders.Add("Host", "customhost");
 
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
 
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
 
@@ -715,22 +707,26 @@ namespace MonoTests.System.Net.Http
                {
                        bool? failed = null;
 
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
 
                                try {
-                                       Assert.AreEqual (1, request.Headers.Count, "#1");
+                                       Assert.AreEqual (2, request.Headers.Count, "#1");
+                                       Assert.AreEqual ("keep-alive", request.Headers ["Connection"], "#2");
                                        failed = false;
-                               } catch {
+                               } catch (Exception ex){
+                                       Console.WriteLine (ex);
+                                       Console.WriteLine (String.Join ("#", l.Request.Headers.AllKeys));
                                        failed = true;
                                }
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
                                client.DefaultRequestHeaders.TransferEncodingChunked = true;
 
-                               client.GetAsync (LocalServer).Wait ();
+                               client.GetAsync ($"http://localhost:{port}/").Wait ();
 
                                Assert.AreEqual (false, failed, "#102");
                        } finally {
@@ -747,15 +743,16 @@ namespace MonoTests.System.Net.Http
                {
                        bool? failed = null;
 
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                failed = true;
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
                                client.DefaultRequestHeaders.TransferEncoding.Add (new TransferCodingHeaderValue ("chunked2"));
 
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
 
                                try {
                                        client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Wait ();
@@ -776,15 +773,16 @@ namespace MonoTests.System.Net.Http
 #endif
                public void Send_Complete_Content ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                l.Response.OutputStream.WriteByte (55);
                                l.Response.OutputStream.WriteByte (75);
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                Assert.IsTrue (request.Headers.TryAddWithoutValidation ("aa", "vv"), "#0");
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
 
@@ -806,16 +804,17 @@ namespace MonoTests.System.Net.Http
 #endif
                public void Send_Complete_Content_MaxResponseContentBufferSize ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                var b = new byte[4000];
                                l.Response.OutputStream.Write (b, 0, b.Length);
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
                                client.MaxResponseContentBufferSize = 1000;
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
 
                                Assert.AreEqual (4000, response.Content.ReadAsStringAsync ().Result.Length, "#100");
@@ -831,16 +830,17 @@ namespace MonoTests.System.Net.Http
 #endif
                public void Send_Complete_Content_MaxResponseContentBufferSize_Error ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                var b = new byte[4000];
                                l.Response.OutputStream.Write (b, 0, b.Length);
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
                                client.MaxResponseContentBufferSize = 1000;
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
 
                                try {
                                        client.SendAsync (request, HttpCompletionOption.ResponseContentRead).Wait (WaitTimeout);
@@ -858,34 +858,60 @@ namespace MonoTests.System.Net.Http
 #if FEATURE_NO_BSD_SOCKETS
                [ExpectedException (typeof (PlatformNotSupportedException))]
 #endif
-               public void Send_Complete_NoContent ()
+               public void Send_Complete_NoContent_Post ()
+               {
+                       Send_Complete_NoContent (HttpMethod.Post);
+               }
+
+               [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+               public void Send_Complete_NoContent_Put ()
                {
-                       foreach (var method in new HttpMethod[] { HttpMethod.Post, HttpMethod.Put, HttpMethod.Delete }) {
-                               bool? failed = null;
-                               var listener = CreateListener (l => {
-                                       try {
-                                               var request = l.Request;
-
-                                               Assert.AreEqual (2, request.Headers.Count, "#1");
-                                               Assert.AreEqual ("0", request.Headers ["Content-Length"], "#1b");
-                                               Assert.AreEqual (method.Method, request.HttpMethod, "#2");
-                                               failed = false;
-                                       } catch {
-                                               failed = true;
-                                       }
-                               });
+                       Send_Complete_NoContent (HttpMethod.Put);
+               }
+
+               [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+               public void Send_Complete_NoContent_Delete ()
+               {
+                       Send_Complete_NoContent (HttpMethod.Delete);
+               }
 
+               void Send_Complete_NoContent (HttpMethod method)
+               {
+                       bool? failed = null;
+                       var port = NetworkHelpers.FindFreePort ();
+                       var listener = CreateListener (l => {
                                try {
-                                       var client = new HttpClient ();
-                                       var request = new HttpRequestMessage (method, LocalServer);
-                                       var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
+                                       var request = l.Request;
 
-                                       Assert.AreEqual ("", response.Content.ReadAsStringAsync ().Result, "#100");
-                                       Assert.AreEqual (HttpStatusCode.OK, response.StatusCode, "#101");
-                                       Assert.AreEqual (false, failed, "#102");
-                               } finally {
-                                       listener.Close ();
+                                       Assert.AreEqual (3, request.Headers.Count, "#1");
+                                       Assert.AreEqual ("0", request.Headers ["Content-Length"], "#1b");
+                                       Assert.AreEqual ("keep-alive", request.Headers ["Connection"], "#1c");
+                                       Assert.AreEqual (method.Method, request.HttpMethod, "#2");
+                                       failed = false;
+                               } catch (Exception ex){
+                                       Console.WriteLine (ex);
+                                       Console.WriteLine (String.Join ("#", l.Request.Headers.AllKeys));
+                                       
+                                       failed = true;
                                }
+                       }, port);
+
+                       try {
+                               var client = new HttpClient ();
+                               var request = new HttpRequestMessage (method, $"http://localhost:{port}/");
+                               var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
+
+                               Assert.AreEqual ("", response.Content.ReadAsStringAsync ().Result, "#100");
+                               Assert.AreEqual (HttpStatusCode.OK, response.StatusCode, "#101");
+                               Assert.AreEqual (false, failed, "#102");
+                       } finally {
+                               listener.Close ();
                        }
                }
 
@@ -895,14 +921,15 @@ namespace MonoTests.System.Net.Http
 #endif
                public void Send_Complete_Error ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var response = l.Response;
                                response.StatusCode = 500;
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var request = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result;
 
                                Assert.AreEqual ("", response.Content.ReadAsStringAsync ().Result, "#100");
@@ -918,14 +945,15 @@ namespace MonoTests.System.Net.Http
 #endif
                public void Send_Content_Get ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                l.Response.OutputStream.WriteByte (72);
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var r = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var r = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                var response = client.SendAsync (r).Result;
 
                                Assert.AreEqual ("H", response.Content.ReadAsStringAsync ().Result);
@@ -940,6 +968,7 @@ namespace MonoTests.System.Net.Http
 #endif
                public void Send_Content_BomEncoding ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
 
@@ -948,11 +977,11 @@ namespace MonoTests.System.Net.Http
                                str.WriteByte (0xBB);
                                str.WriteByte (0xBF);
                                str.WriteByte (71);
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var r = new HttpRequestMessage (HttpMethod.Get, LocalServer);
+                               var r = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/");
                                var response = client.SendAsync (r).Result;
 
                                Assert.AreEqual ("G", response.Content.ReadAsStringAsync ().Result);
@@ -968,16 +997,17 @@ namespace MonoTests.System.Net.Http
                public void Send_Content_Put ()
                {
                        bool passed = false;
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                passed = 7 == request.ContentLength64;
                                passed &= request.ContentType == "text/plain; charset=utf-8";
                                passed &= request.InputStream.ReadByte () == 'm';
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var r = new HttpRequestMessage (HttpMethod.Put, LocalServer);
+                               var r = new HttpRequestMessage (HttpMethod.Put, $"http://localhost:{port}/");
                                r.Content = new StringContent ("my text");
                                var response = client.SendAsync (r).Result;
 
@@ -996,15 +1026,16 @@ namespace MonoTests.System.Net.Http
                public void Send_Content_Put_CustomStream ()
                {
                        bool passed = false;
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                passed = 44 == request.ContentLength64;
                                passed &= request.ContentType == null;
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
-                               var r = new HttpRequestMessage (HttpMethod.Put, LocalServer);
+                               var r = new HttpRequestMessage (HttpMethod.Put, $"http://localhost:{port}/");
                                r.Content = new StreamContent (new CustomStream ());
                                var response = client.SendAsync (r).Result;
 
@@ -1100,6 +1131,7 @@ namespace MonoTests.System.Net.Http
                public void Post_TransferEncodingChunked ()
                {
                        bool? failed = null;
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                try {
                                        var request = l.Request;
@@ -1109,7 +1141,7 @@ namespace MonoTests.System.Net.Http
                                        Assert.IsNull (request.ContentType, "#3");
                                        Assert.AreEqual (0, request.Cookies.Count, "#4");
                                        Assert.IsTrue (request.HasEntityBody, "#5");
-                                       Assert.AreEqual (TestHost, request.Headers ["Host"], "#6b");
+                                       Assert.AreEqual ($"localhost:{port}", request.Headers ["Host"], "#6b");
                                        Assert.AreEqual ("POST", request.HttpMethod, "#7");
                                        Assert.IsFalse (request.IsAuthenticated, "#8");
                                        Assert.IsTrue (request.IsLocal, "#9");
@@ -1128,7 +1160,7 @@ namespace MonoTests.System.Net.Http
                                        failed = true;
                                        Console.WriteLine (e);
                                }
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
@@ -1137,7 +1169,7 @@ namespace MonoTests.System.Net.Http
 
                                var imageContent = new StreamContent (new MemoryStream ());
 
-                               var response = client.PostAsync (LocalServer, imageContent).Result;
+                               var response = client.PostAsync ($"http://localhost:{port}/", imageContent).Result;
 
                                Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "#101");
                                Assert.AreEqual(false, failed, "#102");
@@ -1153,6 +1185,7 @@ namespace MonoTests.System.Net.Http
                public void Post_StreamCaching ()
                {
                        bool? failed = null;
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                try {
                                        var request = l.Request;
@@ -1162,7 +1195,7 @@ namespace MonoTests.System.Net.Http
                                        Assert.IsNull (request.ContentType, "#3");
                                        Assert.AreEqual (0, request.Cookies.Count, "#4");
                                        Assert.IsFalse (request.HasEntityBody, "#5");
-                                       Assert.AreEqual (TestHost, request.Headers ["Host"], "#6b");
+                                       Assert.AreEqual ($"localhost:{port}", request.Headers ["Host"], "#6b");
                                        Assert.AreEqual ("POST", request.HttpMethod, "#7");
                                        Assert.IsFalse (request.IsAuthenticated, "#8");
                                        Assert.IsTrue (request.IsLocal, "#9");
@@ -1181,14 +1214,14 @@ namespace MonoTests.System.Net.Http
                                        failed = true;
                                        Console.WriteLine (e);
                                }
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
 
                                var imageContent = new StreamContent (new MemoryStream ());
 
-                               var response = client.PostAsync (LocalServer, imageContent).Result;
+                               var response = client.PostAsync ($"http://localhost:{port}/", imageContent).Result;
 
                                Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "#101");
                                Assert.AreEqual(false, failed, "#102");
@@ -1214,13 +1247,14 @@ namespace MonoTests.System.Net.Http
                                response.OutputStream.WriteByte (0x6f);
                        };
 
-                       var listener = CreateListener (context); // creates a default request handler
+                       var port = NetworkHelpers.FindFreePort ();
+                       var listener = CreateListener (context, port); // creates a default request handler
                        AddListenerContext (listener, context);  // add another request handler for the second request
 
                        try {
                                var client = new HttpClient ();
-                               var t1 = client.GetStringAsync (LocalServer);
-                               var t2 = client.GetStringAsync (LocalServer);
+                               var t1 = client.GetStringAsync ($"http://localhost:{port}/");
+                               var t2 = client.GetStringAsync ($"http://localhost:{port}/");
                                Assert.IsTrue (Task.WaitAll (new [] { t1, t2 }, WaitTimeout));
                                Assert.AreEqual ("hello", t1.Result, "#1");
                                Assert.AreEqual ("hello", t2.Result, "#2");
@@ -1236,16 +1270,17 @@ namespace MonoTests.System.Net.Http
 #endif
                public void GetByteArray_ServerError ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var response = l.Response;
                                response.StatusCode = 500;
                                l.Response.OutputStream.WriteByte (72);
-                       });
+                       }, port);
 
                        try {
                                var client = new HttpClient ();
                                try {
-                                       client.GetByteArrayAsync (LocalServer).Wait (WaitTimeout);
+                                       client.GetByteArrayAsync ($"http://localhost:{port}/").Wait (WaitTimeout);
                                        Assert.Fail ("#1");
                                } catch (AggregateException e) {
                                        Assert.IsTrue (e.InnerException is HttpRequestException , "#2");
@@ -1261,13 +1296,14 @@ namespace MonoTests.System.Net.Http
 #endif
                public void DisallowAutoRedirect ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                var response = l.Response;
                                
                                response.StatusCode = (int)HttpStatusCode.Moved;
                                response.RedirectLocation = "http://xamarin.com/";
-                       });
+                       }, port);
 
                        try {
                                var chandler = new HttpClientHandler ();
@@ -1275,7 +1311,7 @@ namespace MonoTests.System.Net.Http
                                var client = new HttpClient (chandler);
 
                                try {
-                                       client.GetStringAsync (LocalServer).Wait (WaitTimeout);
+                                       client.GetStringAsync ($"http://localhost:{port}/").Wait (WaitTimeout);
                                        Assert.Fail ("#1");
                                } catch (AggregateException e) {
                                        Assert.IsTrue (e.InnerException is HttpRequestException, "#2");
@@ -1292,13 +1328,16 @@ namespace MonoTests.System.Net.Http
 #endif
                public void RequestUriAfterRedirect ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
+                       var redirectPort = NetworkHelpers.FindFreePort ();
+
                        var listener = CreateListener (l => {
                                var request = l.Request;
                                var response = l.Response;
 
                                response.StatusCode = (int)HttpStatusCode.Moved;
-                               response.RedirectLocation = "http://localhost:8811/";
-                       });
+                               response.RedirectLocation = $"http://localhost:{redirectPort}/";
+                       }, port);
 
                        var listener2 = CreateListener (l => {
                                var response = l.Response;
@@ -1309,17 +1348,17 @@ namespace MonoTests.System.Net.Http
                                response.OutputStream.WriteByte (0x6c);
                                response.OutputStream.WriteByte (0x6c);
                                response.OutputStream.WriteByte (0x6f);
-                       }, 8811);
+                       }, redirectPort);
 
                        try {
                                var chandler = new HttpClientHandler ();
                                chandler.AllowAutoRedirect = true;
                                var client = new HttpClient (chandler);
 
-                               var r = client.GetAsync (LocalServer);
+                               var r = client.GetAsync ($"http://localhost:{port}/");
                                Assert.IsTrue (r.Wait (WaitTimeout), "#1");
                                var resp = r.Result;
-                               Assert.AreEqual ("http://localhost:8811/", resp.RequestMessage.RequestUri.AbsoluteUri, "#2");
+                               Assert.AreEqual ($"http://localhost:{redirectPort}/", resp.RequestMessage.RequestUri.AbsoluteUri, "#2");
                                Assert.AreEqual ("hello", resp.Content.ReadAsStringAsync ().Result, "#3");
                        } finally {
                                listener.Abort ();
@@ -1342,14 +1381,15 @@ namespace MonoTests.System.Net.Http
                        chandler.AllowAutoRedirect = true;
                        var client = new HttpClient (chandler, true);
 
+                       var port = NetworkHelpers.FindFreePort ();
                        var listener = CreateListener (l => {
                                var response = l.Response;
                                response.StatusCode = 200;
                                response.OutputStream.WriteByte (55);
-                       });
+                       }, port);
 
                        try {
-                               client.GetStringAsync (LocalServer).Wait (WaitTimeout);
+                               client.GetStringAsync ($"http://localhost:{port}/").Wait (WaitTimeout);
                                try {
                                        chandler.AllowAutoRedirect = false;
                                        Assert.Fail ("#1");
@@ -1388,11 +1428,6 @@ namespace MonoTests.System.Net.Http
                        ch.AllowAutoRedirect = false;
                }
 
-               HttpListener CreateListener (Action<HttpListenerContext> contextAssert)
-               {
-                       return CreateListener (contextAssert, port);
-               }
-
                HttpListener CreateListener (Action<HttpListenerContext> contextAssert, int port)
                {
                        var l = new HttpListener ();
index 8aae7d9e602904bd3c5b2c4e181e210051db3ffb..4d942c11997937f3fd968b944ce6a2f830b4adca 100644 (file)
@@ -1,4 +1,5 @@
 ../../test-helpers/NunitHelpers.cs
+../../test-helpers/NetworkHelpers.cs
 System.Runtime.Remoting.Channels.Tcp/TcpChannelTest.cs
 ServerObject.cs
 ContextsTest.cs
index b70409344f9eb48f580153c3399e6796b87dd082..5ea68f21d5a931d59a6cd9c381e9a8eb9e20e9d0 100644 (file)
@@ -14,6 +14,8 @@ using System.Runtime.Remoting.Channels.Tcp;
 using System.Runtime.Remoting.Channels.Http;
 using NUnit.Framework;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.Remoting
 {
        [TestFixture]
@@ -40,12 +42,14 @@ namespace MonoTests.Remoting
                                AppDomain domain = BaseCallTest.CreateDomain ("testdomain_activation");
                                server = (ActivationServer) domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName,"MonoTests.Remoting.ActivationServer");
                                
-                               RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), "tcp://localhost:9433");
-                               RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), "http://localhost:9434");
-                               RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), "tcp://localhost:9433/wkoSingleCall1");
-                               RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), "tcp://localhost:9433/wkoSingleton1");
-                               RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), "http://localhost:9434/wkoSingleCall2");
-                               RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), "http://localhost:9434/wkoSingleton2");
+                               var tcpUrlPrefix = $"tcp://localhost:{server.TcpPort}";
+                               var httpUrlPrefix = $"http://localhost:{server.HttpPort}";
+                               RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject1), tcpUrlPrefix);
+                               RemotingConfiguration.RegisterActivatedClientType (typeof(CaObject2), httpUrlPrefix);
+                               RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall1), tcpUrlPrefix + "/wkoSingleCall1");
+                               RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton1), tcpUrlPrefix + "/wkoSingleton1");
+                               RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSinglecall2), httpUrlPrefix + "/wkoSingleCall2");
+                               RemotingConfiguration.RegisterWellKnownClientType (typeof(WkObjectSingleton2), httpUrlPrefix + "/wkoSingleton2");
                        }
                        catch (Exception ex)
                        {
@@ -163,8 +167,10 @@ namespace MonoTests.Remoting
                
                public ActivationServer ()
                {
-                       tcp =  new TcpChannel (9433);
-                       http =  new HttpChannel (9434);
+                       TcpPort = NetworkHelpers.FindFreePort ();
+                       HttpPort = NetworkHelpers.FindFreePort ();
+                       tcp =  new TcpChannel (TcpPort);
+                       http =  new HttpChannel (HttpPort);
                        
                        ChannelServices.RegisterChannel (tcp);
                        ChannelServices.RegisterChannel (http);
@@ -182,6 +188,9 @@ namespace MonoTests.Remoting
                        ChannelServices.UnregisterChannel (tcp);
                        ChannelServices.UnregisterChannel (http);
                }
+
+               public int TcpPort { get; private set; }
+               public int HttpPort { get; private set; }
        }
        
        public class BaseObject: MarshalByRefObject
index 519686785c9002b058abc5909165ca4a223aa928..a8a9a7bfead8a0783b18a9a827bcfd2743d36827 100644 (file)
@@ -16,6 +16,8 @@ using System.Runtime.Remoting.Channels.Ipc;
 using System.Threading;
 using NUnit.Framework;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.Remoting
 {
        public interface INested
@@ -166,15 +168,16 @@ namespace MonoTests.Remoting
                [Test]
                public void TestTcpChannel ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        IDictionary props = new Hashtable ();
                        props ["name"] = Guid.NewGuid ().ToString("N");
-                       props ["port"] = 18191;
+                       props ["port"] = port;
                        TcpChannel chan = new TcpChannel (props, null, null);
                        ChannelServices.RegisterChannel (chan);
                        
                        try {
                                Register <Server<object>> ("gentcptest.rem");
-                               RunTests (Connect <Server<object>> ("tcp://localhost:18191/gentcptest.rem"));
+                               RunTests (Connect <Server<object>> ($"tcp://localhost:{port}/gentcptest.rem"));
                        } finally {
                                ChannelServices.UnregisterChannel (chan);
                        }
index c809f96c9401173bd5de5f7a6817026bd9291f24..553c58a580bfbd286c6e19f7d70d3e494236316c 100644 (file)
@@ -7,6 +7,8 @@ using System.Runtime.Remoting.Channels;
 using System.Runtime.Remoting.Channels.Http;
 using NUnit.Framework;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.Remoting.Http
 {
        //Test for Bug 324362 - SoapFormatter cannot deserialize the same MBR twice
@@ -67,13 +69,14 @@ namespace MonoTests.Remoting.Http
                [Test]
                public void Main ()
                {
-                       channel = new HttpChannel (3344);
+                       var port = NetworkHelpers.FindFreePort ();
+                       channel = new HttpChannel (port);
                        ChannelServices.RegisterChannel (channel);
                        RemotingConfiguration.RegisterWellKnownServiceType
                                (typeof (Bug321420),"Server.soap", WellKnownObjectMode.Singleton);
                        
                        Bug321420 s = (Bug321420) Activator.GetObject (typeof
-                               (Bug321420), "http://localhost:3344/Server.soap");
+                               (Bug321420), $"http://localhost:{port}/Server.soap");
                        
                        // this works: s.Method ("a", "b");
                        s.Method ("a", "a");
@@ -98,7 +101,7 @@ namespace MonoTests.Remoting.Http
                public void Main ()
                {
                        Foo foo = (Foo) Activator.GetObject (typeof (Foo),
-                               "http://localhost:4321/Test");
+                               $"http://localhost:{server.HttpPort}/Test");
 
                        Bar bar = foo.Login ();
                        if (bar != null)
@@ -142,7 +145,8 @@ namespace MonoTests.Remoting.Http
                        
                        public void Start ()
                        {
-                               c = new HttpChannel (4321);
+                               HttpPort = NetworkHelpers.FindFreePort ();
+                               c = new HttpChannel (HttpPort);
                                ChannelServices.RegisterChannel (c);
                                
                                Type t = typeof(Foo);
@@ -155,6 +159,8 @@ namespace MonoTests.Remoting.Http
                                c.StopListening (null);
                                ChannelServices.UnregisterChannel (c);
                        }
+
+                       public int HttpPort { get; private set; }
                }
        }
        
@@ -172,7 +178,7 @@ namespace MonoTests.Remoting.Http
                        ChannelServices.RegisterChannel (channel);
                        MarshalByRefObject obj = (MarshalByRefObject) RemotingServices.Connect (
                                typeof (IFactorial),
-                               "http://localhost:60000/MyEndPoint");
+                               $"http://localhost:{server.HttpPort}/MyEndPoint");
                        IFactorial cal = (IFactorial) obj;
                        Assert.AreEqual (cal.CalculateFactorial (4), 24);
                }
@@ -209,7 +215,8 @@ namespace MonoTests.Remoting.Http
                        
                        public void Start ()
                        {
-                               c = new HttpChannel (60000);
+                               HttpPort = NetworkHelpers.FindFreePort ();
+                               c = new HttpChannel (HttpPort);
                                ChannelServices.RegisterChannel (c);
                                
                                Type t = typeof(Calculator);
@@ -222,6 +229,8 @@ namespace MonoTests.Remoting.Http
                                c.StopListening (null);
                                ChannelServices.UnregisterChannel (c);
                        }
+
+                       public int HttpPort { get; private set; }
                }
                
                public class Calculator : MarshalByRefObject, IFactorial
index 02c6a532c00ce24d94a757b312892a2df1920c86..0dd58aa38cbbaef1f10eb1ec19e6134aa6074baf 100644 (file)
@@ -18,6 +18,8 @@ using System.Runtime.Remoting.Proxies;
 using System.Runtime.Remoting.Channels;\r
 using System.Runtime.Remoting.Channels.Tcp;\r
 \r
+using MonoTests.Helpers;\r
+\r
 namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal\r
 {\r
        // We need our own proxy to intercept messages to remote object\r
@@ -286,17 +288,18 @@ namespace MonoTests.Remoting
                [Test]\r
                public void Connect ()\r
                {\r
+                       var port = NetworkHelpers.FindFreePort ();\r
                        MarshalObject objMarshal = NewMarshalObject ();\r
 \r
                        IDictionary props = new Hashtable ();\r
                        props ["name"] = objMarshal.Uri;\r
-                       props ["port"] = 1236;\r
+                       props ["port"] = port;\r
                        TcpChannel chn = new TcpChannel (props, null, null);\r
                        ChannelServices.RegisterChannel (chn);\r
 \r
                        try {\r
                                RemotingServices.Marshal (objMarshal, objMarshal.Uri);\r
-                               MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), "tcp://localhost:1236/" + objMarshal.Uri);\r
+                               MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), $"tcp://localhost:{port}/" + objMarshal.Uri);\r
                                Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#A08");\r
                        } finally {\r
                                ChannelServices.UnregisterChannel (chn);\r
@@ -308,17 +311,18 @@ namespace MonoTests.Remoting
                [Test]\r
                public void MarshalThrowException ()\r
                {\r
+                       var port = NetworkHelpers.FindFreePort ();\r
                        MarshalObject objMarshal = NewMarshalObject ();\r
 \r
                        IDictionary props = new Hashtable ();\r
                        props ["name"] = objMarshal.Uri;\r
-                       props ["port"] = 1237;\r
+                       props ["port"] = port;\r
                        TcpChannel chn = new TcpChannel (props, null, null);\r
                        ChannelServices.RegisterChannel (chn);\r
 \r
                        try {\r
                                RemotingServices.Marshal (objMarshal, objMarshal.Uri);\r
-                               MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), "tcp://localhost:1237/" + objMarshal.Uri);\r
+                               MarshalObject objRem = (MarshalObject) RemotingServices.Connect (typeof (MarshalObject), $"tcp://localhost:{port}/" + objMarshal.Uri);\r
                                // This line should throw a RemotingException\r
                                // It is forbidden to export an object which is not\r
                                // a real object\r
@@ -341,14 +345,15 @@ namespace MonoTests.Remoting
                [Test]\r
                public void ExecuteMessage ()\r
                {\r
-                       TcpChannel chn = new TcpChannel (1235);\r
+                       var port = NetworkHelpers.FindFreePort ();\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
                                MarshalObject objMarshal = NewMarshalObject ();\r
                                RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall);\r
 \r
                                // use a proxy to catch the Message\r
-                               MyProxy proxy = new MyProxy (typeof (MarshalObject), (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1235/" + objMarshal.Uri));\r
+                               MyProxy proxy = new MyProxy (typeof (MarshalObject), (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/" + objMarshal.Uri));\r
 \r
                                MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy ();\r
 \r
@@ -373,12 +378,13 @@ namespace MonoTests.Remoting
                [Test]\r
                public void IsOneWay ()\r
                {\r
-                       TcpChannel chn = new TcpChannel (1238);\r
+                       var port = NetworkHelpers.FindFreePort ();\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
                                RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);\r
 \r
-                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1238/MarshalObject.rem");\r
+                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/MarshalObject.rem");\r
 \r
                                Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#A10.1");\r
 \r
@@ -396,13 +402,14 @@ namespace MonoTests.Remoting
                [Test]\r
                public void GetObjRefForProxy ()\r
                {\r
-                       TcpChannel chn = new TcpChannel (1239);\r
+                       var port = NetworkHelpers.FindFreePort ();\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
                                // Register le factory as a SAO\r
                                RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObjectFactory), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap", WellKnownObjectMode.Singleton);\r
 \r
-                               MarshalObjectFactory objFactory = (MarshalObjectFactory) Activator.GetObject (typeof (MarshalObjectFactory), "tcp://localhost:1239/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");\r
+                               MarshalObjectFactory objFactory = (MarshalObjectFactory) Activator.GetObject (typeof (MarshalObjectFactory), $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");\r
 \r
                                // Get a new "CAO"\r
                                MarshalObject objRem = objFactory.GetNewMarshalObject ();\r
@@ -419,12 +426,13 @@ namespace MonoTests.Remoting
                [Test]\r
                public void GetRealProxy ()\r
                {\r
-                       TcpChannel chn = new TcpChannel (1241);\r
+                       var port = NetworkHelpers.FindFreePort ();\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
                                RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);\r
 \r
-                               MyProxy proxy = new MyProxy (typeof (MarshalObject), (MarshalByRefObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1241/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));\r
+                               MyProxy proxy = new MyProxy (typeof (MarshalObject), (MarshalByRefObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));\r
                                MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy ();\r
 \r
                                RealProxy rp = RemotingServices.GetRealProxy (objRem);\r
@@ -440,14 +448,15 @@ namespace MonoTests.Remoting
                [Test]\r
                public void SetObjectUriForMarshal ()\r
                {\r
-                       TcpChannel chn = new TcpChannel (1242);\r
+                       var port = NetworkHelpers.FindFreePort ();\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
                                MarshalObject objRem = NewMarshalObject ();\r
                                RemotingServices.SetObjectUriForMarshal (objRem, objRem.Uri);\r
                                RemotingServices.Marshal (objRem);\r
 \r
-                               objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1242/" + objRem.Uri);\r
+                               objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/" + objRem.Uri);\r
                                Assert.IsNotNull (objRem, "#A14");\r
                        } finally {\r
                                ChannelServices.UnregisterChannel (chn);\r
@@ -459,7 +468,8 @@ namespace MonoTests.Remoting
                [Test]\r
                public void GetServeurTypeForUri ()\r
                {\r
-                       TcpChannel chn = new TcpChannel (1243);\r
+                       var port = NetworkHelpers.FindFreePort ();\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        Type type = typeof (MarshalObject);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
@@ -480,12 +490,13 @@ namespace MonoTests.Remoting
                [Category ("NotWorking")]\r
                public void IsObjectOutOf ()\r
                {\r
-                       TcpChannel chn = new TcpChannel (1245);\r
+                       var port = NetworkHelpers.FindFreePort ();\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
                                RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "MarshalObject2.rem", WellKnownObjectMode.Singleton);\r
 \r
-                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1245/MarshalObject2.rem");\r
+                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/MarshalObject2.rem");\r
 \r
                                Assert.IsTrue (RemotingServices.IsObjectOutOfAppDomain (objRem), "#A16");\r
                                Assert.IsTrue (RemotingServices.IsObjectOutOfContext (objRem), "#A17");\r
@@ -501,14 +512,15 @@ namespace MonoTests.Remoting
                [Test]\r
                public void ApplicationNameTest ()\r
                {\r
+                       var port = NetworkHelpers.FindFreePort ();\r
                        RemotingConfiguration.ApplicationName = "app";\r
-                       TcpChannel chn = new TcpChannel (1246);\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
                                RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "obj3.rem", WellKnownObjectMode.Singleton);\r
 \r
-                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1246/app/obj3.rem");\r
-                               MarshalObject objRem2 = (MarshalObject) Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1246/obj3.rem");\r
+                               MarshalObject objRem = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/app/obj3.rem");\r
+                               MarshalObject objRem2 = (MarshalObject) Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/obj3.rem");\r
 \r
                                Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem), "#AN1");\r
                                Assert.IsTrue (RemotingServices.IsTransparentProxy (objRem2), "#AN2");\r
@@ -528,13 +540,14 @@ namespace MonoTests.Remoting
                [Test]\r
                public void GetObjectWithChannelDataTest ()\r
                {\r
-                       TcpChannel chn = new TcpChannel (1247);\r
+                       var port = NetworkHelpers.FindFreePort ();\r
+                       TcpChannel chn = new TcpChannel (port);\r
                        ChannelServices.RegisterChannel (chn);\r
                        try {\r
                                RemotingConfiguration.RegisterWellKnownServiceType (typeof (MarshalObject), "getobjectwithchanneldata.rem", WellKnownObjectMode.Singleton);\r
 \r
                                string channelData = "test";\r
-                               Assert.IsNotNull (Activator.GetObject (typeof (MarshalObject), "tcp://localhost:1247/getobjectwithchanneldata.rem", channelData), "#01");\r
+                               Assert.IsNotNull (Activator.GetObject (typeof (MarshalObject), $"tcp://localhost:{port}/getobjectwithchanneldata.rem", channelData), "#01");\r
                        } finally {\r
                                ChannelServices.UnregisterChannel (chn);\r
                        }\r
@@ -544,28 +557,29 @@ namespace MonoTests.Remoting
                [Ignore ("We cannot test RemotingConfiguration.Configure() because it keeps channels registered. If we really need to test it, do it as a standalone case")]\r
                public void ConnectProxyCast ()\r
                {\r
+                       var port = NetworkHelpers.FindFreePort ();\r
                        object o;\r
                        RemotingConfiguration.Configure (null);\r
 \r
-                       o = RemotingServices.Connect (typeof (MarshalByRefObject), "tcp://localhost:3434/ff1.rem");\r
+                       o = RemotingServices.Connect (typeof (MarshalByRefObject), $"tcp://localhost:{port}/ff1.rem");\r
                        Assert.IsInstanceOfType (typeof (DD), o, "#m1");\r
                        Assert.IsInstanceOfType (typeof (A), o, "#m2");\r
                        Assert.IsInstanceOfType (typeof (B), o, "#m3");\r
                        AssertHelper.IsNotInstanceOfType (typeof (CC), !(o is CC), "#m4");\r
 \r
-                       o = RemotingServices.Connect (typeof (A), "tcp://localhost:3434/ff3.rem");\r
+                       o = RemotingServices.Connect (typeof (A), $"tcp://localhost:{port}/ff3.rem");\r
                        Assert.IsInstanceOfType (typeof (DD), o, "#a1");\r
                        Assert.IsInstanceOfType (typeof (A), o, "#a2");\r
                        Assert.IsInstanceOfType (typeof (B), o, "#a3");\r
                        AssertHelper.IsNotInstanceOfType (typeof (CC), o, "#a4");\r
 \r
-                       o = RemotingServices.Connect (typeof (DD), "tcp://localhost:3434/ff4.rem");\r
+                       o = RemotingServices.Connect (typeof (DD), $"tcp://localhost:{port}/ff4.rem");\r
                        Assert.IsInstanceOfType (typeof (DD), o, "#d1");\r
                        Assert.IsInstanceOfType (typeof (A), o, "#d2");\r
                        Assert.IsInstanceOfType (typeof (B), o, "#d3");\r
                        AssertHelper.IsNotInstanceOfType (typeof (CC), o, "#d4");\r
 \r
-                       o = RemotingServices.Connect (typeof (CC), "tcp://localhost:3434/ff5.rem");\r
+                       o = RemotingServices.Connect (typeof (CC), $"tcp://localhost:{port}/ff5.rem");\r
                        AssertHelper.IsNotInstanceOfType (typeof (DD), o, "#c1");\r
                        Assert.IsInstanceOfType (typeof (A), o, "#c2");\r
                        Assert.IsInstanceOfType (typeof (B), o, "#c3");\r
index 9074921c78d8db75d25d7451ece48a1269789ce7..c49df5bd0dcaeae2ef63c099fcb389b4269e57be 100644 (file)
@@ -35,6 +35,8 @@ using System.Runtime.Remoting.Channels.Tcp;
 
 using NUnit.Framework;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.Remoting
 {
        [TestFixture]
@@ -50,9 +52,10 @@ namespace MonoTests.Remoting
 
                        MarshalObject marshal = new MarshalObject ();
 
+                       var port = NetworkHelpers.FindFreePort ();
                        IDictionary props = new Hashtable ();
                        props ["name"] = "marshal channel";
-                       props ["port"] = 1236;
+                       props ["port"] = port;
                        props ["bindTo"] = IPAddress.Loopback.ToString ();
                        chn = new TcpChannel (props, null, null);
 
@@ -62,11 +65,11 @@ namespace MonoTests.Remoting
                        urls = chn.GetUrlsForUri (SERVICE_URI);
                        Assert.IsNotNull (urls, "#A2");
                        Assert.AreEqual (1, urls.Length, "#A3");
-                       Assert.AreEqual ("tcp://" + IPAddress.Loopback.ToString () + ":1236/" + SERVICE_URI, urls [0], "#A6");
+                       Assert.AreEqual ($"tcp://{IPAddress.Loopback.ToString ()}:{port}/{SERVICE_URI}", urls [0], "#A6");
                        ds = chn.ChannelData as ChannelDataStore;
                        Assert.IsNotNull (ds, "#A4");
                        Assert.AreEqual (1, ds.ChannelUris.Length, "#A5");
-                       Assert.AreEqual ("tcp://" + IPAddress.Loopback.ToString () + ":1236", ds.ChannelUris [0], "#A6");
+                       Assert.AreEqual ($"tcp://{IPAddress.Loopback.ToString ()}:{port}", ds.ChannelUris [0], "#A6");
 
                        ChannelServices.UnregisterChannel (chn);
                        
index e2af0ca1f761eb9c27ac566b3c08da078fafced2..8f7365939eb24ea37011586c01c62268b64325d3 100644 (file)
@@ -7,6 +7,8 @@ using System.ServiceModel.Channels;
 using System.ServiceModel.Web;
 using NUnit.Framework;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.System.ServiceModel.Activation
 {
        class MyHostFactory : WebScriptServiceHostFactory
@@ -23,8 +25,9 @@ namespace MonoTests.System.ServiceModel.Activation
                [Test]
                public void CreateServiceHost ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var f = new MyHostFactory ();
-                       var host = f.DoCreateServiceHost (typeof (TestService), new Uri [] {new Uri ("http://localhost:37564")});
+                       var host = f.DoCreateServiceHost (typeof (TestService), new Uri [] {new Uri ($"http://localhost:{port}")});
                        Assert.IsFalse (host is WebServiceHost, "#1");
                        host.Open ();
                        host.Close ();
@@ -34,8 +37,9 @@ namespace MonoTests.System.ServiceModel.Activation
                [ExpectedException (typeof (NotSupportedException))]
                public void ResponseWrappedIsInvalid ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var f = new MyHostFactory ();
-                       var host = f.DoCreateServiceHost (typeof (TestService2), new Uri [] {new Uri ("http://localhost:37564")});
+                       var host = f.DoCreateServiceHost (typeof (TestService2), new Uri [] {new Uri ($"http://localhost:{port}")});
                        host.Open (); // should raise an error here.
                }
 
@@ -43,8 +47,9 @@ namespace MonoTests.System.ServiceModel.Activation
                [ExpectedException (typeof (InvalidOperationException))]
                public void MultipleContract ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        var f = new MyHostFactory ();
-                       var host = f.DoCreateServiceHost (typeof (TestServiceMultiple), new Uri [] {new Uri ("http://localhost:37564")});
+                       var host = f.DoCreateServiceHost (typeof (TestServiceMultiple), new Uri [] {new Uri ($"http://localhost:{port}")});
                        host.Open ();
                }
 
index 8807873a86dd9053847ae65a81cdace19f47b589..6a225a25f52682fee5feb016c243a28910d82777 100644 (file)
@@ -45,11 +45,16 @@ namespace System.ServiceModel.PeerResolvers
        public class CustomPeerResolverService : IPeerResolverContract
        {
                static ServiceHost localhost;
+               static int port;
 
                static void SetupCustomPeerResolverServiceHost ()
                {
+                       string customPort = Environment.GetEnvironmentVariable ("MONO_CUSTOMPEERRESOLVERSERVICE_PORT");
+                       if (customPort == null || !int.TryParse (customPort, out port))
+                               port = 8931;
+
                        // launch peer resolver service locally only when it does not seem to be running ...
-                       var t = new TcpListener (8931);
+                       var t = new TcpListener (port);
                        try {
                                t.Start ();
                                t.Stop ();
@@ -59,7 +64,7 @@ namespace System.ServiceModel.PeerResolvers
                        Console.WriteLine ("WARNING: it is running peer resolver service locally. This means, the node registration is valid only within this application domain...");
                        var host = new ServiceHost (new LocalPeerResolverService (TextWriter.Null));
                        host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().InstanceContextMode = InstanceContextMode.Single;
-                       host.AddServiceEndpoint (typeof (ICustomPeerResolverContract), new BasicHttpBinding (), "http://localhost:8931");
+                       host.AddServiceEndpoint (typeof (ICustomPeerResolverContract), new BasicHttpBinding (), $"http://localhost:{port}");
                        localhost = host;
                        host.Open ();
                }
@@ -70,7 +75,7 @@ namespace System.ServiceModel.PeerResolvers
 
                public CustomPeerResolverService ()
                {
-                       client = ChannelFactory<ICustomPeerResolverClient>.CreateChannel (new BasicHttpBinding (), new EndpointAddress ("http://localhost:8931"));
+                       client = ChannelFactory<ICustomPeerResolverClient>.CreateChannel (new BasicHttpBinding (), new EndpointAddress ($"http://localhost:{port}"));
 
                        refresh_interval = new TimeSpan (0, 10, 0);
                        cleanup_interval = new TimeSpan (0, 1, 0);
index 211627b39c6f8ea78cc26519c8941362fb3ac6c1..80513455ec1ab771029d2573cc94f12ab9bfae9f 100644 (file)
@@ -14,14 +14,17 @@ using MonoTests.stand_alone.WebHarness;
 using System.ServiceModel.Dispatcher;
 using System.Collections.ObjectModel;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.Features
 {
        public class Configuration
        {
                static Configuration() {
+                       var port = NetworkHelpers.FindFreePort ();
                        onlyServers = Boolean.Parse (ConfigurationManager.AppSettings ["onlyServers"]  ?? "false");
                        onlyClients = Boolean.Parse (ConfigurationManager.AppSettings ["onlyClients"]  ?? "false");
-                       endpointBase = ConfigurationManager.AppSettings ["endpointBase"] ?? "http://localhost:9999/";
+                       endpointBase = ConfigurationManager.AppSettings ["endpointBase"] ?? $"http://localhost:{port}/";
                        if (!endpointBase.EndsWith ("/"))
                                endpointBase = endpointBase + '/';
                        logMessages = Boolean.Parse (ConfigurationManager.AppSettings ["logMessages"] ?? "false");
index 593ded1b011ad12caddc022a8e01259000a4d0e3..398a29a9847548b896a73d94688ac5327cd58ed7 100644 (file)
@@ -16,6 +16,8 @@ using System.Text;
 
 using NUnit.Framework;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.System.ServiceModel.PeerResolvers
 {
        [TestFixture]
@@ -26,6 +28,8 @@ namespace MonoTests.System.ServiceModel.PeerResolvers
                [SetUp]
                protected void SetUp ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
+                       Environment.SetEnvironmentVariable ("MONO_CUSTOMPEERRESOLVERSERVICE_PORT", port.ToString ());
                        cprs = new CustomPeerResolverService ();
                }
 
index d30f1f484f90f434fcfc5dfcccfad05ad0fd9387..0cc69e47648db2ed9fc45b7bc8af47bd83713b5d 100644 (file)
@@ -848,24 +848,7 @@ namespace Mono.AppleTls
 
                public override void Shutdown ()
                {
-                       if (Interlocked.Exchange (ref pendingIO, 1) == 1)
-                               throw new InvalidOperationException ();
-
-                       Debug ("Shutdown");
-
-                       lastException = null;
-
-                       try {
-                               if (closed || disposed)
-                                       return;
-
-                               var status = SSLClose (Handle);
-                               Debug ("Shutdown done: {0}", status);
-                               CheckStatusAndThrow (status);
-                       } finally {
-                               closed = true;
-                               pendingIO = 0;
-                       }
+                       closed = true;
                }
 
                #endregion
index 4fdabfd3ae3d22b8658a5a86dd5db672cc0edcd1..9582f6aceb74a6d3c23d1dbafdb3b77f2e520530 100644 (file)
@@ -65,6 +65,10 @@ namespace Mono.AppleTls
                        get { return true; }
                }
 
+               internal override bool SupportsCleanShutdown {
+                       get { return false; }
+               }
+
                public override SslProtocols SupportedProtocols {
                        get { return SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; }
                }
index 335be7d3090989200f346caef2b04bf420b998ed..559db4aca5d4f8288686b51369d6324a1114f5fd 100644 (file)
@@ -357,7 +357,8 @@ namespace Mono.Btls
                public override void Shutdown ()
                {
                        Debug ("Shutdown!");
-//                     ssl.SetQuietShutdown ();
+                       if (Settings == null || !Settings.SendCloseNotify)
+                               ssl.SetQuietShutdown ();
                        ssl.Shutdown ();
                }
 
index bd979345e0debc693cfe43b9c5db0c7ca096277e..0db248b991264239131aac70f934d6557e2c1fd0 100644 (file)
@@ -75,6 +75,10 @@ namespace Mono.Btls
                        get { return true; }
                }
 
+               internal override bool SupportsCleanShutdown {
+                       get { return true; }
+               }
+
                public override SslProtocols SupportedProtocols {
                        get { return SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls; }
                }
index 3c537a7e42798b46ee80b02477db30759666c7fa..8ed25908b0f0d38b61d55e10a12103cf3949383c 100644 (file)
@@ -158,7 +158,7 @@ namespace Mono.Net.Security
                        RunSynchronously = sync;
                }
 
-               [SD.Conditional ("MARTIN_DEBUG")]
+               [SD.Conditional ("MONO_TLS_DEBUG")]
                protected void Debug (string message, params object[] args)
                {
                        Parent.Debug ("{0}({1}:{2}): {3}", Name, Parent.ID, ID, string.Format (message, args));
@@ -226,6 +226,7 @@ namespace Mono.Net.Security
 
                                if (Interlocked.Exchange (ref WriteRequested, 0) != 0) {
                                        // Flush the write queue.
+                                       Debug ("ProcessOperation - flushing write queue");
                                        await Parent.InnerWrite (RunSynchronously, cancellationToken);
                                }
 
index a67b1ff069e9c67c83a61f73e65c04165ad54af6..d5d66c2f5eedd5e28a0b57a6007102630e024cad 100644 (file)
@@ -68,6 +68,10 @@ namespace Mono.Net.Security
                        get { return false; }
                }
 
+               internal override bool SupportsCleanShutdown {
+                       get { return false; }
+               }
+
                public override SslProtocols SupportedProtocols {
                        get { return SslProtocols.Tls; }
                }
index f15f32596b7b151a196f5f2acb6292a2cb190dd3..95ecb8fd64a2d1e8a4a59296eba02dd660a86bea 100644 (file)
@@ -384,10 +384,10 @@ namespace Mono.Net.Security
                static int nextId;
                internal readonly int ID = ++nextId;
 
-               [SD.Conditional ("MARTIN_DEBUG")]
+               [SD.Conditional ("MONO_TLS_DEBUG")]
                protected internal void Debug (string message, params object[] args)
                {
-                       Console.Error.WriteLine ("MobileAuthenticatedStream({0}): {1}", ID, string.Format (message, args));
+                       MonoTlsProviderFactory.Debug ("MobileAuthenticatedStream({0}): {1}", ID, string.Format (message, args));
                }
 
 #region Called back from native code via SslConnection
index 83014b2c9e8a6ae29c4c5e71e84d8d04d9e747ff..74410976a85098a4b786d38618d220da78b78863 100644 (file)
@@ -78,10 +78,10 @@ namespace Mono.Net.Security
                        get { return parent.Provider; }
                }
 
-               [SD.Conditional ("MARTIN_DEBUG")]
+               [SD.Conditional ("MONO_TLS_DEBUG")]
                protected void Debug (string message, params object[] args)
                {
-                       Console.Error.WriteLine ("{0}: {1}", GetType ().Name, string.Format (message, args));
+                       parent.Debug ("{0}: {1}", GetType ().Name, string.Format (message, args));
                }
 
                public abstract bool HasContext {
index 660e3b41bb6b5e5ca366a52dfbba32ad5810830e..dcc640ad30fea939f1212247233e18284e40705a 100644 (file)
@@ -38,6 +38,7 @@ using System.Security.Cryptography.X509Certificates;
 
 using System;
 using System.Net;
+using System.Diagnostics;
 using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 
@@ -192,6 +193,22 @@ namespace Mono.Net.Security
                        }
                }
 
+               static bool enableDebug;
+
+               [Conditional ("MONO_TLS_DEBUG")]
+               static void InitializeDebug ()
+               {
+                       if (Environment.GetEnvironmentVariable ("MONO_TLS_DEBUG") != null)
+                               enableDebug = true;
+               }
+
+               [Conditional ("MONO_TLS_DEBUG")]
+               internal static void Debug (string message, params object[] args)
+               {
+                       if (enableDebug)
+                               Console.Error.WriteLine (message, args);
+               }
+
 #endregion
 
                internal static readonly Guid AppleTlsId = new Guid ("981af8af-a3a3-419a-9f01-a518e3a17c1c");
@@ -203,6 +220,9 @@ namespace Mono.Net.Security
                        lock (locker) {
                                if (providerRegistration != null)
                                        return;
+
+                               InitializeDebug ();
+
                                providerRegistration = new Dictionary<string,Tuple<Guid,string>> ();
                                providerCache = new Dictionary<Guid,MSI.MonoTlsProvider> ();
 
index 238d4e93b2ddf02c3d97c9872bad2740d5760cd9..e72ecbccdb1cef30a05d346c09c69c9ae6fb71e1 100644 (file)
     <Compile Include="Mono.Btls\MonoBtlsSsl.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsSslCtx.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsSslError.cs" />\r
+    <Compile Include="Mono.Btls\MonoBtlsSslRenegotiateMode.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsStream.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsUtils.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsX509.cs" />\r
index a5674f117fd22a2d8d918f7360c0c7982e1dd237..1ce421563e9f0a4eba99cc4ef492ed73a11398c0 100644 (file)
     <Compile Include="Mono.Btls\MonoBtlsSsl.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsSslCtx.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsSslError.cs" />\r
+    <Compile Include="Mono.Btls\MonoBtlsSslRenegotiateMode.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsStream.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsUtils.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsX509.cs" />\r
index ba3f462a940ec3e8f9666a2b1a3ca80674e4071a..70ecd84110e69c3934c2580792b428b58f0629d6 100644 (file)
     <Compile Include="Mono.Btls\MonoBtlsSsl.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsSslCtx.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsSslError.cs" />\r
+    <Compile Include="Mono.Btls\MonoBtlsSslRenegotiateMode.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsStream.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsUtils.cs" />\r
     <Compile Include="Mono.Btls\MonoBtlsX509.cs" />\r
index ae92b8d730bb51f7ad2493ae02351ccd90cbfb36..4a889e4dd2709692107c9acee71d19ca0b670551 100644 (file)
@@ -1290,7 +1290,12 @@ namespace System.Net.Sockets
                        ThrowIfBufferOutOfRange (buffer, offset, size);
 
                        int nativeError;
-                       int ret = Receive_internal (m_Handle, buffer, offset, size, socketFlags, out nativeError, is_blocking);
+                       int ret;
+                       unsafe {
+                               fixed (byte* pbuffer = buffer) {
+                                       ret = Receive_internal (m_Handle, &pbuffer[offset], size, socketFlags, out nativeError, is_blocking);
+                               }
+                       }
 
                        errorCode = (SocketError) nativeError;
                        if (errorCode != SocketError.Success && errorCode != SocketError.WouldBlock && errorCode != SocketError.InProgress) {
@@ -1315,25 +1320,27 @@ namespace System.Net.Sockets
                        int nativeError;
                        int ret;
 
-                       /* Only example I can find of sending a byte array reference directly into an internal
-                        * call is in System.Runtime.Remoting/System.Runtime.Remoting.Channels.Ipc.Win32/NamedPipeSocket.cs,
-                        * so taking a lead from that... */
-                       WSABUF[] bufarray = new WSABUF[numsegments];
                        GCHandle[] gch = new GCHandle[numsegments];
+                       try {
+                               unsafe {
+                                       fixed (WSABUF* bufarray = new WSABUF[numsegments]) {
+                                               for (int i = 0; i < numsegments; i++) {
+                                                       ArraySegment<byte> segment = buffers[i];
 
-                       for (int i = 0; i < numsegments; i++) {
-                               ArraySegment<byte> segment = buffers[i];
+                                                       if (segment.Offset < 0 || segment.Count < 0 || segment.Count > segment.Array.Length - segment.Offset)
+                                                               throw new ArgumentOutOfRangeException ("segment");
 
-                               if (segment.Offset < 0 || segment.Count < 0 || segment.Count > segment.Array.Length - segment.Offset)
-                                       throw new ArgumentOutOfRangeException ("segment");
+                                                       try {} finally {
+                                                               gch[i] = GCHandle.Alloc (segment.Array, GCHandleType.Pinned);
+                                                       }
 
-                               gch[i] = GCHandle.Alloc (segment.Array, GCHandleType.Pinned);
-                               bufarray[i].len = segment.Count;
-                               bufarray[i].buf = Marshal.UnsafeAddrOfPinnedArrayElement (segment.Array, segment.Offset);
-                       }
+                                                       bufarray[i].len = segment.Count;
+                                                       bufarray[i].buf = Marshal.UnsafeAddrOfPinnedArrayElement (segment.Array, segment.Offset);
+                                               }
 
-                       try {
-                               ret = Receive_internal (m_Handle, bufarray, socketFlags, out nativeError, is_blocking);
+                                               ret = Receive_internal (m_Handle, bufarray, numsegments, socketFlags, out nativeError, is_blocking);
+                                       }
+                               }
                        } finally {
                                for (int i = 0; i < numsegments; i++) {
                                        if (gch[i].IsAllocated)
@@ -1422,7 +1429,11 @@ namespace System.Net.Sockets
                        int total = 0;
 
                        try {
-                               total = Receive_internal (sockares.socket.m_Handle, sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, out sockares.error, sockares.socket.is_blocking);
+                               unsafe {
+                                       fixed (byte* pbuffer = sockares.Buffer) {
+                                               total = Receive_internal (sockares.socket.m_Handle, &pbuffer[sockares.Offset], sockares.Size, sockares.SockFlags, out sockares.error, sockares.socket.is_blocking);
+                                       }
+                               }
                        } catch (Exception e) {
                                sockares.Complete (e);
                                return;
@@ -1488,31 +1499,31 @@ namespace System.Net.Sockets
                        return sockares.Total;
                }
 
-               static int Receive_internal (SafeSocketHandle safeHandle, WSABUF[] bufarray, SocketFlags flags, out int error, bool blocking)
+               static unsafe int Receive_internal (SafeSocketHandle safeHandle, WSABUF* bufarray, int count, SocketFlags flags, out int error, bool blocking)
                {
                        try {
                                safeHandle.RegisterForBlockingSyscall ();
-                               return Receive_internal (safeHandle.DangerousGetHandle (), bufarray, flags, out error, blocking);
+                               return Receive_internal (safeHandle.DangerousGetHandle (), bufarray, count, flags, out error, blocking);
                        } finally {
                                safeHandle.UnRegisterForBlockingSyscall ();
                        }
                }
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               extern static int Receive_internal (IntPtr sock, WSABUF[] bufarray, SocketFlags flags, out int error, bool blocking);
+               extern static unsafe int Receive_internal (IntPtr sock, WSABUF* bufarray, int count, SocketFlags flags, out int error, bool blocking);
 
-               static int Receive_internal (SafeSocketHandle safeHandle, byte[] buffer, int offset, int count, SocketFlags flags, out int error, bool blocking)
+               static unsafe int Receive_internal (SafeSocketHandle safeHandle, byte* buffer, int count, SocketFlags flags, out int error, bool blocking)
                {
                        try {
                                safeHandle.RegisterForBlockingSyscall ();
-                               return Receive_internal (safeHandle.DangerousGetHandle (), buffer, offset, count, flags, out error, blocking);
+                               return Receive_internal (safeHandle.DangerousGetHandle (), buffer, count, flags, out error, blocking);
                        } finally {
                                safeHandle.UnRegisterForBlockingSyscall ();
                        }
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern static int Receive_internal(IntPtr sock, byte[] buffer, int offset, int count, SocketFlags flags, out int error, bool blocking);
+               extern static unsafe int Receive_internal(IntPtr sock, byte* buffer, int count, SocketFlags flags, out int error, bool blocking);
 
 #endregion
 
@@ -1541,7 +1552,12 @@ namespace System.Net.Sockets
                        SocketAddress sockaddr = remoteEP.Serialize();
 
                        int nativeError;
-                       int cnt = ReceiveFrom_internal (m_Handle, buffer, offset, size, socketFlags, ref sockaddr, out nativeError, is_blocking);
+                       int cnt;
+                       unsafe {
+                               fixed (byte* pbuffer = buffer) {
+                                       cnt = ReceiveFrom_internal (m_Handle, &pbuffer[offset], size, socketFlags, ref sockaddr, out nativeError, is_blocking);
+                               }
+                       }
 
                        errorCode = (SocketError) nativeError;
                        if (errorCode != SocketError.Success) {
@@ -1672,18 +1688,18 @@ namespace System.Net.Sockets
 
 
 
-               static int ReceiveFrom_internal (SafeSocketHandle safeHandle, byte[] buffer, int offset, int count, SocketFlags flags, ref SocketAddress sockaddr, out int error, bool blocking)
+               static unsafe int ReceiveFrom_internal (SafeSocketHandle safeHandle, byte* buffer, int count, SocketFlags flags, ref SocketAddress sockaddr, out int error, bool blocking)
                {
                        try {
                                safeHandle.RegisterForBlockingSyscall ();
-                               return ReceiveFrom_internal (safeHandle.DangerousGetHandle (), buffer, offset, count, flags, ref sockaddr, out error, blocking);
+                               return ReceiveFrom_internal (safeHandle.DangerousGetHandle (), buffer, count, flags, ref sockaddr, out error, blocking);
                        } finally {
                                safeHandle.UnRegisterForBlockingSyscall ();
                        }
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern static int ReceiveFrom_internal(IntPtr sock, byte[] buffer, int offset, int count, SocketFlags flags, ref SocketAddress sockaddr, out int error, bool blocking);
+               extern static unsafe int ReceiveFrom_internal(IntPtr sock, byte* buffer, int count, SocketFlags flags, ref SocketAddress sockaddr, out int error, bool blocking);
 
 #endregion
 
@@ -1757,8 +1773,12 @@ namespace System.Net.Sockets
                        int nativeError;
                        int sent = 0;
                        do {
-                               sent += Send_internal (
-m_Handle, buffer, offset + sent, size - sent, socketFlags, out nativeError, is_blocking);
+                               unsafe {
+                                       fixed (byte *pbuffer = buffer) {
+                                               sent += Send_internal (m_Handle, &pbuffer[offset + sent], size - sent, socketFlags, out nativeError, is_blocking);
+                                       }
+                               }
+
                                errorCode = (SocketError)nativeError;
                                if (errorCode != SocketError.Success && errorCode != SocketError.WouldBlock && errorCode != SocketError.InProgress) {
                                        is_connected = false;
@@ -1786,28 +1806,32 @@ m_Handle, buffer, offset + sent, size - sent, socketFlags, out nativeError, is_b
                        int nativeError;
                        int ret;
 
-                       WSABUF[] bufarray = new WSABUF[numsegments];
                        GCHandle[] gch = new GCHandle[numsegments];
+                       try {
+                               unsafe {
+                                       fixed (WSABUF* bufarray = new WSABUF[numsegments]) {
+                                               for(int i = 0; i < numsegments; i++) {
+                                                       ArraySegment<byte> segment = buffers[i];
 
-                       for(int i = 0; i < numsegments; i++) {
-                               ArraySegment<byte> segment = buffers[i];
+                                                       if (segment.Offset < 0 || segment.Count < 0 || segment.Count > segment.Array.Length - segment.Offset)
+                                                               throw new ArgumentOutOfRangeException ("segment");
 
-                               if (segment.Offset < 0 || segment.Count < 0 || segment.Count > segment.Array.Length - segment.Offset)
-                                       throw new ArgumentOutOfRangeException ("segment");
+                                                       try {} finally {
+                                                               gch[i] = GCHandle.Alloc (segment.Array, GCHandleType.Pinned);
+                                                       }
 
-                               gch[i] = GCHandle.Alloc (segment.Array, GCHandleType.Pinned);
-                               bufarray[i].len = segment.Count;
-                               bufarray[i].buf = Marshal.UnsafeAddrOfPinnedArrayElement (segment.Array, segment.Offset);
-                       }
+                                                       bufarray[i].len = segment.Count;
+                                                       bufarray[i].buf = Marshal.UnsafeAddrOfPinnedArrayElement (segment.Array, segment.Offset);
+                                               }
 
-                       try {
-                               ret = Send_internal (m_Handle, bufarray, socketFlags, out nativeError, is_blocking);
-                       } finally {
-                               for(int i = 0; i < numsegments; i++) {
-                                       if (gch[i].IsAllocated) {
-                                               gch[i].Free ();
+                                               ret = Send_internal (m_Handle, bufarray, numsegments, socketFlags, out nativeError, is_blocking);
                                        }
                                }
+                       } finally {
+                               for (int i = 0; i < numsegments; i++) {
+                                       if (gch[i].IsAllocated)
+                                               gch[i].Free();
+                               }
                        }
 
                        errorCode = (SocketError)nativeError;
@@ -1890,7 +1914,11 @@ m_Handle, buffer, offset + sent, size - sent, socketFlags, out nativeError, is_b
                        int total = 0;
 
                        try {
-                               total = Socket.Send_internal (sockares.socket.m_Handle, sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, out sockares.error, false);
+                               unsafe {
+                                       fixed (byte *pbuffer = sockares.Buffer) {
+                                               total = Socket.Send_internal (sockares.socket.m_Handle, &pbuffer[sockares.Offset], sockares.Size, sockares.SockFlags, out sockares.error, false);
+                                       }
+                               }
                        } catch (Exception e) {
                                sockares.Complete (e);
                                return;
@@ -1978,31 +2006,31 @@ m_Handle, buffer, offset + sent, size - sent, socketFlags, out nativeError, is_b
                        return sockares.Total;
                }
 
-               static int Send_internal (SafeSocketHandle safeHandle, WSABUF[] bufarray, SocketFlags flags, out int error, bool blocking)
+               static unsafe int Send_internal (SafeSocketHandle safeHandle, WSABUF* bufarray, int count, SocketFlags flags, out int error, bool blocking)
                {
                        try {
                                safeHandle.RegisterForBlockingSyscall ();
-                               return Send_internal (safeHandle.DangerousGetHandle (), bufarray, flags, out error, blocking);
+                               return Send_internal (safeHandle.DangerousGetHandle (), bufarray, count, flags, out error, blocking);
                        } finally {
                                safeHandle.UnRegisterForBlockingSyscall ();
                        }
                }
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               extern static int Send_internal (IntPtr sock, WSABUF[] bufarray, SocketFlags flags, out int error, bool blocking);
+               extern static unsafe int Send_internal (IntPtr sock, WSABUF* bufarray, int count, SocketFlags flags, out int error, bool blocking);
 
-               static int Send_internal (SafeSocketHandle safeHandle, byte[] buf, int offset, int count, SocketFlags flags, out int error, bool blocking)
+               static unsafe int Send_internal (SafeSocketHandle safeHandle, byte* buffer, int count, SocketFlags flags, out int error, bool blocking)
                {
                        try {
                                safeHandle.RegisterForBlockingSyscall ();
-                               return Send_internal (safeHandle.DangerousGetHandle (), buf, offset, count, flags, out error, blocking);
+                               return Send_internal (safeHandle.DangerousGetHandle (), buffer, count, flags, out error, blocking);
                        } finally {
                                safeHandle.UnRegisterForBlockingSyscall ();
                        }
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern static int Send_internal(IntPtr sock, byte[] buf, int offset, int count, SocketFlags flags, out int error, bool blocking);
+               extern static unsafe int Send_internal(IntPtr sock, byte* buffer, int count, SocketFlags flags, out int error, bool blocking);
 
 #endregion
 
@@ -2018,7 +2046,12 @@ m_Handle, buffer, offset + sent, size - sent, socketFlags, out nativeError, is_b
                                throw new ArgumentNullException("remoteEP");
 
                        int error;
-                       int ret = SendTo_internal (m_Handle, buffer, offset, size, socketFlags, remoteEP.Serialize (), out error, is_blocking);
+                       int ret;
+                       unsafe {
+                               fixed (byte *pbuffer = buffer) {
+                                       ret = SendTo_internal (m_Handle, &pbuffer[offset], size, socketFlags, remoteEP.Serialize (), out error, is_blocking);
+                               }
+                       }
 
                        SocketError err = (SocketError) error;
                        if (err != 0) {
@@ -2134,18 +2167,18 @@ m_Handle, buffer, offset + sent, size - sent, socketFlags, out nativeError, is_b
                        return sockares.Total;
                }
 
-               static int SendTo_internal (SafeSocketHandle safeHandle, byte[] buffer, int offset, int count, SocketFlags flags, SocketAddress sa, out int error, bool blocking)
+               static unsafe int SendTo_internal (SafeSocketHandle safeHandle, byte* buffer, int count, SocketFlags flags, SocketAddress sa, out int error, bool blocking)
                {
                        try {
                                safeHandle.RegisterForBlockingSyscall ();
-                               return SendTo_internal (safeHandle.DangerousGetHandle (), buffer, offset, count, flags, sa, out error, blocking);
+                               return SendTo_internal (safeHandle.DangerousGetHandle (), buffer, count, flags, sa, out error, blocking);
                        } finally {
                                safeHandle.UnRegisterForBlockingSyscall ();
                        }
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern static int SendTo_internal (IntPtr sock, byte[] buffer, int offset, int count, SocketFlags flags, SocketAddress sa, out int error, bool blocking);
+               extern static unsafe int SendTo_internal (IntPtr sock, byte* buffer, int count, SocketFlags flags, SocketAddress sa, out int error, bool blocking);
 
 #endregion
 
index 9a24b95e1b1642201544691b3af094e39acc17af..5925388413a4c49a8efbbb9481ea70e1be8af759 100755 (executable)
@@ -30,9 +30,7 @@ namespace MonoTests.System.Net.Sockets
        [TestFixture]
        public class SocketTest
        {
-               // note: also used in SocketCas tests
                public const string BogusAddress = "192.168.244.244";
-               public const int BogusPort = 23483;
 
                [Test]
 #if FEATURE_NO_BSD_SOCKETS
@@ -94,7 +92,7 @@ namespace MonoTests.System.Net.Sockets
                public void BogusEndConnect ()
                {
                        IPAddress ipOne = IPAddress.Parse (BogusAddress);
-                       IPEndPoint ipEP = new IPEndPoint (ipOne, BogusPort);
+                       IPEndPoint ipEP = new IPEndPoint (ipOne, NetworkHelpers.FindFreePort ());
                        Socket sock = new Socket (ipEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                        IAsyncResult ar = sock.BeginConnect (ipEP, null, null);
 
@@ -501,8 +499,7 @@ namespace MonoTests.System.Net.Sockets
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
-                       IPEndPoint ep = new IPEndPoint (IPAddress.Loopback,
-                                                       BogusPort);
+                       IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
                        
                        SocketError_event.Reset ();
 
@@ -745,8 +742,7 @@ namespace MonoTests.System.Net.Sockets
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
-                       IPEndPoint ep = new IPEndPoint (IPAddress.Loopback,
-                                                       BogusPort);
+                       IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
                        
                        Assert.AreEqual (false, sock.IsBound, "IsBoundTcp #1");
                        
@@ -780,8 +776,7 @@ namespace MonoTests.System.Net.Sockets
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Dgram,
                                                  ProtocolType.Udp);
-                       IPEndPoint ep = new IPEndPoint (IPAddress.Loopback,
-                                                       BogusPort);
+                       IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
                        
                        Assert.AreEqual (false, sock.IsBound, "IsBoundUdp #1");
                        
@@ -1739,13 +1734,14 @@ namespace MonoTests.System.Net.Sockets
                [Test]
                public void BeginConnectAddressPortNull ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
                        IPAddress ip = null;
 
                        try {
-                               sock.BeginConnect (ip, 1244, BCCallback,
+                               sock.BeginConnect (ip, port, BCCallback,
                                                   sock);
                                Assert.Fail ("BeginConnectAddressPortNull #1");
                        } catch (ArgumentNullException) {
@@ -1782,6 +1778,7 @@ namespace MonoTests.System.Net.Sockets
                [ExpectedException (typeof(ObjectDisposedException))]
                public void BeginConnectAddressPortClosed ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
@@ -1789,7 +1786,7 @@ namespace MonoTests.System.Net.Sockets
                        
                        sock.Close ();
                        
-                       sock.BeginConnect (ip, 1244, BCCallback, sock);
+                       sock.BeginConnect (ip, port, BCCallback, sock);
                }
                
                [Test]
@@ -1911,13 +1908,14 @@ namespace MonoTests.System.Net.Sockets
                [Test]
                public void BeginConnectMultipleNull ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
                        IPAddress[] ips = null;
                        
                        try {
-                               sock.BeginConnect (ips, 1246, BCCallback,
+                               sock.BeginConnect (ips, port, BCCallback,
                                                   sock);
                                Assert.Fail ("BeginConnectMultipleNull #1");
                        } catch (ArgumentNullException) {
@@ -1961,6 +1959,7 @@ namespace MonoTests.System.Net.Sockets
                [ExpectedException (typeof(ObjectDisposedException))]
                public void BeginConnectMultipleClosed ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
@@ -1973,7 +1972,7 @@ namespace MonoTests.System.Net.Sockets
                        
                        sock.Close ();
                        
-                       sock.BeginConnect (ips, 1247, BCCallback, sock);
+                       sock.BeginConnect (ips, port, BCCallback, sock);
                }
                
                [Test]
@@ -2248,13 +2247,14 @@ namespace MonoTests.System.Net.Sockets
                [Test]
                public void ConnectAddressPortNull ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
                        IPAddress ip = null;
 
                        try {
-                               sock.Connect (ip, 1249);
+                               sock.Connect (ip, port);
                                Assert.Fail ("ConnectAddressPortNull #1");
                        } catch (ArgumentNullException) {
                        } finally {
@@ -2290,6 +2290,7 @@ namespace MonoTests.System.Net.Sockets
                [ExpectedException (typeof(ObjectDisposedException))]
                public void ConnectAddressPortClosed ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
@@ -2297,7 +2298,7 @@ namespace MonoTests.System.Net.Sockets
                        
                        sock.Close ();
                        
-                       sock.Connect (ip, 1250);
+                       sock.Connect (ip, port);
                }
                
                [Test]
@@ -2397,13 +2398,14 @@ namespace MonoTests.System.Net.Sockets
                [Test]
                public void ConnectMultipleNull ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
                        IPAddress[] ips = null;
                        
                        try {
-                               sock.Connect (ips, 1251);
+                               sock.Connect (ips, port);
                                Assert.Fail ("ConnectMultipleNull #1");
                        } catch (ArgumentNullException) {
                        } finally {
@@ -2445,6 +2447,7 @@ namespace MonoTests.System.Net.Sockets
                [ExpectedException (typeof(ObjectDisposedException))]
                public void ConnectMultipleClosed ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        Socket sock = new Socket (AddressFamily.InterNetwork,
                                                  SocketType.Stream,
                                                  ProtocolType.Tcp);
@@ -2457,7 +2460,7 @@ namespace MonoTests.System.Net.Sockets
                        
                        sock.Close ();
                        
-                       sock.Connect (ips, 1252);
+                       sock.Connect (ips, port);
                }
                
                [Test]
@@ -4301,7 +4304,7 @@ namespace MonoTests.System.Net.Sockets
                                IPv6MulticastOption option = new IPv6MulticastOption (
                                        IPAddress.Parse ("ff02::1"));
 
-                               s.Bind (new IPEndPoint (IPAddress.IPv6Any, 1902));
+                               s.Bind (new IPEndPoint (IPAddress.IPv6Any, 0));
                                s.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.AddMembership,
                                        option);
                                s.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.DropMembership,
@@ -4551,6 +4554,7 @@ namespace MonoTests.System.Net.Sockets
 #if FEATURE_NO_BSD_SOCKETS
                [ExpectedException (typeof (PlatformNotSupportedException))]
 #endif
+               [Ignore ("https://bugzilla.xamarin.com/show_bug.cgi?id=43172")]
                public void SendAsyncFile ()
                {
                        Socket serverSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
index cefe3bebc599a27a06a3892d3687a73a797be5bc..d827ae4de367cc074666e49c3a182b7ad4148c52 100644 (file)
@@ -155,7 +155,7 @@ namespace MonoTests.System.Net.Sockets
                        TcpClient client = new TcpClient ();
                        IPAddress[] ipAddresses = null;
                        
-                       client.Connect (ipAddresses, 1234);
+                       client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
                }
                
                [Test]
@@ -170,7 +170,7 @@ namespace MonoTests.System.Net.Sockets
                        ipAddresses[0] = IPAddress.Any;
                        
                        try {
-                               client.Connect (ipAddresses, 1234);
+                               client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
                                Assert.Fail ("ConnectMultiAny #1");
                        } catch (SocketException ex) {
                                Assert.AreEqual (10049, ex.ErrorCode, "ConnectMultiAny #2");
@@ -191,7 +191,7 @@ namespace MonoTests.System.Net.Sockets
                        ipAddresses[0] = IPAddress.Loopback;
                        
                        try {
-                               client.Connect (ipAddresses, 1234);
+                               client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
                                Assert.Fail ("ConnectMultiRefused #1");
                        } catch (SocketException ex) {
                                Assert.AreEqual (10061, ex.ErrorCode, "ConnectMultiRefused #2");
index 29ab8ef2ca64a8e4e4ff91f9acbd9959f3804e5a..1d2373b62158a1db5ec1ed67b4a5c9b5c5e87360 100644 (file)
@@ -13,6 +13,8 @@ using System.Threading.Tasks;
 
 using NUnit.Framework;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.System.Net.Sockets {
        [TestFixture]
        public class UdpClientTest {
@@ -212,7 +214,7 @@ namespace MonoTests.System.Net.Sockets {
                        IPEndPoint localEP;
                        IPEndPoint clientEP;
 
-                       clientEP = new IPEndPoint (IPAddress.Loopback, 8001);
+                       clientEP = new IPEndPoint (IPAddress.Loopback, NetworkHelpers.FindFreePort ());
                        using (MyUdpClient client = new MyUdpClient (clientEP))
                        {
                                s = client.Client;
@@ -381,9 +383,7 @@ namespace MonoTests.System.Net.Sockets {
                        Socket s;
                        IPEndPoint localEP;
 
-                       // Bug #5503
-                       // UDP port 0 doesn't seem to be valid.
-                       using (MyUdpClient client = new MyUdpClient ("127.0.0.1", 53))
+                       using (MyUdpClient client = new MyUdpClient ("127.0.0.1", NetworkHelpers.FindFreePort ()))
                        {
                                s = client.Client;
                                Assert.IsNotNull (s, "#A:Client");
@@ -481,7 +481,7 @@ namespace MonoTests.System.Net.Sockets {
                        byte[] bytes = new byte[] {10, 11, 12, 13};
 
                        try {
-                               client.Send (bytes, bytes.Length, new IPEndPoint (IPAddress.Broadcast, 1235));
+                               client.Send (bytes, bytes.Length, new IPEndPoint (IPAddress.Broadcast, NetworkHelpers.FindFreePort ()));
                        } finally {
                                client.Close ();
                        }
@@ -495,7 +495,7 @@ namespace MonoTests.System.Net.Sockets {
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) {
                                client.JoinMulticastGroup (mcast_addr);
                        }
                }
@@ -511,7 +511,7 @@ namespace MonoTests.System.Net.Sockets {
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) {
                                client.JoinMulticastGroup (mcast_addr);
                        }
                }
@@ -522,7 +522,7 @@ namespace MonoTests.System.Net.Sockets {
 #endif
                public void JoinMulticastGroup1_MulticastAddr_Null ()
                {
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) {
                                try {
                                        client.JoinMulticastGroup ((IPAddress) null);
                                        Assert.Fail ("#1");
@@ -543,7 +543,7 @@ namespace MonoTests.System.Net.Sockets {
                {
                        IPAddress mcast_addr = null;
 
-                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234));
+                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0));
                        client.Close ();
                        try {
                                client.JoinMulticastGroup (mcast_addr);
@@ -578,7 +578,7 @@ namespace MonoTests.System.Net.Sockets {
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) {
                                try {
                                        client.JoinMulticastGroup (0, mcast_addr);
                                        Assert.Fail ("#1");
@@ -606,7 +606,7 @@ namespace MonoTests.System.Net.Sockets {
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) {
                                client.JoinMulticastGroup (0, mcast_addr);
                        }
                }
@@ -617,7 +617,7 @@ namespace MonoTests.System.Net.Sockets {
 #endif
                public void JoinMulticastGroup2_MulticastAddr_Null ()
                {
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) {
                                try {
                                        client.JoinMulticastGroup (0, (IPAddress) null);
                                        Assert.Fail ("#1");
@@ -641,7 +641,7 @@ namespace MonoTests.System.Net.Sockets {
 
                        IPAddress mcast_addr = null;
 
-                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234));
+                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0));
                        client.Close ();
                        try {
                                client.JoinMulticastGroup (0, mcast_addr);
@@ -676,11 +676,11 @@ namespace MonoTests.System.Net.Sockets {
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) {
                                client.JoinMulticastGroup (mcast_addr, 0);
                        }
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) {
                                client.JoinMulticastGroup (mcast_addr, 255);
                        }
                }
@@ -696,11 +696,11 @@ namespace MonoTests.System.Net.Sockets {
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) {
                                client.JoinMulticastGroup (mcast_addr, 0);
                        }
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) {
                                client.JoinMulticastGroup (mcast_addr, 255);
                        }
                }
@@ -711,7 +711,7 @@ namespace MonoTests.System.Net.Sockets {
 #endif
                public void JoinMulticastGroup3_MulticastAddr_Null ()
                {
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) {
                                try {
                                        client.JoinMulticastGroup ((IPAddress) null, int.MaxValue);
                                        Assert.Fail ("#1");
@@ -732,7 +732,7 @@ namespace MonoTests.System.Net.Sockets {
                {
                        IPAddress mcast_addr = null;
 
-                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234));
+                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0));
                        client.Close ();
                        try {
                                client.JoinMulticastGroup (mcast_addr, 0);
@@ -768,7 +768,7 @@ namespace MonoTests.System.Net.Sockets {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
                        IPAddress local_addr = IPAddress.Any;
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0))) {
                                client.JoinMulticastGroup (mcast_addr, local_addr);
                        }
                }
@@ -785,7 +785,7 @@ namespace MonoTests.System.Net.Sockets {
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
                        IPAddress local_addr = IPAddress.IPv6Any;
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 0))) {
                                try {
                                        client.JoinMulticastGroup (mcast_addr, local_addr);
                                        Assert.Fail ("#1");
@@ -810,7 +810,7 @@ namespace MonoTests.System.Net.Sockets {
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
 
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) {
                                try {
                                        client.JoinMulticastGroup (mcast_addr, (IPAddress) null);
                                        Assert.Fail ("#1");
@@ -829,7 +829,7 @@ namespace MonoTests.System.Net.Sockets {
 #endif
                public void JoinMulticastGroup4_MulticastAddr_Null ()
                {
-                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
+                       using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 0))) {
                                try {
                                        client.JoinMulticastGroup ((IPAddress) null, IPAddress.Loopback);
                                        Assert.Fail ("#1");
@@ -851,7 +851,7 @@ namespace MonoTests.System.Net.Sockets {
                        IPAddress mcast_addr = null;
                        IPAddress local_addr = null;
 
-                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 1234));
+                       UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Any, 0));
                        client.Close ();
                        try {
                                client.JoinMulticastGroup (mcast_addr, local_addr);
@@ -885,18 +885,7 @@ namespace MonoTests.System.Net.Sockets {
 #endif
                public void CloseInReceive ()
                {
-                       UdpClient client = null;
-                       var rnd = new Random ();
-                       for (int i = 0, max = 5; i < max; i++) {
-                               int port = rnd.Next (1025, 65534);
-                               try {
-                                       client = new UdpClient (port);
-                                       break;
-                               } catch (Exception) {
-                                       if (i == max - 1)
-                                               throw;
-                               }
-                       }
+                       UdpClient client = new UdpClient (NetworkHelpers.FindFreePort ());
 
                        ManualResetEvent ready = new ManualResetEvent (false);
                        bool got_exc = false;
@@ -928,7 +917,7 @@ namespace MonoTests.System.Net.Sockets {
 #endif
                public void JoinMulticastGroupWithLocal ()
                {
-                       UdpClient client = new UdpClient (9001);
+                       UdpClient client = new UdpClient (0);
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.24");
                        IPAddress local_addr = IPAddress.Any;
 
@@ -995,7 +984,7 @@ namespace MonoTests.System.Net.Sockets {
                        IPEndPoint ep = null;
                        foreach (IPAddress a in addresses) {
                                if (a.AddressFamily == AddressFamily.InterNetwork) {
-                                       ep = new IPEndPoint (a, 1236);
+                                       ep = new IPEndPoint (a, NetworkHelpers.FindFreePort ());
                                        break;
                                }
                        }
@@ -1035,13 +1024,14 @@ namespace MonoTests.System.Net.Sockets {
 #endif
                public void BeginReceive ()
                {
-                       UdpClient client = new UdpClient (1237);
+                       var port = NetworkHelpers.FindFreePort ();
+                       UdpClient client = new UdpClient (port);
                        
                        BRCalledBack.Reset ();
                        
                        client.BeginReceive (BRCallback, client);
 
-                       IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 1237);
+                       IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, port);
                        byte[] send_bytes = new byte[] {10, 11, 12, 13};
                        client.Send (send_bytes, send_bytes.Length, ep);
 
@@ -1063,8 +1053,9 @@ namespace MonoTests.System.Net.Sockets {
 #endif
                public void Available ()
                {
-                       using (UdpClient client = new UdpClient (1238)) {
-                               IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 1238);
+                       var port = NetworkHelpers.FindFreePort ();
+                       using (UdpClient client = new UdpClient (port)) {
+                               IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, port);
                                byte[] bytes = new byte[] {10, 11, 12, 13};
                                
                                int res = client.Send (bytes, bytes.Length, ep);
@@ -1129,7 +1120,7 @@ namespace MonoTests.System.Net.Sockets {
                [Category ("NotWorking")] // Not supported on Linux
                public void ExclusiveAddressUseBound ()
                {
-                       UdpClient client = new UdpClient (1239);
+                       UdpClient client = new UdpClient (0);
 
                        client.ExclusiveAddressUse = true;
 
@@ -1158,12 +1149,13 @@ namespace MonoTests.System.Net.Sockets {
                        if (!Socket.OSSupportsIPv6)
                                Assert.Ignore ("IPv6 not enabled.");
 
-                       int PORT = 9997;
-                       using(var udpClient = new UdpClient (PORT, AddressFamily.InterNetworkV6))
-                       using(var udpClient2 = new UdpClient (PORT+1, AddressFamily.InterNetworkV6))
+                       int port1 = NetworkHelpers.FindFreePort ();
+                       int port2 = NetworkHelpers.FindFreePort ();
+                       using(var udpClient = new UdpClient (port1, AddressFamily.InterNetworkV6))
+                       using(var udpClient2 = new UdpClient (port2, AddressFamily.InterNetworkV6))
                        {
                                var dataSent = new byte [] {1,2,3};
-                               udpClient2.SendAsync (dataSent, dataSent.Length, "::1", PORT);
+                               udpClient2.SendAsync (dataSent, dataSent.Length, "::1", port1);
 
                                IPEndPoint endPoint = new IPEndPoint (IPAddress.IPv6Any, 0);
                                var data = udpClient.Receive (ref endPoint);
index b09a8180eafd6593fa30a07a9878138a93727de6..20763df580258234f11c7b5f04b0c6262fcf4626 100644 (file)
@@ -31,6 +31,8 @@ using System.Net;
 using NUnit.Framework;
 using HLPC=System.Net.HttpListenerPrefixCollection;
 
+using MonoTests.Helpers;
+
 namespace MonoTests.System.Net {
        [TestFixture]
        public class HttpListenerPrefixCollectionTest {
@@ -68,10 +70,11 @@ namespace MonoTests.System.Net {
 #endif
                public void AddOne ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        HttpListener listener = new HttpListener ();
                        HLPC coll = listener.Prefixes;
                        listener.Start ();
-                       coll.Add ("http://127.0.0.1:8181/");
+                       coll.Add ($"http://127.0.0.1:{port}/");
                        Assert.AreEqual (1, coll.Count, "Count");
                        Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
                        Assert.IsFalse (coll.IsSynchronized, "IsSynchronized");
@@ -84,10 +87,11 @@ namespace MonoTests.System.Net {
 #endif
                public void Duplicate ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        HttpListener listener = new HttpListener ();
                        HLPC coll = listener.Prefixes;
-                       coll.Add ("http://127.0.0.1:8181/");
-                       coll.Add ("http://127.0.0.1:8181/");
+                       coll.Add ($"http://127.0.0.1:{port}/");
+                       coll.Add ($"http://127.0.0.1:{port}/");
                        listener.Start ();
                        Assert.AreEqual (1, coll.Count, "Count");
                        Assert.IsFalse (coll.IsReadOnly, "IsReadOnly");
diff --git a/mcs/class/corlib/Test/System.Runtime.Remoting/RemotingServicesTest.cs b/mcs/class/corlib/Test/System.Runtime.Remoting/RemotingServicesTest.cs
deleted file mode 100644 (file)
index 8582663..0000000
+++ /dev/null
@@ -1,529 +0,0 @@
-//
-// System.Runtime.Remoting.RemotingServices NUnit V2.0 test class
-//
-// Author Jean-Marc ANDRE (jean-marc.andre@polymtl.ca)
-//
-// ToDo: I didn't write test functions for the method not yep
-// implemented by Mono
-
-using System;
-using System.Collections;
-using NUnit.Framework;
-using System.Reflection;
-using System.Runtime.Remoting;
-using System.Threading;
-using System.Runtime.Remoting.Activation;
-using System.Runtime.Remoting.Messaging;
-using System.Runtime.Remoting.Proxies;
-using System.Runtime.Remoting.Channels;
-using System.Runtime.Remoting.Channels.Tcp;
-
-namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal
-{
-       // We need our own proxy to intercept messages to remote object
-       // and forward them using RemotingServices.ExecuteMessage
-       public class MyProxy: RealProxy
-       {
-               MarshalByRefObject target;
-               IMessageSink _sink;
-               MethodBase _mthBase;
-               bool methodOverloaded = false;
-               
-               public MethodBase MthBase
-               {
-                       get{ return _mthBase;}
-               }
-               
-               public bool IsMethodOverloaded
-               {
-                       get{return methodOverloaded;}
-               }
-               
-               public MyProxy(Type serverType, MarshalByRefObject target): base(serverType)
-               {
-                       this.target = target;
-                       
-                       IChannel[] registeredChannels = ChannelServices.RegisteredChannels;
-                       string ObjectURI;
-                       
-                       // A new IMessageSink chain has to be created
-                       // since the RemotingServices.GetEnvoyChainForProxy() is not yet
-                       // implemented.
-                       foreach(IChannel channel in registeredChannels)
-                       {
-                               IChannelSender channelSender = channel as IChannelSender;
-                               if(channelSender != null)
-                               {
-                                       _sink = (IMessageSink) channelSender.CreateMessageSink(RemotingServices.GetObjectUri(target), null, out ObjectURI);
-                               }
-                       }
-                       
-               }
-               
-               // Messages will be intercepted here and redirected
-               // to another object.
-               public override IMessage Invoke(IMessage msg)
-               {
-                       if(msg is IConstructionCallMessage)
-                       {
-                               IActivator remActivator = (IActivator) RemotingServices.Connect(typeof(IActivator), "tcp://localhost:1234/RemoteActivationService.rem");
-                               IConstructionReturnMessage crm = remActivator.Activate((IConstructionCallMessage)msg);
-                               return crm;
-                       }
-                       else
-                       {
-                               methodOverloaded = RemotingServices.IsMethodOverloaded((IMethodMessage)msg);
-                               
-                               _mthBase = RemotingServices.GetMethodBaseFromMethodMessage((IMethodMessage)msg);
-                               MethodCallMessageWrapper mcm = new MethodCallMessageWrapper((IMethodCallMessage) msg);
-                               mcm.Uri = RemotingServices.GetObjectUri((MarshalByRefObject)target);
-                               MarshalByRefObject objRem = (MarshalByRefObject)Activator.CreateInstance(GetProxiedType());
-                               RemotingServices.ExecuteMessage((MarshalByRefObject)objRem, (IMethodCallMessage)msg);
-                               IMessage rtnMsg = null;
-                               
-                               try
-                               {
-                                       rtnMsg = _sink.SyncProcessMessage(msg);
-                               }
-                               catch(Exception e)
-                               {
-                                       Console.WriteLine(e.Message);
-                               }
-                               
-                               return rtnMsg;
-                       }
-               }
-       } // end MyProxy
-       
-       // This class is used to create "CAO"
-       public class MarshalObjectFactory: MarshalByRefObject
-       {
-               public MarshalObject GetNewMarshalObject()
-               {
-                       return new MarshalObject();
-               }
-       }
-       
-       // A class used by the tests
-       public class MarshalObject: ContextBoundObject
-       {
-               public MarshalObject()
-               {
-                       
-               }
-               
-               public MarshalObject(int id, string uri)
-               {
-                       this.id = id;
-                       this.uri = uri;
-               }
-               public int Id
-               {
-                       get{return id;}
-                       set{id = value;}
-               }
-               public string Uri
-               {
-                       get{return uri;}
-               }
-               
-               public void Method1()
-               {
-                       _called++;
-                       methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());                        
-               }
-               
-               public void Method2()
-               {
-                       methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());                        
-               }
-               
-               public void Method2(int i)
-               {
-                       methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());                        
-                       
-               }
-               
-               [OneWay()]
-               public void Method3()
-               {
-                       methodOneWay = RemotingServices.IsOneWay(MethodBase.GetCurrentMethod());                        
-                       
-               }
-               
-               public static int Called
-               {
-                       get{return _called;}
-               }
-               
-               public static bool IsMethodOneWay
-               {
-                       get{return methodOneWay;}
-               }
-               
-               
-               private static int _called;
-               private int id = 0;
-               private string uri;
-               private static bool methodOneWay = false;
-       }
-       
-       // Another class used by the tests
-       public class DerivedMarshalObject: MarshalObject
-       {
-               public DerivedMarshalObject(){}
-               
-               public DerivedMarshalObject(int id, string uri): base(id, uri) {}
-       }
-} // namespace MonoTests.System.Runtime.Remoting.RemotingServicesInternal
-
-namespace MonoTests.System.Runtime.Remoting
-{
-       using MonoTests.System.Runtime.Remoting.RemotingServicesInternal;
-       
-       // The main test class
-       [TestFixture]
-       public class RemotingServicesTest 
-       {
-               private static int MarshalObjectId = 0;
-                       
-               public RemotingServicesTest()
-               {
-                       MarshalObjectId = 0;
-               }
-               
-               // Helper function that create a new
-               // MarshalObject with an unique ID
-               private static MarshalObject NewMarshalObject()
-               {
-                       string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject" + MarshalObjectId.ToString();
-                       MarshalObject objMarshal = new MarshalObject(MarshalObjectId, uri);
-                       
-                       MarshalObjectId++;
-                       
-                       return objMarshal;
-               }
-               
-               // Another helper function
-               private DerivedMarshalObject NewDerivedMarshalObject()
-               {
-                       string uri = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.DerivedMarshalObject" + MarshalObjectId.ToString();
-                       DerivedMarshalObject objMarshal = new DerivedMarshalObject(MarshalObjectId, uri);
-                       
-                       MarshalObjectId++;
-                       
-                       return objMarshal;
-               }
-               
-               // The two folling method test RemotingServices.Marshal()
-               [Test]
-               public void Marshal1()
-               {
-                       
-                       MarshalObject objMarshal = NewMarshalObject();
-                       ObjRef objRef = RemotingServices.Marshal(objMarshal);
-                       
-                       Assert.IsTrue(objRef.URI != null, "#A01");
-                       
-                       MarshalObject objRem = (MarshalObject) RemotingServices.Unmarshal(objRef);
-                       Assert.AreEqual(objMarshal.Id, objRem.Id, "#A02");
-                       
-                       objRem.Id = 2;
-                       Assert.AreEqual(objMarshal.Id, objRem.Id, "#A03");
-                       
-                       // TODO: uncomment when RemotingServices.Disconnect is implemented
-                       //RemotingServices.Disconnect(objMarshal);
-                       
-                       objMarshal = NewMarshalObject();
-                       
-                       objRef = RemotingServices.Marshal(objMarshal, objMarshal.Uri);
-                       
-                       Assert.IsTrue(objRef.URI.EndsWith(objMarshal.Uri), "#A04");
-                       // TODO: uncomment when RemotingServices.Disconnect is implemented
-                       //RemotingServices.Disconnect(objMarshal);              
-               }
-               
-               [Test]
-               public void Marshal2()
-               {
-                       DerivedMarshalObject derivedObjMarshal = NewDerivedMarshalObject();
-                       
-                       ObjRef objRef = RemotingServices.Marshal(derivedObjMarshal, derivedObjMarshal.Uri, typeof(MarshalObject));
-                       
-                       // Check that the type of the marshaled object is MarshalObject
-                       Assert.IsTrue(objRef.TypeInfo.TypeName.StartsWith((typeof(MarshalObject)).ToString()), "#A05");
-                       
-                       // TODO: uncomment when RemotingServices.Disconnect is implemented
-                       //RemotingServices.Disconnect(derivedObjMarshal);
-               }
-               
-               // Tests RemotingServices.GetObjectUri()
-               [Test]
-               public void GetObjectUri()
-               {
-                       MarshalObject objMarshal = NewMarshalObject();
-                       
-                       Assert.IsTrue(RemotingServices.GetObjectUri(objMarshal) == null, "#A06");
-                       
-                       ObjRef objRef = RemotingServices.Marshal(objMarshal);
-                       
-                       Assert.IsTrue(RemotingServices.GetObjectUri(objMarshal) != null, "#A07");
-                       // TODO: uncomment when RemotingServices.Disconnect is implemented
-                       //RemotingServices.Disconnect(objMarshal);
-               }
-               
-               // Tests RemotingServices.Connect
-               [Test]
-               public void Connect()
-               {
-                       MarshalObject objMarshal = NewMarshalObject();
-                       
-                       IDictionary props = new Hashtable();
-                       props["name"] = objMarshal.Uri;
-                       props["port"] = 1236;
-                       TcpChannel chn = new TcpChannel(props, null, null);
-                       ChannelServices.RegisterChannel(chn);
-                       
-                       RemotingServices.Marshal(objMarshal,objMarshal.Uri);
-                       
-                       MarshalObject objRem = (MarshalObject) RemotingServices.Connect(typeof(MarshalObject), "tcp://localhost:1236/" + objMarshal.Uri);
-                       
-                       Assert.IsTrue(RemotingServices.IsTransparentProxy(objRem), "#A08");
-                       
-                       ChannelServices.UnregisterChannel(chn);
-                       
-                       // TODO: uncomment when RemotingServices.Disconnect is implemented
-                       //RemotingServices.Disconnect(objMarshal);
-               }
-               
-               // Tests RemotingServices.Marshal()
-               [Test]
-               [ExpectedException(typeof(RemotingException))]  
-               public void MarshalThrowException()
-               {
-                       MarshalObject objMarshal = NewMarshalObject();
-                       
-                       IDictionary props = new Hashtable();
-                       props["name"] = objMarshal.Uri;
-                       props["port"] = 1237;
-                       TcpChannel chn = new TcpChannel(props, null, null);
-                       ChannelServices.RegisterChannel(chn);
-                       
-                       RemotingServices.Marshal(objMarshal,objMarshal.Uri);
-                       
-                       MarshalObject objRem = (MarshalObject) RemotingServices.Connect(typeof(MarshalObject), "tcp://localhost:1237/" + objMarshal.Uri);
-                       // This line sould throw a RemotingException
-                       // It is forbidden to export an object which is not
-                       // a real object
-                       try
-                       {
-                               RemotingServices.Marshal(objRem, objMarshal.Uri);
-                       }
-                       catch(Exception e)
-                       {
-                               ChannelServices.UnregisterChannel(chn);
-                       
-                       // TODO: uncomment when RemotingServices.Disconnect is implemented
-                       //RemotingServices.Disconnect(objMarshal);
-                       
-                               throw e;
-                       }               
-               }
-               
-               // Tests RemotingServices.ExecuteMessage()
-               // also tests GetMethodBaseFromMessage()
-               // IsMethodOverloaded()
-               [Test]
-               public void ExecuteMessage()
-               {
-                       TcpChannel chn = null;
-                       try
-                       {
-                               chn = new TcpChannel(1235);
-                               ChannelServices.RegisterChannel(chn);
-                               
-                               MarshalObject objMarshal = NewMarshalObject();
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall);
-                               
-                               // use a proxy to catch the Message
-                               MyProxy proxy = new MyProxy(typeof(MarshalObject), (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1235/" + objMarshal.Uri));
-                               
-                               MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy();
-                               
-                               objRem.Method1();
-                               
-                               // Tests RemotingServices.GetMethodBaseFromMethodMessage()
-                               AssertEquals("#A09","Method1",proxy.MthBase.Name);
-                               Assert.IsTrue(!proxy.IsMethodOverloaded, "#A09.1");
-                               
-                               objRem.Method2();
-                               Assert.IsTrue(proxy.IsMethodOverloaded, "#A09.2");
-                       
-                               // Tests RemotingServices.ExecuteMessage();
-                               // If ExecuteMessage does it job well, Method1 should be called 2 times
-                               Assert.AreEqual(2, MarshalObject.Called, "#A10");
-                       }
-                       finally
-                       {
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);
-                       }
-               }
-               
-               // Tests the IsOneWay method
-               [Test]
-               public void IsOneWay()
-               {
-                       TcpChannel chn = null;
-                       try
-                       {
-                               chn = new TcpChannel(1238);
-                               ChannelServices.RegisterChannel(chn);
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);
-                               
-                               MarshalObject objRem = (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1238/MarshalObject.rem");
-                               
-                               Assert.IsTrue(RemotingServices.IsTransparentProxy(objRem), "#A10.1");
-                               
-                               objRem.Method1();
-                               Thread.Sleep(20);
-                               Assert.IsTrue(!MarshalObject.IsMethodOneWay, "#A10.2");
-                               objRem.Method3();
-                               Thread.Sleep(20);
-                               Assert.IsTrue(MarshalObject.IsMethodOneWay, "#A10.2");
-                       }
-                       finally
-                       {
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);
-                       }
-               }
-               
-               [Test]
-               public void GetObjRefForProxy()
-               {
-                       TcpChannel chn = null;
-                       try
-                       {
-                               chn = new TcpChannel(1239);
-                               ChannelServices.RegisterChannel(chn);
-                               
-                               // Register le factory as a SAO
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObjectFactory), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap", WellKnownObjectMode.Singleton);
-                               
-                               MarshalObjectFactory objFactory = (MarshalObjectFactory) Activator.GetObject(typeof(MarshalObjectFactory), "tcp://localhost:1239/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");
-                               
-                               // Get a new "CAO"
-                               MarshalObject objRem = objFactory.GetNewMarshalObject();
-                               
-                               ObjRef objRefRem = RemotingServices.GetObjRefForProxy((MarshalByRefObject)objRem);
-                               
-                               Assert.IsTrue(objRefRem != null, "#A11");
-                       }
-                       finally
-                       {
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);                         
-                       }
-               }
-               
-               // Tests GetRealProxy
-               [Test]
-               public void GetRealProxy()
-               {
-                       TcpChannel chn = null;
-                       try
-                       {
-                               chn = new TcpChannel(1241);
-                               ChannelServices.RegisterChannel(chn);
-                               
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);
-                               
-                               MyProxy proxy = new  MyProxy(typeof(MarshalObject), (MarshalByRefObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1241/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));
-                               MarshalObject objRem = (MarshalObject) proxy.GetTransparentProxy();
-                               
-                               RealProxy rp = RemotingServices.GetRealProxy(objRem);
-                               
-                               Assert.IsTrue(rp != null, "#A12");
-                               Assert.AreEqual("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString(), "#A13");
-                       }
-                       finally
-                       {
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);
-                       }
-               }
-               
-               // Tests SetObjectUriForMarshal()
-               [Test]
-               public void SetObjectUriForMarshal()
-               {
-                       TcpChannel chn = null;
-                       try
-                       {
-                               chn = new TcpChannel(1242);
-                               ChannelServices.RegisterChannel(chn);
-                               
-                               MarshalObject objRem = NewMarshalObject();
-                               RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);
-                               RemotingServices.Marshal(objRem);
-                               
-                               objRem = (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1242/"+objRem.Uri);
-                               Assert.IsTrue(objRem != null, "#A14");
-                       }
-                       finally
-                       {
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);
-                       }                       
-                       
-               }
-               
-               // Tests GetServeurTypeForUri()
-               [Test]
-               public void GetServeurTypeForUri()
-               {
-                       TcpChannel chn = null;
-                       Type type = typeof(MarshalObject);
-                       try
-                       {
-                               chn = new TcpChannel(1243);
-                               ChannelServices.RegisterChannel(chn);
-                               
-                               MarshalObject objRem = NewMarshalObject();
-                               RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);
-                               RemotingServices.Marshal(objRem);
-                               
-                               Type typeRem = RemotingServices.GetServerTypeForUri(RemotingServices.GetObjectUri(objRem));
-                               Assert.AreEqual(type, typeRem, "#A15");
-                       }
-                       finally
-                       {
-                               if(chn != null) ChannelServices.UnregisterChannel(chn);
-                       }                       
-               }
-               
-               // Tests IsObjectOutOfDomain
-               // Tests IsObjectOutOfContext
-               [Test]
-               public void IsObjectOutOf()
-               {
-                       TcpChannel chn = null;
-                       try
-                       {
-                               chn = new TcpChannel(1245);
-                               ChannelServices.RegisterChannel(chn);
-                               
-                               RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);
-                               
-                               MarshalObject objRem = (MarshalObject) Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1245/MarshalObject.rem");
-                               
-                               Assert.IsTrue(RemotingServices.IsObjectOutOfAppDomain(objRem), "#A16");
-                               Assert.IsTrue(RemotingServices.IsObjectOutOfContext(objRem), "#A17");
-                               
-                               MarshalObject objMarshal = new MarshalObject();
-                               Assert.IsTrue(!RemotingServices.IsObjectOutOfAppDomain(objMarshal), "#A18");
-                               Assert.IsTrue(!RemotingServices.IsObjectOutOfContext(objMarshal), "#A19");
-                       }
-                       finally
-                       {
-                               ChannelServices.UnregisterChannel(chn);
-                       }
-               }
-       } // end class RemotingServicesTest
-} // end of namespace MonoTests.System.Runtime.Remoting.RemotingServicesTest
index 63b58916eaee510654e48dace49a84ad71c09ea4..8b08b22c32e06a7e696c0b5243627340f0b82464 100644 (file)
@@ -33,7 +33,6 @@ System.Reflection.Emit/TypeBuilderTest.cs
 System.Reflection.Emit/SaveTest.cs
 System.Runtime.Remoting/ContextTest.cs
 System.Runtime.Remoting/RemotingConfigurationTest.cs
-System.Runtime.Remoting/RemotingServicesTest.cs
 System.Runtime.Remoting/SoapServicesTest.cs
 System.Runtime.Remoting/SynchronizationAttributeTest.cs
 System.Runtime.Remoting.Channels/ChannelServicesTest.cs
index 7ebc1fc9c1512b54e5bf808c6ebde1908f659fac..9d5eb1140816690a5d1ab6c03e97b8a94935da32 100644 (file)
@@ -17,11 +17,12 @@ namespace MonoTests.Helpers {
                {
                        while (true) {
                                var ep = new IPEndPoint (IPAddress.Loopback, rndPort.Next (10000, 60000));
-                               var socket = new Socket (ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
 
                                try {
-                                       socket.Bind (ep);
-                                       socket.Close ();
+                                       using (var socket = new Socket (ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) {
+                                               socket.Bind (ep);
+                                               socket.Close ();
+                                       }
                                        return ep;
                                } catch (SocketException) { }
                        }
index af7120dce5878fc481227faf290c186e52eb5662..fc2e213bc8730dfb332386dbb5b7447eab669dac 100644 (file)
@@ -53,6 +53,7 @@ namespace Mono.ILASM {
                        private bool keycontainer = false;
                        private string keyname;
                        private StrongName sn;
+                        bool noautoinherit;
 
                         public DriverMain (string[] args)
                         {
@@ -67,7 +68,7 @@ namespace Mono.ILASM {
                                 if (output_file == null)
                                         output_file = CreateOutputFilename ();
                                 try {
-                                        codegen = new CodeGen (output_file, target == Target.Dll, debugging_info);
+                                        codegen = new CodeGen (output_file, target == Target.Dll, debugging_info, noautoinherit);
                                         foreach (string file_path in il_file_list) {
                                                 Report.FilePath = file_path;
                                                 ProcessFile (file_path);
@@ -270,6 +271,9 @@ namespace Mono.ILASM {
                                                else
                                                        keyname = command_arg;
                                                break;
+                                        case "noautoinherit":
+                                                noautoinherit = true;
+                                                break;
                                         case "scan_only":
                                                 scan_only = true;
                                                 break;
@@ -336,16 +340,17 @@ namespace Mono.ILASM {
 
                         private void Usage ()
                         {
-                                Console.WriteLine ("Mono ILasm compiler\n" +
+                                Console.WriteLine ("Mono IL assembler compiler\n" +
                                         "ilasm [options] source-files\n" +
-                                        "   --about            About the Mono ILasm compiler\n" +
-                                        "   --version          Print the version number of the Mono ILasm compiler\n" +
+                                        "   --about            About the Mono IL assembler compiler\n" +
+                                        "   --version          Print the version number of the compiler\n" +
                                         "   /output:file_name  Specifies output file.\n" +
                                         "   /exe               Compile to executable.\n" +
                                         "   /dll               Compile to library.\n" +
                                         "   /debug             Include debug information.\n" +
                                        "   /key:keyfile       Strongname using the specified key file\n" +
                                        "   /key:@container    Strongname using the specified key container\n" +
+                                        "   /noautoinherit     Disable inheriting from System.Object by default\n" +
                                         "Options can be of the form -option or /option\n");
                                 Environment.Exit (1);
                         }
@@ -361,7 +366,7 @@ namespace Mono.ILASM {
                         private void Version ()
                         {
                                 string version = System.Reflection.Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
-                                Console.WriteLine ("Mono ILasm compiler version {0}", version);
+                                Console.WriteLine ("Mono IL assembler compiler version {0}", version);
                                 Environment.Exit (0);
                         }
 
index 6b9aadfc80ecd363d6e14baea059ba95c60e5d29..1d9ebe4b1ccee3a9220bdbe91356b2f89ee19096 100644 (file)
@@ -63,14 +63,16 @@ namespace Mono.ILASM {
                 private string output_file;\r
                 private bool is_dll;\r
                 private bool entry_point;\r
+                bool noautoinherit;\r
 \r
                 private Module this_module;\r
 \r
-                public CodeGen (string output_file, bool is_dll, bool debugging_info)\r
+                public CodeGen (string output_file, bool is_dll, bool debugging_info, bool noautoinherit)\r
                 {\r
                         this.output_file = output_file;\r
                         this.is_dll = is_dll;\r
-\r
+                        this.noautoinherit = noautoinherit;\r
+                        \r
                        if (debugging_info)\r
                                symwriter = new SymbolWriter (output_file);\r
 \r
@@ -313,7 +315,7 @@ namespace Mono.ILASM {
 \r
                         typedef = new TypeDef (attr, current_namespace,\r
                                         name, parent, impl_list, location, gen_params, outer);\r
-\r
+                        typedef.NoAutoInherit = noautoinherit && parent == null;\r
                         type_manager[cache_name] = typedef;\r
                         current_customattrtarget = current_typedef = typedef;\r
                         current_declsectarget = typedef;\r
index 74200cddf49e06d741e1bfdce3d04f019c0bb672..f35dca0bd4a4216d1a8a9f7cdca45ec62799c43c 100644 (file)
@@ -93,6 +93,8 @@ namespace Mono.ILASM {
                                 this.attr |= PEAPI.TypeAttr.Abstract;
                 }
 
+                               public bool NoAutoInherit { get; set; }
+
                 public string Name {
                         get { return name; }
                 }
@@ -389,7 +391,7 @@ namespace Mono.ILASM {
                                                         name_space, name);
                                         }
                                 }
-                                if (FullName == "System.Object")
+                                if (FullName == "System.Object" || NoAutoInherit)
                                         classdef.SpecialNoSuper ();
                         }
 
index 4c2a6cfd26dc4514426999c3eab5507d3d4ee9e5..a72cd9f0060d791b234405c2fefc8ba8b80e6b9e 100644 (file)
@@ -35,7 +35,7 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="PEAPI">
-      <HintPath>..\class\lib\net_4_5\PEAPI.dll</HintPath>
+      <HintPath>..\class\lib\net_4_x\PEAPI.dll</HintPath>
     </Reference>
     <Reference Include="Mono.CompilerServices.SymbolWriter" />
     <Reference Include="Mono.Security" />
index c12eeaf978be47f106f6620198cbd223988e3ab2..b564427b568fa5956bc83bf9fee47d3c78750b79 100644 (file)
@@ -288,6 +288,7 @@ namespace Mono.ILASM {
 /* Keywords */\r
 %token K_AT\r
 %token K_AS\r
+%token K_AGGRESSIVEINLINING\r
 %token K_IMPLICITCOM\r
 %token K_IMPLICITRES\r
 %token K_NOAPPDOMAIN\r
@@ -2016,6 +2017,7 @@ impl_attr         : /* EMPTY */                   { $$ = new ImplAttr (); }
                        | impl_attr K_SYNCHRONIZED      { $$ = (ImplAttr) $1 | ImplAttr.Synchronised; }\r
                        | impl_attr K_NOINLINING        { $$ = (ImplAttr) $1 | ImplAttr.NoInLining; }\r
                        | impl_attr K_NOOPTIMIZATION    { $$ = (ImplAttr) $1 | ImplAttr.NoOptimization; }\r
+                       | impl_attr K_AGGRESSIVEINLINING{ $$ = (ImplAttr) $1 | ImplAttr.AggressiveInlining; }\r
                        ;\r
 \r
 sig_args               : /* EMPTY */\r
index fa13dd77c08bb451991546e419feb36d6031e719..9e62ebf638c5ddf57b0df1211211e09a5792a5b1 100644 (file)
@@ -321,6 +321,7 @@ namespace Mono.ILASM {
                                 keywords ["legacy"] = new ILToken (Token.K_LEGACY, "legacy");\r
                                 keywords ["library"] = new ILToken (Token.K_LIBRARY, "library");\r
                                 keywords ["auto"] = new ILToken (Token.K_AUTO, "auto");\r
+                                keywords ["aggressiveinlining"] = new ILToken (Token.K_AGGRESSIVEINLINING, "aggressiveinlining");\r
 \r
                                 return keywords;\r
                         }\r
index 97cf6c6a240c6521ec1a7d23a6a0f5f70365a443..8680e0bbf8160f8f502a3705956eb7ebc06b88cb 100755 (executable)
@@ -135,7 +135,7 @@ class MakeBundle {
                                        return 1;
                                }
                                if (sdk_path != null || runtime != null)
-                                       Error ("You can not specify one of --runtime, --sdk or --cross");
+                                       Error ("You can only specify one of --runtime, --sdk or --cross");
                                custom_mode = false;
                                autodeps = true;
                                cross_target = args [++i];
@@ -213,7 +213,7 @@ class MakeBundle {
                                autodeps = true;
                                sdk_path = args [++i];
                                if (cross_target != null || runtime != null)
-                                       Error ("You can not specify one of --runtime, --sdk or --cross");
+                                       Error ("You can only specify one of --runtime, --sdk or --cross");
                                break;
                        case "--runtime":
                                if (i+1 == top){
@@ -624,6 +624,8 @@ class MakeBundle {
                        return false;
                }
                maker.Add (code, file);
+               // add a space after code (="systemconfig:" or "machineconfig:")
+               Console.WriteLine (code + " " + file);
                return true;
        }
        
@@ -659,15 +661,17 @@ class MakeBundle {
                        Console.WriteLine ("     Assembly: " + fname);
                        if (File.Exists (fname + ".config")){
                                maker.Add ("config:" + aname, fname + ".config");
-                               Console.WriteLine ("       Config: " + runtime);
+                               Console.WriteLine ("       Config: " + fname + ".config");
                        }
                }
                
                if (!MaybeAddFile (maker, "systemconfig:", config_file) || !MaybeAddFile (maker, "machineconfig:", machine_config_file))
                        return false;
 
-               if (config_dir != null)
+               if (config_dir != null){
                        maker.Add ("config_dir:", config_dir);
+                       Console.WriteLine ("   Config_dir: " + config_dir );
+               }
                if (embedded_options != null)
                        maker.AddString ("options:", embedded_options);
                if (environment.Count > 0){
index edf8c1283791bde051589c5199693cb6ad1014ba..c581a0c277dfa37def4d2823e3f03e023aefa09a 100644 (file)
 ../../../../external/nunit-lite/NUnitLite-1.0.0/src/framework/Internal/Commands/CommandStage.cs
 ../../../../external/nunit-lite/NUnitLite-1.0.0/src/framework/Internal/Commands/DelegatingTestCommand.cs
 ../../../../external/nunit-lite/NUnitLite-1.0.0/src/framework/Internal/Commands/ExpectedExceptionCommand.cs
+../../../../external/nunit-lite/NUnitLite-1.0.0/src/framework/Internal/Commands/FlakyTestRetriesCommand.cs
 ../../../../external/nunit-lite/NUnitLite-1.0.0/src/framework/Internal/Commands/ICommandDecorator.cs
 ../../../../external/nunit-lite/NUnitLite-1.0.0/src/framework/Internal/Commands/MaxTimeCommand.cs
 ../../../../external/nunit-lite/NUnitLite-1.0.0/src/framework/Internal/Commands/OneTimeSetUpCommand.cs
index ab1fbb483bd53d995c6b86f216655563cfc2b757..c213c8823ff1d8ba2858b1b70ad78b6f4baaf79d 100644 (file)
@@ -87,6 +87,6 @@ g_mkdtemp (char *tmp_template)
 
        return mkdtemp (template_copy);
 #else
-       g_error("Function not supported");
+       g_error("Function mkdtemp not supported");
 #endif
 }
index cd2fda3c2a115f0fe3a04526d31719d90e0e8e84..e8a76e429cccd7ab887be324e7aa855ab3ef0eae 100644 (file)
 
 #include <errno.h>
 
-/*
- *  Linux knows two different versions of strerror_r () that can only be distinguished
- *  by using feature test macros.  Please check the man pages for more details.
- */
-#if defined (_POSIX_C_SOURCE) && defined (_GNU_SOURCE)
-#if (_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE
-#define USE_STRERROR_R_XSI
-#endif
-#endif
-
 /* 
  * g_strndup and g_vasprintf need to allocate memory with g_malloc if 
  * ENABLE_OVERRIDABLE_ALLOCATORS is defined so that it can be safely freed with g_free 
@@ -244,7 +234,7 @@ g_strerror (gint errnum)
                size_t buff_len = sizeof (tmp_buff);
                buff [0] = 0;
 
-#ifdef USE_STRERROR_R_XSI
+#ifndef STRERROR_R_CHAR_P
                int r;
                while ((r = strerror_r (errnum, buff, buff_len - 1))) {
                        if (r != ERANGE) {
@@ -262,11 +252,11 @@ g_strerror (gint errnum)
                        error_messages [errnum] = g_strdup (buff);
                if (buff != tmp_buff)
                        g_free (buff);
-#else /* USE_STRERROR_R_XSI */
+#else /* STRERROR_R_CHAR_P */
                buff = strerror_r (errnum, buff, buff_len);
                if (!error_messages [errnum])
                        error_messages [errnum] = g_strdup (buff);
-#endif /* USE_STRERROR_R_XSI */
+#endif /* STRERROR_R_CHAR_P */
 
 #else /* HAVE_STRERROR_R */
                if (!error_messages [errnum])
index a93f04a867d0512a93bd8aafd49c19656eea153c..33ccf0294164002e9d62603d38005b5244c1b29e 100644 (file)
@@ -36,6 +36,7 @@
 #include <mono/utils/mono-os-mutex.h>
 #include <mono/utils/mono-counters.h>
 #include <mono/utils/mono-compiler.h>
+#include <mono/utils/unlocked.h>
 
 #if HAVE_BOEHM_GC
 
@@ -482,7 +483,7 @@ on_gc_notification (GC_EventType event)
                        mono_perfcounters->gc_gen0size = heap_size;
                }
 #endif
-               InterlockedAdd64 (&gc_stats.major_gc_time, mono_100ns_ticks () - gc_start_time);
+               UnlockedAdd64 (&gc_stats.major_gc_time, mono_100ns_ticks () - gc_start_time);
                mono_trace_message (MONO_TRACE_GC, "gc took %" G_GINT64_FORMAT " usecs", (mono_100ns_ticks () - gc_start_time) / 10);
                break;
        default:
index d57cb52796be252c94d86cffbbc96db8bab7167c..b00ab355d6ecd3c9736d316c0ba167fb3890a521 100644 (file)
@@ -640,14 +640,21 @@ mono_cominterop_cleanup (void)
 }
 
 void
-mono_mb_emit_cominterop_call (MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethod* method)
+mono_mb_emit_cominterop_get_function_pointer (MonoMethodBuilder *mb, MonoMethod *method)
 {
 #ifndef DISABLE_JIT
        // get function pointer from 1st arg, the COM interface pointer
        mono_mb_emit_ldarg (mb, 0);
        mono_mb_emit_icon (mb, cominterop_get_com_slot_for_method (method));
        mono_mb_emit_icall (mb, cominterop_get_function_pointer);
+       /* Leaves the function pointer on top of the stack */
+#endif
+}
 
+void
+mono_mb_emit_cominterop_call_function_pointer (MonoMethodBuilder *mb, MonoMethodSignature *sig)
+{
+#ifndef DISABLE_JIT
        mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
        mono_mb_emit_byte (mb, CEE_MONO_SAVE_LMF);
        mono_mb_emit_calli (mb, sig);
@@ -656,6 +663,16 @@ mono_mb_emit_cominterop_call (MonoMethodBuilder *mb, MonoMethodSignature *sig, M
 #endif /* DISABLE_JIT */
 }
 
+void
+mono_mb_emit_cominterop_call (MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethod* method)
+{
+#ifndef DISABLE_JIT
+       mono_mb_emit_cominterop_get_function_pointer (mb, method);
+
+       mono_mb_emit_cominterop_call_function_pointer (mb, sig);
+#endif /* DISABLE_JIT */
+}
+
 void
 mono_cominterop_emit_ptr_to_object_conv (MonoMethodBuilder *mb, MonoType *type, MonoMarshalConv conv, MonoMarshalSpec *mspec)
 {
index 04abc6e5fab1015ee3698302894f9f4abd5ac1b1..6f93ec191dfb1dc16b9b4c6d03a815fa5a01ad1c 100644 (file)
@@ -19,6 +19,12 @@ mono_cominterop_init (void);
 void
 mono_cominterop_cleanup (void);
 
+void
+mono_mb_emit_cominterop_get_function_pointer (MonoMethodBuilder *mb, MonoMethod* method);
+
+void
+mono_mb_emit_cominterop_call_function_pointer (MonoMethodBuilder *mb, MonoMethodSignature *sig);
+
 void
 mono_mb_emit_cominterop_call (MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethod* method);
 
index ecd050a26e0469e29f4d71f42dce3c75fe5bdc7f..28615d8c1a986bb9eacb71051805387e20e365f0 100644 (file)
@@ -467,15 +467,15 @@ HANDLES(ICALL(SOCK_21, "IOControl_internal(intptr,int,byte[],byte[],int&)", ves_
 HANDLES(ICALL(SOCK_9, "Listen_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_Listen_internal))
 HANDLES(ICALL(SOCK_10, "LocalEndPoint_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_LocalEndPoint_internal))
 HANDLES(ICALL(SOCK_11, "Poll_internal", ves_icall_System_Net_Sockets_Socket_Poll_internal))
-HANDLES(ICALL(SOCK_13, "ReceiveFrom_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&,bool)", ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal))
-HANDLES(ICALL(SOCK_11a, "Receive_internal(intptr,System.Net.Sockets.Socket/WSABUF[],System.Net.Sockets.SocketFlags,int&,bool)", ves_icall_System_Net_Sockets_Socket_Receive_array_internal))
-HANDLES(ICALL(SOCK_12, "Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&,bool)", ves_icall_System_Net_Sockets_Socket_Receive_internal))
+HANDLES(ICALL(SOCK_13, "ReceiveFrom_internal(intptr,byte*,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&,int&,bool)", ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal))
+HANDLES(ICALL(SOCK_11a, "Receive_internal(intptr,System.Net.Sockets.Socket/WSABUF*,int,System.Net.Sockets.SocketFlags,int&,bool)", ves_icall_System_Net_Sockets_Socket_Receive_array_internal))
+HANDLES(ICALL(SOCK_12, "Receive_internal(intptr,byte*,int,System.Net.Sockets.SocketFlags,int&,bool)", ves_icall_System_Net_Sockets_Socket_Receive_internal))
 HANDLES(ICALL(SOCK_14, "RemoteEndPoint_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal))
 HANDLES(ICALL(SOCK_15, "Select_internal(System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal))
 HANDLES(ICALL(SOCK_15a, "SendFile_internal(intptr,string,byte[],byte[],System.Net.Sockets.TransmitFileOptions,int&,bool)", ves_icall_System_Net_Sockets_Socket_SendFile_internal))
-HANDLES(ICALL(SOCK_16, "SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&,bool)", ves_icall_System_Net_Sockets_Socket_SendTo_internal))
-HANDLES(ICALL(SOCK_16a, "Send_internal(intptr,System.Net.Sockets.Socket/WSABUF[],System.Net.Sockets.SocketFlags,int&,bool)", ves_icall_System_Net_Sockets_Socket_Send_array_internal))
-HANDLES(ICALL(SOCK_17, "Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&,bool)", ves_icall_System_Net_Sockets_Socket_Send_internal))
+HANDLES(ICALL(SOCK_16, "SendTo_internal(intptr,byte*,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&,bool)", ves_icall_System_Net_Sockets_Socket_SendTo_internal))
+HANDLES(ICALL(SOCK_16a, "Send_internal(intptr,System.Net.Sockets.Socket/WSABUF*,int,System.Net.Sockets.SocketFlags,int&,bool)", ves_icall_System_Net_Sockets_Socket_Send_array_internal))
+HANDLES(ICALL(SOCK_17, "Send_internal(intptr,byte*,int,System.Net.Sockets.SocketFlags,int&,bool)", ves_icall_System_Net_Sockets_Socket_Send_internal))
 HANDLES(ICALL(SOCK_18, "SetSocketOption_internal(intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&)", ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal))
 HANDLES(ICALL(SOCK_19, "Shutdown_internal(intptr,System.Net.Sockets.SocketShutdown,int&)", ves_icall_System_Net_Sockets_Socket_Shutdown_internal))
 HANDLES(ICALL(SOCK_20, "Socket_internal(System.Net.Sockets.AddressFamily,System.Net.Sockets.SocketType,System.Net.Sockets.ProtocolType,int&)", ves_icall_System_Net_Sockets_Socket_Socket_internal))
index 63358bf3baff17983faf525d7d4c0fe1c9d5b5b1..05b23fddf3feae116697913694a6033b94c022df 100644 (file)
@@ -375,8 +375,8 @@ mono_marshal_init (void)
                register_icall (mono_marshal_free_asany, "mono_marshal_free_asany", "void object ptr int32 int32", FALSE);
                register_icall (ves_icall_marshal_alloc, "ves_icall_marshal_alloc", "ptr ptr", FALSE);
                register_icall (mono_marshal_free, "mono_marshal_free", "void ptr", FALSE);
-               register_icall (mono_marshal_set_last_error, "mono_marshal_set_last_error", "void", FALSE);
-               register_icall (mono_marshal_set_last_error_windows, "mono_marshal_set_last_error_windows", "void int32", FALSE);
+               register_icall (mono_marshal_set_last_error, "mono_marshal_set_last_error", "void", TRUE);
+               register_icall (mono_marshal_set_last_error_windows, "mono_marshal_set_last_error_windows", "void int32", TRUE);
                register_icall (mono_string_utf8_to_builder, "mono_string_utf8_to_builder", "void ptr ptr", FALSE);
                register_icall (mono_string_utf8_to_builder2, "mono_string_utf8_to_builder2", "object ptr", FALSE);
                register_icall (mono_string_utf16_to_builder, "mono_string_utf16_to_builder", "void ptr ptr", FALSE);
@@ -7658,6 +7658,9 @@ mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, MonoM
        int i, argnum, *tmp_locals;
        int type, param_shift = 0;
        int coop_gc_stack_dummy, coop_gc_var;
+#ifndef DISABLE_COM
+       int coop_cominterop_fnptr;
+#endif
 
        memset (&m, 0, sizeof (m));
        m.mb = mb;
@@ -7700,6 +7703,11 @@ mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, MonoM
                coop_gc_stack_dummy = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
                /* local 5, the local to be used when calling the suspend funcs */
                coop_gc_var = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
+#ifndef DISABLE_COM
+               if (!func_param && MONO_CLASS_IS_IMPORT (mb->method->klass)) {
+                       coop_cominterop_fnptr = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
+               }
+#endif
        }
 
        /*
@@ -7745,6 +7753,13 @@ mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, MonoM
                        mono_mb_emit_byte (mb, CEE_POP); // Result not needed yet
                }
 
+#ifndef DISABLE_COM
+               if (!func_param && MONO_CLASS_IS_IMPORT (mb->method->klass)) {
+                       mono_mb_emit_cominterop_get_function_pointer (mb, &piinfo->method);
+                       mono_mb_emit_stloc (mb, coop_cominterop_fnptr);
+               }
+#endif
+
                mono_mb_emit_ldloc_addr (mb, coop_gc_stack_dummy);
                mono_mb_emit_icall (mb, mono_threads_enter_gc_safe_region_unbalanced);
                mono_mb_emit_stloc (mb, coop_gc_var);
@@ -7767,7 +7782,12 @@ mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, MonoM
                mono_mb_emit_calli (mb, csig);
        } else if (MONO_CLASS_IS_IMPORT (mb->method->klass)) {
 #ifndef DISABLE_COM
-               mono_mb_emit_cominterop_call (mb, csig, &piinfo->method);
+               if (!mono_threads_is_blocking_transition_enabled ()) {
+                       mono_mb_emit_cominterop_call (mb, csig, &piinfo->method);
+               } else {
+                       mono_mb_emit_ldloc (mb, coop_cominterop_fnptr);
+                       mono_mb_emit_cominterop_call_function_pointer (mb, csig);
+               }
 #else
                g_assert_not_reached ();
 #endif
@@ -10936,6 +10956,9 @@ mono_marshal_string_to_utf16_copy (MonoString *s)
 void
 mono_marshal_set_last_error (void)
 {
+       /* This icall is called just after a P/Invoke call before the P/Invoke
+        * wrapper transitions the runtime back to running mode. */
+       MONO_REQ_GC_SAFE_MODE;
 #ifdef WIN32
        mono_native_tls_set_value (last_error_tls_id, GINT_TO_POINTER (GetLastError ()));
 #else
@@ -10947,6 +10970,9 @@ static void
 mono_marshal_set_last_error_windows (int error)
 {
 #ifdef WIN32
+       /* This icall is called just after a P/Invoke call before the P/Invoke
+        * wrapper transitions the runtime back to running mode. */
+       MONO_REQ_GC_SAFE_MODE;
        mono_native_tls_set_value (last_error_tls_id, GINT_TO_POINTER (error));
 #endif
 }
index 8604d9321a0aa47e35178ebb6013b3e48fb5cd6c..7f2a233401d7da565051c04dbd08f7faf851c95d 100644 (file)
@@ -2665,6 +2665,54 @@ sgen_client_metadata_for_object (GCObject *obj)
        return mono_object_domain (obj);
 }
 
+/**
+ * mono_gchandle_new:
+ * \param obj managed object to get a handle for
+ * \param pinned whether the object should be pinned
+ * This returns a handle that wraps the object, this is used to keep a
+ * reference to a managed object from the unmanaged world and preventing the
+ * object from being disposed.
+ * 
+ * If \p pinned is false the address of the object can not be obtained, if it is
+ * true the address of the object can be obtained.  This will also pin the
+ * object so it will not be possible by a moving garbage collector to move the
+ * object. 
+ * 
+ * \returns a handle that can be used to access the object from unmanaged code.
+ */
+guint32
+mono_gchandle_new (MonoObject *obj, gboolean pinned)
+{
+       return sgen_gchandle_new (obj, pinned);
+}
+
+/**
+ * mono_gchandle_new_weakref:
+ * \param obj managed object to get a handle for
+ * \param track_resurrection Determines how long to track the object, if this is set to TRUE, the object is tracked after finalization, if FALSE, the object is only tracked up until the point of finalization.
+ *
+ * This returns a weak handle that wraps the object, this is used to
+ * keep a reference to a managed object from the unmanaged world.
+ * Unlike the \c mono_gchandle_new the object can be reclaimed by the
+ * garbage collector.  In this case the value of the GCHandle will be
+ * set to zero.
+ * 
+ * If \p track_resurrection is TRUE the object will be tracked through
+ * finalization and if the object is resurrected during the execution
+ * of the finalizer, then the returned weakref will continue to hold
+ * a reference to the object.   If \p track_resurrection is FALSE, then
+ * the weak reference's target will become NULL as soon as the object
+ * is passed on to the finalizer.
+ * 
+ * \returns a handle that can be used to access the object from
+ * unmanaged code.
+ */
+guint32
+mono_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection)
+{
+       return sgen_gchandle_new_weakref (obj, track_resurrection);
+}
+
 /**
  * mono_gchandle_is_in_domain:
  * \param gchandle a GCHandle's handle.
@@ -2678,6 +2726,20 @@ mono_gchandle_is_in_domain (guint32 gchandle, MonoDomain *domain)
        return domain->domain_id == gchandle_domain->domain_id;
 }
 
+/**
+ * mono_gchandle_free:
+ * \param gchandle a GCHandle's handle.
+ *
+ * Frees the \p gchandle handle.  If there are no outstanding
+ * references, the garbage collector can reclaim the memory of the
+ * object wrapped. 
+ */
+void
+mono_gchandle_free (guint32 gchandle)
+{
+       sgen_gchandle_free (gchandle);
+}
+
 /**
  * mono_gchandle_free_domain:
  * \param unloading domain that is unloading
@@ -2690,6 +2752,22 @@ mono_gchandle_free_domain (MonoDomain *unloading)
 {
 }
 
+/**
+ * mono_gchandle_get_target:
+ * \param gchandle a GCHandle's handle.
+ *
+ * The handle was previously created by calling \c mono_gchandle_new or
+ * \c mono_gchandle_new_weakref. 
+ *
+ * \returns a pointer to the \c MonoObject* represented by the handle or
+ * NULL for a collected object if using a weakref handle.
+ */
+MonoObject*
+mono_gchandle_get_target (guint32 gchandle)
+{
+       return sgen_gchandle_get_target (gchandle);
+}
+
 static gpointer
 null_link_if_in_domain (gpointer hidden, GCHandleType handle_type, int max_generation, gpointer user)
 {
index 65547135b3b11adacd09a7ed750c426e93d78f43..448cd8c2e5a0dbb4615fe283f8c80a904b8c0b87 100644 (file)
@@ -4256,6 +4256,7 @@ static _wapi_drive_type _wapi_drive_types[] = {
        { DRIVE_REMOTE, "ftp" },
        { DRIVE_FIXED, "hfs" },
        { DRIVE_FIXED, "apfs" },
+       { DRIVE_REMOTE, "kbfuse" },
        { DRIVE_FIXED, "msdos" },
        { DRIVE_REMOTE, "nfs" },
        { DRIVE_FIXED, "ntfs" },
index cf9fb28e466950607f2eee6c681d9ce86c009f40..62e2eb154c9c4e28c62a81e23787d7703c10f134 100644 (file)
 #define TF_DISCONNECT 0x01
 #define TF_REUSE_SOCKET 0x02
 
-typedef struct {
-       guint32 len;
-       gpointer buf;
-} WSABUF, *LPWSABUF;
-
 typedef struct {
        gpointer Head;
        guint32 HeadLength;
index 9c0053455829860be455830da6f617c57ffb73c4..43df41bfdc717181022977d5bbc39853e43bdb87 100644 (file)
@@ -1429,21 +1429,15 @@ ves_icall_System_Net_Sockets_Socket_Duplicate_internal (gpointer handle, gint32
 }
 
 gint32
-ves_icall_System_Net_Sockets_Socket_Receive_internal (gsize sock, MonoArrayHandle buffer, gint32 offset, gint32 count, gint32 flags, gint32 *werror, gboolean blocking, MonoError *error)
+ves_icall_System_Net_Sockets_Socket_Receive_internal (gsize sock, gchar *buffer, gint32 count, gint32 flags, gint32 *werror, gboolean blocking, MonoError *error)
 {
        int ret;
-       gint32 alen;
        int recvflags = 0;
        gboolean interrupted;
-       MonoInternalThread* curthread G_GNUC_UNUSED = mono_thread_internal_current ();
        
        error_init (error);
        *werror = 0;
        
-       alen = mono_array_handle_length (buffer);
-       if (offset > alen - count)
-               return 0;
-       
        recvflags = convert_socketflags (flags);
        if (recvflags == -1) {
                *werror = WSAEOPNOTSUPP;
@@ -1454,12 +1448,7 @@ ves_icall_System_Net_Sockets_Socket_Receive_internal (gsize sock, MonoArrayHandl
        if (interrupted)
                return 0;
 
-       uint32_t gchandle;
-       gchar *buf = MONO_ARRAY_HANDLE_PIN (buffer, gchar, offset, &gchandle);
-
-       ret = mono_w32socket_recv (sock, buf, count, recvflags, blocking);
-
-       mono_gchandle_free (gchandle);
+       ret = mono_w32socket_recv (sock, buffer, count, recvflags, blocking);
        
        if (ret == SOCKET_ERROR)
                *werror = mono_w32socket_get_last_error ();
@@ -1475,9 +1464,9 @@ ves_icall_System_Net_Sockets_Socket_Receive_internal (gsize sock, MonoArrayHandl
 }
 
 gint32
-ves_icall_System_Net_Sockets_Socket_Receive_array_internal (gsize sock, MonoArrayHandle buffers, gint32 flags, gint32 *werror, gboolean blocking, MonoError *error)
+ves_icall_System_Net_Sockets_Socket_Receive_array_internal (gsize sock, WSABUF *buffers, gint32 count, gint32 flags, gint32 *werror, gboolean blocking, MonoError *error)
 {
-       int ret, count;
+       int ret;
        gboolean interrupted;
        guint32 recv;
        guint32 recvflags = 0;
@@ -1485,8 +1474,6 @@ ves_icall_System_Net_Sockets_Socket_Receive_array_internal (gsize sock, MonoArra
        error_init (error);
        *werror = 0;
        
-       count = mono_array_handle_length (buffers);
-       
        recvflags = convert_socketflags (flags);
        if (recvflags == -1) {
                *werror = WSAEOPNOTSUPP;
@@ -1499,12 +1486,7 @@ ves_icall_System_Net_Sockets_Socket_Receive_array_internal (gsize sock, MonoArra
                return 0;
        }
 
-       uint32_t gchandle;
-       WSABUF *wsabufs = MONO_ARRAY_HANDLE_PIN (buffers, WSABUF, 0, &gchandle);
-
-       ret = mono_w32socket_recvbuffers (sock, wsabufs, count, &recv, &recvflags, NULL, NULL, blocking);
-
-       mono_gchandle_free (gchandle);
+       ret = mono_w32socket_recvbuffers (sock, buffers, count, &recv, &recvflags, NULL, NULL, blocking);
 
        if (ret == SOCKET_ERROR)
                *werror = mono_w32socket_get_last_error ();
@@ -1520,11 +1502,9 @@ ves_icall_System_Net_Sockets_Socket_Receive_array_internal (gsize sock, MonoArra
 }
 
 gint32
-ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal (gsize sock, MonoArrayHandle buffer, gint32 offset, gint32 count, gint32 flags, MonoObjectHandle sockaddr, gint32 *werror, gboolean blocking, MonoError *error)
+ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal (gsize sock, gchar *buffer, gint32 count, gint32 flags, MonoObjectHandle sockaddr, gint32 *werror, gboolean blocking, MonoError *error)
 {
        int ret;
-       gchar *buf;
-       gint32 alen;
        int recvflags = 0;
        struct sockaddr *sa;
        socklen_t sa_size;
@@ -1532,10 +1512,6 @@ ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal (gsize sock, MonoArrayH
        
        error_init (error);
        *werror = 0;
-       
-       alen = mono_array_handle_length (buffer);
-       if (offset > alen - count)
-               return 0;
 
        sa = create_sockaddr_from_handle (sockaddr, &sa_size, werror, error);
        if (*werror != 0)
@@ -1556,12 +1532,7 @@ ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal (gsize sock, MonoArrayH
                return 0;
        }
 
-       uint32_t gchandle;
-       buf = MONO_ARRAY_HANDLE_PIN (buffer, gchar, offset, &gchandle);
-
-       ret = mono_w32socket_recvfrom (sock, buf, count, recvflags, sa, &sa_size, blocking);
-
-       mono_gchandle_free (gchandle);
+       ret = mono_w32socket_recvfrom (sock, buffer, count, recvflags, sa, &sa_size, blocking);
 
        if (ret == SOCKET_ERROR)
                *werror = mono_w32socket_get_last_error ();
@@ -1596,22 +1567,15 @@ ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal (gsize sock, MonoArrayH
 }
 
 gint32
-ves_icall_System_Net_Sockets_Socket_Send_internal (gsize sock, MonoArrayHandle buffer, gint32 offset, gint32 count, gint32 flags, gint32 *werror, gboolean blocking, MonoError *error)
+ves_icall_System_Net_Sockets_Socket_Send_internal (gsize sock, gchar *buffer, gint32 count, gint32 flags, gint32 *werror, gboolean blocking, MonoError *error)
 {
        int ret;
-       gint32 alen;
        int sendflags = 0;
        gboolean interrupted;
        
        error_init (error);
        *werror = 0;
        
-       alen = mono_array_handle_length (buffer);
-       if (offset > alen - count)
-               return 0;
-
-       LOGDEBUG (g_message("%s: alen: %d", __func__, alen));
-       
        LOGDEBUG (g_message("%s: Sending %d bytes", __func__, count));
 
        sendflags = convert_socketflags (flags);
@@ -1626,12 +1590,7 @@ ves_icall_System_Net_Sockets_Socket_Send_internal (gsize sock, MonoArrayHandle b
                return 0;
        }
 
-       uint32_t gchandle;
-       gchar *buf = MONO_ARRAY_HANDLE_PIN (buffer, gchar, offset, &gchandle);
-
-       ret = mono_w32socket_send (sock, buf, count, sendflags, blocking);
-
-       mono_gchandle_free (gchandle);
+       ret = mono_w32socket_send (sock, buffer, count, sendflags, blocking);
 
        if (ret == SOCKET_ERROR)
                *werror = mono_w32socket_get_last_error ();
@@ -1647,9 +1606,9 @@ ves_icall_System_Net_Sockets_Socket_Send_internal (gsize sock, MonoArrayHandle b
 }
 
 gint32
-ves_icall_System_Net_Sockets_Socket_Send_array_internal (gsize sock, MonoArrayHandle buffers, gint32 flags, gint32 *werror, gboolean blocking, MonoError *error)
+ves_icall_System_Net_Sockets_Socket_Send_array_internal (gsize sock, WSABUF *buffers, gint32 count, gint32 flags, gint32 *werror, gboolean blocking, MonoError *error)
 {
-       int ret, count;
+       int ret;
        guint32 sent;
        guint32 sendflags = 0;
        gboolean interrupted;
@@ -1657,8 +1616,6 @@ ves_icall_System_Net_Sockets_Socket_Send_array_internal (gsize sock, MonoArrayHa
        error_init (error);
        *werror = 0;
        
-       count = mono_array_handle_length (buffers);
-       
        sendflags = convert_socketflags (flags);
        if (sendflags == -1) {
                *werror = WSAEOPNOTSUPP;
@@ -1671,12 +1628,7 @@ ves_icall_System_Net_Sockets_Socket_Send_array_internal (gsize sock, MonoArrayHa
                return 0;
        }
 
-       uint32_t gchandle;
-       WSABUF *wsabufs = MONO_ARRAY_HANDLE_PIN (buffers, WSABUF, 0, &gchandle);
-
-       ret = mono_w32socket_sendbuffers (sock, wsabufs, count, &sent, sendflags, NULL, NULL, blocking);
-
-       mono_gchandle_free (gchandle);
+       ret = mono_w32socket_sendbuffers (sock, buffers, count, &sent, sendflags, NULL, NULL, blocking);
 
        if (ret == SOCKET_ERROR)
                *werror = mono_w32socket_get_last_error ();
@@ -1692,29 +1644,21 @@ ves_icall_System_Net_Sockets_Socket_Send_array_internal (gsize sock, MonoArrayHa
 }
 
 gint32
-ves_icall_System_Net_Sockets_Socket_SendTo_internal (gsize sock, MonoArrayHandle buffer, gint32 offset, gint32 count, gint32 flags, MonoObjectHandle sockaddr, gint32 *werror, gboolean blocking, MonoError *error)
+ves_icall_System_Net_Sockets_Socket_SendTo_internal (gsize sock, gchar *buffer, gint32 count, gint32 flags, MonoObjectHandle sockaddr, gint32 *werror, gboolean blocking, MonoError *error)
 {
        int ret;
-       gint32 alen;
        int sendflags = 0;
        struct sockaddr *sa;
        socklen_t sa_size;
        gboolean interrupted;
        
        *werror = 0;
-       
-       alen = mono_array_handle_length (buffer);
-       if (offset > alen - count) {
-               return 0;
-       }
 
        sa = create_sockaddr_from_handle (sockaddr, &sa_size, werror, error);
        if (*werror != 0)
                return 0;
        return_val_if_nok (error, 0);
        
-       LOGDEBUG (g_message ("%s: alen: %d", __func__, alen));
-       
        LOGDEBUG (g_message("%s: Sending %d bytes", __func__, count));
 
        sendflags = convert_socketflags (flags);
@@ -1731,12 +1675,7 @@ ves_icall_System_Net_Sockets_Socket_SendTo_internal (gsize sock, MonoArrayHandle
                return 0;
        }
 
-       uint32_t gchandle;
-       gchar *buf = MONO_ARRAY_HANDLE_PIN (buffer, gchar, offset, &gchandle);
-
-       ret = mono_w32socket_sendto (sock, buf, count, sendflags, sa, sa_size, blocking);
-
-       mono_gchandle_free (gchandle);
+       ret = mono_w32socket_sendto (sock, buffer, count, sendflags, sa, sa_size, blocking);
 
        if (ret == SOCKET_ERROR)
                *werror = mono_w32socket_get_last_error ();
index 9fcd2341d7825e05b7aeb5065ce87acc0d2f94d0..5d5aa4adc53b472f35e448cf21e01bacc80e1829 100644 (file)
 
 #ifndef HOST_WIN32
 typedef gint SOCKET;
+
+typedef struct {
+       guint32 len;
+       gpointer buf;
+} WSABUF, *LPWSABUF;
 #endif
 
 /* This is a copy of System.Net.Sockets.SocketType */
@@ -204,32 +209,28 @@ void
 ves_icall_System_Net_Sockets_Socket_Connect_internal (gsize sock, MonoObjectHandle sockaddr, gint32 *werror, gboolean blocking, MonoError *error);
 
 gint32
-ves_icall_System_Net_Sockets_Socket_Receive_internal (gsize sock, MonoArrayHandle buffer, gint32 offset, gint32 count,
+ves_icall_System_Net_Sockets_Socket_Receive_internal (gsize sock, gchar *buffer, gint32 count,
                                                      gint32 flags, gint32 *werror, gboolean blocking, MonoError *error);
 
 gint32
-ves_icall_System_Net_Sockets_Socket_Receive_array_internal (gsize sock, MonoArrayHandle buffers, gint32 flags,
+ves_icall_System_Net_Sockets_Socket_Receive_array_internal (gsize sock, WSABUF *buffers, gint32 count, gint32 flags,
                                                            gint32 *werror, gboolean blocking, MonoError *error);
 
-/* gint32 */
-/* ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal (gsize sock, MonoArray *buffer, gint32 offset, gint32 count, */
-/*                                                       gint32 flags, MonoObject **sockaddr, gint32 *werror, gboolean blocking); */
-
 gint32
-ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal (gsize sock, MonoArrayHandle buffer, gint32 offset, gint32 count,
+ves_icall_System_Net_Sockets_Socket_ReceiveFrom_internal (gsize sock, gchar *buffer, gint32 count,
                                                          gint32 flags, MonoObjectHandle sockaddr, gint32 *werror, gboolean blocking, MonoError *error);
 
 
 gint32
-ves_icall_System_Net_Sockets_Socket_Send_internal (gsize sock, MonoArrayHandle buffer, gint32 offset, gint32 count,
+ves_icall_System_Net_Sockets_Socket_Send_internal (gsize sock, gchar *buffer, gint32 count,
                                                   gint32 flags, gint32 *werror, gboolean blocking, MonoError *error);
 
 gint32
-ves_icall_System_Net_Sockets_Socket_Send_array_internal (gsize sock, MonoArrayHandle buffers, gint32 flags,
+ves_icall_System_Net_Sockets_Socket_Send_array_internal (gsize sock, WSABUF *buffers, gint32 count, gint32 flags,
                                                         gint32 *werror, gboolean blocking, MonoError *error);
 
 gint32
-ves_icall_System_Net_Sockets_Socket_SendTo_internal (gsize sock, MonoArrayHandle buffer, gint32 offset, gint32 count,
+ves_icall_System_Net_Sockets_Socket_SendTo_internal (gsize sock, gchar *buffer, gint32 count,
                                                     gint32 flags, MonoObjectHandle sockaddr, gint32 *werror,
                                                     gboolean blocking, MonoError *error);
 
index d35a867778fe49e99c74ab07296a3d58d6bc935b..b2354f176286a27a1ebc08ac029f2b253234aaff 100755 (executable)
@@ -99,8 +99,8 @@ long_min_un: dest:i src1:i src2:i len:16 clob:1
 long_max: dest:i src1:i src2:i len:16 clob:1
 long_max_un: dest:i src1:i src2:i len:16 clob:1
 
-throw: src1:i len:18
-rethrow: src1:i len:18
+throw: src1:i len:24
+rethrow: src1:i len:24
 start_handler: len:16
 endfinally: len:9
 endfilter: src1:a len:9
index 016423072bd74048996f6c85363e28b6c52d90d7..4a2637c1943e4339c4aaca8a2762a8a538012405 100644 (file)
@@ -3662,13 +3662,10 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx
                        return;
 
                if (agent_config.defer) {
-                       /* Make sure the thread id is always set when doing deferred debugging */
                        if (is_debugger_thread ()) {
                                /* Don't suspend on events from the debugger thread */
                                suspend_policy = SUSPEND_POLICY_NONE;
-                               thread = mono_thread_get_main ();
                        }
-                       else thread = mono_thread_current ();
                } else {
                        if (is_debugger_thread () && event != EVENT_KIND_VM_DEATH)
                                // FIXME: Send these with a NULL thread, don't suspend the current thread
@@ -3691,7 +3688,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx
                        thread = NULL;
                } else {
                        if (!thread)
-                               thread = mono_thread_current ();
+                               thread = is_debugger_thread () ? mono_thread_get_main () : mono_thread_current ();
 
                        if (event == EVENT_KIND_VM_START && arg != NULL)
                                thread = (MonoThread *)arg;
@@ -4749,25 +4746,17 @@ breakpoint_matches_assembly (MonoBreakpoint *bp, MonoAssembly *assembly)
        return bp->method && bp->method->klass->image->assembly == assembly;
 }
 
-static MonoObject*
-get_this (StackFrame *frame)
+static gpointer
+get_this_addr (StackFrame *frame)
 {
        //Logic inspiered by "add_var" method and took out path that happens in async method for getting this
        MonoDebugVarInfo *var = frame->jit->this_var;
        if ((var->index & MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS) != MONO_DEBUG_VAR_ADDRESS_MODE_REGOFFSET)
                return NULL;
 
-       guint8 * addr = (guint8 *)mono_arch_context_get_int_reg (&frame->ctx, var->index & ~MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS);
+       guint8 *addr = (guint8 *)mono_arch_context_get_int_reg (&frame->ctx, var->index & ~MONO_DEBUG_VAR_ADDRESS_MODE_FLAGS);
        addr += (gint32)var->offset;
-       return *(MonoObject**)addr;
-}
-
-//This ID is used to figure out if breakpoint hit on resumeOffset belongs to us or not
-//since thread probably changed...
-static int
-get_this_async_id (StackFrame *frame)
-{
-       return get_objid (get_this (frame));
+       return addr;
 }
 
 static MonoMethod*
@@ -4782,25 +4771,100 @@ get_set_notification_method (MonoClass* async_builder_class)
        return set_notification_method;
 }
 
-static void
-set_set_notification_for_wait_completion_flag (StackFrame *frame)
+static MonoMethod*
+get_object_id_for_debugger_method (MonoClass* async_builder_class)
+{
+       MonoError error;
+       GPtrArray *array = mono_class_get_methods_by_name (async_builder_class, "get_ObjectIdForDebugger", 0x24, FALSE, FALSE, &error);
+       mono_error_assert_ok (&error);
+       g_assert (array->len == 1);
+       MonoMethod *method = (MonoMethod *)g_ptr_array_index (array, 0);
+       g_ptr_array_free (array, TRUE);
+       return method;
+}
+
+/* Return the address of the AsyncMethodBuilder struct belonging to the state machine method pointed to by FRAME */
+static gpointer
+get_async_method_builder (StackFrame *frame)
 {
-       MonoObject* obj = get_this (frame);
-       g_assert (obj);
-       MonoClassField *builder_field = mono_class_get_field_from_name (obj->vtable->klass, "<>t__builder");
+       MonoObject *this_obj;
+       MonoClassField *builder_field;
+       gpointer builder;
+       guint8 *this_addr;
+
+       builder_field = mono_class_get_field_from_name (frame->method->klass, "<>t__builder");
        g_assert (builder_field);
-       MonoObject* builder;
+
+       this_addr = get_this_addr (frame);
+       if (!this_addr)
+               return NULL;
+
+       if (frame->method->klass->valuetype) {
+               guint8 *vtaddr = *(guint8**)this_addr;
+               builder = (char*)vtaddr + builder_field->offset - sizeof (MonoObject);
+       } else {
+               this_obj = *(MonoObject**)this_addr;
+               builder = (char*)this_obj + builder_field->offset;
+       }
+
+       return builder;
+}
+
+//This ID is used to figure out if breakpoint hit on resumeOffset belongs to us or not
+//since thread probably changed...
+static int
+get_this_async_id (StackFrame *frame)
+{
+       MonoClassField *builder_field;
+       gpointer builder;
+       MonoMethod *method;
+       MonoObject *ex;
        MonoError error;
-       builder = mono_field_get_value_object_checked (frame->domain, builder_field, obj, &error);
+       MonoObject *obj;
+       gboolean old_disable_breakpoints = FALSE;
+       DebuggerTlsData *tls;
+
+       /*
+        * FRAME points to a method in a state machine class/struct.
+        * Call the ObjectIdForDebugger method of the associated method builder type.
+        */
+       builder = get_async_method_builder (frame);
+       if (!builder)
+               return 0;
+
+       builder_field = mono_class_get_field_from_name (frame->method->klass, "<>t__builder");
+       g_assert (builder_field);
+
+       tls = (DebuggerTlsData *)mono_native_tls_get_value (debugger_tls_id);
+       if (tls) {
+               old_disable_breakpoints = tls->disable_breakpoints;
+               tls->disable_breakpoints = TRUE;
+       }
+
+       method = get_object_id_for_debugger_method (mono_class_from_mono_type (builder_field->type));
+       obj = mono_runtime_try_invoke (method, builder, NULL, &ex, &error);
        mono_error_assert_ok (&error);
+
+       if (tls)
+               tls->disable_breakpoints = old_disable_breakpoints;
+
+       return get_objid (obj);
+}
+
+static void
+set_set_notification_for_wait_completion_flag (StackFrame *frame)
+{
+       MonoClassField *builder_field = mono_class_get_field_from_name (frame->method->klass, "<>t__builder");
+       g_assert (builder_field);
+       gpointer builder = get_async_method_builder (frame);
        g_assert (builder);
 
        void* args [1];
        gboolean arg = TRUE;
+       MonoError error;
        args [0] = &arg;
-       mono_runtime_invoke_checked (get_set_notification_method (builder->vtable->klass), mono_object_unbox (builder), args, &error);
+       mono_runtime_invoke_checked (get_set_notification_method (mono_class_from_mono_type (builder_field->type)), builder, args, &error);
        mono_error_assert_ok (&error);
-       mono_field_set_value (obj, builder_field, mono_object_unbox (builder));
 }
 
 static MonoMethod* notify_debugger_of_wait_completion_method_cache = NULL;
@@ -6982,7 +7046,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
        MonoMethodSignature *sig;
        guint8 **arg_buf;
        void **args;
-       MonoObject *this_arg, *res, *exc;
+       MonoObject *this_arg, *res, *exc = NULL;
        MonoDomain *domain;
        guint8 *this_buf;
 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
@@ -7154,7 +7218,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8
 
        mono_stopwatch_start (&watch);
        res = mono_runtime_try_invoke (m, m->klass->valuetype ? (gpointer) this_buf : (gpointer) this_arg, args, &exc, &error);
-       if (exc == NULL && !mono_error_ok (&error)) {
+       if (!mono_error_ok (&error) && exc == NULL) {
                exc = (MonoObject*) mono_error_convert_to_exception (&error);
        } else {
                mono_error_cleanup (&error); /* FIXME report error */
index e10f65766c97c3db26ecd53d7415bbc893ff44c2..e09d72e9192f97b23ef69eb35c1e97ee6d66b831 100644 (file)
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
+#if LLVM_API_VERSION >= 500
+#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
+#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/JITSymbol.h"
+#else
 #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
+#endif
 
 #include <cstdlib>
 
@@ -121,21 +127,46 @@ MonoJitMemoryManager::finalizeMemory(std::string *ErrMsg)
 class MonoLLVMJIT {
 public:
        /* We use our own trampoline infrastructure instead of the Orc one */
+#if LLVM_API_VERSION >= 500
+       typedef RTDyldObjectLinkingLayer ObjLayerT;
+       typedef IRCompileLayer<ObjLayerT, SimpleCompiler> CompileLayerT;
+       typedef CompileLayerT::ModuleHandleT ModuleHandleT;
+#else
        typedef ObjectLinkingLayer<> ObjLayerT;
        typedef IRCompileLayer<ObjLayerT> CompileLayerT;
        typedef CompileLayerT::ModuleSetHandleT ModuleHandleT;
+#endif
 
-       MonoLLVMJIT (TargetMachine *TM)
+       MonoLLVMJIT (TargetMachine *TM, MonoJitMemoryManager *mm)
+#if LLVM_API_VERSION >= 500
+               : TM(TM), ObjectLayer([=] { return std::shared_ptr<RuntimeDyld::MemoryManager> (mm); }),
+#else
                : TM(TM),
-                 CompileLayer (ObjectLayer, SimpleCompiler (*TM)) {
+#endif
+                 CompileLayer (ObjectLayer, SimpleCompiler (*TM)),
+                 modules() {
        }
 
-       ModuleHandleT addModule(Module *M) {
+#if LLVM_API_VERSION >= 500
+       ModuleHandleT addModule(Function *F, std::shared_ptr<Module> M) {
+#else
+       ModuleHandleT addModule(Function *F, Module *M) {
+#endif
                auto Resolver = createLambdaResolver(
                       [&](const std::string &Name) {
                                                  const char *name = Name.c_str ();
-                                                 if (!strcmp (name, "___bzero"))
-                                                         return RuntimeDyld::SymbolInfo((uint64_t)(gssize)(void*)bzero, (JITSymbolFlags)0);
+#if LLVM_API_VERSION >= 500
+                                                 JITSymbolFlags flags = JITSymbolFlags ();
+#else
+                                                 JITSymbolFlags flags = (JITSymbolFlags)0;
+#endif
+                                                 if (!strcmp (name, "___bzero")) {
+#if LLVM_API_VERSION >= 500
+                                                         return JITSymbol((uint64_t)(gssize)(void*)bzero, flags);
+#else
+                                                         return RuntimeDyld::SymbolInfo((uint64_t)(gssize)(void*)bzero, flags);
+#endif
+                                                 }
 
                                                  MonoDl *current;
                                                  char *err;
@@ -150,7 +181,11 @@ public:
                                                  if (!symbol)
                                                          outs () << "R: " << Name << "\n";
                                                  assert (symbol);
-                                                 return RuntimeDyld::SymbolInfo((uint64_t)(gssize)symbol, (JITSymbolFlags)0);
+#if LLVM_API_VERSION >= 500
+                                                 return JITSymbol((uint64_t)(gssize)symbol, flags);
+#else
+                                                 return RuntimeDyld::SymbolInfo((uint64_t)(gssize)symbol, flags);
+#endif
                       },
                       [](const std::string &S) {
                                                  outs () << "R2: " << S << "\n";
@@ -158,9 +193,15 @@ public:
                                                  return nullptr;
                                          } );
 
+#if LLVM_API_VERSION >= 500
+               ModuleHandleT m = CompileLayer.addModule(M,
+                                                                                                std::move(Resolver));
+               return m;
+#else
                return CompileLayer.addModuleSet(singletonSet(M),
                                                                                  make_unique<MonoJitMemoryManager>(),
                                                                                  std::move(Resolver));
+#endif
        }
 
        std::string mangle(const std::string &Name) {
@@ -186,8 +227,14 @@ public:
 
        gpointer compile (Function *F, int nvars, LLVMValueRef *callee_vars, gpointer *callee_addrs, gpointer *eh_frame) {
                F->getParent ()->setDataLayout (TM->createDataLayout ());
-               auto ModuleHandle = addModule (F->getParent ());
-
+#if LLVM_API_VERSION >= 500
+               // Orc uses a shared_ptr to refer to modules so we have to save them ourselves to keep a ref
+               std::shared_ptr<Module> m (F->getParent ());
+               modules.push_back (m);
+               auto ModuleHandle = addModule (F, m);
+#else
+               auto ModuleHandle = addModule (F, F->getParent ());
+#endif
                auto BodySym = CompileLayer.findSymbolIn(ModuleHandle, mangle (F), false);
                auto BodyAddr = BodySym.getAddress();
                assert (BodyAddr);
@@ -213,9 +260,11 @@ private:
        TargetMachine *TM;
        ObjLayerT ObjectLayer;
        CompileLayerT CompileLayer;
+       std::vector<std::shared_ptr<Module>> modules;
 };
 
 static MonoLLVMJIT *jit;
+static MonoJitMemoryManager *mono_mm;
 
 MonoEERef
 mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, FunctionEmittedCb *emitted_cb, ExceptionTableCb *exception_cb, DlSymCb *dlsym_cb, LLVMExecutionEngineRef *ee)
@@ -239,7 +288,8 @@ mono_llvm_create_ee (LLVMModuleProviderRef MP, AllocCodeMemoryCb *alloc_cb, Func
        auto TM = EB.selectTarget ();
        assert (TM);
 
-       jit = new MonoLLVMJIT (TM);
+       mono_mm = new MonoJitMemoryManager ();
+       jit = new MonoLLVMJIT (TM, mono_mm);
 
        return NULL;
 }
index 02f056f694d4c81251766673338a371789a0c452..949e5a362a6f7a4a413fcc0d3d19757f3fd72d1b 100644 (file)
@@ -2870,6 +2870,11 @@ emit_call_body (MonoCompile *cfg, guint8 *code, MonoJumpInfoType patch_type, gco
                        amd64_call_code (code, 0);
                }
                else {
+                       if (!no_patch && ((guint32)(code + 2 - cfg->native_code) % 8) != 0) {
+                               guint32 pad_size = 8 - ((guint32)(code + 2 - cfg->native_code) % 8);
+                               amd64_padding (code, pad_size);
+                               g_assert ((guint64)(code + 2 - cfg->native_code) % 8 == 0);
+                       }
                        mono_add_patch_info (cfg, code - cfg->native_code, patch_type, data);
                        amd64_set_reg_template (code, GP_SCRATCH_REG);
                        amd64_call_reg (code, GP_SCRATCH_REG);
index b688502060669d8f06f5cec7f668d70fd6b3284f..f09f285a17bb26b132a9e30ff6710db8b37ad020 100644 (file)
@@ -237,9 +237,10 @@ static AMD64_XMM_Reg_No float_return_regs [] = { AMD64_XMM0 };
 #define PARAM_REGS 6
 #define FLOAT_PARAM_REGS 8
 
-static AMD64_Reg_No param_regs [] = { AMD64_RDI, AMD64_RSI, AMD64_RDX, AMD64_RCX, AMD64_R8, AMD64_R9 };
+static const AMD64_Reg_No param_regs [] = {AMD64_RDI, AMD64_RSI, AMD64_RDX,
+                                          AMD64_RCX, AMD64_R8,  AMD64_R9};
 
-static AMD64_Reg_No return_regs [] = { AMD64_RAX, AMD64_RDX };
+static const AMD64_Reg_No return_regs [] = {AMD64_RAX, AMD64_RDX};
 #endif
 
 typedef struct {
index 8ac2da6b60711132f7873655aa30e318bc9a18d9..253cd42ff81b93f61cfa49d1a40eac51737e1a82 100644 (file)
@@ -30,6 +30,7 @@
 #include <llvm/IR/IRBuilder.h>
 #include <llvm/IR/Module.h>
 #include <llvm/IR/DIBuilder.h>
+#include <llvm/IR/CallSite.h>
 
 #include "mini-llvm-cpp.h"
 
@@ -56,7 +57,11 @@ mono_llvm_build_alloca (LLVMBuilderRef builder, LLVMTypeRef Ty,
                                                LLVMValueRef ArraySize,
                                                int alignment, const char *Name)
 {
+#if LLVM_API_VERSION >= 500
+       return wrap (unwrap (builder)->Insert (new AllocaInst (unwrap (Ty), 0, unwrap (ArraySize), alignment), Name));
+#else
        return wrap (unwrap (builder)->Insert (new AllocaInst (unwrap (Ty), unwrap (ArraySize), alignment), Name));
+#endif
 }
 
 LLVMValueRef 
@@ -244,6 +249,106 @@ mono_llvm_set_call_notail (LLVMValueRef func)
 #endif
 }
 
+#if LLVM_API_VERSION > 500
+static Attribute::AttrKind
+convert_attr (AttrKind kind)
+{
+       switch (kind) {
+       case LLVM_ATTR_NO_UNWIND:
+               return Attribute::NoUnwind;
+       case LLVM_ATTR_NO_INLINE:
+               return Attribute::NoInline;
+       case LLVM_ATTR_OPTIMIZE_FOR_SIZE:
+               return Attribute::OptimizeForSize;
+       case LLVM_ATTR_IN_REG:
+               return Attribute::InReg;
+       case LLVM_ATTR_STRUCT_RET:
+               return Attribute::StructRet;
+       case LLVM_ATTR_NO_ALIAS:
+               return Attribute::NoAlias;
+       case LLVM_ATTR_BY_VAL:
+               return Attribute::ByVal;
+       case LLVM_ATTR_UW_TABLE:
+               return Attribute::UWTable;
+       default:
+               assert (0);
+               return Attribute::NoUnwind;
+       }
+}
+#else
+static LLVMAttribute
+convert_attr (AttrKind kind)
+{
+       switch (kind) {
+       case LLVM_ATTR_NO_UNWIND:
+               return LLVMNoUnwindAttribute;
+       case LLVM_ATTR_NO_INLINE:
+               return LLVMNoInlineAttribute;
+       case LLVM_ATTR_OPTIMIZE_FOR_SIZE:
+               return LLVMOptimizeForSizeAttribute;
+       case LLVM_ATTR_IN_REG:
+               return LLVMInRegAttribute;
+       case LLVM_ATTR_STRUCT_RET:
+               return LLVMStructRetAttribute;
+       case LLVM_ATTR_NO_ALIAS:
+               return LLVMNoAliasAttribute;
+       case LLVM_ATTR_BY_VAL:
+               return LLVMByValAttribute;
+       case LLVM_ATTR_UW_TABLE:
+               return LLVMUWTable;
+       default:
+               assert (0);
+               return LLVMNoUnwindAttribute;
+       }
+}
+#endif
+
+void
+mono_llvm_add_func_attr (LLVMValueRef func, AttrKind kind)
+{
+#if LLVM_API_VERSION > 100
+       unwrap<Function> (func)->addAttribute (AttributeList::FunctionIndex, convert_attr (kind));
+#else
+       Function *Func = unwrap<Function>(func);
+       const AttributeSet PAL = Func->getAttributes();
+       AttrBuilder B(convert_attr (kind));
+       const AttributeSet PALnew =
+               PAL.addAttributes(Func->getContext(), AttributeSet::FunctionIndex,
+                                                 AttributeSet::get(Func->getContext(),
+                                                                                       AttributeSet::FunctionIndex, B));
+       Func->setAttributes(PALnew);
+#endif
+}
+
+void
+mono_llvm_add_param_attr (LLVMValueRef param, AttrKind kind)
+{
+#if LLVM_API_VERSION > 100
+       Function *func = unwrap<Argument> (param)->getParent ();
+       int n = unwrap<Argument> (param)->getArgNo ();
+       func->addParamAttr (n, convert_attr (kind));
+#else
+       Argument *A = unwrap<Argument>(param);
+       AttrBuilder B(convert_attr (kind));
+       A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1,  B));
+#endif
+}
+
+void
+mono_llvm_add_instr_attr (LLVMValueRef val, int index, AttrKind kind)
+{
+#if LLVM_API_VERSION > 100
+       CallSite (unwrap<Instruction> (val)).addAttribute (index, convert_attr (kind));
+#else
+  CallSite Call = CallSite(unwrap<Instruction>(val));
+  AttrBuilder B(convert_attr (kind));
+  Call.setAttributes(
+    Call.getAttributes().addAttributes(Call->getContext(), index,
+                                       AttributeSet::get(Call->getContext(),
+                                                         index, B)));
+#endif
+}
+
 #if LLVM_API_VERSION > 100
 
 void*
@@ -257,7 +362,14 @@ mono_llvm_di_create_compile_unit (void *di_builder, const char *cu_name, const c
 {
        DIBuilder *builder = (DIBuilder*)di_builder;
 
+#if LLVM_API_VERSION >= 500
+       DIFile *di_file;
+
+       di_file = builder->createFile (cu_name, dir);
+       return builder->createCompileUnit (dwarf::DW_LANG_C99, di_file, producer, true, "", 0);
+#else
        return builder->createCompileUnit (dwarf::DW_LANG_C99, cu_name, dir, producer, true, "", 0);
+#endif
 }
 
 void*
index 67dd9418a7da3f568b288ab010996b5fa1a6cc11..53ecc02de1a0a48e30a11562628e83d96541007c 100644 (file)
@@ -35,6 +35,17 @@ typedef enum {
        LLVM_ATOMICRMW_OP_ADD = 1,
 } AtomicRMWOp;
 
+typedef enum {
+       LLVM_ATTR_NO_UNWIND,
+       LLVM_ATTR_NO_INLINE,
+       LLVM_ATTR_OPTIMIZE_FOR_SIZE,
+       LLVM_ATTR_IN_REG,
+       LLVM_ATTR_STRUCT_RET,
+       LLVM_ATTR_NO_ALIAS,
+       LLVM_ATTR_BY_VAL,
+       LLVM_ATTR_UW_TABLE
+} AttrKind;
+
 void
 mono_llvm_dump_value (LLVMValueRef value);
 
@@ -93,6 +104,15 @@ mono_llvm_set_call_preserveall_cc (LLVMValueRef call);
 void
 mono_llvm_set_call_notail (LLVMValueRef call);
 
+void
+mono_llvm_add_func_attr (LLVMValueRef func, AttrKind kind);
+
+void
+mono_llvm_add_param_attr (LLVMValueRef param, AttrKind kind);
+
+void
+mono_llvm_add_instr_attr (LLVMValueRef val, int index, AttrKind kind);
+
 _Unwind_Reason_Code 
 mono_debug_personality (int a, _Unwind_Action b,
        uint64_t c, struct _Unwind_Exception *d, struct _Unwind_Context *e);
index f072ac56c1eb5f3561fbd7802ffbf85b31643771..8a0b622da281a5d7917e799a7f247b72fc70c0b3 100644 (file)
@@ -2465,7 +2465,7 @@ emit_get_method (MonoLLVMModule *module)
        func = LLVMAddFunction (lmodule, module->get_method_symbol, LLVMFunctionType1 (rtype, LLVMInt32Type (), FALSE));
        LLVMSetLinkage (func, LLVMExternalLinkage);
        LLVMSetVisibility (func, LLVMHiddenVisibility);
-       LLVMAddFunctionAttr (func, LLVMNoUnwindAttribute);
+       mono_llvm_add_func_attr (func, LLVM_ATTR_NO_UNWIND);
        module->get_method = func;
 
        entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
@@ -2545,7 +2545,7 @@ emit_get_unbox_tramp (MonoLLVMModule *module)
        func = LLVMAddFunction (lmodule, module->get_unbox_tramp_symbol, LLVMFunctionType1 (rtype, LLVMInt32Type (), FALSE));
        LLVMSetLinkage (func, LLVMExternalLinkage);
        LLVMSetVisibility (func, LLVMHiddenVisibility);
-       LLVMAddFunctionAttr (func, LLVMNoUnwindAttribute);
+       mono_llvm_add_func_attr (func, LLVM_ATTR_NO_UNWIND);
        module->get_unbox_tramp = func;
 
        entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
@@ -2596,7 +2596,7 @@ emit_llvm_code_start (MonoLLVMModule *module)
 
        func = LLVMAddFunction (lmodule, "llvm_code_start", LLVMFunctionType (LLVMVoidType (), NULL, 0, FALSE));
        LLVMSetLinkage (func, LLVMInternalLinkage);
-       LLVMAddFunctionAttr (func, LLVMNoUnwindAttribute);
+       mono_llvm_add_func_attr (func, LLVM_ATTR_NO_UNWIND);
        module->code_start = func;
        entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
        builder = LLVMCreateBuilder ();
@@ -2635,7 +2635,7 @@ emit_init_icall_wrapper (MonoLLVMModule *module, const char *name, const char *i
                g_assert_not_reached ();
        }
        LLVMSetLinkage (func, LLVMInternalLinkage);
-       LLVMAddFunctionAttr (func, LLVMNoInlineAttribute);
+       mono_llvm_add_func_attr (func, LLVM_ATTR_NO_INLINE);
        mono_llvm_set_preserveall_cc (func);
        entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
        builder = LLVMCreateBuilder ();
@@ -2704,7 +2704,7 @@ emit_llvm_code_end (MonoLLVMModule *module)
 
        func = LLVMAddFunction (lmodule, "llvm_code_end", LLVMFunctionType (LLVMVoidType (), NULL, 0, FALSE));
        LLVMSetLinkage (func, LLVMInternalLinkage);
-       LLVMAddFunctionAttr (func, LLVMNoUnwindAttribute);
+       mono_llvm_add_func_attr (func, LLVM_ATTR_NO_UNWIND);
        module->code_end = func;
        entry_bb = LLVMAppendBasicBlock (func, "ENTRY");
        builder = LLVMCreateBuilder ();
@@ -2857,17 +2857,17 @@ emit_unbox_tramp (EmitContext *ctx, const char *method_name, LLVMTypeRef method_
        tramp_name = g_strdup_printf ("ut_%s", method_name);
        tramp = LLVMAddFunction (ctx->module->lmodule, tramp_name, method_type);
        LLVMSetLinkage (tramp, LLVMInternalLinkage);
-       LLVMAddFunctionAttr (tramp, LLVMOptimizeForSizeAttribute);
-       //LLVMAddFunctionAttr (tramp, LLVMNoUnwindAttribute);
+       mono_llvm_add_func_attr (tramp, LLVM_ATTR_OPTIMIZE_FOR_SIZE);
+       //mono_llvm_add_func_attr (tramp, LLVM_ATTR_NO_UNWIND);
        linfo = ctx->linfo;
        // FIXME: Reduce code duplication with mono_llvm_compile_method () etc.
        if (!ctx->llvm_only && ctx->rgctx_arg_pindex != -1)
-               LLVMAddAttribute (LLVMGetParam (tramp, ctx->rgctx_arg_pindex), LLVMInRegAttribute);
+               mono_llvm_add_param_attr (LLVMGetParam (tramp, ctx->rgctx_arg_pindex), LLVM_ATTR_IN_REG);
        if (ctx->cfg->vret_addr) {
                LLVMSetValueName (LLVMGetParam (tramp, linfo->vret_arg_pindex), "vret");
                if (linfo->ret.storage == LLVMArgVtypeByRef) {
-                       LLVMAddAttribute (LLVMGetParam (tramp, linfo->vret_arg_pindex), LLVMStructRetAttribute);
-                       LLVMAddAttribute (LLVMGetParam (tramp, linfo->vret_arg_pindex), LLVMNoAliasAttribute);
+                       mono_llvm_add_param_attr (LLVMGetParam (tramp, linfo->vret_arg_pindex), LLVM_ATTR_STRUCT_RET);
+                       mono_llvm_add_param_attr (LLVMGetParam (tramp, linfo->vret_arg_pindex), LLVM_ATTR_NO_ALIAS);
                }
        }
 
@@ -2889,9 +2889,9 @@ emit_unbox_tramp (EmitContext *ctx, const char *method_name, LLVMTypeRef method_
        }
        call = LLVMBuildCall (builder, method, args, nargs, "");
        if (!ctx->llvm_only && ctx->rgctx_arg_pindex != -1)
-               LLVMAddInstrAttribute (call, 1 + ctx->rgctx_arg_pindex, LLVMInRegAttribute);
+               mono_llvm_add_instr_attr (call, 1 + ctx->rgctx_arg_pindex, LLVM_ATTR_IN_REG);
        if (linfo->ret.storage == LLVMArgVtypeByRef)
-               LLVMAddInstrAttribute (call, 1 + linfo->vret_arg_pindex, LLVMStructRetAttribute);
+               mono_llvm_add_instr_attr (call, 1 + linfo->vret_arg_pindex, LLVM_ATTR_STRUCT_RET);
 
        // FIXME: This causes assertions in clang
        //mono_llvm_set_must_tail (call);
@@ -3541,18 +3541,18 @@ process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref,
                mono_llvm_set_call_preserveall_cc (lcall);
 
        if (cinfo->ret.storage == LLVMArgVtypeByRef)
-               LLVMAddInstrAttribute (lcall, 1 + cinfo->vret_arg_pindex, LLVMStructRetAttribute);
+               mono_llvm_add_instr_attr (lcall, 1 + cinfo->vret_arg_pindex, LLVM_ATTR_STRUCT_RET);
        if (!ctx->llvm_only && call->rgctx_arg_reg)
-               LLVMAddInstrAttribute (lcall, 1 + cinfo->rgctx_arg_pindex, LLVMInRegAttribute);
+               mono_llvm_add_instr_attr (lcall, 1 + cinfo->rgctx_arg_pindex, LLVM_ATTR_IN_REG);
        if (call->imt_arg_reg)
-               LLVMAddInstrAttribute (lcall, 1 + cinfo->imt_arg_pindex, LLVMInRegAttribute);
+               mono_llvm_add_instr_attr (lcall, 1 + cinfo->imt_arg_pindex, LLVM_ATTR_IN_REG);
 
        /* Add byval attributes if needed */
        for (i = 0; i < sig->param_count; ++i) {
                LLVMArgInfo *ainfo = &call->cinfo->args [i + sig->hasthis];
 
                if (ainfo && ainfo->storage == LLVMArgVtypeByVal)
-                       LLVMAddInstrAttribute (lcall, 1 + ainfo->pindex, LLVMByValAttribute);
+                       mono_llvm_add_instr_attr (lcall, 1 + ainfo->pindex, LLVM_ATTR_BY_VAL);
        }
 
        /*
@@ -4011,18 +4011,15 @@ emit_handler_start (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef builder
                g_assert (personality);
        } else {
 #if LLVM_API_VERSION > 100
-               personality = ctx->module->personality;
-               if (!personality) {
-                       LLVMTypeRef personality_type = LLVMFunctionType (LLVMInt32Type (), NULL, 0, TRUE);
-                       personality = LLVMAddFunction (ctx->lmodule, "mono_personality", personality_type);
-                       LLVMAddFunctionAttr (personality, LLVMNoUnwindAttribute);
-                       LLVMBasicBlockRef entry_bb = LLVMAppendBasicBlock (personality, "ENTRY");
-                       LLVMBuilderRef builder2 = LLVMCreateBuilder ();
-                       LLVMPositionBuilderAtEnd (builder2, entry_bb);
-                       LLVMBuildRet (builder2, LLVMConstInt (LLVMInt32Type (), 0, FALSE));
-                       ctx->module->personality = personality;
-                       LLVMDisposeBuilder (builder2);
-               }
+               /* Can't cache this as each method is in its own llvm module */
+               LLVMTypeRef personality_type = LLVMFunctionType (LLVMInt32Type (), NULL, 0, TRUE);
+               personality = LLVMAddFunction (ctx->lmodule, "mono_personality", personality_type);
+               mono_llvm_add_func_attr (personality, LLVM_ATTR_NO_UNWIND);
+               LLVMBasicBlockRef entry_bb = LLVMAppendBasicBlock (personality, "ENTRY");
+               LLVMBuilderRef builder2 = LLVMCreateBuilder ();
+               LLVMPositionBuilderAtEnd (builder2, entry_bb);
+               LLVMBuildRet (builder2, LLVMConstInt (LLVMInt32Type (), 0, FALSE));
+               LLVMDisposeBuilder (builder2);
 #else
                static gint32 mapping_inited;
 
@@ -6466,7 +6463,11 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
                        args [0] = lhs;
                        args [1] = rhs;
                        /* 0xf1 == multiply all 4 elements, add them together, and store the result to the lowest element */
+#if LLVM_API_VERSION >= 500
+                       args [2] = LLVMConstInt (LLVMInt8Type (), 0xf1, FALSE);
+#else
                        args [2] = LLVMConstInt (LLVMInt32Type (), 0xf1, FALSE);
+#endif
 
                        values [ins->dreg] = LLVMBuildCall (builder, get_intrinsic (ctx, simd_op_to_intrins (ins->opcode)), args, 3, dname);
                        break;
@@ -6875,7 +6876,7 @@ mono_llvm_emit_method (MonoCompile *cfg)
        if (cfg->compile_aot)
                ctx->lmodule = ctx->module->lmodule;
        else
-               ctx->lmodule = LLVMModuleCreateWithName ("jit-module");
+               ctx->lmodule = LLVMModuleCreateWithName (g_strdup_printf ("jit-module-%s", cfg->method->name));
 #else
        ctx->lmodule = ctx->module->lmodule;
 #endif
@@ -6976,7 +6977,7 @@ emit_method_inner (EmitContext *ctx)
                LLVMSetFunctionCallConv (method, LLVMMono1CallConv);
        LLVMSetLinkage (method, LLVMPrivateLinkage);
 
-       LLVMAddFunctionAttr (method, LLVMUWTable);
+       mono_llvm_add_func_attr (method, LLVM_ATTR_UW_TABLE);
 
        if (cfg->compile_aot) {
                LLVMSetLinkage (method, LLVMInternalLinkage);
@@ -7016,7 +7017,7 @@ emit_method_inner (EmitContext *ctx)
        }
        if (header->num_clauses || (cfg->method->iflags & METHOD_IMPL_ATTRIBUTE_NOINLINING) || cfg->no_inline)
                /* We can't handle inlined methods with clauses */
-               LLVMAddFunctionAttr (method, LLVMNoInlineAttribute);
+               mono_llvm_add_func_attr (method, LLVM_ATTR_NO_INLINE);
 
        if (linfo->rgctx_arg) {
                ctx->rgctx_arg = LLVMGetParam (method, linfo->rgctx_arg_pindex);
@@ -7027,7 +7028,7 @@ emit_method_inner (EmitContext *ctx)
                 * CC_X86_64_Mono in X86CallingConv.td.
                 */
                if (!ctx->llvm_only)
-                       LLVMAddAttribute (ctx->rgctx_arg, LLVMInRegAttribute);
+                       mono_llvm_add_param_attr (ctx->rgctx_arg, LLVM_ATTR_IN_REG);
                LLVMSetValueName (ctx->rgctx_arg, "rgctx");
        } else {
                ctx->rgctx_arg_pindex = -1;
@@ -7036,8 +7037,8 @@ emit_method_inner (EmitContext *ctx)
                values [cfg->vret_addr->dreg] = LLVMGetParam (method, linfo->vret_arg_pindex);
                LLVMSetValueName (values [cfg->vret_addr->dreg], "vret");
                if (linfo->ret.storage == LLVMArgVtypeByRef) {
-                       LLVMAddAttribute (LLVMGetParam (method, linfo->vret_arg_pindex), LLVMStructRetAttribute);
-                       LLVMAddAttribute (LLVMGetParam (method, linfo->vret_arg_pindex), LLVMNoAliasAttribute);
+                       mono_llvm_add_param_attr (LLVMGetParam (method, linfo->vret_arg_pindex), LLVM_ATTR_STRUCT_RET);
+                       mono_llvm_add_param_attr (LLVMGetParam (method, linfo->vret_arg_pindex), LLVM_ATTR_NO_ALIAS);
                }
        }
 
@@ -7082,7 +7083,7 @@ emit_method_inner (EmitContext *ctx)
                LLVMSetValueName (values [cfg->args [i + sig->hasthis]->dreg], name);
                g_free (name);
                if (ainfo->storage == LLVMArgVtypeByVal)
-                       LLVMAddAttribute (LLVMGetParam (method, pindex), LLVMByValAttribute);
+                       mono_llvm_add_param_attr (LLVMGetParam (method, pindex), LLVM_ATTR_BY_VAL);
 
                if (ainfo->storage == LLVMArgVtypeByRef) {
                        /* For OP_LDADDR */
@@ -8215,7 +8216,11 @@ add_intrinsic (LLVMModuleRef module, int id)
                ret_type = type_to_simd_type (MONO_TYPE_R4);
                arg_types [0] = type_to_simd_type (MONO_TYPE_R4);
                arg_types [1] = type_to_simd_type (MONO_TYPE_R4);
+#if LLVM_API_VERSION >= 500
+               arg_types [2] = LLVMInt8Type ();
+#else
                arg_types [2] = LLVMInt32Type ();
+#endif
                AddFunc (module, name, ret_type, arg_types, 3);
                break;
 #endif
index 3b74b398e1bfed72b0773d0216b02bfb7208313a..a3f4883f74d5fc7ffc43c20047a7f5d254dcbc37 100644 (file)
@@ -2622,6 +2622,8 @@ mono_jit_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObjec
 #endif
 
        error_init (error);
+       if (exc)
+               *exc = NULL;
 
        if (obj == NULL && !(method->flags & METHOD_ATTRIBUTE_STATIC) && !method->string_ctor && (method->wrapper_type == 0)) {
                g_warning ("Ignoring invocation of an instance method on a NULL instance.\n");
index c78abccad633d929d1dcef391ef5ba360dd0ee16..a63b8ea322368427b297bc4a29397b1d97facadc 100644 (file)
@@ -824,19 +824,19 @@ gpointer
 mono_magic_trampoline (mgreg_t *regs, guint8 *code, gpointer arg, guint8* tramp)
 {
        gpointer res;
+       MonoError error;
 
-       MONO_ENTER_GC_UNSAFE_UNBALANCED;
+       MONO_REQ_GC_UNSAFE_MODE;
 
-       MonoError error;
+       g_assert (mono_thread_is_gc_unsafe_mode ());
 
        trampoline_calls ++;
 
        res = common_call_trampoline (regs, code, (MonoMethod *)arg, NULL, NULL, &error);
-       mono_error_set_pending_exception (&error);
-
-       mono_interruption_checkpoint_from_trampoline ();
-
-       MONO_EXIT_GC_UNSAFE_UNBALANCED;
+       if (!is_ok (&error)) {
+               mono_error_set_pending_exception (&error);
+               return NULL;
+       }
 
        return res;
 }
index ea912ba6ce94a94a9c7e0735b15c05a0c24fa550..365b0ae81630cb6ef7d753bb016931ba1d2bcaf6 100644 (file)
@@ -144,6 +144,7 @@ mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr)
        if (((code [-13] == 0x49) && (code [-12] == 0xbb)) || (code [-5] == 0xe8)) {
                if (code [-5] != 0xe8) {
                        if (can_write) {
+                               g_assert ((guint64)(orig_code - 11) % 8 == 0);
                                InterlockedExchangePointer ((gpointer*)(orig_code - 11), addr);
                                VALGRIND_DISCARD_TRANSLATIONS (orig_code - 11, sizeof (gpointer));
                        }
index 8f56a644ac7bb9678f3405b6ebd154fea8f85ed3..1b9c83586944fd6d007bec4655810afa0edf91bf 100644 (file)
@@ -262,7 +262,7 @@ usage (void)
                mono_profiler_printf ("\t                         %s", event_list [i].event_name);
 
        mono_profiler_printf ("\t[no]alloc            enable/disable recording allocation info");
-       mono_profiler_printf ("\t[no]legacy           enable/disable pre mono 5.4 default profiler events");
+       mono_profiler_printf ("\t[no]legacy           enable/disable pre Mono 5.6 default profiler events");
        mono_profiler_printf ("\tsample[-real][=FREQ] enable/disable statistical sampling of threads");
        mono_profiler_printf ("\t                     FREQ in Hz, 100 by default");
        mono_profiler_printf ("\t                     the -real variant uses wall clock time instead of process time");
index 54ff725b22b3c169e7234dffde1a626cf11ee9c2..beb5ce1b2580c265935db3200a138fd91f31c9a4 100644 (file)
 
 #include <mono/utils/memcheck.h>
 #include <mono/utils/mono-mmap-internals.h>
+#include <mono/utils/unlocked.h>
 
 #undef pthread_create
 #undef pthread_join
@@ -1862,7 +1863,7 @@ collect_nursery (const char *reason, gboolean is_overflow, SgenGrayQueue *unpin_
        major_collector.finish_nursery_collection ();
 
        TV_GETTIME (last_minor_collection_end_tv);
-       InterlockedAdd64 (&gc_stats.minor_gc_time, TV_ELAPSED (last_minor_collection_start_tv, last_minor_collection_end_tv));
+       UnlockedAdd64 (&gc_stats.minor_gc_time, TV_ELAPSED (last_minor_collection_start_tv, last_minor_collection_end_tv));
 
        sgen_debug_dump_heap ("minor", InterlockedRead (&gc_stats.minor_gc_count) - 1, NULL);
 
@@ -2356,7 +2357,7 @@ major_do_collection (const char *reason, gboolean is_overflow, gboolean forced)
        sgen_gray_object_queue_dispose (&gc_thread_gray_queue);
 
        TV_GETTIME (time_end);
-       InterlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (time_start, time_end));
+       UnlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (time_start, time_end));
 
        /* FIXME: also report this to the user, preferably in gc-end. */
        if (major_collector.get_and_reset_num_major_objects_marked)
@@ -2392,7 +2393,7 @@ major_start_concurrent_collection (const char *reason)
        num_objects_marked = major_collector.get_and_reset_num_major_objects_marked ();
 
        TV_GETTIME (time_end);
-       InterlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (time_start, time_end));
+       UnlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (time_start, time_end));
 
        current_collection_generation = -1;
 }
@@ -2420,7 +2421,7 @@ major_update_concurrent_collection (void)
        sgen_los_update_cardtable_mod_union ();
 
        TV_GETTIME (total_end);
-       InterlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (total_start, total_end));
+       UnlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (total_start, total_end));
 }
 
 static void
@@ -2442,7 +2443,7 @@ major_finish_concurrent_collection (gboolean forced)
        sgen_workers_stop_all_workers (GENERATION_OLD);
 
        SGEN_TV_GETTIME (time_major_conc_collection_end);
-       InterlockedAdd64 (&gc_stats.major_gc_time_concurrent, SGEN_TV_ELAPSED (time_major_conc_collection_start, time_major_conc_collection_end));
+       UnlockedAdd64 (&gc_stats.major_gc_time_concurrent, SGEN_TV_ELAPSED (time_major_conc_collection_start, time_major_conc_collection_end));
 
        major_collector.update_cardtable_mod_union ();
        sgen_los_update_cardtable_mod_union ();
@@ -2457,7 +2458,7 @@ major_finish_concurrent_collection (gboolean forced)
        sgen_gray_object_queue_dispose (&gc_thread_gray_queue);
 
        TV_GETTIME (total_end);
-       InterlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (total_start, total_end));
+       UnlockedAdd64 (&gc_stats.major_gc_time, TV_ELAPSED (total_start, total_end));
 
        current_collection_generation = -1;
 }
index 3e2620b219fdfca712a8afec98468c49b63945b7..4ed1ec495f98cd7ba2d87e689458aab47ecbd979 100644 (file)
@@ -968,10 +968,14 @@ void sgen_null_links_if (SgenObjectPredicateFunc predicate, void *data, int gene
 
 typedef gpointer (*SgenGCHandleIterateCallback) (gpointer hidden, GCHandleType handle_type, int max_generation, gpointer user);
 
+guint32 sgen_gchandle_new (GCObject *obj, gboolean pinned);
+guint32 sgen_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection);
 void sgen_gchandle_iterate (GCHandleType handle_type, int max_generation, SgenGCHandleIterateCallback callback, gpointer user);
 void sgen_gchandle_set_target (guint32 gchandle, GCObject *obj);
 void sgen_mark_normal_gc_handles (void *addr, SgenUserMarkFunc mark_func, void *gc_data);
 gpointer sgen_gchandle_get_metadata (guint32 gchandle);
+GCObject *sgen_gchandle_get_target (guint32 gchandle);
+void sgen_gchandle_free (guint32 gchandle);
 
 /* Other globals */
 
index 555d5bf483f68db8dc8f02f59fec6d389f129f5b..ba7259f50f9bd9a77e3317ff4d3090ec6f21011b 100644 (file)
@@ -202,50 +202,14 @@ sgen_gchandle_iterate (GCHandleType handle_type, int max_generation, SgenGCHandl
        } SGEN_ARRAY_LIST_END_FOREACH_SLOT;
 }
 
-/**
- * mono_gchandle_new:
- * \param obj managed object to get a handle for
- * \param pinned whether the object should be pinned
- * This returns a handle that wraps the object, this is used to keep a
- * reference to a managed object from the unmanaged world and preventing the
- * object from being disposed.
- * 
- * If \p pinned is false the address of the object can not be obtained, if it is
- * true the address of the object can be obtained.  This will also pin the
- * object so it will not be possible by a moving garbage collector to move the
- * object. 
- * 
- * \returns a handle that can be used to access the object from unmanaged code.
- */
 guint32
-mono_gchandle_new (GCObject *obj, gboolean pinned)
+sgen_gchandle_new (GCObject *obj, gboolean pinned)
 {
        return alloc_handle (gc_handles_for_type (pinned ? HANDLE_PINNED : HANDLE_NORMAL), obj, FALSE);
 }
 
-/**
- * mono_gchandle_new_weakref:
- * \param obj managed object to get a handle for
- * \param track_resurrection Determines how long to track the object, if this is set to TRUE, the object is tracked after finalization, if FALSE, the object is only tracked up until the point of finalization.
- *
- * This returns a weak handle that wraps the object, this is used to
- * keep a reference to a managed object from the unmanaged world.
- * Unlike the \c mono_gchandle_new the object can be reclaimed by the
- * garbage collector.  In this case the value of the GCHandle will be
- * set to zero.
- * 
- * If \p track_resurrection is TRUE the object will be tracked through
- * finalization and if the object is resurrected during the execution
- * of the finalizer, then the returned weakref will continue to hold
- * a reference to the object.   If \p track_resurrection is FALSE, then
- * the weak reference's target will become NULL as soon as the object
- * is passed on to the finalizer.
- * 
- * \returns a handle that can be used to access the object from
- * unmanaged code.
- */
 guint32
-mono_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection)
+sgen_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection)
 {
        return alloc_handle (gc_handles_for_type (track_resurrection ? HANDLE_WEAK_TRACK : HANDLE_WEAK), obj, track_resurrection);
 }
@@ -292,18 +256,8 @@ retry:
        return obj;
 }
 
-/**
- * mono_gchandle_get_target:
- * \param gchandle a GCHandle's handle.
- *
- * The handle was previously created by calling \c mono_gchandle_new or
- * \c mono_gchandle_new_weakref. 
- *
- * \returns a pointer to the \c MonoObject* represented by the handle or
- * NULL for a collected object if using a weakref handle.
- */
 GCObject*
-mono_gchandle_get_target (guint32 gchandle)
+sgen_gchandle_get_target (guint32 gchandle)
 {
        guint index = MONO_GC_HANDLE_SLOT (gchandle);
        GCHandleType type = MONO_GC_HANDLE_TYPE (gchandle);
@@ -382,16 +336,8 @@ sgen_gchandle_get_metadata (guint32 gchandle)
        return mono_gchandle_slot_metadata (slot, MONO_GC_HANDLE_TYPE_IS_WEAK (type));
 }
 
-/**
- * mono_gchandle_free:
- * \param gchandle a GCHandle's handle.
- *
- * Frees the \p gchandle handle.  If there are no outstanding
- * references, the garbage collector can reclaim the memory of the
- * object wrapped. 
- */
 void
-mono_gchandle_free (guint32 gchandle)
+sgen_gchandle_free (guint32 gchandle)
 {
        guint32 index = MONO_GC_HANDLE_SLOT (gchandle);
        GCHandleType type = MONO_GC_HANDLE_TYPE (gchandle);
index 38e869cd040e9ffb3504349cbd9bb7c25aa0babb..1518438babbb9a99d2f1844bf65b3a35888d8bd0 100644 (file)
@@ -633,3 +633,21 @@ mono_thread_state_name (int state)
 {
        return state_name (state);
 }
+
+gboolean
+mono_thread_is_gc_unsafe_mode (void)
+{
+       MonoThreadInfo *cur = mono_thread_info_current ();
+
+       if (!cur)
+               return FALSE;
+
+       switch (mono_thread_info_current_state (cur)) {
+       case STATE_RUNNING:
+       case STATE_ASYNC_SUSPEND_REQUESTED:
+       case STATE_SELF_SUSPEND_REQUESTED:
+               return TRUE;
+       default:
+               return FALSE;
+       }
+}
index ffa9de63a66e5468d8cd5fe58989202cb73755b1..b95784fa6fd9ebeb5d69a5f94eba78e658ad4809 100644 (file)
@@ -612,6 +612,7 @@ gboolean mono_thread_info_is_live (THREAD_INFO_TYPE *info);
 int mono_thread_info_suspend_count (THREAD_INFO_TYPE *info);
 int mono_thread_info_current_state (THREAD_INFO_TYPE *info);
 const char* mono_thread_state_name (int state);
+gboolean mono_thread_is_gc_unsafe_mode (void);
 
 gboolean mono_thread_info_in_critical_location (THREAD_INFO_TYPE *info);
 gboolean mono_thread_info_begin_suspend (THREAD_INFO_TYPE *info);
index 2ece0733d122a42d8ac969a7027081faf6af501a..81b0ade26bc94114cf06cfc43f78da7296cd9953 100644 (file)
@@ -90,8 +90,10 @@ mono_unicode_from_external (const gchar *in, gsize *bytes)
        g_strfreev (encodings);
        
        if(g_utf8_validate (in, -1, NULL)) {
-               gunichar2 *unires=g_utf8_to_utf16 (in, -1, NULL, (glong *)bytes, NULL);
-               *bytes *= 2;
+               glong items_written;
+               gunichar2 *unires=g_utf8_to_utf16 (in, -1, NULL, &items_written, NULL);
+               items_written *= 2;
+               *bytes = items_written;
                return(unires);
        }
 
index ef12456508a57232cf204090d76755ad5e88dfc6..5188f37291151780129e4e1fb41e9f4d9393f9ad 100644 (file)
@@ -1,50 +1,80 @@
-# ------------------------------------------------------------ #
-#   mono/eglib
-# ------------------------------------------------------------ #
+# --------------------------------------------------------------------------- #
+#   mono/eglib                                                                #
+# --------------------------------------------------------------------------- #
+
+# ghashtable.c #
 
 fun:monoeg_g_hash_table_iter_next
+fun:monoeg_g_hash_table_lookup_extended
+
+# sort.frag.h #
+
+fun:init_sort_info
+fun:insert_list
+fun:merge_lists
+
+# --------------------------------------------------------------------------- #
+#   mono/metadata                                                             #
+# --------------------------------------------------------------------------- #
+
+# class-accessors.c #
+
+fun:mono_class_get_first_method_idx
+fun:mono_class_get_flags
+fun:mono_class_get_generic_class
+fun:mono_class_get_method_count
+fun:mono_class_get_field_count
+fun:mono_class_set_first_method_idx
+fun:mono_class_set_method_count
+
+# class-inlines.h #
+
+fun:mono_class_is_ginst
+fun:mono_class_is_gtd
 
-# ------------------------------------------------------------ #
-#   mono/metadata
-# ------------------------------------------------------------ #
+# class-internals.h #
+
+fun:mono_class_has_parent
+fun:mono_class_has_parent_fast
 
 # class.c #
 
+fun:can_access_type
+fun:inflate_generic_context
 fun:inflate_generic_type
 fun:init_sizes_with_info
 fun:make_generic_param_class
+fun:mono_bounded_array_class_get
 fun:mono_class_create_from_typedef
 fun:mono_class_from_generic_parameter_internal
-fun:mono_class_get_field_count
+fun:mono_class_from_mono_type
+fun:mono_class_get_cctor
+fun:mono_class_get_inflated_method
 fun:mono_class_get_method_from_name_flags
 fun:mono_class_get_methods
+fun:mono_class_get_vtable_entry
 fun:mono_class_has_failure
 fun:mono_class_has_finalizer
 fun:mono_class_inflate_generic_method_full_checked
-fun:mono_class_inflate_generic_type_no_copy
-fun:mono_class_inflate_generic_type_with_mempool
 fun:mono_class_init
+fun:mono_class_instance_size
+fun:mono_class_is_assignable_from
 fun:mono_class_layout_fields
 fun:mono_class_setup_basic_field_info
 fun:mono_class_setup_fields
+fun:mono_class_setup_interfaces
 fun:mono_class_setup_methods
+fun:mono_class_setup_supertypes
 fun:mono_class_setup_vtable_full
 fun:mono_class_setup_vtable_general
+fun:mono_field_resolve_type
 fun:mono_generic_class_get_class
 fun:mono_method_get_context_general
+fun:mono_method_get_method_definition
+fun:mono_ptr_class_get
 fun:mono_type_get_basic_type_from_generic
 fun:mono_type_get_underlying_type
-
-# class-accessors.c #
-
-fun:mono_class_get_flags
-fun:mono_class_get_method_count
-fun:mono_class_set_method_count
-
-# class-inlines.h #
-
-fun:mono_class_is_ginst
-fun:mono_class_is_gtd
+fun:mono_type_has_exceptions
 
 # domain.c #
 
@@ -56,21 +86,26 @@ fun:finalize_domain_objects
 fun:finalizer_thread
 fun:mono_domain_finalize
 fun:mono_gc_cleanup
-
-# handle.h #
-
-fun:mono_stack_mark_pop
+fun:object_register_finalizer
 
 # handle.c #
 
 fun:mono_handle_new
 fun:mono_handle_stack_scan
 
+# handle.h #
+
+fun:mono_stack_mark_init
+fun:mono_stack_mark_pop
+
 # icall.c #
 
+fun:vell_icall_get_method_attributes
+fun:ves_icall_InternalInvoke
+fun:ves_icall_RuntimeTypeHandle_IsArray
+fun:ves_icall_RuntimeType_GetConstructors_native
 fun:ves_icall_System_Array_FastCopy
 fun:ves_icall_System_Reflection_MonoMethodInfo_get_parameter_info
-fun:ves_icall_RuntimeType_GetConstructors_native
 
 # image.c #
 
@@ -82,79 +117,101 @@ fun:mono_image_strdup
 
 fun:jit_info_table_add
 fun:jit_info_table_chunk_index
+fun:jit_info_table_copy_and_split_chunk
 fun:jit_info_table_find
 fun:jit_info_table_index
-fun:mono_jit_compile_method_with_opt
+fun:jit_info_table_split_chunk
 fun:mono_jit_info_init
-fun:mono_jit_info_table_find_internal
 
 # loader.c #
 
 fun:cache_memberref_sig
-fun:mon_new
+fun:inflate_generic_signature_checked
 fun:mono_get_method_from_token
 fun:mono_method_get_signature_checked
 fun:mono_method_signature_checked
 
 # marshal.c #
 
+fun:mono_icall_start
 fun:mono_marshal_get_native_wrapper
 fun:mono_marshal_isinst_with_cache
 
 # metadata.c #
 
-fun:img_set_cache_get
 fun:_mono_metadata_generic_class_equal
+fun:collect_method_images
+fun:do_mono_metadata_parse_type
+fun:img_set_cache_get
+fun:mono_metadata_decode_row
+fun:mono_metadata_get_canonical_generic_inst
 fun:mono_metadata_lookup_generic_class
+fun:mono_metadata_parse_type_internal
+fun:mono_type_get_class
 fun:mono_type_get_type
 fun:mono_type_is_struct
 
 # monitor.c #
 
+fun:mon_new
 fun:mono_monitor_ensure_owned
+fun:mono_monitor_enter_v4_fast
 fun:mono_monitor_exit_inflated
+fun:mono_monitor_inflate
 fun:mono_monitor_try_enter_inflated
 fun:mono_monitor_try_enter_internal
 fun:mono_object_hash
 fun:ves_icall_System_Threading_Monitor_Monitor_pulse_all
 fun:ves_icall_System_Threading_Monitor_Monitor_test_synchronised
+fun:ves_icall_System_Threading_Monitor_Monitor_try_enter_with_atomic_var
 fun:ves_icall_System_Threading_Monitor_Monitor_wait
 
 # mono-conc-hash.c #
 
+fun:expand_table
 fun:mono_conc_g_hash_table_lookup_extended
 fun:set_key
 
 # mono-hash.c #
 
 fun:mono_g_hash_table_find_slot
-fun:mono_g_hash_table_max_chain_length
 
 # object.c #
 
 fun:mono_class_compute_gc_descriptor
 fun:mono_class_create_runtime_vtable
 fun:mono_class_vtable_full
-fun:mono_delegate_ctor_with_method
+fun:mono_object_handle_get_virtual_method
 fun:mono_object_handle_isinst
+fun:mono_object_isinst_checked
+fun:mono_object_new_alloc_specific_checked
+fun:mono_object_new_specific_checked
 fun:mono_runtime_class_init_full
+fun:mono_runtime_invoke_array_checked
+fun:mono_runtime_try_invoke_array
+fun:mono_string_new_size_checked
+
+# reflection-cache.h #
+
+fun:cache_object_handle
 
 # reflection.c #
 
 fun:method_object_construct
 fun:reflected_equal
 
-# reflection-cache.h #
-
-fun:cache_object_handle
-
 # runtime.c #
 
 fun:mono_runtime_is_shutting_down
 fun:mono_runtime_try_shutdown
 
+# sgen-client-mono.h #
+
+fun:SGEN_LOAD_VTABLE_UNCHECKED
+
 # sgen-mono.c #
 
+fun:mono_gchandle_free
 fun:mono_gc_alloc_string
 fun:mono_gc_alloc_vector
 fun:mono_gc_thread_in_critical_region
@@ -162,18 +219,22 @@ fun:mono_gc_wbarrier_set_arrayref
 fun:sgen_client_gchandle_created
 fun:sgen_client_gchandle_destroyed
 
-# threadpool.c #
-
-fun:worker_callback
-
 # threadpool-worker-default.c #
 
 fun:heuristic_adjust
 fun:heuristic_notify_work_completed
 fun:heuristic_should_adjust
+fun:hill_climbing_change_thread_count
+fun:hill_climbing_force_change
 fun:hill_climbing_update
 fun:monitor_should_keep_running
 fun:monitor_thread
+fun:monitor_sufficient_delay_since_last_dequeue
+
+# threadpool.c #
+
+fun:try_invoke_perform_wait_callback
+fun:worker_callback
 
 # threads.c #
 
@@ -181,40 +242,69 @@ fun:build_wait_tids
 fun:create_thread
 fun:mono_thread_clr_state
 fun:mono_thread_detach_internal
+fun:mono_thread_set_name_internal
 fun:mono_threads_add_joinable_thread
 fun:mono_threads_join_threads
 fun:remove_and_abort_threads
+fun:request_thread_abort
 
 # w32handle.c #
 
-fun:mono_w32handle_init_handle
+fun:mono_w32handle_lookup
 fun:mono_w32handle_lookup_data
+fun:mono_w32handle_new_internal
+fun:mono_w32handle_ref_core
 fun:mono_w32handle_unref_core
 
-# ------------------------------------------------------------ #
-#   mono/mini
-# ------------------------------------------------------------ #
+# --------------------------------------------------------------------------- #
+#   mono/mini                                                                 #
+# --------------------------------------------------------------------------- #
 
 # alias-analysis.c #
 
 fun:recompute_aliased_variables
 
-# method-to-ir.c #
+# aot-runtime.c #
 
-fun:mono_method_to_ir
+fun:mono_aot_get_cached_class_info
+fun:mono_aot_get_method_from_vt_slot
 
-# mini.c #
+# decompose.c #
 
-fun:mini_method_compile
-fun:mono_allocate_stack_slots
-fun:mono_jit_compile_method_inner
-fun:mono_save_seq_point_info
-fun:mono_time_track_end
-fun:mono_type_to_load_membase
+fun:mono_decompose_vtype_opts
+
+# linear-scan.c #
+
+fun:mono_linear_scan
+
+# liveness.c #
+
+fun:mono_analyze_liveness
+fun:mono_liveness_handle_exception_clauses
+
+# method-to-ir.c #
+
+fun:check_call_signature
+fun:emit_init_rvar
+fun:inline_method
+fun:mono_method_check_inlining
+fun:mono_method_to_ir
+fun:mono_spill_global_vars
 
 # mini-amd64.c #
 
+fun:get_call_info
+fun:mono_arch_allocate_vars
+fun:mono_arch_emit_epilog
+fun:mono_arch_emit_prolog
 fun:mono_arch_get_delegate_invoke_impl
+fun:mono_arch_lowering_pass
+fun:mono_arch_peephole_pass_2
+
+# mini-codegen.c #
+
+fun:mono_local_regalloc
+fun:mono_peephole_ins
 
 # mini-exceptions.c #
 
@@ -222,12 +312,23 @@ fun:mono_thread_state_init_from_sigctx
 
 # mini-generic-sharing.c #
 
+fun:alloc_template
+fun:class_get_rgctx_template_oti
+fun:get_info_templates
+fun:inflate_info
+fun:inst_check_context_used
 fun:mini_get_basic_type_from_generic
 fun:mini_is_gsharedvt_type
 fun:mini_type_get_underlying_type
 fun:mono_class_fill_runtime_generic_context
 fun:mono_generic_context_check_used
 fun:mono_method_check_context_used
+fun:mono_method_fill_runtime_generic_context
+fun:mono_method_get_declaring_generic_method
+fun:mono_method_is_generic_impl
+fun:mono_method_needs_static_rgctx_invoke
+fun:rgctx_template_set_slot
+fun:set_info_templates
 
 # mini-native-types.c #
 
@@ -235,21 +336,52 @@ fun:mini_native_type_replace_type
 
 # mini-runtime.c #
 
+fun:create_runtime_invoke_info
+fun:mini_imt_entry_inited
+fun:mono_jit_compile_method_with_opt
 fun:mono_jit_find_compiled_method_with_jit_info
+fun:mono_jit_runtime_invoke
 
 # mini-trampolines.c #
 
 fun:common_call_trampoline
+fun:mini_add_method_trampoline
 fun:mini_resolve_imt_method
+fun:mono_create_delegate_trampoline_info
 fun:mono_create_jit_trampoline
+fun:mono_create_jump_trampoline
 fun:mono_delegate_trampoline
 fun:mono_magic_trampoline
 fun:mono_rgctx_lazy_fetch_trampoline
 fun:mono_vcall_trampoline
 
-# ------------------------------------------------------------ #
-#   mono/sgen
-# ------------------------------------------------------------ #
+# mini.c #
+
+fun:mini_method_compile
+fun:mono_allocate_stack_slots
+fun:mono_codegen
+fun:mono_compile_create_vars
+fun:mono_insert_branches_between_bblocks
+fun:mono_jit_compile_method_inner
+fun:mono_time_track_end
+fun:mono_type_to_load_membase
+fun:mono_type_to_store_membase
+
+# seq-points.c #
+
+fun:mono_save_seq_point_info
+
+# tramp-amd64.c #
+
+fun:mono_arch_patch_callsite
+
+# unwind.c #
+
+fun:mono_unwind_ops_encode_full
+
+# --------------------------------------------------------------------------- #
+#   mono/sgen                                                                 #
+# --------------------------------------------------------------------------- #
 
 # sgen-alloc.c #
 
@@ -257,14 +389,18 @@ fun:sgen_alloc_obj
 fun:sgen_clear_tlabs
 fun:sgen_try_alloc_obj_nolock
 
+# sgen-array-list.c #
+
+fun:sgen_array_list_add
+fun:sgen_array_list_find_unset
+
 # sgen-array-list.h #
 
 fun:sgen_array_list_bucketize
 
-# sgen-array-list.c #
+# sgen-cardtable.c #
 
-fun:sgen_array_list_add
-fun:sgen_array_list_find_unset
+fun:sgen_card_table_wbarrier_range_copy
 
 # sgen-cardtable.h #
 
@@ -274,25 +410,24 @@ fun:sgen_card_table_mark_address
 
 fun:add_stage_entry
 
-# sgen-gc.h #
-
-fun:sgen_set_nursery_scan_start
-
 # sgen-gc.c #
 
 fun:mono_gc_wbarrier_generic_store
-fun:sgen_conservatively_pin_objects_from
+
+# sgen-gc.h #
+
+fun:sgen_set_nursery_scan_start
 
 # sgen-gchandles.c #
 
 fun:is_slot_set
 fun:link_get
-fun:mono_gchandle_free
 fun:sgen_gchandle_iterate
 
 # sgen-marksweep.c #
 
 fun:ensure_block_is_checked_for_sweeping
+fun:ensure_can_access_block_free_list
 fun:major_finish_sweep_checking
 fun:set_block_state
 fun:sweep_block
@@ -306,14 +441,20 @@ fun:sgen_fragment_allocator_alloc
 fun:sgen_fragment_allocator_par_range_alloc
 fun:sgen_fragment_allocator_release
 
-# ------------------------------------------------------------ #
-#   mono/utils
-# ------------------------------------------------------------ #
+# --------------------------------------------------------------------------- #
+#   mono/utils                                                                #
+# --------------------------------------------------------------------------- #
 
 # hazard-pointer.c #
 
 fun:is_pointer_hazardous
 fun:mono_get_hazardous_pointer
+fun:mono_thread_small_id_alloc
+
+# lock-free-array-queue.c #
+
+fun:mono_lock_free_array_queue_pop
+fun:mono_lock_free_array_queue_push
 
 # memfuncs.c #
 
@@ -322,16 +463,27 @@ fun:mono_gc_memmove_aligned
 
 # mono-conc-hashtable.c #
 
+fun:expand_table
+fun:mono_conc_hashtable_insert
 fun:mono_conc_hashtable_lookup
 
 # mono-context.c #
 
 fun:mono_sigctx_to_monoctx
 
+# mono-error.c #
+
+fun:mono_error_cleanup
+
 # mono-lazy-init.h #
 
 fun:mono_lazy_initialize
 
+# mono-linked-list-set.c #
+
+fun:mono_lls_find
+fun:mono_lls_get_hazardous_pointer_with_mask
+
 # mono-threads-posix-signals.c #
 
 fun:restart_signal_handler
@@ -342,6 +494,10 @@ fun:suspend_signal_handler
 fun:check_thread_state
 fun:mono_threads_transition_finish_async_suspend
 
+# mono-threads.c #
+
+fun:mono_thread_info_uninstall_interrupt
+
 # os-event-unix.c #
 
 fun:mono_os_event_set
index 247f310c23b95a26c7fd1ae7460fe672766ab1a6..b5fdae354c22ba3e820da8c13b5b2ae9e7db394d 100644 (file)
@@ -52,7 +52,7 @@ get_function (const char *name)
                        compare_names);
 
        if (ptr == NULL) {
-               g_warning ("Function '%s' not not found.", name);
+               g_warning ("Function '%s' not found.", name);
                return NULL;
        }