1 /* ----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * API for invoking Haskell functions via the RTS
7 * To understand the structure of the RTS headers, see the wiki:
8 * http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
10 * --------------------------------------------------------------------------*/
22 * Running the scheduler
25 NoStatus, /* not finished yet */
26 Success, /* completed successfully */
27 Killed, /* uncaught exception */
28 Interrupted, /* stopped in response to a call to interruptStgRts */
29 HeapExhausted /* out of memory */
32 typedef struct StgClosure_ *HaskellObj;
35 * An abstract type representing the token returned by rts_lock() and
36 * used when allocating objects and threads in the RTS.
38 typedef struct Capability_ Capability;
40 /* ----------------------------------------------------------------------------
41 Starting up and shutting down the Haskell RTS.
42 ------------------------------------------------------------------------- */
43 extern void startupHaskell ( int argc, char *argv[],
44 void (*init_root)(void) );
45 extern void shutdownHaskell ( void );
46 extern void shutdownHaskellAndExit ( int exitCode );
47 extern void getProgArgv ( int *argc, char **argv[] );
48 extern void setProgArgv ( int argc, char *argv[] );
49 extern void getFullProgArgv ( int *argc, char **argv[] );
50 extern void setFullProgArgv ( int argc, char *argv[] );
51 extern void freeFullProgArgv ( void ) ;
53 #ifndef mingw32_HOST_OS
54 extern void shutdownHaskellAndSignal (int sig);
58 extern void (*exitFn)(int);
60 /* ----------------------------------------------------------------------------
63 You have to surround all access to the RtsAPI with these calls.
64 ------------------------------------------------------------------------- */
66 // acquires a token which may be used to create new objects and
68 Capability *rts_lock (void);
70 // releases the token acquired with rts_lock().
71 void rts_unlock (Capability *token);
73 // If you are in a context where you know you have a current capability but
74 // do not know what it is, then use this to get it. Basically this only
75 // applies to "unsafe" foreign calls (as unsafe foreign calls are made with
76 // the capability held).
78 // WARNING: There is *no* guarantee this returns anything sensible (eg NULL)
79 // when there is no current capability.
80 Capability *rts_unsafeGetMyCapability (void);
82 /* ----------------------------------------------------------------------------
83 Building Haskell objects from C datatypes.
84 ------------------------------------------------------------------------- */
85 HaskellObj rts_mkChar ( Capability *, HsChar c );
86 HaskellObj rts_mkInt ( Capability *, HsInt i );
87 HaskellObj rts_mkInt8 ( Capability *, HsInt8 i );
88 HaskellObj rts_mkInt16 ( Capability *, HsInt16 i );
89 HaskellObj rts_mkInt32 ( Capability *, HsInt32 i );
90 HaskellObj rts_mkInt64 ( Capability *, HsInt64 i );
91 HaskellObj rts_mkWord ( Capability *, HsWord w );
92 HaskellObj rts_mkWord8 ( Capability *, HsWord8 w );
93 HaskellObj rts_mkWord16 ( Capability *, HsWord16 w );
94 HaskellObj rts_mkWord32 ( Capability *, HsWord32 w );
95 HaskellObj rts_mkWord64 ( Capability *, HsWord64 w );
96 HaskellObj rts_mkPtr ( Capability *, HsPtr a );
97 HaskellObj rts_mkFunPtr ( Capability *, HsFunPtr a );
98 HaskellObj rts_mkFloat ( Capability *, HsFloat f );
99 HaskellObj rts_mkDouble ( Capability *, HsDouble f );
100 HaskellObj rts_mkStablePtr ( Capability *, HsStablePtr s );
101 HaskellObj rts_mkBool ( Capability *, HsBool b );
102 HaskellObj rts_mkString ( Capability *, char *s );
104 HaskellObj rts_apply ( Capability *, HaskellObj, HaskellObj );
106 /* ----------------------------------------------------------------------------
107 Deconstructing Haskell objects
108 ------------------------------------------------------------------------- */
109 HsChar rts_getChar ( HaskellObj );
110 HsInt rts_getInt ( HaskellObj );
111 HsInt8 rts_getInt8 ( HaskellObj );
112 HsInt16 rts_getInt16 ( HaskellObj );
113 HsInt32 rts_getInt32 ( HaskellObj );
114 HsInt64 rts_getInt64 ( HaskellObj );
115 HsWord rts_getWord ( HaskellObj );
116 HsWord8 rts_getWord8 ( HaskellObj );
117 HsWord16 rts_getWord16 ( HaskellObj );
118 HsWord32 rts_getWord32 ( HaskellObj );
119 HsWord64 rts_getWord64 ( HaskellObj );
120 HsPtr rts_getPtr ( HaskellObj );
121 HsFunPtr rts_getFunPtr ( HaskellObj );
122 HsFloat rts_getFloat ( HaskellObj );
123 HsDouble rts_getDouble ( HaskellObj );
124 HsStablePtr rts_getStablePtr ( HaskellObj );
125 HsBool rts_getBool ( HaskellObj );
127 /* ----------------------------------------------------------------------------
128 Evaluating Haskell expressions
130 The versions ending in '_' allow you to specify an initial stack size.
131 Note that these calls may cause Garbage Collection, so all HaskellObj
132 references are rendered invalid by these calls.
133 ------------------------------------------------------------------------- */
135 rts_eval (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
138 rts_eval_ (Capability *, HaskellObj p, unsigned int stack_size,
139 /*out*/HaskellObj *ret);
142 rts_evalIO (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
145 rts_evalStableIO (Capability *, HsStablePtr s, /*out*/HsStablePtr *ret);
148 rts_evalLazyIO (Capability *, HaskellObj p, /*out*/HaskellObj *ret);
151 rts_evalLazyIO_ (Capability *, HaskellObj p, unsigned int stack_size,
152 /*out*/HaskellObj *ret);
155 rts_checkSchedStatus (char* site, Capability *);
158 rts_getSchedStatus (Capability *cap);
160 /* --------------------------------------------------------------------------
163 These are used by foreign export and foreign import "wrapper" stubs.
164 ----------------------------------------------------------------------- */
166 // When producing Windows DLLs the we need to know which symbols are in the
167 // local package/DLL vs external ones.
169 // Note that RtsAPI.h is also included by foreign export stubs in
170 // the base package itself.
172 #if defined(mingw32_HOST_OS) && defined(__PIC__) && !defined(COMPILING_BASE_PACKAGE)
173 __declspec(dllimport) extern StgWord base_GHCziTopHandler_runIO_closure[];
174 __declspec(dllimport) extern StgWord base_GHCziTopHandler_runNonIO_closure[];
176 extern StgWord base_GHCziTopHandler_runIO_closure[];
177 extern StgWord base_GHCziTopHandler_runNonIO_closure[];
180 #define runIO_closure base_GHCziTopHandler_runIO_closure
181 #define runNonIO_closure base_GHCziTopHandler_runNonIO_closure
183 /* ------------------------------------------------------------------------ */
189 #endif /* RTSAPI_H */