| 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. |
| 5 | * |
| 6 | * MLton is released under a BSD-style license. |
| 7 | * See the file MLton-LICENSE for details. |
| 8 | */ |
| 9 | |
| 10 | #ifndef _MLTON_PLATFORM_H_ |
| 11 | #define _MLTON_PLATFORM_H_ |
| 12 | |
| 13 | #include "cenv.h" |
| 14 | #include "util.h" |
| 15 | #include "ml-types.h" |
| 16 | #include "c-types.h" |
| 17 | |
| 18 | #ifndef MLton_Platform_Arch_host |
| 19 | #error MLton_Platform_Arch_host not defined |
| 20 | #endif |
| 21 | |
| 22 | #ifndef MLton_Platform_OS_host |
| 23 | #error MLton_Platform_OS_host not defined |
| 24 | #endif |
| 25 | |
| 26 | #ifndef HAS_FEROUND |
| 27 | #error HAS_FEROUND not defined |
| 28 | #endif |
| 29 | |
| 30 | #ifndef HAS_MSG_DONTWAIT |
| 31 | #error HAS_MSG_DONTWAIT not defined |
| 32 | #endif |
| 33 | |
| 34 | #ifndef HAS_REMAP |
| 35 | #error HAS_REMAP not defined |
| 36 | #endif |
| 37 | |
| 38 | #ifndef HAS_SIGALTSTACK |
| 39 | #error HAS_SIGALTSTACK not defined |
| 40 | #else |
| 41 | #ifndef NEEDS_SIGALTSTACK_EXEC |
| 42 | #error NEEDS_SIGALTSTACK_EXEC not defined |
| 43 | #endif |
| 44 | #endif |
| 45 | |
| 46 | #ifndef HAS_SPAWN |
| 47 | #error HAS_SPAWN not defined |
| 48 | #endif |
| 49 | |
| 50 | #ifndef HAS_TIME_PROFILING |
| 51 | #error HAS_TIME_PROFILING not defined |
| 52 | #endif |
| 53 | |
| 54 | #ifndef EXECVP |
| 55 | #define EXECVP execvp |
| 56 | #endif |
| 57 | |
| 58 | #ifndef EXECVE |
| 59 | #define EXECVE execve |
| 60 | #endif |
| 61 | |
| 62 | |
| 63 | #define FE_NOSUPPORT -1 |
| 64 | |
| 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. |
| 70 | */ |
| 71 | |
| 72 | #if not HAS_FEROUND |
| 73 | #ifdef FE_TONEAREST |
| 74 | #undef FE_TONEAREST |
| 75 | #endif |
| 76 | #ifdef FE_DOWNWARD |
| 77 | #undef FE_DOWNWARD |
| 78 | #endif |
| 79 | #ifdef FE_UPWARD |
| 80 | #undef FE_UPWARD |
| 81 | #endif |
| 82 | #ifdef FE_TOWARDZERO |
| 83 | #undef FE_TOWARDZERO |
| 84 | #endif |
| 85 | #define FE_TONEAREST 0 |
| 86 | #define FE_DOWNWARD 1 |
| 87 | #define FE_UPWARD 2 |
| 88 | #define FE_TOWARDZERO 3 |
| 89 | #endif |
| 90 | |
| 91 | #ifndef MLTON_CODEGEN_STATIC_INLINE |
| 92 | #define MLTON_CODEGEN_STATIC_INLINE PRIVATE |
| 93 | #endif |
| 94 | #ifndef MLTON_CODEGEN_MATHFN |
| 95 | #define MLTON_CODEGEN_MATHFN(decl) |
| 96 | #endif |
| 97 | #ifndef MLTON_CODEGEN_WORDSQUOTREM |
| 98 | #define MLTON_CODEGEN_WORDSQUOTREM(func) func |
| 99 | #endif |
| 100 | #ifndef MLTON_CODEGEN_WORDSQUOTREM_IMPL |
| 101 | #define MLTON_CODEGEN_WORDSQUOTREM_IMPL(func) func |
| 102 | #endif |
| 103 | #include "basis-ffi.h" |
| 104 | |
| 105 | #include "gc.h" |
| 106 | |
| 107 | /* ---------------------------------------------------------------- */ |
| 108 | /* Runtime Init/Exit/Alloc */ |
| 109 | /* ---------------------------------------------------------------- */ |
| 110 | |
| 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); |
| 114 | |
| 115 | /* ---------------------------------------------------------------- */ |
| 116 | /* Utility libraries */ |
| 117 | /* ---------------------------------------------------------------- */ |
| 118 | |
| 119 | /* ---------------------------------------------------------------- */ |
| 120 | /* Garbage Collector */ |
| 121 | /* ---------------------------------------------------------------- */ |
| 122 | |
| 123 | /* ------------------------------------------------- */ |
| 124 | /* Virtual Memory */ |
| 125 | /* ------------------------------------------------- */ |
| 126 | |
| 127 | /* GC_displayMem displays the virtual memory mapping to stdout. |
| 128 | * It is used to diagnose memory problems. |
| 129 | */ |
| 130 | PRIVATE void GC_displayMem (void); |
| 131 | |
| 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); |
| 138 | |
| 139 | PRIVATE size_t GC_pageSize (void); |
| 140 | PRIVATE uintmax_t GC_physMem (void); |
| 141 | |
| 142 | PRIVATE void GC_setCygwinUseMmap (bool b); |
| 143 | |
| 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); |
| 147 | |
| 148 | /* ------------------------------------------------- */ |
| 149 | /* SigProf Handler */ |
| 150 | /* ------------------------------------------------- */ |
| 151 | |
| 152 | PRIVATE void GC_setSigProfHandler (struct sigaction *sa); |
| 153 | |
| 154 | /* ---------------------------------------------------------------- */ |
| 155 | /* MLton libraries */ |
| 156 | /* ---------------------------------------------------------------- */ |
| 157 | |
| 158 | /* ------------------------------------------------- */ |
| 159 | /* MLton */ |
| 160 | /* ------------------------------------------------- */ |
| 161 | |
| 162 | /* ---------------------------------- */ |
| 163 | /* MLton.Platform */ |
| 164 | /* ---------------------------------- */ |
| 165 | |
| 166 | #define MLton_Platform_Arch_bigendian isBigEndian() |
| 167 | |
| 168 | PRIVATE extern Bool MLton_Platform_CygwinUseMmap; |
| 169 | |
| 170 | /* ------------------------------------------------- */ |
| 171 | /* Socket */ |
| 172 | /* ------------------------------------------------- */ |
| 173 | |
| 174 | #if (defined (__MSVCRT__)) |
| 175 | PRIVATE void MLton_initSockets (void); |
| 176 | PRIVATE void MLton_fixSocketErrno (void); |
| 177 | #else |
| 178 | static inline void MLton_initSockets (void) {} |
| 179 | static inline void MLton_fixSocketErrno (void) {} |
| 180 | #endif |
| 181 | |
| 182 | #if HAS_MSG_DONTWAIT |
| 183 | #define MLton_recv recv |
| 184 | #define MLton_recvfrom recvfrom |
| 185 | #else |
| 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); |
| 190 | #endif |
| 191 | |
| 192 | #endif /* _MLTON_PLATFORM_H_ */ |