#include "Schedule.h"
#include "RtsFlags.h"
-#ifdef HAVE_TIME_H
+#if defined(HAVE_TIME_H)
#include <time.h>
#endif
/* HACK: On Mac OS X 10.4 (at least), time.h doesn't declare ctime_r with
* _POSIX_C_SOURCE. If this is the case, we declare it ourselves.
*/
-#if HAVE_CTIME_R && !HAVE_DECL_CTIME_R
+#if defined(HAVE_CTIME_R) && !HAVE_DECL_CTIME_R
extern char *ctime_r(const time_t *, char *);
#endif
-#ifdef HAVE_FCNTL_H
+#if defined(HAVE_FCNTL_H)
#include <fcntl.h>
#endif
-#ifdef HAVE_GETTIMEOFDAY
+#if defined(HAVE_GETTIMEOFDAY)
#include <sys/time.h>
#endif
#include <stdarg.h>
#include <stdio.h>
-#ifdef HAVE_SIGNAL_H
+#if defined(HAVE_SIGNAL_H)
#include <signal.h>
#endif
-------------------------------------------------------------------------- */
void *
-stgMallocBytes (int n, char *msg)
+stgMallocBytes (size_t n, char *msg)
{
- char *space;
- size_t n2;
+ void *space;
- n2 = (size_t) n;
- if ((space = (char *) malloc(n2)) == NULL) {
+ if ((space = malloc(n)) == NULL) {
/* Quoting POSIX.1-2008 (which says more or less the same as ISO C99):
*
* "Upon successful completion with size not equal to 0, malloc() shall
if (n == 0) return NULL;
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
- rtsConfig.mallocFailHook((W_) n, msg); /*msg*/
+ rtsConfig.mallocFailHook((W_) n, msg);
stg_exit(EXIT_INTERNAL_ERROR);
}
+ IF_DEBUG(sanity, memset(space, 0xbb, n));
return space;
}
void *
-stgReallocBytes (void *p, int n, char *msg)
+stgReallocBytes (void *p, size_t n, char *msg)
{
- char *space;
- size_t n2;
+ void *space;
- n2 = (size_t) n;
- if ((space = (char *) realloc(p, (size_t) n2)) == NULL) {
+ if ((space = realloc(p, n)) == NULL) {
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
- rtsConfig.mallocFailHook((W_) n, msg); /*msg*/
+ rtsConfig.mallocFailHook((W_) n, msg);
stg_exit(EXIT_INTERNAL_ERROR);
}
return space;
}
void *
-stgCallocBytes (int n, int m, char *msg)
+stgCallocBytes (size_t n, size_t m, char *msg)
{
- char *space;
+ void *space;
- if ((space = (char *) calloc((size_t) n, (size_t) m)) == NULL) {
+ if ((space = calloc(n, m)) == NULL) {
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
- rtsConfig.mallocFailHook((W_) n*m, msg); /*msg*/
+ rtsConfig.mallocFailHook((W_) n*m, msg);
stg_exit(EXIT_INTERNAL_ERROR);
}
return space;
}
/* -----------------------------------------------------------------------------
- Stack overflow
-
- Not sure if this belongs here.
+ Stack/heap overflow
-------------------------------------------------------------------------- */
void
-stackOverflow(StgTSO* tso)
+reportStackOverflow(StgTSO* tso)
{
rtsConfig.stackOverflowHook(tso->tot_stack_size * sizeof(W_));
}
void
-heapOverflow(void)
+reportHeapOverflow(void)
{
- if (!heap_overflow)
- {
- /* don't fflush(stdout); WORKAROUND bug in Linux glibc */
- rtsConfig.outOfHeapHook(0/*unknown request size*/,
- (W_)RtsFlags.GcFlags.maxHeapSize * BLOCK_SIZE);
-
- heap_overflow = rtsTrue;
- }
+ /* don't fflush(stdout); WORKAROUND bug in Linux glibc */
+ rtsConfig.outOfHeapHook(0/*unknown request size*/,
+ (W_)RtsFlags.GcFlags.maxHeapSize * BLOCK_SIZE);
}
/* -----------------------------------------------------------------------------
if (now == 0) {
time(&now);
-#if HAVE_CTIME_R
+#if defined(HAVE_CTIME_R)
ctime_r(&now, nowstr);
#else
strcpy(nowstr, ctime(&now));
-------------------------------------------------------------------------- */
char *
-showStgWord64(StgWord64 x, char *s, rtsBool with_commas)
+showStgWord64(StgWord64 x, char *s, bool with_commas)
{
if (with_commas) {
if (x < (StgWord64)1e3)
// Can be used as a breakpoint to set on every heap check failure.
-#ifdef DEBUG
+#if defined(DEBUG)
void
heapCheckFail( void )
{
#endif
}
-static void mkRtsInfoPair(char *key, char *val) {
+static void mkRtsInfoPair(const char *key, const char *val) {
/* XXX should check for "s, \s etc in key and val */
printf(" ,(\"%s\", \"%s\")\n", key, val);
}
#define TOSTRING2(x) #x
#define TOSTRING(x) TOSTRING2(x)
-void printRtsInfo(void) {
+void printRtsInfo(const RtsConfig rts_config) {
/* The first entry is just a hack to make it easy to get the
* commas right */
printf(" [(\"GHC RTS\", \"YES\")\n");
mkRtsInfoPair("Word size", TOSTRING(WORD_SIZE_IN_BITS));
mkRtsInfoPair("Compiler unregisterised", GhcUnregisterised);
mkRtsInfoPair("Tables next to code", GhcEnableTablesNextToCode);
+ mkRtsInfoPair("Flag -with-rtsopts", /* See Trac #15261 */
+ rts_config.rts_opts != NULL ? rts_config.rts_opts : "");
printf(" ]\n");
}
// profiled or not. GHCi uses it (see #2197).
int rts_isProfiled(void)
{
-#ifdef PROFILING
+#if defined(PROFILING)
return 1;
#else
return 0;
// dynamically-linked or not.
int rts_isDynamic(void)
{
-#ifdef DYNAMIC
+#if defined(DYNAMIC)
return 1;
#else
return 0;
// Used for detecting a non-empty FPU stack on x86 (see #4914)
void checkFPUStack(void)
{
-#ifdef i386_HOST_ARCH
+#if defined(i386_HOST_ARCH)
static unsigned char buf[108];
asm("FSAVE %0":"=m" (buf));
}
#endif
}
-