summaryrefslogtreecommitdiff
path: root/Ports/OpenJDK/patches/0005-hotspot-Update-non-BSD-native-modules-for-Serenity.patch
blob: 420eff12824485bbfc282db0c9c19e2b4a941aab (plain)
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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Timur Sultanov <sultanovts@yandex.ru>
Date: Sun, 12 Jun 2022 13:55:07 -0600
Subject: [PATCH] hotspot: Update non-BSD native modules for Serenity

Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
---
 src/hotspot/os/posix/os_posix.cpp             | 23 ++++++++++++++++++-
 src/hotspot/os/posix/signals_posix.cpp        | 12 ++++++++++
 src/hotspot/share/runtime/os.cpp              |  6 ++++-
 src/hotspot/share/runtime/os.hpp              |  2 +-
 src/hotspot/share/runtime/semaphore.hpp       |  2 +-
 .../share/utilities/globalDefinitions.hpp     |  4 ++++
 .../share/utilities/globalDefinitions_gcc.hpp |  6 ++---
 src/hotspot/share/utilities/ostream.cpp       |  2 +-
 8 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/src/hotspot/os/posix/os_posix.cpp b/src/hotspot/os/posix/os_posix.cpp
index 9eb1fcbcc..0676cb83d 100644
--- a/src/hotspot/os/posix/os_posix.cpp
+++ b/src/hotspot/os/posix/os_posix.cpp
@@ -65,7 +65,9 @@
 #include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
+#ifndef SERENITY
 #include <utmpx.h>
+#endif
 
 #ifdef __APPLE__
   #include <crt_externs.h>
@@ -272,7 +274,12 @@ static int util_posix_fallocate(int fd, off_t offset, off_t len) {
   }
   return -1;
 #else
+#ifndef SERENITY
   return posix_fallocate(fd, offset, len);
+#else
+  // YOLO
+  return 0;
+#endif
 #endif
 }
 
@@ -418,6 +425,7 @@ void os::Posix::print_load_average(outputStream* st) {
 // unfortunately it does not work on macOS and Linux because the utx chain has no entry
 // for reboot at least on my test machines
 void os::Posix::print_uptime_info(outputStream* st) {
+#ifndef SERENITY
   int bootsec = -1;
   int currsec = time(NULL);
   struct utmpx* ent;
@@ -432,6 +440,9 @@ void os::Posix::print_uptime_info(outputStream* st) {
   if (bootsec != -1) {
     os::print_dhm(st, "OS uptime:", (long) (currsec-bootsec));
   }
+#else
+    st->print("OS uptime: not implemented");
+#endif
 }
 
 static void print_rlimit(outputStream* st, const char* msg,
@@ -470,7 +481,9 @@ void os::Posix::print_rlimit_info(outputStream* st) {
 
   print_rlimit(st, ", THREADS", RLIMIT_THREADS);
 #else
+#ifndef SERENITY
   print_rlimit(st, ", NPROC", RLIMIT_NPROC);
+#endif
 #endif
 
   print_rlimit(st, ", NOFILE", RLIMIT_NOFILE);
@@ -638,7 +651,11 @@ void os::dll_unload(void *lib) {
 }
 
 jlong os::lseek(int fd, jlong offset, int whence) {
+#ifdef SERENITY
+  return (jlong) ::lseek(fd, offset, whence);
+#else
   return (jlong) BSD_ONLY(::lseek) NOT_BSD(::lseek64)(fd, offset, whence);
+#endif
 }
 
 int os::fsync(int fd) {
@@ -646,7 +663,11 @@ int os::fsync(int fd) {
 }
 
 int os::ftruncate(int fd, jlong length) {
-   return BSD_ONLY(::ftruncate) NOT_BSD(::ftruncate64)(fd, length);
+#ifdef SERENITY
+  return ::ftruncate(fd, length);
+#else
+  return BSD_ONLY(::ftruncate) NOT_BSD(::ftruncate64)(fd, length);
+#endif
 }
 
 const char* os::get_current_directory(char *buf, size_t buflen) {
diff --git a/src/hotspot/os/posix/signals_posix.cpp b/src/hotspot/os/posix/signals_posix.cpp
index 2c020a794..9f3316f5b 100644
--- a/src/hotspot/os/posix/signals_posix.cpp
+++ b/src/hotspot/os/posix/signals_posix.cpp
@@ -552,6 +552,8 @@ public:
 #define JVM_HANDLE_XXX_SIGNAL JVM_handle_aix_signal
 #elif defined(LINUX)
 #define JVM_HANDLE_XXX_SIGNAL JVM_handle_linux_signal
+#elif defined(SERENITY)
+#define JVM_HANDLE_XXX_SIGNAL JVM_handle_serenity_signal
 #else
 #error who are you?
 #endif
@@ -933,8 +935,10 @@ static bool get_signal_code_description(const siginfo_t* si, enum_sigcode_desc_t
     { SIGFPE,  FPE_FLTRES,   "FPE_FLTRES",   "Floating-point inexact result." },
     { SIGFPE,  FPE_FLTINV,   "FPE_FLTINV",   "Invalid floating-point operation." },
     { SIGFPE,  FPE_FLTSUB,   "FPE_FLTSUB",   "Subscript out of range." },
+#ifndef SERENITY
     { SIGSEGV, SEGV_MAPERR,  "SEGV_MAPERR",  "Address not mapped to object." },
     { SIGSEGV, SEGV_ACCERR,  "SEGV_ACCERR",  "Invalid permissions for mapped object." },
+#endif
 #if defined(AIX)
     // no explanation found what keyerr would be
     { SIGSEGV, SEGV_KEYERR,  "SEGV_KEYERR",  "key error" },
@@ -942,11 +946,13 @@ static bool get_signal_code_description(const siginfo_t* si, enum_sigcode_desc_t
 #if defined(IA64) && !defined(AIX)
     { SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" },
 #endif
+#ifndef SERENITY
     { SIGBUS,  BUS_ADRALN,   "BUS_ADRALN",   "Invalid address alignment." },
     { SIGBUS,  BUS_ADRERR,   "BUS_ADRERR",   "Nonexistent physical address." },
     { SIGBUS,  BUS_OBJERR,   "BUS_OBJERR",   "Object-specific hardware error." },
     { SIGTRAP, TRAP_BRKPT,   "TRAP_BRKPT",   "Process breakpoint." },
     { SIGTRAP, TRAP_TRACE,   "TRAP_TRACE",   "Process trace trap." },
+#endif
     { SIGCHLD, CLD_EXITED,   "CLD_EXITED",   "Child has exited." },
     { SIGCHLD, CLD_KILLED,   "CLD_KILLED",   "Child has terminated abnormally and did not create a core file." },
     { SIGCHLD, CLD_DUMPED,   "CLD_DUMPED",   "Child has terminated abnormally and created a core file." },
@@ -967,11 +973,17 @@ static bool get_signal_code_description(const siginfo_t* si, enum_sigcode_desc_t
   const struct {
     int code; const char* s_code; const char* s_desc;
   } t2 [] = {
+    { SIGTRAP,      "SIGTRAP",   "SIGTRAP FIXME" },
+    { SIGBUS,       "SIGBUS",   "SIGBUS FIXME" },
+    { SIGILL,       "SIGILL",   "Illegal opcode FIXME." },
+    { SIGSEGV,      "SIGSEGV",  "SIGSEGV FIXME" },
+#ifndef SERENITY
     { SI_USER,      "SI_USER",     "Signal sent by kill()." },
     { SI_QUEUE,     "SI_QUEUE",    "Signal sent by the sigqueue()." },
     { SI_TIMER,     "SI_TIMER",    "Signal generated by expiration of a timer set by timer_settime()." },
     { SI_ASYNCIO,   "SI_ASYNCIO",  "Signal generated by completion of an asynchronous I/O request." },
     { SI_MESGQ,     "SI_MESGQ",    "Signal generated by arrival of a message on an empty message queue." },
+#endif
     // Linux specific
 #ifdef SI_TKILL
     { SI_TKILL,     "SI_TKILL",    "Signal sent by tkill (pthread_kill)" },
diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp
index 9b8e667f9..4e9a5f0e6 100644
--- a/src/hotspot/share/runtime/os.cpp
+++ b/src/hotspot/share/runtime/os.cpp
@@ -155,7 +155,7 @@ char* os::iso8601_time(jlong milliseconds_since_19700101, char* buffer, size_t b
   // No offset when dealing with UTC
   time_t UTC_to_local = 0;
   if (!utc) {
-#if defined(_ALLBSD_SOURCE) || defined(_GNU_SOURCE)
+#if (defined(_ALLBSD_SOURCE) || defined(_GNU_SOURCE)) && !defined(SERENITY)
     UTC_to_local = -(time_struct.tm_gmtoff);
 #elif defined(_WINDOWS)
     long zone;
@@ -1502,6 +1502,7 @@ size_t os::page_size_for_region_unaligned(size_t region_size, size_t min_pages)
 }
 
 static const char* errno_to_string (int e, bool short_text) {
+#ifndef SERENITY
   #define ALL_SHARED_ENUMS(X) \
     X(E2BIG, "Argument list too long") \
     X(EACCES, "Permission denied") \
@@ -1579,6 +1580,9 @@ static const char* errno_to_string (int e, bool short_text) {
     X(ETXTBSY, "Text file busy") \
     X(EWOULDBLOCK, "Operation would block") \
     X(EXDEV, "Cross-device link")
+#else
+  #define ALL_SHARED_ENUMS(X) ENUMERATE_ERRNO_CODES(X)
+#endif
 
   #define DEFINE_ENTRY(e, text) { e, #e, text },
 
diff --git a/src/hotspot/share/runtime/os.hpp b/src/hotspot/share/runtime/os.hpp
index 7eaaa9db9..50591f707 100644
--- a/src/hotspot/share/runtime/os.hpp
+++ b/src/hotspot/share/runtime/os.hpp
@@ -468,7 +468,7 @@ class os: AllStatic {
   // need special-case handling of the primordial thread if it attaches
   // to the VM.
   static bool is_primordial_thread(void)
-#if defined(_WINDOWS) || defined(BSD)
+#if defined(_WINDOWS) || defined(BSD) || defined(SERENITY)
     // No way to identify the primordial thread.
     { return false; }
 #else
diff --git a/src/hotspot/share/runtime/semaphore.hpp b/src/hotspot/share/runtime/semaphore.hpp
index 0e19c101d..afc007e7a 100644
--- a/src/hotspot/share/runtime/semaphore.hpp
+++ b/src/hotspot/share/runtime/semaphore.hpp
@@ -28,7 +28,7 @@
 #include "memory/allocation.hpp"
 #include "utilities/globalDefinitions.hpp"
 
-#if defined(LINUX) || defined(AIX)
+#if defined(LINUX) || defined(AIX) || defined(SERENITY)
 # include "semaphore_posix.hpp"
 #elif defined(BSD)
 # include "semaphore_bsd.hpp"
diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp b/src/hotspot/share/utilities/globalDefinitions.hpp
index 082a3272c..65157b52e 100644
--- a/src/hotspot/share/utilities/globalDefinitions.hpp
+++ b/src/hotspot/share/utilities/globalDefinitions.hpp
@@ -1209,5 +1209,9 @@ template<typename K> bool primitive_equals(const K& k0, const K& k1) {
   return k0 == k1;
 }
 
+#ifdef SERENITY
+#define MAX2(a,b)          ((a)>(b)?(a):(b))
+#define alloca(p)              __builtin_alloca(p)
+#endif
 
 #endif // SHARE_UTILITIES_GLOBALDEFINITIONS_HPP
diff --git a/src/hotspot/share/utilities/globalDefinitions_gcc.hpp b/src/hotspot/share/utilities/globalDefinitions_gcc.hpp
index 30cca9ee7..7cac45142 100644
--- a/src/hotspot/share/utilities/globalDefinitions_gcc.hpp
+++ b/src/hotspot/share/utilities/globalDefinitions_gcc.hpp
@@ -48,7 +48,7 @@
 #include <limits.h>
 #include <errno.h>
 
-#if defined(LINUX) || defined(_ALLBSD_SOURCE)
+#if defined(LINUX) || defined(_ALLBSD_SOURCE) || defined(SERENITY)
 #include <inttypes.h>
 #include <signal.h>
 #ifndef __OpenBSD__
@@ -79,7 +79,7 @@
   #define NULL_WORD  NULL
 #endif
 
-#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
+#if !defined(LINUX) && !defined(_ALLBSD_SOURCE) && !defined(SERENITY)
 // Compiler-specific primitive types
 typedef unsigned short     uint16_t;
 #ifndef _UINT32_T
@@ -111,7 +111,7 @@ typedef uint64_t julong;
 // checking for nanness
 #if defined(__APPLE__)
 inline int g_isnan(double f) { return isnan(f); }
-#elif defined(LINUX) || defined(_ALLBSD_SOURCE)
+#elif defined(LINUX) || defined(_ALLBSD_SOURCE) || defined(SERENITY)
 inline int g_isnan(float  f) { return isnan(f); }
 inline int g_isnan(double f) { return isnan(f); }
 #else
diff --git a/src/hotspot/share/utilities/ostream.cpp b/src/hotspot/share/utilities/ostream.cpp
index 04995064f..e25c3a429 100644
--- a/src/hotspot/share/utilities/ostream.cpp
+++ b/src/hotspot/share/utilities/ostream.cpp
@@ -1065,7 +1065,7 @@ bufferedStream::~bufferedStream() {
 
 #ifndef PRODUCT
 
-#if defined(LINUX) || defined(AIX) || defined(_ALLBSD_SOURCE)
+#if defined(LINUX) || defined(AIX) || defined(_ALLBSD_SOURCE) || defined(SERENITY)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>