runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Issue with DllImport

Open manu-st opened this issue 10 years ago • 25 comments

While exploring how DllImport worked on Linux, I found the following issue at this line: https://github.com/dotnet/coreclr/blob/master/src/vm/dllimport.cpp#L7165

It seems that the code forgot to assign the result of the call to LoadFromNativeDllSearchDirectories to hmod. Is this expected?

manu-st avatar May 18 '16 02:05 manu-st

@manu-silicon You're right. Thanks for finding this issue!

adityamandaleeka avatar May 18 '16 03:05 adityamandaleeka

@adityamandaleeka You are welcome.

manu-st avatar May 18 '16 04:05 manu-st

Wouldn't it be nice if the language / compiler complained loudly when return values were ignored?

https://twitter.com/xjoeduffyx/status/730991667960893440

:smirk:

whoisj avatar May 18 '16 04:05 whoisj

@adityamandaleeka I just discovered this as well and I have a fix (https://github.com/dotnet/coreclr/pull/5048) that fixes this as well as a different issue. Our PR probably going to conflict since I'm moving that exact same code.

yizhang82 avatar May 18 '16 06:05 yizhang82

@yizhang82 I've closed my PR, and am reassigning this issue to you.

adityamandaleeka avatar May 18 '16 18:05 adityamandaleeka

@adityamandaleeka Thank you!

yizhang82 avatar May 18 '16 18:05 yizhang82

Fixed with dotnet/coreclr#5048

yizhang82 avatar May 18 '16 20:05 yizhang82

@yizhang82 By the way, how one can set NATIVE_DLL_SEARCH_DIRECTORIES?

manu-st avatar May 19 '16 00:05 manu-st

@manu-silicon Only host can. See https://github.com/dotnet/coreclr/blob/f4fe31a03dca4ede37bd6451d0c81365ee9ee7e4/src/coreclr/hosts/corerun/corerun.cpp

yizhang82 avatar May 19 '16 00:05 yizhang82

I see. Is there a way to have that set of directories searched too for PInvoke? That would help tremendously!

manu-st avatar May 19 '16 00:05 manu-st

Yep. It is being searched already and that's exactly what LoadFromNativeDllSearchDirectories does. My other PR dotnet/coreclr#5048 only changes the order.

yizhang82 avatar May 19 '16 00:05 yizhang82

Actually I found that one could define the CORE_LIBRARIES environment variable but this only seems to work on Windows. The unix version of corerun doesn't check for it. Would be nice to have them consistent.

manu-st avatar May 19 '16 00:05 manu-st

@manu-silicon That's a host specific issue since host owns translating the environment variables into NATIVE_DLL_SEARCH_DIRECTORIES that is understood by the runtime. @schellap Can you take a look and create a issue as well? /cc @gkhanna79

yizhang82 avatar May 19 '16 00:05 yizhang82

In the meantime, I'll work on porting the Windows code to unixcoreruncommon to fetch the value of CORE_LIBRARIES as I need this to run some program on Unix. Thanks!

manu-st avatar May 19 '16 00:05 manu-st

Corelibraries is for internal development. We should probably clean it up and remove it. You should use native ski search path envvar only.

gkhanna79 avatar May 19 '16 01:05 gkhanna79

Not sure to understand what native ski means. I just made a patch for picking up from CORE_LIBRARIES. See https://github.com/dotnet/coreclr/compare/master...manu-silicon:core_libraries?expand=1 Let me know if this is worth creating a pull request.

manu-st avatar May 19 '16 01:05 manu-st

@manu-silicon Sorry, auto-correct on phone does its own thing.

CORE_LIBRARIES is just a development/internal-testing environment variable and should not be relied upon. If you wish to add it to unixcorerun for consistentcy, that is fine. But this is not expected to be formally supported in any host used in formal scenarios. The formal way to specify the folders to look for pinvoke targets is NATIVE_DLL_SEARCH_PATHS.

gkhanna79 avatar May 19 '16 03:05 gkhanna79

@gkhanna79 I understand that but how do I set this as a user? I only found CORE_LIBRARIES as a solution.

manu-st avatar May 19 '16 03:05 manu-st

You cannot - this is a host property and you will need to write a host that sets it. For .NET Core, this is automatically computed based upon the app manifest and .NET Host passes it to the runtime. If you have a scenario where you wish to have an external user specify such a value, consider authoring a host.

gkhanna79 avatar May 19 '16 03:05 gkhanna79

I was thinking about an app manifest too. Is this supported just for Windows?

manu-st avatar May 19 '16 03:05 manu-st