* [interp] Remove unop conditional branch applied to constant
Convert it to unconditional branch
* [interp] Enable more optimization
If we failed to emit stloc.np we no longer track stack contents or try other optimizations
* [interp] Fix emit_store_value_as_local
mint_type for a native type is i4/i8 while we were loading the address of this local using LDLOC_VT. This was wrong. Passing a valuetype this is done with LDLOCA.
* [interp] Fix incorrect cond branch opcodes
We didn't emit correct conditional branch opcode, because we didn't check the new stack types, after the addition of the implicit conversion opcodes.
* [interp] Remove binop conditional branch applied to constant
Convert it to unconditional branch
Xamarin-Android will need this for the net6 migration, so might as well add it before I forget about it. They currently use `mono_image_open_from_data_with_name`. cc: @grendello
Co-authored-by: CoffeeFlux <[email protected]>
Recent debugger test runs were showing lot of
`CWL: Failed to lookup sequence point` messages.
These are being shown for cases like:
`CWL: list_frames: Failed to lookup sequence point. method: runtime_invoke_direct_void, native_offset: 56`
This is a warning, and doesn't need to be emitted by default.
Co-authored-by: radical <[email protected]>
* Only set basepath to the source directory if useSourcePath is set.
* Fixes a regression from mono 4 that happened when changing the code
to not use reflection.
Co-authored-by: MarkS <[email protected]>
* Look for "xmonkeysloveplay" also at the end of LC_SYMTAB section, for signed Mac OS X binaries
This extends Miguel de Icaza's previous work on allowing mono to load embedded
assemblies / shared libraries, which was in turn a workaround on recent
Mac OS X's increased security (and stopping LD_LIBRARY_PATH and friends from
working). Miguel de Icaza came up with the idea of appending all of those
embedded assemblies / shared libraries to the end of mono's main executable,
and getting it to look at its own file and unpacking resources from an offset
number + "xmonkeysloveplay" written to the end of file.
Even more recent Mac OS X starts to prefer /require binaries to be code-signed.
Code signing appends a "LC_CODE_SIGNATURE" section to the binary, thus breaking
mono's embedded resource-loading. Also code-signing requires that the binary
has no unknown parts.
To make mkbundle / mono embedded resource-loading work in a code-signing
situation, two parts are required:
- adjust mkbundle to extend the LC_SYMTAB section to cover the appended
assemblies / shared libraries, so code-signing can happen.
( addresses https://github.com/mono/mono/issues/17881 )
- adjust mono's main executable to also look at the end of the LC_SYMTAB
section for the magic offset + "xmonkeysloveplay" token to find the embedded
resources.
( addresses https://github.com/mono/mono/issues/18826 )
This change addresses the 2nd of the above. I also tried looking for the
presence and beginnig of the LC_CODE_SIGNATURE section, but that proves
unreliable: Code-signing can pad a few null bytes after "xmonkeysloveplay"
to align the LC_CODE_SIGNATURE section to an 8(?)-byte boundary.
* saving offset before read, so later lseek does not need to backtrack on the read
This is a small simplification of the previous commit on this part of code.
* fixes wrong drop-through from mis-positioning of #endif
* Update mono/mini/main.c
Adding spaces for clarity
Co-authored-by: Ryan Lucia <[email protected]>
* Update mono/mini/main.c
Adding spaces for clarity
Co-authored-by: Ryan Lucia <[email protected]>
* Update mono/mini/main.c
Adding spaces for clarity
Co-authored-by: Ryan Lucia <[email protected]>
* Update mono/mini/main.c
Adding spaces for clarity
Co-authored-by: Ryan Lucia <[email protected]>
* Update mono/mini/main.c
Added comment about what's going on.
Co-authored-by: Ryan Lucia <[email protected]>
* Adding comments for clarity
* rename variable "h" to "bin_header", for clarity
* Limit Apple code-signing work around to only the desktop OS (vs iDevices/TV)
* remove stylistic "else"; no change in functionality
Co-authored-by: Ryan Lucia <[email protected]>
We previously had a weird split between the domain and loader headers/files. This makes fewer things public, moves the useful ALC functions to loader-internals.h with the implementation in assembly-load-context.c, and cleans up the flow for some unloading behavior.
Co-authored-by: CoffeeFlux <[email protected]>
This PR:
* Enables `-Wc++-compat` on all platforms: we support building the runtime as C++, so this helps catch errors before they're found in CI and will help keep the netcore build C++-compatible
* Sets `-Werror` on netcore CI for OSX
It also fixes various warnings currently present in the build.
`-Werror` should probably be extended to cover all CI platforms eventually. Adding a new platform is as simple as adding to the line in mono.proj whitelisting platforms and fixing the warnings.
Not sure if there's a better way to handle the cpuidex function, but if we're using that from mini it should definitely be in a header somewhere.
Co-authored-by: CoffeeFlux <[email protected]>
* Catch attempts to create enum types with an underlying type that is itself an incomplete enum type.
Previously, only non-enum types containing fields with incomplete enum
types were forbidden.
* Permit static constant fields with incomplete types if the incomplete type is the type currently being defined
Co-authored-by: Alexis Christoforides <[email protected]>
* Avoid following invalid pointers in mono_w32process_get_modules on Darwin.
`_dyld_get_image_name` and `_dyld_get_image_header` can return pointers
to data that will be freed or unmapped by concurrent calls to `dlclose`.
Avoid this by using `_dyld_register_func_for_add_image` and
`_dyld_register_func_for_remove_image` to install callbacks that
maintain a runtime-internal set of loaded dynamic libraries.
Some notes:
- dyld doesn't provide a public "app store friendly" API (like
`dl_iterate_phdr`) to traverse a snapshot of all loaded dynamic
libraries in a process. There are two alternative private APIs that do
this: one uses `_dyld_process_info_create` and friends and is present in
macOS 10.12 and above, and the other depends on
`_dyld_get_all_image_infos`, which is documented by Apple (... in a WWDC
video) to "go away" at some point in dyld3.
- `dladdr` linearly scans the dyld loaded image array (and each image's
segment set) for a matching address, so `image_added` will get slower as
more dynamic libraries are loaded in the process. But dyld3's
implementation of dlopen already scales linearly in time with the number
of loaded libraries. The use of `dladdr` can be avoided by using
`_dyld_register_for_image_loads` or
`_dyld_register_for_bulk_image_loads`, but those are both private APIs.
- The callbacks registered with `_dyld_register_func_for_add_image` and
`_dyld_register_func_for_remove_image` can never be unregistered, so
this is yet another thing that makes it impossible to safely unload an
embedded mono.
- `MonoW32ProcessModule::inode` only seems to be used to avoid dupicates
in other implementations of w32process; sorting the returned module list
in `mono_w32process_get_modules` wouldn't be necessary if the
`mono_dyld_image_info`s were also kept in an intrusive circular doubly
linked list.
- It looks like `mono_w32process_get_modules` in `w32process-unix-bsd.c`
has a similar race condition.
Also see: https://github.com/mono/mono/issues/20107
* Formatting.
* Make `image_added` and `image_removed` non-blocking.
It is theoretically possible for `mono_w32process_get_modules` to cause
a deadlock if either `image_added` or `image_removed` is waiting for the
image table mutex to be released and if `g_new0`, `g_strdup`,
`g_hash_table_iter_next`, or any of the symbols they depend on are
lazily bound and haven't already been resolved.
Only one thread may iterate over the image table and only one thread may
add/remove entries to/from the image table.
The writer thread attemps to lock a mutex to block readers from
iterating over the table. If the writer successfully acquires this lock,
then no readers are concurrently iterating over the image table and it
is safe to eagerly free stale data.
If the writer doesn't successfully acquire this lock, then the reader
thread is running concurrently with the writer; if this happens, the
writer pushes stale data into a limbo list. Readers opportunistically
clear this list.
Use `mono_mutex_t` instead of `MonoCoopMutex`. Hand-roll the necessary
GC state transitions inside `mono_w32process_get_modules`.
Add `mono_conc_hashtable_foreach_snapshot` to mono-conc-hashtable.{h,c}.
`MonoConcurrentHashTable` depends on the hazard pointer table
(`hazard_table` inside hazard-pointer.c), which is initialized lazily on
the first call to `mono_thread_small_id_alloc`. Perhaps this should be
explicitly initialized early during `mono_init_internal`.
* Revert "Make `image_added` and `image_removed` non-blocking."
This reverts commit a22a4440df5f0f13da29b1b90e80a3420223c2b9.
* Use mono_mutex_t instead of MonoCoopMutex
* Explicitly load symbols not used by `image_added` before `mono_w32process_get_modules` runs
When this experiment is enabled, the GC doesn't scan stack or registers. This mode is meant to disable scanning of native frames. This implementation only makes sense in full interpreter mode, where the interp stack is scanned separately from the thread stack. Longer term we could use this mode to scan only the managed stack, also in jit mode.
The point of this mode is to be able to stress test the GC in a wasm like environment, where stack can't be scanned. We can more easily reproduce and investigate GC crashes in this configuration, that would also happen on wasm.
Co-authored-by: BrzVlad <[email protected]>
This mostly completes support for the attribute. Our algorithm differs a bit from CoreCLR right now, so we don't support the legacy behavior flag since it makes less since in the context of our algorithm, but this should be good enough for most cases.
Co-authored-by: CoffeeFlux <[email protected]>
Similar logging was added to the managed loading algorithm when it proved extremely useful for debugging a Blazor crash, so the equivalent is probably useful for the unmanaged library algorithm as well
Co-authored-by: CoffeeFlux <[email protected]>
The important change here is not leaking the coop handles, the other is because I'm too lazy to create two separate PRs for this.
Co-authored-by: CoffeeFlux <[email protected]>
Fix https://github.com/mono/mono/pull/19494 adds missing array ctor needed by several tests currently failing as described by https://github.com/dotnet/runtime/issues/34068.
This PR fixes an additional problem hit by the IL array tests using an lbound != 0. Current Mono codegen for Set/Get/Address array methods didn't adjust index with regards to lbound causing failures in several of the array tests. NOTE, this scenario should only be hit when directly calling Set/Get/Address using IL on an array with an lbound != 0. It shouldn't affect regular szarray's at all since that code paths should never be used and the codegen currently looks up the lbounds unconditionally in the array, so if that code path ever gets hit by a szarray, it will imdediate crash, so shouldn't be causing any performance impact on szarrays. There is also an additional check on the array type as well as an additional precaution, so only arrays of type MONO_TYPE_ARRAY, hitting codegen for Set/Get/Address array method calls will adjust index based on lbound.
This PR fix the lbound index codegen for that specific code path and re-eanbles the tests currently listed in https://github.com/dotnet/runtime/issues/34068.
Co-authored-by: lateralusX <[email protected]>
Make EventSource call static version of EventActivityIdControl in EventPipeEventProvider instead of direct calling low level
EventPipeInternal (now only called from EventPipe* sources). Doing it that way will also keep EventPipeEventProvider.EventActivityIdControl in S.P.C meaning that tests like eventactivityidcontrol won't risk
of using methods that has been trimmed away by linker.
Added missing case into Mono's EventPipeInternal::EventActivityIdControl implementations.
Enabled eventactivityidcontrol test on Mono runtime. Adjusted test to use static EventPipeEventProvider.EventActivityIdControl version.
Co-authored-by: lateralusX <[email protected]>