Skip to content

try libnode.dll first in load_exe_hook#2834

Merged
lukekarrys merged 1 commit into
nodejs:mainfrom
zombieyang:main
Dec 13, 2024
Merged

try libnode.dll first in load_exe_hook#2834
lukekarrys merged 1 commit into
nodejs:mainfrom
zombieyang:main

Conversation

@zombieyang

@zombieyang zombieyang commented Apr 26, 2023

Copy link
Copy Markdown
Contributor
Checklist
  • npm install && npm test passes
  • tests are included
  • documentation is changed or added
  • commit message follows commit guidelines
Description of change

It is a following PR of nodejs/node#47682.

I've tried to rename my executable to node.exe but the error is still there.
That's because the node.js's symbol is in libnode.dll but not in my executable. So, GetModuleHandle(NULL) will not work.

However, I think we can try to load libnode.dll first. If failed then fallback to try the executable. That will solve the problem and keep the original path work either.
Maybe it is looks like a edge case, but as Node.js has a embedding tutorial in the doc, I think it's worth to do this.

Or please tell me if there is a more simple way to solve my problem.


Test is not included because I need to provide a huge nodedll binary.

Thank you, I love node.js.

@Kreijstal

Copy link
Copy Markdown

Can anyone review?

@zombieyang

Copy link
Copy Markdown
Contributor Author

I'm not quite sure if it still make sense after such a long time. Maybe you can consider cherry-picking dd56ec0

@lukekarrys

Copy link
Copy Markdown
Member

I have rebased this PR to include only dd56ec0

@Kreijstal

Copy link
Copy Markdown

I have rebased this PR to include only dd56ec0

Thank you

@zombieyang

Copy link
Copy Markdown
Contributor Author

I have rebased this PR to include only dd56ec0

Thank you, will it merge?

@Kreijstal

Copy link
Copy Markdown

I have rebased this PR to include only dd56ec0

Thank you, will it merge?

i hope so

@lukekarrys
lukekarrys merged commit 0d00253 into nodejs:main Dec 13, 2024
cuva added a commit to raycast/napi-rs that referenced this pull request Jul 7, 2026
On Windows, load_all() resolved N-API symbols exclusively from the process
executable on MSVC targets. That works when the host is node.exe (or an
executable that re-exports Node symbols, like Electron), but fails when
Node runs embedded through libnode.dll: the process image has no N-API
exports and every addon load errors out.

Compile the existing find_node_library() fallback chain (process image
first, then an already-loaded libnode/node module) for MSVC targets too,
mirroring node-gyp's delay-load hook behavior (nodejs/node-gyp#2834).
Subprocess hosts are unaffected: the process-image lookup still wins when
the executable exports the symbols.
cuva added a commit to raycast/napi-rs that referenced this pull request Jul 7, 2026
On Windows, load_all() resolved N-API symbols exclusively from the process
executable on MSVC targets. That works when the host is node.exe (or an
executable that re-exports Node symbols, like Electron), but fails when
Node runs embedded through libnode.dll: the process image has no N-API
exports and every addon load errors out.

Compile the existing find_node_library() fallback chain (process image
first, then an already-loaded libnode/node module) for MSVC targets too,
mirroring node-gyp's delay-load hook behavior (nodejs/node-gyp#2834).
Subprocess hosts are unaffected: the process-image lookup still wins when
the executable exports the symbols.
Brooooooklyn pushed a commit to napi-rs/napi-rs that referenced this pull request Jul 7, 2026
…#3384)

On Windows, load_all() resolved N-API symbols exclusively from the process
executable on MSVC targets. That works when the host is node.exe (or an
executable that re-exports Node symbols, like Electron), but fails when
Node runs embedded through libnode.dll: the process image has no N-API
exports and every addon load errors out.

Compile the existing find_node_library() fallback chain (process image
first, then an already-loaded libnode/node module) for MSVC targets too,
mirroring node-gyp's delay-load hook behavior (nodejs/node-gyp#2834).
Subprocess hosts are unaffected: the process-image lookup still wins when
the executable exports the symbols.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants