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

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

Open
tiangolo opened this issue May 4, 2017 · 5 comments

Comments

@tiangolo
Copy link
Contributor

tiangolo commented May 4, 2017

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?

@unbornchikken
Copy link
Member

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.

@tiangolo
Copy link
Contributor Author

tiangolo commented May 5, 2017

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?

@unbornchikken
Copy link
Member

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

@tiangolo tiangolo changed the title Debugging Windows 32 bits, some calls fail Support calling conventions other than the default: Windows 32 bits, some calls fail May 5, 2017
@tiangolo
Copy link
Contributor Author

tiangolo commented May 5, 2017

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

@unbornchikken
Copy link
Member

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.

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

No branches or pull requests

2 participants