Skip to content
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

WIN API LoadLibraryA is failling when loading a DLL created by Intel Fortran compiler in Windows Nanoserver container #448

Closed
mpospisil opened this issue Dec 5, 2023 · 8 comments
Labels
question Further information is requested

Comments

@mpospisil
Copy link

mpospisil commented Dec 5, 2023

We have a dll 'k2femmkl64.dll' which was generated by Intel Fortran compiler. It depends on Intel's libiomp5md.dll

If we call HMODULE dllHandle = LoadLibraryA("k2femmkl64.dll");

it fails in Windows Nano Server container but it works in Windows Core container.

the error message is

Failed to load DLL: 127
CDB says “Specified procedure could not be found”

e8f8c477-36bf-4281-a1b8-4571b246beef

the problem can be reproduced by checking out the repository

https://github.com/mpospisil/intel_mkl_test

and running the application in a container see https://github.com/mpospisil/intel_mkl_test

If I use Windows Core container as my base image - it works

How can I find why Nano Server gives me the error 127 ?

@mpospisil mpospisil added the question Further information is requested label Dec 5, 2023
@ntrappe-msft ntrappe-msft added the triage New and needs attention label Dec 6, 2023
@conioh
Copy link

conioh commented Dec 12, 2023

Try running the process under WinDbg after enabling loader snaps.

@mpospisil
Copy link
Author

mpospisil commented Dec 18, 2023

I have successfully run
gflags.exe /i K2FemMklLoader.exe +sls

in the container

(but I had to run my container with an option " --user ContainerAdministrator " )

docker run -i -t --isolation=process --user ContainerAdministrator --volume c:\git\HiltiProfis\container-shared:c:\local k2femmkl-nanoserver

otherwise the value is not set

now I am getting a better log (see
loader-snaps-log.txt )

the problem is a missing function GetDllDirectoryA

`
0e0c:72ec @ 24968656 - LdrpNameToOrdinal - WARNING: Procedure "GetDllDirectoryA" could not be located in DLL at base 0x00007FFFCB940000.
0e0c:72ec @ 24968656 - LdrpReportError - ERROR: Locating export "GetDllDirectoryA" for DLL "c:\app\k2femmkl64.dll" failed with status: 0xc0000139.
(e0c.72ec): Unknown exception - code c0000139 (first chance)
0e0c:72ec @ 24968656 - LdrpGenericExceptionFilter - ERROR: Function LdrpSnapModule raised exception 0xc0000139
Exception record: .exr 000000CF873FE0B0
Context record: .cxr 000000CF873FDBC0
0e0c:72ec @ 24968656 - LdrpProcessWork - ERROR: Unable to load DLL: "k2femmkl64.dll", Parent Module: "(null)", Status: 0xc0000139
0e0c:72ec @ 24968656 - LdrpLoadDllInternal - RETURN: Status: 0xc0000139
0e0c:72ec @ 24968656 - LdrLoadDll - RETURN: Status: 0xc0000139

The specified procedure could not be found.

Failed to load DLL: 127
0e0c:72ec @ 24968656 - LdrLoadDll - ENTER: DLL name: api-ms-win-appmodel-runtime-l1-1-2
0e0c:72ec @ 24968656 - LdrpPreprocessDllName - ERROR: LdrpPreprocessDllName for DLL api-ms-win-appmodel-runtime-l1-1-2 failed with status 0xc0000481
0e0c:72ec @ 24968656 - LdrLoadDll - RETURN: Status: 0xc0000481
0e0c:72ec @ 24968656 - LdrGetDllHandleEx - ENTER: DLL name: mscoree.dll
0e0c:72ec @ 24968656 - LdrpFindLoadedDllInternal - RETURN: Status: 0xc0000135
0e0c:72ec @ 24968656 - LdrGetDllHandleEx - RETURN: Status: 0xc0000135
0e0c:72ec @ 24968656 - LdrShutdownProcess - INFO: Process 0x0000000000000E0C (c:\app\K2FemMklLoader.exe -v) exiting
0e0c:72ec @ 24968656 - LdrpGetProcedureAddress - INFO: Locating procedure "RtlDllShutdownInProgress" by name
0e0c:72ec @ 24968656 - LdrpGetProcedureAddress - INFO: Locating procedure "NtQueryWnfStateData" by name
`

I wonder why this function is not found in case on Windows Nano Server container but Windows Core works fine
Do you have any idea how to fix it ?

@conioh
Copy link

conioh commented Dec 19, 2023

Sounds like you should modify the DLL to use GetDllDirectoryW, which is present, at least in the kernel32legacy.dll in my Nano Server image.

It's not very well (or at all) documented, but Nano Server is very different from "regular" Windows and you can't assume that anything works there. This time it's just an ANSI variant of a function that is missing. If that change solves your issue, consider yourself lucky. There are much bigger differences. Just try running any of the 32-bit WinDbg EXEs...

@mpospisil
Copy link
Author

mpospisil commented Dec 19, 2023

Thank you for your help

@mpospisil mpospisil reopened this Jan 16, 2024
@mpospisil
Copy link
Author

mpospisil commented Jan 16, 2024

we can not modify the DLL (it is Intel dll) but I make it running by copying kernel32.dll to c:\windows\system32

in my nanoserver image
This is the Dockerfile .

It seems it overrides original

'C:\Windows\System32\forwarders\kernel32.dll

from Nanoserver. It has fixed our problem
Do you think it is a good workaround ?

@fady-azmy-msft
Copy link
Contributor

Hey @mpospisil, we're looking into why this is the case with Nanoserver, however we don't recommend copying DLLs between images as this may violate windows server licensing.

@ntrappe-msft ntrappe-msft removed the triage New and needs attention label Feb 7, 2024
Copy link
Contributor

This issue has been open for 30 days with no updates.
no assignees, please provide an update or close this issue.

@mpospisil
Copy link
Author

I agree with you - it is not a nice solution. I don't like copying kernel too but it was only way how to make it working. I am not able to modify native dlls. These are Intels dlls.
My nanoserver container has 885MB the container based on windows server core has 3.95GB.
If there is no better option we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants