I also didn't know that, so I looked at the source, and found out that GHC has a wrapper[1] around `main` which (besides a few other stuff) is responsible for catching exceptions including the ExitCode and figuring out the appropriate exit code. In order to actually exit the program, `shutdownHaskellAndExit` C function from RTS [2] is called from there which takes the exit code as a parameter.

This was good to know, thanks for the question!

Utku

[1]: https://gitlab.haskell.org/ghc/ghc/-/blob/ae11bdfd98a10266bfc7de9e16b500be220307ac/libraries/base/GHC/TopHandler.hs 
[2]: https://gitlab.haskell.org/ghc/ghc/-/blob/ae11bdfd98a10266bfc7de9e16b500be220307ac/rts/RtsStartup.c#L554


On Thu, Jul 16, 2020, at 12:05 AM, Georgi Lyubenov wrote:
Hi!

I'm wondering how values stored in ExitCode "get to" the RTS (i.e. actually make the program exit with the given number).

As far as I can tell ExitCode is used as an everyday normal-looking exception (which are defined entirely in "library code", by using the raise#/catch# primitives), without any direct link to the RTS.

What am I missing?

======
Georgi
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.