File: solaris.c

package info (click to toggle)
mlton 20100608-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 34,980 kB
  • ctags: 69,089
  • sloc: ansic: 18,421; lisp: 2,879; makefile: 1,570; sh: 1,325; pascal: 256; asm: 97
file content (102 lines) | stat: -rw-r--r-- 2,736 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "platform.h"

#include <ieeefp.h>

#include "diskBack.unix.c"
#include "float-math.c"
#include "mmap.c"
#include "mmap-protect.c"
#include "nonwin.c"
#include "sysconf.c"
#include "setenv.putenv.c"

#ifdef __sparc__
int fegetround (void) {
        int mode;

        mode = fpgetround ();
        switch (mode) {
        case FP_RN: mode = 0; break;
        case FP_RM: mode = 1; break;
        case FP_RP: mode = 2; break;
        case FP_RZ: mode = 3; break;
        default:
                die ("fegetround: invalid mode %d\n", mode);
        }
        return mode;
}

int fesetround (int mode) {
        switch (mode) {
        case 0: mode = FP_RN; break;
        case 1: mode = FP_RM; break;
        case 2: mode = FP_RP; break;
        case 3: mode = FP_RZ; break;
        default:
                die ("fesetround: invalid mode %d\n", mode);
        }
        fpsetround (mode);
        return 0;
}
#endif /* __sparc__ */

int fpclassify64 (double d) {
        fpclass_t c;

        c = fpclass (d);
        switch (c) {
        case FP_SNAN:
        case FP_QNAN:
                return FP_NAN;
        case FP_NINF:
        case FP_PINF:
                return FP_INFINITE;
        case FP_NDENORM:
        case FP_PDENORM:
                return FP_SUBNORMAL;
        case FP_NZERO:
        case FP_PZERO:
                return FP_ZERO;
        case FP_NNORM:
        case FP_PNORM:
                return FP_NORMAL;
        default:
                die ("Real_class error: invalid class %d\n", c);
        }
}

/* ------------------------------------------------- */
/*                        GC                         */
/* ------------------------------------------------- */

void GC_displayMem (void) {
        static char buffer[256];
        snprintf (buffer, cardof(buffer), "pmap %d\n", (int)(getpid ()));
        system (buffer);
}

static void catcher (__attribute__ ((unused)) int signo,
                     __attribute__ ((unused)) siginfo_t* info,
                     void* context) {
        ucontext_t* ucp = (ucontext_t*)context;
        GC_handleSigProf ((code_pointer) ucp->uc_mcontext.gregs[REG_PC]);
}

void GC_setSigProfHandler (struct sigaction *sa) {
        sa->sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO;
        sa->sa_sigaction = (void (*)(int, siginfo_t*, void*))catcher;
}

/* On Solaris 5.7, MAP_ANON causes EINVAL and mmap requires a file descriptor.
 */
void *GC_mmapAnon (void *start, size_t length) {
        static int fd = -1;

        if (-1 == fd)
                fd = open ("/dev/zero", O_RDONLY);
        return mmap (start, length, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
}

void GC_release (void *base, size_t length) {
        munmap_safe (base, length);
}