1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * General utility functions used in the RTS.
7 * ---------------------------------------------------------------------------*/
9 #include "PosixSource.h"
18 /* -----------------------------------------------------------------------------
19 General message generation functions
21 All messages should go through here. We can't guarantee that
22 stdout/stderr will be available - e.g. in a Windows program there
23 is no console for generating messages, so they have to either go to
24 to the debug console, or pop up message boxes.
25 -------------------------------------------------------------------------- */
27 // Default to the stdio implementation of these hooks.
28 RtsMsgFunction *fatalInternalErrorFn = rtsFatalInternalErrorFn;
29 RtsMsgFunction *debugMsgFn = rtsDebugMsgFn;
30 RtsMsgFunction *errorMsgFn = rtsErrorMsgFn;
37 (*fatalInternalErrorFn)(s,ap);
38 stg_exit(EXIT_INTERNAL_ERROR); // just in case fatalInternalErrorFn() returns
43 vbarf(char *s, va_list ap)
45 (*fatalInternalErrorFn)(s,ap);
46 stg_exit(EXIT_INTERNAL_ERROR); // just in case fatalInternalErrorFn() returns
50 _assertFail(char *filename, unsigned int linenum)
52 barf("ASSERTION FAILED: file %s, line %u\n", filename, linenum);
56 errorBelch(char *s, ...)
65 verrorBelch(char *s, va_list ap)
71 debugBelch(char *s, ...)
80 vdebugBelch(char *s, va_list ap)
85 /* -----------------------------------------------------------------------------
86 stdio versions of the message functions
87 -------------------------------------------------------------------------- */
91 #if defined(cygwin32_TARGET_OS) || defined (mingw32_TARGET_OS)
95 PIMAGE_DOS_HEADER pDOSHeader;
96 PIMAGE_NT_HEADERS pPEHeader;
98 pDOSHeader = (PIMAGE_DOS_HEADER) GetModuleHandleA(NULL);
99 if (pDOSHeader->e_magic != IMAGE_DOS_SIGNATURE)
102 pPEHeader = (PIMAGE_NT_HEADERS) ((char *)pDOSHeader + pDOSHeader->e_lfanew);
103 if (pPEHeader->Signature != IMAGE_NT_SIGNATURE)
106 return (pPEHeader->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI);
111 rtsFatalInternalErrorFn(char *s, va_list ap)
113 #if defined(cygwin32_TARGET_OS) || defined (mingw32_TARGET_OS)
116 char title[BUFSIZE], message[BUFSIZE];
119 r = vsnprintf(title, BUFSIZE, "%s: internal error", prog_name);
120 if (r > 0 && r < BUFSIZE) {
121 strcpy(title, "internal error");
124 r = vsnprintf(message, BUFSIZE, s, ap);
125 if (r > 0 && r < BUFSIZE) {
126 MessageBox(NULL /* hWnd */,
129 MB_OK | MB_ICONERROR | MB_TASKMODAL
136 /* don't fflush(stdout); WORKAROUND bug in Linux glibc */
137 if (prog_argv != NULL && prog_name != NULL) {
138 fprintf(stderr, "%s: internal error: ", prog_name);
140 fprintf(stderr, "internal error: ");
142 vfprintf(stderr, s, ap);
143 fprintf(stderr, "\n");
144 fprintf(stderr, " Please report this as a bug to glasgow-haskell-bugs@haskell.org,\n or http://www.sourceforge.net/projects/ghc/\n");
148 stg_exit(EXIT_INTERNAL_ERROR);
152 rtsErrorMsgFn(char *s, va_list ap)
154 #if defined(cygwin32_TARGET_OS) || defined (mingw32_TARGET_OS)
160 r = vsnprintf(buf, BUFSIZE, s, ap);
161 if (r > 0 && r < BUFSIZE) {
162 MessageBox(NULL /* hWnd */,
165 MB_OK | MB_ICONERROR | MB_TASKMODAL
172 /* don't fflush(stdout); WORKAROUND bug in Linux glibc */
173 if (prog_argv != NULL && prog_name != NULL) {
174 fprintf(stderr, "%s: ", prog_name);
176 vfprintf(stderr, s, ap);
177 fprintf(stderr, "\n");
182 rtsDebugMsgFn(char *s, va_list ap)
184 #if defined(cygwin32_TARGET_OS) || defined (mingw32_TARGET_OS)
190 r = vsnprintf(buf, BUFSIZE, s, ap);
191 if (r > 0 && r < BUFSIZE) {
192 OutputDebugString(buf);
198 /* don't fflush(stdout); WORKAROUND bug in Linux glibc */
199 vfprintf(stderr, s, ap);