Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / runtime / platform / darwin.c
CommitLineData
7f918cf1
CE
1#include "platform.h"
2
3#include <dlfcn.h>
4#include <stdio.h>
5
6#include "diskBack.unix.c"
7#include "mmap-protect.c"
8#include "nonwin.c"
9#include "sysctl.c"
10#include "use-mmap.c"
11
12void GC_displayMem (void) {
13 static char buffer[256];
14
15 snprintf (buffer, cardof(buffer), "/usr/bin/vmmap -w -interleaved %d\n", (int)getpid ());
16 (void)system (buffer);
17}
18
19static void catcher (__attribute__ ((unused)) int signo,
20 __attribute__ ((unused)) siginfo_t* info,
21 void* context) {
22 ucontext_t* ucp = (ucontext_t*)context;
23#if (defined(__powerpc__) || defined(__ppc__))
24#if __DARWIN_UNIX03
25 GC_handleSigProf ((code_pointer) ucp->uc_mcontext->__ss.__srr0);
26#else
27 GC_handleSigProf ((code_pointer) ucp->uc_mcontext->ss.srr0);
28#endif
29#elif (defined(__i386__))
30#if __DARWIN_UNIX03
31 GC_handleSigProf ((code_pointer) ucp->uc_mcontext->__ss.__eip);
32#else
33 GC_handleSigProf ((code_pointer) ucp->uc_mcontext->ss.eip);
34#endif
35#elif (defined(__x86_64__))
36#if __DARWIN_UNIX03
37 GC_handleSigProf ((code_pointer) ucp->uc_mcontext->__ss.__rip);
38#else
39 GC_handleSigProf ((code_pointer) ucp->uc_mcontext->ss.rip);
40#endif
41#else
42#error Unsupported darwin CPU architecture
43#endif
44}
45
46void GC_setSigProfHandler (struct sigaction *sa) {
47 sa->sa_flags = SA_ONSTACK | SA_RESTART | SA_SIGINFO;
48 sa->sa_sigaction = (void (*)(int, siginfo_t*, void*))catcher;
49}