node-api: explicitly set __cdecl for Node-API functions#42780
Closed
vmoroz wants to merge 1 commit intonodejs:masterfrom
Closed
node-api: explicitly set __cdecl for Node-API functions#42780vmoroz wants to merge 1 commit intonodejs:masterfrom
vmoroz wants to merge 1 commit intonodejs:masterfrom
Conversation
Collaborator
|
Review requested:
|
Contributor
|
We discussed this on today's Node API meeting. This makes sense to me. Does anyone else on the team have any issues / concerns? We may need to look at the |
713c6e6 to
7434911
Compare
mhdawson
approved these changes
May 2, 2022
Member
mhdawson
left a comment
There was a problem hiding this comment.
LGTM. From the discussion in the last Node-api team meeting my understaning is that does not change anything since CDECL was already the default, but it does help my making it explicit.
Collaborator
This was referenced May 3, 2022
Collaborator
mhdawson
pushed a commit
that referenced
this pull request
May 13, 2022
PR-URL: #42780 Reviewed-By: Michael Dawson <midawson@redhat.com>
Member
|
Landed in fb74474 |
BethGriggs
pushed a commit
that referenced
this pull request
May 16, 2022
PR-URL: #42780 Reviewed-By: Michael Dawson <midawson@redhat.com>
Merged
Member
|
This is blocked by #42459 |
targos
pushed a commit
that referenced
this pull request
Jul 31, 2022
PR-URL: #42780 Reviewed-By: Michael Dawson <midawson@redhat.com>
guangwong
pushed a commit
to noslate-project/node
that referenced
this pull request
Oct 10, 2022
PR-URL: nodejs/node#42780 Reviewed-By: Michael Dawson <midawson@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The issue
The Node-API is a quite generic ABI-safe API that can be used as JavaScript engine ABI-safe API outside of Node.JS project.
The issue is that currently it does not specify calling conventions which is critical if Windows DLLs compiled with different default calling conventions. It is not important for x64 or non-Windows platforms because they use one predefined calling convention, but for Windows x86 applications there are multiple calling conventions, and their mismatch causes a runtime crash.
E.g. I had previously added
__cdecltov8jsi.dllcopy ofjs_native_api.h, but we still saw crashes in Windows x86 because__cdeclwas not added to function pointers injs_native_api_types.h. The issue is being addressed by microsoft/v8-jsi#122.This example shows how important the calling conventions are for Window x86 platform.
The solution
In this PR we are adding
__cdeclto all functions and function pointers that target Win32 platform.To do that we add a new macro
NAPI_CDECL. It is expanded to__cdeclfor Win32 platforms and to nothing for other platforms.Discussion
This PR sets
__cdeclas the calling conventions because it is the default in C/C++ compilers.It would be ideal to use
__stdcallcalling conventions to match Windows API because it produces more compact code on calling side, but my concern is that such change may affect existing code. Though, if Node.JS is not shipped for x86, then it may be still safe to use__stdcallinstead of__cdecl.