summaryrefslogtreecommitdiff
path: root/includes/RtsAPI.h
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-11-15 15:43:28 +0000
committerSimon Marlow <marlowsd@gmail.com>2011-11-16 14:39:24 +0000
commit1df28a805b465a28b61f4cfe4db28f247a183206 (patch)
tree2fff045a1ac1b8468bff2fb892b7059d397d794e /includes/RtsAPI.h
parent1790dbe4a5829af5bcdc5bc81eafb67b154008cc (diff)
downloadhaskell-1df28a805b465a28b61f4cfe4db28f247a183206.tar.gz
Generate the C main() function when linking a binary (fixes #5373)
Rather than have main() be statically compiled as part of the RTS, we now generate it into the tiny C file that we compile when linking a binary. The main motivation is that we want to pass the settings for the -rtsotps and -with-rtsopts flags into the RTS, rather than relying on fragile linking semantics to override the defaults, which don't work with DLLs on Windows (#5373). In order to do this, we need to extend the API for initialising the RTS, so now we have: void hs_init_ghc (int *argc, char **argv[], // program arguments RtsConfig rts_config); // RTS configuration hs_init_ghc() can optionally be used instead of hs_init(), and allows passing in configuration options for the RTS. RtsConfig is a struct, which currently has two fields: typedef struct { RtsOptsEnabledEnum rts_opts_enabled; const char *rts_opts; } RtsConfig; but might have more in the future. There is a default value for the struct, defaultRtsConfig, the idea being that you start with this and override individual fields as necessary. In fact, main() was in a separate static library, libHSrtsmain.a. That's now gone.
Diffstat (limited to 'includes/RtsAPI.h')
-rw-r--r--includes/RtsAPI.h48
1 files changed, 43 insertions, 5 deletions
diff --git a/includes/RtsAPI.h b/includes/RtsAPI.h
index dc151faf07..329b1569ab 100644
--- a/includes/RtsAPI.h
+++ b/includes/RtsAPI.h
@@ -38,26 +38,64 @@ typedef struct StgClosure_ *HaskellObj;
typedef struct Capability_ Capability;
/* ----------------------------------------------------------------------------
+ RTS configuration settings, for passing to hs_init_ghc()
+ ------------------------------------------------------------------------- */
+
+typedef enum {
+ RtsOptsNone, // +RTS causes an error
+ RtsOptsSafeOnly, // safe RTS options allowed; others cause an error
+ RtsOptsAll // all RTS options allowed
+ } RtsOptsEnabledEnum;
+
+// The RtsConfig struct is passed (by value) to hs_init_ghc(). The
+// reason for using a struct is extensibility: we can add more
+// fields to this later without breaking existing client code.
+typedef struct {
+ RtsOptsEnabledEnum rts_opts_enabled;
+ const char *rts_opts;
+} RtsConfig;
+
+// Clients should start with defaultRtsConfig and then customise it.
+// Bah, I really wanted this to be a const struct value, but it seems
+// you can't do that in C (it generates code).
+extern const RtsConfig defaultRtsConfig;
+
+/* ----------------------------------------------------------------------------
Starting up and shutting down the Haskell RTS.
------------------------------------------------------------------------- */
-extern void startupHaskell ( int argc, char *argv[],
+
+/* DEPRECATED, use hs_init() or hs_init_ghc() instead */
+extern void startupHaskell ( int argc, char *argv[],
void (*init_root)(void) );
+
+/* DEPRECATED, use hs_exit() instead */
extern void shutdownHaskell ( void );
+
+/*
+ * GHC-specific version of hs_init() that allows specifying whether
+ * +RTS ... -RTS options are allowed or not (default: only "safe"
+ * options are allowed), and allows passing an option string that is
+ * to be interpreted by the RTS only, not passed to the program.
+ */
+extern void hs_init_ghc (int *argc, char **argv[], // program arguments
+ RtsConfig rts_config); // RTS configuration
+
extern void shutdownHaskellAndExit ( int exitCode )
#if __GNUC__ >= 3
__attribute__((__noreturn__))
#endif
;
+
+#ifndef mingw32_HOST_OS
+extern void shutdownHaskellAndSignal (int sig);
+#endif
+
extern void getProgArgv ( int *argc, char **argv[] );
extern void setProgArgv ( int argc, char *argv[] );
extern void getFullProgArgv ( int *argc, char **argv[] );
extern void setFullProgArgv ( int argc, char *argv[] );
extern void freeFullProgArgv ( void ) ;
-#ifndef mingw32_HOST_OS
-extern void shutdownHaskellAndSignal (int sig);
-#endif
-
/* exit() override */
extern void (*exitFn)(int);