fastcall
fastcall copied to clipboard
Support calling conventions other than the default: Windows 32 bits, some calls fail
Description
I'm trying to use active-win that uses fastcall as a dependency.
I'm being able to "build" / install it run it.
When I use it in a Windows 7 with a x64 architecture it all works fine.
But when I try to use it in a Windows 7 with a ia32 architecture, it fails. I'm trying to run it in a node interactive session / terminal. But when I call the library it just exits without even thowing an exception or showing any error.
Steps to reproduce
- Download a Windows 7
ia32(x86) free virtual machine from: https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/, for example:IE8 on Win7 (x86). - Install requirements (Cmake, Windows Build Tools / https://github.com/felixrieseberg/windows-build-tools).
- Create a directory.
- Create a
package.jsonin that directory withnpm init(without it,cmake-jscompilation would fail). - Install
active-win:npm install --save active-win. - Open a PowerShell and set the
DEBUGenv var:$env:DEBUG="*" - Run an interactive Node session in PowerShell:
node. - Require
active-win:const activeWin = require('active-win');. - Call the function:
activeWin(). - You should get a
Promise, but instead, Node just closes, without showing any error. - The debug log shows:
fastcall:es5Support running in ES2015 mode +0ms
ref creating a reference to buffer <Buffer > +16ms
ref allocating Buffer for type with "size" 0 +0ms
ref setting value on allocated buffer <Buffer > +0ms
ref set(): (offset: 0) <Buffer 08 8b 90 03> <Buffer > +0ms
ref writing pointer to buffer <Buffer 08 8b 90 03> 0 <Buffer > +0ms
ref creating a reference to buffer <Buffer > +172ms
ref allocating Buffer for type with "size" 0 +0ms
ref setting value on allocated buffer <Buffer > +0ms
ref set(): (offset: 0) <Buffer 76 65 72 69> <Buffer > +0ms
ref writing pointer to buffer <Buffer 76 65 72 69> 0 <Buffer > +15ms
Details
-
The code in
active-winthat usesfastcallis here: https://github.com/sindresorhus/active-win/blob/master/windows.js -
It's possible to do all the same steps above, but instead of installing
active-winas a dependency, installingfastcallandref-wchar. -
Then, running an interactive Node session, it's possible to run all the code in that file, line by line, up until: https://github.com/sindresorhus/active-win/blob/master/windows.js#L42, in that line is that it "explodes".
-
I did all the same experiment, in the same VM, but instead of using
fastcall, replacing everything withnode-ffiand it worked as expected. So it seems that it's not a problem with the names of the symbols or something similar.
I'm unable to see any error, I don't really know how to try to find the problem. Do you have any suggestion on how to debug it?
Hello there,
Unfortunately that's expected. fastcall currently doesn't support setting calling conventions, just uses the default C call of the actual platform. It happens that Win64 uses that too, but Win32 uses its own stdcall conventionwhich is different than standard C.
I'm planning to implement calling convention support, but it won't magically fixes active-win because it have to decalre its calling conventions based on the actual node runtime.
OK, get it (kind of, I'm not a C guy). Thanks for the explanation.
So, for now, for that specific use case, I'm stuck with node-ffi, right?
I'm considering this issue as a feature request to support calling conventions other than the default.
OK, cool. I'll update the title so you can refer to it later more easily.
Unfortunatelly I need more time to get back to this project. This request hasn't forgotten, but real life issues burn up my whole spare time recently.