summaryrefslogtreecommitdiff
path: root/src/vm/ilmarshalers.h
AgeCommit message (Collapse)AuthorFilesLines
2019-05-23Fewer ilstubs in corelib from reflection apis (#24708)David Wrighton1-21/+0
Rework use of marshalling for RuntimeTypeHandle, RuntimeModule, RuntimeAssembly, and IRuntimeMethodInfo as used by QCalls - Remove special QCall only used marshallers for RuntimeAssembly, RuntimeModule and IRuntimeMethodInfo - Following the pattern of ObjectHandleOnStack, implement QCall handle types for RuntimeAssembly/Module/TypeHandle. Use these in all QCalls that once passed the types directly. - For uses of IRuntimeMethodInfo, follow the existing RuntimeMethodHandleInternal pattern Also perform some replacement of bool marshalling with use of Interop.BOOL, and a few cases of using pointers instead of byref arguments. Fix delivers a relatively small win on startup, and small throughput gains around reflection as IL stubs are no longer necessary for many functions in reflection that once needed them. Reduces methods jitted on powershell startup from 422 to 399, (About 5%) but performance win is only about 5ms on ~400ms as the methods removed are simple.
2019-04-15Opt COM methods out of the new Windows instance-method handling. (#23974)Jeremy Koritzinsky1-3/+1
* Opt COM methods out of the new Windows instance-method handling. * Add test for an HResult "struct" returned from a COM method. * Update ErrorMarshalTesting.cs * Update "is member function" check on the ilmarshalers.h side to only consider thiscall.
2019-04-05Enable return buffers on Windows ARM64 for struct-returning member functions ↵Jeremy Koritzinsky1-10/+15
(#23625) * Enable return buffers on Windows ARM64 for struct-returning member functions. Fixes #23577. * Update comment to match new condition. * Enable byref return on all Windows (excluding arm64 HFA. Add more test cases for ThisCall. * On x86, if we have a normalized return value in an instance method, get back the actual type so that we correctly marshal it via a return buffer. * Fix param ordering. * Clean up based on PR feedback. * Fix accidental variable shadowing.
2019-03-29Correctly marshal structure return values in member functions on Win-x64 and ↵Jeremy Koritzinsky1-12/+42
Win-x86 (#23145) * In Windows-x64, if we have a native member function signature with a struct return type, we need to do a by-ref return. * Implement support for marshalling structure return values via a return buffer argument correctly in instance signatures on AMD64-Windows. * Change field initialization ordering to satisfy warning. * Try to narrow down the conditions that trigger these changes to just COM methods. * Don't bash the return type on AMD64 Windows. Only treat it as a byref return buffer. * PR feedback. * Enable returning structs from COM methods via a return buffer on x86 for structs <= 8 bytes. * Add test for struct returns with ThisCall. Extend the "struct return buffer" fix to functions marked as unmanaged thiscall since they all must be instance methods * Don't include the return-type-bashing switch on AMD64 platforms. * Don't do the signature swapping/copy on non-instance functions with struct returns. * Cast the return type of GetStubTargetCallingConv to the right calling convention enum type. * If we're doing a thiscall, marshal the "this" parameter before the return buffer (if the return buffer exists) on all platforms. * Remove temporary logging code I added in for debugging. * Clean up class naming. * Try using a vtable instead of a pointer-to-member-function. * Remove delete of class with non-virtual destructor
2019-03-19Implement support for copy constructors when marshalling in IJW (#22805)Jeremy Koritzinsky1-0/+32
Fixes #22219. I decided to try simplifying the code when bringing this feature over from .NET Framework. The .NETFX x86 implementation of this marshaler adds a lot of extra code-paths, and intercepts the calling stub to enable it to exactly replicate the behavior of what would be the native code by copy-constructing an object in-place where it goes on the stack for the native call. Instead of adding all of that extra goo, I decided to keep the implementation much more similar to the non-x86 implementation from .NETFX. Instead of intercepting the call and adding bookkeeping helper stubs, the marshaler just copies to a local in the IL stub, just like non-x86. When calling the native function, it just loads the local onto the IL stack and calls the native function as a normal function. There is a difference there, but I cannot think of a way that the difference is observable to the user. The non-x86 implementation is identical to the .NETFX implementation.
2019-02-13Replace Win32Native.cs with Interop files (#22540)Stephen Toub1-6/+6
* Replace Win32Native.cs with Interop files - Replace Win32Native usage with existing Interop.* calls where they already existed - Moved Win32Native.* to their own files otherwise, and changed call sites - Left a stub Win32Native in place to handle some emitted IL from the runtime. The current infrastructure doesn't support targeting nested types, like Interop.Kernel32, and fixing that would be more involved. * Remove Win32Native.cs Replace emitted calls with ones to Marshal. * Fix incorrectly changed field * Fix Kernel32 -> Ole32
2019-02-06Throw an exception when passing strings by-value as out parameters. (#21513)Jeremy Koritzinsky1-2/+13
* Throw an exception when passing strings by-value as out parameters. * Fix encoding * Don't use override in this PR. * Clean up Marshal_In Marshal_In was copied back into existence from Marshal_InOut. Clean it up a bit. * Remove extraneous whitespace. * Fix failing test. * Remove out attribute in COM string tests. * Add back attribute and check for exception thow in COM tests. * Add block comment to explain the implementation of Reverse_LPWStr_OutAttr in the NETServer. * Only throw in a CLR->Native marshalling situation. * Fix asserts from changed code-paths used in ILWSTRMarshaler. * Add comment and explicitly load in a null value (instead of leaving it uninitialized). * Apply suggestions from code review Co-Authored-By: jkoritzinsky <jkoritzinsky@gmail.com> Co-authored-by: Jan Vorlicek <janvorli@microsoft.com>
2019-01-14Custom Marshalers in custom-ALC-loaded assemblies results in types loaded ↵Jeremy Koritzinsky1-6/+6
from crossing ALCs (#21606) * Create repro for dotnet/coreclr#19654 * Update ICustomMarshaler.csproj * Update ICustomMarshaler.csproj * Clean up repro per feedback. * Add test case for different assemblies with the same CustomMarshaler name. * Move EEMarshalingData cache from AppDomain to LoaderAllocator. This fixes the custom-marshaler conflict when using unloadable assembly contexts. * Internalize the LoaderHeap* parameter. * Add the pointer to the requesting assembly to the hashtable key. * Fix linux-musl build break. * Move Crst out of FEATURE_COMINTEROP block. * Make sure to copy over the assembly pointer to the key that's actually stored in the hash table. * Add comment for m_invokingAssembly. * Move all usages of EEMarshallingData to hang off the correct loader allocator instead of always the global one. * Change to m_InteropDataCrst since this EEMarshallingData can be used in preemptive GC mode. * Always init m_InteropDataCrst (since it's used by EEMarshallingData as well as COM). * PR Feedback. * Remove extraneous inlines.
2019-01-08Extract cleanup changes from #21793. (#21852)Jeremy Koritzinsky1-1/+0
* Cleanup changes from #21793. * Emit the data pointer offset directly into the IL stream (and calculate it as needed instead of passing it through) * Fix broken assumption that OverrideProcArgs::na::m_pMT is the array type instead of the element type (which it was).
2018-11-15Add tests for ANSI BSTRs (#20985)Jeremy Koritzinsky1-2/+0
* Add tests for ANSI BSTRs * Fix signed/unsigned mismatch in comparisons. Add xplatform include * Use regular memcpy * Enable ANSI BSTR off-windows. * Also enable UnmanagedType.TBStr off-Windows since both BStr variants are available off-Windows. * Make sure the AnsiBSTR marshaller is hooked up off-Windows. * Remove a few more ifdefs I missed. * remove ifdefs around binder definitions and the C# stub helpers. * PR Feedback. * Add xplat ARRAYSIZE macro * Move xplat ARRAYSIZE to platformdefines.h
2018-09-28Enable BSTR Marshaling Support for x-plat PInvoke (#19766)Luqun Lou1-2/+1
2017-03-15[x86/Linux] Fix IL_STUB_PInvoke with RetBuf (#10144)Hanjoung Lee1-0/+3
* [x86/Linux] Fix IL_STUB_PInvoke with RetBuf Fix calling convention and IL_STUB_PInvoke for native functions which was problematic for native functions that has a RetBuf argument(struct size <= 8) on x86/Linux. Fix #10027
2017-02-10Remove always defined FEATURE_CORECLRdanmosemsft1-37/+1
2016-07-01Revert Pinvoke ILStub calli signature for desktop clrRahul Kumar1-1/+7
2016-06-28Fix Pinvoke IL Stubs to emit correct return type in signature of calli ↵Rahul Kumar1-1/+1
instruction
2016-05-24[ARM/Linux] Fix incorrect return marshaling in PInvoke stub (#5010)Jonghyun Park1-1/+1
* Revises compMethodReturnsMultiRegRetType for ARM For ARM, the current implementation of 'compMethodReturnsMultiRegRetType' always returns false. Unfortunately, this behavior is inconsistent with JIT importer. JIT impoter attempts to merge various return statements as one statement via inserting an assignment statement just before each return statement if there are more than 4 returns. If the method of interest has a return value, then JIT importer introduces a local temporary variable, and use it to return value. Due to the above implementation, JIT importer never generates a return variable, which results in assertion violation insider JIT morph, which is discussed in #5009. This commit attempts to fix #5009 via implementing 'compMethodReturnsMultiRegRetType' for ARM. * Uses compRetNativeType instead of compRetType * Fix typo '_TARGET_ARM' as '_TARGET_ARM_'
2016-05-06UTF8 Marshaling support(UnmanagedType.LPUTF8Str)Tijoy Tom Kalathiparambil1-0/+60
Usage: [MarshalAs(UnmanagedType.LPUTF8Str)] applied to string and stringbuilder. Implementation mostly use Encoding.UTF8 API to do the byte buffer to string roundtripping. Introducing two new marshalers, UTF8StringMarshaler and UTF8BufferMarshaler which handle string and StringBuilder respectively. [Out] StringBuilder marshaling use builder capacity as the buffer size ie (builder. Capacity + 1) *3 which is enough for any UTF8 char in BMP plane, infact Encoding.UTF8 mscorlib APIs use the same length.All marshaling flags(ThrowOnUnmapable, defaultchar) are ignored since they do not make sense in UTF16 to UTD8 context. The public contracts are not yet updated, the public contracts and public marshaling API (Marshal.PtrToStringUtf8 and StringToHGlobalUtf8) will be added once the implementation is in. The marshal api are anyway going to be a wrapper around Encoding.GetBytes and GetChars.
2016-01-27Update license headersdotnet-bot1-4/+3
2015-10-20Implementation of System V ABI struct passing.Lubomir Litchev1-1/+1
This PR adds support for System V x86_64 ABI classification and calling convention to the VM and the Jit, including, but not limited to Ubuntu Linux and Mac OS X. The general rules outlined in the System V x86_64 ABI (described at http://www.x86-64.org/documentation/abi.pdf) are followed with a few little exceptions, described below: 1. The hidden argument for by-value passed structs is always after the ÎéÎíthisÎéÎí parameter (if there is one.). This is a difference with the Sysetem V ABI and affects only the internal jit calling conventions. For PInvoke calls the hidden argument is always the first parameter since there is no ÎéÎíthisÎéÎí parameter in this case. 2. Managed structs that have no fields are always passed by-value on the stack. 3. The jit proactively generates frame register frames (with RBP as a frame register) in order to aid the native OS tooling for stack unwinding and the like.
2015-08-25Replace MAX_PATH with new defines in vm.Lakshmi Priya Sekar1-5/+5
2015-07-10Add missing contracts to some constructorsJan Vorlicek1-0/+6
After adding virtual destructors to some classes, the contract scanning tool started to complain about missing contracts in some of the constructors that were not touched. This change adds contracts to those.
2015-07-08Add missing contracts to some destructorsJan Vorlicek1-1/+4
This change adds missing contract annotation to several destructors that were missing it.
2015-05-26Fix the virtual destructor warningJan Vorlicek1-0/+2
This change changes destructors to be virtual or adds virtual ones where they were missing based on the clang warnings.
2015-01-30Initial commit to populate CoreCLR repo dotnet-bot1-0/+3367
[tfs-changeset: 1407945]