From: Niklas Therning Date: Mon, 11 Sep 2017 09:07:53 +0000 (+0200) Subject: Merge pull request #5504 from ntherning/wait-for-native-thread-to-die-in-Thread-Join X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=f98d0799d89401853f59e4427764932d633b8935;hp=95f0800520afb6d7f28eba2178ae3b7c1d104c00;p=mono.git Merge pull request #5504 from ntherning/wait-for-native-thread-to-die-in-Thread-Join Wait for the native thread to die in Thread.Join() on Windows --- diff --git a/CODEOWNERS b/CODEOWNERS index 8c203a4b093..d72a176cb79 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,22 +1,18 @@ # Mono Code Owners File # -# GitHub uses this file to determine who to ping for reviews on pull requests. -# If you're the primary maintainer of an area of Mono and you don't mind -# reviewing pull requests, please add yourself to this file. You may want to -# avoid adding entries for commonly changed or automatically generated files -# (e.g. stuff in external/, or various generated *.csproj files) so as not to -# get spammed with emails. +# GitHub uses this file to determine who to assign for reviews +# on pull requests. Please keep this file alphabetically sorted. # -# Note that if two patterns match a file, the later pattern takes precedence. -# -# Please keep this file alphabetically sorted. -# -# Reference: +# References: # # https://github.com/blog/2392-introducing-code-owners # https://help.github.com/articles/about-codeowners -/ @luhenry @marek-safar + +# These owners will be the default owners for everything in the repo. +* @luhenry @marek-safar + +# Order is important. The last matching pattern has the most precedence. /acceptance-tests @akoeplinger /acceptance-tests/profiler-stress* @alexrp diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b767c969fb6..96ba2a40f38 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,6 +34,11 @@ CLA Contributions are now taken under the [.NET Foundation CLA](https://cla2.dotnetfoundation.org/). +Code Review +======= +We are requiring code reviews before merging a pull request. +GitHub won't let you merge a PR until someone from the Mono team approves it. + Testing ======= diff --git a/configure.ac b/configure.ac index 2c5e83eb768..bad8ecc8e3c 100644 --- a/configure.ac +++ b/configure.ac @@ -117,8 +117,8 @@ host_darwin=no if test "x$enable_wasm" = "xyes"; then -CFLAGS="$CFLAGS -D_REENTRANT -D_GNU_SOURCE -DNO_UNALIGNED_ACCESS -s WASM=1 -DWASM -Os" -CPPFLAGS="$CPPFLAGS -D_REENTRANT -DUSE_MMAP -D_GNU_SOURCE -DNO_UNALIGNED_ACCESS -s WASM=1 -DWASM -Os" +CFLAGS="$CFLAGS -D_REENTRANT -D_GNU_SOURCE -DNO_UNALIGNED_ACCESS -s WASM=1" +CPPFLAGS="$CPPFLAGS -D_REENTRANT -DUSE_MMAP -D_GNU_SOURCE -DNO_UNALIGNED_ACCESS -s WASM=1" libdl="-ldl" libgc_threads=pthreads @@ -555,7 +555,18 @@ AC_CHECK_FUNCS(_finite, , AC_MSG_CHECKING(for _finite in math.h) AC_CHECK_HEADERS(linux/magic.h) # not 64 bit clean in cross-compile -AC_CHECK_SIZEOF(void *, 4) +if test "x$enable_wasm" = "xyes"; then +AC_DEFINE(SIZEOF_VOID_P,4) +AC_DEFINE(SIZEOF_LONG,4) +ac_cv_sizeof_void_p="4" +ac_cv_sizeof_long="4" +else +AC_CHECK_SIZEOF(void *) +AC_CHECK_SIZEOF(long) +fi + +AC_CHECK_SIZEOF(int) +AC_CHECK_SIZEOF(long long) AC_CACHE_CHECK([for clang], mono_cv_clang,[ @@ -3067,6 +3078,7 @@ TARGET=WASM HOST=WASM arch_target=wasm AC_DEFINE(TARGET_WASM, 1, [Target wasm]) +AC_DEFINE(HOST_WASM, 1, [Host wasm]) BTLS_SUPPORTED=no with_tls=pthread target_mach=no @@ -3752,10 +3764,6 @@ AC_SUBST(PIDTYPE) AC_DEFINE(HAVE_CLASSIC_WINAPI_SUPPORT, 1, [Use classic Windows API support]) AC_DEFINE(HAVE_UWP_WINAPI_SUPPORT, 0, [Don't use UWP Windows API support]) -AC_CHECK_SIZEOF(int) -AC_CHECK_SIZEOF(void *) -AC_CHECK_SIZEOF(long) -AC_CHECK_SIZEOF(long long) AC_CHECK_FUNCS(strlcpy stpcpy strtok_r rewinddir vasprintf strerror_r) AC_CHECK_FUNCS(getrlimit) AC_CHECK_FUNCS(fork execv execve) @@ -4342,6 +4350,7 @@ AM_CONDITIONAL(POWERPC64, test x$TARGET = xPOWERPC64) AM_CONDITIONAL(ARM, test x$TARGET = xARM) AM_CONDITIONAL(ARM64, test x$TARGET = xARM64) AM_CONDITIONAL(S390X, test x$TARGET = xS390X) +AM_CONDITIONAL(WASM, test x$TARGET = xWASM) AM_CONDITIONAL(HOST_X86, test x$HOST = xX86) AM_CONDITIONAL(HOST_AMD64, test x$HOST = xAMD64) AM_CONDITIONAL(HOST_ARM, test x$HOST = xARM) @@ -4373,7 +4382,7 @@ AC_SUBST(mono_build_root) mono_runtime=mono/mini/mono AC_SUBST(mono_runtime) -CSC_LOCATION=`cd $srcdir && pwd`/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.1/tools/csc.exe +CSC_LOCATION=`cd $srcdir && pwd`/external/roslyn-binaries/Microsoft.Net.Compilers/Microsoft.Net.Compilers.2.3.2/tools/csc.exe if test $csc_compiler = mcs; then CSC=$mcs_topdir/class/lib/build/mcs.exe diff --git a/external/api-snapshot b/external/api-snapshot index 4dfe97ec246..08ec62bbd34 160000 --- a/external/api-snapshot +++ b/external/api-snapshot @@ -1 +1 @@ -Subproject commit 4dfe97ec246b7ebd2f7b4af378817abf436cf102 +Subproject commit 08ec62bbd349c042a40f959f242db7a54412e916 diff --git a/external/binary-reference-assemblies b/external/binary-reference-assemblies index 142cbeb62ff..9c5cc7f051a 160000 --- a/external/binary-reference-assemblies +++ b/external/binary-reference-assemblies @@ -1 +1 @@ -Subproject commit 142cbeb62ffabf1dd9c1414d8dd76f93bcbed0c2 +Subproject commit 9c5cc7f051a0bba2e41341a5baebfc4d2c2133ef diff --git a/external/roslyn-binaries b/external/roslyn-binaries index 9d196fb7777..1904c7d0682 160000 --- a/external/roslyn-binaries +++ b/external/roslyn-binaries @@ -1 +1 @@ -Subproject commit 9d196fb777776880b2f3c31602aa167394ae2f6b +Subproject commit 1904c7d0682a878e2d25b4d49f3475d12fbb9cc6 diff --git a/man/mcs.1 b/man/mcs.1 index 644b85a6e4f..607cea48047 100644 --- a/man/mcs.1 +++ b/man/mcs.1 @@ -4,26 +4,27 @@ .. .TH mcs 1 "6 January 2001" .SH NAME -mcs \- Mono C# Compiler +mcs \- Turbo C# Compiler .SH SYNOPSIS .B mcs [option] [source-files] .SH DESCRIPTION -mcs is the Mono C# compiler, an implementation of the ECMA-334 -language specification. You can pass one or more options to drive the -compiler, and a set of source files. Extra options or arguments can -be provided in a response file. Response files are referenced by -prepending the @ symbol to the response file name. +mcs is the Turbo C# compiler (also known as the Mono C# compiler), it +is an implementation of the ECMA-334 language specification. You can +pass one or more options to drive the compiler, and a set of source +files. Extra options or arguments can be provided in a response file. +Response files are referenced by prepending the @ symbol to the +response file name. .PP The .I mcs compiler is used to compile against the latest Mono Base Class Library version and fully implements C# 1.0, 2.0, 3.0, 4.0, 5.0 and 6.0 -specifications. +specifications with partial support for C# 7.0. .PP See the section on packages for more information. .PP -The Mono C# compiler accepts the same command line options that the +The Turbo C# compiler accepts the same command line options that the Microsoft C# compiler does. Those options can start with a slash or a dash (/checked is the same as -checked). Additionally some GNU-like options are supported, those begin with "--". All MCS-specific flags @@ -37,13 +38,13 @@ for partial compilation. To achieve the benefits of partial compilation, you should compile programs into their own assemblies, and later reference them with the "-r" flag. .PP -The Mono C# compiler generates images (.exe files) that contain CIL +The Turbo C# compiler generates images (.exe files) that contain CIL byte code that can be executed by any system that implements a Common Language Infrastructure virtual machine such as the Microsoft .NET runtime engine on Windows or the Mono runtime engine on Unix systems. Executables are not bound to a specific CPU or operating system. .PP -The Mono C# compiler by default only references three assemblies: +The Turbo C# compiler by default only references three assemblies: mscorlib.dll, System.dll and System.Xml.dll. If you want to reference extra libraries you must manually specify them using the -pkg: command line option or the -r: command line option. @@ -53,7 +54,7 @@ use the -pkg:dotnet command line option. .SH OPTIONS .TP .I \-\-about -Displays information about the Mono C# compiler +Displays information about the Turbo C# compiler .TP .I \-\-addmodule:MODULE1[,MODULE2] Includes the specified modules in the resulting assembly. Modules are diff --git a/mcs/class/Mono.Data.Tds/Test/bug-4786.cs b/mcs/class/Mono.Data.Tds/Test/bug-4786.cs index 91f8a06fc1a..ed44567b40d 100644 --- a/mcs/class/Mono.Data.Tds/Test/bug-4786.cs +++ b/mcs/class/Mono.Data.Tds/Test/bug-4786.cs @@ -51,13 +51,10 @@ namespace MonoTests.Mono.Data.Tds //require at this point: a listener on port 1433... try{ - Socket Listener = new Socket(AddressFamily.InterNetwork, - SocketType.Stream, - ProtocolType.Tcp); IPAddress hostIP =Dns.GetHostEntry("localhost").AddressList[0]; - IPEndPoint ep = new IPEndPoint(hostIP, 1433); - Listener.Bind(ep); - Listener.Listen(1); + IPEndPoint ep = new IPEndPoint(hostIP, 1433); + TcpListener Listener = new TcpListener (ep); + Listener.Start (); } catch (Exception){ //ignore } @@ -103,6 +100,7 @@ namespace MonoTests.Mono.Data.Tds pool.ReleaseConnection(tds); + Listener.Stop (); //exit } } diff --git a/mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogProcessor.cs b/mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogProcessor.cs index 5afdbbeb4eb..7e8111b6c29 100644 --- a/mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogProcessor.cs +++ b/mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogProcessor.cs @@ -102,73 +102,86 @@ namespace Mono.Profiler.Log { var extType = (LogEventType) (type & 0xf0); _time = ReadTime (); + LogEvent ev = null; switch (basicType) { case LogEventType.Allocation: switch (extType) { case LogEventType.AllocationBacktrace: case LogEventType.AllocationNoBacktrace: - return new AllocationEvent { + ev = new AllocationEvent { ClassPointer = ReadPointer (), ObjectPointer = ReadObject (), ObjectSize = (long) Reader.ReadULeb128 (), Backtrace = ReadBacktrace (extType == LogEventType.AllocationBacktrace), }; + break; default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; case LogEventType.GC: switch (extType) { case LogEventType.GCEvent: - return new GCEvent { + ev = new GCEvent { Type = (LogGCEvent) Reader.ReadByte (), Generation = Reader.ReadByte (), }; + break; case LogEventType.GCResize: - return new GCResizeEvent { + ev = new GCResizeEvent { NewSize = (long) Reader.ReadULeb128 (), }; + break; case LogEventType.GCMove: { var list = new long [(int) Reader.ReadULeb128 ()]; for (var i = 0; i < list.Length; i++) list [i] = ReadObject (); - return new GCMoveEvent { + ev = new GCMoveEvent { OldObjectPointers = list.Where ((_, i) => i % 2 == 0).ToArray (), NewObjectPointers = list.Where ((_, i) => i % 2 != 0).ToArray (), }; + break; } case LogEventType.GCHandleCreationNoBacktrace: case LogEventType.GCHandleCreationBacktrace: - return new GCHandleCreationEvent { + ev = new GCHandleCreationEvent { Type = (LogGCHandleType) Reader.ReadULeb128 (), Handle = (long) Reader.ReadULeb128 (), ObjectPointer = ReadObject (), Backtrace = ReadBacktrace (extType == LogEventType.GCHandleCreationBacktrace), }; + break; case LogEventType.GCHandleDeletionNoBacktrace: case LogEventType.GCHandleDeletionBacktrace: - return new GCHandleDeletionEvent { + ev = new GCHandleDeletionEvent { Type = (LogGCHandleType) Reader.ReadULeb128 (), Handle = (long) Reader.ReadULeb128 (), Backtrace = ReadBacktrace (extType == LogEventType.GCHandleDeletionBacktrace), }; + break; case LogEventType.GCFinalizeBegin: - return new GCFinalizeBeginEvent (); + ev = new GCFinalizeBeginEvent (); + break; case LogEventType.GCFinalizeEnd: - return new GCFinalizeEndEvent (); + ev = new GCFinalizeEndEvent (); + break; case LogEventType.GCFinalizeObjectBegin: - return new GCFinalizeObjectBeginEvent { + ev = new GCFinalizeObjectBeginEvent { ObjectPointer = ReadObject (), }; + break; case LogEventType.GCFinalizeObjectEnd: - return new GCFinalizeObjectEndEvent { + ev = new GCFinalizeObjectEndEvent { ObjectPointer = ReadObject (), }; + break; default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; case LogEventType.Metadata: { var load = false; var unload = false; @@ -191,150 +204,169 @@ namespace Mono.Profiler.Log { switch (metadataType) { case LogMetadataType.Class: if (load) { - return new ClassLoadEvent { + ev = new ClassLoadEvent { ClassPointer = ReadPointer (), ImagePointer = ReadPointer (), Name = Reader.ReadCString (), }; } else throw new LogException ("Invalid class metadata event."); + break; case LogMetadataType.Image: if (load) { - return new ImageLoadEvent { + ev = new ImageLoadEvent { ImagePointer = ReadPointer (), Name = Reader.ReadCString (), }; } else if (unload) { - return new ImageUnloadEvent { + ev = new ImageUnloadEvent { ImagePointer = ReadPointer (), Name = Reader.ReadCString (), }; } else throw new LogException ("Invalid image metadata event."); + break; case LogMetadataType.Assembly: if (load) { - return new AssemblyLoadEvent { + ev = new AssemblyLoadEvent { AssemblyPointer = ReadPointer (), ImagePointer = ReadPointer (), Name = Reader.ReadCString (), }; } else if (unload) { - return new AssemblyUnloadEvent { + ev = new AssemblyUnloadEvent { AssemblyPointer = ReadPointer (), ImagePointer = ReadPointer (), Name = Reader.ReadCString (), }; } else throw new LogException ("Invalid assembly metadata event."); + break; case LogMetadataType.AppDomain: if (load) { - return new AppDomainLoadEvent { + ev = new AppDomainLoadEvent { AppDomainId = ReadPointer (), }; } else if (unload) { - return new AppDomainUnloadEvent { + ev = new AppDomainUnloadEvent { AppDomainId = ReadPointer (), }; } else { - return new AppDomainNameEvent { + ev = new AppDomainNameEvent { AppDomainId = ReadPointer (), Name = Reader.ReadCString (), }; } + break; case LogMetadataType.Thread: if (load) { - return new ThreadStartEvent { + ev = new ThreadStartEvent { ThreadId = ReadPointer (), }; } else if (unload) { - return new ThreadEndEvent { + ev = new ThreadEndEvent { ThreadId = ReadPointer (), }; } else { - return new ThreadNameEvent { + ev = new ThreadNameEvent { ThreadId = ReadPointer (), Name = Reader.ReadCString (), }; } + break; case LogMetadataType.Context: if (load) { - return new ContextLoadEvent { + ev = new ContextLoadEvent { ContextId = ReadPointer (), AppDomainId = ReadPointer (), }; } else if (unload) { - return new ContextUnloadEvent { + ev = new ContextUnloadEvent { ContextId = ReadPointer (), AppDomainId = ReadPointer (), }; } else throw new LogException ("Invalid context metadata event."); + break; default: throw new LogException ($"Invalid metadata type ({metadataType})."); } + break; } case LogEventType.Method: switch (extType) { case LogEventType.MethodLeave: - return new LeaveEvent { + ev = new LeaveEvent { MethodPointer = ReadMethod (), }; + break; case LogEventType.MethodEnter: - return new EnterEvent { + ev = new EnterEvent { MethodPointer = ReadMethod (), }; + break; case LogEventType.MethodLeaveExceptional: - return new ExceptionalLeaveEvent { + ev = new ExceptionalLeaveEvent { MethodPointer = ReadMethod (), }; + break; case LogEventType.MethodJit: - return new JitEvent { + ev = new JitEvent { MethodPointer = ReadMethod (), CodePointer = ReadPointer (), CodeSize = (long) Reader.ReadULeb128 (), Name = Reader.ReadCString (), }; + break; default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; case LogEventType.Exception: switch (extType) { case LogEventType.ExceptionThrowNoBacktrace: case LogEventType.ExceptionThrowBacktrace: - return new ThrowEvent { + ev = new ThrowEvent { ObjectPointer = ReadObject (), Backtrace = ReadBacktrace (extType == LogEventType.ExceptionThrowBacktrace), }; + break; case LogEventType.ExceptionClause: - return new ExceptionClauseEvent { + ev = new ExceptionClauseEvent { Type = (LogExceptionClause) Reader.ReadByte (), Index = (long) Reader.ReadULeb128 (), MethodPointer = ReadMethod (), ObjectPointer = ReadObject (), }; + break; default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; case LogEventType.Monitor: switch (extType) { case LogEventType.MonitorNoBacktrace: case LogEventType.MonitorBacktrace: - return new MonitorEvent { + ev = new MonitorEvent { Event = (LogMonitorEvent) Reader.ReadByte (), ObjectPointer = ReadObject (), Backtrace = ReadBacktrace (extType == LogEventType.MonitorBacktrace), }; + break; default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; case LogEventType.Heap: switch (extType) { case LogEventType.HeapBegin: - return new HeapBeginEvent (); + ev = new HeapBeginEvent (); + break; case LogEventType.HeapEnd: - return new HeapEndEvent (); + ev = new HeapEndEvent (); + break; case LogEventType.HeapObject: { - var ev = new HeapObjectEvent { + HeapObjectEvent hoe = new HeapObjectEvent { ObjectPointer = ReadObject (), ClassPointer = ReadPointer (), ObjectSize = (long) Reader.ReadULeb128 (), @@ -349,17 +381,18 @@ namespace Mono.Profiler.Log { }; } - ev.References = list; + hoe.References = list; + ev = hoe; - return ev; + break; } + case LogEventType.HeapRoots: { // TODO: This entire event makes no sense. - - var ev = new HeapRootsEvent (); + var hre = new HeapRootsEvent (); var list = new HeapRootsEvent.HeapRoot [(int) Reader.ReadULeb128 ()]; - ev.MaxGenerationCollectionCount = (long) Reader.ReadULeb128 (); + hre.MaxGenerationCollectionCount = (long) Reader.ReadULeb128 (); for (var i = 0; i < list.Length; i++) { list [i] = new HeapRootsEvent.HeapRoot { @@ -369,36 +402,41 @@ namespace Mono.Profiler.Log { }; } - ev.Roots = list; + hre.Roots = list; + ev = hre; - return ev; + break; } default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; case LogEventType.Sample: switch (extType) { case LogEventType.SampleHit: - return new SampleHitEvent { + ev = new SampleHitEvent { ThreadId = ReadPointer (), UnmanagedBacktrace = ReadBacktrace (true, false), ManagedBacktrace = ReadBacktrace (true), }; + break; case LogEventType.SampleUnmanagedSymbol: - return new UnmanagedSymbolEvent { + ev = new UnmanagedSymbolEvent { CodePointer = ReadPointer (), CodeSize = (long) Reader.ReadULeb128 (), Name = Reader.ReadCString (), }; + break; case LogEventType.SampleUnmanagedBinary: - return new UnmanagedBinaryEvent { + ev = new UnmanagedBinaryEvent { SegmentPointer = ReadPointer (), SegmentOffset = (long) Reader.ReadULeb128 (), SegmentSize = (long) Reader.ReadULeb128 (), FileName = Reader.ReadCString (), }; + break; case LogEventType.SampleCounterDescriptions: { - var ev = new CounterDescriptionsEvent (); + var cde = new CounterDescriptionsEvent (); var list = new CounterDescriptionsEvent.CounterDescription [(int) Reader.ReadULeb128 ()]; for (var i = 0; i < list.Length; i++) { @@ -415,12 +453,13 @@ namespace Mono.Profiler.Log { }; } - ev.Descriptions = list; + cde.Descriptions = list; + ev = cde; - return ev; + break; } case LogEventType.SampleCounters: { - var ev = new CounterSamplesEvent (); + var cse = new CounterSamplesEvent (); var list = new List (); while (true) { @@ -461,40 +500,51 @@ namespace Mono.Profiler.Log { }); } - ev.Samples = list; + cse.Samples = list; + ev = cse; - return ev; + break; } default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; case LogEventType.Runtime: switch (extType) { case LogEventType.RuntimeJitHelper: { var helperType = (LogJitHelper) Reader.ReadByte (); - return new JitHelperEvent { + ev = new JitHelperEvent { Type = helperType, BufferPointer = ReadPointer (), BufferSize = (long) Reader.ReadULeb128 (), Name = helperType == LogJitHelper.SpecificTrampoline ? Reader.ReadCString () : string.Empty, }; + break; } default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; case LogEventType.Meta: switch (extType) { case LogEventType.MetaSynchronizationPoint: - return new SynchronizationPointEvent { + ev = new SynchronizationPointEvent { Type = (LogSynchronizationPoint) Reader.ReadByte (), }; + break; default: throw new LogException ($"Invalid extended event type ({extType})."); } + break; default: throw new LogException ($"Invalid basic event type ({basicType})."); } + + ev.Timestamp = _time; + ev.Buffer = _bufferHeader; + + return ev; } long ReadPointer () diff --git a/mcs/class/Mono.Security/Mono.Security-net_4_x.csproj b/mcs/class/Mono.Security/Mono.Security-net_4_x.csproj index 3aed1008318..7a9b42a261f 100644 --- a/mcs/class/Mono.Security/Mono.Security-net_4_x.csproj +++ b/mcs/class/Mono.Security/Mono.Security-net_4_x.csproj @@ -90,24 +90,17 @@ - - - - - - - diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/BufferOffsetSize.cs b/mcs/class/Mono.Security/Mono.Security.Interface/BufferOffsetSize.cs deleted file mode 100644 index 71389628f2c..00000000000 --- a/mcs/class/Mono.Security/Mono.Security.Interface/BufferOffsetSize.cs +++ /dev/null @@ -1,96 +0,0 @@ -// -// BufferOffsetSize.cs -// -// Author: -// Martin Baulig -// -// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; - -namespace Mono.Security.Interface -{ - public class BufferOffsetSize : SecretParameters, IBufferOffsetSize - { - public byte[] Buffer { - get; - private set; - } - - public int Offset { - get; - internal set; - } - - public int Size { - get { return EndOffset - Offset; } - } - - public int EndOffset { - get; - internal set; - } - - public BufferOffsetSize (byte[] buffer, int offset, int size) - { - Buffer = buffer; - Offset = offset; - EndOffset = offset + size; - } - - public BufferOffsetSize (byte[] buffer) - : this (buffer, 0, buffer.Length) - { - } - - public BufferOffsetSize (int size) - : this (new byte [size]) - { - } - - public byte[] GetBuffer () - { - var copy = new byte [Size]; - Array.Copy (Buffer, Offset, copy, 0, Size); - return copy; - } - - public void TruncateTo (int newSize) - { - if (newSize > Size) - throw new ArgumentException ("newSize"); - EndOffset = Offset + newSize; - } - - protected void SetBuffer (byte[] buffer, int offset, int size) - { - Buffer = buffer; - Offset = offset; - EndOffset = offset + size; - } - - protected override void Clear () - { - Buffer = null; - Offset = EndOffset = 0; - } - } -} - diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/IBufferOffsetSize.cs b/mcs/class/Mono.Security/Mono.Security.Interface/IBufferOffsetSize.cs deleted file mode 100644 index 93b422c38bf..00000000000 --- a/mcs/class/Mono.Security/Mono.Security.Interface/IBufferOffsetSize.cs +++ /dev/null @@ -1,43 +0,0 @@ -// -// IBufferOffsetSize.cs -// -// Author: -// Martin Baulig -// -// Copyright (c) 2015 Xamarin, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -namespace Mono.Security.Interface -{ - public interface IBufferOffsetSize - { - byte[] Buffer { - get; - } - - int Offset { - get; - } - - int Size { - get; - } - } -} - diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/IMonoTlsEventSink.cs b/mcs/class/Mono.Security/Mono.Security.Interface/IMonoTlsEventSink.cs deleted file mode 100644 index 37729301297..00000000000 --- a/mcs/class/Mono.Security/Mono.Security.Interface/IMonoTlsEventSink.cs +++ /dev/null @@ -1,37 +0,0 @@ -// -// IMonoTlsEventSink.cs -// -// Author: -// Martin Baulig -// -// Copyright (c) 2015 Xamarin, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; - -namespace Mono.Security.Interface -{ - public interface IMonoTlsEventSink - { - void Error (Exception exception); - - void ReceivedCloseNotify (); - } -} - diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/SecretParameters.cs b/mcs/class/Mono.Security/Mono.Security.Interface/SecretParameters.cs deleted file mode 100644 index a225ba67e82..00000000000 --- a/mcs/class/Mono.Security/Mono.Security.Interface/SecretParameters.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -// SecretParameters.cs -// -// Author: -// Martin Baulig -// -// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; - -namespace Mono.Security.Interface -{ - public abstract class SecretParameters : IDisposable - { - protected abstract void Clear (); - - bool disposed; - - protected void CheckDisposed () - { - if (disposed) - throw new ObjectDisposedException (GetType ().Name); - } - - protected static void Clear (byte[] array) - { - Array.Clear (array, 0, array.Length); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - void Dispose (bool disposing) - { - if (!disposed) { - disposed = true; - Clear (); - } - } - - ~SecretParameters () - { - Dispose (false); - } - } -} - diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/SecureBuffer.cs b/mcs/class/Mono.Security/Mono.Security.Interface/SecureBuffer.cs deleted file mode 100644 index fc05f7a535e..00000000000 --- a/mcs/class/Mono.Security/Mono.Security.Interface/SecureBuffer.cs +++ /dev/null @@ -1,86 +0,0 @@ -// -// SecureBuffer.cs -// -// Author: -// Martin Baulig -// -// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; - -namespace Mono.Security.Interface -{ - public class SecureBuffer : SecretParameters, IBufferOffsetSize - { - byte[] buffer; - - public byte[] Buffer { - get { - CheckDisposed (); - return buffer; - } - } - - public int Size { - get { - CheckDisposed (); - return buffer != null ? buffer.Length : 0; - } - } - - int IBufferOffsetSize.Offset { - get { return 0; } - } - - public SecureBuffer (int size) - { - buffer = new byte [size]; - } - - public SecureBuffer (byte[] buffer) - { - this.buffer = buffer; - } - - public byte[] StealBuffer () - { - CheckDisposed (); - var retval = this.buffer; - this.buffer = null; - return retval; - } - - public static SecureBuffer CreateCopy (byte[] buffer) - { - var copy = new byte [buffer.Length]; - Array.Copy (buffer, copy, buffer.Length); - return new SecureBuffer (copy); - } - - protected override void Clear () - { - if (buffer != null) { - Array.Clear (buffer, 0, buffer.Length); - buffer = null; - } - } - } -} - diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/TlsBuffer.cs b/mcs/class/Mono.Security/Mono.Security.Interface/TlsBuffer.cs deleted file mode 100644 index be3c007b5b5..00000000000 --- a/mcs/class/Mono.Security/Mono.Security.Interface/TlsBuffer.cs +++ /dev/null @@ -1,334 +0,0 @@ -// -// TlsBuffer.cs -// -// Author: -// Martin Baulig -// -// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; - -namespace Mono.Security.Interface -{ - public class TlsBuffer : SecretParameters - { - public int Position { - get; set; - } - - public int Remaining { - get { return Size - (Position - Offset); } - } - - public byte[] Buffer { - get { return innerBuffer.Buffer; } - } - - public int Offset { - get { return innerBuffer.Offset; } - } - - public int Size { - get { return innerBuffer.Size; } - } - - public int EndOffset { - get { return Offset + Size; } - } - - IBufferOffsetSize innerBuffer; - - protected TlsBuffer () - : this (null, 0, 0) - { - } - - public TlsBuffer (IBufferOffsetSize bos) - { - innerBuffer = bos; - Position = bos.Offset; - } - - public TlsBuffer (byte[] buffer, int offset, int size) - : this (new BufferOffsetSize (buffer, offset, size)) - { - } - - public TlsBuffer (byte[] buffer) - : this (buffer, 0, buffer.Length) - { - } - - public TlsBuffer (int size) - : this (new byte [size], 0, size) - { - } - - public byte ReadByte () - { - if (Position >= EndOffset) - throw new TlsException (AlertDescription.DecodeError, "Buffer overflow"); - return Buffer [Position++]; - } - - public short ReadInt16 () - { - if (Position + 1 >= EndOffset) - throw new TlsException (AlertDescription.DecodeError, "Buffer overflow"); - var retval = (short)(Buffer [Position] << 8 | Buffer [Position + 1]); - Position += 2; - return retval; - } - - public int ReadInt24 () - { - if (Position + 2 >= EndOffset) - throw new TlsException (AlertDescription.DecodeError, "Buffer overflow"); - var retval = ((Buffer [Position] << 16) | (Buffer [Position+1] << 8) | Buffer [Position+2]); - Position += 3; - return retval; - } - - public int ReadInt32 () - { - if (Position + 3 >= EndOffset) - throw new TlsException (AlertDescription.DecodeError, "Buffer overflow"); - var retval = ((Buffer [Position] << 24) | (Buffer [Position+1] << 16) | (Buffer [Position+2] << 8) | Buffer [Position+3]); - Position += 4; - return retval; - } - - public TlsBuffer ReadBuffer (int length) - { - if (Position + length > EndOffset) - throw new TlsException (AlertDescription.DecodeError, "Buffer overflow"); - var retval = new TlsBuffer (Buffer, Position, length); - Position += length; - return retval; - } - - public IBufferOffsetSize GetRemaining () - { - return new BufferOffsetSize (Buffer, Position, Remaining); - } - - protected virtual void MakeRoomInternal (int size) - { - if (Position + size > EndOffset) - throw new TlsException (AlertDescription.DecodeError, "Buffer overflow"); - } - - public void Write (byte value) - { - MakeRoomInternal (1); - Buffer [Position++] = value; - } - - public void Write (short value) - { - MakeRoomInternal (2); - WriteInt16 (Buffer, Position, value); - Position += 2; - } - - public static void WriteInt16 (byte[] buffer, int offset, short value) - { - buffer[offset] = ((byte)(value >> 8)); - buffer[offset+1] = ((byte)value); - } - - public void Write (int value) - { - MakeRoomInternal (4); - WriteInt32 (Buffer, Position, value); - Position += 4; - } - - public void WriteInt24 (int value) - { - MakeRoomInternal (3); - WriteInt24 (Buffer, Position, value); - Position += 3; - } - - #pragma warning disable 3001 - public void Write (ulong value) - #pragma warning restore 3001 - { - MakeRoomInternal (8); - WriteInt64 (Buffer, Position, value); - Position += 8; - } - - public static void WriteInt24 (byte[] buffer, int offset, int value) - { - buffer[offset] = ((byte)(value >> 16)); - buffer[offset+1] = ((byte)(value >> 8)); - buffer[offset+2] = ((byte)value); - } - - public static void WriteInt32 (byte[] buffer, int offset, int value) - { - buffer[offset] = ((byte)(value >> 24)); - buffer[offset+1] = ((byte)(value >> 16)); - buffer[offset+2] = ((byte)(value >> 8)); - buffer[offset+3] = ((byte)value); - } - - #pragma warning disable 3001 - public static void WriteInt64 (byte[] buffer, int offset, ulong value) - #pragma warning restore 3001 - { - buffer[offset] = (byte) (value >> 56); - buffer[offset+1] = (byte) (value >> 48); - buffer[offset+2] = (byte) (value >> 40); - buffer[offset+3] = (byte) (value >> 32); - buffer[offset+4] = (byte) (value >> 24); - buffer[offset+5] = (byte) (value >> 16); - buffer[offset+6] = (byte) (value >> 8); - buffer[offset+7] = (byte) value; - } - - public void Write (byte[] buffer) - { - Write (buffer, 0, buffer.Length); - } - - public void Write (byte[] buffer, int offset, int size) - { - MakeRoomInternal (size); - Array.Copy (buffer, offset, Buffer, Position, size); - Position += size; - } - - public void Write (IBufferOffsetSize buffer) - { - Write (buffer.Buffer, buffer.Offset, buffer.Size); - } - - public SecureBuffer ReadSecureBuffer (int count) - { - return new SecureBuffer (ReadBytes (count)); - } - - public byte[] ReadBytes (int count) - { - if (Position + count > EndOffset) - throw new TlsException (AlertDescription.DecodeError, "Buffer overflow"); - var retval = new byte [count]; - Array.Copy (Buffer, Position, retval, 0, count); - Position += count; - return retval; - } - - internal static bool Compare (SecureBuffer buffer1, SecureBuffer buffer2) - { - if (buffer1 == null || buffer2 == null) - return false; - - if (buffer1.Size != buffer2.Size) - return false; - - for (int i = 0; i < buffer1.Size; i++) { - if (buffer1.Buffer [i] != buffer2.Buffer [i]) - return false; - } - return true; - } - - public static bool Compare (IBufferOffsetSize buffer1, IBufferOffsetSize buffer2) - { - if (buffer1 == null || buffer2 == null) - return false; - - if (buffer1.Size != buffer2.Size) - return false; - - for (int i = 0; i < buffer1.Size; i++) { - if (buffer1.Buffer [buffer1.Offset + i] != buffer2.Buffer [buffer2.Offset + i]) - return false; - } - return true; - } - - public static bool Compare (byte[] buffer1, byte[] buffer2) - { - if (buffer1 == null || buffer2 == null) - return false; - - return Compare (buffer1, 0, buffer1.Length, buffer2, 0, buffer2.Length); - } - - public static bool Compare (byte[] buffer1, int offset1, int size1, byte[] buffer2, int offset2, int size2) - { - if (buffer1 == null || buffer2 == null) - return false; - - if (size1 != size2) - return false; - - for (int i = 0; i < size1; i++) { - if (buffer1 [offset1 + i] != buffer2 [offset2 + i]) - return false; - } - return true; - - } - - public static int ConstantTimeCompare (byte[] buffer1, int offset1, int size1, byte[] buffer2, int offset2, int size2) - { - int status = 0; - int effectiveSize; - if (size1 < size2) { - status--; - effectiveSize = size1; - } else if (size2 < size1) { - status--; - effectiveSize = size2; - } else { - effectiveSize = size1; - } - - for (int i = 0; i < effectiveSize; i++) { - if (buffer1 [offset1 + i] != buffer2 [offset2 + i]) - status--; - } - - return status; - } - - protected void SetBuffer (byte[] buffer, int offset, int size) - { - innerBuffer = new BufferOffsetSize (buffer, offset, size); - } - - protected override void Clear () - { - var disposable = innerBuffer as IDisposable; - if (disposable != null) - disposable.Dispose (); - innerBuffer = null; - Position = 0; - } - - public static readonly byte[] EmptyArray = new byte [0]; - } -} - diff --git a/mcs/class/Mono.Security/Mono.Security.Interface/TlsMultiBuffer.cs b/mcs/class/Mono.Security/Mono.Security.Interface/TlsMultiBuffer.cs deleted file mode 100644 index de2975a81db..00000000000 --- a/mcs/class/Mono.Security/Mono.Security.Interface/TlsMultiBuffer.cs +++ /dev/null @@ -1,119 +0,0 @@ -// -// TlsMultiBuffer.cs -// -// Author: -// Martin Baulig -// -// Copyright (c) 2014-2016 Xamarin Inc. (http://www.xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; - -namespace Mono.Security.Interface -{ - public class TlsMultiBuffer - { - MemoryChunk first, last; - - private class MemoryChunk : BufferOffsetSize - { - public MemoryChunk next; - - public MemoryChunk (byte[] buffer, int offset, int size) - : base (buffer, offset, size) - { - } - } - - public bool IsEmpty { - get { return first == null; } - } - - public bool IsSingle { - get { return first != null && first.next == null; } - } - - public void Add (TlsBuffer buffer) - { - Add (buffer.Buffer, buffer.Offset, buffer.Size); - } - - public void Add (byte[] buffer) - { - Add (buffer, 0, buffer.Length); - } - - public void Add (byte[] buffer, int offset, int size) - { - var chunk = new MemoryChunk (buffer, offset, size); - if (last == null) - first = last = chunk; - else { - last.next = chunk; - last = chunk; - } - } - - public BufferOffsetSize[] GetBufferArray () - { - int count = 0; - for (var ptr = first; ptr != null; ptr = ptr.next) - count++; - var array = new BufferOffsetSize [count]; - count = 0; - for (var ptr = first; ptr != null; ptr = ptr.next) - array [count++] = ptr; - return array; - } - - public void Clear () - { - for (var ptr = first; ptr != null; ptr = ptr.next) - ptr.Dispose (); - first = last = null; - } - - public BufferOffsetSize GetBuffer () - { - int totalSize = 0; - for (var ptr = first; ptr != null; ptr = ptr.next) - totalSize += ptr.Size; - - var outBuffer = new BufferOffsetSize (new byte [totalSize]); - int offset = 0; - for (var ptr = first; ptr != null; ptr = ptr.next) { - Buffer.BlockCopy (ptr.Buffer, ptr.Offset, outBuffer.Buffer, offset, ptr.Size); - offset += ptr.Size; - } - return outBuffer; - } - - public BufferOffsetSize StealBuffer () - { - if (IsSingle) { - var retval = first; - first = last = null; - return retval; - } - - return GetBuffer (); - } - } -} - diff --git a/mcs/class/Mono.Security/Mono.Security.dll.sources b/mcs/class/Mono.Security/Mono.Security.dll.sources index a270d5f75de..a3572f49478 100644 --- a/mcs/class/Mono.Security/Mono.Security.dll.sources +++ b/mcs/class/Mono.Security/Mono.Security.dll.sources @@ -142,8 +142,6 @@ ./Mono.Security.Interface/CipherSuiteCode.cs ./Mono.Security.Interface/ExchangeAlgorithmType.cs ./Mono.Security.Interface/HashAlgorithmType.cs -./Mono.Security.Interface/IBufferOffsetSize.cs -./Mono.Security.Interface/IMonoTlsEventSink.cs ./Mono.Security.Interface/IMonoSslStream.cs ./Mono.Security.Interface/MonoTlsConnectionInfo.cs ./Mono.Security.Interface/MonoTlsProvider.cs @@ -153,8 +151,3 @@ ./Mono.Security.Interface/TlsProtocolCode.cs ./Mono.Security.Interface/TlsProtocols.cs -./Mono.Security.Interface/BufferOffsetSize.cs -./Mono.Security.Interface/SecretParameters.cs -./Mono.Security.Interface/SecureBuffer.cs -./Mono.Security.Interface/TlsBuffer.cs -./Mono.Security.Interface/TlsMultiBuffer.cs diff --git a/mcs/class/System.Drawing/Test/System.Drawing.Imaging/tests-ms.sh b/mcs/class/System.Drawing/Test/System.Drawing.Imaging/tests-ms.sh deleted file mode 100755 index 98b2c00dbe8..00000000000 --- a/mcs/class/System.Drawing/Test/System.Drawing.Imaging/tests-ms.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -if [ $# -eq 0 ]; then - echo "You should give a list of test names such as: " - echo "$0 System.Drawing.TestStringFormat" - echo "or" - echo "$0 all" - exit 1 -fi - -export MSNet=Yes -cp ../../System.Drawing_test.dll . -topdir=../../../.. -NUNITCONSOLE=$topdir/class/lib/nunit-console.exe -MONO_PATH=$topdir/nunit20:$topdir/class/lib:. - -for i in $@; do - if [ "$i" = "all" ]; then - fixture="" - else - fixture="/fixture:MonoTests.${i}" - fi - MONO_PATH=$MONO_PATH \ - ${NUNITCONSOLE} System.Drawing_test.dll $fixture -done - - - diff --git a/mcs/class/System.Drawing/Test/System.Drawing.Imaging/tests.sh b/mcs/class/System.Drawing/Test/System.Drawing.Imaging/tests.sh deleted file mode 100755 index 511cfcd6ee6..00000000000 --- a/mcs/class/System.Drawing/Test/System.Drawing.Imaging/tests.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -if [ $# -eq 0 ]; then - echo "You should give a list of test names such as: " - echo "$0 System.Drawing.TestStringFormat" - echo "or" - echo "$0 all" - exit 1 -fi - -cp ../../System.Drawing_test_default.dll . - -topdir=../../../.. -NUNITCONSOLE=$topdir/class/lib/default/nunit-console.exe -MONO_PATH=$topdir/nunit20:$topdir/class/lib/default:. - - -for i in $@; do - if [ "$i" = "all" ]; then - fixture="" - else - fixture="/fixture:MonoTests.${i}" - fi - MONO_PATH=$MONO_PATH \ - mono --debug ${NUNITCONSOLE} System.Drawing_test_default.dll $fixture -done - - - diff --git a/mcs/class/System.Drawing/Test/System.Drawing/README b/mcs/class/System.Drawing/Test/System.Drawing/README deleted file mode 100644 index 957903d11bb..00000000000 --- a/mcs/class/System.Drawing/Test/System.Drawing/README +++ /dev/null @@ -1,12 +0,0 @@ -README - -* To run the tests using the Mono rutime - -cd mcs/class/System.Drawing -make run-test - -* test-ms.sh runs the test using the MS .Net runtime and stores the bimaps -created by tests in the directory called MsNet. - - - diff --git a/mcs/class/System.Drawing/Test/System.Drawing/tests-ms.sh b/mcs/class/System.Drawing/Test/System.Drawing/tests-ms.sh deleted file mode 100755 index 6e17f270393..00000000000 --- a/mcs/class/System.Drawing/Test/System.Drawing/tests-ms.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -if [ $# -eq 0 ]; then - echo "You should give a list of test names such as: " - echo "$0 System.Drawing.TestStringFormat" - echo "or" - echo "$0 all" - exit 1 -fi - -export MSNet=Yes -cp ../../System.Drawing_test_default.dll . -topdir=../../../.. -NUNITCONSOLE=$topdir/class/lib/default/nunit-console.exe -MONO_PATH=$topdir/nunit20:$topdir/class/lib:. - -for i in $@; do - if [ "$i" = "all" ]; then - fixture="" - else - fixture="/fixture:MonoTests.${i}" - fi - MONO_PATH=$MONO_PATH \ - ${NUNITCONSOLE} System.Drawing_test_default.dll $fixture -done - - - diff --git a/mcs/class/System.Drawing/Test/System.Drawing/tests.sh b/mcs/class/System.Drawing/Test/System.Drawing/tests.sh deleted file mode 100755 index 511cfcd6ee6..00000000000 --- a/mcs/class/System.Drawing/Test/System.Drawing/tests.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -if [ $# -eq 0 ]; then - echo "You should give a list of test names such as: " - echo "$0 System.Drawing.TestStringFormat" - echo "or" - echo "$0 all" - exit 1 -fi - -cp ../../System.Drawing_test_default.dll . - -topdir=../../../.. -NUNITCONSOLE=$topdir/class/lib/default/nunit-console.exe -MONO_PATH=$topdir/nunit20:$topdir/class/lib/default:. - - -for i in $@; do - if [ "$i" = "all" ]; then - fixture="" - else - fixture="/fixture:MonoTests.${i}" - fi - MONO_PATH=$MONO_PATH \ - mono --debug ${NUNITCONSOLE} System.Drawing_test_default.dll $fixture -done - - - diff --git a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests-ms.sh b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests-ms.sh deleted file mode 100755 index d30fb697ca8..00000000000 --- a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests-ms.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -if [ $# -eq 0 ]; then - echo "You should give a list of test names such as: " - echo "$0 System.Windows.Forms.ListViewItemTest" - echo "or" - echo "$0 all" - exit 1 -fi - -export MSNet=Yes -cp ../../System.Windows.Forms_test_default.dll . -topdir=../../../.. -NUNITCONSOLE=$topdir/class/lib/default/nunit-console.exe -MONO_PATH=$topdir/nunit20:$topdir/class/lib:. - -for i in $@; do - if [ "$i" = "all" ]; then - fixture="" - else - fixture="/fixture:MonoTests.${i}" - fi - MONO_PATH=$MONO_PATH \ - ${NUNITCONSOLE} System.Windows.Forms_test_default.dll $fixture -done - - - diff --git a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests-ms2.sh b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests-ms2.sh deleted file mode 100644 index 4e5dd142da1..00000000000 --- a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests-ms2.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -if [ $# -eq 0 ]; then - echo "You should give a list of test names such as: " - echo "$0 System.Windows.Forms.ListViewItemTest" - echo "or" - echo "$0 all" - exit 1 -fi - -export MSNet=Yes -cp ../../System.Windows.Forms_test_NET_2_0.dll . -topdir=../../../.. -NUNITCONSOLE=$topdir/class/lib/net_2_0/nunit-console.exe -MONO_PATH=$topdir/nunit20:$topdir/class/lib/net_2_0:. - -for i in $@; do - if [ "$i" = "all" ]; then - fixture="" - else - fixture="/fixture:MonoTests.${i}" - fi - MONO_PATH=$MONO_PATH \ - ${NUNITCONSOLE} System.Windows.Forms_test_NET_2_0.dll $fixture -done \ No newline at end of file diff --git a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests.sh b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests.sh deleted file mode 100755 index d440326d899..00000000000 --- a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -if [ $# -eq 0 ]; then - echo "You should give a list of test names such as: " - echo "$0 System.Windows.Forms.ListViewItemTest" - echo "or" - echo "$0 all" - exit 1 -fi - -cp ../../System.Windows.Forms_test_default.dll . - -topdir=../../../.. -NUNITCONSOLE=$topdir/class/lib/default/nunit-console.exe -MONO_PATH=$topdir/nunit20:$topdir/class/lib/default:. - - -for i in $@; do - if [ "$i" = "all" ]; then - fixture="" - else - fixture="/fixture:MonoTests.${i}" - fi - MONO_PATH=$MONO_PATH \ - mono --debug ${NUNITCONSOLE} System.Windows.Forms_test_default.dll $fixture -done - - - diff --git a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests2.sh b/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests2.sh deleted file mode 100644 index 6a01dcb4fd0..00000000000 --- a/mcs/class/System.Windows.Forms/Test/System.Windows.Forms/tests2.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -function usage { -if [ $# -eq 0 ]; then - echo </lib/mono/4.0/mscorlib.dll or Mono.Posix.dll, # so we need to place something there or those tools break. We decided to symlink to the reference assembly for now. # See https://bugzilla.xamarin.com/show_bug.cgi?id=38331 and https://bugzilla.xamarin.com/show_bug.cgi?id=41052 @@ -71,6 +82,7 @@ DISTFILES = \ $(wildcard ../../../external/binary-reference-assemblies/v4.0/*.dll) \ $(wildcard ../../../external/binary-reference-assemblies/v3.5/*.dll) \ $(wildcard ../../../external/binary-reference-assemblies/v2.0/*.dll) \ + $(wildcard ../../../external/binary-reference-assemblies/mono/*.dll) \ $(wildcard ../../../external/binary-reference-assemblies/src/v4.7/Facades/*.cs) \ $(wildcard ../../../external/binary-reference-assemblies/src/v4.6.2/Facades/*.cs) \ $(wildcard ../../../external/binary-reference-assemblies/src/v4.6.1/Facades/*.cs) \ @@ -88,6 +100,7 @@ DISTFILES = \ $(wildcard ../../../external/binary-reference-assemblies/src/v4.0/*.cs) \ $(wildcard ../../../external/binary-reference-assemblies/src/v3.5/*.cs) \ $(wildcard ../../../external/binary-reference-assemblies/src/v2.0/*.cs) \ + $(wildcard ../../../external/binary-reference-assemblies/src/mono/*.cs) \ ../../../external/binary-reference-assemblies/v4.7/Makefile \ ../../../external/binary-reference-assemblies/v4.6.2/Makefile \ ../../../external/binary-reference-assemblies/v4.6.1/Makefile \ @@ -98,6 +111,7 @@ DISTFILES = \ ../../../external/binary-reference-assemblies/v4.0/Makefile \ ../../../external/binary-reference-assemblies/v3.5/Makefile \ ../../../external/binary-reference-assemblies/v2.0/Makefile \ + ../../../external/binary-reference-assemblies/mono/Makefile \ ../../../external/binary-reference-assemblies/Makefile \ Makefile diff --git a/mcs/mcs/settings.cs b/mcs/mcs/settings.cs index f3a7bb79b07..98083a7e0ec 100644 --- a/mcs/mcs/settings.cs +++ b/mcs/mcs/settings.cs @@ -346,7 +346,7 @@ namespace Mono.CSharp { void About () { output.WriteLine ( - "The Mono C# compiler is Copyright 2001-2011, Novell, Inc. 2011-2016 Xamarin Inc, 2016-2017 Microsoft Corp\n\n" + + "The Turbo C# compiler is Copyright 2001-2011, Novell, Inc. 2011-2016 Xamarin Inc, 2016-2017 Microsoft Corp\n\n" + "The compiler source code is released under the terms of the \n" + "MIT X11 or GNU GPL licenses\n\n" + @@ -1603,7 +1603,7 @@ namespace Mono.CSharp { void Usage () { output.WriteLine ( - "Mono C# compiler, Copyright 2001-2011 Novell, Inc., 2011-2016 Xamarin, Inc, 2016-2017 Microsoft Corp\n" + + "Turbo C# compiler, Copyright 2001-2011 Novell, Inc., 2011-2016 Xamarin, Inc, 2016-2017 Microsoft Corp\n" + "mcs [options] source-files\n" + " --about About the Mono C# compiler\n" + " -addmodule:M1[,Mn] Adds the module to the generated assembly\n" + diff --git a/mono/arch/s390x/s390x-codegen.h b/mono/arch/s390x/s390x-codegen.h index 695e318267d..9c3750e213b 100644 --- a/mono/arch/s390x/s390x-codegen.h +++ b/mono/arch/s390x/s390x-codegen.h @@ -1131,6 +1131,7 @@ typedef struct { #define s390_agf(c, r, x, b, d) S390_RXY(c, 0xe318, r, x, b, d) #define s390_agfi(c, r, v) S390_RIL_1(c, 0xc28, r, v) #define s390_afgr(c, r1, r2) S390_RRE(c, 0xb918, r1, r2) +#define s390_agh(c, r, x, b, d) S390_RXY(c, 0xe338, r, b, d) #define s390_aghi(c, r, v) S390_RI(c, 0xa7b, r, v) #define s390_aghik(c, r1, r3, v) S390_RIE_1(c, 0xecd9, r1, r3, v) #define s390_agr(c, r1, r2) S390_RRE(c, 0xb908, r1, r2) @@ -1154,6 +1155,7 @@ typedef struct { #define s390_algfr(c, r1, r2) S390_RRE(c, 0xb91a, r1, r2) #define s390_alghsik(c, r1, r3, v) S390_RIE_1(c, 0xecdb, r1, r3, v) #define s390_algr(c, r1, r2) S390_RRE(c, 0xb90a, r1, r2) +#define s390_algrk(c, r1, r2, r3) S390_RRF_1(c, 0xb9ea, r1, r2, r3) #define s390_algsi(c, d1, b1, i2) S390_SIY_1(c, 0xeb7e, d1, b1, i2) #define s390_alhhhr(c, r1, r2, r3) S390_RRF_1(c, 0xb9ca, r1, r2, r3) #define s390_alhhlr(c, r1, r2, r3) S390_RRF_1(c, 0xb9da, r1, r2, r3) @@ -1172,6 +1174,8 @@ typedef struct { #define s390_basr(c, r1, r2) S390_RR(c, 0x0d, r1, r2) #define s390_bctr(c, r1, r2) S390_RR(c, 0x06, r1, r2) #define s390_bctrg(c, r1, r2) S390_RRE(c, 0xb946, r1, r2) +#define s390_bi(c, x, b, d) S390_RXY(c, 0xe347, S390_CC_UN, x, b, d) +#define s390_bic(c, m, x, b, d) S390_RXY(c, 0xe347, m, x, b, d) #define s390_bnzr(c, r) S390_RR(c, 0x07, 0x07, r) #define s390_bras(c, r, o) S390_RI(c, 0xa75, r, o) #define s390_brasl(c, r, o) S390_RIL_1(c, 0xc05, r, o) @@ -1327,11 +1331,13 @@ typedef struct { #define s390_lgfi(c, r, v) S390_RIL_1(c, 0xc01, r, v) #define s390_lgfrl(c, r1, d) S390_RIL_1(c, 0xc4c, r1, d) #define s390_lgfr(c, r1, r2) S390_RRE(c, 0xb914, r1, r2) +#define s390_lgg(c, r, x, b, d) S390_RXY(c, 0xe34c, r, x, b, d) #define s390_lgh(c, r, x, b, d) S390_RXY(c, 0xe315, r, x, b, d) #define s390_lghi(c, r, v) S390_RI(c, 0xa79, r, v) #define s390_lghr(c, r1, r2) S390_RRE(c, 0xb907, r1, r2) #define s390_lgr(c, r1, r2) S390_RRE(c, 0xb904, r1, r2) #define s390_lgrl(c, r1, d) S390_RIL_1(c, 0xc48, r1, d) +#define s390_lgsc(c, r, x, b, d) S390_RXY(c, 0xe34d, r, x, b, d) #define s390_lh(c, r, x, b, d) S390_RX(c, 0x48, r, x, b, d) #define s390_lhr(c, r1, r2) S390_RRE(c, 0xb927, r1, r2) #define s390_lhg(c, r, x, b, d) S390_RXY(c, 0xe315, r, x, b, d) @@ -1344,6 +1350,7 @@ typedef struct { #define s390_llgfr(c, r1, r2) S390_RRE(c, 0xb916, r1, r2) #define s390_llgh(c, r, x, b, d) S390_RXY(c, 0xe391, r, x, b, d) #define s390_llghr(c, r1, r2) S390_RRE(c, 0xb985, r1, r2) +#define s390_llgfsg(c, r, x, b, d) S390_RXY(c, 0xe348, r, x, b, d) #define s390_llhr(c, r1, r2) S390_RRE(c, 0xb995, r1, r2) #define s390_llihf(c, r, v) S390_RIL_1(c, 0xc0e, r, v) #define s390_llihh(c, r, v) S390_RI(c, 0xa5c, r, v) @@ -1371,15 +1378,19 @@ typedef struct { #define s390_m(c, r, x, b, d) S390_RX(c, 0x5c, r, x, b, d) #define s390_mdbr(c, r1, r2) S390_RRE(c, 0xb31c, r1, r2) #define s390_meebr(c, r1, r2) S390_RRE(c, 0xb317, r1, r2) +#define s390_mg(c, r, x, b, d) S390_RXY(c, 0xe384, r, x, b, d) +#define s390_mgh(c, r, x, b, d) S390_RXY(c, 0xe33c, r, x, b, d) +#define s390_mgrk(c, r1, r2, r3) S390_RRF_1(c, 0xb9ec, r1, r2, r3) #define s390_mfy(c, r, x, b, d) S390_RXY(c, 0xe35c, r, x, b, d) #define s390_mlgr(c, r1, r2) S390_RRE(c, 0xb986, r1, r2) #define s390_mlr(c, r1, r2) S390_RRE(c, 0xb996, r1, r2) #define s390_mr(c, r1, r2) S390_RR(c, 0x1c, r1, r2) #define s390_ms(c, r, x, b, d) S390_RX(c, 0x71, r, x, b, d) -#define s390_msi(c, r, v) S390_RIL_1(c, 0xc21, r, v) +#define s390_msfi(c, r, v) S390_RIL_1(c, 0xc20, r, v) +#define s390_msgfi(c, r, v) S390_RIL_1(c, 0xc21, r, v) #define s390_msgfr(c, r1, r2) S390_RRE(c, 0xb91c, r1, r2) -#define s390_msgi(c, r, v) S390_RIL_1(c, 0xc20, r, v) #define s390_msgr(c, r1, r2) S390_RRE(c, 0xb90c, r1, r2) +#define s390_msgrkc(c, r1, r2, r3) S390_RRF_1(c, 0xb9ed, r1, r2, r3) #define s390_msr(c, r1, r2) S390_RRE(c, 0xb252, r1, r2) #define s390_mvc(c, l, b1, d1, b2, d2) S390_SS_1(c, 0xd2, l, b1, d1, b2, d2) #define s390_mvcl(c, r1, r2) S390_RR(c, 0x0e, r1, r2) @@ -1421,6 +1432,7 @@ typedef struct { #define s390_sebr(c, r1, r2) S390_RRE(c, 0xb30b, r1, r2) #define s390_sg(c, r, x, b, d) S390_RXY(c, 0xe309, r, x, b, d) #define s390_sgf(c, r, x, b, d) S390_RXY(c, 0xe319, r, x, b, d) +#define s390_sgh(c, r, x, b, d) S390_RXY(c, 0xe339, r, x, b, d) #define s390_sgr(c, r1, r2) S390_RRE(c, 0xb909, r1, r2) #define s390_sgrk(c, r1, r2, r3) S390_RRF_1(c, 0xb9e9, r1, r2, r3) #define s390_sl(c, r, x, b, d) S390_RX(c, 0x5f, r, x, b, d) @@ -1437,9 +1449,11 @@ typedef struct { #define s390_slgfr(c, r1, r2) S390_RRE(c, 0xb91b, r1, r2) #define s390_slgfi(c, r, v) S390_RIL_1(c, 0xc24, r, v) #define s390_slgr(c, r1, r2) S390_RRE(c, 0xb90b, r1, r2) +#define s390_slgrk(c, r1, r2, r3) S390_RRF_1(c, 0xb9eb, r1, r2, r3) #define s390_sll(c, r, b, d) S390_RS_3(c, 0x89, r, b, d) #define s390_sllg(c, r1, r2, b, d) S390_RSY_1(c, 0xeb0d, r1, r2, b, d) #define s390_slr(c, r1, r2) S390_RR(c, 0x1f, r1, r2) +#define s390_slrk(c, r1, r2, r3) S390_RRF_1(c, 0xb9fb, r1, r2, r3) #define s390_sqdbr(c, r1, r2) S390_RRE(c, 0xb315, r1, r2) #define s390_sqebr(c, r1, r2) S390_RRE(c, 0xb314, r1, r2) #define s390_sra(c, r, b, d) S390_RS_3(c, 0x8a, r, b, d) @@ -1447,6 +1461,7 @@ typedef struct { #define s390_sr(c, r1, r2) S390_RR(c, 0x1b, r1, r2) #define s390_srda(c, r, b, d) S390_RS_3(c, 0x8e, r, b, d) #define s390_srdl(c, r, b, d) S390_RS_3(c, 0x8c, r, b, d) +#define s390_srk(c, r1, r2, r3) S390_RRF_1(c, 0xb9f9, r1, r2, r3) #define s390_srl(c, r, b, d) S390_RS_3(c, 0x88, r, b, d) #define s390_srlg(c, r1, r2, b, d) S390_RSY_1(c, 0xeb0c, r1, r2, b, d) #define s390_st(c, r, x, b, d) S390_RX(c, 0x50, r, x, b, d) @@ -1461,6 +1476,7 @@ typedef struct { #define s390_stey(c, r, x, b, d) S390_RXY(c, 0xed66, r, x, b, d) #define s390_stfpc(c, b, d) S390_S(c, 0xb29c, b, d) #define s390_stg(c, r, x, b, d) S390_RXY(c, 0xe324, r, x, b, d) +#define s390_stgsc(c, r, x, b, d) S390_RXY(c, 0xe349, r, x, b, d) #define s390_sth(c, r, x, b, d) S390_RX(c, 0x40, r, x, b, d) #define s390_sthy(c, r, x, b, d) S390_RXY(c, 0xe370, r, x, b, d) #define s390_stm(c, r1, r2, b, d) S390_RS_1(c, 0x90, r1, r2, b, d) diff --git a/mono/eglib/eglib-config.h.in b/mono/eglib/eglib-config.h.in index 71797575e68..26e48fd3490 100644 --- a/mono/eglib/eglib-config.h.in +++ b/mono/eglib/eglib-config.h.in @@ -37,6 +37,11 @@ typedef signed @GSIZE@ gssize; #define G_BREAKPOINT() #endif +#if defined (HOST_WASM) +#undef G_BREAKPOINT +#define G_BREAKPOINT() do { printf ("MONO: BREAKPOINT\n"); abort (); } while (0) +#endif + typedef @PIDTYPE@ GPid; #endif diff --git a/mono/eglib/gpath.c b/mono/eglib/gpath.c index 59f5923125b..21e77704603 100644 --- a/mono/eglib/gpath.c +++ b/mono/eglib/gpath.c @@ -160,7 +160,8 @@ g_path_get_basename (const char *filename) return g_strdup (&r[1]); } -#ifndef HAVE_STRTOK_R +//wasm does have strtok_r even though autoconf fails to find +#if !defined (HAVE_STRTOK_R) && !defined (HOST_WASM) // This is from BSD's strtok_r char * diff --git a/mono/metadata/boehm-gc.c b/mono/metadata/boehm-gc.c index 33ccf029416..482a7425d03 100644 --- a/mono/metadata/boehm-gc.c +++ b/mono/metadata/boehm-gc.c @@ -278,7 +278,7 @@ void mono_gc_collect (int generation) { #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_induced++; + InterlockedIncrement (&mono_perfcounters->gc_induced); #endif GC_gcollect (); } @@ -457,7 +457,7 @@ on_gc_notification (GC_EventType event) MONO_GC_BEGIN (1); #ifndef DISABLE_PERFCOUNTERS if (mono_perfcounters) - mono_perfcounters->gc_collections0++; + InterlockedIncrement (&mono_perfcounters->gc_collections0); #endif InterlockedIncrement (&gc_stats.major_gc_count); gc_start_time = mono_100ns_ticks (); @@ -477,10 +477,11 @@ on_gc_notification (GC_EventType event) if (mono_perfcounters) { guint64 heap_size = GC_get_heap_size (); guint64 used_size = heap_size - GC_get_free_bytes (); - mono_perfcounters->gc_total_bytes = used_size; - mono_perfcounters->gc_committed_bytes = heap_size; - mono_perfcounters->gc_reserved_bytes = heap_size; - mono_perfcounters->gc_gen0size = heap_size; + /* FIXME: change these to InterlockedWrite64 () */ + UnlockedWrite64 (&mono_perfcounters->gc_total_bytes, used_size); + UnlockedWrite64 (&mono_perfcounters->gc_committed_bytes, heap_size); + UnlockedWrite64 (&mono_perfcounters->gc_reserved_bytes, heap_size); + UnlockedWrite64 (&mono_perfcounters->gc_gen0size, heap_size); } #endif UnlockedAdd64 (&gc_stats.major_gc_time, mono_100ns_ticks () - gc_start_time); @@ -522,9 +523,10 @@ on_gc_heap_resize (size_t new_size) guint64 heap_size = GC_get_heap_size (); #ifndef DISABLE_PERFCOUNTERS if (mono_perfcounters) { - mono_perfcounters->gc_committed_bytes = heap_size; - mono_perfcounters->gc_reserved_bytes = heap_size; - mono_perfcounters->gc_gen0size = heap_size; + /* FIXME: change these to InterlockedWrite64 () */ + UnlockedWrite64 (&mono_perfcounters->gc_committed_bytes, heap_size); + UnlockedWrite64 (&mono_perfcounters->gc_reserved_bytes, heap_size); + UnlockedWrite64 (&mono_perfcounters->gc_gen0size, heap_size); } #endif @@ -1736,7 +1738,7 @@ alloc_handle (HandleData *handles, MonoObject *obj, gboolean track) } #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_num_handles++; + InterlockedIncrement (&mono_perfcounters->gc_num_handles); #endif unlock_handles (handles); res = MONO_GC_HANDLE (slot, handles->type); @@ -1934,7 +1936,7 @@ mono_gchandle_free (guint32 gchandle) /* print a warning? */ } #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_num_handles--; + InterlockedDecrement (&mono_perfcounters->gc_num_handles); #endif /*g_print ("freed entry %d of type %d\n", slot, handles->type);*/ unlock_handles (handles); diff --git a/mono/metadata/class-internals.h b/mono/metadata/class-internals.h index 67f360e975e..2b3a0b42aa3 100644 --- a/mono/metadata/class-internals.h +++ b/mono/metadata/class-internals.h @@ -792,78 +792,78 @@ typedef struct { */ typedef struct { /* JIT category */ - guint32 jit_methods; - guint32 jit_bytes; - guint32 jit_time; - guint32 jit_failures; + gint32 jit_methods; + gint32 jit_bytes; + gint32 jit_time; + gint32 jit_failures; /* Exceptions category */ - guint32 exceptions_thrown; - guint32 exceptions_filters; - guint32 exceptions_finallys; - guint32 exceptions_depth; - guint32 aspnet_requests_queued; - guint32 aspnet_requests; + gint32 exceptions_thrown; + gint32 exceptions_filters; + gint32 exceptions_finallys; + gint32 exceptions_depth; + gint32 aspnet_requests_queued; + gint32 aspnet_requests; /* Memory category */ - guint32 gc_collections0; - guint32 gc_collections1; - guint32 gc_collections2; - guint32 gc_promotions0; - guint32 gc_promotions1; - guint32 gc_promotion_finalizers; - guint32 gc_gen0size; - guint32 gc_gen1size; - guint32 gc_gen2size; - guint32 gc_lossize; - guint32 gc_fin_survivors; - guint32 gc_num_handles; - guint32 gc_allocated; - guint32 gc_induced; - guint32 gc_time; - guint32 gc_total_bytes; - guint32 gc_committed_bytes; - guint32 gc_reserved_bytes; - guint32 gc_num_pinned; - guint32 gc_sync_blocks; + gint32 gc_collections0; + gint32 gc_collections1; + gint32 gc_collections2; + gint32 gc_promotions0; + gint32 gc_promotions1; + gint32 gc_promotion_finalizers; + gint64 gc_gen0size; + gint64 gc_gen1size; + gint64 gc_gen2size; + gint32 gc_lossize; + gint32 gc_fin_survivors; + gint32 gc_num_handles; + gint32 gc_allocated; + gint32 gc_induced; + gint32 gc_time; + gint64 gc_total_bytes; + gint64 gc_committed_bytes; + gint64 gc_reserved_bytes; + gint32 gc_num_pinned; + gint32 gc_sync_blocks; /* Remoting category */ - guint32 remoting_calls; - guint32 remoting_channels; - guint32 remoting_proxies; - guint32 remoting_classes; - guint32 remoting_objects; - guint32 remoting_contexts; + gint32 remoting_calls; + gint32 remoting_channels; + gint32 remoting_proxies; + gint32 remoting_classes; + gint32 remoting_objects; + gint32 remoting_contexts; /* Loader category */ - guint32 loader_classes; - guint32 loader_total_classes; - guint32 loader_appdomains; - guint32 loader_total_appdomains; - guint32 loader_assemblies; - guint32 loader_total_assemblies; - guint32 loader_failures; - guint32 loader_bytes; - guint32 loader_appdomains_uloaded; + gint32 loader_classes; + gint32 loader_total_classes; + gint32 loader_appdomains; + gint32 loader_total_appdomains; + gint32 loader_assemblies; + gint32 loader_total_assemblies; + gint32 loader_failures; + gint32 loader_bytes; + gint32 loader_appdomains_uloaded; /* Threads and Locks category */ - guint32 thread_contentions; - guint32 thread_queue_len; - guint32 thread_queue_max; - guint32 thread_num_logical; - guint32 thread_num_physical; - guint32 thread_cur_recognized; - guint32 thread_num_recognized; + gint32 thread_contentions; + gint32 thread_queue_len; + gint32 thread_queue_max; + gint32 thread_num_logical; + gint32 thread_num_physical; + gint32 thread_cur_recognized; + gint32 thread_num_recognized; /* Interop category */ - guint32 interop_num_ccw; - guint32 interop_num_stubs; - guint32 interop_num_marshals; + gint32 interop_num_ccw; + gint32 interop_num_stubs; + gint32 interop_num_marshals; /* Security category */ - guint32 security_num_checks; - guint32 security_num_link_checks; - guint32 security_time; - guint32 security_depth; - guint32 unused; + gint32 security_num_checks; + gint32 security_num_link_checks; + gint32 security_time; + gint32 security_depth; + gint32 unused; /* Threadpool */ - guint64 threadpool_workitems; - guint64 threadpool_ioworkitems; - guint threadpool_threads; - guint threadpool_iothreads; + gint64 threadpool_workitems; + gint64 threadpool_ioworkitems; + gint32 threadpool_threads; + gint32 threadpool_iothreads; } MonoPerfCounters; extern MonoPerfCounters *mono_perfcounters; diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c index de2a6970f73..b0e7068104d 100644 --- a/mono/metadata/domain.c +++ b/mono/metadata/domain.c @@ -430,8 +430,8 @@ mono_domain_create (void) mono_appdomains_unlock (); #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_appdomains++; - mono_perfcounters->loader_total_appdomains++; + InterlockedIncrement (&mono_perfcounters->loader_appdomains); + InterlockedIncrement (&mono_perfcounters->loader_total_appdomains); #endif mono_debug_domain_create (domain); @@ -1171,7 +1171,8 @@ mono_domain_free (MonoDomain *domain, gboolean force) mono_code_manager_invalidate (domain->code_mp); } else { #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes -= mono_mempool_get_allocated (domain->mp); + /* FIXME: use an explicit subtraction method as soon as it's available */ + InterlockedAdd (&mono_perfcounters->loader_bytes, -1 * mono_mempool_get_allocated (domain->mp)); #endif mono_mempool_destroy (domain->mp); domain->mp = NULL; @@ -1218,7 +1219,7 @@ mono_domain_free (MonoDomain *domain, gboolean force) mono_gc_free_fixed (domain); #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_appdomains--; + InterlockedDecrement (&mono_perfcounters->loader_appdomains); #endif if (domain == mono_root_domain) @@ -1286,7 +1287,7 @@ mono_domain_alloc (MonoDomain *domain, guint size) mono_domain_lock (domain); #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes += size; + InterlockedAdd (&mono_perfcounters->loader_bytes, size); #endif res = mono_mempool_alloc (domain->mp, size); mono_domain_unlock (domain); @@ -1306,7 +1307,7 @@ mono_domain_alloc0 (MonoDomain *domain, guint size) mono_domain_lock (domain); #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes += size; + InterlockedAdd (&mono_perfcounters->loader_bytes, size); #endif res = mono_mempool_alloc0 (domain->mp, size); mono_domain_unlock (domain); diff --git a/mono/metadata/gc.c b/mono/metadata/gc.c index 4b1a56f4c0f..3c78b6153c2 100644 --- a/mono/metadata/gc.c +++ b/mono/metadata/gc.c @@ -995,7 +995,7 @@ mono_gc_cleanup (void) ret = guarded_wait (gc_thread->handle, MONO_INFINITE_WAIT, FALSE); g_assert (ret == MONO_THREAD_INFO_WAIT_RET_SUCCESS_0); - mono_thread_join (GUINT_TO_POINTER (gc_thread->tid)); + mono_threads_add_joinable_thread (GUINT_TO_POINTER (gc_thread->tid)); break; } @@ -1020,7 +1020,7 @@ mono_gc_cleanup (void) g_assert (ret == MONO_THREAD_INFO_WAIT_RET_SUCCESS_0); - mono_thread_join (GUINT_TO_POINTER (gc_thread->tid)); + mono_threads_add_joinable_thread (GUINT_TO_POINTER (gc_thread->tid)); break; } diff --git a/mono/metadata/image.c b/mono/metadata/image.c index 3f4dd249c6d..6ec372bbe9f 100644 --- a/mono/metadata/image.c +++ b/mono/metadata/image.c @@ -2172,7 +2172,8 @@ mono_image_close_finish (MonoImage *image) mono_image_close_all (image->modules, image->module_count); #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes -= mono_mempool_get_allocated (image->mempool); + /* FIXME: use an explicit subtraction method as soon as it's available */ + InterlockedAdd (&mono_perfcounters->loader_bytes, -1 * mono_mempool_get_allocated (image->mempool)); #endif if (!image_is_dynamic (image)) { @@ -2707,7 +2708,7 @@ mono_image_alloc (MonoImage *image, guint size) gpointer res; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes += size; + InterlockedAdd (&mono_perfcounters->loader_bytes, size); #endif mono_image_lock (image); res = mono_mempool_alloc (image->mempool, size); @@ -2722,7 +2723,7 @@ mono_image_alloc0 (MonoImage *image, guint size) gpointer res; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes += size; + InterlockedAdd (&mono_perfcounters->loader_bytes, size); #endif mono_image_lock (image); res = mono_mempool_alloc0 (image->mempool, size); @@ -2737,7 +2738,7 @@ mono_image_strdup (MonoImage *image, const char *s) char *res; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes += strlen (s); + InterlockedAdd (&mono_perfcounters->loader_bytes, strlen (s)); #endif mono_image_lock (image); res = mono_mempool_strdup (image->mempool, s); @@ -2754,7 +2755,7 @@ mono_image_strdup_vprintf (MonoImage *image, const char *format, va_list args) buf = mono_mempool_strdup_vprintf (image->mempool, format, args); mono_image_unlock (image); #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes += strlen (buf); + InterlockedAdd (&mono_perfcounters->loader_bytes, strlen (buf)); #endif return buf; } diff --git a/mono/metadata/loader.c b/mono/metadata/loader.c index 0cd4e07b739..85b5639384b 100644 --- a/mono/metadata/loader.c +++ b/mono/metadata/loader.c @@ -62,10 +62,10 @@ static mono_mutex_t global_loader_data_mutex; static gboolean loader_lock_inited; /* Statistics */ -static guint32 inflated_signatures_size; -static guint32 memberref_sig_cache_size; -static guint32 methods_size; -static guint32 signatures_size; +static gint32 inflated_signatures_size; +static gint32 memberref_sig_cache_size; +static gint32 methods_size; +static gint32 signatures_size; /* * This TLS variable holds how many times the current thread has acquired the loader @@ -75,7 +75,6 @@ MonoNativeTlsKey loader_lock_nest_id; static void dllmap_cleanup (void); - static void global_loader_data_lock (void) { @@ -164,7 +163,7 @@ cache_memberref_sig (MonoImage *image, guint32 sig_idx, gpointer sig) else { g_hash_table_insert (image->memberref_signatures, GUINT_TO_POINTER (sig_idx), sig); /* An approximation based on glib 2.18 */ - memberref_sig_cache_size += sizeof (gpointer) * 4; + InterlockedAdd (&memberref_sig_cache_size, sizeof (gpointer) * 4); } mono_image_unlock (image); @@ -725,7 +724,7 @@ mono_method_get_signature_checked (MonoMethod *method, MonoImage *image, guint32 if (cached != sig) mono_metadata_free_inflated_signature (sig); else - inflated_signatures_size += mono_metadata_signature_size (cached); + InterlockedAdd (&inflated_signatures_size, mono_metadata_signature_size (cached)); sig = cached; } @@ -1655,7 +1654,7 @@ mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass, result = (MonoMethod *)mono_image_alloc0 (image, sizeof (MonoMethodPInvoke)); } else { result = (MonoMethod *)mono_image_alloc0 (image, sizeof (MonoMethod)); - methods_size += sizeof (MonoMethod); + InterlockedAdd (&methods_size, sizeof (MonoMethod)); } InterlockedIncrement (&mono_stats.method_count); @@ -2394,7 +2393,7 @@ mono_method_signature_checked (MonoMethod *m, MonoError *error) if (!mono_error_ok (error)) return NULL; - inflated_signatures_size += mono_metadata_signature_size (signature); + InterlockedAdd (&inflated_signatures_size, mono_metadata_signature_size (signature)); mono_image_lock (img); @@ -2451,7 +2450,7 @@ mono_method_signature_checked (MonoMethod *m, MonoError *error) mono_image_unlock (img); } - signatures_size += mono_metadata_signature_size (signature); + InterlockedAdd (&signatures_size, mono_metadata_signature_size (signature)); } /* Verify metadata consistency */ diff --git a/mono/metadata/metadata.c b/mono/metadata/metadata.c index 0ba52ce0b73..7b31abe9bb9 100644 --- a/mono/metadata/metadata.c +++ b/mono/metadata/metadata.c @@ -31,9 +31,10 @@ #include #include #include +#include #include -static int img_set_cache_hit, img_set_cache_miss, img_set_count; +static gint32 img_set_cache_hit, img_set_cache_miss, img_set_count; /* Auxiliary structure used for caching inflated signatures */ @@ -2478,10 +2479,10 @@ img_set_cache_get (MonoImage **images, int nimages) int index = hash_code % HASH_TABLE_SIZE; MonoImageSet *img = img_set_cache [index]; if (!img || !compare_img_set (img, images, nimages)) { - ++img_set_cache_miss; + UnlockedIncrement (&img_set_cache_miss); return NULL; } - ++img_set_cache_hit; + UnlockedIncrement (&img_set_cache_hit); return img; } @@ -2566,7 +2567,7 @@ get_image_set (MonoImage **images, int nimages) l = l->next; } - // If we iterated all the way through l without breaking, the imageset does not already exist and we shuold create it + // If we iterated all the way through l without breaking, the imageset does not already exist and we should create it if (!l) { set = g_new0 (MonoImageSet, 1); set->nimages = nimages; @@ -2583,7 +2584,7 @@ get_image_set (MonoImage **images, int nimages) set->images [i]->image_sets = g_slist_prepend (set->images [i]->image_sets, set); g_ptr_array_add (image_sets, set); - ++img_set_count; + UnlockedIncrement (&img_set_count); /* locked by image_sets_lock () */ } /* Cache the set. If there was a cache collision, the previously cached value will be replaced. */ diff --git a/mono/metadata/monitor.c b/mono/metadata/monitor.c index 702a47c654f..c371f0f3c47 100644 --- a/mono/metadata/monitor.c +++ b/mono/metadata/monitor.c @@ -373,7 +373,7 @@ mon_finalize (MonoThreadsSync *mon) mon->data = monitor_freelist; monitor_freelist = mon; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_sync_blocks--; + InterlockedDecrement (&mono_perfcounters->gc_sync_blocks); #endif } @@ -445,7 +445,7 @@ mon_new (gsize id) new_->data = NULL; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_sync_blocks++; + InterlockedIncrement (&mono_perfcounters->gc_sync_blocks); #endif return new_; } @@ -792,7 +792,7 @@ retry: /* The object must be locked by someone else... */ #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->thread_contentions++; + InterlockedIncrement (&mono_perfcounters->thread_contentions); #endif /* If ms is 0 we don't block, but just fail straight away */ @@ -874,8 +874,8 @@ retry_contended: waitms = ms; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->thread_queue_len++; - mono_perfcounters->thread_queue_max++; + InterlockedIncrement (&mono_perfcounters->thread_queue_len); + InterlockedIncrement (&mono_perfcounters->thread_queue_max); #endif thread = mono_thread_internal_current (); @@ -909,7 +909,7 @@ retry_contended: done_waiting: #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->thread_queue_len--; + InterlockedDecrement (&mono_perfcounters->thread_queue_len); #endif if (wait_ret == MONO_SEM_TIMEDWAIT_RET_ALERTED && !allow_interruption) { diff --git a/mono/metadata/mono-perfcounters-def.h b/mono/metadata/mono-perfcounters-def.h index c72b708532a..3a4dbc89110 100644 --- a/mono/metadata/mono-perfcounters-def.h +++ b/mono/metadata/mono-perfcounters-def.h @@ -59,18 +59,18 @@ PERFCTR_COUNTER(GC_PROM1, "Promoted Memory from Gen 1", "", NumberOfItems32, gc_ PERFCTR_COUNTER(GC_PROM0SEC, "Gen 0 Promoted Bytes/Sec", "", RateOfCountsPerSecond32, gc_promotions0) PERFCTR_COUNTER(GC_PROM1SEC, "Gen 1 Promoted Bytes/Sec", "", RateOfCountsPerSecond32, gc_promotions1) PERFCTR_COUNTER(GC_PROMFIN, "Promoted Finalization-Memory from Gen 0", "", NumberOfItems32, gc_promotion_finalizers) -PERFCTR_COUNTER(GC_GEN0SIZE, "Gen 0 heap size", "", NumberOfItems32, gc_gen0size) -PERFCTR_COUNTER(GC_GEN1SIZE, "Gen 1 heap size", "", NumberOfItems32, gc_gen1size) -PERFCTR_COUNTER(GC_GEN2SIZE, "Gen 2 heap size", "", NumberOfItems32, gc_gen2size) +PERFCTR_COUNTER(GC_GEN0SIZE, "Gen 0 heap size", "", NumberOfItems64, gc_gen0size) +PERFCTR_COUNTER(GC_GEN1SIZE, "Gen 1 heap size", "", NumberOfItems64, gc_gen1size) +PERFCTR_COUNTER(GC_GEN2SIZE, "Gen 2 heap size", "", NumberOfItems64, gc_gen2size) PERFCTR_COUNTER(GC_LOSIZE, "Large Object Heap size", "", NumberOfItems32, gc_lossize) PERFCTR_COUNTER(GC_FINSURV, "Finalization Survivors", "", NumberOfItems32, gc_fin_survivors) PERFCTR_COUNTER(GC_NHANDLES, "# GC Handles", "", NumberOfItems32, gc_num_handles) PERFCTR_COUNTER(GC_BYTESSEC, "Allocated Bytes/sec", "", RateOfCountsPerSecond32, gc_allocated) PERFCTR_COUNTER(GC_INDGC, "# Induced GC", "", NumberOfItems32, gc_induced) PERFCTR_COUNTER(GC_PERCTIME, "% Time in GC", "", RawFraction, gc_time) -PERFCTR_COUNTER(GC_BYTES, "# Bytes in all Heaps", "", NumberOfItems32, gc_total_bytes) -PERFCTR_COUNTER(GC_COMMBYTES, "# Total committed Bytes", "", NumberOfItems32, gc_committed_bytes) -PERFCTR_COUNTER(GC_RESBYTES, "# Total reserved Bytes", "", NumberOfItems32, gc_reserved_bytes) +PERFCTR_COUNTER(GC_BYTES, "# Bytes in all Heaps", "", NumberOfItems64, gc_total_bytes) +PERFCTR_COUNTER(GC_COMMBYTES, "# Total committed Bytes", "", NumberOfItems64, gc_committed_bytes) +PERFCTR_COUNTER(GC_RESBYTES, "# Total reserved Bytes", "", NumberOfItems64, gc_reserved_bytes) PERFCTR_COUNTER(GC_PINNED, "# of Pinned Objects", "", NumberOfItems32, gc_num_pinned) PERFCTR_COUNTER(GC_SYNKB, "# of Sink Blocks in use", "", NumberOfItems32, gc_sync_blocks) diff --git a/mono/metadata/mono-perfcounters.c b/mono/metadata/mono-perfcounters.c index f4ec3e34c2b..1a3123a30aa 100644 --- a/mono/metadata/mono-perfcounters.c +++ b/mono/metadata/mono-perfcounters.c @@ -48,6 +48,7 @@ #include "utils/mono-networkinterfaces.h" #include "utils/mono-error-internals.h" #include "utils/atomic.h" +#include "utils/unlocked.h" /* map of CounterSample.cs */ struct _MonoCounterSample { @@ -1073,52 +1074,52 @@ predef_writable_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounter case CATEGORY_EXC: switch (id) { case COUNTER_EXC_THROWN: - sample->rawValue = mono_perfcounters->exceptions_thrown; + sample->rawValue = InterlockedRead (&mono_perfcounters->exceptions_thrown); return TRUE; } break; case CATEGORY_ASPNET: switch (id) { case COUNTER_ASPNET_REQ_Q: - sample->rawValue = mono_perfcounters->aspnet_requests_queued; + sample->rawValue = InterlockedRead (&mono_perfcounters->aspnet_requests_queued); return TRUE; case COUNTER_ASPNET_REQ_TOTAL: - sample->rawValue = mono_perfcounters->aspnet_requests; + sample->rawValue = InterlockedRead (&mono_perfcounters->aspnet_requests); return TRUE; } break; case CATEGORY_THREADPOOL: switch (id) { case COUNTER_THREADPOOL_WORKITEMS: - sample->rawValue = mono_perfcounters->threadpool_workitems; + sample->rawValue = InterlockedRead64 (&mono_perfcounters->threadpool_workitems); return TRUE; case COUNTER_THREADPOOL_IOWORKITEMS: - sample->rawValue = mono_perfcounters->threadpool_ioworkitems; + sample->rawValue = InterlockedRead64 (&mono_perfcounters->threadpool_ioworkitems); return TRUE; case COUNTER_THREADPOOL_THREADS: - sample->rawValue = mono_perfcounters->threadpool_threads; + sample->rawValue = InterlockedRead (&mono_perfcounters->threadpool_threads); return TRUE; case COUNTER_THREADPOOL_IOTHREADS: - sample->rawValue = mono_perfcounters->threadpool_iothreads; + sample->rawValue = InterlockedRead (&mono_perfcounters->threadpool_iothreads); return TRUE; } break; case CATEGORY_JIT: switch (id) { case COUNTER_JIT_BYTES: - sample->rawValue = mono_perfcounters->jit_bytes; + sample->rawValue = InterlockedRead (&mono_perfcounters->jit_bytes); return TRUE; case COUNTER_JIT_METHODS: - sample->rawValue = mono_perfcounters->jit_methods; + sample->rawValue = InterlockedRead (&mono_perfcounters->jit_methods); return TRUE; case COUNTER_JIT_TIME: - sample->rawValue = mono_perfcounters->jit_time; + sample->rawValue = InterlockedRead (&mono_perfcounters->jit_time); return TRUE; case COUNTER_JIT_BYTES_PSEC: - sample->rawValue = mono_perfcounters->jit_bytes; + sample->rawValue = InterlockedRead (&mono_perfcounters->jit_bytes); return TRUE; case COUNTER_JIT_FAILURES: - sample->rawValue = mono_perfcounters->jit_failures; + sample->rawValue = InterlockedRead (&mono_perfcounters->jit_failures); return TRUE; } break; @@ -1129,7 +1130,7 @@ predef_writable_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounter static gint64 predef_writable_update (ImplVtable *vtable, MonoBoolean do_incr, gint64 value) { - guint32 *volatile ptr = NULL; + gint32 *volatile ptr = NULL; gint64 *volatile ptr64 = NULL; int cat_id = GPOINTER_TO_INT (vtable->arg); int id = cat_id >> 16; @@ -1143,8 +1144,8 @@ predef_writable_update (ImplVtable *vtable, MonoBoolean do_incr, gint64 value) break; case CATEGORY_THREADPOOL: switch (id) { - case COUNTER_THREADPOOL_WORKITEMS: ptr64 = (gint64 *) &mono_perfcounters->threadpool_workitems; break; - case COUNTER_THREADPOOL_IOWORKITEMS: ptr64 = (gint64 *) &mono_perfcounters->threadpool_ioworkitems; break; + case COUNTER_THREADPOOL_WORKITEMS: ptr64 = &mono_perfcounters->threadpool_workitems; break; + case COUNTER_THREADPOOL_IOWORKITEMS: ptr64 = &mono_perfcounters->threadpool_ioworkitems; break; case COUNTER_THREADPOOL_THREADS: ptr = &mono_perfcounters->threadpool_threads; break; case COUNTER_THREADPOOL_IOTHREADS: ptr = &mono_perfcounters->threadpool_iothreads; break; } @@ -1153,29 +1154,23 @@ predef_writable_update (ImplVtable *vtable, MonoBoolean do_incr, gint64 value) if (ptr) { if (do_incr) { if (value == 1) - return InterlockedIncrement ((gint32 *) ptr); /* FIXME: sign */ + return InterlockedIncrement (ptr); if (value == -1) - return InterlockedDecrement ((gint32 *) ptr); /* FIXME: sign */ + return InterlockedDecrement (ptr); - *ptr += value; - return *ptr; + return InterlockedAdd(ptr, value); } /* this can be non-atomic */ *ptr = value; return value; } else if (ptr64) { if (do_incr) { - /* FIXME: we need to do this atomically */ - /* No InterlockedIncrement64() yet */ - /* if (value == 1) - return InterlockedIncrement64 (ptr); + return UnlockedIncrement64 (ptr64); /* FIXME: use InterlockedIncrement64 () */ if (value == -1) - return InterlockedDecrement64 (ptr); - */ + return UnlockedDecrement64 (ptr64); /* FIXME: use InterlockedDecrement64 () */ - *ptr64 += value; - return *ptr64; + return UnlockedAdd64 (ptr64, value); /* FIXME: use InterlockedAdd64 () */ } /* this can be non-atomic */ *ptr64 = value; diff --git a/mono/metadata/null-gc-handles.c b/mono/metadata/null-gc-handles.c index caa0616464d..8bad1701b25 100644 --- a/mono/metadata/null-gc-handles.c +++ b/mono/metadata/null-gc-handles.c @@ -220,7 +220,7 @@ alloc_handle (HandleData *handles, MonoObject *obj, gboolean track) } #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_num_handles++; + InterlockedIncrement (&mono_perfcounters->gc_num_handles); #endif unlock_handles (handles); res = MONO_GC_HANDLE (slot, handles->type); @@ -412,7 +412,7 @@ mono_gchandle_free (guint32 gchandle) /* print a warning? */ } #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_num_handles--; + InterlockedDecrement (&mono_perfcounters->gc_num_handles); #endif /*g_print ("freed entry %d of type %d\n", slot, handles->type);*/ unlock_handles (handles); diff --git a/mono/metadata/object.c b/mono/metadata/object.c index 4ebc52bca25..2ea88c75f8c 100644 --- a/mono/metadata/object.c +++ b/mono/metadata/object.c @@ -2565,7 +2565,7 @@ mono_remote_class (MonoDomain *domain, MonoStringHandle class_name, MonoClass *p rc->xdomain_vtable = NULL; rc->proxy_class_name = name; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->loader_bytes += mono_string_length (MONO_HANDLE_RAW (class_name)) + 1; + InterlockedAdd (&mono_perfcounters->loader_bytes, mono_string_length (MONO_HANDLE_RAW (class_name)) + 1); #endif g_hash_table_insert (domain->proxy_vtable_hash, key, rc); @@ -5257,8 +5257,9 @@ mono_object_new_checked (MonoDomain *domain, MonoClass *klass, MonoError *error) MonoVTable *vtable; - vtable = mono_class_vtable (domain, klass); - g_assert (vtable); /* FIXME don't swallow the error */ + vtable = mono_class_vtable_full (domain, klass, error); + if (!is_ok (error)) + return NULL; MonoObject *o = mono_object_new_specific_checked (vtable, error); return o; diff --git a/mono/metadata/sgen-client-mono.h b/mono/metadata/sgen-client-mono.h index a5ec02d480e..b163dcfee81 100644 --- a/mono/metadata/sgen-client-mono.h +++ b/mono/metadata/sgen-client-mono.h @@ -297,9 +297,9 @@ sgen_client_binary_protocol_collection_begin (int minor_gc_count, int generation #ifndef DISABLE_PERFCOUNTERS if (generation == GENERATION_NURSERY) - mono_perfcounters->gc_collections0++; + InterlockedIncrement (&mono_perfcounters->gc_collections0); else - mono_perfcounters->gc_collections1++; + InterlockedIncrement (&mono_perfcounters->gc_collections1); #endif } diff --git a/mono/metadata/sgen-mono.c b/mono/metadata/sgen-mono.c index 7f2a233401d..4cd30493fff 100644 --- a/mono/metadata/sgen-mono.c +++ b/mono/metadata/sgen-mono.c @@ -2803,7 +2803,7 @@ void sgen_client_gchandle_created (int handle_type, GCObject *obj, guint32 handle) { #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_num_handles++; + InterlockedIncrement (&mono_perfcounters->gc_num_handles); #endif MONO_PROFILER_RAISE (gc_handle_created, (handle, handle_type, obj)); @@ -2813,7 +2813,7 @@ void sgen_client_gchandle_destroyed (int handle_type, guint32 handle) { #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_num_handles--; + InterlockedDecrement (&mono_perfcounters->gc_num_handles); #endif MONO_PROFILER_RAISE (gc_handle_deleted, (handle, handle_type)); diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 4e29232b785..3eb6b3b623c 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -3049,6 +3049,8 @@ mono_thread_callbacks_init (void) void mono_thread_cleanup (void) { + mono_threads_join_threads (); + #if !defined(RUN_IN_SUBTHREAD) && !defined(HOST_WIN32) /* The main thread must abandon any held mutexes (particularly * important for named mutexes as they are shared across diff --git a/mono/mini/Makefile.am.in b/mono/mini/Makefile.am.in index e33441b6d35..28fb9ee5b8d 100755 --- a/mono/mini/Makefile.am.in +++ b/mono/mini/Makefile.am.in @@ -312,6 +312,12 @@ genmdesc_LDADD = \ $(GLIB_LIBS) \ $(LIBICONV) +wasm_sources = \ + mini-wasm.c \ + mini-wasm.h \ + exceptions-wasm.c \ + tramp-wasm.c + x86_sources = \ mini-x86.c \ mini-x86.h \ @@ -456,6 +462,7 @@ common_sources = \ aot-compiler.h \ aot-compiler.c \ aot-runtime.c \ + aot-runtime-wasm.c \ graph.c \ mini-codegen.c \ mini-exceptions.c \ @@ -541,6 +548,12 @@ endif regtests = $(filter-out $(regtests_DISABLED),$(regtests_UNIVERSAL)) +if WASM +arch_sources = $(wasm_sources) +arch_built=cpu-wasm.h +arch_define=__wasm__ +endif + if X86 arch_sources = $(x86_sources) arch_built=cpu-x86.h @@ -687,12 +700,20 @@ GENMDESC_OPTS= # build dependency for the poor windows users # $(arch_define) is the preprocessor symbol that enables all the opcodes # for the specific platform in mini-ops.h + if CROSS_COMPILING GENMDESC_PRG=perl $(srcdir)/genmdesc.pl $(arch_define) $(srcdir) $(GENMDESC_OPTS) -else !CROSS_COMPILING +else +if WASM +GENMDESC_PRG=perl $(srcdir)/genmdesc.pl $(arch_define) $(srcdir) $(GENMDESC_OPTS) +else GENMDESC_PRG=./genmdesc $(GENMDESC_OPTS) +endif endif !CROSS_COMPILING +cpu-wasm.h: cpu-wasm.md genmdesc$(EXEEXT) + $(GENMDESC_PRG) cpu-wasm.h wasm_desc $(srcdir)/cpu-wasm.md + cpu-x86.h: cpu-x86.md genmdesc$(EXEEXT) $(GENMDESC_PRG) cpu-x86.h x86_desc $(srcdir)/cpu-x86.md @@ -882,6 +903,7 @@ EXTRA_DIST = TestDriver.cs \ TestHelpers.cs \ genmdesc.pl \ $(test_sources) \ + $(wasm_sources) cpu-wasm.md \ $(x86_sources) cpu-x86.md \ $(amd64_sources) cpu-amd64.md \ $(ppc_sources) cpu-ppc.md cpu-ppc64.md \ diff --git a/mono/mini/aot-runtime-wasm.c b/mono/mini/aot-runtime-wasm.c new file mode 100644 index 00000000000..4fb8906941c --- /dev/null +++ b/mono/mini/aot-runtime-wasm.c @@ -0,0 +1,408 @@ +/** + * \file + * WASM AOT runtime + */ + +#include "config.h" + +#include + +#include "mini.h" +#include "interp/interp.h" + +#ifdef TARGET_WASM + +static void +wasm_restore_context (void) +{ + g_error ("wasm_restore_context"); +} + +static void +wasm_call_filter (void) +{ + g_error ("wasm_call_filter"); +} + +static void +wasm_throw_exception (void) +{ + g_error ("wasm_throw_exception"); +} + +static void +wasm_rethrow_exception (void) +{ + g_error ("wasm_rethrow_exception"); +} + +static void +wasm_throw_corlib_exception (void) +{ + g_error ("wasm_throw_corlib_exception"); +} + +static char +type_to_c (MonoType *t) +{ + if (t->byref) + return 'I'; + +handle_enum: + switch (t->type) { + case MONO_TYPE_BOOLEAN: + case MONO_TYPE_CHAR: + case MONO_TYPE_I1: + case MONO_TYPE_U1: + case MONO_TYPE_I2: + case MONO_TYPE_U2: + case MONO_TYPE_I4: + case MONO_TYPE_U4: + case MONO_TYPE_I: + case MONO_TYPE_U: + case MONO_TYPE_PTR: + case MONO_TYPE_SZARRAY: + case MONO_TYPE_CLASS: + case MONO_TYPE_OBJECT: + case MONO_TYPE_STRING: + return 'I'; + case MONO_TYPE_R4: + return 'F'; + case MONO_TYPE_R8: + return 'D'; + break; + case MONO_TYPE_I8: + case MONO_TYPE_U8: + return 'L'; + case MONO_TYPE_VOID: + return 'V'; + case MONO_TYPE_VALUETYPE: + if (t->data.klass->enumtype) { + t = mono_class_enum_basetype (t->data.klass); + goto handle_enum; + } + + return 'I'; + case MONO_TYPE_GENERICINST: + if (t->data.klass->valuetype) + return 'S'; + return 'I'; + default: + g_warning ("CANT TRANSLATE %s", mono_type_full_name (t)); + return 'X'; + } +} + +#if SIZEOF_VOID_P == 4 +#define FIDX(x) ((x) * 2) +#else +#define FIDX(x) (x) +#endif + +static void +wasm_invoke_v (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(void) = target_func; + func (); +} + +static void +wasm_invoke_vi (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a) = target_func; + func (margs->iargs [0]); +} + +static void +wasm_invoke_vii (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, gpointer b) = target_func; + func (margs->iargs [0], margs->iargs [1]); +} + +static void +wasm_invoke_viii (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, gpointer b, gpointer c) = target_func; + func (margs->iargs [0], margs->iargs [1], margs->iargs [2]); +} + +static void +wasm_invoke_viiii (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, gpointer b, gpointer c, gpointer d) = target_func; + func (margs->iargs [0], margs->iargs [1], margs->iargs [2], margs->iargs [3]); +} + +static void +wasm_invoke_viiiii (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, gpointer b, gpointer c, gpointer d, gpointer e) = target_func; + func (margs->iargs [0], margs->iargs [1], margs->iargs [2], margs->iargs [3], margs->iargs [4]); +} + +static void +wasm_invoke_viiiiii (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, gpointer b, gpointer c, gpointer d, gpointer e, gpointer f) = target_func; + func (margs->iargs [0], margs->iargs [1], margs->iargs [2], margs->iargs [3], margs->iargs [4], margs->iargs [5]); +} + +static void +wasm_invoke_i (void *target_func, InterpMethodArguments *margs) +{ + int (*func)(void) = target_func; + int res = func (); + *(int*)margs->retval = res; +} + +static void +wasm_invoke_ii (void *target_func, InterpMethodArguments *margs) +{ + int (*func)(gpointer a) = target_func; + int res = func (margs->iargs [0]); + *(int*)margs->retval = res; +} + +static void +wasm_invoke_iii (void *target_func, InterpMethodArguments *margs) +{ + int (*func)(gpointer a, gpointer b) = target_func; + int res = func (margs->iargs [0], margs->iargs [1]); + *(int*)margs->retval = res; +} + +static void +wasm_invoke_iiii (void *target_func, InterpMethodArguments *margs) +{ + int (*func)(gpointer a, gpointer b, gpointer c) = target_func; + int res = func (margs->iargs [0], margs->iargs [1], margs->iargs [2]); + *(int*)margs->retval = res; +} + +static void +wasm_invoke_iiiii (void *target_func, InterpMethodArguments *margs) +{ + int (*func)(gpointer a, gpointer b, gpointer c, gpointer d) = target_func; + int res = func (margs->iargs [0], margs->iargs [1], margs->iargs [2], margs->iargs [3]); + *(int*)margs->retval = res; +} + +static void +wasm_invoke_iiiiii (void *target_func, InterpMethodArguments *margs) +{ + int (*func)(gpointer a, gpointer b, gpointer c, gpointer d, gpointer e) = target_func; + int res = func (margs->iargs [0], margs->iargs [1], margs->iargs [2], margs->iargs [3], margs->iargs [4]); + *(int*)margs->retval = res; +} + +typedef union { + gint64 l; + struct { + gint32 lo; + gint32 hi; + } pair; +} interp_pair; + +static void +wasm_invoke_ll (void *target_func, InterpMethodArguments *margs) +{ + gint64 (*func)(gint64 a) = target_func; + + interp_pair p; + p.pair.lo = (gint32)margs->iargs [0]; + p.pair.hi = (gint32)margs->iargs [1]; + + gint64 res = func (p.l); + *(gint64*)margs->retval = res; +} + +static void +wasm_invoke_li (void *target_func, InterpMethodArguments *margs) +{ + gint64 (*func)(gpointer a) = target_func; + gint64 res = func (margs->iargs [0]); + *(gint64*)margs->retval = res; +} + +static void +wasm_invoke_lil (void *target_func, InterpMethodArguments *margs) +{ + gint64 (*func)(gpointer a, gint64 b) = target_func; + + interp_pair p; + p.pair.lo = (gint32)margs->iargs [1]; + p.pair.hi = (gint32)margs->iargs [2]; + + gint64 res = func (margs->iargs [0], p.l); + *(gint64*)margs->retval = res; +} + +static void +wasm_invoke_dd (void *target_func, InterpMethodArguments *margs) +{ + double (*func)(double a) = target_func; + + double res = func (margs->fargs [FIDX (0)]); + *(double*)margs->retval = res; +} + +static void +wasm_invoke_ddd (void *target_func, InterpMethodArguments *margs) +{ + double (*func)(double a, double b) = target_func; + + double res = func (margs->fargs [FIDX (0)], margs->fargs [FIDX (1)]); + *(double*)margs->retval = res; +} + + + +static void +wasm_invoke_vif (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, float b) = target_func; + + func (margs->iargs [0], + *(float*)&margs->fargs [FIDX (0)]); +} + +static void +wasm_invoke_viff (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, float b, float c) = target_func; + + func (margs->iargs [0], + *(float*)&margs->fargs [FIDX (0)], + *(float*)&margs->fargs [FIDX (1)]); +} + +static void +wasm_invoke_viffff (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, float b, float c, float d, float e) = target_func; + + func (margs->iargs [0], + *(float*)&margs->fargs [FIDX (0)], + *(float*)&margs->fargs [FIDX (1)], + *(float*)&margs->fargs [FIDX (2)], + *(float*)&margs->fargs [FIDX (3)]); +} + +static void +wasm_invoke_vifffffi (void *target_func, InterpMethodArguments *margs) +{ + void (*func)(gpointer a, float b, float c, float d, float e, float f, int g) = target_func; + + func (margs->iargs [0], + *(float*)&margs->fargs [FIDX (0)], + *(float*)&margs->fargs [FIDX (1)], + *(float*)&margs->fargs [FIDX (2)], + *(float*)&margs->fargs [FIDX (3)], + *(float*)&margs->fargs [FIDX (4)], + *(float*)&margs->iargs [1]); +} + +static void +wasm_enter_icall_trampoline (void *target_func, InterpMethodArguments *margs) +{ + static char cookie [8]; + static int c_count; + + MonoMethodSignature *sig = margs->sig; + + c_count = sig->param_count + sig->hasthis + 1; + cookie [0] = type_to_c (sig->ret); + if (sig->hasthis) + cookie [1] = 'I'; + for (int i = 0; i < sig->param_count; ++i) + cookie [1 + sig->hasthis + i ] = type_to_c (sig->params [i]); + cookie [c_count] = 0; + + if (!strcmp ("V", cookie)) + wasm_invoke_v (target_func, margs); + else if (!strcmp ("VI", cookie)) + wasm_invoke_vi (target_func, margs); + else if (!strcmp ("VII", cookie)) + wasm_invoke_vii (target_func, margs); + else if (!strcmp ("VIII", cookie)) + wasm_invoke_viii (target_func, margs); + else if (!strcmp ("VIIII", cookie)) + wasm_invoke_viiii (target_func, margs); + else if (!strcmp ("VIIIII", cookie)) + wasm_invoke_viiiii (target_func, margs); + else if (!strcmp ("VIIIIII", cookie)) + wasm_invoke_viiiiii (target_func, margs); + else if (!strcmp ("I", cookie)) + wasm_invoke_i (target_func, margs); + else if (!strcmp ("II", cookie)) + wasm_invoke_ii (target_func, margs); + else if (!strcmp ("III", cookie)) + wasm_invoke_iii (target_func, margs); + else if (!strcmp ("IIII", cookie)) + wasm_invoke_iiii (target_func, margs); + else if (!strcmp ("IIIII", cookie)) + wasm_invoke_iiiii (target_func, margs); + else if (!strcmp ("IIIIII", cookie)) + wasm_invoke_iiiiii (target_func, margs); + else if (!strcmp ("LL", cookie)) + wasm_invoke_ll (target_func, margs); + else if (!strcmp ("LI", cookie)) + wasm_invoke_li (target_func, margs); + else if (!strcmp ("LIL", cookie)) + wasm_invoke_lil (target_func, margs); + else if (!strcmp ("DD", cookie)) + wasm_invoke_dd (target_func, margs); + else if (!strcmp ("DDD", cookie)) + wasm_invoke_ddd (target_func, margs); + else if (!strcmp ("VIF", cookie)) + wasm_invoke_vif (target_func, margs); + else if (!strcmp ("VIFF", cookie)) + wasm_invoke_viff (target_func, margs); + else if (!strcmp ("VIFFFF", cookie)) + wasm_invoke_viffff (target_func, margs); + else if (!strcmp ("VIFFFFFI", cookie)) + wasm_invoke_vifffffi (target_func, margs); + else { + printf ("CANNOT HANDLE COOKIE %s\n", cookie); + g_assert (0); + } +} + +gpointer +mono_aot_get_trampoline_full (const char *name, MonoTrampInfo **out_tinfo) +{ + gpointer code = NULL; + + if (!strcmp (name, "restore_context")) + code = wasm_restore_context; + else if (!strcmp (name, "call_filter")) + code = wasm_call_filter; + else if (!strcmp (name, "throw_exception")) + code = wasm_throw_exception; + else if (!strcmp (name, "rethrow_exception")) + code = wasm_rethrow_exception; + else if (!strcmp (name, "throw_corlib_exception")) + code = wasm_throw_corlib_exception; + else if (!strcmp (name, "enter_icall_trampoline")) + code = wasm_enter_icall_trampoline; + + g_assert (code); + + if (out_tinfo) { + MonoTrampInfo *tinfo = g_new0 (MonoTrampInfo, 1); + tinfo->code = code; + tinfo->code_size = 1; + tinfo->name = g_strdup (name); + tinfo->ji = NULL; + tinfo->unwind_ops = NULL; + tinfo->uw_info = NULL; + tinfo->uw_info_len = 0; + tinfo->owns_uw_info = FALSE; + + *out_tinfo = tinfo; + } + + return code; +} +#endif diff --git a/mono/mini/aot-runtime.c b/mono/mini/aot-runtime.c index d6c2486414f..4e86a5a3f32 100644 --- a/mono/mini/aot-runtime.c +++ b/mono/mini/aot-runtime.c @@ -5143,6 +5143,8 @@ no_trampolines (void) g_assert_not_reached (); } + +#ifndef TARGET_WASM /* * Return the trampoline identified by NAME from the mscorlib AOT file. * On ppc64, this returns a function descriptor. @@ -5159,6 +5161,8 @@ mono_aot_get_trampoline_full (const char *name, MonoTrampInfo **out_tinfo) return mono_create_ftnptr_malloc ((guint8 *)load_function_full (amodule, name, out_tinfo)); } +#endif + gpointer mono_aot_get_trampoline (const char *name) diff --git a/mono/mini/cpu-wasm.md b/mono/mini/cpu-wasm.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 4a2637c1943..cb0600828e9 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -2670,7 +2670,7 @@ thread_interrupt (DebuggerTlsData *tls, MonoThreadInfo *info, MonoJitInfo *ji) } copy_unwind_state_from_frame_data (&tls->async_state, &data, jit_tls); - copy_unwind_state_from_frame_data (&tls->context, &data, jit_tls); + /* Don't set tls->context, it could race with the thread processing a breakpoint etc. */ } else { tls->async_state.valid = FALSE; } diff --git a/mono/mini/driver.c b/mono/mini/driver.c index 297179bf86c..f293f7c6803 100644 --- a/mono/mini/driver.c +++ b/mono/mini/driver.c @@ -2376,6 +2376,11 @@ mono_jit_set_aot_mode (MonoAotMode mode) mono_aot_only = TRUE; mono_use_interpreter = TRUE; } + if (mono_aot_mode == MONO_AOT_MODE_INTERP_LLVMONLY) { + mono_aot_only = TRUE; + mono_use_interpreter = TRUE; + mono_llvm_only = TRUE; + } } mono_bool diff --git a/mono/mini/exceptions-wasm.c b/mono/mini/exceptions-wasm.c new file mode 100644 index 00000000000..63e72b0cd1f --- /dev/null +++ b/mono/mini/exceptions-wasm.c @@ -0,0 +1,34 @@ +#include "mini.h" + + +gpointer +mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot) +{ + g_error ("mono_arch_get_call_filter"); + return NULL; +} + +gpointer +mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot) +{ + g_error ("mono_arch_get_restore_context"); + return NULL; +} + +gboolean +mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, + MonoJitInfo *ji, MonoContext *ctx, + MonoContext *new_ctx, MonoLMF **lmf, + mgreg_t **save_locations, + StackFrameInfo *frame) +{ + g_error ("mono_arch_unwind_frame"); + return FALSE; +} + +gpointer +mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot) +{ + g_error ("mono_arch_get_throw_corlib_exception"); + return NULL; +} \ No newline at end of file diff --git a/mono/mini/genmdesc.pl b/mono/mini/genmdesc.pl old mode 100644 new mode 100755 index 8c8e7eac640..ae49ecba9f2 --- a/mono/mini/genmdesc.pl +++ b/mono/mini/genmdesc.pl @@ -20,7 +20,7 @@ sub INST_MAX () {return 6;} # this must include all the #defines used in mini-ops.h my @defines = qw (__i386__ __x86_64__ __ppc__ __powerpc__ __ppc64__ __arm__ - __sparc__ sparc __s390__ s390 __alpha__ __mips__ __aarch64__); + __sparc__ sparc __s390__ s390 __alpha__ __mips__ __aarch64__ __wasm__); my %table =(); my %template_table =(); my @opcodes = (); @@ -88,7 +88,9 @@ sub load_opcodes if ($arch =~ "__aarch64__") { $arch_define = "TARGET_ARM64"; } - + if ($arch =~ "__wasm__") { + $arch_define = "TARGET_WASM"; + } parse_file ($arch_define, "$srcdir/mini-ops.h"); return; $cpp .= " -D$arch_define $srcdir/mini-ops.h|"; diff --git a/mono/mini/interp/interp.c b/mono/mini/interp/interp.c index fccce6b3411..42b91954fcf 100644 --- a/mono/mini/interp/interp.c +++ b/mono/mini/interp/interp.c @@ -795,6 +795,10 @@ static InterpMethodArguments* build_args_from_sig (MonoMethodSignature *sig, Int int i8_align = mono_arm_i8_align (); #endif +#ifdef TARGET_WASM + margs->sig = sig; +#endif + if (sig->hasthis) margs->ilen++; diff --git a/mono/mini/interp/interp.h b/mono/mini/interp/interp.h index 6abf93a6f0a..42198d92193 100644 --- a/mono/mini/interp/interp.h +++ b/mono/mini/interp/interp.h @@ -6,8 +6,13 @@ #define __MONO_MINI_INTERPRETER_H__ #include +#ifdef TARGET_WASM +#define INTERP_ICALL_TRAMP_IARGS 12 +#define INTERP_ICALL_TRAMP_FARGS 12 +#else #define INTERP_ICALL_TRAMP_IARGS 12 #define INTERP_ICALL_TRAMP_FARGS 4 +#endif struct _InterpMethodArguments { size_t ilen; @@ -16,6 +21,9 @@ struct _InterpMethodArguments { double *fargs; gpointer *retval; size_t is_float_ret; +#ifdef TARGET_WASM + MonoMethodSignature *sig; +#endif }; typedef struct _InterpMethodArguments InterpMethodArguments; diff --git a/mono/mini/jit.h b/mono/mini/jit.h index 408fead304e..3a91c13f0d5 100644 --- a/mono/mini/jit.h +++ b/mono/mini/jit.h @@ -57,7 +57,9 @@ typedef enum { MONO_AOT_MODE_LLVMONLY, /* Uses Interpreter, JIT is disabled and not allowed, * equivalent to "--full-aot --interpreter" */ - MONO_AOT_MODE_INTERP + MONO_AOT_MODE_INTERP, + /* Same as INTERP, but use only llvm compiled code */ + MONO_AOT_MODE_INTERP_LLVMONLY, } MonoAotMode; MONO_API void diff --git a/mono/mini/mini-amd64.c b/mono/mini/mini-amd64.c index 949e5a362a6..949f8946ddd 100644 --- a/mono/mini/mini-amd64.c +++ b/mono/mini/mini-amd64.c @@ -3650,7 +3650,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) #define EXTRA_CODE_SPACE (16) - if (G_UNLIKELY (offset > (cfg->code_size - max_len - EXTRA_CODE_SPACE))) { + if (G_UNLIKELY ((offset + max_len + EXTRA_CODE_SPACE) > cfg->code_size)) { cfg->code_size *= 2; cfg->native_code = (unsigned char *)mono_realloc_native_code(cfg); code = cfg->native_code + offset; @@ -4487,6 +4487,17 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) g_assert (!cfg->method->save_lmf); + /* the size of the tailcall op depends on signature, let's check for enough + * space in the code buffer here again */ + max_len += AMD64_NREG * 4 + call->stack_usage * 15 + EXTRA_CODE_SPACE; + + if (G_UNLIKELY (offset + max_len > cfg->code_size)) { + cfg->code_size *= 2; + cfg->native_code = (unsigned char *) mono_realloc_native_code(cfg); + code = cfg->native_code + offset; + cfg->stat_code_reallocs++; + } + /* Restore callee saved registers */ save_area_offset = cfg->arch.reg_save_area_offset; for (i = 0; i < AMD64_NREG; ++i) @@ -4517,7 +4528,6 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) #endif } - offset = code - cfg->native_code; mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_METHOD_JUMP, call->method); if (cfg->compile_aot) amd64_mov_reg_membase (code, AMD64_R11, AMD64_RIP, 0, 8); diff --git a/mono/mini/mini-arch.h b/mono/mini/mini-arch.h index eb50de0f5e4..c49ed5a41d5 100644 --- a/mono/mini/mini-arch.h +++ b/mono/mini/mini-arch.h @@ -25,6 +25,8 @@ #include "mini-arm64.h" #elif defined(__mips__) #include "mini-mips.h" +#elif TARGET_WASM +#include "mini-wasm.h" #else #error add arch specific include file in mini-arch.h #endif diff --git a/mono/mini/mini-exceptions.c b/mono/mini/mini-exceptions.c index f15af494bb1..10cf1b75cb1 100644 --- a/mono/mini/mini-exceptions.c +++ b/mono/mini/mini-exceptions.c @@ -1700,7 +1700,7 @@ mono_handle_exception_internal_first_pass (MonoContext *ctx, MonoObject *obj, gi if (ei->flags == MONO_EXCEPTION_CLAUSE_FILTER) { #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->exceptions_filters++; + InterlockedIncrement (&mono_perfcounters->exceptions_filters); #endif #ifndef MONO_CROSS_COMPILE @@ -2153,7 +2153,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu } mono_set_lmf (lmf); #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->exceptions_depth += frame_count; + InterlockedAdd (&mono_perfcounters->exceptions_depth, frame_count); #endif if (obj == (MonoObject *)domain->stack_overflow_ex) jit_tls->handling_stack_ovf = FALSE; @@ -2175,7 +2175,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu MONO_PROFILER_RAISE (exception_clause, (method, i, ei->flags, ex_obj)); jit_tls->orig_ex_ctx_set = FALSE; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->exceptions_finallys++; + InterlockedIncrement (&mono_perfcounters->exceptions_finallys); #endif } if (ei->flags == MONO_EXCEPTION_CLAUSE_FAULT || ei->flags == MONO_EXCEPTION_CLAUSE_FINALLY) { @@ -2277,7 +2277,7 @@ mono_handle_exception (MonoContext *ctx, MonoObject *obj) MONO_REQ_GC_UNSAFE_MODE; #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->exceptions_thrown++; + InterlockedIncrement (&mono_perfcounters->exceptions_thrown); #endif return mono_handle_exception_internal (ctx, obj, FALSE, NULL); @@ -3263,7 +3263,7 @@ mono_llvm_load_exception (void) if (mono_ex->trace_ips) { GList *trace_ips = NULL; - gpointer ip = __builtin_return_address (0); + gpointer ip = RETURN_ADDRESS (); size_t upper = mono_array_length (mono_ex->trace_ips); diff --git a/mono/mini/mini-generic-sharing.c b/mono/mini/mini-generic-sharing.c index 243c83cbe5d..5faf6495769 100644 --- a/mono/mini/mini-generic-sharing.c +++ b/mono/mini/mini-generic-sharing.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "mini.h" @@ -32,10 +34,19 @@ static void mono_class_unregister_image_generic_subclasses (MonoImage *image, gpointer user_data); /* Counters */ -static int num_templates_allocted; -static int num_templates_bytes; -static int num_oti_allocted; -static int num_oti_bytes; +static gint32 rgctx_template_num_allocated; +static gint32 rgctx_template_bytes_allocated; +static gint32 rgctx_oti_num_allocated; +static gint32 rgctx_oti_bytes_allocated; +static gint32 rgctx_oti_num_markers; +static gint32 rgctx_oti_num_data; +static gint32 rgctx_max_slot_number; +static gint32 rgctx_num_allocated; +static gint32 rgctx_num_arrays_allocated; +static gint32 rgctx_bytes_allocated; +static gint32 mrgctx_num_arrays_allocated; +static gint32 mrgctx_bytes_allocated; +static gint32 gsharedvt_num_trampolines; #define gshared_lock() mono_os_mutex_lock (&gshared_mutex) #define gshared_unlock() mono_os_mutex_unlock (&gshared_mutex) @@ -354,10 +365,10 @@ mono_class_unregister_image_generic_subclasses (MonoImage *image, gpointer user_ static MonoRuntimeGenericContextTemplate* alloc_template (MonoClass *klass) { - int size = sizeof (MonoRuntimeGenericContextTemplate); + gint32 size = sizeof (MonoRuntimeGenericContextTemplate); - num_templates_allocted++; - num_templates_bytes += size; + InterlockedIncrement (&rgctx_template_num_allocated); + InterlockedAdd(&rgctx_template_bytes_allocated, size); return (MonoRuntimeGenericContextTemplate *)mono_image_alloc0 (klass->image, size); } @@ -366,10 +377,10 @@ alloc_template (MonoClass *klass) static MonoRuntimeGenericContextInfoTemplate* alloc_oti (MonoImage *image) { - int size = sizeof (MonoRuntimeGenericContextInfoTemplate); + gint32 size = sizeof (MonoRuntimeGenericContextInfoTemplate); - num_oti_allocted++; - num_oti_bytes += size; + InterlockedIncrement (&rgctx_oti_num_allocated); + InterlockedAdd (&rgctx_oti_bytes_allocated, size); return (MonoRuntimeGenericContextInfoTemplate *)mono_image_alloc0 (image, size); } @@ -404,20 +415,10 @@ static void rgctx_template_set_slot (MonoImage *image, MonoRuntimeGenericContextTemplate *template_, int type_argc, int slot, gpointer data, MonoRgctxInfoType info_type) { - static gboolean inited = FALSE; - static int num_markers = 0; - static int num_data = 0; - int i; MonoRuntimeGenericContextInfoTemplate *list = get_info_templates (template_, type_argc); MonoRuntimeGenericContextInfoTemplate **oti = &list; - if (!inited) { - mono_counters_register ("RGCTX oti num markers", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &num_markers); - mono_counters_register ("RGCTX oti num data", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &num_data); - inited = TRUE; - } - g_assert (slot >= 0); g_assert (data); @@ -436,10 +437,11 @@ rgctx_template_set_slot (MonoImage *image, MonoRuntimeGenericContextTemplate *te set_info_templates (image, template_, type_argc, list); + /* interlocked by loader lock (by definition) */ if (data == MONO_RGCTX_SLOT_USED_MARKER) - ++num_markers; + UnlockedIncrement (&rgctx_oti_num_markers); else - ++num_data; + UnlockedIncrement (&rgctx_oti_num_data); } /* @@ -1616,8 +1618,6 @@ mini_get_gsharedvt_out_sig_wrapper_signature (gboolean has_this, gboolean has_re gpointer mini_get_gsharedvt_wrapper (gboolean gsharedvt_in, gpointer addr, MonoMethodSignature *normal_sig, MonoMethodSignature *gsharedvt_sig, gint32 vcall_offset, gboolean calli) { - static gboolean inited = FALSE; - static int num_trampolines; MonoError error; gpointer res, info; MonoDomain *domain = mono_domain_get (); @@ -1625,11 +1625,6 @@ mini_get_gsharedvt_wrapper (gboolean gsharedvt_in, gpointer addr, MonoMethodSign GSharedVtTrampInfo *tramp_info; GSharedVtTrampInfo tinfo; - if (!inited) { - mono_counters_register ("GSHAREDVT arg trampolines", MONO_COUNTER_JIT | MONO_COUNTER_INT, &num_trampolines); - inited = TRUE; - } - if (mono_llvm_only) { MonoMethod *wrapper; @@ -1696,7 +1691,7 @@ mini_get_gsharedvt_wrapper (gboolean gsharedvt_in, gpointer addr, MonoMethodSign else addr = mono_arch_get_gsharedvt_arg_trampoline (mono_domain_get (), info, addr); - num_trampolines ++; + InterlockedIncrement (&gsharedvt_num_trampolines); /* Cache it */ tramp_info = (GSharedVtTrampInfo *)mono_domain_alloc0 (domain, sizeof (GSharedVtTrampInfo)); @@ -2354,9 +2349,6 @@ static int lookup_or_register_info (MonoClass *klass, int type_argc, gpointer data, MonoRgctxInfoType info_type, MonoGenericContext *generic_context) { - static gboolean inited = FALSE; - static int max_slot = 0; - MonoRuntimeGenericContextTemplate *rgctx_template = mono_class_get_runtime_generic_context_template (klass); MonoRuntimeGenericContextInfoTemplate *oti_list, *oti; @@ -2389,14 +2381,11 @@ lookup_or_register_info (MonoClass *klass, int type_argc, gpointer data, MonoRgc /* We haven't found the info */ i = register_info (klass, type_argc, data, info_type); - mono_loader_unlock (); + /* interlocked by loader lock */ + if (i > UnlockedRead (&rgctx_max_slot_number)) + UnlockedWrite (&rgctx_max_slot_number, i); - if (!inited) { - mono_counters_register ("RGCTX max slot number", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &max_slot); - inited = TRUE; - } - if (i > max_slot) - max_slot = i; + mono_loader_unlock (); return i; } @@ -2466,29 +2455,16 @@ mono_class_rgctx_get_array_size (int n, gboolean mrgctx) static gpointer* alloc_rgctx_array (MonoDomain *domain, int n, gboolean is_mrgctx) { - static gboolean inited = FALSE; - static int rgctx_num_alloced = 0; - static int rgctx_bytes_alloced = 0; - static int mrgctx_num_alloced = 0; - static int mrgctx_bytes_alloced = 0; - - int size = mono_class_rgctx_get_array_size (n, is_mrgctx) * sizeof (gpointer); + gint32 size = mono_class_rgctx_get_array_size (n, is_mrgctx) * sizeof (gpointer); gpointer *array = (gpointer *)mono_domain_alloc0 (domain, size); - if (!inited) { - mono_counters_register ("RGCTX num arrays alloced", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_num_alloced); - mono_counters_register ("RGCTX bytes alloced", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_bytes_alloced); - mono_counters_register ("MRGCTX num arrays alloced", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &mrgctx_num_alloced); - mono_counters_register ("MRGCTX bytes alloced", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &mrgctx_bytes_alloced); - inited = TRUE; - } - + /* interlocked by domain lock (by definition) */ if (is_mrgctx) { - mrgctx_num_alloced++; - mrgctx_bytes_alloced += size; + UnlockedIncrement (&mrgctx_num_arrays_allocated); + UnlockedAdd (&mrgctx_bytes_allocated, size); } else { - rgctx_num_alloced++; - rgctx_bytes_alloced += size; + UnlockedIncrement (&rgctx_num_arrays_allocated); + UnlockedAdd (&rgctx_bytes_allocated, size); } return array; @@ -2589,9 +2565,6 @@ fill_runtime_generic_context (MonoVTable *class_vtable, MonoRuntimeGenericContex gpointer mono_class_fill_runtime_generic_context (MonoVTable *class_vtable, guint32 slot, MonoError *error) { - static gboolean inited = FALSE; - static int num_alloced = 0; - MonoDomain *domain = class_vtable->domain; MonoRuntimeGenericContext *rgctx; gpointer info; @@ -2600,16 +2573,11 @@ mono_class_fill_runtime_generic_context (MonoVTable *class_vtable, guint32 slot, mono_domain_lock (domain); - if (!inited) { - mono_counters_register ("RGCTX num alloced", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &num_alloced); - inited = TRUE; - } - rgctx = class_vtable->runtime_generic_context; if (!rgctx) { rgctx = alloc_rgctx_array (domain, 0, FALSE); class_vtable->runtime_generic_context = rgctx; - num_alloced++; + UnlockedIncrement (&rgctx_num_allocated); /* interlocked by domain lock */ } mono_domain_unlock (domain); @@ -3326,10 +3294,19 @@ mini_type_stack_size_full (MonoType *t, guint32 *align, gboolean pinvoke) void mono_generic_sharing_init (void) { - mono_counters_register ("RGCTX template num allocted", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &num_templates_allocted); - mono_counters_register ("RGCTX template bytes allocted", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &num_templates_bytes); - mono_counters_register ("RGCTX oti num allocted", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &num_oti_allocted); - mono_counters_register ("RGCTX oti bytes allocted", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &num_oti_bytes); + mono_counters_register ("RGCTX template num allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_template_num_allocated); + mono_counters_register ("RGCTX template bytes allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_template_bytes_allocated); + mono_counters_register ("RGCTX oti num allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_oti_num_allocated); + mono_counters_register ("RGCTX oti bytes allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_oti_bytes_allocated); + mono_counters_register ("RGCTX oti num markers", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_oti_num_markers); + mono_counters_register ("RGCTX oti num data", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_oti_num_data); + mono_counters_register ("RGCTX max slot number", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_max_slot_number); + mono_counters_register ("RGCTX num allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_num_allocated); + mono_counters_register ("RGCTX num arrays allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_num_arrays_allocated); + mono_counters_register ("RGCTX bytes allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &rgctx_bytes_allocated); + mono_counters_register ("MRGCTX num arrays allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &mrgctx_num_arrays_allocated); + mono_counters_register ("MRGCTX bytes allocated", MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &mrgctx_bytes_allocated); + mono_counters_register ("GSHAREDVT num trampolines", MONO_COUNTER_JIT | MONO_COUNTER_INT, &gsharedvt_num_trampolines); mono_install_image_unload_hook (mono_class_unregister_image_generic_subclasses, NULL); diff --git a/mono/mini/mini-s390x.c b/mono/mini/mini-s390x.c index 8e82dfa0cca..584813cc4db 100644 --- a/mono/mini/mini-s390x.c +++ b/mono/mini/mini-s390x.c @@ -3717,33 +3717,43 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) if (ins->dreg != ins->sreg1) { s390_lgr (code, ins->dreg, ins->sreg1); } - if (s390_is_imm16 (ins->inst_imm)) { - s390_lghi (code, s390_r13, ins->inst_imm); - } else if (s390_is_imm32 (ins->inst_imm)) { - s390_lgfi (code, s390_r13, ins->inst_imm); + if ((mono_hwcap_s390x_has_gie) && + (s390_is_imm32 (ins->inst_imm))) { + s390_msgfi (code, ins->dreg, ins->inst_imm); } else { - S390_SET (code, s390_r13, ins->inst_imm); + if (s390_is_imm16 (ins->inst_imm)) { + s390_lghi (code, s390_r13, ins->inst_imm); + } else if (s390_is_imm32 (ins->inst_imm)) { + s390_lgfi (code, s390_r13, ins->inst_imm); + } else { + S390_SET (code, s390_r13, ins->inst_imm); + } + s390_msgr (code, ins->dreg, s390_r13); } - s390_msgr (code, ins->dreg, s390_r13); } break; case OP_LMUL_OVF: { short int *o[2]; - s390_ltgr (code, s390_r1, ins->sreg1); - s390_jz (code, 0); CODEPTR(code, o[0]); - s390_ltgr (code, s390_r0, ins->sreg2); - s390_jnz (code, 6); - s390_lghi (code, s390_r1, 0); - s390_j (code, 0); CODEPTR(code, o[1]); - s390_xgr (code, s390_r0, s390_r1); - s390_msgr (code, s390_r1, ins->sreg2); - s390_xgr (code, s390_r0, s390_r1); - s390_srlg (code, s390_r0, s390_r0, 0, 63); - s390_ltgr (code, s390_r0, s390_r0); - EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException"); - PTRSLOT (code, o[0]); - PTRSLOT (code, o[1]); - s390_lgr (code, ins->dreg, s390_r1); + if (mono_hwcap_s390x_has_mie2) { + s390_msgrkc (code, ins->dreg, ins->sreg1, ins->sreg2); + EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException"); + } else { + s390_ltgr (code, s390_r1, ins->sreg1); + s390_jz (code, 0); CODEPTR(code, o[0]); + s390_ltgr (code, s390_r0, ins->sreg2); + s390_jnz (code, 6); + s390_lghi (code, s390_r1, 0); + s390_j (code, 0); CODEPTR(code, o[1]); + s390_xgr (code, s390_r0, s390_r1); + s390_msgr (code, s390_r1, ins->sreg2); + s390_xgr (code, s390_r0, s390_r1); + s390_srlg (code, s390_r0, s390_r0, 0, 63); + s390_ltgr (code, s390_r0, s390_r0); + EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException"); + PTRSLOT (code, o[0]); + PTRSLOT (code, o[1]); + s390_lgr (code, ins->dreg, s390_r1); + } } break; case OP_LMUL_OVF_UN: { @@ -3798,26 +3808,42 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) break; case OP_LADD_OVF: case OP_S390_LADD_OVF: { - CHECK_SRCDST_COM; - s390_agr (code, ins->dreg, src2); + if (mono_hwcap_s390x_has_mlt) { + s390_agrk (code, ins->dreg, ins->sreg1, ins->sreg2); + } else { + CHECK_SRCDST_COM; + s390_agr (code, ins->dreg, src2); + } EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException"); } break; case OP_LADD_OVF_UN: case OP_S390_LADD_OVF_UN: { - CHECK_SRCDST_COM; - s390_algr (code, ins->dreg, src2); + if (mono_hwcap_s390x_has_mlt) { + s390_algrk (code, ins->dreg, ins->sreg1, ins->sreg2); + } else { + CHECK_SRCDST_COM; + s390_algr (code, ins->dreg, src2); + } EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException"); } break; case OP_ISUBCC: { - CHECK_SRCDST_NCOM_I; - s390_slgr (code, ins->dreg, src2); + if (mono_hwcap_s390x_has_mlt) { + s390_slgrk (code, ins->dreg, ins->sreg1, ins->sreg2); + } else { + CHECK_SRCDST_NCOM_I; + s390_slgr (code, ins->dreg, src2); + } } break; case OP_ISUB: { - CHECK_SRCDST_NCOM_I; - s390_sgr (code, ins->dreg, src2); + if (mono_hwcap_s390x_has_mlt) { + s390_sgrk (code, ins->dreg, ins->sreg1, ins->sreg2); + } else { + CHECK_SRCDST_NCOM_I; + s390_sgr (code, ins->dreg, src2); + } } break; case OP_ISBB: { @@ -3843,24 +3869,37 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) break; case OP_ISUB_OVF: case OP_S390_ISUB_OVF: { - CHECK_SRCDST_NCOM; - s390_sr (code, ins->dreg, src2); - EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException"); - s390_lgfr (code, ins->dreg, ins->dreg); + if (mono_hwcap_s390x_has_mlt) { + s390_srk (code, ins->dreg, ins->sreg1, ins->sreg2); + EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException"); + } else { + CHECK_SRCDST_NCOM; + s390_sr (code, ins->dreg, src2); + EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException"); + s390_lgfr (code, ins->dreg, ins->dreg); + } } break; case OP_ISUB_OVF_UN: case OP_S390_ISUB_OVF_UN: { - CHECK_SRCDST_NCOM; - s390_slr (code, ins->dreg, src2); + if (mono_hwcap_s390x_has_mlt) { + s390_slrk (code, ins->dreg, ins->sreg1, ins->sreg2); + } else { + CHECK_SRCDST_NCOM; + s390_slr (code, ins->dreg, src2); + } EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException"); s390_llgfr(code, ins->dreg, ins->dreg); } break; case OP_LSUB_OVF: case OP_S390_LSUB_OVF: { - CHECK_SRCDST_NCOM; - s390_sgr (code, ins->dreg, src2); + if (mono_hwcap_s390x_has_mlt) { + s390_sgrk (code, ins->dreg, ins->sreg1, ins->sreg2); + } else { + CHECK_SRCDST_NCOM; + s390_sgr (code, ins->dreg, src2); + } EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException"); } break; diff --git a/mono/mini/mini-wasm.c b/mono/mini/mini-wasm.c new file mode 100644 index 00000000000..0104909e4d0 --- /dev/null +++ b/mono/mini/mini-wasm.c @@ -0,0 +1,253 @@ +#include "mini.h" + + +gpointer +mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code) +{ + g_error ("mono_arch_get_this_arg_from_call"); +} + +gpointer +mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method, int offset, gboolean load_imt_reg) +{ + g_error ("mono_arch_get_delegate_virtual_invoke_impl"); +} + + +void +mono_arch_cpu_init (void) +{ + // printf ("mono_arch_cpu_init\n"); +} + +void +mono_arch_finish_init (void) +{ + // printf ("mono_arch_finish_init\n"); +} + +void +mono_arch_init (void) +{ + // printf ("mono_arch_init\n"); +} + +void +mono_arch_cleanup (void) +{ +} + +void +mono_arch_register_lowlevel_calls (void) +{ +} + +void +mono_arch_flush_register_windows (void) +{ +} + +void +mono_arch_free_jit_tls_data (MonoJitTlsData *tls) +{ +} + + +MonoMethod* +mono_arch_find_imt_method (mgreg_t *regs, guint8 *code) +{ + g_error ("mono_arch_find_static_call_vtable"); + return (MonoMethod*) regs [MONO_ARCH_IMT_REG]; +} + +MonoVTable* +mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code) +{ + g_error ("mono_arch_find_static_call_vtable"); + return (MonoVTable*) regs [MONO_ARCH_RGCTX_REG]; +} + +gpointer +mono_arch_build_imt_trampoline (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count, gpointer fail_tramp) +{ + g_error ("mono_arch_build_imt_trampoline"); +} + +guint32 +mono_arch_cpu_enumerate_simd_versions (void) +{ + return 0; +} + +guint32 +mono_arch_cpu_optimizations (guint32 *exclude_mask) +{ + return 0; +} + +GSList* +mono_arch_get_delegate_invoke_impls (void) +{ + g_error ("mono_arch_get_delegate_invoke_impls"); + return NULL; +} + +gpointer +mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target) +{ + g_error ("mono_arch_get_delegate_invoke_impl"); + return NULL; +} + +mgreg_t +mono_arch_context_get_int_reg (MonoContext *ctx, int reg) +{ + g_error ("mono_arch_context_get_int_reg"); + return 0; +} + +int +mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info) +{ + g_error ("mono_arch_get_argument_info"); + return 0; + +} + +void +mono_arch_init_lmf_ext (MonoLMFExt *ext, gpointer prev_lmf) +{ + ext->lmf.previous_lmf = (gsize)prev_lmf; + /* Mark that this is a MonoLMFExt */ + ext->lmf.previous_lmf = (gsize)(gpointer)(((gssize)ext->lmf.previous_lmf) | 2); +} + + + +void +mono_runtime_setup_stat_profiler (void) +{ + g_error ("mono_runtime_setup_stat_profiler"); +} + + +void +mono_runtime_shutdown_stat_profiler (void) +{ + g_error ("mono_runtime_shutdown_stat_profiler"); +} + + +gboolean +MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal) +{ + g_error ("mono_chain_signal"); + + return FALSE; +} + +void +mono_runtime_install_handlers (void) +{ +} + +void +mono_runtime_cleanup_handlers (void) +{ +} + +gboolean +mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info) +{ + g_error ("WASM systems don't support mono_thread_state_init_from_handle"); + return FALSE; +} + + +/* +The following functions don't belong here, but are due to laziness. +*/ + +//w32file-wasm.c +gboolean +mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize) +{ + g_error ("mono_w32file_get_volume_information"); +} + + +//llvm builtin's that we should not have used in the first place + + +//libc / libpthread missing bits from musl or shit we didn't detect :facepalm: +int pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *param) +{ + g_error ("pthread_getschedparam"); + return 0; +} + +int +pthread_attr_getstacksize (const pthread_attr_t *restrict attr, size_t *restrict stacksize) +{ + return 65536; //wasm page size +} + +int +pthread_sigmask (int how, const sigset_t * restrict set, sigset_t * restrict oset) +{ + return 0; +} + + +int +sigsuspend(const sigset_t *sigmask) +{ + g_error ("sigsuspend"); + return 0; +} + +int +getdtablesize (void) +{ + return 256; //random constant that is the fd limit +} + +void * +getgrnam (const char *name) +{ + return NULL; +} + +void * +getgrgid (gid_t gid) +{ + return NULL; +} + +int +inotify_init (void) +{ + g_error ("inotify_init"); +} + +int +inotify_rm_watch (int fd, int wd) +{ + g_error ("inotify_rm_watch"); + return 0; +} + +int +inotify_add_watch (int fd, const char *pathname, uint32_t mask) +{ + g_error ("inotify_add_watch"); + return 0; +} + +int +sem_timedwait (sem_t *sem, const struct timespec *abs_timeout) +{ + g_error ("sem_timedwait"); + return 0; + +} diff --git a/mono/mini/mini-wasm.h b/mono/mini/mini-wasm.h new file mode 100644 index 00000000000..8205dc1b561 --- /dev/null +++ b/mono/mini/mini-wasm.h @@ -0,0 +1,50 @@ +#ifndef __MONO_MINI_WASM_H__ +#define __MONO_MINI_WASM_H__ + +#include +#include + +#define MONO_ARCH_CPU_SPEC mono_wasm_desc + +#define MONO_ARCH_HAVE_INIT_LMF_EXT 1 + +#define MONO_MAX_IREGS 1 +#define MONO_MAX_FREGS 1 + +#define WASM_REG_0 0 + + +struct MonoLMF { + /* + * If the second lowest bit is set to 1, then this is a MonoLMFExt structure, and + * the other fields are not valid. + */ + gpointer previous_lmf; + gpointer lmf_addr; + + /* This is only set in trampoline LMF frames */ + MonoMethod *method; + + gboolean top_entry; +}; + +typedef struct { + int dummy; +} MonoCompileArch; + +#define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf) do { (lmf)->top_entry = TRUE; } while (0) + +#define MONO_CONTEXT_SET_LLVM_EXC_REG(ctx, exc) do { (ctx)->llvm_exc_reg = (gsize)exc; } while (0) + +#define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \ + MONO_CONTEXT_SET_IP ((ctx), (start_func)); \ + MONO_CONTEXT_SET_BP ((ctx), (0)); \ + MONO_CONTEXT_SET_SP ((ctx), (0)); \ + } while (0) + + +#define MONO_ARCH_VTABLE_REG WASM_REG_0 +#define MONO_ARCH_IMT_REG WASM_REG_0 +#define MONO_ARCH_RGCTX_REG WASM_REG_0 + +#endif /* __MONO_MINI_WASM_H__ */ diff --git a/mono/mini/mini.c b/mono/mini/mini.c index ee6ec6659bf..4cfe898b0a0 100644 --- a/mono/mini/mini.c +++ b/mono/mini/mini.c @@ -3875,8 +3875,8 @@ mini_method_compile (MonoMethod *method, guint32 opts, MonoDomain *domain, JitFl /* collect statistics */ #ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->jit_methods++; - mono_perfcounters->jit_bytes += header->code_size; + InterlockedIncrement (&mono_perfcounters->jit_methods); + InterlockedAdd (&mono_perfcounters->jit_bytes, header->code_size); #endif mono_jit_stats.allocated_code_size += cfg->code_len; code_size_ratio = cfg->code_len; diff --git a/mono/mini/mini.h b/mono/mini/mini.h index 9645a0de7b9..0edfea186b4 100644 --- a/mono/mini/mini.h +++ b/mono/mini/mini.h @@ -3266,4 +3266,31 @@ gboolean MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal); */ void mono_interruption_checkpoint_from_trampoline (void); + +#if defined (HOST_WASM) + +#define RETURN_ADDRESS_N(N) NULL +#define RETURN_ADDRESS() RETURN_ADDRESS_N(0) + + +#elif defined (__GNUC__) + +#define RETURN_ADDRESS_N(N) (__builtin_extract_return_addr (__builtin_return_address (N))) +#define RETURN_ADDRESS() RETURN_ADDRESS_N(0) + +#elif defined(_MSC_VER) + +#include +#pragma intrinsic(_ReturnAddress) + +#define RETURN_ADDRESS() _ReturnAddress() +#define RETURN_ADDRESS_N(N) NULL + +#else + +#error "Missing return address intrinsics implementation" + +#endif + + #endif /* __MONO_MINI_H__ */ diff --git a/mono/mini/trace.c b/mono/mini/trace.c index 0e50ae55070..b81fe604ed3 100644 --- a/mono/mini/trace.c +++ b/mono/mini/trace.c @@ -33,25 +33,6 @@ # define fprintf(__ignore, ...) g_log ("mono-gc", G_LOG_LEVEL_MESSAGE, __VA_ARGS__) #endif -#ifdef __GNUC__ - -#define RETURN_ADDRESS_N(N) (__builtin_extract_return_addr (__builtin_return_address (N))) -#define RETURN_ADDRESS() RETURN_ADDRESS_N(0) - -#elif defined(_MSC_VER) - -#include -#pragma intrinsic(_ReturnAddress) - -#define RETURN_ADDRESS() _ReturnAddress() -#define RETURN_ADDRESS_N(N) NULL - -#else - -#error "Missing return address intrinsics implementation" - -#endif - static MonoTraceSpec trace_spec; static volatile gint32 output_lock = 0; diff --git a/mono/mini/tramp-wasm.c b/mono/mini/tramp-wasm.c new file mode 100644 index 00000000000..50447fbae56 --- /dev/null +++ b/mono/mini/tramp-wasm.c @@ -0,0 +1,54 @@ +#include "mini.h" + + +gpointer +mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len) +{ + g_error ("mono_arch_create_specific_trampoline"); +} + +guchar* +mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot) +{ + g_error ("mono_arch_create_generic_trampoline"); +} + +gpointer +mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot) +{ + g_error ("mono_arch_create_rgctx_lazy_fetch_trampoline"); +} + +void +mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr) +{ + g_error ("mono_arch_patch_plt_entry"); +} + +gpointer +mono_arch_get_enter_icall_trampoline (MonoTrampInfo **info) +{ + printf ("mono_arch_get_enter_icall_trampoline"); + g_assert (0); + return NULL; +} + +void +mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr) +{ + g_error ("mono_arch_patch_callsite"); +} + +gpointer +mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr) +{ + g_error ("mono_arch_get_unbox_trampoline"); + return NULL; +} + +gpointer +mono_arch_get_static_rgctx_trampoline (gpointer arg, gpointer addr) +{ + g_error ("mono_arch_get_static_rgctx_trampoline"); + return NULL; +} \ No newline at end of file diff --git a/mono/sgen/sgen-conf.h b/mono/sgen/sgen-conf.h index 53e962c2b70..5e8866ffff8 100644 --- a/mono/sgen/sgen-conf.h +++ b/mono/sgen/sgen-conf.h @@ -104,6 +104,20 @@ typedef mword SgenDescriptor; #endif #endif +#if defined (TARGET_WASM) +#define DEFAULT_MAJOR SGEN_MAJOR_SERIAL +#define DEFAULT_SWEEP_MODE SGEN_SWEEP_SERIAL +#elif defined(HAVE_CONC_GC_AS_DEFAULT) +/* Use concurrent major on deskstop platforms */ +#define DEFAULT_MAJOR SGEN_MAJOR_CONCURRENT +#define DEFAULT_SWEEP_MODE SGEN_SWEEP_CONCURRENT +#else +#define DEFAULT_MAJOR SGEN_MAJOR_SERIAL +#define DEFAULT_SWEEP_MODE SGEN_SWEEP_CONCURRENT +#endif + + + /* * Maximum level of debug to enable on this build. * Making this a constant enables us to put logging in a lot of places and diff --git a/mono/sgen/sgen-gc.c b/mono/sgen/sgen-gc.c index beb5ce1b258..d5416f0df36 100644 --- a/mono/sgen/sgen-gc.c +++ b/mono/sgen/sgen-gc.c @@ -337,13 +337,6 @@ nursery_canaries_enabled (void) #define safe_object_get_size sgen_safe_object_get_size -#if defined(HAVE_CONC_GC_AS_DEFAULT) -/* Use concurrent major on deskstop platforms */ -#define DEFAULT_MAJOR SGEN_MAJOR_CONCURRENT -#else -#define DEFAULT_MAJOR SGEN_MAJOR_SERIAL -#endif - typedef enum { SGEN_MAJOR_DEFAULT, SGEN_MAJOR_SERIAL, diff --git a/mono/sgen/sgen-marksweep.c b/mono/sgen/sgen-marksweep.c index 5f4185d4df7..e06ac6d3f83 100644 --- a/mono/sgen/sgen-marksweep.c +++ b/mono/sgen/sgen-marksweep.c @@ -189,10 +189,15 @@ enum { SWEEP_STATE_COMPACTING }; +typedef enum { + SGEN_SWEEP_SERIAL = FALSE, + SGEN_SWEEP_CONCURRENT = TRUE, +} SgenSweepMode; + static volatile int sweep_state = SWEEP_STATE_SWEPT; static gboolean concurrent_mark; -static gboolean concurrent_sweep = TRUE; +static gboolean concurrent_sweep = DEFAULT_SWEEP_MODE; int sweep_pool_context = -1; diff --git a/mono/sgen/sgen-thread-pool.c b/mono/sgen/sgen-thread-pool.c index 211bc8b7277..c9aaaa2667b 100644 --- a/mono/sgen/sgen-thread-pool.c +++ b/mono/sgen/sgen-thread-pool.c @@ -305,6 +305,10 @@ sgen_thread_pool_shutdown (void) mono_os_mutex_destroy (&lock); mono_os_cond_destroy (&work_cond); mono_os_cond_destroy (&done_cond); + + for (int i = 0; i < threads_num; i++) { + mono_threads_add_joinable_thread ((gpointer)threads [i]); + } } SgenThreadPoolJob* diff --git a/mono/tests/Makefile.am b/mono/tests/Makefile.am index d7b3119374d..4e4de8f0db8 100755 --- a/mono/tests/Makefile.am +++ b/mono/tests/Makefile.am @@ -304,6 +304,7 @@ TESTS_CS_SRC= \ delegate-async-exit.cs \ delegate-delegate-exit.cs \ delegate-exit.cs \ + delegate-disposed-hashcode.cs \ finalizer-abort.cs \ finalizer-exception.cs \ finalizer-exit.cs \ diff --git a/mono/tests/delegate-disposed-hashcode.cs b/mono/tests/delegate-disposed-hashcode.cs new file mode 100644 index 00000000000..f90118a54d0 --- /dev/null +++ b/mono/tests/delegate-disposed-hashcode.cs @@ -0,0 +1,38 @@ +using System; + +// Regression test for bug #59235 + +public static class Program { + delegate void MyDel (int i, int j); + + public static void Main (string[] args) { + var o = new MyTarget (); + Console.WriteLine ("Hashcode1: " + o.GetHashCode ()); + + MyDel d = o.DoStuff; + Console.WriteLine ("Hashcode2: " + d.GetHashCode ()); + Console.WriteLine ("Hashcode3: " + o.GetHashCode ()); + + o.Dispose (); + Console.WriteLine ("Hashcode4: " + d.GetHashCode ()); + } + + class MyTarget : IDisposable { + public int counter = 0; + bool avail = true; + + public void DoStuff (int i, int j) { + counter += i + j; + } + + public void Dispose () { + avail = false; + } + + public override int GetHashCode () { + if (!avail) + throw new ObjectDisposedException ("MyTarget is dead"); + return counter.GetHashCode (); + } + } +} diff --git a/mono/utils/mono-counters.c b/mono/utils/mono-counters.c index a7108623b82..8aed4659391 100644 --- a/mono/utils/mono-counters.c +++ b/mono/utils/mono-counters.c @@ -150,7 +150,7 @@ register_internal (const char *name, int type, void *addr, int size) for (counter = counters; counter; counter = counter->next) { if (counter->addr == addr) { - g_warning ("you are registering twice the same counter address"); + g_warning ("you are registering the same counter address twice: %s at %p", name, addr); mono_os_mutex_unlock (&counters_mutex); return; } diff --git a/mono/utils/mono-dl-posix.c b/mono/utils/mono-dl-posix.c index c2b2b96d9d7..ea1b595c4a5 100644 --- a/mono/utils/mono-dl-posix.c +++ b/mono/utils/mono-dl-posix.c @@ -15,7 +15,7 @@ #include #endif -#if defined(_POSIX_VERSION) +#if defined(_POSIX_VERSION) && !defined (HOST_WASM) #include "mono/utils/mono-dl.h" #include "mono/utils/mono-embed.h" diff --git a/mono/utils/mono-hwcap-s390x.c b/mono/utils/mono-hwcap-s390x.c index 40318232c21..f6a6dfa9a5a 100644 --- a/mono/utils/mono-hwcap-s390x.c +++ b/mono/utils/mono-hwcap-s390x.c @@ -63,7 +63,7 @@ typedef struct { uint8_t ee:1; // 035 - Execute extensions uint8_t em:1; // 036 - Enhanced monitor uint8_t fpe:1; // 037 - Floating point extension - uint8_t x001:1; // 038 - Undefined + uint8_t opcf:1; // 038 - Order-preserving-compression facility uint8_t ibm03:1; // 039 - Assigned to IBM uint8_t spp:1; // 040 - Set program parameters uint8_t fpse:1; // 041 - FP support enhancement @@ -79,11 +79,11 @@ typedef struct { uint8_t ltlb:1; // 051 - Local TLB clearing uint8_t ia:1; // 052 - Interlocked access uint8_t lsoc2:1; // 053 - Load/store on CC 2 - uint8_t x002:1; // 054 - Undefined + uint8_t eecf:1; // 054 - Entropy-encoding compression facility uint8_t ibm05:1; // 055 - Assigned to IBM uint8_t x003:1; // 056 - Undefined uint8_t msa5:1; // 057 - Message security assist 5 - uint8_t x004:1; // 058 - Undefined + uint8_t mie2:1; // 058 - Miscellaneous execution facility 2 uint8_t x005:1; // 059 - Undefined uint8_t x006:1; // 060 - Undefined uint8_t x007:1; // 061 - Undefined @@ -110,11 +110,27 @@ typedef struct { uint8_t x012[5]; // 088-127 - Undefined uint8_t ibm12:1; // 128 - Assigned to IBM uint8_t vec:1; // 129 - Vector facility - uint8_t x013:6; // 130-135 - Undefined - uint8_t x014:6; // 136-141 - Undefined + uint8_t iep:1; // 130 - Instruction Execution Protection Facility + uint8_t sea:1; // 131 - Side-effect-access Faility + uint8_t x013:1; // 132 - Undefined + uint8_t gs:1; // 133 - Guarded Storage Facility + uint8_t vpd:1; // 134 - Vector Packed Decimal Facility + uint8_t ve1:1; // 135 - Vector Enhancements Facilityty + uint8_t x014:2; // 136-137 - Undefined + uint8_t cazm:1; // 138 - Configuration-z/Architecture-arcitectural -mode Faciliy + uint8_t mef:1; // 139 - Multiple-epoch Facility ture-arcitectural -mode Faciliy + uint8_t ibm13:2; // 140-141 - Assigned to IBM uint8_t sccm:1; // 142 - Store CPU counter multiple - uint8_t ibm13:1; // 143 - Assigned to IBM - uint8_t x015[14]; // 144-256 Undefined + uint8_t x015:1; // 143 - Assigned to IBM + uint8_t tpei:1; // 144 - Test Pending External Interrption Facility + uint8_t irbm:1; // 145 - Insert Reference Bits Multiple Facility + uint8_t mse8:1; // 146 - Message Security Assist Extension 8 + uint8_t ibm14:1; // 147 - Reserved for IBM use + uint8_t x016:4; // 148-151 - Undefined + uint8_t x017[2]; // 152-167 - Undefined + uint8_t esac:1; // 168 - ESA/390 Compatibility Mode Facility + uint8_t x018:7; // 169-175 - Undefined + uint8_t x019[10]; // 176-256 Undefined } __attribute__ ((__packed__)) __attribute__ ((__aligned__(8))) facilityList_t; void @@ -131,9 +147,11 @@ mono_hwcap_arch_init (void) : "0", "cc" ); - mono_hwcap_s390x_has_fpe = facs.fpe; - mono_hwcap_s390x_has_vec = facs.vec; - mono_hwcap_s390x_has_mlt = facs.multi; - mono_hwcap_s390x_has_ia = facs.ia; - mono_hwcap_s390x_has_gie = facs.gie; + mono_hwcap_s390x_has_fpe = facs.fpe; + mono_hwcap_s390x_has_vec = facs.vec; + mono_hwcap_s390x_has_mlt = facs.multi; + mono_hwcap_s390x_has_ia = facs.ia; + mono_hwcap_s390x_has_gie = facs.gie; + mono_hwcap_s390x_has_mie2 = facs.mie2; + mono_hwcap_s390x_has_gs = facs.gs; } diff --git a/mono/utils/mono-hwcap-vars.h b/mono/utils/mono-hwcap-vars.h index 47ae051428a..05f89a34ef9 100644 --- a/mono/utils/mono-hwcap-vars.h +++ b/mono/utils/mono-hwcap-vars.h @@ -38,6 +38,8 @@ MONO_HWCAP_VAR(s390x_has_vec) MONO_HWCAP_VAR(s390x_has_mlt) MONO_HWCAP_VAR(s390x_has_ia) MONO_HWCAP_VAR(s390x_has_gie) +MONO_HWCAP_VAR(s390x_has_mie2) +MONO_HWCAP_VAR(s390x_has_gs) #elif defined (TARGET_SPARC) || defined (TARGET_SPARC64) diff --git a/mono/utils/mono-threads-coop.c b/mono/utils/mono-threads-coop.c index 440eff85125..1b9849fe5af 100644 --- a/mono/utils/mono-threads-coop.c +++ b/mono/utils/mono-threads-coop.c @@ -37,6 +37,9 @@ #ifdef _MSC_VER // TODO: Find MSVC replacement for __builtin_unwind_init #define SAVE_REGS_ON_STACK g_assert_not_reached (); +#elif defined (HOST_WASM) +//TODO: figure out wasm stack scanning +#define SAVE_REGS_ON_STACK do {} while (0) #else #define SAVE_REGS_ON_STACK __builtin_unwind_init (); #endif diff --git a/mono/utils/mono-threads-wasm.c b/mono/utils/mono-threads-wasm.c index 6ef8a9c5e84..60816ed8d57 100644 --- a/mono/utils/mono-threads-wasm.c +++ b/mono/utils/mono-threads-wasm.c @@ -7,13 +7,13 @@ #define round_down(addr, val) ((void*)((addr) & ~((val) - 1))) -void -mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize) +int +mono_threads_get_max_stack_size (void) { - *staddr = round_down ((size_t)&staddr, 65536); //WASM pagesize is 64k - *stsize = 65536 * 4; //we say it's 4 pages, there isn't much that uses this beyond the GC + return 65536 * 8; //totally arbitrary, this value is actually useless until WASM supports multiple threads. } + void mono_threads_suspend_init_signals (void) { @@ -57,4 +57,79 @@ mono_threads_suspend_abort_syscall (MonoThreadInfo *info) { } +//---- + +gboolean +mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2) +{ + return id1 == id2; +} + + +MonoNativeThreadId +mono_native_thread_id_get (void) +{ + return (MonoNativeThreadId)1; +} + +MONO_API gboolean +mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg) +{ + g_error ("WASM doesn't support threading"); +} + +static const char *thread_name; + +void +mono_native_thread_set_name (MonoNativeThreadId tid, const char *name) +{ + thread_name = g_strdup (name); +} + +gboolean +mono_native_thread_join (MonoNativeThreadId tid) +{ + g_error ("WASM doesn't support threading"); + return FALSE; +} + +//---- + +gboolean +mono_threads_platform_yield (void) +{ + return TRUE; +} + +void +mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize) +{ + *staddr = round_down ((size_t)&staddr, 65536); //WASM pagesize is 64k + *stsize = 65536 * 4; //we say it's 4 pages, there isn't much that uses this beyond the GC +} + + +gboolean +mono_thread_platform_create_thread (MonoThreadStart thread_fn, gpointer thread_data, gsize* const stack_size, MonoNativeThreadId *tid) +{ + g_error ("WASM doesn't support threading"); + return FALSE; +} + +void mono_threads_platform_init (void) +{ +} + +void +mono_threads_platform_exit (gsize exit_code) +{ + g_error ("WASM doesn't support threading"); +} + +gboolean +mono_threads_platform_in_critical_region (MonoNativeThreadId tid) +{ + return FALSE; +} + #endif diff --git a/mono/utils/networking-missing.c b/mono/utils/networking-missing.c index 32aeb963388..45ccf518a7d 100644 --- a/mono/utils/networking-missing.c +++ b/mono/utils/networking-missing.c @@ -16,7 +16,8 @@ #include #endif -#ifndef HAVE_INET_PTON +//wasm does have inet_pton even though autoconf fails to find +#if !defined (HAVE_INET_PTON) && !defined (HOST_WASM) int inet_pton (int family, const char *address, void *inaddrp) diff --git a/mono/utils/unlocked.h b/mono/utils/unlocked.h index a989dafdbc7..6c4abcf4682 100644 --- a/mono/utils/unlocked.h +++ b/mono/utils/unlocked.h @@ -31,6 +31,20 @@ UnlockedIncrement (gint32 *val) return ++*val; } +MONO_UNLOCKED_ATTRS +gint64 +UnlockedIncrement64 (gint64 *val) +{ + return ++*val; +} + +MONO_UNLOCKED_ATTRS +gint64 +UnlockedDecrement64 (gint64 *val) +{ + return --*val; +} + MONO_UNLOCKED_ATTRS gint32 UnlockedDecrement (gint32 *val) @@ -66,6 +80,13 @@ UnlockedWrite (gint32 *dest, gint32 val) *dest = val; } +MONO_UNLOCKED_ATTRS +void +UnlockedWrite64 (gint64 *dest, gint64 val) +{ + *dest = val; +} + MONO_UNLOCKED_ATTRS gint32 UnlockedRead (gint32 *src) diff --git a/packaging/MacSDK/fsharp.py b/packaging/MacSDK/fsharp.py index eeab6c36a92..f2e7a9bcdb6 100644 --- a/packaging/MacSDK/fsharp.py +++ b/packaging/MacSDK/fsharp.py @@ -8,7 +8,7 @@ class FsharpPackage(GitHubTarballPackage): override_properties={ 'make': 'make' }) self.extra_stage_files = ['lib/mono/xbuild/Microsoft/VisualStudio/v/FSharp/Microsoft.FSharp.Targets'] - self.sources.extend(['patches/fsharp-fix-mdb-support.patch']) + self.sources.extend(['patches/fsharp-portable-pdb.patch', 'patches/fsharp-metadata-table-size-fix.patch']) def prep(self): Package.prep(self) diff --git a/packaging/MacSDK/patches/fsharp-fix-mdb-support.patch b/packaging/MacSDK/patches/fsharp-fix-mdb-support.patch deleted file mode 100644 index 164ad3d2bc8..00000000000 --- a/packaging/MacSDK/patches/fsharp-fix-mdb-support.patch +++ /dev/null @@ -1,29 +0,0 @@ -commit 26e3e557e25b0ba5103dfb683050d2435f7708bb -Author: Ankit Jain -Date: Wed Feb 8 18:44:41 2017 -0500 - - [msbuild] Add support for .mdb files to be copied, with mono's msbuild - - msbuild defaults to .pdb files as the default debug file extension. - Mono's msbuild has `$(_DebugFileExt)` property to override this. We need - to set that to `.mdb`, else the generated `.mdb` files won't get - copied/deployed. - - But this feature is not upstream yet, so it is not present in upstream - F# yet. - -diff --git a/src/fsharp/FSharp.Build/Microsoft.FSharp.targets b/src/fsharp/FSharp.Build/Microsoft.FSharp.targets -index e185bdf..2788988 100644 ---- a/src/fsharp/FSharp.Build/Microsoft.FSharp.targets -+++ b/src/fsharp/FSharp.Build/Microsoft.FSharp.targets -@@ -38,6 +38,10 @@ this file. - RootNamespace - false - $(Prefer32Bit) -+ -+ -+ <_DebugFileExt Condition="'$(FscDebugFileExt)' != ''">$(FscDebugFileExt) -+ <_DebugFileExt Condition="'$(_DebugFileExt)' == ''">.mdb - - - ++ <_ConfigurationNameTmp>$(ConfigurationName) ++ <_ConfigurationNameTmp Condition="'$(ConfigurationName)' == ''">$(Configuration) ++ ++ ++ <_DebugFileExt>.pdb ++ <_DebugFileExt Condition="'$(FscDebugFileExt)' != ''">$(FscDebugFileExt) ++ ++ portable ++ $(FscDebugType) + + +