Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Expose NativeLibrary APIs #34567

Merged
merged 1 commit into from
Jan 17, 2019
Merged

Expose NativeLibrary APIs #34567

merged 1 commit into from
Jan 17, 2019

Conversation

swaroop-sridhar
Copy link
Contributor

Expose the System.Runtime.Interop.NativeLibrary APIs implemented in CoreCLR.

API review: #32015
CoreCLR Change: dotnet/coreclr#21821

public static bool TryLoad(string libraryPath, out System.IntPtr handle) { throw null; }
public static bool TryLoad(string libraryName, System.Reflection.Assembly assembly, DllImportSearchPath? searchPath, out System.IntPtr handle) { throw null; }
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there tests to go along with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Mono reuse CoreCLR tests, like they do CoreFX tests? @marek-safar

Copy link
Member

@jkotas jkotas Jan 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Mono reuse CoreCLR tests

Yes, Mono runs snapshot of CoreCLR tests. BTW: mono/mono#9640 tracks updating that snapshot

In general, a large part of interop test coverage is in CoreCLR. CoreFX does not have the specific infrastructure required to build and run interop tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are few places in CoreFX, where these APIs could be used:
https://github.com/dotnet/corefx/search?l=csharp&q=dlopen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, it'd be good to use System.Drawing as validation for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it is a good idea to use the new API in CoreFX libraries. However,

  1. I don't think it is a good idea to make product changes to libraries in this checkin.
  2. There is currently no way to pass RTDL_NOW to NativeLibrary.Load() methods.
    This should be investigated along with this issue.

If there are specific cases in CoreFx libraries that are not tested by NativeLibraryTests, I'm happy to extract them and add as test cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is a good idea to make product changes to libraries in this checkin

Right, we should have a follow up issue for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Runtime.InteropServices.cs" />
<Compile Condition="'$(TargetsNetCoreApp)' == 'true'" Include="System.Runtime.InteropServices.netcoreapp.cs" />
Copy link
Member

@jkotas jkotas Jan 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we have been keeping the API set the same between netcoreapp and uap. When the API was not implemented for ProjectN yet, we added it to the API compat baseline to be looked at later.

Copy link
Contributor Author

@swaroop-sridhar swaroop-sridhar Jan 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas: Originally, in #34322, we exposed the API universally and updated the baseline.
But @ericstj recommended that we only expose the API for netcoreapp, because it is unlikely that the API will be implemented for UWP.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see a fundamental problem with implementing these APIs for UWP. They will be limited to what UWP allows you do, but that's ok. And we can always implement them by throwing PNSE if there is no better option.

Also, I think it is unlikely we would keep UWP as a separate targeting pack in the next major turn of the crank of that platform. I expect that we would just merge it with netcoreapp once that happens.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see a fundamental problem with implementing these APIs for UWP. They will be limited to what UWP allows you do, but that's ok

It's my understanding that all of these are wrappers over LoadLibrary which is unavailable in UWP due to WACK.
Though I just had a look at https://docs.microsoft.com/en-us/uwp/win32-and-com/win32-apis and noticed LoadPackagedLibrary is available (as well as GetProcAddress and FreeLibrary). I suppose I could imagine this being implemented on top of that for UWP.

it is unlikely we would keep UWP as a separate targeting pack in the next major turn of the crank

That's news to me. Don't get me wrong I'd love to see it happen but I'm unaware of such POR. I don't see it happening from a consumption side of things due to existing library ecosystem so as long as it remains a separate TFM we can provide a separate reference for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no POR for next major turn of the crank for UWP today. I am just making a guess about what the POR is likely going to be once there is one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noticed LoadPackagedLibrary is available (as well as GetProcAddress and FreeLibrary

Right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That actually makes this API specifically interesting for UWP where we haven't permitted dynamic load in the past. If we can provide a way to do it safely then I think this actually adds value there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation @ericstj. I'll change the contract to be visible everywhere, with implementation exceptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sorry for the original poor advice. That was my misunderstanding.

Expose the System.Runtime.Interop.NativeLibrary APIs implemented in CoreCLR.

API review: #32015
CoreCLR Change: dotnet/coreclr#21821

Tests for the API are here:
https://github.com/dotnet/coreclr/blob/master/tests/src/Interop/NativeLibrary/NativeLibraryTests.cs
@jkotas jkotas merged commit 5241ad4 into dotnet:master Jan 17, 2019
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Expose the System.Runtime.Interop.NativeLibrary APIs implemented in CoreCLR.

API review: dotnet/corefx#32015
CoreCLR Change: dotnet/coreclr#21821

Tests for the API are here:
https://github.com/dotnet/coreclr/blob/master/tests/src/Interop/NativeLibrary/NativeLibraryTests.cs

Commit migrated from dotnet/corefx@5241ad4
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants