How does the RTS "know" about ExitCode

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

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/ae11bdfd98a10266bfc7de9e16b500be22... [2]: https://gitlab.haskell.org/ghc/ghc/-/blob/ae11bdfd98a10266bfc7de9e16b500be22... 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.

Thanks! There is still one missing bit for me though - at what point/in what way does the user's main hook into the TopHandler stuff? (I'm interested in how practical it is to roll your own base, at least in regards to the exceptions mechanism.) ====== Georgi
participants (2)
-
Georgi Lyubenov
-
Utku Demir