summaryrefslogtreecommitdiff
path: root/src/vm/dllimport.cpp
AgeCommit message (Collapse)AuthorFilesLines
2019-10-11[Tizen] Implement ASan wrapper for Linux ARM32Vyacheslav Cherkashin1-0/+11
This commit implements wrappers that allow interception transitions from managed to external unmanaged code (CIL -> native) and back (native -> CIL). This allows enable/disable ASan during transitions. Due to this, we sanitize only external code, which allows us to achieve acceptable performance. Change-Id: I53ecdc14d28f7210cd9e7f5bd4db0c8ef5ed81fc Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
2019-10-07Build error fix on FEATURE_PREJIT=trueSwift Kim1-1/+1
This fix is to update usages of SetupGcCoverage() under FEATURE_PREJIT aligned to the signature change in #25261.
2019-06-20Fix eventpipe filtering (#25221)Sung Yoon Whang1-1/+1
* Add DOTNET_TRACE_CONTEXT and change macros to use DOTNET_TRACE_CONTEXT instead of MCGEN_TRACE_CONTEXT * Fixing macro definitions * eventing codegen scripts now generates EventPipe trace contexts * Fix macros to use the EVENTPIPE_TRACE_Context * Fix linux build * Fix windows build * Update Eventpipe provider context at EtwCallbackComon * break in switch * Update rundown provider context manually * PR feedback * Eventpipe->EventPipe * cleanup in codegen script
2019-06-20Remove dead code related to copy-constructors and intercept stubs (#25264)Jeremy Koritzinsky1-32/+1
* Remove dead code related to copy-constructors and intercept stubs * PR Feedback.
2019-06-11Delete dead code (#25066)Jan Kotas1-39/+2
2019-06-11R2R ilstubs (#24823)David Wrighton1-17/+13
* Basic support for precompiled pinvoke stubs * Generate R2R file with multiple references to same IL stub (one per method which the IL stub is associated with) * Not all il stubs are p/invokes. Don't fail when they aren't. * Consistently use IsDynamicScope and GetModule to avoid unsafe memory access in IL stub compilation paths * Enable full p/invoke il stubs when compiling System.Private.Corelib * Disable IL Stub generation in crossgen for ARM32. - The cross bitness logic is not correct for IL Stub generation
2019-05-24Enable LCID marshalling and clean up our LCID marshalling tests. (#24642)Jeremy Koritzinsky1-8/+1
* Enable LCID marshalling and clean up our LCID marshalling tests. * Fix return type. * Enable LCID IDispatch reverse marshalling * Add more tests for LCID marshalling. * Add testing for reverse-IDispatch. Fix bug in Thread::GetCulture when culture has not been initialized on the managed side. * PR Feedback. * Fix install command.
2019-05-21Avoid PAL LoadLibrary simulator for regular PInvoke (#24669)Jan Kotas1-18/+5
Fixes #21009
2019-05-20Cuckoo metadata (#24498)David Wrighton1-7/+6
* Basic infra for cuckoo filter of attributes - Implement cuckoo filter lookup logic - Implement new ready to run section - Add dumper to R2RDump - Parse section on load into data structure - Implement function to query filter - Add concept of enum of well known attributes - So that attribute name hashes themselves may be cached * Wrap all even vaguely perf critical uses of attribute by name parsing with use of R2R data * Update emmintrin.h in the PAL header to contain the needed SSE2 intrinsics for the feature - Disable the presence table for non Corelib cases. Current performance data does not warrant the size increase in other generated binaries
2019-05-13Delete InternalCasingHelper (#24511)Jan Kotas1-5/+5
The unmanaged runtime has number of different paths for case-insensitive operations, each with unique issues. This is replacing InternalCasingHelper with SString to reduce number of different paths for case-insensitive operations that need to be maintained. Contributes to #20616
2019-05-08Remove more MDA support code (#24457)Steve MacLean1-205/+1
* Remove more MDA support code * PR Feedback
2019-04-26Typos (#24280)John Doe1-1/+1
* thier -> their * exeption -> exception * Estbalisher -> Establisher * neeed -> need * neeed -> need * neeeded -> needed * neeeded -> needed * facilitiate -> facilitate * extremly -> extremely * extry -> extra
2019-04-18Move R2R-specific code to be outside FEATURE_PREJIT (#24075)Jan Kotas1-0/+4
This refactoring is preparation for disabling fragile NGen support in the runtime. It keeps fragile-NGen specific code under FEATURE_PREJIT and moves the code required to support R2R to be outside FEATURE_PREJIT. The eventual goal is to compile the runtime without FEATURE_PREJIT defined to avoid fragile-NGen specific overhead.
2019-04-16Nit: Update comment (#23896)Next Turn1-1/+1
2019-04-15Opt COM methods out of the new Windows instance-method handling. (#23974)Jeremy Koritzinsky1-1/+4
* 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-5/+7
(#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-04-03Change Auto charset to mean UTF-8 off-Windows (#23664)Jeremy Koritzinsky1-4/+16
Match Mono's behavior by changing the Auto character set to mean UTF-8 on non-Windows platforms (new behavior) and UCS-2/UTF-16 on Windows (current behavior). Fixes #23464 Fixes dotnet/corefx#32442 Impact of breaking change: It is highly unlikely that anyone is actively using current behavior since it is inconsistent with Mono and doesn't match any native system APIs on non-Windows platforms (they're all UTF-8 based). We will need to update our documentation to reflect this updated behavior.
2019-04-01Enable R2R compilation/inlining of PInvoke stubs where no marshalling is ↵Fadi Hanna1-0/+8
required (#22560) * These changes enable the inlining of some PInvokes that do not require any marshalling. With inlined pinvokes, R2R performance should become slightly better, since we'll avoid jitting some of the pinvoke IL stubs that we jit today for S.P.CoreLib. Performance gains not yet measured. * Added JIT_PInvokeBegin/End helpers for all architectures. Linux stubs not yet implemented * Add INLINE_GETTHREAD for arm/arm64 * Set CORJIT_FLAG_USE_PINVOKE_HELPERS jit flag for ReadyToRun compilations * Updating R2RDump tool to handle pinvokes
2019-03-29Correctly marshal structure return values in member functions on Win-x64 and ↵Jeremy Koritzinsky1-80/+99
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-22Fix WinRT marshalling for NotifyPropertyChangedEventArgs and ↵Jeremy Koritzinsky1-2/+2
NotifyCollectionChangedEventArgs (CoreCLR side) (#23401) * Enable marshalling IntPtr and UIntPtr in WinRT scenarios to support our marshalling infrastructure. * Enable getting an RCW for a native COM object while ignoring WinRT projections. * Rename to Marshal.GetUniqueObjectForIUnknownWithoutUnboxing * Clean up contract. * Move GetUniqueObjectForIUnknownWithoutUnboxing to WindowsRuntimeMarshal. * Move WinRT-specific FCalls to WindowsRuntimeMarshal.
2019-03-19Implement support for copy constructors when marshalling in IJW (#22805)Jeremy Koritzinsky1-0/+1
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-03-07Fix signed compare warningsSinan Kaya1-3/+3
warning: comparison between signed and unsigned integer expressions [-Wsign-compare] conversions Update src/ToolBox/superpmi/mcs/verbdumptoc.cpp Co-Authored-By: franksinankaya <41809318+franksinankaya@users.noreply.github.com>
2019-01-23Remove all traces of FEATURE_STACK_PROBE. (#22149)Filip Navara1-1/+0
2019-01-18Add Per-assembly Load Native Library callbacks (#21555)Swaroop Sridhar1-57/+146
Add Per-assembly Load Native Library callbacks This Change implements the Native Library resolution Call-backs proposed in https://github.com/dotnet/corefx/issues/32015
2019-01-12Add NativeLibrary Resolve Event (#21929)Swaroop Sridhar1-26/+100
This change adds the Native library resolving event, to be raised as the last attempt to resolve a native DLL in an AssemblyLoadContext. With this change, the DllImport resolution sequence is as follows (stopping at any step with successful resolution): * If the invoking-assembly is not in the default load context, call AssemblyLoadContext.LoadUnmanagedDll() * Run the default load logic, try loading from: * AppDomain cache * NATIVE_DLL_SEARCH_DIRECTORIES * Invoking-assembly directory, System32, etc. based on DllImportSearchPaths * Raise the ResolvingUnmanagedDll event API Review: https://github.com/dotnet/corefx/issues/32850 The ResolveEventTests triggered a pre-existing bug in the exception handling code (#21964). Disabling the test on ARM64 Windows until the issue is fixed.
2019-01-11Enable returning more complex structures via PInvoke returns. (#21470)Jeremy Koritzinsky1-19/+26
* Add test verifying behavior in dotnet/coreclr#19676. * Clean up test code. * Test what happens if we enable returning structures by value. * Use braced initializer. * Update Decimal tests to expect that returning a decimal by LPStruct or Currency works. * Change handle-in-struct marshalling to expect a NotSupportedException thrown at marshal time instead of expecting a MarshalDirectiveException at signature time. * Update Decimal Reverse-PInvoke tests. * Disable some previously disabled return marshalling types and add a nice comment block explaining why they're disabled. * Enable marshalling DateTime return values and add a test. * Rename IsUnuspportedValueTypeReturn * Add return test for ArrayWithOffset * Remove extraneous P/Invoke. * Fix spelling. * Add test for successfully returning a struct that has one field of a type that is return-type blocked. * Add explicit struct return test. * Clean up tests. * Fix grammer. * Add test for struct whose managed layout doesn't require a stdcall return buffer but whose native layout does. * Add test verifying HandleRef behavior. * Clean up IsUnsupportedTypedefReturn per PR feedback.
2019-01-03Cleanup current culture handling in the unmanaged runtime (#21706)Jan Kotas1-21/+8
Large portion of the current culture handling in the unmanaged runtime inherited from desktop has been no-op. The nativeInitCultureAccessors QCall that it used to depend on desktop got (almost) never called in CoreCLR. - Delete resetting of current culture on threadpool threads. It was needed in desktop because of a very tricky flow of current culture between appdomains. It is superseded by the flowing the current culture via AsyncLocal in CoreCLR. - Comment out fetch of managed current culture for unmanaged resource lookup. It has number of problems that are not easy to fix. We are not localizing the unmanaged runtime currently anyway, so it is ok to just comment it out. - Fix the rest to call CultureInfo directly without going through Thread.CurrentThread
2018-11-22Sequel to NativeLibrary API (#21148)Swaroop Sridhar1-18/+20
Small changes to address furhter feedback: - Perform argument validation in the Marshall.cs instead of DllImport helpers - Improve doc comments.
2018-11-21Introduce Marshall.LoadLibrary API (#20871)Swaroop Sridhar1-42/+148
Implement Native LoadLibrary API This change commits the following changes: 1) Refactoring DllImport code to reuse LodLibrary by search for pInvoke and LoadLibrary cases 2) Implement the new Native Library API in System.Runtime.Interop.Marshall 3) Add tests for the new APIs
2018-11-12LoadLibrary refactoring (#20841)Swaroop Sridhar1-157/+170
* Refactor LoadLibrary Methods This change refactors the code in DllImport in preparation for implementing the new NativeLibrary API here: dotnet/corefx#32015 The two main changes are: 1) A change in the semantics of the internal LoadLibrary helper functions. When a native library is loaded, there are two categories of callers expecting different return values: External callers like AssemblyNative::InternalLoadUnmanagedDllFromPath() and the upcoming System.Runtime.Interop.Marshall.LoadLibrary() need the raw system handle Internal callers like LoadLibraryModule() need the PAL registered handle This change modifies the internal LoadLibraryModule* methods to work in terms of native system handles, so that external callers can obrain them directly. Methods requiring PAL-handles can register them explicitly. There is no change in external signature of DllImport class, or the native Dll cache in AppDomain class. 2) Differentiate HMODULE and NATIVE_LIBRARY_HANDLE This change defines NATIVE_LIBRARY_HANDLE type to represent raw system handles to native libraries that are not registered with the PAL (On Unix systems). The types on PAL and DlImport methods are adjusted to make this semantic distinction explicit. * Fix loading LibC via PAL_LoadLibraryDirect()
2018-11-10Keep delegate fields alive across a full native call (#20896)Jeremy Koritzinsky1-1/+1
* Repurpose CleanupWorkList to also preserve delegate references in structs across the full native call. * Change CleanupWorkListElement to abstract base class instead of interface. * Make CleanupWorkList a singlely linked list. * PR Feedback. * Remove CleanupWorkList and make CleanupWorkListElement be able to represent the full list. * Add back throw in SafeHandle field marshalling. * PR feedback.
2018-10-31Make the check for a struct fitting in a register check for either managed ↵Jeremy Koritzinsky1-1/+1
or native depending on the situation (i.e. managed call, reflection, P/Invoke) instead of only for managed. Fixes #20702. Clean up duplicate #ifdefs. Move #ifdef into method impl instead of outside the implementations. Move IsRegPassedStruct out of UNIX_AMD64_ABI #ifdef. Move check for enregistered struct out of UNIX_AMD64_ABI #ifdef Add dummy implementation of IsRegPassedStruct and IsNativeStructPassedInRegisters when UNIX_AMD64_ABI isn't defined.
2018-10-30Add support for large number of argumets in CCW call on Arm64 (#20670)David Wrighton1-0/+167
* Fix CCW with large numbers of arguments on arm64 - Correctly align the stack in COMToCLRDispatchHelper - Add tests for naturally 16 byte aligned stack growth, and non-aligned growth * New many arguments COM test * Add support for the IL stub ETW diagnostic event
2018-10-24Remove support for nonexistent ↵Jeremy Koritzinsky1-4/+0
UnmanagedFunctionPointerAttribute.PreserveSig. (#20396) UnmanagedFunctionPointer doesn't have a PreserveSig attribute on framework or core, so remove the unused, confusing, and inaccurate support from the runtime.
2018-08-28Enable mixed mode assembly loading (#19542)Morgan Brown1-0/+168
Bring back functionality for loading IJW assemblies and calling managed->native. Also add workaround to test case for the C++ compiler inserting calls to mscoree.
2018-07-23Remove hosthook api (#19079)Aaron Robinson1-54/+3
* Remove CallNeedsHostHook() API * Remove IsHostHookEnabled() API and with it related dead code * Remove code enabling host hooks (i.e. COMPlus_GenerateStubForHost) Remove function declarations for creating host hooks Update comments
2018-06-04Fix error during compilation with /permissive- (#18272)Andrey Kurdyumov1-1/+2
2018-06-01Native lib relative path (#18239)Aaron Robinson1-57/+63
* Typo in #define * Don't add prefix for relative path to native images if the path contains a platform path delimiter * Use already defined delimiter macro Create max variation count variable
2018-05-27Typo (#18141)John Doe1-1/+1
* Ajusted -> Adjusted * alot -> a lot * Ambigous -> Ambiguous * amoun -> amount * amoung -> among * Amperstand -> Ampersand * Anbody -> Anybody * anddoens't -> and doesn't * anme -> name * annoations -> annotations * annother -> another * anothr -> another * ansynchronous -> asynchronous * anticpation -> anticipation * anway -> anyway * aother -> another * Apparant -> Apparent * appartment -> apartment * appdmomain -> appdomain * Appdomian -> Appdomain * appdomin -> appdomain * approproiate -> appropriate * approprate -> appropriate * approp -> appropriate * appened -> appended * appropiately -> appropriately * appropraitely -> appropriately * Apperantly -> Apparently * approp. -> appropriate * Approriate -> Appropriate
2018-04-23GenericPInvokeCalli shift left then or 1 (#17734)Steve MacLean1-0/+5
When _WIN64 is defined vm relies on the secret arg being shifted left and orred with #1. Revert part of changes from #17659 to fix dotnet/corefx#29266 Fix arm64 to match amd64 Simplify dllimport.cpp
2018-04-19[Arm64/Linux] Fix GenericPInvokeCalliHelper (#17659)Steve MacLean1-25/+3
2018-04-16Enable support DllImport a native assembly whose name contains '.' (#17505)Luqun Lou1-23/+61
2018-02-28Replace ambiguous _WIN64 and BIT64 with _TARGET_64BIT_ macroEgor Chesakov1-5/+5
2018-01-29improve DllImport library name variation trying (#15912)Tom Deseyn1-87/+116
* dllimport: refactor libname variation code * Change order of libname variations depending on suffix presence * make MAX_LIBNAME_VARIATIONS static * PR feedback * Fix non PAL build
2018-01-25 Add GetLoadLibrary function for PAL & use in TrackErrorCode (#15831)William Godbe1-9/+36
* Add GetLoadLibrary function for PAL & use in TrackErrorCode * Finish changes to dllimport.cpp * Fix unix build errors * fix windows issues * Address feedback * Fix return type * Address feedback * Fix return type * Fix usage of LPCWSTR * Use shared library string * Append message strings * Fix append * Append newline * Fix spelling * Modify error messages * Resolve conflicts * Add mac message & stop appending all exceptions * Fix another error message * Fix NoName Error * Add newline to .h file
2017-08-07Cleanup code access security from the unmanaged runtime (#13241)Jan Kotas1-40/+0
2017-07-24Add the runtime code versioning featurenoahfalk1-2/+1
This makes tiered compilation work properly with profiler ReJIT, and positions the runtime to integrate other versioning related features together in the future. See the newly added code-versioning design-doc in this commit for more information. Breaking changes for profilers: See code-versioning-profiler-breaking-changes.md for more details.
2017-06-02Remove relocations from SECTION_MethodDesc for ngened images for fields ↵gbalykov1-0/+12
accessed from jit code for Linux ARM (#11963)
2017-05-30Remove relocations from SECTION_MethodDesc for ngened images (#11394)gbalykov1-2/+2
2017-05-17Finish deleting dead CAS code from CoreLib (#11436)Jan Kotas1-3/+0
Fixes #9321 and deletes CleanupToDoList.cs Delete unmanaged security implementation