Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / platform / solaris.c
1 #include "platform.h"
2
3 #include <ieeefp.h>
4
5 #include "diskBack.unix.c"
6 #include "float-math.c"
7 #include "mmap.c"
8 #include "mmap-protect.c"
9 #include "nonwin.c"
10 #include "sysconf.c"
11 #include "setenv.putenv.c"
12
13 #ifdef __sparc__
14 int fegetround (void) {
15 int mode;
16
17 mode = fpgetround ();
18 switch (mode) {
19 case FP_RN: mode = 0; break;
20 case FP_RM: mode = 1; break;
21 case FP_RP: mode = 2; break;
22 case FP_RZ: mode = 3; break;
23 default:
24 die ("fegetround: invalid mode %d\n", mode);
25 }
26 return mode;
27 }
28
29 int fesetround (int mode) {
30 switch (mode) {
31 case 0: mode = FP_RN; break;
32 case 1: mode = FP_RM; break;
33 case 2: mode = FP_RP; break;
34 case 3: mode = FP_RZ; break;
35 default:
36 die ("fesetround: invalid mode %d\n", mode);
37 }
38 fpsetround (mode);
39 return 0;
40 }
41 #endif /* __sparc__ */
42
43 /* ------------------------------------------------- */
44 /* GC */
45 /* ------------------------------------------------- */
46
47 void GC_displayMem (void) {
48 static char buffer[256];
49 snprintf (buffer, cardof(buffer), "pmap %d\n", (int)(getpid ()));
50 system (buffer);
51 }
52
53 static void catcher (__attribute__ ((unused)) int signo,
54 __attribute__ ((unused)) siginfo_t* info,
55 void* context) {
56 ucontext_t* ucp = (ucontext_t*)context;
57 GC_handleSigProf ((code_pointer) ucp->uc_mcontext.gregs[REG_PC]);
58 }
59
60 void GC_setSigProfHandler (struct sigaction *sa) {
61 sa->sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO;
62 sa->sa_sigaction = (void (*)(int, siginfo_t*, void*))catcher;
63 }
64
65 /* On Solaris 5.7, MAP_ANON causes EINVAL and mmap requires a file descriptor.
66 */
67 void *GC_mmapAnon (void *start, size_t length) {
68 static int fd = -1;
69
70 if (-1 == fd)
71 fd = open ("/dev/zero", O_RDONLY);
72 return mmap (start, length, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
73 }
74
75 void GC_release (void *base, size_t length) {
76 munmap_safe (base, length);
77 }