+
+/* -----------------------------------------------------------------------------
+ Getting/Setting the program's arguments.
+
+ These are used by System.Environment.
+ -------------------------------------------------------------------------- */
+
+void
+getProgArgv(int *argc, char **argv[])
+{
+ if (argc) { *argc = prog_argc; }
+ if (argv) { *argv = prog_argv; }
+}
+
+void
+setProgArgv(int argc, char *argv[])
+{
+ /* Usually this is done by startupHaskell, so we don't need to call this.
+ However, sometimes Hugs wants to change the arguments which Haskell
+ getArgs >>= ... will be fed. So you can do that by calling here
+ _after_ calling startupHaskell.
+ */
+ prog_argc = argc;
+ prog_argv = argv;
+}
+
+/* -----------------------------------------------------------------------------
+ Per-module initialisation
+
+ This process traverses all the compiled modules in the program
+ starting with "Main", and performing per-module initialisation for
+ each one.
+
+ So far, two things happen at initialisation time:
+
+ - we register stable names for each foreign-exported function
+ in that module. This prevents foreign-exported entities, and
+ things they depend on, from being garbage collected.
+
+ - we supply a unique integer to each statically declared cost
+ centre and cost centre stack in the program.
+
+ The code generator inserts a small function "__stginit_<module>" in each
+ module and calls the registration functions in each of the modules it
+ imports.
+
+ The init* functions are compiled in the same way as STG code,
+ i.e. without normal C call/return conventions. Hence we must use
+ StgRun to call this stuff.
+ -------------------------------------------------------------------------- */
+
+/* The init functions use an explicit stack...
+ */
+#define INIT_STACK_BLOCKS 4
+static F_ *init_stack = NULL;
+
+void
+hs_add_root(void (*init_root)(void))
+{
+ bdescr *bd;
+#ifdef SMP
+ Capability cap;
+#else
+#define cap MainCapability