8324539: Do not use LFS64 symbols in JDK libs

Reviewed-by: jwaters, erikj, mbaesken, alanb
This commit is contained in:
Magnus Ihse Bursie 2024-02-12 08:04:39 +00:00
parent efa071dd06
commit e5cb78cc88
29 changed files with 166 additions and 287 deletions

View File

@ -480,12 +480,13 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
#### OS DEFINES, these should be independent on toolchain #### OS DEFINES, these should be independent on toolchain
if test "x$OPENJDK_TARGET_OS" = xlinux; then if test "x$OPENJDK_TARGET_OS" = xlinux; then
CFLAGS_OS_DEF_JVM="-DLINUX -D_FILE_OFFSET_BITS=64" CFLAGS_OS_DEF_JVM="-DLINUX -D_FILE_OFFSET_BITS=64"
CFLAGS_OS_DEF_JDK="-D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE" CFLAGS_OS_DEF_JDK="-D_GNU_SOURCE -D_REENTRANT -D_FILE_OFFSET_BITS=64"
elif test "x$OPENJDK_TARGET_OS" = xmacosx; then elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
CFLAGS_OS_DEF_JVM="-D_ALLBSD_SOURCE -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE" CFLAGS_OS_DEF_JVM="-D_ALLBSD_SOURCE -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE"
CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT" CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
elif test "x$OPENJDK_TARGET_OS" = xaix; then elif test "x$OPENJDK_TARGET_OS" = xaix; then
CFLAGS_OS_DEF_JVM="-DAIX -D_LARGE_FILES" CFLAGS_OS_DEF_JVM="-DAIX -D_LARGE_FILES"
CFLAGS_OS_DEF_JDK="-D_LARGE_FILES"
elif test "x$OPENJDK_TARGET_OS" = xbsd; then elif test "x$OPENJDK_TARGET_OS" = xbsd; then
CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE" CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE"
elif test "x$OPENJDK_TARGET_OS" = xwindows; then elif test "x$OPENJDK_TARGET_OS" = xwindows; then
@ -543,7 +544,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
ALWAYS_DEFINES_JVM="-D_GNU_SOURCE" ALWAYS_DEFINES_JVM="-D_GNU_SOURCE"
elif test "x$TOOLCHAIN_TYPE" = xxlc; then elif test "x$TOOLCHAIN_TYPE" = xxlc; then
ALWAYS_DEFINES_JVM="-D_REENTRANT" ALWAYS_DEFINES_JVM="-D_REENTRANT"
ALWAYS_DEFINES_JDK="-D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE -DSTDC" ALWAYS_DEFINES_JDK="-D_GNU_SOURCE -D_REENTRANT -DSTDC"
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
# Access APIs for Windows 8 and above # Access APIs for Windows 8 and above
# see https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170 # see https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170

View File

@ -1,5 +1,5 @@
# #
# Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -27,10 +27,7 @@ include LibCommon.gmk
################################################################################ ################################################################################
ifeq ($(call isTargetOs, linux), true) ifeq ($(call isTargetOs, macosx), true)
SA_CFLAGS := -D_FILE_OFFSET_BITS=64
else ifeq ($(call isTargetOs, macosx), true)
SA_CFLAGS := -D_GNU_SOURCE -mno-omit-leaf-frame-pointer \ SA_CFLAGS := -D_GNU_SOURCE -mno-omit-leaf-frame-pointer \
-mstack-alignment=16 -fPIC -mstack-alignment=16 -fPIC
LIBSA_EXTRA_SRC := $(SUPPORT_OUTPUTDIR)/gensrc/jdk.hotspot.agent LIBSA_EXTRA_SRC := $(SUPPORT_OUTPUTDIR)/gensrc/jdk.hotspot.agent

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -138,13 +138,13 @@ void os_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) {
char *args = NULL; char *args = NULL;
jstring cmdexe = NULL; jstring cmdexe = NULL;
char fn[32]; char fn[32];
struct stat64 stat_buf; struct stat stat_buf;
/* /*
* Stat /proc/<pid> to get the user id * Stat /proc/<pid> to get the user id
*/ */
snprintf(fn, sizeof fn, "/proc/%d", pid); snprintf(fn, sizeof fn, "/proc/%d", pid);
if (stat64(fn, &stat_buf) == 0) { if (stat(fn, &stat_buf) == 0) {
unix_getUserInfo(env, jinfo, stat_buf.st_uid); unix_getUserInfo(env, jinfo, stat_buf.st_uid);
JNU_CHECK_EXCEPTION(env); JNU_CHECK_EXCEPTION(env);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,7 +57,7 @@ Java_sun_nio_ch_FileDispatcherImpl_transferFrom0(JNIEnv *env, jobject this,
jint srcFD = fdval(env, srcFDO); jint srcFD = fdval(env, srcFDO);
jint dstFD = fdval(env, dstFDO); jint dstFD = fdval(env, dstFDO);
off64_t offset = (off64_t)position; loff_t offset = (loff_t)position;
size_t len = (size_t)count; size_t len = (size_t)count;
jlong n = my_copy_file_range_func(srcFD, NULL, dstFD, &offset, len, 0); jlong n = my_copy_file_range_func(srcFD, NULL, dstFD, &offset, len, 0);
if (n < 0) { if (n < 0) {
@ -91,7 +91,7 @@ Java_sun_nio_ch_FileDispatcherImpl_transferTo0(JNIEnv *env, jobject this,
if (append == JNI_TRUE) if (append == JNI_TRUE)
return IOS_UNSUPPORTED_CASE; return IOS_UNSUPPORTED_CASE;
off64_t offset = (off64_t)position; loff_t offset = (loff_t)position;
jlong n; jlong n;
if (my_copy_file_range_func != NULL) { if (my_copy_file_range_func != NULL) {
size_t len = (size_t)count; size_t len = (size_t)count;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -165,7 +165,7 @@ JNIEXPORT jint JNICALL
Java_sun_nio_fs_LinuxNativeDispatcher_posix_1fadvise(JNIEnv* env, jclass this, Java_sun_nio_fs_LinuxNativeDispatcher_posix_1fadvise(JNIEnv* env, jclass this,
jint fd, jlong offset, jlong len, jint advice) jint fd, jlong offset, jlong len, jint advice)
{ {
return posix_fadvise64((int)fd, (off64_t)offset, (off64_t)len, (int)advice); return posix_fadvise((int)fd, (off_t)offset, (off_t)len, (int)advice);
} }
// Copy all bytes from src to dst, within the kernel if possible, // Copy all bytes from src to dst, within the kernel if possible,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -100,16 +100,7 @@ JLI_CmdToArgs(char *cmdline);
#define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2)) #define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2))
#define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3)) #define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3))
#define JLI_Open open #define JLI_Open open
#ifdef __linux__
#define _LARGFILE64_SOURCE
#define JLI_Lseek lseek64
#endif
#ifdef MACOSX
#define JLI_Lseek lseek #define JLI_Lseek lseek
#endif
#ifdef _AIX
#define JLI_Lseek lseek
#endif
#endif /* _WIN32 */ #endif /* _WIN32 */
/* /*

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -100,14 +100,6 @@
#include <dirent.h> #include <dirent.h>
#endif /* Unix */ #endif /* Unix */
#if defined(_AIX)
#define DIR DIR64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#endif
static int static int
exists(const char* filename) exists(const char* filename)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -46,11 +46,6 @@
#include "zip_util.h" #include "zip_util.h"
#include <zlib.h> #include <zlib.h>
#ifdef _ALLBSD_SOURCE
#define off64_t off_t
#define mmap64 mmap
#endif
/* USE_MMAP means mmap the CEN & ENDHDR part of the zip file. */ /* USE_MMAP means mmap the CEN & ENDHDR part of the zip file. */
#ifdef USE_MMAP #ifdef USE_MMAP
#include <sys/mman.h> #include <sys/mman.h>
@ -656,7 +651,7 @@ readCEN(jzfile *zip, jint knownTotal)
*/ */
zip->mlen = cenpos - offset + cenlen + endhdrlen; zip->mlen = cenpos - offset + cenlen + endhdrlen;
zip->offset = offset; zip->offset = offset;
mappedAddr = mmap64(0, zip->mlen, PROT_READ, MAP_SHARED, zip->zfd, (off64_t) offset); mappedAddr = mmap(0, zip->mlen, PROT_READ, MAP_SHARED, zip->zfd, (off_t) offset);
zip->maddr = (mappedAddr == (void*) MAP_FAILED) ? NULL : zip->maddr = (mappedAddr == (void*) MAP_FAILED) ? NULL :
(unsigned char*)mappedAddr; (unsigned char*)mappedAddr;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -49,11 +49,6 @@
#if defined(_AIX) #if defined(_AIX)
#include <sys/procfs.h> #include <sys/procfs.h>
#define DIR DIR64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#endif #endif
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -54,12 +54,6 @@ static char *isFileIdentical(char* buf, size_t size, char *pathname);
#define filegets fgets #define filegets fgets
#define fileclose fclose #define fileclose fclose
#if defined(_ALLBSD_SOURCE)
#define stat64 stat
#define lstat64 lstat
#define fstat64 fstat
#endif
#if defined(__linux__) || defined(_ALLBSD_SOURCE) #if defined(__linux__) || defined(_ALLBSD_SOURCE)
static const char *ETC_TIMEZONE_FILE = "/etc/timezone"; static const char *ETC_TIMEZONE_FILE = "/etc/timezone";
static const char *ZONEINFO_DIR = "/usr/share/zoneinfo"; static const char *ZONEINFO_DIR = "/usr/share/zoneinfo";
@ -219,12 +213,12 @@ static char *
isFileIdentical(char *buf, size_t size, char *pathname) isFileIdentical(char *buf, size_t size, char *pathname)
{ {
char *possibleMatch = NULL; char *possibleMatch = NULL;
struct stat64 statbuf; struct stat statbuf;
char *dbuf = NULL; char *dbuf = NULL;
int fd = -1; int fd = -1;
int res; int res;
RESTARTABLE(stat64(pathname, &statbuf), res); RESTARTABLE(stat(pathname, &statbuf), res);
if (res == -1) { if (res == -1) {
return NULL; return NULL;
} }
@ -264,7 +258,7 @@ isFileIdentical(char *buf, size_t size, char *pathname)
static char * static char *
getPlatformTimeZoneID() getPlatformTimeZoneID()
{ {
struct stat64 statbuf; struct stat statbuf;
char *tz = NULL; char *tz = NULL;
FILE *fp; FILE *fp;
int fd; int fd;
@ -301,7 +295,7 @@ getPlatformTimeZoneID()
/* /*
* Next, try /etc/localtime to find the zone ID. * Next, try /etc/localtime to find the zone ID.
*/ */
RESTARTABLE(lstat64(DEFAULT_ZONEINFO_FILE, &statbuf), res); RESTARTABLE(lstat(DEFAULT_ZONEINFO_FILE, &statbuf), res);
if (res == -1) { if (res == -1) {
return NULL; return NULL;
} }
@ -343,7 +337,7 @@ getPlatformTimeZoneID()
return NULL; return NULL;
} }
RESTARTABLE(fstat64(fd, &statbuf), res); RESTARTABLE(fstat(fd, &statbuf), res);
if (res == -1) { if (res == -1) {
(void) close(fd); (void) close(fd);
return NULL; return NULL;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -55,21 +55,8 @@
#if !defined(NAME_MAX) #if !defined(NAME_MAX)
#define NAME_MAX MAXNAMLEN #define NAME_MAX MAXNAMLEN
#endif #endif
#define DIR DIR64 #define statvfs statvfs64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#define stat stat64
#endif #endif
#if defined(_ALLBSD_SOURCE)
#ifndef MACOSX
#define statvfs64 statvfs
#define stat64 stat
#endif
#endif
/* -- Field IDs -- */ /* -- Field IDs -- */
static struct { static struct {
@ -117,8 +104,8 @@ Java_java_io_UnixFileSystem_canonicalize0(JNIEnv *env, jobject this,
static jboolean static jboolean
statMode(const char *path, int *mode) statMode(const char *path, int *mode)
{ {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
*mode = sb.st_mode; *mode = sb.st_mode;
return JNI_TRUE; return JNI_TRUE;
} }
@ -229,8 +216,8 @@ Java_java_io_UnixFileSystem_getLastModifiedTime0(JNIEnv *env, jobject this,
jlong rv = 0; jlong rv = 0;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
#if defined(_AIX) #if defined(_AIX)
rv = (jlong)sb.st_mtime * 1000; rv = (jlong)sb.st_mtime * 1000;
rv += (jlong)sb.st_mtime_n / 1000000; rv += (jlong)sb.st_mtime_n / 1000000;
@ -254,8 +241,8 @@ Java_java_io_UnixFileSystem_getLength0(JNIEnv *env, jobject this,
jlong rv = 0; jlong rv = 0;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
rv = sb.st_size; rv = sb.st_size;
} }
} END_PLATFORM_STRING(env, path); } END_PLATFORM_STRING(env, path);
@ -409,9 +396,9 @@ Java_java_io_UnixFileSystem_setLastModifiedTime0(JNIEnv *env, jobject this,
jboolean rv = JNI_FALSE; jboolean rv = JNI_FALSE;
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) { WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
struct timeval tv[2]; struct timeval tv[2];
/* Preserve access time */ /* Preserve access time */
@ -467,7 +454,7 @@ Java_java_io_UnixFileSystem_getSpace0(JNIEnv *env, jobject this,
#ifdef MACOSX #ifdef MACOSX
struct statfs fsstat; struct statfs fsstat;
#else #else
struct statvfs64 fsstat; struct statvfs fsstat;
int res; int res;
#endif #endif
memset(&fsstat, 0, sizeof(fsstat)); memset(&fsstat, 0, sizeof(fsstat));
@ -491,7 +478,7 @@ Java_java_io_UnixFileSystem_getSpace0(JNIEnv *env, jobject this,
} }
} }
#else #else
RESTARTABLE(statvfs64(path, &fsstat), res); RESTARTABLE(statvfs(path, &fsstat), res);
if (res == 0) { if (res == 0) {
switch(t) { switch(t) {
case java_io_FileSystem_SPACE_TOTAL: case java_io_FileSystem_SPACE_TOTAL:

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -59,11 +59,6 @@ isAsciiDigit(char c)
#if defined(_AIX) #if defined(_AIX)
/* AIX does not understand '/proc/self' - it requires the real process ID */ /* AIX does not understand '/proc/self' - it requires the real process ID */
#define FD_DIR aix_fd_dir #define FD_DIR aix_fd_dir
#define DIR DIR64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#elif defined(_ALLBSD_SOURCE) #elif defined(_ALLBSD_SOURCE)
#define FD_DIR "/dev/fd" #define FD_DIR "/dev/fd"
#else #else

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -74,13 +74,13 @@ jstring newStringPlatform(JNIEnv *env, const char* str)
FD FD
handleOpen(const char *path, int oflag, int mode) { handleOpen(const char *path, int oflag, int mode) {
FD fd; FD fd;
RESTARTABLE(open64(path, oflag, mode), fd); RESTARTABLE(open(path, oflag, mode), fd);
if (fd != -1) { if (fd != -1) {
struct stat64 buf64; struct stat buf;
int result; int result;
RESTARTABLE(fstat64(fd, &buf64), result); RESTARTABLE(fstat(fd, &buf), result);
if (result != -1) { if (result != -1) {
if (S_ISDIR(buf64.st_mode)) { if (S_ISDIR(buf.st_mode)) {
close(fd); close(fd);
errno = EISDIR; errno = EISDIR;
fd = -1; fd = -1;
@ -201,13 +201,13 @@ jint
handleAvailable(FD fd, jlong *pbytes) handleAvailable(FD fd, jlong *pbytes)
{ {
int mode; int mode;
struct stat64 buf64; struct stat buf;
jlong size = -1, current = -1; jlong size = -1, current = -1;
int result; int result;
RESTARTABLE(fstat64(fd, &buf64), result); RESTARTABLE(fstat(fd, &buf), result);
if (result != -1) { if (result != -1) {
mode = buf64.st_mode; mode = buf.st_mode;
if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
int n; int n;
int result; int result;
@ -217,18 +217,18 @@ handleAvailable(FD fd, jlong *pbytes)
return 1; return 1;
} }
} else if (S_ISREG(mode)) { } else if (S_ISREG(mode)) {
size = buf64.st_size; size = buf.st_size;
} }
} }
if ((current = lseek64(fd, 0, SEEK_CUR)) == -1) { if ((current = lseek(fd, 0, SEEK_CUR)) == -1) {
return 0; return 0;
} }
if (size < current) { if (size < current) {
if ((size = lseek64(fd, 0, SEEK_END)) == -1) if ((size = lseek(fd, 0, SEEK_END)) == -1)
return 0; return 0;
else if (lseek64(fd, current, SEEK_SET) == -1) else if (lseek(fd, current, SEEK_SET) == -1)
return 0; return 0;
} }
@ -240,16 +240,16 @@ jint
handleSetLength(FD fd, jlong length) handleSetLength(FD fd, jlong length)
{ {
int result; int result;
RESTARTABLE(ftruncate64(fd, length), result); RESTARTABLE(ftruncate(fd, length), result);
return result; return result;
} }
jlong jlong
handleGetLength(FD fd) handleGetLength(FD fd)
{ {
struct stat64 sb; struct stat sb;
int result; int result;
RESTARTABLE(fstat64(fd, &sb), result); RESTARTABLE(fstat(fd, &sb), result);
if (result < 0) { if (result < 0) {
return -1; return -1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -59,6 +59,7 @@ FD getFD(JNIEnv *env, jobject cur, jfieldID fid);
* Route the routines * Route the routines
*/ */
#define IO_Sync fsync #define IO_Sync fsync
#define IO_Lseek lseek
#define IO_Read handleRead #define IO_Read handleRead
#define IO_Write handleWrite #define IO_Write handleWrite
#define IO_Append handleWrite #define IO_Append handleWrite
@ -66,17 +67,6 @@ FD getFD(JNIEnv *env, jobject cur, jfieldID fid);
#define IO_SetLength handleSetLength #define IO_SetLength handleSetLength
#define IO_GetLength handleGetLength #define IO_GetLength handleGetLength
#ifdef _ALLBSD_SOURCE
#define open64 open
#define fstat64 fstat
#define stat64 stat
#define lseek64 lseek
#define ftruncate64 ftruncate
#define IO_Lseek lseek
#else
#define IO_Lseek lseek64
#endif
/* /*
* On Solaris, the handle field is unused * On Solaris, the handle field is unused
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,12 +30,6 @@
#include "nio_util.h" #include "nio_util.h"
#include "sun_nio_ch_FileKey.h" #include "sun_nio_ch_FileKey.h"
#ifdef _ALLBSD_SOURCE
#define stat64 stat
#define fstat64 fstat
#endif
static jfieldID key_st_dev; /* id for FileKey.st_dev */ static jfieldID key_st_dev; /* id for FileKey.st_dev */
static jfieldID key_st_ino; /* id for FileKey.st_ino */ static jfieldID key_st_ino; /* id for FileKey.st_ino */
@ -51,12 +45,12 @@ Java_sun_nio_ch_FileKey_initIDs(JNIEnv *env, jclass clazz)
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_sun_nio_ch_FileKey_init(JNIEnv *env, jobject this, jobject fdo) Java_sun_nio_ch_FileKey_init(JNIEnv *env, jobject this, jobject fdo)
{ {
struct stat64 fbuf; struct stat fbuf;
int res; int res;
RESTARTABLE(fstat64(fdval(env, fdo), &fbuf), res); RESTARTABLE(fstat(fdval(env, fdo), &fbuf), res);
if (res < 0) { if (res < 0) {
JNU_ThrowIOExceptionWithLastError(env, "fstat64 failed"); JNU_ThrowIOExceptionWithLastError(env, "fstat failed");
} else { } else {
(*env)->SetLongField(env, this, key_st_dev, (jlong)fbuf.st_dev); (*env)->SetLongField(env, this, key_st_dev, (jlong)fbuf.st_dev);
(*env)->SetLongField(env, this, key_st_ino, (jlong)fbuf.st_ino); (*env)->SetLongField(env, this, key_st_ino, (jlong)fbuf.st_ino);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,20 +29,7 @@
#include <sys/statvfs.h> #include <sys/statvfs.h>
#if defined(_ALLBSD_SOURCE) #if defined(_ALLBSD_SOURCE)
#define lseek64 lseek
#define stat64 stat
#define flock64 flock
#define off64_t off_t
#define F_SETLKW64 F_SETLKW
#define F_SETLK64 F_SETLK
#define pread64 pread
#define pwrite64 pwrite
#define ftruncate64 ftruncate
#define fstat64 fstat
#define fdatasync fsync #define fdatasync fsync
#define mmap64 mmap
#define statvfs64 statvfs
#define fstatvfs64 fstatvfs
#endif #endif
#if defined(__linux__) #if defined(__linux__)
@ -57,6 +44,11 @@
#include "java_lang_Long.h" #include "java_lang_Long.h"
#include <assert.h> #include <assert.h>
#if defined(_AIX)
#define statvfs statvfs64
#define fstatvfs fstatvfs64
#endif
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_sun_nio_ch_UnixFileDispatcherImpl_read0(JNIEnv *env, jclass clazz, Java_sun_nio_ch_UnixFileDispatcherImpl_read0(JNIEnv *env, jclass clazz,
jobject fdo, jlong address, jint len) jobject fdo, jlong address, jint len)
@ -74,7 +66,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_pread0(JNIEnv *env, jclass clazz, jobject
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address); void *buf = (void *)jlong_to_ptr(address);
return convertReturnVal(env, pread64(fd, buf, len, offset), JNI_TRUE); return convertReturnVal(env, pread(fd, buf, len, offset), JNI_TRUE);
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
@ -103,7 +95,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_pwrite0(JNIEnv *env, jclass clazz, jobjec
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
void *buf = (void *)jlong_to_ptr(address); void *buf = (void *)jlong_to_ptr(address);
return convertReturnVal(env, pwrite64(fd, buf, len, offset), JNI_FALSE); return convertReturnVal(env, pwrite(fd, buf, len, offset), JNI_FALSE);
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
@ -131,13 +123,13 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_seek0(JNIEnv *env, jclass clazz,
jobject fdo, jlong offset) jobject fdo, jlong offset)
{ {
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
off64_t result; off_t result;
if (offset < 0) { if (offset < 0) {
result = lseek64(fd, 0, SEEK_CUR); result = lseek(fd, 0, SEEK_CUR);
} else { } else {
result = lseek64(fd, offset, SEEK_SET); result = lseek(fd, offset, SEEK_SET);
} }
return handle(env, (jlong)result, "lseek64 failed"); return handle(env, (jlong)result, "lseek failed");
} }
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
@ -161,7 +153,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_truncate0(JNIEnv *env, jobject this,
jobject fdo, jlong size) jobject fdo, jlong size)
{ {
return handle(env, return handle(env,
ftruncate64(fdval(env, fdo), size), ftruncate(fdval(env, fdo), size),
"Truncation failed"); "Truncation failed");
} }
@ -169,9 +161,9 @@ JNIEXPORT jlong JNICALL
Java_sun_nio_ch_UnixFileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject fdo) Java_sun_nio_ch_UnixFileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject fdo)
{ {
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
struct stat64 fbuf; struct stat fbuf;
if (fstat64(fd, &fbuf) < 0) if (fstat(fd, &fbuf) < 0)
return handle(env, -1, "Size failed"); return handle(env, -1, "Size failed");
#if defined(__linux__) #if defined(__linux__)
@ -194,28 +186,28 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_lock0(JNIEnv *env, jobject this, jobject
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
jint lockResult = 0; jint lockResult = 0;
int cmd = 0; int cmd = 0;
struct flock64 fl; struct flock fl;
fl.l_whence = SEEK_SET; fl.l_whence = SEEK_SET;
if (size == (jlong)java_lang_Long_MAX_VALUE) { if (size == (jlong)java_lang_Long_MAX_VALUE) {
fl.l_len = (off64_t)0; fl.l_len = (off_t)0;
} else { } else {
fl.l_len = (off64_t)size; fl.l_len = (off_t)size;
} }
fl.l_start = (off64_t)pos; fl.l_start = (off_t)pos;
if (shared == JNI_TRUE) { if (shared == JNI_TRUE) {
fl.l_type = F_RDLCK; fl.l_type = F_RDLCK;
} else { } else {
fl.l_type = F_WRLCK; fl.l_type = F_WRLCK;
} }
if (block == JNI_TRUE) { if (block == JNI_TRUE) {
cmd = F_SETLKW64; cmd = F_SETLKW;
} else { } else {
cmd = F_SETLK64; cmd = F_SETLK;
} }
lockResult = fcntl(fd, cmd, &fl); lockResult = fcntl(fd, cmd, &fl);
if (lockResult < 0) { if (lockResult < 0) {
if ((cmd == F_SETLK64) && (errno == EAGAIN || errno == EACCES)) if ((cmd == F_SETLK) && (errno == EAGAIN || errno == EACCES))
return sun_nio_ch_UnixFileDispatcherImpl_NO_LOCK; return sun_nio_ch_UnixFileDispatcherImpl_NO_LOCK;
if (errno == EINTR) if (errno == EINTR)
return sun_nio_ch_UnixFileDispatcherImpl_INTERRUPTED; return sun_nio_ch_UnixFileDispatcherImpl_INTERRUPTED;
@ -230,16 +222,16 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_release0(JNIEnv *env, jobject this,
{ {
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
jint lockResult = 0; jint lockResult = 0;
struct flock64 fl; struct flock fl;
int cmd = F_SETLK64; int cmd = F_SETLK;
fl.l_whence = SEEK_SET; fl.l_whence = SEEK_SET;
if (size == (jlong)java_lang_Long_MAX_VALUE) { if (size == (jlong)java_lang_Long_MAX_VALUE) {
fl.l_len = (off64_t)0; fl.l_len = (off_t)0;
} else { } else {
fl.l_len = (off64_t)size; fl.l_len = (off_t)size;
} }
fl.l_start = (off64_t)pos; fl.l_start = (off_t)pos;
fl.l_type = F_UNLCK; fl.l_type = F_UNLCK;
lockResult = fcntl(fd, cmd, &fl); lockResult = fcntl(fd, cmd, &fl);
if (lockResult < 0) { if (lockResult < 0) {
@ -319,7 +311,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_map0(JNIEnv *env, jclass klass, jobject f
#endif #endif
} }
mapAddress = mmap64( mapAddress = mmap(
0, /* Let OS decide location */ 0, /* Let OS decide location */
len, /* Number of bytes to map */ len, /* Number of bytes to map */
protections, /* File permissions */ protections, /* File permissions */
@ -359,7 +351,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_setDirect0(JNIEnv *env, jclass clazz,
{ {
jint fd = fdval(env, fdo); jint fd = fdval(env, fdo);
jint result; jint result;
struct statvfs64 file_stat; struct statvfs file_stat;
#if defined(O_DIRECT) || defined(F_NOCACHE) || defined(DIRECTIO_ON) #if defined(O_DIRECT) || defined(F_NOCACHE) || defined(DIRECTIO_ON)
#ifdef O_DIRECT #ifdef O_DIRECT
@ -387,7 +379,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_setDirect0(JNIEnv *env, jclass clazz,
return result; return result;
} }
#endif #endif
result = fstatvfs64(fd, &file_stat); result = fstatvfs(fd, &file_stat);
if(result == -1) { if(result == -1) {
JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed");
return result; return result;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <limits.h> #include <limits.h>
#include <fcntl.h> #include <fcntl.h>
#include <dirent.h> #include <dirent.h>
@ -54,22 +55,8 @@
#include <sys/sysmacros.h> // makedev macros #include <sys/sysmacros.h> // makedev macros
#endif #endif
#if defined(__linux__) || defined(_AIX) #if defined(_AIX)
#include <string.h> #define statvfs statvfs64
#endif
#ifdef _ALLBSD_SOURCE
#include <string.h>
#define stat64 stat
#ifndef MACOSX
#define statvfs64 statvfs
#endif
#define open64 open
#define fstat64 fstat
#define lstat64 lstat
#define readdir64 readdir
#endif #endif
#if defined(__linux__) #if defined(__linux__)
@ -170,14 +157,6 @@ struct my_statx
#include "sun_nio_fs_UnixNativeDispatcher.h" #include "sun_nio_fs_UnixNativeDispatcher.h"
#if defined(_AIX)
#define DIR DIR64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#endif
/** /**
* Size of password or group entry when not available via sysconf * Size of password or group entry when not available via sysconf
*/ */
@ -231,8 +210,8 @@ static jfieldID entry_dev;
/** /**
* System calls that may not be available at run time. * System calls that may not be available at run time.
*/ */
typedef int openat64_func(int, const char *, int, ...); typedef int openat_func(int, const char *, int, ...);
typedef int fstatat64_func(int, const char *, struct stat64 *, int); typedef int fstatat_func(int, const char *, struct stat *, int);
typedef int unlinkat_func(int, const char*, int); typedef int unlinkat_func(int, const char*, int);
typedef int renameat_func(int, const char*, int, const char*); typedef int renameat_func(int, const char*, int, const char*);
typedef int futimesat_func(int, const char *, const struct timeval *); typedef int futimesat_func(int, const char *, const struct timeval *);
@ -244,8 +223,8 @@ typedef int statx_func(int dirfd, const char *restrict pathname, int flags,
unsigned int mask, struct my_statx *restrict statxbuf); unsigned int mask, struct my_statx *restrict statxbuf);
#endif #endif
static openat64_func* my_openat64_func = NULL; static openat_func* my_openat_func = NULL;
static fstatat64_func* my_fstatat64_func = NULL; static fstatat_func* my_fstatat_func = NULL;
static unlinkat_func* my_unlinkat_func = NULL; static unlinkat_func* my_unlinkat_func = NULL;
static renameat_func* my_renameat_func = NULL; static renameat_func* my_renameat_func = NULL;
static futimesat_func* my_futimesat_func = NULL; static futimesat_func* my_futimesat_func = NULL;
@ -261,8 +240,8 @@ static statx_func* my_statx_func = NULL;
*/ */
#if defined(__linux__) && (defined(__i386) || defined(__arm__)) #if defined(__linux__) && (defined(__i386) || defined(__arm__))
#define FSTATAT64_SYSCALL_AVAILABLE #define FSTATAT64_SYSCALL_AVAILABLE
static int fstatat64_wrapper(int dfd, const char *path, static int fstatat_wrapper(int dfd, const char *path,
struct stat64 *statbuf, int flag) struct stat *statbuf, int flag)
{ {
#ifndef __NR_fstatat64 #ifndef __NR_fstatat64
#define __NR_fstatat64 300 #define __NR_fstatat64 300
@ -273,8 +252,8 @@ static int fstatat64_wrapper(int dfd, const char *path,
#if defined(__linux__) && defined(_LP64) && defined(__NR_newfstatat) #if defined(__linux__) && defined(_LP64) && defined(__NR_newfstatat)
#define FSTATAT64_SYSCALL_AVAILABLE #define FSTATAT64_SYSCALL_AVAILABLE
static int fstatat64_wrapper(int dfd, const char *path, static int fstatat_wrapper(int dfd, const char *path,
struct stat64 *statbuf, int flag) struct stat *statbuf, int flag)
{ {
return syscall(__NR_newfstatat, dfd, path, statbuf, flag); return syscall(__NR_newfstatat, dfd, path, statbuf, flag);
} }
@ -375,11 +354,12 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
/* system calls that might not be available at run time */ /* system calls that might not be available at run time */
#if defined(_ALLBSD_SOURCE) #if defined(_ALLBSD_SOURCE)
my_openat64_func = (openat64_func*)dlsym(RTLD_DEFAULT, "openat"); my_openat_func = (openat_func*)dlsym(RTLD_DEFAULT, "openat");
my_fstatat64_func = (fstatat64_func*)dlsym(RTLD_DEFAULT, "fstatat"); my_fstatat_func = (fstatat_func*)dlsym(RTLD_DEFAULT, "fstatat");
#else #else
my_openat64_func = (openat64_func*) dlsym(RTLD_DEFAULT, "openat64"); // Make sure we link to the 64-bit version of the functions
my_fstatat64_func = (fstatat64_func*) dlsym(RTLD_DEFAULT, "fstatat64"); my_openat_func = (openat_func*) dlsym(RTLD_DEFAULT, "openat64");
my_fstatat_func = (fstatat_func*) dlsym(RTLD_DEFAULT, "fstatat64");
#endif #endif
my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat"); my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat");
my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat"); my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat");
@ -389,6 +369,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
#endif #endif
my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens"); my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens");
#if defined(_AIX) #if defined(_AIX)
// Make sure we link to the 64-bit version of the function
my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64"); my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64");
#else #else
my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir"); my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir");
@ -396,8 +377,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
#if defined(FSTATAT64_SYSCALL_AVAILABLE) #if defined(FSTATAT64_SYSCALL_AVAILABLE)
/* fstatat64 missing from glibc */ /* fstatat64 missing from glibc */
if (my_fstatat64_func == NULL) if (my_fstatat_func == NULL)
my_fstatat64_func = (fstatat64_func*)&fstatat64_wrapper; my_fstatat_func = (fstatat_func*)&fstatat_wrapper;
#endif #endif
/* supports futimes or futimesat, futimens, and/or lutimes */ /* supports futimes or futimesat, futimens, and/or lutimes */
@ -416,7 +397,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
/* supports openat, etc. */ /* supports openat, etc. */
if (my_openat64_func != NULL && my_fstatat64_func != NULL && if (my_openat_func != NULL && my_fstatat_func != NULL &&
my_unlinkat_func != NULL && my_renameat_func != NULL && my_unlinkat_func != NULL && my_renameat_func != NULL &&
my_futimesat_func != NULL && my_fdopendir_func != NULL) my_futimesat_func != NULL && my_fdopendir_func != NULL)
{ {
@ -543,7 +524,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_open0(JNIEnv* env, jclass this,
jint fd; jint fd;
const char* path = (const char*)jlong_to_ptr(pathAddress); const char* path = (const char*)jlong_to_ptr(pathAddress);
RESTARTABLE(open64(path, (int)oflags, (mode_t)mode), fd); RESTARTABLE(open(path, (int)oflags, (mode_t)mode), fd);
if (fd == -1) { if (fd == -1) {
throwUnixException(env, errno); throwUnixException(env, errno);
} }
@ -557,12 +538,12 @@ Java_sun_nio_fs_UnixNativeDispatcher_openat0(JNIEnv* env, jclass this, jint dfd,
jint fd; jint fd;
const char* path = (const char*)jlong_to_ptr(pathAddress); const char* path = (const char*)jlong_to_ptr(pathAddress);
if (my_openat64_func == NULL) { if (my_openat_func == NULL) {
JNU_ThrowInternalError(env, "should not reach here"); JNU_ThrowInternalError(env, "should not reach here");
return -1; return -1;
} }
RESTARTABLE((*my_openat64_func)(dfd, path, (int)oflags, (mode_t)mode), fd); RESTARTABLE((*my_openat_func)(dfd, path, (int)oflags, (mode_t)mode), fd);
if (fd == -1) { if (fd == -1) {
throwUnixException(env, errno); throwUnixException(env, errno);
} }
@ -638,9 +619,9 @@ static void copy_statx_attributes(JNIEnv* env, struct my_statx* buf, jobject att
#endif #endif
/** /**
* Copy stat64 members into sun.nio.fs.UnixFileAttributes * Copy stat members into sun.nio.fs.UnixFileAttributes
*/ */
static void copy_stat64_attributes(JNIEnv* env, struct stat64* buf, jobject attrs) { static void copy_stat_attributes(JNIEnv* env, struct stat* buf, jobject attrs) {
(*env)->SetIntField(env, attrs, attrs_st_mode, (jint)buf->st_mode); (*env)->SetIntField(env, attrs, attrs_st_mode, (jint)buf->st_mode);
(*env)->SetLongField(env, attrs, attrs_st_ino, (jlong)buf->st_ino); (*env)->SetLongField(env, attrs, attrs_st_ino, (jlong)buf->st_ino);
(*env)->SetLongField(env, attrs, attrs_st_dev, (jlong)buf->st_dev); (*env)->SetLongField(env, attrs, attrs_st_dev, (jlong)buf->st_dev);
@ -674,7 +655,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_stat0(JNIEnv* env, jclass this,
jlong pathAddress, jobject attrs) jlong pathAddress, jobject attrs)
{ {
int err; int err;
struct stat64 buf; struct stat buf;
const char* path = (const char*)jlong_to_ptr(pathAddress); const char* path = (const char*)jlong_to_ptr(pathAddress);
#if defined(__linux__) #if defined(__linux__)
struct my_statx statx_buf; struct my_statx statx_buf;
@ -682,7 +663,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_stat0(JNIEnv* env, jclass this,
unsigned int mask = STATX_ALL; unsigned int mask = STATX_ALL;
if (my_statx_func != NULL) { if (my_statx_func != NULL) {
// Prefer statx over stat64 on Linux if it's available // Prefer statx over stat on Linux if it's available
RESTARTABLE(statx_wrapper(AT_FDCWD, path, flags, mask, &statx_buf), err); RESTARTABLE(statx_wrapper(AT_FDCWD, path, flags, mask, &statx_buf), err);
if (err == 0) { if (err == 0) {
copy_statx_attributes(env, &statx_buf, attrs); copy_statx_attributes(env, &statx_buf, attrs);
@ -692,9 +673,9 @@ Java_sun_nio_fs_UnixNativeDispatcher_stat0(JNIEnv* env, jclass this,
} }
} }
#endif #endif
RESTARTABLE(stat64(path, &buf), err); RESTARTABLE(stat(path, &buf), err);
if (err == 0) { if (err == 0) {
copy_stat64_attributes(env, &buf, attrs); copy_stat_attributes(env, &buf, attrs);
return 0; return 0;
} else { } else {
return errno; return errno;
@ -706,7 +687,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_lstat0(JNIEnv* env, jclass this,
jlong pathAddress, jobject attrs) jlong pathAddress, jobject attrs)
{ {
int err; int err;
struct stat64 buf; struct stat buf;
const char* path = (const char*)jlong_to_ptr(pathAddress); const char* path = (const char*)jlong_to_ptr(pathAddress);
#if defined(__linux__) #if defined(__linux__)
struct my_statx statx_buf; struct my_statx statx_buf;
@ -714,7 +695,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_lstat0(JNIEnv* env, jclass this,
unsigned int mask = STATX_ALL; unsigned int mask = STATX_ALL;
if (my_statx_func != NULL) { if (my_statx_func != NULL) {
// Prefer statx over stat64 on Linux if it's available // Prefer statx over stat on Linux if it's available
RESTARTABLE(statx_wrapper(AT_FDCWD, path, flags, mask, &statx_buf), err); RESTARTABLE(statx_wrapper(AT_FDCWD, path, flags, mask, &statx_buf), err);
if (err == 0) { if (err == 0) {
copy_statx_attributes(env, &statx_buf, attrs); copy_statx_attributes(env, &statx_buf, attrs);
@ -725,11 +706,11 @@ Java_sun_nio_fs_UnixNativeDispatcher_lstat0(JNIEnv* env, jclass this,
return; return;
} }
#endif #endif
RESTARTABLE(lstat64(path, &buf), err); RESTARTABLE(lstat(path, &buf), err);
if (err == -1) { if (err == -1) {
throwUnixException(env, errno); throwUnixException(env, errno);
} else { } else {
copy_stat64_attributes(env, &buf, attrs); copy_stat_attributes(env, &buf, attrs);
} }
} }
@ -738,7 +719,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstat0(JNIEnv* env, jclass this, jint fd,
jobject attrs) jobject attrs)
{ {
int err; int err;
struct stat64 buf; struct stat buf;
#if defined(__linux__) #if defined(__linux__)
struct my_statx statx_buf; struct my_statx statx_buf;
int flags = AT_EMPTY_PATH | AT_STATX_SYNC_AS_STAT; int flags = AT_EMPTY_PATH | AT_STATX_SYNC_AS_STAT;
@ -757,11 +738,11 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstat0(JNIEnv* env, jclass this, jint fd,
return; return;
} }
#endif #endif
RESTARTABLE(fstat64((int)fd, &buf), err); RESTARTABLE(fstat((int)fd, &buf), err);
if (err == -1) { if (err == -1) {
throwUnixException(env, errno); throwUnixException(env, errno);
} else { } else {
copy_stat64_attributes(env, &buf, attrs); copy_stat_attributes(env, &buf, attrs);
} }
} }
@ -770,7 +751,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstatat0(JNIEnv* env, jclass this, jint dfd
jlong pathAddress, jint flag, jobject attrs) jlong pathAddress, jint flag, jobject attrs)
{ {
int err; int err;
struct stat64 buf; struct stat buf;
const char* path = (const char*)jlong_to_ptr(pathAddress); const char* path = (const char*)jlong_to_ptr(pathAddress);
#if defined(__linux__) #if defined(__linux__)
struct my_statx statx_buf; struct my_statx statx_buf;
@ -778,7 +759,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstatat0(JNIEnv* env, jclass this, jint dfd
unsigned int mask = STATX_ALL; unsigned int mask = STATX_ALL;
if (my_statx_func != NULL) { if (my_statx_func != NULL) {
// Prefer statx over stat64 on Linux if it's available // Prefer statx over stat on Linux if it's available
if (((int)flag & AT_SYMLINK_NOFOLLOW) > 0) { // flag set in java code if (((int)flag & AT_SYMLINK_NOFOLLOW) > 0) { // flag set in java code
flags |= AT_SYMLINK_NOFOLLOW; flags |= AT_SYMLINK_NOFOLLOW;
} }
@ -793,15 +774,15 @@ Java_sun_nio_fs_UnixNativeDispatcher_fstatat0(JNIEnv* env, jclass this, jint dfd
} }
#endif #endif
if (my_fstatat64_func == NULL) { if (my_fstatat_func == NULL) {
JNU_ThrowInternalError(env, "should not reach here"); JNU_ThrowInternalError(env, "should not reach here");
return; return;
} }
RESTARTABLE((*my_fstatat64_func)((int)dfd, path, &buf, (int)flag), err); RESTARTABLE((*my_fstatat_func)((int)dfd, path, &buf, (int)flag), err);
if (err == -1) { if (err == -1) {
throwUnixException(env, errno); throwUnixException(env, errno);
} else { } else {
copy_stat64_attributes(env, &buf, attrs); copy_stat_attributes(env, &buf, attrs);
} }
} }
@ -1210,14 +1191,14 @@ Java_sun_nio_fs_UnixNativeDispatcher_statvfs0(JNIEnv* env, jclass this,
#ifdef MACOSX #ifdef MACOSX
struct statfs buf; struct statfs buf;
#else #else
struct statvfs64 buf; struct statvfs buf;
#endif #endif
const char* path = (const char*)jlong_to_ptr(pathAddress); const char* path = (const char*)jlong_to_ptr(pathAddress);
#ifdef MACOSX #ifdef MACOSX
RESTARTABLE(statfs(path, &buf), err); RESTARTABLE(statfs(path, &buf), err);
#else #else
RESTARTABLE(statvfs64(path, &buf), err); RESTARTABLE(statvfs(path, &buf), err);
#endif #endif
if (err == -1) { if (err == -1) {
throwUnixException(env, errno); throwUnixException(env, errno);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,9 @@
#if defined(DEBUG) #if defined(DEBUG)
#include <assert.h>
#include <string.h>
#include "debug_util.h" #include "debug_util.h"
enum { enum {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,9 @@
#if defined(DEBUG) #if defined(DEBUG)
#include <stdlib.h>
#include <string.h>
#include "debug_util.h" #include "debug_util.h"
#define DMEM_MIN(a,b) (a) < (b) ? (a) : (b) #define DMEM_MIN(a,b) (a) < (b) ? (a) : (b)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -23,6 +23,8 @@
* questions. * questions.
*/ */
#include <string.h>
#include "debug_util.h" #include "debug_util.h"
#if defined(DEBUG) #if defined(DEBUG)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -45,12 +45,6 @@ typedef void * dmutex_t;
#include "jni.h" #include "jni.h"
#include "jni_util.h" #include "jni_util.h"
#include "jvm.h" #include "jvm.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
/* keep these after the other headers */ /* keep these after the other headers */
#include "debug_mem.h" #include "debug_mem.h"

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,10 @@
#include "SpanIterator.h" #include "SpanIterator.h"
#include "Trace.h" #include "Trace.h"
#if defined(_AIX) && defined(open)
#undef open
#endif
/* The "header" consists of a jint opcode and a jint span count value */ /* The "header" consists of a jint opcode and a jint span count value */
#define INTS_PER_HEADER 2 #define INTS_PER_HEADER 2
#define BYTES_PER_HEADER 8 #define BYTES_PER_HEADER 8

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,7 @@
#include <jni.h> #include <jni.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <jni_util.h> #include <jni_util.h>
#include <string.h> #include <string.h>
#include <X11/X.h> #include <X11/X.h>

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -55,12 +55,6 @@ Java_java_util_prefs_FileSystemPreferences_chmod(JNIEnv *env,
return (jint) result; return (jint) result;
} }
#if defined(_ALLBSD_SOURCE)
typedef struct flock FLOCK;
#else
typedef struct flock64 FLOCK;
#endif
/** /**
* Try to open a named lock file. * Try to open a named lock file.
* The result is a cookie that can be used later to unlock the file. * The result is a cookie that can be used later to unlock the file.
@ -74,7 +68,7 @@ Java_java_util_prefs_FileSystemPreferences_lockFile0(JNIEnv *env,
int result[2] = {0, 0}; int result[2] = {0, 0};
jintArray javaResult = NULL; jintArray javaResult = NULL;
int old_umask; int old_umask;
FLOCK fl; struct flock fl;
if (!fname) if (!fname)
return javaResult; return javaResult;
@ -101,11 +95,7 @@ Java_java_util_prefs_FileSystemPreferences_lockFile0(JNIEnv *env,
if (fd < 0) { if (fd < 0) {
result[0] = 0; result[0] = 0;
} else { } else {
#if defined(_ALLBSD_SOURCE)
rc = fcntl(fd, F_SETLK, &fl); rc = fcntl(fd, F_SETLK, &fl);
#else
rc = fcntl(fd, F_SETLK64, &fl);
#endif
result[1] = errno; result[1] = errno;
if (rc < 0) { if (rc < 0) {
result[0]= 0; result[0]= 0;
@ -130,18 +120,13 @@ Java_java_util_prefs_FileSystemPreferences_unlockFile0(JNIEnv *env,
jclass thisclass, jint fd) { jclass thisclass, jint fd) {
int rc; int rc;
FLOCK fl; struct flock fl;
fl.l_whence = SEEK_SET; fl.l_whence = SEEK_SET;
fl.l_len = 0; fl.l_len = 0;
fl.l_start = 0; fl.l_start = 0;
fl.l_type = F_UNLCK; fl.l_type = F_UNLCK;
#if defined(_ALLBSD_SOURCE)
rc = fcntl(fd, F_SETLK, &fl); rc = fcntl(fd, F_SETLK, &fl);
#else
rc = fcntl(fd, F_SETLK64, &fl);
#endif
if (rc < 0) { if (rc < 0) {
close(fd); close(fd);
return (jint)errno; return (jint)errno;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2018 SAP SE. All rights reserved. * Copyright (c) 2015, 2018 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
@ -133,11 +133,11 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
jboolean isCopy; jboolean isCopy;
const char* p = GetStringPlatformChars(env, path, &isCopy); const char* p = GetStringPlatformChars(env, path, &isCopy);
if (p != NULL) { if (p != NULL) {
struct stat64 sb; struct stat sb;
uid_t uid, gid; uid_t uid, gid;
int res; int res;
memset(&sb, 0, sizeof(struct stat64)); memset(&sb, 0, sizeof(struct stat));
/* /*
* Check that the path is owned by the effective uid/gid of this * Check that the path is owned by the effective uid/gid of this
@ -146,7 +146,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
uid = geteuid(); uid = geteuid();
gid = getegid(); gid = getegid();
res = stat64(p, &sb); res = stat(p, &sb);
if (res != 0) { if (res != 0) {
/* save errno */ /* save errno */
res = errno; res = errno;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -136,11 +136,11 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
jboolean isCopy; jboolean isCopy;
const char* p = GetStringPlatformChars(env, path, &isCopy); const char* p = GetStringPlatformChars(env, path, &isCopy);
if (p != NULL) { if (p != NULL) {
struct stat64 sb; struct stat sb;
uid_t uid, gid; uid_t uid, gid;
int res; int res;
memset(&sb, 0, sizeof(struct stat64)); memset(&sb, 0, sizeof(struct stat));
/* /*
* Check that the path is owned by the effective uid/gid of this * Check that the path is owned by the effective uid/gid of this
@ -149,7 +149,7 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_VirtualMachineImpl_checkPermissions
uid = geteuid(); uid = geteuid();
gid = getegid(); gid = getegid();
res = stat64(p, &sb); res = stat(p, &sb);
if (res != 0) { if (res != 0) {
/* save errno */ /* save errno */
res = errno; res = errno;

View File

@ -51,11 +51,6 @@ static char *skipNonWhitespace(char *p) {
#if defined(_AIX) #if defined(_AIX)
/* AIX does not understand '/proc/self' - it requires the real process ID */ /* AIX does not understand '/proc/self' - it requires the real process ID */
#define FD_DIR aix_fd_dir #define FD_DIR aix_fd_dir
#define DIR DIR64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#elif defined(_ALLBSD_SOURCE) #elif defined(_ALLBSD_SOURCE)
#define FD_DIR "/dev/fd" #define FD_DIR "/dev/fd"
#else #else

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -30,10 +30,6 @@
#include "jni_util.h" #include "jni_util.h"
#include "jdk_internal_agent_FileSystemImpl.h" #include "jdk_internal_agent_FileSystemImpl.h"
#ifdef _ALLBSD_SOURCE
#define stat64 stat
#endif
/* /*
* JNI_OnLoad * JNI_OnLoad
*/ */
@ -60,11 +56,11 @@ JNIEXPORT jboolean JNICALL Java_jdk_internal_agent_FileSystemImpl_isAccessUserOn
jboolean isCopy; jboolean isCopy;
const char *path = JNU_GetStringPlatformChars(env, str, &isCopy); const char *path = JNU_GetStringPlatformChars(env, str, &isCopy);
if (path != NULL) { if (path != NULL) {
struct stat64 sb; struct stat sb;
if (stat64(path, &sb) == 0) { if (stat(path, &sb) == 0) {
res = ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) == 0) ? JNI_TRUE : JNI_FALSE; res = ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) == 0) ? JNI_TRUE : JNI_FALSE;
} else { } else {
JNU_ThrowIOExceptionWithLastError(env, "stat64 failed"); JNU_ThrowIOExceptionWithLastError(env, "stat failed");
} }
if (isCopy) { if (isCopy) {
JNU_ReleaseStringPlatformChars(env, str, path); JNU_ReleaseStringPlatformChars(env, str, path);

View File

@ -74,14 +74,6 @@ static jlong page_size = 0;
#endif /* _ALLBSD_SOURCE */ #endif /* _ALLBSD_SOURCE */
#if defined(_AIX)
#define DIR DIR64
#define dirent dirent64
#define opendir opendir64
#define readdir readdir64
#define closedir closedir64
#endif
// true = get available swap in bytes // true = get available swap in bytes
// false = get total swap in bytes // false = get total swap in bytes
static jlong get_total_or_available_swap_space_size(JNIEnv* env, jboolean available) { static jlong get_total_or_available_swap_space_size(JNIEnv* env, jboolean available) {