1 /* Copyright (C) 2010,2012,2016 Matthew Fluet.
2 * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 #ifndef _MLTON_PLATFORM_H_
11 #define _MLTON_PLATFORM_H_
18 #ifndef MLton_Platform_Arch_host
19 #error MLton_Platform_Arch_host not defined
22 #ifndef MLton_Platform_OS_host
23 #error MLton_Platform_OS_host not defined
27 #error HAS_FEROUND not defined
30 #ifndef HAS_MSG_DONTWAIT
31 #error HAS_MSG_DONTWAIT not defined
35 #error HAS_REMAP not defined
38 #ifndef HAS_SIGALTSTACK
39 #error HAS_SIGALTSTACK not defined
41 #ifndef NEEDS_SIGALTSTACK_EXEC
42 #error NEEDS_SIGALTSTACK_EXEC not defined
47 #error HAS_SPAWN not defined
50 #ifndef HAS_TIME_PROFILING
51 #error HAS_TIME_PROFILING not defined
63 #define FE_NOSUPPORT -1
65 /* With HAS_FEROUND unset, the runtime will provide the implementation.
66 * That implementation depends on FE_* having the values we set below.
67 * We must therefore make sure to eliminate any existing #defines and
68 * then create our own defines, which will also take precedence over
69 * any enums we included from system headers.
85 #define FE_TONEAREST 0
88 #define FE_TOWARDZERO 3
91 #ifndef MLTON_CODEGEN_STATIC_INLINE
92 #define MLTON_CODEGEN_STATIC_INLINE PRIVATE
94 #ifndef MLTON_CODEGEN_MATHFN
95 #define MLTON_CODEGEN_MATHFN(decl)
97 #ifndef MLTON_CODEGEN_WORDSQUOTREM
98 #define MLTON_CODEGEN_WORDSQUOTREM(func) func
100 #ifndef MLTON_CODEGEN_WORDSQUOTREM_IMPL
101 #define MLTON_CODEGEN_WORDSQUOTREM_IMPL(func) func
103 #include "basis-ffi.h"
107 /* ---------------------------------------------------------------- */
108 /* Runtime Init/Exit/Alloc */
109 /* ---------------------------------------------------------------- */
111 PRIVATE
void MLton_init (int argc
, char **argv
, GC_state s
);
112 PRIVATE
__attribute__ ((noreturn
)) void MLton_halt (GC_state s
, C_Int_t status
);
113 PRIVATE
__attribute__ ((noreturn
)) void MLton_heapCheckTooLarge (void);
115 /* ---------------------------------------------------------------- */
116 /* Utility libraries */
117 /* ---------------------------------------------------------------- */
119 /* ---------------------------------------------------------------- */
120 /* Garbage Collector */
121 /* ---------------------------------------------------------------- */
123 /* ------------------------------------------------- */
125 /* ------------------------------------------------- */
127 /* GC_displayMem displays the virtual memory mapping to stdout.
128 * It is used to diagnose memory problems.
130 PRIVATE
void GC_displayMem (void);
132 PRIVATE
void *GC_mmapAnon (void *start
, size_t length
);
133 PRIVATE
void *GC_mmapAnon_safe (void *start
, size_t length
);
134 PRIVATE
void *GC_mmapAnon_safe_protect (void *start
, size_t length
, int prot
,
135 size_t dead_low
, size_t dead_high
);
136 PRIVATE
void *GC_mremap (void *start
, size_t oldLength
, size_t newLength
);
137 PRIVATE
void GC_release (void *base
, size_t length
);
139 PRIVATE
size_t GC_pageSize (void);
140 PRIVATE
uintmax_t GC_physMem (void);
142 PRIVATE
void GC_setCygwinUseMmap (bool b
);
144 PRIVATE
void GC_diskBack_close (void *data
);
145 PRIVATE
void GC_diskBack_read (void *data
, pointer buf
, size_t size
);
146 PRIVATE
void *GC_diskBack_write (pointer buf
, size_t size
);
148 /* ------------------------------------------------- */
149 /* SigProf Handler */
150 /* ------------------------------------------------- */
152 PRIVATE
void GC_setSigProfHandler (struct sigaction
*sa
);
154 /* ---------------------------------------------------------------- */
155 /* MLton libraries */
156 /* ---------------------------------------------------------------- */
158 /* ------------------------------------------------- */
160 /* ------------------------------------------------- */
162 /* ---------------------------------- */
164 /* ---------------------------------- */
166 #define MLton_Platform_Arch_bigendian isBigEndian()
168 PRIVATE
extern Bool MLton_Platform_CygwinUseMmap
;
170 /* ------------------------------------------------- */
172 /* ------------------------------------------------- */
174 #if (defined (__MSVCRT__))
175 PRIVATE
void MLton_initSockets (void);
176 PRIVATE
void MLton_fixSocketErrno (void);
178 static inline void MLton_initSockets (void) {}
179 static inline void MLton_fixSocketErrno (void) {}
183 #define MLton_recv recv
184 #define MLton_recvfrom recvfrom
186 /* Platform has no MSG_DONTWAIT flag for recv(), so these must be
187 defined to simulate that flag. */
188 PRIVATE
int MLton_recv(int s
, void *buf
, int len
, int flags
);
189 PRIVATE
int MLton_recvfrom(int s
, void *buf
, int len
, int flags
, void *from
, socklen_t
*fromlen
);
192 #endif /* _MLTON_PLATFORM_H_ */