This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement struct marshalling via IL Stubs instead of via Field… (#26340)
* First pass on adding support for byref field homes to il marshalers. Remove dead code for calculating managed field size. Add field IL marshal infra up to MarshalInfo::GenerateFieldIL. Add preliminary changes for MarshalInfo ctor to have the logic handle field marshalling logic. Still need to handle WinRT struct field logic correctly. First shot at handling fields of WinRT structs. Cleanup Clean up entrypoints Fix cleanup marshal emit. Disable specific paths on struct marshal stubs. Implement emitting full struct marshalling stub. Add StructMarshalInteropStub method name. Add NDirect::CreateMarshalILStub Get byvalue StructMarshalling/PInvoke tests passing excluding missing ILMarshalers (ByValArray and ByValTStr). Correctly classify struct marshal stubs as struct marshal stubs instead of PInvoke stubs. Implement UnmanagedType.ByValArray IL marshaler. Implement ILMarshaler equivalent for ansi-char fixed arrays. Fix parameter mismatch in Native->CLR direction for struct marshalling. Implement ByValTStr marshalling. Support unaligned fields in IL stubs. Load CleanupWorkList from param list if in a struct marshalling stub Implement SafeHandle and CriticalHandle field marshalling in IL struct stubs Fix handle field marshalers. Add error reporting in struct field IL marshalers consistent with old FieldMarshaler error reporting. Convert Array-of-nonblittable-struct marshalling to use IL stubs. Convert LayoutClass marshalling to use IL stubs. Fix marshalling of LayoutClass fields in structs. Add non-blittable fixed buffer assert in the struct IL stub path. Implement Marshal APIs via the IL stubs. Fix default char marshaler selection. Move hidden-length-array marshalling over to struct marshalling stubs. Convert struct marshal IL stub users to use helper that will automatically cleanup on failure to marshal. Match MarshalInfo::MarshalInfo behavior to ParseNativeType for fields. Remove old FieldMarshaler-based marshalling. Fix signed/unsigned mismatch. Fix IsFieldScenario on non-COMINTEROP plaforms Fix off-Windows build. Handle automatic partial cleanup of struct marshaling entirely within the struct stub. Remove now-unused ValueClassMarshaler. Move DateMarshaler to managed since it doesn't need to be an FCall. Error out on recursive struct definitions in the IL stub generation as we did in the field marshalling. Remove FieldMarshalers and replace with a significantly simpler structure (NativeFieldDescriptor) that stores only the needed info for determining validity in WinRT, blittability, and calling convention classification. This will save 4/8 bytes for every field in a non-auto-layout structure or class loaded into the runtime. Add explicit test for recursive native layout. Allow marshalling as UnmanagedType.Error on all platforms (on non-Windows the behavior matches UnmanagedType.I4). Collapse common primitive marshalling cases together. Disable WinRT parameter/retval-only marshalers in field scenarios. Revert "Collapse common primitive marshalling cases together." This reverts commit e73b78a. Fix error marshalling off Windows for uint. Disable LPStruct marshalling in structs. Disable copy-constructor marshaler in the field scenario. Match error messages between MarshalInfo::MarshalInfo and ParseNativeType in the field scenario. Refactor managed-sequential check out of ParseNativeType. Remove invalid MARSHAL_TYPE_GENERIC_U8 references. Add override specifier. Change ParseNativeType to use MarshalInfo::MarshalInfo to calculate field marshalling info instead of maintaining two native field classification functions. Clean up native field categories. Remove nsenums.h since it is now unused. Move CheckIfDisqualifiedFromManagedSequential to class.cpp. Encapsulate stub flags for struct stubs. Read the BestFitAttribute once for the type instead of per field. Fix perf regression in by-val arrays of non-blittable structures by caching the MethodDesc* to the struct stub in the "managed marshaler" structure. Now we have a perf improvement! Fix memory leak in sig creation. Keep compile-time information for struct stubs around as long as the owning loader allocator (instead of leaking). Allocate the signature on the same heap as the IL stubs so it shares the same lifetime. Fix build with fragile NGen support enabled so as to not break partners. Add missing native field descriptors. Fix clang build. Only assert if we're emitting IL (so we don't assert during type-load). Determine desciptor for pointer-sized fields based on target not host pointer size. Don't emit IL stubs that call struct stubs into R2R images since there's not a good way for us to emit the token. Fix tracing test failures. Force field marshaling to not stackalloc. Cache Sytem.RuntimeMethodInfoStub instances created in the VM in the MethodDesc's owning LoaderAllocator. Struct marshal stubs don't have an MethodDesc context arg. Copy FieldDesc on NFD assignment. Fix initialization of stubMethodInfoCache lock owner. Fix alignment calculation of decimal fields and decimal array fields in NFDs. Fix Crst leveling. Enable handling decimal-as-currency fields accurately off-Windows. Fix deadlock where two threads are both trying to generate an IL stub for the same P/Invoke and one of the parameters needs a struct stub generated. Fix incorrect check for if we need a struct marshal stub in some of the variant/array cases. We never need to promote a field value to 8 bytes. Fix issue with recursive pointer fields. Shortcut blittable types in stubhelpers. Use LDFTN + PREPARE_NONVIRUTAL_CALLSITE_USING_CODE instead of LDTOKEN + GetInternalToken. Revert "Fix Crst leveling." This reverts commit 1d8e56e. Revert "Fix initialization of stubMethodInfoCache lock owner." This reverts commit a095390. Revert "Cache Sytem.RuntimeMethodInfoStub instances created in the VM in the MethodDesc's owning LoaderAllocator." This reverts commit 7266538. Fix case where struct marshal stub is unused in native-only mashalling paths. PR Feedback. Clean up terenary statement in dispatchinfo.cpp Cleanup ILStubResolver::AllocGeneratedIL a little bit. * Cleanup LayoutClass test. * Encapsulate getting the entrypoint of a struct marshal stub. * VTHACK_NONBLITTABLERECORD is only used for hidden-length array marshalling, and VT_RECORD is not used in hidden-length array marshalling. * Align new entries in mtypes.h * Whitespace and field ordering changes.
- Loading branch information