fastcall icon indicating copy to clipboard operation
fastcall copied to clipboard

Support calling conventions other than the default: Windows 32 bits, some calls fail

Open tiangolo opened this issue 8 years ago • 5 comments

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.json in that directory with npm init (without it, cmake-js compilation would fail).
  • Install active-win: npm install --save active-win.
  • Open a PowerShell and set the DEBUG env 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-win that uses fastcall is 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-win as a dependency, installing fastcall and ref-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 with node-ffi and 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?

tiangolo avatar May 04 '17 21:05 tiangolo

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.

unbornchikken avatar May 05 '17 07:05 unbornchikken

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?

tiangolo avatar May 05 '17 13:05 tiangolo

I'm considering this issue as a feature request to support calling conventions other than the default.

unbornchikken avatar May 05 '17 14:05 unbornchikken

OK, cool. I'll update the title so you can refer to it later more easily.

tiangolo avatar May 05 '17 14:05 tiangolo

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.

unbornchikken avatar Nov 02 '17 07:11 unbornchikken