PackageDb: Explicitly unlock package database before closing
[ghc.git] / ghc / hschooks.c
1 /*
2 These routines customise the error messages
3 for various bits of the RTS. They are linked
4 in instead of the defaults.
5 */
6
7 #include "../rts/PosixSource.h"
8
9 /*
10 * This should be linked against Rts.h from the compiler which is compiling us.
11 * For instance, if we are compiling this file to produce the stage1 compiler,
12 * we should use Rts.h from stage0.
13 */
14 #include "Rts.h"
15
16 #include "HsFFI.h"
17
18 #include <string.h>
19 #include <stdbool.h>
20
21 #if defined(HAVE_UNISTD_H)
22 #include <unistd.h>
23 #endif
24
25 void
26 initGCStatistics(void)
27 {
28 /* Workaround for #8754: if the GC stats aren't enabled because the
29 compiler couldn't use -Bsymbolic to link the default hooks, then
30 initialize them sensibly. See Note [-Bsymbolic and hooks] in
31 Main.hs. */
32 if (RtsFlags.GcFlags.giveStats == NO_GC_STATS) {
33 RtsFlags.GcFlags.giveStats = COLLECT_GC_STATS;
34 }
35 }
36
37 void
38 defaultsHook (void)
39 {
40 // This helps particularly with large compiles, but didn't work
41 // very well with earlier GHCs because it caused large amounts of
42 // fragmentation. See rts/sm/BlockAlloc.c:allocLargeChunk().
43 RtsFlags.GcFlags.heapSizeSuggestionAuto = true;
44
45 RtsFlags.GcFlags.maxStkSize = 512*1024*1024 / sizeof(W_);
46
47 initGCStatistics();
48
49 // See #3408: the default idle GC time of 0.3s is too short on
50 // Windows where we receive console events once per second or so.
51 RtsFlags.GcFlags.idleGCDelayTime = SecondsToTime(5);
52 }
53
54 void
55 StackOverflowHook (StgWord stack_size) /* in bytes */
56 {
57 fprintf(stderr,
58 "GHC stack-space overflow: current limit is %zu bytes.\n"
59 "Use the `-K<size>' option to increase it.\n",
60 (size_t) stack_size);
61 }
62
63 int main (int argc, char *argv[])
64 {
65 RtsConfig conf = defaultRtsConfig;
66 conf.defaultsHook = defaultsHook;
67 conf.rts_opts_enabled = RtsOptsAll;
68 conf.stackOverflowHook = StackOverflowHook;
69 extern StgClosure ZCMain_main_closure;
70
71 hs_main(argc, argv, &ZCMain_main_closure, conf);
72 }