ladybird/Ports/OpenJDK/patches/0007-java.base-Update-native-modules-to-support-Serenity.patch
2023-05-05 02:19:05 +02:00

606 lines
21 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Timur Sultanov <SultanovTS@yandex.ru>
Date: Wed, 16 Feb 2022 21:06:23 +0300
Subject: [PATCH] java.base: Update native modules to support Serenity
---
.../nio/ch/SocketOptionRegistry.java.template | 21 +++++
src/java.base/share/native/libjava/io_util.h | 5 +-
src/java.base/share/native/libjli/jli_util.h | 3 +
src/java.base/share/native/libzip/zip_util.c | 2 +-
.../sun/nio/fs/UnixConstants.java.template | 91 ++++++++++++++++++-
.../native/libjava/ProcessHandleImpl_unix.c | 2 +-
.../unix/native/libjava/TimeZone_md.c | 4 +-
.../unix/native/libjava/io_util_md.c | 2 +-
.../unix/native/libjava/io_util_md.h | 6 +-
src/java.base/unix/native/libjsig/jsig.c | 4 +
.../unix/native/libnet/Inet4AddressImpl.c | 3 +
.../unix/native/libnet/Inet6AddressImpl.c | 4 +
.../unix/native/libnet/NetworkInterface.c | 11 ++-
.../unix/native/libnet/net_util_md.h | 4 +
.../unix/native/libnio/MappedMemoryUtils.c | 4 +
.../unix/native/libnio/ch/FileChannelImpl.c | 3 +
.../native/libnio/ch/FileDispatcherImpl.c | 7 +-
src/java.base/unix/native/libnio/ch/FileKey.c | 2 +-
.../unix/native/libnio/ch/NativeThread.c | 2 +-
src/java.base/unix/native/libnio/ch/Net.c | 2 +-
.../native/libnio/fs/UnixNativeDispatcher.c | 39 +++++++-
21 files changed, 205 insertions(+), 16 deletions(-)
diff --git a/src/java.base/share/classes/sun/nio/ch/SocketOptionRegistry.java.template b/src/java.base/share/classes/sun/nio/ch/SocketOptionRegistry.java.template
index 0672ced15e268cd5f07cabd91793eafe441e6fa8..55bde3569d9a429e5e24ad39e393bdb8149f956c 100644
--- a/src/java.base/share/classes/sun/nio/ch/SocketOptionRegistry.java.template
+++ b/src/java.base/share/classes/sun/nio/ch/SocketOptionRegistry.java.template
@@ -50,6 +50,24 @@
#endif
#endif
+#define SO_RCVTIMEO 0
+#define SO_SNDTIMEO 1
+#define SO_TYPE 2
+#define SO_ERROR 3
+#define SO_PEERCRED 4
+#define SO_SNDBUF 5
+#define SO_RCVBUF 6
+#define SO_DEBUG 7
+#define SO_REUSEADDR 8
+#define SO_BINDTODEVICE 9
+#define SO_KEEPALIVE 10
+#define SO_TIMESTAMP 11
+#define SO_BROADCAST 12
+#define SO_LINGER 13
+#define SO_ACCEPTCONN 14
+#define SO_DONTROUTE 15
+#define SO_OOBINLINE 16
+
/* To be able to name the Java constants the same as the C constants without
having the preprocessor rewrite those identifiers, add PREFIX_ to all
identifiers matching a C constant. The PREFIX_ is filtered out in the
@@ -125,6 +143,9 @@ class SocketOptionRegistry {
#ifdef AF_INET6
// IPPROTO_IPV6 is 41
+#ifdef SERENITY
+#define IPV6_TCLASS 1
+#endif
map.put(new RegistryKey(StandardSocketOptions.PREFIX_IP_TOS,
StandardProtocolFamily.INET6), new OptionKey(41, IPV6_TCLASS));
map.put(new RegistryKey(StandardSocketOptions.PREFIX_IP_MULTICAST_IF,
diff --git a/src/java.base/share/native/libjava/io_util.h b/src/java.base/share/native/libjava/io_util.h
index 6e960c0347fe7cf8d2d40211a9b8f744673f1a05..cbd1d087ed50ba0a74e35e7e1c1cec0ef0aa4ccf 100644
--- a/src/java.base/share/native/libjava/io_util.h
+++ b/src/java.base/share/native/libjava/io_util.h
@@ -30,11 +30,14 @@ extern jfieldID IO_fd_fdID;
extern jfieldID IO_handle_fdID;
extern jfieldID IO_append_fdID;
-#ifdef _ALLBSD_SOURCE
+#if defined(_ALLBSD_SOURCE) || defined(SERENITY)
#include <fcntl.h>
#ifndef O_SYNC
#define O_SYNC O_FSYNC
#endif
+#if defined(SERENITY)
+#define O_DSYNC O_SYNC
+#endif
#ifndef O_DSYNC
#define O_DSYNC O_FSYNC
#endif
diff --git a/src/java.base/share/native/libjli/jli_util.h b/src/java.base/share/native/libjli/jli_util.h
index 6aa26a04f77a9085f7fda850c006f503d44f9005..35cff6b4005e596cc1cd3224e87b94d634fc80a9 100644
--- a/src/java.base/share/native/libjli/jli_util.h
+++ b/src/java.base/share/native/libjli/jli_util.h
@@ -104,6 +104,9 @@ JLI_CmdToArgs(char *cmdline);
#define _LARGFILE64_SOURCE
#define JLI_Lseek lseek64
#endif
+#ifdef SERENITY
+#define JLI_Lseek lseek
+#endif
#ifdef MACOSX
#define JLI_Lseek lseek
#endif
diff --git a/src/java.base/share/native/libzip/zip_util.c b/src/java.base/share/native/libzip/zip_util.c
index fbbd9d850fcc7d4ccc7a55a22c8a5fe84affe6f9..eef30b9e4dedbe96dfd615444f10adf8b5732f16 100644
--- a/src/java.base/share/native/libzip/zip_util.c
+++ b/src/java.base/share/native/libzip/zip_util.c
@@ -46,7 +46,7 @@
#include "zip_util.h"
#include <zlib.h>
-#ifdef _ALLBSD_SOURCE
+#if defined(_ALLBSD_SOURCE) || defined(SERENITY)
#define off64_t off_t
#define mmap64 mmap
#endif
diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixConstants.java.template b/src/java.base/unix/classes/sun/nio/fs/UnixConstants.java.template
index d60283d24aafd83854c2506de5b5a88d2e13ac5f..cc953ba3a89456c70d5bf98225fdaaea6acba2ed 100644
--- a/src/java.base/unix/classes/sun/nio/fs/UnixConstants.java.template
+++ b/src/java.base/unix/classes/sun/nio/fs/UnixConstants.java.template
@@ -31,6 +31,95 @@
#include <fcntl.h>
#include <sys/stat.h>
+#ifdef SERENITY
+
+#define ESUCCESS 0
+#define EPERM 1
+#define ENOENT 2
+#define ESRCH 3
+#define EINTR 4
+#define EIO 5
+#define ENXIO 6
+#define E2BIG 7
+#define ENOEXEC 8
+#define EBADF 9
+#define ECHILD 10
+#define EAGAIN 12
+#define ENOMEM 12
+#define EACCES 13
+#define EFAULT 14
+#define ENOTBLK 15
+#define EBUSY 16
+#define EEXIST 17
+#define EXDEV 18
+#define ENODEV 19
+#define ENOTDIR 20
+#define EISDIR 21
+#define EINVAL 22
+#define ENFILE 23
+#define EMFILE 24
+#define ENOTTY 25
+#define ETXTBSY 26
+#define EFBIG 27
+#define ENOSPC 28
+#define ESPIPE 29
+#define EROFS 30
+#define EMLINK 31
+#define EPIPE 32
+#define ERANGE 33
+#define ENAMETOOLONG 34
+#define ELOOP 35
+#define EOVERFLOW 36
+#define EOPNOTSUPP 37
+#define ENOSYS 38
+#define ENOTIMPL 39
+#define EAFNOSUPPORT 40
+#define ENOTSOCK 41
+#define EADDRINUSE 42
+#define ENOTEMPTY 43
+#define EDOM 44
+#define ECONNREFUSED 45
+#define EHOSTDOWN 46
+#define EADDRNOTAVAIL 47
+#define EISCONN 48
+#define ECONNABORTED 49
+#define EALREADY 50
+#define ECONNRESET 51
+#define EDESTADDRREQ 52
+#define EHOSTUNREACH 53
+#define EILSEQ 54
+#define EMSGSIZE 55
+#define ENETDOWN 56
+#define ENETUNREACH 57
+#define ENETRESET 58
+#define ENOBUFS 59
+#define ENOLCK 60
+#define ENOMSG 61
+#define ENOPROTOOPT 62
+#define ENOTCONN 63
+#define ESHUTDOWN 64
+#define ETOOMANYREFS 65
+#define EPROTONOSUPPORT 66
+#define ESOCKTNOSUPPORT 67
+#define EDEADLK 68
+#define ETIMEDOUT 69
+#define EPROTOTYPE 70
+#define EINPROGRESS 71
+#define ENOTHREAD 72
+#define EPROTO 73
+#define ENOTSUP 74
+#define EPFNOSUPPORT 75
+#define EDQUOT 76
+#define EDIRINTOSELF 77
+#define ENOTRECOVERABLE 78
+#define ECANCELED 79
+#define EMAXERRNO 80
+
+
+#define EWOULDBLOCK EAGAIN //Serenity doesn't define it
+#define ENODATA EMAXERRNO
+#endif
+
/* To be able to name the Java constants the same as the C constants without
having the preprocessor rewrite those identifiers, add PREFIX_ to all
identifiers matching a C constant. The PREFIX_ is filtered out in the
@@ -120,7 +209,7 @@ class UnixConstants {
// fgetxattr error codes for absent attributes depend on the OS:
#ifdef _ALLBSD_SOURCE
static final int PREFIX_XATTR_NOT_FOUND = ENOATTR;
-#elif __linux__
+#elif defined(__linux__)
static final int PREFIX_XATTR_NOT_FOUND = ENODATA;
#else
// not supported (dummy values will not be used at runtime).
diff --git a/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c b/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c
index d53e88764c5892996bd7bb5a611b6cb7ebc48c2e..eddb5f169d149bb62cc9a317c691675c9cb34ecc 100644
--- a/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c
+++ b/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c
@@ -488,7 +488,7 @@ void unix_getUserInfo(JNIEnv* env, jobject jinfo, uid_t uid) {
* The following functions are common on Solaris, Linux and AIX.
*/
-#if defined (__linux__) || defined(_AIX)
+#if defined (__linux__) || defined(_AIX) || defined(SERENITY)
/*
* Returns the children of the requested pid and optionally each parent and
diff --git a/src/java.base/unix/native/libjava/TimeZone_md.c b/src/java.base/unix/native/libjava/TimeZone_md.c
index 660665392c12db9879a535f8d30a0262d4ba3b92..c4aebe381330ea77084b674acf2f7a25cef79be3 100644
--- a/src/java.base/unix/native/libjava/TimeZone_md.c
+++ b/src/java.base/unix/native/libjava/TimeZone_md.c
@@ -53,7 +53,7 @@ static char *isFileIdentical(char* buf, size_t size, char *pathname);
#define filegets fgets
#define fileclose fclose
-#if defined(_ALLBSD_SOURCE)
+#if defined(_ALLBSD_SOURCE) || defined(SERENITY)
#define stat64 stat
#define lstat64 lstat
#define fstat64 fstat
@@ -75,7 +75,7 @@ static const char popularZones[][4] = {"UTC", "GMT"};
static const char *ETC_ENVIRONMENT_FILE = "/etc/environment";
#endif
-#if defined(__linux__) || defined(MACOSX)
+#if defined(__linux__) || defined(MACOSX) || defined(SERENITY)
/*
* Returns a pointer to the zone ID portion of the given zoneinfo file
diff --git a/src/java.base/unix/native/libjava/io_util_md.c b/src/java.base/unix/native/libjava/io_util_md.c
index e207c57d49b751b03a845f6ab2f053f8bbb38b30..8afabc544caada520dc990b649895acee3b95c46 100644
--- a/src/java.base/unix/native/libjava/io_util_md.c
+++ b/src/java.base/unix/native/libjava/io_util_md.c
@@ -30,7 +30,7 @@
#include <string.h>
#include <unistd.h>
-#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
+#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(_AIX) || defined(SERENITY)
#include <sys/ioctl.h>
#endif
diff --git a/src/java.base/unix/native/libjava/io_util_md.h b/src/java.base/unix/native/libjava/io_util_md.h
index 3dccf64f41f7bc2cecada62d428514afcb94ef10..3e9e7d3b09e07866eb02f3c40e60ce090c546dda 100644
--- a/src/java.base/unix/native/libjava/io_util_md.h
+++ b/src/java.base/unix/native/libjava/io_util_md.h
@@ -66,7 +66,7 @@ FD getFD(JNIEnv *env, jobject cur, jfieldID fid);
#define IO_SetLength handleSetLength
#define IO_GetLength handleGetLength
-#ifdef _ALLBSD_SOURCE
+#if defined(_ALLBSD_SOURCE) || defined(SERENITY)
#define open64 open
#define fstat64 fstat
#define stat64 stat
@@ -77,6 +77,10 @@ FD getFD(JNIEnv *env, jobject cur, jfieldID fid);
#define IO_Lseek lseek64
#endif
+#ifdef SERENITY
+#define statvfs64 statvfs
+#endif
+
/*
* On Solaris, the handle field is unused
*/
diff --git a/src/java.base/unix/native/libjsig/jsig.c b/src/java.base/unix/native/libjsig/jsig.c
index 1108b2f9ce5a37efd0e404d2ebb4f9415730e2b0..d891aab931ba6e12c8e861db7ac04584de69104d 100644
--- a/src/java.base/unix/native/libjsig/jsig.c
+++ b/src/java.base/unix/native/libjsig/jsig.c
@@ -100,6 +100,10 @@ static sa_handler_t call_os_signal(int sig, sa_handler_t disp,
bool is_sigset) {
sa_handler_t res;
+#ifdef SERENITY
+#define RTLD_NEXT 0 //stub out RTLD_NEXT
+#endif
+
if (os_signal == NULL) {
// Deprecation warning first time through
printf(HOTSPOT_VM_DISTRO " VM warning: the use of signal() and sigset() "
diff --git a/src/java.base/unix/native/libnet/Inet4AddressImpl.c b/src/java.base/unix/native/libnet/Inet4AddressImpl.c
index b165be7cea1f60836c354772b5adfd6c5119ade4..a4cd7000329ab444bf1937c833bab8df6a33fbd7 100644
--- a/src/java.base/unix/native/libnet/Inet4AddressImpl.c
+++ b/src/java.base/unix/native/libnet/Inet4AddressImpl.c
@@ -335,6 +335,7 @@ static jboolean
ping4(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
jint timeout, jint ttl)
{
+#ifndef SERENITY
jint n, size = 60 * 1024, hlen, tmout2, seq = 1;
socklen_t len;
unsigned char sendbuf[1500], recvbuf[1500];
@@ -438,6 +439,8 @@ ping4(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
timeout -= 1000;
} while (timeout > 0);
close(fd);
+#endif
+ //FIXME implement setsockopt(IPPROTO_IP)
return JNI_FALSE;
}
diff --git a/src/java.base/unix/native/libnet/Inet6AddressImpl.c b/src/java.base/unix/native/libnet/Inet6AddressImpl.c
index 058f3d3a7e47d09e20d1851a38c0a696e8cab1fd..61460fda89f1b54d36744dac69ea5726e9fedbe3 100644
--- a/src/java.base/unix/native/libnet/Inet6AddressImpl.c
+++ b/src/java.base/unix/native/libnet/Inet6AddressImpl.c
@@ -29,7 +29,9 @@
#include <sys/time.h>
#include <sys/types.h>
#include <netinet/in.h>
+#ifndef SERENITY
#include <netinet/icmp6.h>
+#endif
#if defined(_ALLBSD_SOURCE)
#include <ifaddrs.h>
@@ -539,6 +541,7 @@ static jboolean
ping6(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
jint timeout, jint ttl)
{
+#ifndef SERENITY
jint n, size = 60 * 1024, tmout2, seq = 1;
socklen_t len;
unsigned char sendbuf[1500], recvbuf[1500];
@@ -643,6 +646,7 @@ ping6(JNIEnv *env, jint fd, SOCKETADDRESS *sa, SOCKETADDRESS *netif,
timeout -= 1000;
} while (timeout > 0);
close(fd);
+#endif
return JNI_FALSE;
}
diff --git a/src/java.base/unix/native/libnet/NetworkInterface.c b/src/java.base/unix/native/libnet/NetworkInterface.c
index 990bc1bcc5101185803c16164ee414ddd946c6f1..fdeff2bf67a34d9765f4c7c24df60d884dcc7352 100644
--- a/src/java.base/unix/native/libnet/NetworkInterface.c
+++ b/src/java.base/unix/native/libnet/NetworkInterface.c
@@ -43,6 +43,10 @@
#include <ifaddrs.h>
#endif
+#if defined(SERENITY)
+#include <ifaddrs.h>
+#endif
+
#include "net_util.h"
#include "java_net_InetAddress.h"
@@ -1351,7 +1355,7 @@ static int getMacAddress
static int getMTU(JNIEnv *env, int sock, const char *ifname) {
struct ifreq if2;
memset((char *)&if2, 0, sizeof(if2));
- strncpy(if2.ifr_name, ifname, sizeof(if2.ifr_name) - 1);
+ memcpy(if2.ifr_name, ifname, sizeof(if2.ifr_name) - 1);
if (ioctl(sock, SIOCGIFMTU, (char *)&if2) < 0) {
JNU_ThrowByNameWithMessageAndLastError
@@ -1664,7 +1668,7 @@ static int getFlags(int sock, const char *ifname, int *flags) {
#endif /* _AIX */
/** BSD **/
-#if defined(_ALLBSD_SOURCE)
+#if defined(_ALLBSD_SOURCE) || defined(SERENITY)
/*
* Opens a socket for further ioctl calls. Tries AF_INET socket first and
@@ -1803,6 +1807,7 @@ static int getMacAddress
(JNIEnv *env, const char *ifname, const struct in_addr *addr,
unsigned char *buf)
{
+#ifndef SERENITY // FIXME: define sockaddr_dl in net/if_dl.h
struct ifaddrs *ifa0, *ifa;
struct sockaddr *saddr;
int i;
@@ -1827,7 +1832,7 @@ static int getMacAddress
}
freeifaddrs(ifa0);
}
-
+#endif
return -1;
}
diff --git a/src/java.base/unix/native/libnet/net_util_md.h b/src/java.base/unix/native/libnet/net_util_md.h
index 68835987b64008df1c7e02b17d8b302fac289d22..f99b112077eb95081c2c61ae7e3cd4664520f5aa 100644
--- a/src/java.base/unix/native/libnet/net_util_md.h
+++ b/src/java.base/unix/native/libnet/net_util_md.h
@@ -30,6 +30,10 @@
#include <poll.h>
#include <sys/socket.h>
+#ifdef SERENITY
+#include <netinet/in.h>
+#endif
+
/************************************************************************
* Macros and constants
*/
diff --git a/src/java.base/unix/native/libnio/MappedMemoryUtils.c b/src/java.base/unix/native/libnio/MappedMemoryUtils.c
index e90acd2863fa1e96564456a616ea0cb65971bf4b..34787fff4b7fd1af6f38bd3330dd7d92984c9cf1 100644
--- a/src/java.base/unix/native/libnio/MappedMemoryUtils.c
+++ b/src/java.base/unix/native/libnio/MappedMemoryUtils.c
@@ -58,6 +58,7 @@ JNIEXPORT jboolean JNICALL
Java_java_nio_MappedMemoryUtils_isLoaded0(JNIEnv *env, jobject obj, jlong address,
jlong len, jlong numPages)
{
+#ifndef SERENITY
jboolean loaded = JNI_TRUE;
int result = 0;
long i = 0;
@@ -100,6 +101,9 @@ Java_java_nio_MappedMemoryUtils_isLoaded0(JNIEnv *env, jobject obj, jlong addres
}
free(vec);
return loaded;
+#else
+ return JNI_FALSE; //FIXME implement mincore() or equivalent
+#endif
}
diff --git a/src/java.base/unix/native/libnio/ch/FileChannelImpl.c b/src/java.base/unix/native/libnio/ch/FileChannelImpl.c
index 8cc753e6aa090c14623afecb47f59281eeddea88..28fa5526972b032681905fa5a9e6e716467a2423 100644
--- a/src/java.base/unix/native/libnio/ch/FileChannelImpl.c
+++ b/src/java.base/unix/native/libnio/ch/FileChannelImpl.c
@@ -39,6 +39,9 @@
#include <sys/uio.h>
#define lseek64 lseek
#define mmap64 mmap
+#elif defined(SERENITY)
+#define lseek64 lseek
+#define mmap64 mmap
#endif
#include "jni.h"
diff --git a/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c b/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c
index c0c31d6ab2cec8445aac9c85645052cbc9200034..3a4d8a632becb07c46879badfa652b93a9523c34 100644
--- a/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c
+++ b/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c
@@ -40,7 +40,7 @@
#include <sys/ioctl.h>
#endif
-#if defined(_ALLBSD_SOURCE)
+#if defined(_ALLBSD_SOURCE) || defined(SERENITY)
#define lseek64 lseek
#define stat64 stat
#define flock64 flock
@@ -54,6 +54,11 @@
#define fdatasync fsync
#endif
+#ifdef SERENITY
+#define statvfs64 statvfs
+#define fstatvfs64 fstatvfs
+#endif
+
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
diff --git a/src/java.base/unix/native/libnio/ch/FileKey.c b/src/java.base/unix/native/libnio/ch/FileKey.c
index bdb42a6324b685400fd2a6893b80f7504cea56b6..a433cdf013471f584b06dcd6592ffc4ddb525d7c 100644
--- a/src/java.base/unix/native/libnio/ch/FileKey.c
+++ b/src/java.base/unix/native/libnio/ch/FileKey.c
@@ -30,7 +30,7 @@
#include "nio_util.h"
#include "sun_nio_ch_FileKey.h"
-#ifdef _ALLBSD_SOURCE
+#if defined(_ALLBSD_SOURCE) || defined(SERENITY)
#define stat64 stat
#define fstat64 fstat
diff --git a/src/java.base/unix/native/libnio/ch/NativeThread.c b/src/java.base/unix/native/libnio/ch/NativeThread.c
index 92dcb9e569c81bb69e149279b29f074872faf185..4bf09d03b90afefb297cbe073ccb344eea953516 100644
--- a/src/java.base/unix/native/libnio/ch/NativeThread.c
+++ b/src/java.base/unix/native/libnio/ch/NativeThread.c
@@ -40,7 +40,7 @@
#elif defined(_AIX)
/* Also defined in net/aix_close.c */
#define INTERRUPT_SIGNAL (SIGRTMAX - 1)
-#elif defined(_ALLBSD_SOURCE)
+#elif defined(_ALLBSD_SOURCE) || defined(SERENITY)
/* Also defined in net/bsd_close.c */
#define INTERRUPT_SIGNAL SIGIO
#else
diff --git a/src/java.base/unix/native/libnio/ch/Net.c b/src/java.base/unix/native/libnio/ch/Net.c
index 42a07359dde3e2daa8b5dfb3b34e1184bae37d94..ca14018610dd531c5efdf46da76d79e415ca9734 100644
--- a/src/java.base/unix/native/libnio/ch/Net.c
+++ b/src/java.base/unix/native/libnio/ch/Net.c
@@ -701,7 +701,7 @@ JNIEXPORT jint JNICALL
Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, jobject fdo,
jbyteArray group, jint index, jbyteArray source)
{
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(SERENITY)
/* no IPv6 exclude-mode filtering for now */
return IOS_UNAVAILABLE;
#else
diff --git a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
index ad36e6a19b4716724b5366a9fd1b55ae4a12a5b5..f9135f951a673bcd1891d6678d658d1819c8d54b 100644
--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
@@ -57,7 +57,7 @@
#include <string.h>
#endif
-#ifdef _ALLBSD_SOURCE
+#if defined(_ALLBSD_SOURCE) || defined(SERENITY)
#include <string.h>
#define stat64 stat
@@ -1114,6 +1114,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrgid(JNIEnv* env, jclass this, jint gid
int retry;
/* initial size of buffer for group record */
+#ifndef SERENITY
buflen = (int)sysconf(_SC_GETGR_R_SIZE_MAX);
if (buflen == -1)
buflen = ENT_BUF_SIZE;
@@ -1156,6 +1157,24 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrgid(JNIEnv* env, jclass this, jint gid
} while (retry);
+#else
+ // FIXME: Not thread safe, implement getgrgid_r
+ errno = 0;
+ struct group * g = getgrgid(gid);
+ if (g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
+ if (errno == 0)
+ errno = ENOENT;
+ throwUnixException(env, errno);
+ }
+ else {
+ jsize len = strlen(g->gr_name);
+ result = (*env)->NewByteArray(env, len);
+ if (result != NULL) {
+ (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)(g->gr_name));
+ }
+ }
+#endif
+
return result;
}
@@ -1204,6 +1223,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this,
jlong nameAddress)
{
jint gid = -1;
+#ifndef SERENITY
int buflen, retry;
/* initial size of buffer for group record */
@@ -1248,6 +1268,23 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this,
free(grbuf);
} while (retry);
+#else
+ // FIXME: Not thread safe, implement getgrnam_r
+ const char* name = (const char*)jlong_to_ptr(nameAddress);
+ errno = 0;
+ struct group * g = getgrnam(name);
+ if (g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
+ /* not found or error */
+ if (errno != 0 && errno != ENOENT && errno != ESRCH &&
+ errno != EBADF && errno != EPERM)
+ {
+ throwUnixException(env, errno);
+ }
+ }
+ else {
+ gid = g->gr_gid;
+ }
+#endif
return gid;
}