Skip to content

_get_osfhandle in Addon fails on Windows #6369

Description

@davedoesdev
  • Version: v5.10.1
  • Platform: Windows 7, 8 and 10 (32 and 64 bit)
  • Subsystem: fs and Addons

_get_osfhandle fails to map a file descriptor opened in Javascript to a handle.

Please see https://github.com/davedoesdev/node-windows-fd-test for a simple repro. It's also seen in baudehlo/node-fs-ext#57 and nodejs/node-gyp#416

I think this is due to MSVCR being statically linked into Node. _get_osfhandle can't find a descriptor opened in Javascript because the file descriptor to handle map in the Addon is separate to the one statically linked into the Node executable.

It would be nice to be able to use file descriptors passed into Addons on Windows. One idea is to expose _get_osfhandle (or a wrapper) from the Node executable for Addons to link against and call.

Activity

  1. added
    windowsIssues and PRs related to the Windows platform.
    on Apr 25, 2016
  2. bnoordhuis commented on Apr 25, 2016

    @bnoordhuis
    Member

    Related: #6274. We need a way to re-export symbols that aren't marked __declspec(dllexport) but it's currently a right pain to do so.

  3. piscisaureus commented on Apr 28, 2016

    @piscisaureus
    Contributor

    The best way to go about it is probably to make the uv__get_osfhandle() function public.
    https://github.com/libuv/libuv/blob/b12624c13693c4d29ca84b3556eadc9e9c0936a4/src/win/handle-inl.h#L165-L177

  4. bnoordhuis commented on Apr 29, 2016

    @bnoordhuis
    Member

    I'd rather make node properly re-export symbols. We need that anyway to make linking against openssl possible on Windows. I've been nibbling at it but it's slow going.

  5. dimichgh commented on May 9, 2016

    @dimichgh

    I tried to port mmap.js to windows (https://github.com/dimichgh/mmap.js/blob/master/src/winmmap.h#L58), but due to this issue, I am now blocked.

  6. jviotti commented on Apr 5, 2017

    @jviotti
    Member

    This is hard blocker for https://github.com/resin-io/etcher. I opened an issue in libuv. I'm happy to contribute a patch to make uv__get_osfhandle() public if they agree: libuv/libuv#1291

  7. baudehlo commented on Apr 25, 2017

    @baudehlo

    It's a year to the day. Any progress on this?

  8. jviotti commented on Apr 26, 2017

    @jviotti
    Member

    @baudehlo I just sent a PR for this: libuv/libuv#1323

  9. added a commit that references this issue on May 30, 2017
  10. bzoz commented on Jun 20, 2017

    @bzoz
    Contributor

    I guess this was solved by libuv/libuv#1323. Closing.

  11. davedoesdev commented on Jul 6, 2017

    @davedoesdev
    ContributorAuthor

    @bzoz yes indeed, it does work. I've updated my test app (https://github.com/davedoesdev/node-windows-fd-test, see first comment in this ticket) to use uv_get_osfhandle.

    @jviotti thanks for fixing this.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions