* [merp] Put thread into async context before running summarizer
[merp] Put thread into async context before running summarizer
Followup work for https://github.com/mono/mono/pull/17090
In order to get managed method info for unmanaged stacktraces, we call
`mini_jit_info_table_find_ext` which calls `decode_exception_debug_info` which may
allocate if it's not in async context.
Do the switch in `mono_threads_summarize_execute` so that non-supervising threads
all switch when they run the `sigterm_signal_handler`. `mono_threads_summarize`
already does it for the supervisor thread.
Fixes https://github.com/mono/mono/issues/17180
Backport of #17194.
/cc @lambdageek
* [merp] Don't call install_state_summarizer in EnableMicrosoftTelemetry
install_state_summarizer installs a SIGTERM handler. Unfortunately
sigterm_signal_handler assumes that it will only be called when a crash is
already in progress (it assumes it won't be the supervisor, and so it doesn't
setup the memory for capturing a crash report among other things).
* [merp] Register SIGTERM handler in dump_native_stacktrace
Previously it was installed by EnableMicrosoftTelemetry, which is too early.
Now we get here without a handler installed even when mono_merp_enabled returns true.
There is an issue with jumping into DST for some time zones when the incorrect date-time offset is returned for date-time in UTC (which comes from DateTime.Now). The fix is to just check if the incoming date-time is in UTC
Also I added set of tests for some time zones but they verify jumping into DST in general.
Fixes https://github.com/mono/mono/issues/16395
Backport of https://github.com/mono/mono/pull/16430
* [2019-06] Bump msbuild and sdk versions to 3.0.1xx latest
* Bump msbuild again to pull in the build updates
* pull in roslyn-binaries fix
* One more bump
* Fix the roslyn hash
* [msbuild] Bump to pick up a build fix from https://github.com/mono/msbuild/pull/138
* Pull in final update from msbuild of nuget and sdk
NuGet 5.3.0-rtm.6251
Sdk 3.0.100-rc2.19467.3
* Pick up packaging fix in https://github.com/mono/msbuild/pull/141
We sometimes saw the following build error in Mono SDKs builds on Jenkins:
```
[2019-09-16T01:03:30.709Z] CSC [xammac] nunit-lite-console.exe
[2019-09-16T01:03:30.709Z] error CS0009: Metadata file '/Users/builder/jenkins/workspace/archive-mono/2019-08/mac/release/mcs/class/lib/xammac/nunitlite.dll' could not be opened -- PE image doesn't contain managed metadata.
```
Taking a closer look we found out that nunit-lite was trying to be built twice for the same profile which caused a race where the file was corrupted.
The reason for this is that the corlib Makefile defines two test assemblies: the normal PROFILE_corlib_test.dll and BinarySerializationOverVersionsTest.dll and
integrating the BinarySerializationOverVersionsTest.dll via the `test-vts` target incorrectly overwrote the `test` target instead of using `test-local`.
Backport of #16894.
Callers of mono_reflection_create_custom_attr_data_args_noalloc were leaking some of the returned information. Accessed attributes are FixedBufferAttribute and UnmanagedFunctionPointerAttribute.
Add RenamedEvent* to FSW sources from CoreFX
Fixes#16486 - This was only partially fixed until now
* [csproj] Update project files
* Add test files which test these code paths on corefx
* Revert "[aot] partial revert of #14043 (#14135)"
This reverts commit 223e0bd78d.
* Revert "[aot] change method table generation so that it works for larger assemblies on ARM (#14043)"
This reverts commit 9ff3b0d65e.
* Use the right FileSystemWatcher sources
The corefx code for FileSystemEventArgs has some changes to support
constructing one with a null filename.
Fixes#16486
* Remove the mono sources for the newly replaced files
* [csproj] Update project files
Resolves https://github.com/mono/mono/issues/16122
Since we put in the corefx version of GZipStream, it is expected that
our version of DeflateStream actually implements Write+ReadAsyncMemory.
This change does that by just calling the plain WriteAsync & ReadAsync
methods until we decide (or not) to pull in the corefx DeflateStream.
Backport of https://github.com/mono/mono/pull/16523.
* [w32socket] Translate some errno codes to WSA_ errors imprecisely.
These aren't a perfect match, but better than falling into the `default` case
where Mono asserts and crashes.
Addresses part of https://github.com/mono/mono/issues/16024
* [w32error] Add WSA_INVALID_PARAMETER and WSA_INVALID_HANDLE
Backport of #16331.
As of XCode 11 beta6 the MacOSX SDK defines the MAP_32BIT symbol.
This causes the `mono_valloc()` function to try to use the `MAP_32BIT` flag for `mmap()`.
However as mentioned in the comment for the symbol in mman.h it seems to require a special entitlement which isn't available/documented anywhere yet.
This in turn causes the mmap call to fail presumably because we're missing that entitlement.
Instead we now skip setting this flag on Apple platforms to make `mmap()` behave like it did before.
Backport of https://github.com/mono/mono/pull/16441
* Bump msbuild to track mono-2019-06
.. to get changes from https://github.com/mono/msbuild/pull/130
which tracks dotnet `release/3.0.100-preview9`.
Also, bump Roslyn to 3.3.1-beta3-19421-04 .
* Bump the roslyn reference
Using the CoreCLR version of this line fixed the problem and my investigations
also revealed why.
The `SafePipeHandle` contains a reference to both the Socket as well as the
`SafeSocketHandle`, taking ownership of them. If there are no additional
references to either of them, so that both are collected in the same GC pass,
their finalizer may be invoked in any order.
If the Socket gets finalized first, it's `SafeSocketHandle` will have a `_mstate`
of 8 (two references) at the beginning of `DangerousReleaseInternal()` - which
will set it to 6 (one reference plus disposed flag).
Then when the `SafePipeHandle` gets collected, it will call `DangerousRelease ()`
on it's `SafeSocketHandle`. As mentioned above, it's `_mstate` will be 6.
Now we own the handle, so we'll decrease it's reference count by one and set the
`Closed` flag - the new `_mstate` should thus be 3.
However, using
new_state = (old_state & RefCount_Mask) - RefCount_One;
would set it to 1 - thus effectively clearing the `Disposed' flag. And since it's
reference count is now also zero, the next finalize pass will then throw.
The CoreCLR version of this class uses
new_state = old_state - RefCount_One;
which fixes this.
Backport of #16244.
The intention of calling `g_file_test (file, G_FILE_TEST_EXISTS)` where file is
the name of a shared library we want to open is to speed up probing for
non-existent libraries.
See https://github.com/mono/mono/pull/12074
The problem is that if file is just a simple "libdl.so" then `dlopen (file)`
doesn't just look for it in the current working directory, it will probe some
other paths too. (For example on desktop linux you'd also look in all the
directories in LD_LIBRARY_PATH). So the g_file_test() call is not a robust way
to avoid calling dlopen if the filename is relative.
But it actually broke more things: https://github.com/xamarin/xamarin-android/issues/3388
When probing for "libdl.so" on Android mono_lookup_pinvoke_call will first try
prepending some paths that it knows about and we end up calling
`dlopen ("/system/lib/libdl.so")` which will fail because Bionic has security
restrictions on what code can dlopen something from /system/lib with an
absolute path. Eventually mono_lookup_pinvoke_call will go back to trying the
bare "libdl.so" which hits `g_file_test` and returns NULL.
The new code only does the file test if we pass it an absolute path, which
gives Bionic's dlopen a chance to deal with relative paths however it needs to.
* Add missing `Dispose()` call on error in `MonoTlsStream.CreateStream()`.
* Remove the `finally` block to make it more easy to read.
Backport of #16233.
Fixes https://github.com/mono/mono/issues/16032
When we switched to corefx File.Copy on unix, the behavior changed where it opened a source and destination stream in order to pass the safe handles to Interop.Sys.CopyFile. This exposed a flaw in our sharing validation rules in MonoIO.Open, which threw an exception in this scenario:
new FileStream("source.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, 2048, FileOptions.DeleteOnClose);
new FileStream("source.txt", FileMode.Open, FileAccess.Read, FileShare.Read, 2048, FileOptions.None);
Simplified the FileShare check down to:
1. If the caller specifies FileShare.None, then it's an exclusive lock and no
sharing is allowed.
2. If the caller specifies some other FileShare option, then FileShare.None
cannot be specified.
This will allow the interpreter to use System.Reflection.Emit.
Note: There is a small size increase (about 50kb) for an application
built in release mode with the LLVM backend (even if the interpreter
is now used).
Backport of https://github.com/mono/mono/pull/16151
* Fixed RuntimeType.GetConstructorCandidates("") to return 0 elements.
https://github.com/mono/mono/issues/16010
The current behavior for GetConstructorCandidates when the name is null, "",
or "*" is to return the set of constructors for the type. For "", .NET Core and
.NET Framework return 0 elements. This PR adds a check for "" to match that
behavior.
* Removed unncessary changes
* Unnecessary spaces
* Made the if check a bit more readable
Prompted by mono/msbuild#123 :
This includes:
Update to upstream vs16.3 branch
SDK update to track dotnet release/3.0.100-preview8
Roslyn updated to 3.3.0-beta2-19381-14
* Work around remoting1.exe test issue with new Roslyn
* [marshal] Always use gchandles in delegate_hash_table
Makes the code easier to follow and it also fixes race from https://github.com/mono/mono/commit/caa4a753ca8e15d43baaa01adb0f56f374b74a2b with boehm.
* [marshal] Free delegates with target that are passed to native code.
For static method delegates, we have a unique delegate_trampoline that is shared among all delegates. We always keep alive the first static method delegate passed to native, by creating a normal gchandle to it and storing it in delegate_hash_table. For instance methods, each delegate will create a separate wrapper and these wrappers are never shared (which was wrongly assumed in https://github.com/mono/mono/commit/caa4a753ca8e15d43baaa01adb0f56f374b74a2b). We shuldn't keep the delegate alive and this commit reverts the behavior for delegate with instance methods introduced in the mentioned commit.
Fixes https://github.com/mono/mono/issues/15751
Backport of #15935.
We need to clearly distinguish between synchronous and asynchronous completions
and avoid any ambiguities and race conditions when it comes to error handling.
On synchronous completion, we must not invoke the async completion delegate.
In `System.Net.Sockets/Socket.cs`, the internal `BeginSConnect()` and `BeginMConnect()`
now return a `bool` indicating whether or not an async operation is pending.
If any error happens prior to starting the async operation, then we shall call
`SocketAsyncResult.Complete(..., true)` and return `false`. And since this is
a synchronous completion, it's `AsyncCallback` will not be invoked.
In `referencesource/System/net/System/Net/Sockets/_MultipleConnectAsync.cs`,
I compared the entire file against the CoreFX version and then copied the
`AttemptConnection()` method from their implementation to adapt their behavior.
The difference is that on synchronous completion, the `InternalConnectCallback(null, args)`
should be invoked.
Backport of #15947.
[2019-06] [threads] Enter GC Unsafe before pumping HP queue in unregister_thread
If the thread info TLS key dtor runs `unregister_thread` from a foreign thread and we have work in the hazard pointer queue, we need to first switch to GC Unsafe mode because some of the free methods passed to `mono_thread_hazardous_try_free` need to be coop-aware.
Also, added checked mode assertions that `conc_table_free` and `jit_info_table_free` are called from GC Unsafe mode.
Fixes https://github.com/mono/mono/issues/15878
Backport of #15890.
/cc @lambdageek
[2019-06][sre] Make creation of dynamic method synchronized
Before, reflection_create_dynamic_method could end up being called by two threads simultaneously. At the end of the method the ilgen field of the MonoReflectionDynamicMethod object is cleared, to enable its collection since it is no longer needed. The problem with this is that it can confuse the other thread compiling the dynamic method, making it see that there is no body.
We could either bother making this clearing work with multiple threads (and I'm not 100% convinced that the rest of the code is thread safe), disable the clearing of ilgen (which would make us use more memory) or go with the simple approach of locking on this DynamicMethod so only one thread is compiling it at one time.
Backport of https://github.com/mono/mono/pull/15803
The C# version doesn't work on 64bit. It would require to update its dependencies, but Zoltan already added a Python version for WebAssembly which works fine.
Some notes:
* changed the semantics of `--xcode-path` in order to match the output of `xcode-select -p`
* switched to python3/pip3
* removed hack for arm64_32, it works properly now because the Python version uses stock `clang`
* removed some leftover usages of `XCODE32_DIR`.
Manually verified by comparing output with the C# version.
This will unblock the iOS team when building on Catalina/Xcode11, as they can't consume SDK archives there. See xamarin/xamarin-macios#6603 (comment)
Contributes to #9621
master (#15744)
In some jobs we use throttle() logic which would mean only one job can execute on master, blocking other jobs in the meantime.
We don't really care which node executes this so let Jenkins pick one.
(cherry picked from commit 7784f20a26)
Before the code
(a, b) = (b, a);
was the equivalent of
a = b;
b = a;
now, it evaluates it to so something like
tmp1 = a;
tmp2 = b;
a = tmp2;
b = tmp1;
Signed-off-by: Bijan Tabatabai <[email protected]>
This is to handle the following example. The issue is that in Check() we have
a constrained call where the called method is IAdder`1<!!U>::PlusPlus() which
is a default interface method, and we need to determine at runtime whether to
box the this argument.
```
using System;
public interface IAdder<T> {
int Add (int x);
int PlusPlus () {
return Add (1);
}
}
interface IGen3<T> { }
struct Adder<T> : IAdder<IGen3<T>> {
int _field;
public int Add (int x) {
_field = x + _field;
return _field;
}
}
public class P {
public static int Check<T, U>(T t) where T : IAdder<U> {
return t.PlusPlus () + t.PlusPlus ();
}
public static void Main () {
var x = new Adder<object> ();
int y = Check<Adder<object>, IGen3<object>> (x);
Console.WriteLine ("expect 2, got {0}", y);
}
}
```
1) Copied changes from corefx for System.Data (also mono/corefx#310)
2) New Tracing api is left empty (because the current API is empty too)
3) New AES types throw PNSE
Bump netstandard.dll AssemblyVersion to 2.1 (fixes#13412)
Backport of #15696.
This reverts commit d732cef5fc.
The github commit status setter step requires a node context so we now just use on on master instead.
(cherry picked from commit 0509ceccb6)
For some reason when using a separate file and loading the function
from there Jenkins still requires us to have a node() context when
calling the function which is not what we want.
In preparation for notarizing our .pkg with Apple we need to bump the timeout
since it can take up to an hour for Apple's server to return a result.
(cherry picked from commit 7480830b36)
* The example that reproduces the bug does this: var thread = vm.GetThreads()[0]; greetingValue = program.InvokeMethod(thread, greeting, new Value[0]) as StringMirror;
But sometimes the Thread[0] was the MainThread of the program and it works, and other times was the GC Finalizer, but when it tries to run something on GC Finalizer thread, the thread is not suspended and throws an exception.
In the fix I removed the Finalizer thread of the list that is returned when CMD_VM_ALL_THREADS is called.
Fix#13311
* The example that reproduces the bug does this: var thread = vm.GetThreads()[0]; greetingValue = program.InvokeMethod(thread, greeting, new Value[0]) as StringMirror;
But sometimes the Thread[0] was the MainThread of the program and it works, and other times was the GC Finalizer, but when it tries to run something on GC Finalizer thread, the thread is not suspended and throws an exception.
In the fix I removed the Finalizer thread if ti's not executing a managed code of the list that is returned when CMD_VM_ALL_THREADS is called.
Fix#13311
* Changing what was suggested by Aleksey.
* Removing unused attribute.
Fixes#15366 and #15306.
- Fixes NULL termination of `StringBuilder` to UTF-16 marshalling. Additionally an extra NULL is added as defense-in-depth protection for incorrect handling in native calls. This extra NULL adds protection when trying to marshal the NULL-terminated string back and the native function doesn't null-terminate at the size of the buffer.
- Fixes marshalling back from UTF-16/UTF-8 buffers into chunked `StringBuilder`.
- Fixes missing `mono_marshal_free` call causing a memory leak when marshalling `StringBuilder` to UTF-16 and back.
- Skips marshalling back to `StringBuilder` when the parameter doesn't have `[Out]` attribute.
Unit tests are still TBD. Not sure where to put them and how to structure them. Any help would be appreciated. /cc @vargaz @EgorBo
Backport of #15392.
* Fixes https://github.com/mono/mono/issues/14839
The local timezone name was not known and defaulted to "Local".
This change adds an sdk function that returns the local name.
Backport of #15667.
* Permit DYLD mangling, so p/invokes work from non-system paths
* Add com.apple.security.cs.disable-library-validation
This is required for the .dylibs used in p/invokes to work.
* Use adhoc signing
(cherry picked from commit 202dca075b)
Android NDK r20 contains a header file (`ioctl.h`) with this code:
int ioctl(int __fd, int __request, ...);
#if !defined(BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD)
/* enable_if(1) just exists to break overloading ties. */
int ioctl(int __fd, unsigned __request, ...) __overloadable __enable_if(1, "") __RENAME(ioctl);
#endif
The `_RENAME` macro is defined as `__asm__(x)` and serves the purpose of
replacing an existing symbol with the new one, decorated with the keyword.
Unfortunately, Mono's `offsets-tool` doesn't parse the header properly as
`CppSharp` doesn't understand `__asm__`:
Processing triple: armv7-none-linux-androideabi
Error parsing '/Users/rodo/git/xa2/external/mono/mono/metadata/metadata-cross-helpers.c'
/Users/rodo/android-toolchain/ndk/sysroot/usr/include/bits/ioctl.h(60,5): error: conflicting types for 'ioctl'
Error parsing '/Users/rodo/git/xa2/external/mono/mono/mini/mini-cross-helpers.c'
/Users/rodo/android-toolchain/ndk/sysroot/usr/include/bits/ioctl.h(60,5): error: conflicting types for 'ioctl'
make: *** [/Users/rodo/git/xa2/external/mono/sdks/builds/android-cross-arm-release/armv7-linux-android.h] Error 1
The workaround, implemented in this commit, is to define the
`BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD` macro thus removing the "conflicting"
declaration from the picture, which changes nothing from the offset tool's point
of view and lets us process the headers in NDK r20 properly.
* Add TypeForwards for:
* System.IO.Enumeration.FileSystemName
* System.Security.Cryptography.CryptographicOperations
Since these were removed in NS 2.1
* Bump API snapshot submodule
[System]: Allow reading fully buffered `HttpWebResponse` body after close.
If we have already read the entire response body, then we should allow the
user to read it even after the request has been aborted.
* `WebConnectionStream.Read ()`: Move `Operation.ThrowIfClosedOrDisposed ()`
call down after argument checks and call a new protected abstract method
called `TryReadFromBufferedContent ()` prior to it.
* `WebResponseStream.TryReadFromBufferedContent ()`: Implement it here.
If the entire response body has been buffered, then `bufferedEntireContent`
is true and `innerStream is BufferedReadStream` and we can call the new
`BufferedReadStream.TryReadFromBuffer ()`.
* `WebResponseStream.ReadAllAsync ()`: Set `bufferedEntireContent = true`
after reading the entire response body.
* `BufferedReadStream.TryReadFromBuffer ()`: New internal method.
Fixes#10645.
Backport of #15220.
* [sdks] Use @loader_path for mono and libmonosgen
This way we are able to dynamically load libmonosgen and also use host
mono binary.
The library dependencies look like this after the change:
```
otool -L /Users/rodo/git/mono/sdks/out/android-host-Darwin-release/bin/mono
/Users/rodo/git/mono/sdks/out/android-host-Darwin-release/bin/mono:
@loader_path/libmonosgen-2.0.dylib (compatibility version 2.0.0, current version 2.0.0)
...
otool -L /Users/rodo/git/mono/sdks/out/android-host-Darwin-release/lib/libmonosgen-2.0.dylib
/Users/rodo/git/mono/sdks/out/android-host-Darwin-release/lib/libmonosgen-2.0.dylib:
@loader_path/libmonosgen-2.0.dylib (compatibility version 2.0.0, current version 2.0.0)
...
```
This test was checking a broken Mono-specific behavior, which has been
removed after we switched to the new corefx-based handler. It also does
not make much sense to use a `Transfer-Encoding` header with a GET request.
In managed, these functions are used as `static external IntPtr`. This means that previously on arm64 the top bits of the return value were garbage. A comparison with 64-bit -1 like in LinuxNetworkChange.EnsureSocket would never be true, which was causing us to hit other assertions in the runtime.
Co-authored-by: Aleksey Kliger <[email protected]>
* Time zone DST out fix
* Add unit tests for Europe/Vatican, Iran and Europe/Guernsey time zones
* Disable the tests on WINAOT; fixed Iran time zone id
CADMessages are passed directly between appdomains. When using contained data, we need to make sure we don't create any cross domain references.
When domains are unloaded, all threads executing code in that appdomain are aborted and the entire heap is traversed and objects in that appdomain are cleared. If any objects in other domains are directly referencing objects in the unloaded domain, they will reference junk. If any, cross domain refs should only be allowed when the referenced object is in the root domain which is never unloaded.
We have seen sporadic failures in thread pool tests on CI related to
test case:
System.Threading.ThreadPools.Tests.ThreadPoolTests.QueueRegisterPositiveAndFlowTest [FAIL]
Assert.Equal() Failure
Expected: 0
Actual: 1
Stack Trace:
at System.Threading.ThreadPools.Tests.ThreadPoolTests.QueueRegisterPositiveAndFlowTest () [0x00143] in D:\j\workspace\z3\label\w64\external\corefx\src\System.Threading.ThreadPool\tests\ThreadPoolTests.cs:337
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in D:\j\workspace\z3\label\w64\mcs\class\corlib\System.Reflection\RuntimeMethodInfo.cs:395
Finally managed to track down the issue to a race when using the same final
event in sequential calls to RegisterWaitForSingleObject. The event could, depending on
timing, get signaled multiple times for the same RegisterWaitHandle instance
causing a thread waiting for completion on another RegisterWaitHandle using same event
to be signaled before that callback was completed. That will cause the race seen in the
failing test above.
Fix make sure we only signal the final event one time per RegisterWaitHandle
instance.
* [jit] Throw exception if casting fails for special array interface
After the standard interface check (mini_emit_iface_cast), for special interfaces we need to do additional checks. We were skipping these checks if the object was not an array, without throwing a cast exception. This code path is reached for configurations where remoting is disabled.
Fixes https://github.com/mono/mono/issues/14729
* [tests] Add test for interface casting case
This test would have failed on fullaot lane for example.
We recently switched the AOT compiler for iOS armv7 from 32bit host to 64bit host. At the same time we _also_ switched from LLVM 3.6 to the newer LLVM 6.0 fork we support.
In a Xamarin.iOS Release build for iOS armv7 exception handling would crash. Specifically the problem was that the exception object wasn't properly injected into the handler block. The way it works is, that the exception handler machinery passes the pointer to the exception object via `r0`.
With the newer LLVM the generated code of the exception handling block
looks like this:
```
LBB1_15: @ %EH_CLAUSE0_BB3
Ltmp8:
ldr r0, [sp, #24]
str r0, [sp, #4]
ldr r0, [sp, #28]
ldr r0, [sp, #12]
ldr r0, [r0]
cmp r0, #0
beq LBB1_17
```
thus overwriting `r0`, so that the pointer to the exception object is lost. With the older LLVM 3.6 the generated code looks like this:
```
LBB1_8: @ %EH_CLAUSE0_BB3
Ltmp8:
str r0, [sp, #4]
ldr r0, [r6]
cmp r0, #0
beq LBB1_10
```
correctly storing the exception object into a stack slot for later usage.
After some time I figured out that there are _different_ exception handling models. Depending on the model, the exception pointer is passed in `r0` or not:
https://github.com/mono/llvm/blob/2bd2f1db1803f7b36687e5abf912c69baa848305/lib/Target/ARM/ARMISelLowering.cpp#L14416-L14428
`SjLj` stands for "SetJump / LongJump" and means that exception handling is implemented with this. On iOS this is the default model that is used. We want `dwarf` instead, so we tell this `llc` now and the generated code handles it correctly.
So why was it working before? In our older LLVM 3.6 fork we hardcoded it:
https://github.com/mono/llvm/blob/f80899cb3eb75f7f5640b4519e83bd96991bffb8/lib/Target/ARM/ARMISelLowering.cpp#L756-L762
The `-exception-model=` option is also not available in LLVM 3.6.
Contributes to https://github.com/mono/mono/issues/15058 and https://github.com/mono/mono/issues/9621
Homebrew Git 2.22.0 misparses the submodule command and passes arguments like --hard and -xdff to git-submodule instead of to git-reset or git-clean. Passing the entire command as a single argument seems to help.
Git mailing list bug report: https://public-inbox.org/git/[email protected]/
* When the catch found is in a MONO_WRAPPER_RUNTIME_INVOKE the exception should be treated as an UNHANDLED by the debugger.
* Adding unit test.
* trying to fix side effect.
* I've tested the MonoTests.DebuggerTests.UnhandledException_2 test on VsWin using .net Framework and I think the test is wrong because the first break is in throw and the next break will be on breakpoint. In our implementation we were ignoring the unhandled exception and stopping only on breakpoint.
Alias analysis attempts to remove indirection when using OP_LDADDR (which fetches the address of a variable). For example :
ldaddr r1 <- r0
load_mem r2 <- r1
is equivalent to
mov r2 <- r0
The remembered r1 alias needs to be forgotten in case r1 is changed. We were handling this for direct assignment with MOV, but not for the more subtle case where an alias to r1 would be passed to a call, which could lead to changing r1.
https://github.com/mono/mono/issues/14872
We have several issues (e.g. https://github.com/mono/mono/issues/14181) where the installer occasionally fails in the postinstall script for unknown causes, on some hosts.
This seems to be sometimes the culpable section and this patch should help trace the issue or alleviate the common symptoms of it (see https://github.com/mono/mono/issues/14181)
Xamarin.Mac can call back here from a native thread that isn't attached to the
runtime. SGen gchandle code is lockfree, and the profiler event can fire
without involving Mono.
Some profiler events (for example gc_handle_deleted) could be raised on threads
that aren't attached to the runtime. Since the thread won't participate in
Mono's stop the world (since the runtime can't see it), there's no need to do
the transition to GC Safe while the thread is trying to grab the profiler
buffer lock.
* Implementing reabstraction of default interface methods.
* Fixing side effect on unit tests. Tested with another example and changed the implementation: using System; public interface I1 { void M1(); /*void M2(){ System.Console.WriteLine("I1.M2"); }*/ }
public interface I2 : I1
{
abstract void I1.M1();
/* void M2(){
System.Console.WriteLine("I2.M2");
}*/
}
class Test1 : I2
{
static void Main()
{
I1 i1 = new Test1();
i1.M1();
//i1.M2();
}
void I1.M1()
{
System.Console.WriteLine("Test1.M1");
}
}
* Fixing side effect on unit tests.
* Fixing side effect on unit tests.
* Implementing unit test. Fixing side effect.
* Fix unit test.
* Fixing reabstraction.il coreclr test.
* Changing comments.
* Changing things pointed by Aleksey.
* Changing things pointed by Aleksey. Implementing generics test.
* Changing things pointed by Aleksey.
The thread_stopped profiler event can be raised by the thread_info_key_dtor tls
key destructor when the thread is already doesn't have a domain set. In that
case, don't call process_profiler_event since it cannot handle a thread with
null TLS values.
Addresses https://github.com/xamarin/xamarin-android/issues/2920
with the following stack trace
```
* thread #20, name = 'Filter', stop reason = signal SIGSEGV: invalid address (fault address: 0xbc)
* frame #0: libmonosgen-2.0.so`mono_class_vtable_checked(domain=0x0000000000000000, klass=0x0000007200230648, error=0x00000071e92f9178) at object.c:1890
frame #1: libmonosgen-2.0.so`get_current_thread_ptr_for_domain(domain=0x0000000000000000, thread=0x00000071ebfec508) at threads.c:595
frame #2: libmonosgen-2.0.so`mono_thread_current at threads.c:1939
frame #3: libmonosgen-2.0.so`process_event(event=<unavailable>, arg=<unavailable>, il_offset=<unavailable>, ctx=<unavailable>, events=<unavailable>, suspend_policy=<unavailable>) at debugger-agent.c:3715
frame #4: libmonosgen-2.0.so`thread_end [inlined] process_profiler_event(event=EVENT_KIND_THREAD_DEATH, arg=0x00000071ebfec508) at debugger-agent.c:3875
frame #5: libmonosgen-2.0.so`thread_end(prof=<unavailable>, tid=<unavailable>) at debugger-agent.c:3991
frame #6: libmonosgen-2.0.so`mono_profiler_raise_thread_stopped(tid=<unavailable>) at profiler-events.h:105
frame #7: libmonosgen-2.0.so`mono_thread_detach_internal(thread=<unavailable>) at threads.c:979
frame #8: libmonosgen-2.0.so`thread_detach(info=0x00000071e949a000) at threads.c:3215
frame #9: libmonosgen-2.0.so`unregister_thread(arg=<unavailable>) at mono-threads.c:544
frame #10: libmonosgen-2.0.so`thread_info_key_dtor(arg=0x00000071e949a000) at mono-threads.c:774
frame #11: 0x00000072899c58e8 libc.so`pthread_key_clean_all() + 124
frame #12: 0x00000072899c5374 libc.so`pthread_exit + 76
frame #13: 0x00000072899c5264 libc.so`__pthread_start(void*) + 44
frame #14: 0x000000728996617c libc.so`__start_thread + 72
```
This is unfortunate.
The general pattern of:
if initialized
use the data
else:
initialize the data, possibly with lots of locks and barriers
mark initialized
is racy, because "use the data" can be scheduled ahead of "if initialized".
"Barriers come in pairs" generally, and this was missing one.
It depends somewhat. If the data is all pointers, initialized in the else path,
from null to non-null, and use includes dereferencing, which is a common
but not universal case, then it is ok on all non-Alpha processors, due
to "data dependency".
But if the data includes reading globals, then there is a race.
This is a bit of a slow down on fast paths on arm, and possibly
other architectures.
There are barrier-free ways to solve this, involving a thread local,
that should seriously be considered, and applied throughout the runtime.
The runtime has a lot of on-demand initialization and a lot of looks racy.
See www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm.
Which would have to be adopted to be coop-friendly which should not be difficult.
Notice that the existing "lazy" mechanism is also not coop-friendly.
That is not changed by this PR.
* [System.Net.Http]Add hack to the legacy HttpClient to pass down Timeout property. #12577.
* `HttpClientHandler`, `IMonoHttpClientHandler`: add new internal `MonoSetTimeout (TimeSpan)` function.
* `HttpClient.SendAsyncWorker()`: if `handler` is `HttpClientHandler`, call the new internal
`MonoSetTimeout()` function to pass down the timeout.
* `MonoWebRequestHandler.SendAsync()`: this is only used here to pass the timeout to the `HttpWebRequest`.
* Address feedback.
* Update HttpMessageInvoker.cs
* Make it build.
* Really make it build (forgot monotouch_watch).
* [llvm] Enable disabling inlining on llvm
* [llvm] Fix disabling direct calls on llvm
* [llvm] Rename mono_inited even when doing self_init (generated init functions refer to it)
Prevent the SDKs from making dangling symlinks when packaging the MXE
cross-compilers: should hav
mono.exe -> mono-sgen.exe
rather than
mono -> mono-sgen (dangling).
* RSACertificateExtensions.CopyWithPrivateKey(): implement.
Since `RSACertificateExtensions` lives in `System.Core` and only `mscorlib`
internals (but not `System` internals) are visible to it, we need to use a
little trick here:
* System.Security.Cryptography.X509Certificates.X509CertificateImpl:
add new abstract methods CopyWithPrivateKey() and CreateCertificate().
* System.Security.Cryptography.X509Certificates.X509Certificate2Impl:
sealed implement them here.
The `httpcfg` tool, only checks whether the key is valid, so we don't really
need to call `CopyWithPrivateKey()` (which requires us to take a dependency
on `System.Core`).
* [AppDomain] Cross-appdomain wrapper throws NIE for methods with ref struct arguments
If we have a ref struct and a method that takes it as an argument:
```
[Serializable]
public ref struct R {
public int i;
}
public interface I {
public void M1 (R r, SomeClass o);
}
public class M : MarshalByRefObject, I {
public void M1 (R r, SomeClass o) { ... }
}
```
If we create an instance of M in another domain and try to call it:
```
I obj = (I)otherDomain.CreateInstanceAndUnwrap (typeof(M).Assembly.FullName,
nameof(M));
R r;
r.i = 42;
SomeClass o = ...;
obj.M1 (r, o);
```
Mono will need to create a wrapper that can invoke M.M1 in the other domain.
The way the wrapper works in `mono_marshal_get_xappdomain_invoke` is by
creating an array of all the arguments that need to be serialized (see
`mono_get_xdomain_marshal_type`) and then serializing the whole array (by
calling out to `System.Runtime.Remoting.RemotingServices.SerializeCallData`).
In the example it would make a two element array and try to serialize `r` and
`o` into it. For valuetypes it normally does this by boxing the argument.
However since `R` is a ref-struct, boxing it is not allowed.
This works on .NET Framework.
However for Mono we would need to serilize `R` without boxing it, which seems
challenging with our current setup.
So for now we generate a wrapper that just throws a NotImplementedException if
it is ever called.
This fixes https://github.com/mono/mono/issues/14809 (in that marshalling a
TextWriter across domains works again) but in an unsatisfactory way (because
you can't call any of the ReadOnlySpan<char> overloads on the transparent proxy
object).
* [corlib] Add back Serializable attribute on some reflection classes
Tests that use https://www.nuget.org/packages/NUnit.ApplicationDomain/
need to serialize MethodInfo (and hence MethodBase).
* [corlib] Add test for transparent proxies for classes with methods that take ref struct args
Regression test for https://github.com/mono/mono/issues/14809
* Bump API snapshot submodule
Contributes to https://github.com/mono/mono/issues/9621
Fixes https://github.com/mono/mono/issues/14841
Note that it breaks iOS 32bit on devices. The Apple Watch _might_ still works (only tested on `2019-02`). It unblocks some build related issues on the Xamarin.iOS `2019-06` integration, and we have to do it anyway. I'll come back to it to fix device related issues.
It is important to provide this, otherwise the `opt` command will make modifications of every GC safepoint load. For the SmartHotel360 Android app, this can result in `opt` taking 19 minutes and 20 seconds to finish the optimization of the Mono.Android.dll AOT modules.
### IR Example:
Before Opt:
```
> %GC_SAFE_POINT_FLAG_7 = load i64*, i64** getelementptr inbounds ([166068 x i64*], [166068 x i64*]* @mono_aot_Mono_Android_llvm_got, i32 0, i32 7), !invariant.load !139597
> %4 = load volatile i64, i64* %GC_SAFE_POINT_FLAG_7
> %5 = icmp eq i64 %4, 0
> br i1 %5, label %CONT_BB2, label %POLL_BB1
```
After Opt:
```
< %GC_SAFE_POINT_FLAG_7 = load i64*, i64** getelementptr inbounds ([166068 x i64*], [166068 x i64*]* @mono_aot_Mono_Android_llvm_got, i64 0, i64 7), align 8, !invariant.load !139597
< %3 = load volatile i64, i64* %GC_SAFE_POINT_FLAG_7, align 4
< %4 = icmp eq i64 %3, 0
< br i1 %4, label %BB2, label %POLL_BB1
```
This has a huge impact on build time, giving InstCombine a huge slowdown. This change removes the need for opt to rewrite all of these basic blocks.
Backport of #14714.
1) CC_MD5_Init, CC_MD5_Update and CC_MD5_Final are deprecated.
```c
mono-md5.c:45:2: error: 'CC_MD5_Init' is deprecated: first deprecated in macOS 10.15 - This function is
cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256
(or stronger). [-Werror,-Wdeprecated-declarations]
CC_MD5_Init (ctx);
^
```
2) objc_msgSend is deprecated
```
mono-threads-mach-helper.c:95:17: error: too many arguments to function call, expected 0, have 2
objc_msgSend (value, release);
~~~~~~~~~~~~ ^~~~~~~~~~~~~~
```
XCode has a special switch `Enable Strict Checking of objc_msgSend Calls` which is now `true` by default. It's fixed by `-DOBJC_OLD_DISPATCH_PROTOTYPES=1` flag to clang or the corresponding define in the source file.
3) Fixes https://github.com/mono/mono/issues/14793
It worked on pre 10.15 without `-framework GSS`, because it got pulled in through the dependencies. You can see it by running DYLD_PRINT_LIBRARIES=1 csharp and then trace it back. On Mojave /System/Library/Frameworks/GSS.framework/Versions/A/GSS got loaded as dependency of /usr/lib/libcups.2.dylib and so on. Unlike Windows, macOS will resolve the symbols to whatever is already available so it was just happy that someone loaded GSS before libmono-native[-compat/-unified].
Due to few recent updates to dotnet/standard (NETStandard 2.1) we had 40 apicompat issues.
Mostly copy-pasted from dotnet/corefx.
Didn't implement Cryptography stuff yet.
Checked all profiles.
Implements #14609
Backport of #14679.
[2019-06] [arm64] Correct exception filter stack frame size
Fixes: https://github.com/mono/mono/issues/14170
Fixes: https://github.com/xamarin/xamarin-android/issues/3112
The `call_filter()` function generated by `mono_arch_get_call_filter()`
was overwriting a part of the previous stack frame because it was not
creating a large enough new stack frame for itself. This had been
working by luck before the switch to building the runtime with Android
NDK r19.
I used a local build of [xamarin/xamarin-android/d16-1@87a80b][0] to
verify that this change resolved both of the issues linked above. I
also confirmed that I was able to reintroduce the issues in my local
environment by removing the change and rebuilding.
After this change, the generated `call_filter()` function now starts by
reserving sufficient space on the stack to hold a 64-bit value at the
`ctx_offset` location. The 64-bit `ctx` value is saved to the
`ctx_offset` location (offset 344 in the new stack frame) shortly
afterwards:
stp x29, x30, [sp,#-352]!
mov x29, sp
str x0, [x29,#344]
As expected, the invocation of `call_filter()` now no longer modifies
the top of the previous stack frame.
Top of the stack before `call_filter()`:
(gdb) x/8x $sp
0x7fcd2774a0: 0x7144d250 0x00000000 0x2724b700 0x00000000
0x7fcd2774b0: 0x1ee19ff0 0x00000071 0x0cc00300 0x00000071
Top of the stack after `call_filter()` (unchanged):
(gdb) x/8x $sp
0x7fcd2774a0: 0x7144d250 0x00000000 0x2724b700 0x00000000
0x7fcd2774b0: 0x1ee19ff0 0x00000071 0x0cc00300 0x00000071
<details>
<summary>Additional background information</summary>
### The original lucky, "good" behavior for [mono/mono/2018-08@725ba2a built with Android NDK r14][1]
1. The `resume` parameter for `mono_handle_exception_internal()` is
held in register `w23`.
2. That register is saved into the current stack frame at offset 20 by
a `str` instruction:
0x00000000000bc1bc <+3012>: str w23, [sp,#20]
3. `handle_exception_first_pass()` invokes `call_filter()` via a `blr`
instruction:
2279 filtered = call_filter (ctx, ei->data.filter);
0x00000000000bc60c <+4116>: add x9, x22, x24, lsl #6
0x00000000000bc610 <+4120>: ldr x8, [x8,#3120]
0x00000000000bc614 <+4124>: ldr x1, [x9,#112]
0x00000000000bc618 <+4128>: add x0, sp, #0x110
0x00000000000bc61c <+4132>: blr x8
Before the `blr` instruction, the top of the stack looks like this:
(gdb) x/8x $sp
0x7fcd2774a0: 0x7144d250 0x00000000 0x0a8b31d8 0x00000071
0x7fcd2774b0: 0x00000000 0x00000000 0x1ef51980 0x00000071
4. `call_filter()` runs. This function is generated by
`mono_arch_get_call_filter()` and starts with:
stp x29, x30, [sp,#-336]!
mov x29, sp
str x0, [x29,#344]
Note in particular how the first line subtracts 336 from `sp` to
start a new stack frame, but the third line writes to a position
that is 344 bytes beyond that, back within the *previous* stack
frame.
5. After the invocations of `call_filter()` and
`handle_exception_first_pass()`, `w23` is restored from the stack:
0x00000000000bc820 <+4648>: ldr w23, [sp,#20]
At this step, the top of the stack looks like this:
(gdb) x/8x $sp
0x7fcd2774a0: 0x7144d250 0x00000000 0xcd2775b0 0x0000007f
0x7fcd2774b0: 0x00000000 0x00000000 0x1ef51980 0x00000071
Notice how `call_filter()` has overwritten bytes 8 through 15 of the
stack frame. In this original lucky scenario, this does not affect
the value restored into register `w23` because that value starts at
byte 20.
6. `mono_handle_exception_internal()` tests the value of `w23` to
decide how to set the `ji` local variable:
2574 if (resume) {
0x00000000000bb960 <+872>: cbz w23, 0xbb9c4 <mono_handle_exception_internal+972>
Since `w23` is `0`, `mono_handle_exception_internal()` correctly
continues into the `else` branch.
### The bad behavior for [mono/mono/2018-08@725ba2a built with Android NDK r19][2] works slightly differently
1. As before, the local `resume` parameter starts in register `w23`.
2. This time, the register is saved into the stack frame at offset 12
(instead of 20):
0x00000000000bed7c <+3200>: str w23, [sp,#12]
3. As before, `handle_exception_first_pass()` invokes `call_filter()`
via a `blr` instruction.
At this step, the top of the stack looks like this:
(gdb) x/8x $sp
0x7fcd2774a0: 0x7144d250 0x00000000 0x2724b700 0x00000000
0x7fcd2774b0: 0x1ee19ff0 0x00000071 0x0cc00300 0x00000071
4. `call_filter()` runs as before. And the first few instructions of
that function are the same as before:
stp x29, x30, [sp,#-336]!
mov x29, sp
str x0, [x29,#344]
5. `w23` is again restored from the stack, but this time from offset 12:
0x00000000000bf2c0 <+4548>: ldr w23, [sp,#12]
The problem is that `call_filter()` has again overwritten bytes 8
through 15 of the stack frame:
(gdb) x/8x $sp
0x7fcd2774a0: 0x7144d250 0x00000000 0xcd2775b0 0x0000007f
0x7fcd2774b0: 0x1ee19ff0 0x00000071 0x0cc00300 0x00000071
So after the `ldr` instruction, `w23` has an incorrect value of
`0x7f` rather than the correct value `0`.
6. As before, `mono_handle_exception_internal()` tests the value of `w23` to
decide how to set the `ji` local variable:
2574 if (resume) {
0x00000000000be430 <+820>: cbz w23, 0xbe834 <mono_handle_exception_internal+1848>
But this time because `w23` is *not* zero, execution continues
*incorrectly* into the `if` branch rather than the `else` branch.
The result is that `ji` is set to `0` rather than a valid
`(MonoJitInfo *)` value. This incorrect value for `ji` leads to a
null pointer dereference, as seen in the bug reports.
[0]: https://github.com/xamarin/xamarin-android/tree/xamarin-android-9.3.0.22
[1]: https://jenkins.xamarin.com/view/Xamarin.Android/job/xamarin-android-freestyle/1432/Azure/
[2]: https://jenkins.xamarin.com/view/Xamarin.Android/job/xamarin-android-freestyle/1436/Azure/
</details>
Backport of #14757.
/cc @lambdageek @brendanzagaeski
Loaded 100 of 273 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.