-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghc_patch.diff
325 lines (312 loc) · 10.9 KB
/
ghc_patch.diff
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
--- m4/ghc_convert_os.m4 2022-07-02 20:09:36.118816883 +0200
+++ m4/ghc_convert_os.m4 2022-07-02 20:08:43.703819843 +0200
@@ -23,7 +23,7 @@
$3="openbsd"
;;
# As far as I'm aware, none of these have relevant variants
- freebsd|dragonfly|hpux|linuxaout|kfreebsdgnu|freebsd2|mingw32|darwin|nextstep2|nextstep3|sunos4|ultrix|haiku)
+ sortix|freebsd|dragonfly|hpux|linuxaout|kfreebsdgnu|freebsd2|mingw32|darwin|nextstep2|nextstep3|sunos4|ultrix|haiku)
$3="$1"
;;
msys)
--- m4/fptools_set_haskell_platform_vars.m4 2022-07-02 20:09:36.118816883 +0200
+++ m4/fptools_set_haskell_platform_vars.m4 2022-07-02 20:08:43.703819843 +0200
@@ -100,6 +100,6 @@
nto-qnx)
test -z "[$]2" || eval "[$]2=OSQNXNTO"
;;
- dragonfly|hpux|linuxaout|freebsd2|nextstep2|nextstep3|sunos4|ultrix)
+ sortix|dragonfly|hpux|linuxaout|freebsd2|nextstep2|nextstep3|sunos4|ultrix)
test -z "[$]2" || eval "[$]2=OSUnknown"
;;
--- rts/linker/Elf.c 2022-07-02 20:08:43.703819843 +0200
+++ rts/linker/Elf.c 2022-07-02 20:08:43.703819843 +0200
@@ -6,4 +6,5 @@
|| defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) \
-|| defined(openbsd_HOST_OS) || defined(gnu_HOST_OS)
+|| defined(openbsd_HOST_OS) || defined(gnu_HOST_OS) \
+|| defined(sortix_HOST_OS)
// It is essential that this is included before any <elf.h> is included. <elf.h>
@@ -32,3 +32,3 @@
-#include <link.h>
+#include <elf.h>
#include <stdlib.h>
--- compiler/GHC/Platform.hs 2022-07-02 20:08:43.703819843 +0200
+++ compiler/GHC/Platform.hs 2022-07-02 20:08:43.703819843 +0200
@@ -164,3 +164,3 @@
osElfTarget OSHurd = True
-osElfTarget OSUnknown = False
+osElfTarget OSUnknown = True
-- Defaulting to False is safe; it means don't rely on any
--- rts/LinkerInternals.h 2022-07-02 20:09:36.118816883 +0200
+++ rts/LinkerInternals.h 2022-07-02 20:08:43.703819843 +0200
@@ -25,3 +25,3 @@
|| defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) \
-|| defined(openbsd_HOST_OS) || defined(gnu_HOST_OS)
+|| defined(openbsd_HOST_OS) || defined(gnu_HOST_OS) || defined(sortix_HOST_OS)
# define OBJFORMAT_ELF
--- rts/posix/OSMem.c 2022-07-02 20:08:43.703819843 +0200
+++ rts/posix/OSMem.c 2022-07-02 20:08:43.703819843 +0200
@@ -56,3 +56,3 @@
-#if defined(hpux_HOST_OS)
+#if defined(hpux_HOST_OS) || defined(sortix_HOST_OS)
# if !defined(MAP_ANON)
@@ -439,3 +439,6 @@
}
+#elif defined (sortix_HOST_OS)
+ size_t used;
+ memstat(&used,&physMemSize);
#else
/* We'll politely assume we have a system supporting _SC_PHYS_PAGES
--- rts/posix/GetTime.c 2022-07-02 20:08:43.703819843 +0200
+++ rts/posix/GetTime.c 2022-07-02 20:08:43.703819843 +0200
@@ -83,2 +83,4 @@
}
+#elif defined (sortix_HOST_OS)
+ return getClockTime(CLOCK_THREAD_CPUTIME_ID);
#elif defined(HAVE_CLOCK_GETTIME) && \
@@ -232,3 +232,3 @@
{
-#if !defined(HAVE_GETRUSAGE) || defined(haiku_HOST_OS)
+#if !defined(HAVE_GETRUSAGE) || defined(haiku_HOST_OS) || defined(sortix_HOST_OS)
return 0;
--- rts/posix/OSThreads.c 2022-07-02 20:08:43.703819843 +0200
+++ rts/posix/OSThreads.c 2022-07-02 20:08:43.703819843 +0200
@@ -219,4 +219,4 @@
{
-#if defined(DEBUG)
+#if defined(DEBUG) && !defined(sortix_HOST_OS)
pthread_mutexattr_t attr;
{
@@ -452,4 +452,8 @@
interruptOSThread (OSThreadId id)
{
+#if defined(sortix_HOST_OS)
+ abort();
+#else
+ pthread_kill(id, SIGPIPE);
+#endif
- pthread_kill(id, SIGPIPE);
}
--- libraries/base/System/Posix/Internals.hs
+++ libraries/base/System/Posix/Internals.hs
@@ -553,9 +553,5 @@
foreign import ccall unsafe "HsBase.h link"
c_link :: CString -> CString -> IO CInt
--- capi is required at least on Android
-foreign import capi unsafe "HsBase.h mkfifo"
- c_mkfifo :: CString -> CMode -> IO CInt
-
foreign import capi unsafe "signal.h sigemptyset"
c_sigemptyset :: Ptr CSigset -> IO CInt
--- libraries/unix/System/Posix/Files/ByteString.hsc
+++ libraries/unix/System/Posix/Files/ByteString.hsc
@@ -210,5 +210,4 @@
createNamedPipe :: RawFilePath -> FileMode -> IO ()
createNamedPipe name mode = do
- withFilePath name $ \s ->
- throwErrnoPathIfMinus1_ "createNamedPipe" name (c_mkfifo s mode)
+ throwErrno "No named pipes in sortix!" >> return ()
--- libraries/base/System/Environment.hs
+++ libraries/base/System/Environment.hs
@@ -225,2 +225,3 @@
setEnv_ :: String -> String -> IO ()
+#define sortix_HOST_OS 1
#if defined(mingw32_HOST_OS)
@@ -233,2 +233,9 @@
c_SetEnvironmentVariable :: LPTSTR -> LPTSTR -> IO Bool
+#elif defined(sortix_HOST_OS)
+setEnv_ k v = do
+ ks <- getFileSystemEncoding >>= (`GHC.newCString` k)
+ vs <- getFileSystemEncoding >>= (`GHC.newCString` v)
+ throwErrnoIf_ (/= 0) "setenv" (c_setenv ks vs (fromIntegral 1))
+foreign import ccall unsafe "setenv" c_setenv :: CString -> CString -> CInt -> IO CInt
+putEnv keyvalue = throwErrno "putEnv is dangerous!" >> return ()
#else
--- libraries/base/System/Environment/Blank.hsc
+++ libraries/base/System/Environment/Blank.hsc
@@ -146,2 +146,3 @@
unsetEnv :: String -> IO ()
+#define sortix_HOST_OS
#if defined(mingw32_HOST_OS)
@@ -163,3 +163,3 @@
c_GetLastError:: IO DWORD
-#elif HAVE_UNSETENV
+#elif HAVE_UNSETENV || defined(sortix_HOST_OS)
# if !UNSETENV_RETURNS_VOID
--- libraries/unix/System/Posix/Env.hsc
+++ libraries/unix/System/Posix/Env.hsc
@@ -142,2 +142,6 @@
putEnv :: String {- ^ "key=value" -} -> IO ()
+#define sortix_HOST_OS
+#if defined(sortix_HOST_OS)
+putEnv keyvalue = return ()
+#else
putEnv keyvalue = do s <- newFilePath keyvalue
@@ -160,3 +160,4 @@
c_putenv :: CString -> IO CInt
+#endif
{- |The 'setEnv' function inserts or resets the environment variable name in
--- libraries/unix/System/Posix/Files/Common.hsc
+++ libraries/unix/System/Posix/Files/Common.hsc
@@ -75,3 +75,5 @@
toCTimeVal,
- c_utimes,
+#if !defined(sortix_HOST_OS)
+ c_utimes,
+#endif
#ifdef HAVE_LUTIMES
@@ -449,6 +451,9 @@
(sec', frac') = properFraction $ toRational t
-foreign import ccall unsafe "utimes"
- c_utimes :: CString -> Ptr CTimeVal -> IO CInt
+#if !defined(sortix_HOST_OS)
+foreign import ccall unsafe "utimes"
+ c_utimes :: CString -> Ptr CTimeVal -> IO CInt
+#endif
+
#ifdef HAVE_LUTIMES
--- libraries/unix/System/Posix/Process/Common.hsc
+++ libraries/unix/System/Posix/Process/Common.hsc
@@ -106,8 +106,12 @@
-- 'ProcessGroupID' for the current process.
-getProcessGroupID :: IO ProcessGroupID
-getProcessGroupID = c_getpgrp
-
-foreign import ccall unsafe "getpgrp"
- c_getpgrp :: IO CPid
+#if defined (sortix_HOST_OS)
+getProcessGroupID = c_getpgid 0
+#else
+getProcessGroupID :: IO ProcessGroupID
+getProcessGroupID = c_getpgrp
+
+foreign import ccall unsafe "getpgrp"
+ c_getpgrp :: IO CPid
+#endif
-- | @'getProcessGroupIDOf' pid@ calls @getpgid@ to obtain the
@@ -216,13 +216,19 @@
-- Process scheduling priority
-nice prio = do
- resetErrno
- res <- c_nice (fromIntegral prio)
- when (res == -1) $ do
- err <- getErrno
- when (err /= eOK) (throwErrno "nice")
-
-foreign import ccall unsafe "nice"
- c_nice :: CInt -> IO CInt
+#if defined(sortix_HOST_OS)
+{-# WARNING nice
+ "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_GETPID@)" #-}
+nice _ = return ()
+#else
+nice prio = do
+ resetErrno
+ res <- c_nice (fromIntegral prio)
+ when (res == -1) $ do
+ err <- getErrno
+ when (err /= eOK) (throwErrno "nice")
+
+foreign import ccall unsafe "nice"
+ c_nice :: CInt -> IO CInt
+#endif
getProcessPriority :: ProcessID -> IO Int
--- libraries/unix/System/Posix/Files.hsc
+++ libraries/unix/System/Posix/Files.hsc
@@ -215,5 +215,4 @@
createNamedPipe :: RawFilePath -> FileMode -> IO ()
createNamedPipe name mode = do
- withFilePath name $ \s ->
- throwErrnoPathIfMinus1_ "createNamedPipe" name (c_mkfifo s mode)
+ throwErrno "No named pipes in sortix!" >> return ()
--- rts/posix/Signals.c 2022-07-02 20:08:43.703819843 +0200
+++ rts/posix/Signals.c 2022-07-02 20:08:43.703819843 +0200
@@ -353,3 +353,9 @@
while (!signals_pending() && sched_state == SCHED_RUNNING) {
- pause();
+#if defined (sortix_HOST_OS)
+ sigset_t all_sigs;
+ sigfillset(&all_sigs);
+ sigsuspend(&all_sigs);
+#else
+ pause();
+#endif
}
--- hadrian/src/Settings/Flavours/Static.hs
+++ hadrian/src/Settings/Flavours/Static.hs
@@ -51,4 +51,4 @@
-}
- , builder (Ghc CompileHs) ? pure [ "-fPIC", "-static" ]
- , builder (Ghc CompileCWithGhc) ? pure [ "-fPIC", "-optc", "-static"]
+ , builder (Ghc CompileHs) ? pure [ "-static" ]
+ , builder (Ghc CompileCWithGhc) ? pure [ "-optc", "-static"]
, builder (Ghc LinkHs) ? pure [ "-optl", "-static" ]
--- rts/ProfHeap.c
+++ rts/ProfHeap.c
@@ -72,3 +72,3 @@
{
-#if !defined(mingw32_HOST_OS)
+#if !defined(mingw32_HOST_OS) && !defined(sortix_HOST_OS)
if (! prof_locale) {
@@ -86,3 +86,3 @@
{
-#if !defined(mingw32_HOST_OS)
+#if !defined(mingw32_HOST_OS) && !defined(sortix_HOST_OS)
if (prof_locale) {
@@ -101,3 +101,3 @@
setlocale(LC_NUMERIC, "C");
-#else
+#elif !defined(sortix_HOST_OS)
saved_locale = uselocale(prof_locale);
@@ -112,3 +112,3 @@
setlocale(LC_NUMERIC, saved_locale);
-#else
+#elif !defined(sortix_HOST_OS)
uselocale(saved_locale);
--- libraries/time/lib/cbits/HsTime.c 2022-07-02 20:09:36.118816883 +0200
+++ libraries/time/lib/cbits/HsTime.c 2022-07-02 20:09:36.118816883 +0200
@@ -42,2 +42,3 @@
# endif
+long timezone=0;
# if HAVE_DECL_ALTZONE
--- libraries/unix/include/HsUnix.h 2022-07-02 20:09:36.118816883 +0200
+++ libraries/unix/include/HsUnix.h 2022-07-02 20:09:36.118816883 +0200
@@ -110,3 +110,24 @@
#ifndef O_SYNC
+#ifndef O_FSYNC
+#define O_SYNC (1<<16)
+#define F_RDLCK 1
+#define F_WRLCK 2
+#define F_UNLCK 4
+#define F_GETLK_NUM F_NEXTFD_NUM+1
+#define F_SETLK_NUM F_GETLK_NUM+1
+#define F_SETLKW_NUM F_SETLK_NUM+1
+#define F_GETLK F_ENCODE_CMD(F_GETLK_NUM,F_TYPE_INT)
+#define F_SETLK F_ENCODE_CMD(F_SETLK_NUM,F_TYPE_INT)
+#define F_SETLKW F_ENCODE_CMD(F_SETLKW_NUM,F_TYPE_INT)
+#include<sys/types.h>
+struct flock{
+ short l_type; // Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
+ short l_whence; // Flag for starting offset.
+ off_t l_start; // Relative offset in bytes.
+ off_t l_len; // Size; if 0 then until EOF.
+ pid_t l_pid; // Process ID of the process holding the lock; returned with F_GETLK.
+};
+#else
+#define O_SYNC O_FSYNC
+#endif
-# define O_SYNC O_FSYNC
#endif
--- configure.ac 2022-07-02 20:09:36.118816883 +0200
+++ configure.ac 2022-07-02 20:08:43.703819843 +0200
@@ -1078,2 +1078,4 @@
use_large_address_space=no
+ elif test "$ghc_host_os" = "sortix" ; then
+ use_large_address_space=no
elif test "$ghc_host_os" = "mingw32" ; then
@@ -1106,3 +1108,3 @@
case ${TargetOS} in
- linux|linux-android|freebsd|dragonfly|netbsd|openbsd|kfreebsdgnu|gnu|solaris2)
+ sortix|linux|linux-android|freebsd|dragonfly|netbsd|openbsd|kfreebsdgnu|gnu|solaris2)
RtsLinkerUseMmap=1