platform/upstream/dotnet/runtime.git
4 years ago[marshal] Free delegates with target that are passed to native code. (mono/mono#15935)
Vlad Brezae [Thu, 1 Aug 2019 13:06:05 +0000 (16:06 +0300)]
[marshal] Free delegates with target that are passed to native code. (mono/mono#15935)

* [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/mono/mono@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/mono/mono@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

Commit migrated from https://github.com/mono/mono/commit/e3ca891235609663785d70aa1bbc544232070321

4 years ago[mini] Ignore conv.r.un if top of stack is already float (mono/mono#15818)
Vlad Brezae [Thu, 1 Aug 2019 12:21:50 +0000 (15:21 +0300)]
[mini] Ignore conv.r.un if top of stack is already float (mono/mono#15818)

Fixes https://github.com/mono/mono/issues/15794

Commit migrated from https://github.com/mono/mono/commit/ce398411a06b85441611565b9b6119c2702cb284

4 years agoFactor copy/pasted code into mono_gstring_append_thread_name. (mono/mono#15920)
Jay Krell [Wed, 31 Jul 2019 23:25:31 +0000 (16:25 -0700)]
Factor copy/pasted code into mono_gstring_append_thread_name. (mono/mono#15920)

Extracted from https://github.com/mono/mono/pull/15859.

Commit migrated from https://github.com/mono/mono/commit/180fcfe1fdbddb22b0c52c6e0b169b427b583ab3

4 years ago[tests] Bump sleep for pinvoke3 test (mono/mono#15937)
Vlad Brezae [Wed, 31 Jul 2019 21:24:06 +0000 (00:24 +0300)]
[tests] Bump sleep for pinvoke3 test (mono/mono#15937)

On some operating systems, this test can take forever because the worker starves the other threads by holding the gc_lock. Bump sleeping so it doesn't rely on OS scheduling that much and guarantees other threads can progress in reasonable amount of time.

Commit migrated from https://github.com/mono/mono/commit/985a1c33f26b698c10a0789ae5b241059c2d203f

4 years ago[zlib] Fix typo in readme and remove deleted file from msvc projects
Alexander Köplinger [Wed, 31 Jul 2019 20:58:21 +0000 (22:58 +0200)]
[zlib] Fix typo in readme and remove deleted file from msvc projects

Commit migrated from https://github.com/mono/mono/commit/cf0e2dd97253007b3e0f4b3ddea64436073753f4

4 years agoUpdate zlib from 1.2.5 to 1.2.11. (mono/mono#15480)
Jay Krell [Wed, 31 Jul 2019 20:56:34 +0000 (13:56 -0700)]
Update zlib from 1.2.5 to 1.2.11. (mono/mono#15480)

Circa 2010 to circa 2017.

Retrieved with apt-get source zlib on WSL Ubuntu 18.04.2 LTS.

This matches Debian or Ubuntu (they differ by one commit, and one of them restores a dummy function for compat).

---

* [minizip] Ensure we don't ever accidentally change calling convention

Make sure we always #define ZCALLBACK to empty so we don't change
the calling convention on windows by including a header which defines
'CALLBACK'. This will keep things as cdecl as required by the c#
pinvokes.

* Update zlib readme.

* Update zlib from 1.2.5 to 1.2.11.

* [zlib] Small fix for Visual C++.
see https://github.com/madler/zlib/pull/435/files#diff-0558e84b0c24a83ca790dcb05cd26212R1087
and https://github.com/madler/zlib/pull/435/files#diff-0558e84b0c24a83ca790dcb05cd26212R1104

* Add gzguts.h to Makefiles.

* Add .h files to Visual Studio project files just for GUI purposes.

Commit migrated from https://github.com/mono/mono/commit/431bb95c715abd830a5cfd3e9c37cf79f863cf45

4 years agoFix the netcore build. (mono/mono#15941)
Zoltan Varga [Wed, 31 Jul 2019 20:04:37 +0000 (16:04 -0400)]
Fix the netcore build. (mono/mono#15941)

Commit migrated from https://github.com/mono/mono/commit/1d9a87e449d4badaab86c989b92f3dc9ab792f9c

4 years ago[runtime] Convert more icalls to use handles. (mono/mono#15862)
Zoltan Varga [Wed, 31 Jul 2019 18:08:50 +0000 (14:08 -0400)]
[runtime] Convert more icalls to use handles. (mono/mono#15862)

* [runtime] Convert Volatile to use the same approach as the netcore version, get rid of most Volatile icalls.

* [runtime] Reduce the number of handles used by construct_culture ().

* [runtime] Convert some icalls to handles.

* Fix signature of FAMNextEvent.

* [aot] Avoid aoting the gsharedvt versions of Volatile:Read<T>/Write<T>.

* Bump API snapshot submodule

* Convert Marshal:UnsafeAddrOfPinnedArrayElement to use coop handles.

Commit migrated from https://github.com/mono/mono/commit/60c277cb4eec4bac9b4149cc345155f3b810e7da

4 years ago[threads] Enter GC Unsafe before pumping HP queue in unregister_thread (mono/mono...
Aleksey Kliger (λgeek) [Wed, 31 Jul 2019 17:30:30 +0000 (13:30 -0400)]
[threads] Enter GC Unsafe before pumping HP queue in unregister_thread (mono/mono#15890)

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

Commit migrated from https://github.com/mono/mono/commit/349a3d5eef9ceaae51ef4d9d984cebab36ef0a2f

4 years agoCleanup and resynchronize Thread/InternalThread fields. (mono/mono#15910)
Jay Krell [Wed, 31 Jul 2019 16:30:50 +0000 (09:30 -0700)]
Cleanup and resynchronize Thread/InternalThread fields. (mono/mono#15910)

- Remove unused.
- Add missing that just happened to work.
- Synchronize size between netcore and regular. `#if` considered bad.

Extracted from https://github.com/mono/mono/pull/15859.

Commit migrated from https://github.com/mono/mono/commit/499a02d6a14edb90263023a452df439f5ab5bd05

4 years agomono_thread_set_name_internal change unreadable boolean parameters to enum flags...
Jay Krell [Wed, 31 Jul 2019 16:30:28 +0000 (09:30 -0700)]
mono_thread_set_name_internal change unreadable boolean parameters to enum flags. (mono/mono#15921)

Extracted from https://github.com/mono/mono/pull/15859.

Commit migrated from https://github.com/mono/mono/commit/9acd4c8004852aa0d2589e78fcfb86c4cf2459f8

4 years ago[jit] Optimize the initialize of MonoError locals. (mono/mono#15869)
Zoltan Varga [Wed, 31 Jul 2019 12:26:24 +0000 (08:26 -0400)]
[jit] Optimize the initialize of MonoError locals. (mono/mono#15869)

Previously, we would emit a call to memset since the struct is large (> 100 bytes). Only the error code field needs to be initialized.

Commit migrated from https://github.com/mono/mono/commit/6223e7468892cd1371fc52a5d1fd0ac1c4e1b273

4 years agoUpdate Haiku support (mono/mono#15674)
Calvin Buckley [Wed, 31 Jul 2019 12:23:48 +0000 (09:23 -0300)]
Update Haiku support (mono/mono#15674)

* Build System.Native.

* Disable `pthread_mutexattr_setprotocol` use, since it returns EINVAL on Haiku.

* Disable the `strerror` cache on Haiku. On Haiku, errors begin at `0x8000_0000` like a Win32 HRESULT. This means the indexing would be on negative numbers, which is a no-no. There are a few alternative ways to keep it though: hashtable, tuple array, offset...

Unfortunately, doesn't build all the way through. Has a tendency to bomb out during building `build-unix`. Will investigate why.

Commit migrated from https://github.com/mono/mono/commit/1059b3e6f59ef92ccba55092fa410e59fdae091f

4 years agoconfigure.ac: Use = as a test(1) operator. (mono/mono#15876)
coypoop [Wed, 31 Jul 2019 12:22:26 +0000 (12:22 +0000)]
configure.ac: Use = as a test(1) operator. (mono/mono#15876)

== is a bash extension
= is POSIX and equivalent

Commit migrated from https://github.com/mono/mono/commit/f86d46d136f2b09f85f005a5a0469db69fafa00d

4 years agoSave 64 bytes from most Linux/amd64 interpreter frames. (mono/mono#15926)
Jay Krell [Wed, 31 Jul 2019 12:20:03 +0000 (05:20 -0700)]
Save 64 bytes from most Linux/amd64 interpreter frames. (mono/mono#15926)

 Probably same on all 64bit architectures. half on 32bit.

before:
```
0000000000003ce0 <interp_exec_method_full>:
    3ce0: 55                    push   %rbp
    3ce1: 48 89 e5              mov    %rsp,%rbp
    3ce4: 41 57                 push   %r15
    3ce6: 41 56                 push   %r14
    3ce8: 41 55                 push   %r13
    3cea: 41 54                 push   %r12
    3cec: 49 89 f4              mov    %rsi,%r12
    3cef: 53                    push   %rbx
    3cf0: 48 89 fb              mov    %rdi,%rbx
    3cf3: 48 81 ec 78 01 00 00  sub    $0x178,%rsp
```

after:
```
0000000000003ce0 <interp_exec_method_full>:
    3ce0: 55                    push   %rbp
    3ce1: 48 89 e5              mov    %rsp,%rbp
    3ce4: 41 57                 push   %r15
    3ce6: 41 56                 push   %r14
    3ce8: 41 55                 push   %r13
    3cea: 41 54                 push   %r12
    3cec: 49 89 f4              mov    %rsi,%r12
    3cef: 53                    push   %rbx
    3cf0: 48 89 fb              mov    %rdi,%rbx
    3cf3: 48 81 ec 38 01 00 00  sub    $0x138,%rsp
```

It was 0x158 recently.

Some frames will be larger, i.e. dynamic + pinvoke.

Classic technique:
 pointer instead of struct
 initialized to null
 alloca it when needed and not null

A more detailed analysis might enable better, such as making
the parameter optional, and/or having the callee default it to its
local storage.

Commit migrated from https://github.com/mono/mono/commit/e0335d357056f9017f7c170ed41f5cb7e3e32399

4 years agoFix some compiler warnings for Win32/mingw64 build (mono/mono#15903)
Nikolay Sivov [Wed, 31 Jul 2019 12:18:53 +0000 (15:18 +0300)]
Fix some compiler warnings for Win32/mingw64 build (mono/mono#15903)

* [mono] Fix unused variable warning in mono_config_parse().

* [ligc] Fix strict prototype warning for Win32 build.

* Add some casts.

Commit migrated from https://github.com/mono/mono/commit/c8fd75734b7f34ed42968bf7ed9b315303b31abc

4 years agoRemove unused libdl setting (mono/mono#15884)
coypoop [Wed, 31 Jul 2019 12:17:34 +0000 (12:17 +0000)]
Remove unused libdl setting (mono/mono#15884)

We test dlopen with no library and in libdl later, without the
use of this setting.

Got the hint since I'm building for a configuration which had it set wrong.

Commit migrated from https://github.com/mono/mono/commit/bed4c00e02400bc49431af8b8095c76caea71220

4 years agoRemove unused declarations (mono/mono#15907)
coypoop [Wed, 31 Jul 2019 12:16:37 +0000 (12:16 +0000)]
Remove unused declarations (mono/mono#15907)

Commit migrated from https://github.com/mono/mono/commit/a65eec76be06778c355e2a74fc36cfa4e241a37a

4 years agoAlways marshal a class as a COM interface if it has the InterfaceType attribute set...
Zebediah Figura [Wed, 31 Jul 2019 12:15:38 +0000 (07:15 -0500)]
Always marshal a class as a COM interface if it has the InterfaceType attribute set. (mono/mono#15671)

This fixes Game Maker Studio 2 Desktop under Wine.

Commit migrated from https://github.com/mono/mono/commit/dc48d9e241e96e3fd26ce09f69bc2b2672f0f39e

4 years ago[cominterop] Handle NULL pointers when marshalling native-to-managed return values...
Zebediah Figura [Wed, 31 Jul 2019 12:14:39 +0000 (07:14 -0500)]
[cominterop] Handle NULL pointers when marshalling native-to-managed return values. (mono/mono#15906)

Fixes a bug running Rak24u with wine-mono: bugs.winehq.org/show_bug.cgi?id=47561

Commit migrated from https://github.com/mono/mono/commit/b51c696081a58515adf53a50e5746ed08bd1062e

4 years agoFix race condition and use less memory in mono_lookup_icall_symbol. (mono/mono#14532)
Jay Krell [Wed, 31 Jul 2019 12:13:21 +0000 (05:13 -0700)]
Fix race condition and use less memory in mono_lookup_icall_symbol. (mono/mono#14532)

It is racy because it is doing on-demand initialization, which is often racy.

The rewrite changes the result to be one pointer, atomically swapped, which implies a full barrier and data dependency, so no race.

It could also be fixed by copying and sorting an array of pairs, and one pointer to that.

However in order to save memory I instead use indirect data that is an array of uint16 pointing into the original data. That is a slight memory vs. time tradeoff.

Yes there is debugging code left, under #if, that I prefer to leave, both as evidence that I tested it, and to make it somewhat but ideally testable in future.

The code also was using an unnecessary somewhat risky but probably ok here way to compare pointers, that I fixed.

As well the result is marginally smaller and faster because it was inlining something like bubblesort, now reuses qsort.

Commit migrated from https://github.com/mono/mono/commit/c37fc12ca5edd9cbf169ac7e4ab5b2e6ef202f79

5 years ago[Coop] Add `TYPED_HANDLE_DECL`. (mono/mono#15909)
Jay Krell [Wed, 31 Jul 2019 10:35:59 +0000 (03:35 -0700)]
[Coop] Add `TYPED_HANDLE_DECL`. (mono/mono#15909)

Extracted from mono/mono#15900.

Commit migrated from https://github.com/mono/mono/commit/bd0c46a8422dc5bbfb6a41fcf913d8db8d817632

5 years agoUpdate CoreFX.issues.rsp (mono/mono#15870)
Filip Navara [Tue, 30 Jul 2019 21:39:34 +0000 (23:39 +0200)]
Update CoreFX.issues.rsp (mono/mono#15870)

Removed tests fixed by mono/mono#13907.
Fixes mono/mono#14945
Fixes mono/mono#14946
Fixes mono/mono#14948

Commit migrated from https://github.com/mono/mono/commit/60bb726eac6d33038d35c27b23f98c73ff5abc4d

5 years ago[Coop] Convert ves_icall_string_new_wrapper_impl. (mono/mono#15901)
Jay Krell [Tue, 30 Jul 2019 21:37:59 +0000 (14:37 -0700)]
[Coop] Convert ves_icall_string_new_wrapper_impl. (mono/mono#15901)

Static analysis prefers not even these short lived raw pointers.
Extracted from mono/mono#15900.

Commit migrated from https://github.com/mono/mono/commit/ca8f155983139beaa306b77cabc2dde365021bd0

5 years ago[Coop] Convert mono_string_from_byvalwstr_impl. (mono/mono#15902)
Jay Krell [Tue, 30 Jul 2019 21:37:09 +0000 (14:37 -0700)]
[Coop] Convert mono_string_from_byvalwstr_impl. (mono/mono#15902)

Remove the raw pointer that static analysis will flag.
Extracted from mono/mono#15900.

Commit migrated from https://github.com/mono/mono/commit/56082ab5284a61cb5e2ca764e71bbeaeee16c374

5 years ago[interp] Simplify the main interpreter loop code to speed up compilation. (mono/mono...
Zoltan Varga [Tue, 30 Jul 2019 20:02:27 +0000 (16:02 -0400)]
[interp] Simplify the main interpreter loop code to speed up compilation. (mono/mono#15889)

* [interp] Simplify the control flow in the main loop to speed up compilation of interp.c.

Get rid of the handle_finally and main_loop labels.

* [interp] Move some rarely used locals to InterpFrame to speed up compilation and to increase the chance that the other locals end up in registers.

* Add macros for throwing exceptions to shorten the code a bit.

* Fix a previous change.

Commit migrated from https://github.com/mono/mono/commit/f8fd60b5c088753a4a0ccb79483ebae73489e7a2

5 years ago[netcore] Replace dl-test-assets.py with msbuild download (mono/mono#15883)
Alexander Köplinger [Tue, 30 Jul 2019 17:27:42 +0000 (19:27 +0200)]
[netcore] Replace dl-test-assets.py with msbuild download (mono/mono#15883)

The python file was unreliable on macOS, let's see whether a simple msbuild replacement is better.

Also fixed dependencies on some of the Makefile targets so that they correctly detect when they need to run.

Commit migrated from https://github.com/mono/mono/commit/9f0d493eea7da2b9494f1e8185740a99fbee00a1

5 years agoFix warnings. (mono/mono#15768)
Jay Krell [Tue, 30 Jul 2019 10:10:30 +0000 (03:10 -0700)]
Fix warnings. (mono/mono#15768)

* boehm-gc.c:1923:14: warning: variable old_obj set but not used [-Wunused-but-set-variable]

* class-init.c:1720:1: warning: compare_by_interface_id defined but not used [-Wunused-function]

* class.c:1724:1: warning: compare_interface_ids defined but not used [-Wunused-function]

* icall.c:8190:13: warning: variable klass set but not used [-Wunused-but-set-variable]

* image.c:1063:20: warning: variable header set but not used [-Wunused-but-set-variable]

* metadata.c:2573:25: warning: right shift count >= width of type [-Wshift-count-overflow]

* sgen-dynarray.h:194:1: warning: dyn_array_int_is_copy defined but not used [-Wunused-function]

* sgen-mono.c:255:1: warning: emit_managed_allocater_noilgen defined but not used [-Wunused-function]
sgen-mono.c:238:1: warning: emit_nursery_check_noilgen defined but not used [-Wunused-function]

* sgen-tarjan-bridge.c:449:25: warning: right shift count >= width of type [-Wshift-count-overflow]

* threads.c:1451:11: warning: variable res set but not used [-Wunused-but-set-variable]

* w32process-unix-default.c:239:19: warning: variable min_dev set but not used [-Wunused-but-set-variable]
w32process-unix-default.c:239:10: warning: variable maj_dev set but not used [-Wunused-but-set-variable]

* w32process-unix.c:2107:25: warning: variable waitret set but not used [-Wunused-but-set-variable]

* aot-compiler.c:4180:1: warning: add_lazy_init_wrappers defined but not used [-Wunused-function]

* aot-compiler.c:7200:86: warning: format %lu expects argument of type long unsigned int, but argument 3 has type gsize {aka unsigned int} [-Wformat=]

* aot-compiler.c:10013:7: warning: unused variable index [-Wunused-variable]

* aot-compiler.c:10012:15: warning: variable method set but not used [-Wunused-but-set-variable]

* method-to-ir.c:4031:22: warning: variable tmpreg set but not used [-Wunused-but-set-variable]

* mini-runtime.c:2977:14: warning: variable invoke set but not used [-Wunused-but-set-variable]

* mono-rand.c:94:1: warning: mono_getentropy defined but not used [-Wunused-function]

Commit migrated from https://github.com/mono/mono/commit/a8d8fb6ceadde1fa0f7ae5dfe4a82f91442877f9

5 years agoRemove mono_thread_get_name. (mono/mono#15875)
Jay Krell [Tue, 30 Jul 2019 01:08:55 +0000 (18:08 -0700)]
Remove mono_thread_get_name. (mono/mono#15875)

Unused since https://github.com/mono/mono/commit/mono/mono@b5c0c831da328b8ab7b7283a38fa56baaa7ae380.
And not likely to come back.

Commit migrated from https://github.com/mono/mono/commit/f1958bacaad3efd3f6f824664d1db39d50d532bb

5 years agoHANDLE_FUNCTION_RETURN_VAL must not use handles in current frame (mono/mono#15873)
Jay Krell [Mon, 29 Jul 2019 23:39:44 +0000 (16:39 -0700)]
HANDLE_FUNCTION_RETURN_VAL must not use handles in current frame (mono/mono#15873)

Commit migrated from https://github.com/mono/mono/commit/929e3135bb12c55f6976763f43dda1371465d1fa

5 years agoFix thread name leak in debugger. (mono/mono#15858)
Jay Krell [Mon, 29 Jul 2019 09:31:14 +0000 (02:31 -0700)]
Fix thread name leak in debugger. (mono/mono#15858)

Commit migrated from https://github.com/mono/mono/commit/b5c0c831da328b8ab7b7283a38fa56baaa7ae380

5 years ago[Coop] Convert System.Buffer. (mono/mono#15861)
Jay Krell [Mon, 29 Jul 2019 09:30:16 +0000 (02:30 -0700)]
[Coop] Convert System.Buffer. (mono/mono#15861)

And inline `mono_array_handle_length`.
And remove `inline` in .c files a little -- it only belongs in .h.

Commit migrated from https://github.com/mono/mono/commit/babcdbdcbd354296a74fa038daf24c38853d9d20

5 years ago[interp] Optimize ldelema (mono/mono#15846)
Vlad Brezae [Sat, 27 Jul 2019 14:37:00 +0000 (17:37 +0300)]
[interp] Optimize ldelema (mono/mono#15846)

Makes the opcode 2-3x time faster

Commit migrated from https://github.com/mono/mono/commit/91b9ff3e535c6d635a07a2d84696a1e333c38800

5 years ago[WIP] [runtime] Convert WindowsIdentity.GetRoles () icall to coop. (mono/mono#15849)
Zoltan Varga [Sat, 27 Jul 2019 06:27:24 +0000 (02:27 -0400)]
[WIP] [runtime] Convert WindowsIdentity.GetRoles () icall to coop. (mono/mono#15849)

* [runtime] Convert WindowsIdentity.GetRoles () icall to coop.

* [runtime] Replace some Buffer icalls with Unsafe methods.

* Fix the windows build.

Commit migrated from https://github.com/mono/mono/commit/9f253249364fa7cfd158647525850c393acc9ec3

5 years ago[netcore] Fix building of nupkg (mono/mono#15855)
Alexander Köplinger [Fri, 26 Jul 2019 22:17:31 +0000 (00:17 +0200)]
[netcore] Fix building of nupkg (mono/mono#15855)

When https://github.com/mono/mono/commit/mono/mono@9010d2f290d28dc97ac276e0c0d32a2932b7550f was merged we stopped including mcs/build/config.make.
However, that file set the VERSION variable which wasn't migrated to the new netcore/config.make so the nuget package missed the version.

Additionally, System.Private.CoreLib sources were moved into the netcore folder and we now seemingly need to pass `-p:IsPackable=true` for dotnet pack to build the nuget package.

Commit migrated from https://github.com/mono/mono/commit/ae488c93e94e326fde066d78fb4311b149f30825

5 years ago[netcore] Implement AssemblyLoadContext.GetLoadedAssemblies() (mono/mono#15832)
Ryan Lucia [Fri, 26 Jul 2019 16:23:43 +0000 (12:23 -0400)]
[netcore] Implement AssemblyLoadContext.GetLoadedAssemblies() (mono/mono#15832)

* [netcore] Implement AssemblyLoadContext.GetLoadedAssemblies()

* No refonly on netcore

* Ifdef out AppDomain.GetAssemblies() on netcore

* Don't init the error

* Unnecessary ifdef

Commit migrated from https://github.com/mono/mono/commit/29428550c22384cfba20a0d2ab3f420caf082b73

5 years ago[netcore] Add a missing make dependency.
Zoltan Varga [Fri, 26 Jul 2019 02:58:39 +0000 (22:58 -0400)]
[netcore] Add a missing make dependency.

Commit migrated from https://github.com/mono/mono/commit/390353d48b802cdec1052bf85c71c538e578403f

5 years ago[metadata] Fields whose types are gparams with a reference type constraint aren't...
Aleksey Kliger (λgeek) [Thu, 25 Jul 2019 21:31:48 +0000 (17:31 -0400)]
[metadata] Fields whose types are gparams with a reference type constraint aren't blittlable. (mono/mono#15761)

* [metadata] Fields whose types are gparams with a reference type constraint
aren't blittlable.
Don't try to layout the field to find out if it's blittable.
For gshared gparams, follow the blittability of the constraint.

Fixes certain recursive examples.

```
using System;

namespace TestRecursiveType
{
    class Program
    {
        static void Main(string[] args)
        {
            SubClass subC = new SubClass();
            Console.WriteLine(subC.GetTest());
        }
    }

    public struct ValueTest<U>
    {
        // When U is instantiated with T, from BaseClass, we know it'll be a
// reference field, so we know the instantiation ValueTest<T> won't
// be blittable.
        public readonly U value;
    }

    public abstract class BaseClass<T> where T : BaseClass<T>
    {
        public ValueTest<T> valueTest = default(ValueTest<T>);
    }

    public class SubClass : BaseClass<SubClass>
    {
        private String test = "test";

        public string GetTest()
        {
            return test;
        }
    }
}
```

Fixes https://github.com/mono/mono/issues/15760

---

The failure is happening when we are doing mono_class_setup_fields ("BaseClass<T>") which needs to decide for each field whether it is blittable or not. So therefore we are trying to decide if ValueTest<T> (that is: the ValueTest<U> field inside BaseClass<T>) is blittable or not.

So we instantiate U with T.
Now to decide whether VaueTest<T> is blittable or not, we look at every field.
So then we look at T value.
To decide if T is blittable we first check if it's a reference type.

That check is currently inadequate for generic parameters - what the PR adds is the ability to see if theres a T : class constraint or a T : C constraint - where C is some class. As soon as we know that T's constraint will force it to be a reference type we can definitely say that T won't be blittable without having to initialize C, at all.

Previously, Mono would see that T is some kind of type for which it couldn't definitively decide that it's a reference type and it would call: mono_class_setup_fields (field_class) which would then try to setup the fields of the parent class BaseClass<T>. And that would hit the recursion check.

Commit migrated from https://github.com/mono/mono/commit/04517d3a3955c5a4a899d88c4af7987b2b277101

5 years ago[tests] Return non-zero exit code from MERP crash test on failure (mono/mono#15804)
Aleksey Kliger (λgeek) [Thu, 25 Jul 2019 15:20:12 +0000 (11:20 -0400)]
[tests] Return non-zero exit code from MERP crash test on failure (mono/mono#15804)

If any of the stress tests fail, return a non-zero exit code from the
supervising process.

Fixes mono/mono#15781

Commit migrated from https://github.com/mono/mono/commit/090dffb9a09f26dc250d8d09a46819d192290b0b

5 years ago[jit] [x86] Cleanup "_body" and finish conversion to x86_byte. (mono/mono#15628)
Jay Krell [Thu, 25 Jul 2019 13:18:20 +0000 (06:18 -0700)]
[jit] [x86] Cleanup "_body" and finish conversion to x86_byte. (mono/mono#15628)

Commit migrated from https://github.com/mono/mono/commit/ee34e2b1223c461c3d55e6f5a031cdfdaa18cd4a

5 years agold configure: Add another dash to export-dynamic. (mono/mono#15717)
Jay Krell [Wed, 24 Jul 2019 23:02:46 +0000 (16:02 -0700)]
ld configure: Add another dash to export-dynamic. (mono/mono#15717)

GNU ld accept single or double dash, means the same thing.
AIX ld warns on single dash, errors on double dash, in autoconf, and then errors on single dash later.
We want the double dash so autoconf rejects it on AIX.

Commit migrated from https://github.com/mono/mono/commit/8cc722683458ab4745bebc3656224014d9927e5c

5 years ago[netcore] Update CoreFX.issues.rsp (mono/mono#15816)
Filip Navara [Wed, 24 Jul 2019 20:04:57 +0000 (22:04 +0200)]
[netcore] Update CoreFX.issues.rsp (mono/mono#15816)

Remove exclusions fixed by mono/mono#14967

Commit migrated from https://github.com/mono/mono/commit/30ce79f3f992221b0a7759d0a90f34eda63d623f

5 years ago[cxx][llvm] Fix C++ build (mono/mono#15807)
Aleksey Kliger (λgeek) [Wed, 24 Jul 2019 16:37:57 +0000 (12:37 -0400)]
[cxx][llvm] Fix C++ build  (mono/mono#15807)

* [cxx] Fix LLVMModuleFlags var initialization

* [cxx] Fix C++ errors in mini-llvm.c

Commit migrated from https://github.com/mono/mono/commit/784b350c40fc966440eab4bb3062b1244d6530df

5 years agoRemove unneeded auto cast with codeman. (mono/mono#15792)
Jay Krell [Wed, 24 Jul 2019 15:31:26 +0000 (08:31 -0700)]
Remove unneeded auto cast with codeman. (mono/mono#15792)

The uses are all void* or casted.

Commit migrated from https://github.com/mono/mono/commit/9e78ce94d51b6df7cefd84b139159bda1d125a5e

5 years ago[sre] Don't throw random exception when runtime shuts down (mono/mono#15798)
Vlad Brezae [Wed, 24 Jul 2019 15:17:09 +0000 (18:17 +0300)]
[sre] Don't throw random exception when runtime shuts down (mono/mono#15798)

Added here https://github.com/mono/mono/commit/89d1455a80ef`

Commit migrated from https://github.com/mono/mono/commit/4f84f21cbc7e29a1586fe2b5e544a0c055d64185

5 years agoRemove traces of w32process-win32-internals.h which was deleted by previous commit
Alexander Köplinger [Wed, 24 Jul 2019 14:52:37 +0000 (16:52 +0200)]
Remove traces of w32process-win32-internals.h which was deleted by previous commit

Commit migrated from https://github.com/mono/mono/commit/6dff5fc81321a4fd9dd493e215d4ace543475054

5 years ago[Coop] Convert System.Diagnostics.{FileVersionInfo,Process}. (mono/mono#15789)
Jay Krell [Wed, 24 Jul 2019 14:50:39 +0000 (07:50 -0700)]
[Coop] Convert System.Diagnostics.{FileVersionInfo,Process}. (mono/mono#15789)

Commit migrated from https://github.com/mono/mono/commit/f68c52c0891975c5489169830d94443469fa3d45

5 years ago[sre] Make creation of dynamic method synchronized
Vlad Brezae [Tue, 23 Jul 2019 16:03:02 +0000 (19:03 +0300)]
[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.

Commit migrated from https://github.com/mono/mono/commit/71630cce754551e2f0414d59afb8824e7e0b0cfc

5 years agoUpdate CoreFX.issues.rsp
Filip Navara [Wed, 24 Jul 2019 08:05:34 +0000 (10:05 +0200)]
Update CoreFX.issues.rsp

Commit migrated from https://github.com/mono/mono/commit/24bffd544a724fdfa101c06b9cd12f7af5918185

5 years ago[netcore] Allow different enums as return type in CreateDelega… (mono/mono#15787)
Egor Bogatov [Wed, 24 Jul 2019 07:50:29 +0000 (10:50 +0300)]
[netcore] Allow different enums as return type in CreateDelega… (mono/mono#15787)

* Relaxed check for return type in CreateDelegate

* fix build errors

Commit migrated from https://github.com/mono/mono/commit/122494330d635205b0a8766deaeafd0d79bd3d60

5 years ago[netcore] Update roslyn dependency
Marek Safar [Wed, 24 Jul 2019 06:43:56 +0000 (08:43 +0200)]
[netcore] Update roslyn dependency

Commit migrated from https://github.com/mono/mono/commit/2a01e1b125c388ebe2a198f808ae7ac4cc4530f2

5 years ago[netcore] Implement AssemblyLoadContext.InternalLoad (mono/mono#15753)
Aleksey Kliger (λgeek) [Tue, 23 Jul 2019 23:09:27 +0000 (19:09 -0400)]
[netcore] Implement AssemblyLoadContext.InternalLoad (mono/mono#15753)

Fixes https://github.com/mono/mono/issues/14830

Commit migrated from https://github.com/mono/mono/commit/7467ce4369adecef24a9c65854e7e39228ac9637

5 years ago[netcore] Bump CoreFX version to 5.0.0 (mono/mono#15795)
Filip Navara [Tue, 23 Jul 2019 22:53:30 +0000 (00:53 +0200)]
[netcore] Bump CoreFX version to 5.0.0 (mono/mono#15795)

* Bump CoreLib version

* Workaround to get dotnet to find dependencies

* Compile CoreLib with nullablePublicOnly

Commit migrated from https://github.com/mono/mono/commit/1551fa7951f3ae568234feda11f06a56e1cc34c6

5 years agoAvoid creating handles in a loop.
Zoltan Varga [Tue, 23 Jul 2019 03:38:47 +0000 (23:38 -0400)]
Avoid creating handles in a loop.

Commit migrated from https://github.com/mono/mono/commit/69d179cba2cfe386196770264415b8ee4c852b4d

5 years ago[runtime] Convert AssemblyBuilder.basic_init to handles using a gc handle to pin...
Zoltan Varga [Sun, 21 Jul 2019 21:46:32 +0000 (17:46 -0400)]
[runtime] Convert AssemblyBuilder.basic_init to handles using a gc handle to pin the object.

Commit migrated from https://github.com/mono/mono/commit/4d1a6358d0e1abc39e8b21986e0a211bd9bec766

5 years ago[runtime] Mark a few icalls as NOHANDLES.
Zoltan Varga [Sun, 21 Jul 2019 21:25:25 +0000 (17:25 -0400)]
[runtime] Mark a few icalls as NOHANDLES.

Commit migrated from https://github.com/mono/mono/commit/063c3ed7f9adc01d6f4cce556e9a0d0de72df70e

5 years ago[runtime] Convert Environment icalls to handles.
Zoltan Varga [Sun, 21 Jul 2019 21:11:31 +0000 (17:11 -0400)]
[runtime] Convert Environment icalls to handles.

Commit migrated from https://github.com/mono/mono/commit/7b384f710c647617d757b4571332ec3359554f0f

5 years agoFix the netcore build.
Zoltan Varga [Sun, 21 Jul 2019 19:56:44 +0000 (15:56 -0400)]
Fix the netcore build.

Commit migrated from https://github.com/mono/mono/commit/fe015de078a72aa3d180297acee63c1395b5e2a5

5 years ago[runtime] Convert ValueType icalls to handles.
Zoltan Varga [Sun, 21 Jul 2019 13:22:52 +0000 (09:22 -0400)]
[runtime] Convert ValueType icalls to handles.

Commit migrated from https://github.com/mono/mono/commit/5ca052fca2fff6f4cb9699c99f35de59319b68c0

5 years ago[runtime] Convert locale code to use handles. (mono/mono#15774)
Zoltan Varga [Tue, 23 Jul 2019 15:33:20 +0000 (11:33 -0400)]
[runtime] Convert locale code to use handles. (mono/mono#15774)

* [runtime] Convert locale code to use handles.

* Sort a list of defines.

* Remove a do-while.

* Fix c++-ism.

* Use mono_string_handle_to_utf8 (). Update comments.

Commit migrated from https://github.com/mono/mono/commit/a9404577e62c5f90b99e8273ef1fb6ec9f6edcb4

5 years ago[cxx][netcore] Fix C++ build (mono/mono#15786)
Aleksey Kliger (λgeek) [Tue, 23 Jul 2019 09:42:51 +0000 (05:42 -0400)]
[cxx][netcore] Fix C++ build (mono/mono#15786)

assembly.c `exact_sn_match` uses bitwise-or on MonoAssemblyNameEqFlags

Commit migrated from https://github.com/mono/mono/commit/148891b51519371638cb1cffea39d330cbd90e11

5 years ago[netcore] Make assembly name parsing and comparison case-insensitive (mono/mono#15522)
Ryan Lucia [Mon, 22 Jul 2019 15:23:26 +0000 (11:23 -0400)]
[netcore] Make assembly name parsing and comparison case-insensitive (mono/mono#15522)

* Re-enable test

* Parse assembly info case-insensitively

* Lowercase the parsed public key token

* Case-insensitive comparison of public key tokens

* Fix string copy

Commit migrated from https://github.com/mono/mono/commit/beb5553398480fee3543a526fff52633dbde12b1

5 years agoFix build on Autoconf 2.63 (mono/mono#15636)
Jo Shields [Mon, 22 Jul 2019 15:20:47 +0000 (11:20 -0400)]
Fix build on Autoconf 2.63 (mono/mono#15636)

* Fix build on Autoconf 2.63

This was broken in mono/mono@e7f9dbe73c3344c96a13892a6c4c45f8e5c35aa3, because
AS_VAR_APPEND does not exist until v2.63b (?!)

* Work around autoconf for Mac not being fit for purpose

The correct way to do this is with AC_DEFUN in a special m4 file

But this dies on Mac, because reasons.

See also https://github.com/jedisct1/libsodium/issues/217

Commit migrated from https://github.com/mono/mono/commit/548fe0e0c18de99350c64ee7f7dd117eb8fb2e0b

5 years agoMiscellaneous loader-related fixes (mono/mono#15765)
Ryan Lucia [Mon, 22 Jul 2019 14:58:12 +0000 (10:58 -0400)]
Miscellaneous loader-related fixes (mono/mono#15765)

* Clarify contents of list

* Fix mono_assembly_get_alc

* Remove pointless ifdef

* Prepend to domain_assemblies

* Revert "Prepend to domain_assemblies"

This reverts commit mono/mono@dbe6e47b80470fa13d22d97d32721d18c4764597.

* Ditch another ifdef

Commit migrated from https://github.com/mono/mono/commit/54f608d08dd6163a7c4a7d48c0e3cb74cb2f7bcd

5 years ago[interp] Enable inlining of object constructors (mono/mono#15665)
Vlad Brezae [Mon, 22 Jul 2019 14:03:26 +0000 (17:03 +0300)]
[interp] Enable inlining of object constructors (mono/mono#15665)

* [interp] Split code for obj / vt newobj instruction

* [interp] Enable inlining of object constructors

If the ctor was inlined, the newobj instruction receives a max ushort as the data item for the index, so it doesn't execute the ctor in this case. Also, when inlining, we need to push on the stack the allocated object, once as argument for the ctor and the second needs to remain on the stack as the result of the IL newobj instruction.

Commit migrated from https://github.com/mono/mono/commit/009b0dd4c307f60e2b7d0b7e512fe8cf97ffb34f

5 years ago Special-case arrays of interfaces/generic parameters in IsAssignableFrom (mono/mono...
Ryan Lucia [Mon, 22 Jul 2019 13:56:48 +0000 (09:56 -0400)]
 Special-case arrays of interfaces/generic parameters in IsAssignableFrom (mono/mono#15749)

* Formatting fix

* Special-case arrays of interfaces/generic parameters

* Make more generic, fix typo

* Consider class constraint and add more elucidating comment

* Fix for potential crash

* Add test

* Fix test

Commit migrated from https://github.com/mono/mono/commit/3c2813deb7720c954554b11344915af803f84138

5 years agoAdd more tests to tarball with EXTRA_DIST
Alexander Köplinger [Mon, 22 Jul 2019 13:23:09 +0000 (15:23 +0200)]
Add more tests to tarball with EXTRA_DIST

Commit migrated from https://github.com/mono/mono/commit/f497893a84601c6ae301a841f27db352706baa9e

5 years ago[netcore] Re-enable AssemblyGetForwardedTypesLoadFailure (mono/mono#15763)
Aleksey Kliger (λgeek) [Mon, 22 Jul 2019 10:52:17 +0000 (06:52 -0400)]
[netcore] Re-enable AssemblyGetForwardedTypesLoadFailure (mono/mono#15763)

Was fixed by https://github.com/mono/mono/pull/15752

Commit migrated from https://github.com/mono/mono/commit/4138f096f851c4d52b612123e8048aed5d7d92b5

5 years ago[netcore] Make System.Linq.Expressions.Tests.BindTests.GlobalField Pass (mono/mono...
Maxim Lipnin [Fri, 19 Jul 2019 21:21:22 +0000 (00:21 +0300)]
[netcore] Make System.Linq.Expressions.Tests.BindTests.GlobalField Pass (mono/mono#15658)

`Expression.Bind` should throw `ArgumentException` if called with `FieldInfo` for a global field. The exception is thrown from validation of the (null) `DeclaringType` (see https://github.com/dotnet/corefx/pull/15318).
Mono returns `"<Module>"` in this case and doesn't throw so the test fails.

Fixes mono/mono#14917 .

Commit migrated from https://github.com/mono/mono/commit/e8d7f7c0045a38c41a70f6d0a21ef3ccf9a21662

5 years agoRemove mono_arch_free_jit_tls_data. (mono/mono#15662)
Jay Krell [Fri, 19 Jul 2019 18:40:54 +0000 (11:40 -0700)]
Remove mono_arch_free_jit_tls_data. (mono/mono#15662)

Commit migrated from https://github.com/mono/mono/commit/3e432663cde4283fc7fa7f81b20bc3d0a9333b38

5 years ago[netcore] Implement Thread.CurrentOSThreadId (mono/mono#15748)
Ryan Lucia [Fri, 19 Jul 2019 17:22:50 +0000 (13:22 -0400)]
[netcore] Implement Thread.CurrentOSThreadId (mono/mono#15748)

* [netcore] Implement Thread.CurrentOSThreadId

* Add comment explaining differences with mono_native_thread_id_get

* Add haiku implementation

* Attempt to fix linux builds

* Add MonoError parameter to icall

Commit migrated from https://github.com/mono/mono/commit/d685b72cb2c37ab73a8470b074a7557e22ce5b00

5 years ago[metadata] Fix name of header file
Alexander Köplinger [Fri, 19 Jul 2019 13:56:12 +0000 (15:56 +0200)]
[metadata] Fix name of header file

The file added as part of mono/mono@d5b374bb51a07bf3525d63b4cef6ad6979c27d07 was actually called loaded-images-internals.h

Commit migrated from https://github.com/mono/mono/commit/3ff64f1efb167d001d61bda64d2f1612d394a0ef

5 years ago[netcore] Fix CI failures (mono/mono#15745)
Egor Bogatov [Fri, 19 Jul 2019 12:06:04 +0000 (15:06 +0300)]
[netcore] Fix CI failures (mono/mono#15745)

Commit migrated from https://github.com/mono/mono/commit/8b2141a741a6348a363a75e91c2a993ec280c1e2

5 years ago[ios] Switch to python offset tool (mono/mono#15744)
Bernhard Urban [Fri, 19 Jul 2019 11:48:02 +0000 (13:48 +0200)]
[ios] Switch to python offset tool (mono/mono#15744)

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 https://github.com/xamarin/xamarin-macios/pull/6603#issuecomment-512803082

Contributes to https://github.com/mono/mono/issues/9621

Commit migrated from https://github.com/mono/mono/commit/3f7d33ce855dc220873b2e679698f65084dbc336

5 years ago[netcore] Pass ALC in second loader request in load_reference_by_aname_default_asmctx...
Aleksey Kliger (λgeek) [Fri, 19 Jul 2019 11:44:07 +0000 (07:44 -0400)]
[netcore] Pass ALC in second loader request in load_reference_by_aname_default_asmctx (mono/mono#15752)

Fixes crash in System.Reflection.Tests netcore testsuite in
System.Reflection.Tests.AssemblyNetCoreAppTests.AssemblyGetForwardedTypesLoadFailure

Commit migrated from https://github.com/mono/mono/commit/944cc96cac7d68bd528a788f9f87339c6e3b0d88

5 years ago[glib] Use clock_nanosleep if available (mono/mono#15443)
Vlad Brezae [Fri, 19 Jul 2019 07:21:21 +0000 (10:21 +0300)]
[glib] Use clock_nanosleep if available (mono/mono#15443)

According to the manual, it is recommended to use clock_nanosleep instead of nanosleep when the sleep can be repeatedly interrupted by signals and resumed. The remaining sleep interval was greater than the original timespec.

Fixes random timeouts of finalizer-abort.exe

Commit migrated from https://github.com/mono/mono/commit/c449308f8bd1c83131b6613711797533504d0c24

5 years ago[loader] Pass ALC to mono_domain_loaded_internal, and then to domain search hook...
Aleksey Kliger (λgeek) [Fri, 19 Jul 2019 04:01:56 +0000 (00:01 -0400)]
[loader] Pass ALC to mono_domain_loaded_internal, and then to domain search hook (mono/mono#15743)

* Add a temporary mono_domain_ambient_alc function

Just use this to mark places where we need to pass through an ALC

* [runtime] Mark mono_assembly_loaded_full external only.

Runtime should use mono_assembly_loaded_internal.

* [loader] Add mono_install_assembly_search_hook_v2

Use it to install mono_domain_assembly_search and
mono_domain_assembly_postload_search.

The principal difference is that we can pass an assembly load context to the
hook.  But also we cleanup the "requesting assembly" hack for
mono_domain_assembly_postload_search.

* [domain] Comments and mono_assembly_get_alc ()

* [debugger] Comment on suspicious loader lock

Commit migrated from https://github.com/mono/mono/commit/a37ad98b470381950c876bb0928cab57fe8156b2

5 years agoMerge pull request mono/mono#15704 from lewing/bump-msbuild-nuget-5.2
Larry Ewing [Fri, 19 Jul 2019 00:45:02 +0000 (20:45 -0400)]
Merge pull request mono/mono#15704 from lewing/bump-msbuild-nuget-5.2

Bump msbuild to track xplat-master

Commit migrated from https://github.com/mono/mono/commit/34be988e33ecb66d724b2dabdba761e8d836ed05

5 years ago[mini] Runtime check if boxing is needed for DIM constrained calls (mono/mono#15729)
Aleksey Kliger (λgeek) [Thu, 18 Jul 2019 20:46:55 +0000 (16:46 -0400)]
[mini] Runtime check if boxing is needed for DIM constrained calls (mono/mono#15729)

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);
}
}
```

Commit migrated from https://github.com/mono/mono/commit/3f55bfb5cc305c1c416edf84fff5440843784deb

5 years ago[interp] Use correctly-sized writes and reads in Unsafe.AddByteOffset and Unsafe...
imhameed [Thu, 18 Jul 2019 18:16:46 +0000 (11:16 -0700)]
[interp] Use correctly-sized writes and reads in Unsafe.AddByteOffset and Unsafe.ByteOffset (mono/mono#15677)

[interp] Use correctly-sized writes and reads in Unsafe.AddByteOffset and Unsafe.ByteOffset

The truncated store to the top of the stack in`MINT_INTRINS_UNSAFE_BYTE_OFFSET` could cause the upper bytes of the address used as the first argument to `ByteOffset` to linger, yielding inaccurate (and usually excessively large) offsets on systems where `sizeof(void *) > sizeof(guint32)`; this made
`System.Text.Unicode.Utf8Utility.GetPointerToFirstInvalidByte` return nonsense results.

The truncation in `MINT_INTRINS_UNSAFE_ADD_BYTE_OFFSET` hasn't, as far as I know, caused any test failures. But `AddByteOffset` takes an `IntPtr` as its second argument, not an `int`.

Fixes mono/mono#14847.

Commit migrated from https://github.com/mono/mono/commit/561b400baa6322dcb3fb6d2b92bd48513fab79f7

5 years ago[netcore] Clean up rsp-file (mono/mono#15700)
Maxim Lipnin [Thu, 18 Jul 2019 16:34:10 +0000 (19:34 +0300)]
[netcore] Clean up rsp-file (mono/mono#15700)

Commit migrated from https://github.com/mono/mono/commit/ab4eca1785672ae9e2aa4930ea45e61a5743aa11

5 years ago[netcore] Revise items in CoreFX.issues.rsp (mono/mono#15664)
Egor Bogatov [Thu, 18 Jul 2019 16:33:38 +0000 (19:33 +0300)]
[netcore] Revise items in CoreFX.issues.rsp (mono/mono#15664)

Commit migrated from https://github.com/mono/mono/commit/e6d2091a245cd4ecda087a53d1e0c60923323482

5 years ago[loader] Add MonoAssemblyLoadContext; stop sharing MonoImages on netcore (mono/mono...
Aleksey Kliger (λgeek) [Wed, 17 Jul 2019 21:35:15 +0000 (17:35 -0400)]
[loader] Add MonoAssemblyLoadContext; stop sharing MonoImages on netcore (mono/mono#15527)

Implement a couple of things:

1. Add a `MonoAssemblyLoadContext` opaque struct
2. On netcore Mono, use it to keep track of  which `MonoImage`s are loaded.  (Addresses part of mono/mono#13891)

In a bit more detail:

- Add a `MonoLoadedImages` struct to hold the hash tables that we use for checking if a `MonoImage` is already loaded
- Add an opaque `MonoAssemblyLoadContext` typedef
- (Framework Mono) Add a `get_global_loaded_images()` function to get the shared `MonoLoadedImages`
- (netcore Mono) Add a `MonoAssemblyLoadContext` struct that owns a `MonoLoadedImages` and add a `default_alc` member to `MonoDomain
- Pass a `MonoAssemblyLoadContext*` to most `MonoImage`-loading functions - on Framework Mono its usually NULL and we fall back to the global loaded images, on netcore Mono it's usually `domain->default_alc->loaded_images`
- (netcore Mono) Create a default Assembly Load Context when a `MonoDomain` is created
- Add a `MonoAssemblyLoadContext*` field to `MonoAssemblyLoadRequest` and pass an ALC in a few places.

---

Remaining work:

(netcore Mono) There are still places where a `MonoAssemblyLoadRequest` or a `MonoAssemblyOpenRequest` has a `NULL` ALC - those will need to be tracked down and fixed.

(netcore Mono) Eventually `MonoAssemblyLoadContext` should keep track of the loaded `MonoAssembly`s, not just images.  One goal on netcore Mono is to ifdef out `MonoDomain:domain_assemblies`.

---

* [loader] Add a MonoLoadedImages struct to own the MonoImage sharing

   Initially, there's just a single global set of loaded images.

   Once we have AssemblyLoadContext support, each ALC will have a separate set.

   NOTE:
     - Some of the existing Mono API is difficult to support with this design
       since it assumes each MonoImage is loaded at most once.

* [loader] Add a MonoAssemblyLoadContext member to MonoImage for netcore

* [loader] Unregister image from its owner when closing

* [loader] Pass MonoLoadedImages to register_image

* [domain] Add mono_domain_default_alc and mono_alc_get_loaded_images

* [loader] Add an AssemblyLoadContext argument to mono_image_loaded_internal

* [metadata] Add mono_image_get_alc ()

* [loader] Pass MonoAssemblyLoadContext to mono_image_open_from_data_internal

* [loader] Pass MonoAssemblyLoadContext to mono_image_open_from_module_handle

* [loaded] Pass MonoLoadedImages to mono_image_open_a_lot_parameterized

* [loader] Pass MonoAssemblyLoadContext to mono_image_open_a_lot

* [runtime] Mark mono_image_open_full external only

   Runtime should use mono_image_open_a_lot.

* [runtime] Mark mono_image_loaded_by_guid external only

   Also mark mono_image_loaded_by_guid_full external only

   Runtime will need some (as yet unwritten) mechanism that takes a MonoAssemblyLoadContext as an argument.

* [domain] Create a default ALC for each MonoDomain

* [netcore] Pass default ALC in mono_core_preload_hook

   If the assembly name matches a trusted platform assembly, open it in the default ALC of the root domain

* [mini] Open main assembly in default ALC in the root domain

* [netcore] Don't define get_global_loaded_images()

   Every assembly load request should come from an assembly load context.  Each ALC has a set of loaded images.  So we should never need a global list.

   With this PR, we no longer share MonoImages across distinct ALCs.  So in principle, each ALC can open the same assembly but resolve its references in different ways.

   Fixes part of https://github.com/mono/mono/issues/13891

* [runtime] Mark mono_pe_file_open external only

* [loader] Pass MonoAssemblyLoadContext to mono_image_open_raw  and mono_image_open_metadata_only

* [loader] Pass MonoAssemblyLoadContext to do_mono_image_open and set MonoImage:alc

* [loader] Add version 2 of assembly preload hook

   Pass MonoAssemblyLoadContext through the preload hook.  This is used in mono_assembly_request_byname_nosearch which, in turn, is called by load_reference_by_aname_default_asmctx which is used to resolve references from one assembly to another.

* [netcore] Pass native ALC ptr to AssemblyLoadContext.InternalLoadFile

* [netcore] Implement AssemblyLoadContext.InternalInitializeNativeALC

   also implement mono_domain_create_individual_alc ()

* [netcore] Pass ALC to System.Reflection.Assembly.InternalLoad

   Pass the domain default ALC to mono_assembly_load ()

   Also pass MonoAssemblyLoadContext to mono_assembly_load_full_gac_base_default ()

* [loader] Implement MONO_LOADED_IMAGES_ASSEMBLY properly

   Store the MonoLoadedImages for netmodules in the MonoImage for the main image of an assembly.  This is also used by SRE - the dummy module of the AssemblyBuilder has the loaded_images that contains the ModuleBuilders.

* [loader] Use global_loaded_images for netmodules with framework Mono

   The new stuff is only for ALC support in netcore

* [loader] Drop netmodule support in MonoAssemblyLoadContext

   netmodules are not supported in netcore

* [loader] Spin out image hashing out of image.c

   Move MonoLoadedImages support code to loaded-images.c loaded-images-global.c and loaded-images-netcore.c

Also spin out assembly-load-context.c for MonoAssemblyLoadContext functions

* Move ALC icall to assembly-load-context.c

* formatting fix

* [msvc] Add new files to .filters

* update comments

* [image] Change mono_loaded_images_remove_image to decrement the refcount

Decrement the refcount and remove the image from the loaded images hashes in
one place.  Change mono_loaded_images_remove_image to return TRUE if the rest
of image unloading should proceed or not.

* [loader] Drop unused argument to mono_alc_init

Commit migrated from https://github.com/mono/mono/commit/d5b374bb51a07bf3525d63b4cef6ad6979c27d07

5 years agoFix leaks in mono_lookup_internal_call_full_with_flags, for lack of destructors....
Jay Krell [Wed, 17 Jul 2019 19:09:19 +0000 (12:09 -0700)]
Fix leaks in mono_lookup_internal_call_full_with_flags, for lack of destructors. (mono/mono#15659)

* Fix leaks in mono_lookup_internal_call_full_with_flags, for lack of C++ destructors.

* Initialize `sigstart` also.

Commit migrated from https://github.com/mono/mono/commit/e2ce0a16a61a02511728d217d92156691dc42289

5 years agoconfigure/makefile To support updating zlib to 1.2.11. (mono/mono#15697)
Jay Krell [Wed, 17 Jul 2019 19:07:56 +0000 (12:07 -0700)]
configure/makefile To support updating zlib to 1.2.11. (mono/mono#15697)

Commit migrated from https://github.com/mono/mono/commit/b08aa719484455c33553ae52394bb48840d653f5

5 years agoPrint two bytes at a time in mono_pe_file_map conversion error (mono/mono#15523)
Ryan Lucia [Wed, 17 Jul 2019 18:49:30 +0000 (11:49 -0700)]
Print two bytes at a time in mono_pe_file_map conversion error (mono/mono#15523)

* Print two bytes at a time

* Iterate over gunichar2

Commit migrated from https://github.com/mono/mono/commit/86e22c4a7fd1477a5d12df3d2495a2c4bbf84ed4

5 years agoAdd com.apple.security.cs.allow-unsigned-executable-memory exception to hardened...
Alexander Köplinger [Wed, 17 Jul 2019 18:48:06 +0000 (20:48 +0200)]
Add com.apple.security.cs.allow-unsigned-executable-memory exception to hardened runtime entitlements (mono/mono#15721)

This avoids the issue from https://github.com/mono/mono/issues/13445 when hardened runtime is enabled.

Commit migrated from https://github.com/mono/mono/commit/c62473114a9a994676383047104549604230c8e6

5 years agoMerge pull request mono/mono#15713 from lewing/sdk-disable-gac
Larry Ewing [Wed, 17 Jul 2019 13:09:36 +0000 (09:09 -0400)]
Merge pull request mono/mono#15713 from lewing/sdk-disable-gac

[ios][android] disable gac in ios and android sdk builds

Commit migrated from https://github.com/mono/mono/commit/36b9e006f324f4291eb0dc97420142339bfc20a8

5 years ago[netcore] Clear system last error before P/Invoke calls with SetLastError=true (mono...
Filip Navara [Wed, 17 Jul 2019 12:44:50 +0000 (14:44 +0200)]
[netcore] Clear system last error before P/Invoke calls with SetLastError=true (mono/mono#15703)

Fixes mono/mono#15691

Commit migrated from https://github.com/mono/mono/commit/9af45e09db9c0d9813be46cd89d7c5092ea9600b

5 years ago[runtime] Fix the error message for exceptions created from MonoError. (mono/mono...
Zoltan Varga [Wed, 17 Jul 2019 01:09:39 +0000 (21:09 -0400)]
[runtime] Fix the error message for exceptions created from MonoError. (mono/mono#15705)

Fixes https://github.com/mono/mono/issues/15692.

Commit migrated from https://github.com/mono/mono/commit/553fee6f03250a981eddf3a0bc9b6fa4f68ecf43

5 years ago[interp] Make the code GC safe on wasm. (mono/mono#15695)
Zoltan Varga [Tue, 16 Jul 2019 21:49:33 +0000 (17:49 -0400)]
[interp] Make the code GC safe on wasm. (mono/mono#15695)

* [interp] Pass the vtable to get_virtual_method () to reduce the number of objrefs being passed around.

* No longer a prototype.

* [interp] Make the code GC safe on wasm.

* Use frame->o only on WASM.

Commit migrated from https://github.com/mono/mono/commit/978653633b976b65497c931252c6fb8b8724a2a9

5 years agoFix use of freed memory. (mono/mono#15660)
Jay Krell [Tue, 16 Jul 2019 20:16:52 +0000 (13:16 -0700)]
Fix use of freed memory. (mono/mono#15660)

Fix use of freed memory.
Move the free later, on the assumption that the free itself doesn't use memory now freed before it.
Found with Valgrind.

Commit migrated from https://github.com/mono/mono/commit/43f1a268045a1a3746bfd4a610b7b4874599aa38

5 years ago[netcore] Use the strict loader (mono/mono#15668)
Aleksey Kliger (λgeek) [Tue, 16 Jul 2019 18:30:16 +0000 (14:30 -0400)]
[netcore] Use the strict loader (mono/mono#15668)

Mono historically was quite lax in how it resolved assembly references - it
would pick the first assembly with a matching simple name.  The "strict"
mode (available in framework Mono with `--assembly-loader=strict`) follows the
spec behavior: the version and public key token of the candidate assembly must
match what is requested.

Commit migrated from https://github.com/mono/mono/commit/d8a679375d706e992d590c3eb90e1c57cb2864e7

5 years ago[netcore] Ignore public key when matching assemblies (mono/mono#15678)
Filip Navara [Tue, 16 Jul 2019 18:05:26 +0000 (20:05 +0200)]
[netcore] Ignore public key when matching assemblies (mono/mono#15678)

Related to mono/mono#15669

Commit migrated from https://github.com/mono/mono/commit/d2f7851c92f697ef96fe402353768f011d465827

5 years ago[debugger] Don't list finalizer gc thread if it's not executing managed code (mono...
Thays Grazia [Mon, 15 Jul 2019 14:58:04 +0000 (11:58 -0300)]
[debugger] Don't list finalizer gc thread if it's not executing managed code (mono/mono#15618)

* 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 it's not executing a managed code of the list that is returned when CMD_VM_ALL_THREADS is called.

Fix mono/mono#13311

Commit migrated from https://github.com/mono/mono/commit/73128453daff8966f1c8eeacb734579971b02218

5 years agoFix leak in create_runtime_invoke_info when mono_class_vtable_… (mono/mono#15661)
Jay Krell [Mon, 15 Jul 2019 09:34:54 +0000 (02:34 -0700)]
Fix leak in create_runtime_invoke_info when mono_class_vtable_… (mono/mono#15661)

Commit migrated from https://github.com/mono/mono/commit/ceb09980f56bcafbe95247f081bf4233c9544e25

5 years agoTrim mono_mini_arch_lock, mono_mini_arch_unlock, mini_arch_mutex. (mono/mono#15663)
Jay Krell [Mon, 15 Jul 2019 09:34:35 +0000 (02:34 -0700)]
Trim mono_mini_arch_lock, mono_mini_arch_unlock, mini_arch_mutex. (mono/mono#15663)

Commit migrated from https://github.com/mono/mono/commit/6cd6f65f69b35aec860e23e3c2ffcecb29f79791

5 years ago[llvm] avoid FP elimination on iOS/armv7 (mono/mono#15617)
Bernhard Urban [Sun, 14 Jul 2019 20:15:56 +0000 (22:15 +0200)]
[llvm] avoid FP elimination on iOS/armv7 (mono/mono#15617)

[llvm] avoid FP elimination on iOS/armv7

Instead of
```
push    {r4, r5, r6, r7, r10, r11, lr}
```

LLVM will generate
```
push    {r4, r5, r6, r7, lr}
add     r7, sp, mono/mono#12
push    {r9, r10}
```

Seems like this https://github.com/mono/llvm/commit/mono/mono@a04e9e4a0af16f15ace258e81448b7eeca5ff599 assumes that `-disable-fp-elim` is passed for iOS targets. I wondered why this wouldn't break things for them, but when you run `clang` from Xcode with `-v`, you will discover that its driver passes `-mdisable-fp-elim`.

Together with https://github.com/mono/llvm/pull/48 this fixes crashes with FullAOT+LLVM on iOS 32bit.

Fixes https://github.com/mono/mono/issues/15058

Contributes to https://github.com/mono/mono/issues/9621

Commit migrated from https://github.com/mono/mono/commit/9a19bdb6e63590875e9ac80496720dd365611754

5 years agoAdd configure flag to disable GAC support; disable GAC in netcore (mono/mono#15681)
Aleksey Kliger (λgeek) [Sat, 13 Jul 2019 15:36:37 +0000 (11:36 -0400)]
Add configure flag to disable GAC support; disable GAC in netcore (mono/mono#15681)

* [runtime] Add configure flag to disable GAC support

* [netcore] Disable GAC support

Commit migrated from https://github.com/mono/mono/commit/70e9f8c5010cbe118f6043ac34e1e556a9e15d25

5 years agoMerge pull request mono/mono#10202 from Unity-Technologies/fix-dynamic-method-marshal...
Larry Ewing [Fri, 12 Jul 2019 23:22:01 +0000 (18:22 -0500)]
Merge pull request mono/mono#10202 from Unity-Technologies/fix-dynamic-method-marshal-info

Don't try to access metadata for dynamic method added to non-dynamic …

Commit migrated from https://github.com/mono/mono/commit/016a5253bb57c376c9b444387edf22d3facc6ed8