6f7111fc766c71b4af5fe1d4b6cd7b35ceadf779
[ghc-hetmet.git] / ghc / rts / RtsUtils.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * General utility functions used in the RTS.
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef RTSUTILS_H
10 #define RTSUTILS_H
11
12 #include <stdarg.h>
13
14 /* -----------------------------------------------------------------------------
15  * Message generation
16  * -------------------------------------------------------------------------- */
17
18 /*
19  * A fatal internal error: this is for errors that probably indicate
20  * bugs in the RTS or compiler.  We normally output bug reporting
21  * instructions along with the error message.
22  */
23 extern void barf(char *s, ...) 
24    GNUC3_ATTRIBUTE(__noreturn__);
25
26 /*
27  * An error condition which is caused by and/or can be corrected by
28  * the user.
29  */
30 extern void errorBelch(char *s, ...)
31    GNUC3_ATTRIBUTE(format (printf, 1, 2));
32
33 /*
34  * A debugging message.  Debugging messages are generated either as a
35  * virtue of having DEBUG turned on, or by being explicitly selected
36  * via RTS options (eg. +RTS -Ds).
37  */
38 extern void debugBelch(char *s, ...)
39    GNUC3_ATTRIBUTE(format (printf, 1, 2));
40
41 /* Version of debugBelch() that takes parameters as a va_list */
42 extern void vdebugBelch(char *s, va_list ap);
43
44 /* Hooks for redirecting message generation: */
45
46 typedef void RtsMsgFunction(char *, va_list);
47
48 extern RtsMsgFunction *fatalInternalMsgFn;
49 extern RtsMsgFunction *debugMsgFn;
50 extern RtsMsgFunction *errorMsgFn;
51
52 /* Default stdio implementation of the message hooks: */
53
54 extern RtsMsgFunction stdioFatalInternalMsgFn;
55 extern RtsMsgFunction stdioDebugMsgFn;
56 extern RtsMsgFunction stdioErrorMsgFn;
57
58 /* -----------------------------------------------------------------------------
59  * (Checked) dynamic allocation
60  * -------------------------------------------------------------------------- */
61
62 extern void *stgMallocBytes(int n, char *msg) GNUC3_ATTRIBUTE(__malloc__);
63 extern void *stgReallocBytes(void *p, int n, char *msg);
64 extern void *stgCallocBytes(int n, int m, char *msg) GNUC3_ATTRIBUTE(__malloc__);
65 extern void stgFree(void* p);
66
67
68 /* -----------------------------------------------------------------------------
69  * Misc other utilities
70  * -------------------------------------------------------------------------- */
71
72 extern void _stgAssert (char *filename, unsigned int linenum);
73
74 extern void heapOverflow(void);
75
76 extern void setNonBlockingFd(int fd);
77 extern void resetNonBlockingFd(int fd);
78
79 extern nat stg_strlen(char *str);
80
81 char *time_str(void);
82 char *ullong_format_string(ullong, char *, rtsBool);
83
84 #ifdef PAR
85 ullong   msTime(void);
86 #endif
87
88 #ifdef DEBUG
89 extern void heapCheckFail( void );
90 #endif
91
92 extern void* __hscore_get_saved_termios(int fd);
93 extern void __hscore_set_saved_termios(int fd, void* ts);
94
95 #endif // RTSUTILS_H