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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
|
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 3512b1e96f5820afd0d130d840e2bc591183d84f..e60f7581ff8793a26e8453cdc44e90c351c0cd50 100644
--- a/src/java.base/share/native/libjli/jli_util.h
+++ b/src/java.base/share/native/libjli/jli_util.h
@@ -108,6 +108,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 94dfc207f965204d6485f3e6154b669ac951e96e..2a6c3851aef90e0a66517efc134f168d4345439d 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 9df8be1e62c21b5d059f1354e699679c26596fa0..993e240db043f10cb41c218b3b2e909e1f78b807 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;
}
|