Giter Site home page Giter Site logo

Support forking on Windows about munit HOT 15 OPEN

nemequ avatar nemequ commented on July 25, 2024
Support forking on Windows

from munit.

Comments (15)

lygstate avatar lygstate commented on July 25, 2024

CreateProcess

from munit.

nemequ avatar nemequ commented on July 25, 2024

My understanding is that CreateProcess is like to fork+exec, not just fork. The documentation seems to confirm, but I really don't know Windows; maybe there is a way to use it in a more fork-like fashion…

from munit.

lygstate avatar lygstate commented on July 25, 2024

There is parameter to disable exec.

from munit.

nemequ avatar nemequ commented on July 25, 2024

Hm, maybe I'm looking for the wrong keywords, but I don't see anything in the MSDN docs about that. Can you be more specific?

from munit.

nemequ avatar nemequ commented on July 25, 2024

AFAICT the best solution available is to use some undocumented APIs from NT (ZwCreateProcess or NtCreateProcess, I don't know which is preferred). The best thread I can find on the subject is hardly conclusive.

I'd be happy to merge a patch, but I'm probably not going to be writing this code myself; I don't really have a good way to do any development on Windows, and I'm not sure mingw will work for this.

from munit.

lygstate avatar lygstate commented on July 25, 2024

https://github.com/jonclayden/multicore/blob/master/src/forknt.c

from munit.

nemequ avatar nemequ commented on July 25, 2024

Nice. Seeing a full example instead of just a description helps.

It looks like that project is GPLv2. I could rewrite the code, but @s-u, would you mind licensing us a copy under the MIT license instead?

Modern versions of mingw seem to support winternl.h, so I think it should be possible to get rid of most (all?) of those types and typedefs.

from munit.

lygstate avatar lygstate commented on July 25, 2024

@nemequ I suggest do not only support for mingw, both mingw/ msvc need to be supported.

from munit.

nemequ avatar nemequ commented on July 25, 2024

Of course. Does winternl.h not exist for msvc? Based on line 16 I assumed windows had it but mingw didn't…

from munit.

s-u avatar s-u commented on July 25, 2024

Sure, I have added explicit MIT license (with non-binding copyleft) to the original file:

https://github.com/s-u/multicore/blob/master/src/forknt.c

But please keep me posted if you get it working - a lot of people would be very thankful. forknt used to work, but it doesn't on more recent Windows releases (if I recall it started breaking in Vista).

from munit.

nemequ avatar nemequ commented on July 25, 2024

@s-u, thanks, I really appreciate the license change! I like that non-binding request, I'll have to think about adding that to µnit…

I'll try to play around with it a bit at some point, but I'm really not a Windows developer so don't get your hopes up. Regardless, it's a good starting point for anyone else with the desire to tackle this issue.

from munit.

vitasam avatar vitasam commented on July 25, 2024

Hi,
I don't want to create an issue, just a quick question: what is a correct way of running test application under Valgrind: with or without --no-fork option?

from munit.

nemequ avatar nemequ commented on July 25, 2024

@vitasam, it has been a while since I used valgrind (pretty much since AddressSanitizer came out), but IIRC you can pass --trace-children=yes to have it check child processes, or you can pass --no-fork to µnit so valgrind doesn't have to deal with it (though of course you lose the benefits that come with forking).

In the future, please file a new issue. It's actually much less disruptive since it won't cause notifications to be sent to people subscribed to the existing issue, and it helps keep the issues clean.

from munit.

vitasam avatar vitasam commented on July 25, 2024

@nemequ, thanks!

from munit.

Snaipe avatar Snaipe commented on July 25, 2024

I'm the author of Criterion, and it happens that I've been exploring the same set of issues since the inception of the project.

While I started with simple forking, I ended up ditching the idea of just doing that two years later. The fact is that I've had myriads of problems with libraries that are not fork-safe (and most of them aren't. Looking at you, CoreFoundation) in general. Similarly, I've had my fair share of issues with windows, but ended up implementing the horrible pile of hacks that is fork on Windows; and let me tell you that without controlling the whole toolchain, this was horribly fragile and broke between windows releases.

Instead, the new implementation forks, and re-executes the current executable while jumping on another main. All in all, this is just an order of magnitudes cleaner (in particular, since the parent's address space is not inherited, leaks from the parent don't propagate), but involves a lot of efforts to get somewhere.

I understand that this might not follow the design goals of munit, so I thought I would give my two cents on the matter. BoxFort might not be for you, but you might get some ideas out of it.

Good luck! :)

from munit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.