forked from dotnet/coreclr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
60557a9
commit e47524b
Showing
13 changed files
with
243 additions
and
90 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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
13 changes: 13 additions & 0 deletions
13
tests/src/Interop/NativeLibraryResolveCallBack/CMakeLists.txt
This file contains 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,13 @@ | ||
cmake_minimum_required (VERSION 2.6) | ||
project (ResolveLib) | ||
include_directories(${INC_PLATFORM_DIR}) | ||
set(SOURCES ResolveLib.cpp) | ||
|
||
# add the executable | ||
add_library (ResolveLib SHARED ${SOURCES}) | ||
target_link_libraries(ResolveLib ${LINK_LIBRARIES_ADDITIONAL}) | ||
|
||
# add the install targets | ||
install (TARGETS ResolveLib DESTINATION bin) | ||
|
||
|
87 changes: 87 additions & 0 deletions
87
tests/src/Interop/NativeLibraryResolveCallBack/CallBackTests.cs
This file contains 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,87 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using TestLibrary; | ||
|
||
using Console = Internal.Console; | ||
|
||
public class CallBackTests | ||
{ | ||
public static int Main() | ||
{ | ||
try | ||
{ | ||
Assembly assembly = Assembly.GetExecutingAssembly(); | ||
string testBinDir = Path.GetDirectoryName(assembly.Location); | ||
|
||
DllImportResolver resolver = | ||
(string libraryName, Assembly asm, DllImportSearchPath? dllImportSearchPath) => | ||
NativeLibrary.Load("ResolveLib", asm, dllImportSearchPath); | ||
|
||
DllImportResolver anotherResolver = | ||
(string libraryName, Assembly asm, DllImportSearchPath? dllImportSearchPath) => | ||
IntPtr.Zero; | ||
|
||
Console.WriteLine("0 OK"); | ||
try | ||
{ | ||
NativeLibrary.SetDllImportResolver(null, resolver); | ||
|
||
Console.WriteLine("Expected exception not thrown"); | ||
return 101; | ||
} | ||
catch (ArgumentNullException e){} | ||
Console.WriteLine("1 OK"); | ||
|
||
try | ||
{ | ||
NativeLibrary.SetDllImportResolver(assembly, null); | ||
|
||
Console.WriteLine("Expected exception not thrown"); | ||
return 102; | ||
} | ||
catch (ArgumentNullException e){} | ||
Console.WriteLine("2 OK"); | ||
|
||
// Set a resolver callback | ||
NativeLibrary.SetDllImportResolver(assembly, resolver); | ||
|
||
Console.WriteLine("3 OK"); | ||
|
||
try | ||
{ | ||
// Try to set another resolver on the same assembly. | ||
NativeLibrary.SetDllImportResolver(assembly, anotherResolver); | ||
|
||
Console.WriteLine("Expected Exception not thrown"); | ||
return 103; | ||
} | ||
catch (InvalidOperationException e) | ||
{ | ||
Console.WriteLine($"Exception: {e.Message}"); | ||
} | ||
Console.WriteLine("4 OK"); | ||
|
||
if (NativeSum(10, 10) != 20) | ||
{ | ||
Console.WriteLine("Unexpected ReturnValue from NativeSum()"); | ||
return 104; | ||
} | ||
Console.WriteLine("5 OK"); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine($"Unexpected exception: {e.ToString()} {e.Message}"); | ||
return 105; | ||
} | ||
|
||
return 100; | ||
} | ||
|
||
[DllImport("NativeLib")] | ||
static extern int NativeSum(int arg1, int arg2); | ||
} |
Oops, something went wrong.