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

[Help] wonder how luv_renamed.c implement #97

Closed
starwing opened this issue Jun 4, 2015 · 4 comments
Closed

[Help] wonder how luv_renamed.c implement #97

starwing opened this issue Jun 4, 2015 · 4 comments

Comments

@starwing
Copy link
Contributor

starwing commented Jun 4, 2015

Hi,

luv_renamed.c used to redirect dll's that linked with 'luvi.exe' to load symbols from current process, right?

I just want the same tech to make a standalone lua.exe, to makes dlls that linked against lua53.dll to use symbols exported by lua.exe, so I write a redir_luadll.c, same with luv_renamed.c.

but I have some questions:

  1. is my dll (say, foo.dll) need some specific way to build? If that, means I can't use the right now dlls to support my lua.exe.
  2. I use both MSVC and MinGW, does MinGW support this usage?
@creationix
Copy link
Member

ping @rjemanuele

@rjemanuele
Copy link
Member

Hi,

Yes, that is what luv_renamed.c does. It uses a Microsoft concept called Delay Loaded DLLs.

Since our extensions that are DLLs are built against the exports from luvi.exe, those DLLs look for luvi.exe for their unresolved symbols. Since luvi.exe can be renamed and packaged with an appended zip file to contain the lua code and DLLs it may not be able to find luvi.exe. Using the delay loading hooks, tell the operating system loading the DLLs what to do. In our case we catch the lookup of symbols from luvi.exe and redirect it to the current executable.

The delay loading failure hook needs to be in the DLL. In our case, we require some DLL library, that DLL loads, it has other symbols to resolve (including from our luvi.exe), the failure hook makes that redirection.

You may need to build your DLL in a certain way, without more information I cannot be sure. How we build extension DLLs is like this: https://github.com/virgo-agent-toolkit/lua-sigar/blob/master/CMakeLists.txt

@starwing
Copy link
Contributor Author

starwing commented Jun 5, 2015

Thank you for explaining!

I wonder there is a way to redirect dll's dependency without modify dll.

e.g. I have a foo.dll, it depends bar.dll, when I load foo.dll, I make foo.dll do not load bar.dll, but use process handler (GetModuleHandle(NULL)) to resolve symbols. Is that possible?

@rjemanuele
Copy link
Member

I believe you can look up each symbol you need thought GetModuleHandle(NULL), just seems like more work.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants