hschooks.c 1.93 KB
Newer Older
1 2 3 4 5 6
/*
These routines customise the error messages
for various bits of the RTS.  They are linked
in instead of the defaults.
*/

Ian Lynagh's avatar
Ian Lynagh committed
7
#include "../rts/PosixSource.h"
8 9 10 11 12 13 14

/*
 * This should be linked against Rts.h from the compiler which is compiling us.
 * For instance, if we are compiling this file to produce the stage1 compiler,
 * we should use Rts.h from stage0.
 */
#include "Rts.h"
15

16 17
#include "HsFFI.h"

18
#include <string.h>
19
#include <stdbool.h>
20

sof's avatar
sof committed
21 22 23 24
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

Austin Seipp's avatar
Austin Seipp committed
25 26 27 28 29 30 31 32 33 34 35 36
void
initGCStatistics(void)
{
  /* Workaround for #8754: if the GC stats aren't enabled because the
   compiler couldn't use -Bsymbolic to link the default hooks, then
   initialize them sensibly. See Note [-Bsymbolic and hooks] in
   Main.hs. */
  if (RtsFlags.GcFlags.giveStats == NO_GC_STATS) {
    RtsFlags.GcFlags.giveStats = COLLECT_GC_STATS;
  }
}

37 38 39
void
defaultsHook (void)
{
40 41 42 43 44
    // This helps particularly with large compiles, but didn't work
    // very well with earlier GHCs because it caused large amounts of
    // fragmentation.  See rts/sm/BlockAlloc.c:allocLargeChunk().
    RtsFlags.GcFlags.heapSizeSuggestionAuto = rtsTrue;

45
    RtsFlags.GcFlags.maxStkSize         = 512*1024*1024 / sizeof(W_);
Austin Seipp's avatar
Austin Seipp committed
46 47

    initGCStatistics();
48 49 50

    // See #3408: the default idle GC time of 0.3s is too short on
    // Windows where we receive console events once per second or so.
Simon Marlow's avatar
Simon Marlow committed
51
    RtsFlags.GcFlags.idleGCDelayTime = SecondsToTime(5);
52 53
}

54
void
55
StackOverflowHook (StgWord stack_size)    /* in bytes */
56
{
Ian Lynagh's avatar
Ian Lynagh committed
57
    fprintf(stderr, "GHC stack-space overflow: current limit is %zu bytes.\nUse the `-K<size>' option to increase it.\n", (size_t)stack_size);
58 59
}

60 61 62 63 64 65 66 67 68 69 70 71
int main (int argc, char *argv[])
{
    RtsConfig conf = defaultRtsConfig;
#if __GLASGOW_HASKELL__ >= 711
    conf.defaultsHook = defaultsHook;
    conf.rts_opts_enabled = RtsOptsAll;
    conf.stackOverflowHook = StackOverflowHook;
#endif
    extern StgClosure ZCMain_main_closure;

    hs_main(argc, argv, &ZCMain_main_closure, conf);
}