-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Provide an API to get the native module handle of the native process entry-point module #56331
Comments
Implementation question: how does this method affect the handle's reference count? |
This method will cache the handle after it's been called once, so it will only increase the refcount of the handle by 1. On Windows, we'll use Since the module is the process's entry-point module, we don't need to worry about releasing the handle since it is valid until process tear-down (which will release the handle anyway). |
Another approach is to return runtime/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs Line 250 in 57bfe47
|
nit: this doesn't work on every unix. In particular on Android |
Looks good as proposed. namespace System.Runtime.InteropServices
{
public static class NativeLibrary
{
public static IntPtr GetEntryPointModuleHandle();
}
} |
Module is very Windows-specific name. There is nothing called I assume that the non-Windows implementation is going to return |
I didn't want to use |
And since the entrypoint of the program isn't a shared library, the name |
I don't have a strong preference here. "GetMainProgramHandle" or "GetEntryProgramHandle" are fine with me.
I was not aware of that behavior. The latest doc on
That is fair but isn't a |
Yes, we are trying to support a |
Understood. I don't see this as a large concern given we can document the usage clearly and this is a niche scenario so minor confusion is okay and easily remedied. Not shutting down the conversation about renaming simply saying I don't think that will be that hard of a problem to address, but I do think that @jkotas's argument is fair - "Module" is a Windows-centric term. Perhaps @bartonjs or @lambdageek have thoughts on naming alternatives? |
(I'm not great at naming) The man pages from Apple and Linux both call the value passed to namespace System.Runtime.InteropServices
{
public static class NativeLibrary
{
public static IntPtr GetDefaultSearchOrderPseudoHandle();
}
} |
During the API review there was theorization of a companion API like |
Yes, |
namespace System.Runtime.InteropServices
{
public static class NativeLibrary
{
public static IntPtr GetMainProgramHandle();
}
} |
Background and motivation
As mentioned in #7267, there is a strong desire for enabling using the "__Internal" name in a DllImport to point to methods in the hosting executable module of the process in both CoreCLR and Mono. Mono has had this support for many years, but CoreCLR doesn't have built-in support, and we don't have a desire to provide built-in support for this "hidden" name.
However, we understand the need for a way to resolve this name to the correct handle. We propose adding an API that gets the native module handle of the entry-point module.
API Proposal
Alternatively, we considered allowing
null
as a parameter toNativeLibrary.Load(string)
to match how the implementation on non-Windows isdlopen(NULL)
. The interop team decided that design was an abstraction leak and undesirable since the Windows implementation doesn't follow the same model. Additionally, the otherNativeLibrary.Load
overloads have additional behaviors and aren't thin wrappers, which makes thenull
option less desirable.API Usage
Risks
None
The text was updated successfully, but these errors were encountered: