-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[mono] Add QCalls to the Runtime #37670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
16bfd3a
First version of QCalls implementation, using QCalls on ICU Globaliza…
thaystg 56b4b44
Fixing windows compilation.
thaystg 8455282
Fixing warnings at compilation time.
thaystg a6b1f48
Fixing iOS compilation.
thaystg f79c2f1
Fixing iOS compilation.
thaystg 07e609a
Removing implementation of EventPipe using QCalls.
thaystg 26b85db
Fixing usused extern array.
thaystg d492c57
Adding QCALL to log
thaystg 1b4662b
Fixing getNativeHandle and organising files.
thaystg b749e18
Fixing compilation error.
thaystg 10101f8
Adding comments, fixing code style.
thaystg 569de74
Fixing Zoltan suggestion.
thaystg c942e24
Accepting @coffeeflux suggestion.
thaystg 12dca6e
Update src/mono/mono/metadata/native-library.h
thaystg 78e8edb
Update src/mono/mono/metadata/native-library.h
thaystg e1f488b
Update src/mono/mono/metadata/native-library.h
thaystg e1e0ed4
Update src/mono/mono/metadata/native-library.h
thaystg ff6be74
Update src/mono/mono/metadata/native-library.h
thaystg 13dc0d4
Update src/mono/mono/metadata/native-library-qcall.c
thaystg a203a97
Update src/mono/mono/metadata/native-library-qcall.c
thaystg 9d1992e
Update src/mono/mono/metadata/native-library-qcall.c
thaystg 96cf8b0
Update src/mono/mono/metadata/native-library-qcall.c
thaystg bdae239
Update src/mono/mono/metadata/native-library-qcall.c
thaystg 5da75d8
Update src/mono/mono/metadata/native-library-qcall.c
thaystg 040048f
Update src/mono/mono/metadata/native-library-qcall.c
thaystg 20c2177
Update src/mono/mono/metadata/native-library-qcall.c
thaystg 8be4f78
Update src/mono/mono/metadata/native-library-qcall.c
thaystg cc5c49e
Update src/mono/mono/metadata/native-library-qcall.c
thaystg 41d21ab
Update src/mono/mono/metadata/native-library-qcall.c
thaystg faeb893
Fix mono compilation.
thaystg 70ff810
Fix mono compilation.
thaystg a50b92c
Fix mono compilation.
thaystg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| #include "config.h" | ||
| #include "mono/metadata/assembly-internals.h" | ||
| #include "mono/metadata/class-internals.h" | ||
| #include "mono/metadata/icall-decl.h" | ||
| #include "mono/metadata/loader-internals.h" | ||
| #include "mono/metadata/loader.h" | ||
| #include "mono/metadata/object-internals.h" | ||
| #include "mono/metadata/reflection-internals.h" | ||
| #include "mono/utils/checked-build.h" | ||
| #include "mono/utils/mono-compiler.h" | ||
| #include "mono/utils/mono-logger-internals.h" | ||
| #include "mono/utils/mono-path.h" | ||
| #include "mono/metadata/native-library.h" | ||
|
|
||
| extern const void* gPalGlobalizationNative[]; | ||
|
|
||
| enum { | ||
| func_flag_end_of_array = 0x01, | ||
| func_flag_has_signature = 0x02, | ||
| func_flag_unreferenced = 0x04, // Suppress unused fcall check | ||
| func_flag_qcall = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke | ||
| }; | ||
|
|
||
| #if defined(NO_GLOBALIZATION_SHIM) || !defined(ENABLE_NETCORE) | ||
| const void* gPalGlobalizationNative[] = { (void*)func_flag_end_of_array }; | ||
| #endif | ||
|
|
||
| static const MonoQCallDef c_qcalls[] = | ||
| { | ||
| #define FCClassElement(name,namespace,funcs) {name, namespace, funcs}, | ||
| #include "mono/metadata/qcall-def.h" | ||
| #undef FCClassElement | ||
| }; | ||
|
|
||
| const int c_nECClasses = sizeof (c_qcalls) / sizeof (c_qcalls[0]); | ||
|
|
||
| static gboolean is_end_of_array (MonoQCallFunc *func) { return !!((int)func->flags & func_flag_end_of_array); } | ||
| static gboolean has_signature (MonoQCallFunc *func) { return !!((int)func->flags & func_flag_has_signature); } | ||
| static gboolean is_unreferenced (MonoQCallFunc *func) { return !!((int)func->flags & func_flag_unreferenced); } | ||
| static gboolean is_qcall (MonoQCallFunc *func) { return !!((int)func->flags & func_flag_qcall); } | ||
| //CorInfoIntrinsics IntrinsicID(ECFunc *func) { return (CorInfoIntrinsics)((INT8)(func->m_dwFlags >> 16)); } | ||
| //int DynamicID(ECFunc *func) { return (int) ((int8)(func->m_dwFlags >> 24)); } | ||
|
|
||
| static MonoQCallFunc * | ||
| next_in_array (MonoQCallFunc *func) | ||
| { | ||
| return (MonoQCallFunc *)((char *)func +sizeof (MonoQCallFunc)); | ||
| //(HasSignature(func) ? sizeof(ECFunc) : offsetof(ECFunc, func->m_pMethodSig))); | ||
| } | ||
|
|
||
| static int | ||
| find_impls_index_for_class (MonoMethod *method) | ||
| { | ||
| const char *namespace_name = m_class_get_name_space (method->klass); | ||
| const char *name = m_class_get_name (method->klass); | ||
|
|
||
| if (name == NULL) | ||
| return -1; | ||
|
|
||
| unsigned low = 0; | ||
| unsigned high = c_nECClasses; | ||
|
|
||
| #ifdef DEBUG | ||
| static bool checkedSort = FALSE; | ||
| if (!checkedSort) { | ||
| checkedSort = TRUE; | ||
| for (unsigned i = 1; i < high; i++) { | ||
| int cmp = strcmp (c_qcalls[i].class_name, c_qcalls[i-1].class_name); | ||
| if (cmp == 0) | ||
| cmp = strcmp (c_qcalls[i].namespace_name, c_qcalls[i-1].namespace_name); | ||
| g_assert (cmp > 0); | ||
| } | ||
| } | ||
| #endif // DEBUG | ||
| while (high > low) { | ||
| unsigned mid = (high + low) / 2; | ||
| int cmp = strcmp (name, c_qcalls[mid].class_name); | ||
| if (cmp == 0) | ||
| cmp = strcmp (namespace_name, c_qcalls[mid].namespace_name); | ||
|
|
||
| if (cmp == 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: don't need the brackets here. |
||
| return mid; | ||
| } | ||
| if (cmp > 0) | ||
| low = mid + 1; | ||
| else | ||
| high = mid; | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| static int | ||
| find_index_for_method (MonoMethod *method, const void **impls) | ||
| { | ||
| const char *method_name = method->name; | ||
| for (MonoQCallFunc *cur = (MonoQCallFunc *)impls; !is_end_of_array (cur); cur = next_in_array (cur)) | ||
| { | ||
| if (strcmp (cur->method_name, method_name) != 0) | ||
| continue; | ||
| return (int)((const void**)cur - impls); | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| gpointer | ||
| mono_lookup_pinvoke_qcall_internal (MonoMethod *method, MonoLookupPInvokeStatus *status_out) | ||
| { | ||
| int pos_class = find_impls_index_for_class (method); | ||
| if (pos_class < 0) { | ||
| mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_QCALL, | ||
| "Couldn't find class: '%s' in namespace '%s'.", m_class_get_name (method->klass), m_class_get_name_space (method->klass)); | ||
| return NULL; | ||
| } | ||
| int pos_method = find_index_for_method (method, c_qcalls[pos_class].functions); | ||
| if (pos_method < 0) { | ||
| mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_QCALL, | ||
| "Couldn't find method: '%s' in class '%s' in namespace '%s'.", method->name, m_class_get_name (method->klass), m_class_get_name_space (method->klass)); | ||
| return NULL; | ||
| } | ||
| return (gpointer)c_qcalls[pos_class].functions[pos_method+1]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #ifndef _MONO_METADATA_NATIVE_LIBRARY_H_ | ||
| #define _MONO_METADATA_NATIVE_LIBRARY_H_ | ||
|
|
||
| #include <glib.h> | ||
| #include <mono/metadata/appdomain.h> | ||
| #include <mono/metadata/image.h> | ||
| #include <mono/metadata/object-forward.h> | ||
| #include <mono/utils/mono-forward.h> | ||
| #include <mono/utils/mono-error.h> | ||
| #include <mono/utils/mono-coop-mutex.h> | ||
|
|
||
| typedef enum { | ||
| LOOKUP_PINVOKE_ERR_OK = 0, /* No error */ | ||
| LOOKUP_PINVOKE_ERR_NO_LIB, /* DllNotFoundException */ | ||
| LOOKUP_PINVOKE_ERR_NO_SYM, /* EntryPointNotFoundException */ | ||
| } MonoLookupPInvokeErr; | ||
|
|
||
| /* We should just use a MonoError, but mono_lookup_pinvoke_call has this legacy | ||
| * error reporting mechanism where it returns an exception class and a string | ||
| * message. So instead we return an error code and message, and for internal | ||
| * callers convert it to a MonoError. | ||
| * | ||
| * Don't expose this type to the runtime. It's just an implementation | ||
| * detail for backward compatability. | ||
| */ | ||
| typedef struct MonoLookupPInvokeStatus { | ||
| MonoLookupPInvokeErr err_code; | ||
| char *err_arg; | ||
| } MonoLookupPInvokeStatus; | ||
|
|
||
| gpointer | ||
| mono_lookup_pinvoke_qcall_internal (MonoMethod *method, MonoLookupPInvokeStatus *error); | ||
|
|
||
| typedef struct MonoQCallDef | ||
| { | ||
| const char *class_name; | ||
| const char *namespace_name; | ||
| const void **functions; | ||
| } MonoQCallDef; | ||
|
|
||
| typedef struct MonoQCallFunc { | ||
| intptr_t flags; //legal values (0x01 - end of array mareker, 0x08 - qcall) | ||
| void *implementation; | ||
| const char *method_name; | ||
| } MonoQCallFunc; | ||
|
|
||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.