Newer
Older
minerva / Ports / OpenJDK / patches / 0005-hotspot-Update-non-BSD-native-modules-for-Minerva.patch
@minerva minerva on 13 Jul 10 KB Initial commit
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 Minerva

Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
---
 src/hotspot/os/posix/os_posix.cpp              | 18 +++++++++++++++++-
 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, 44 insertions(+), 8 deletions(-)

diff --git a/src/hotspot/os/posix/os_posix.cpp b/src/hotspot/os/posix/os_posix.cpp
index a5c023a5c36aee3919c9e2a9a520d718bdac1dee..ec7e1b8646b5f7d8a269f4059982ff37b57ec68b 100644
--- a/src/hotspot/os/posix/os_posix.cpp
+++ b/src/hotspot/os/posix/os_posix.cpp
@@ -66,7 +66,9 @@
 #include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
+#ifndef MINERVA
 #include <utmpx.h>
+#endif
 
 #ifdef __APPLE__
   #include <crt_externs.h>
@@ -438,6 +440,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 MINERVA
   int bootsec = -1;
   int currsec = time(NULL);
   struct utmpx* ent;
@@ -452,6 +455,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,
@@ -490,7 +496,9 @@ void os::Posix::print_rlimit_info(outputStream* st) {
 
   print_rlimit(st, ", THREADS", RLIMIT_THREADS);
 #else
+#ifndef MINERVA
   print_rlimit(st, ", NPROC", RLIMIT_NPROC);
+#endif
 #endif
 
   print_rlimit(st, ", NOFILE", RLIMIT_NOFILE);
@@ -692,7 +700,11 @@ void os::dll_unload(void *lib) {
 }
 
 jlong os::lseek(int fd, jlong offset, int whence) {
+#ifdef MINERVA
+  return (jlong) ::lseek(fd, offset, whence);
+#else
   return (jlong) BSD_ONLY(::lseek) NOT_BSD(::lseek64)(fd, offset, whence);
+#endif
 }
 
 int os::fsync(int fd) {
@@ -700,7 +712,11 @@ int os::fsync(int fd) {
 }
 
 int os::ftruncate(int fd, jlong length) {
-   return BSD_ONLY(::ftruncate) NOT_BSD(::ftruncate64)(fd, length);
+#ifdef MINERVA
+  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 9a27ddc9ae7aaa6501d2e0419f801ce91ac4db18..200d26cf98ce308a30b0cbd5a987c64b292ddc5a 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(MINERVA)
+#define JVM_HANDLE_XXX_SIGNAL JVM_handle_minerva_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 MINERVA
     { 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 MINERVA
     { 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 MINERVA
     { 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 621efe55f6f8a64c35ad18fc27da785c2b91bedc..1dcf22357bb786568eb971cc474ceecf8c31c82c 100644
--- a/src/hotspot/share/runtime/os.cpp
+++ b/src/hotspot/share/runtime/os.cpp
@@ -156,7 +156,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(MINERVA)
     UTC_to_local = -(time_struct.tm_gmtoff);
 #elif defined(_WINDOWS)
     long zone;
@@ -1530,6 +1530,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 MINERVA
   #define ALL_SHARED_ENUMS(X) \
     X(E2BIG, "Argument list too long") \
     X(EACCES, "Permission denied") \
@@ -1607,6 +1608,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 7eaaa9db984f423c184599050b94238bc0cd1b6f..50591f7070e150e0586bbb05eef00a52b29df47b 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(MINERVA)
     // 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 0e19c101da035baf13a4dd60d81bc024e4d6ac2d..afc007e7a328e05a297a278668386a4944ee1c48 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(MINERVA)
 # 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 082a3272c6faf5899002fc30d14988bde3869af4..65157b52ed0fc68f289fb529ad7e10fd4699a6b0 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 MINERVA
+#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 30cca9ee7aef6abd56a4156d4dfb7e1f191bc542..7cac45142b53c8e407e62108a4c84444fa6c1cd7 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(MINERVA)
 #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(MINERVA)
 // 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(MINERVA)
 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 04995064fe3a98489bebb3605ceadc9d02b38f95..e25c3a4296577ab796f6d750d20186a4de412381 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(MINERVA)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>