Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8214976: Warn about uses of functions replaced for portability #7248

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -2496,17 +2496,17 @@ bool os::dir_is_empty(const char* path) {
DIR *dir = NULL;
struct dirent *ptr;

dir = opendir(path);
dir = os::opendir(path);
if (dir == NULL) return true;

/* Scan the directory */
bool result = true;
while (result && (ptr = readdir(dir)) != NULL) {
while (result && (ptr = os::readdir(dir)) != NULL) {
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
result = false;
}
}
closedir(dir);
os::closedir(dir);
return result;
}

@@ -2845,7 +2845,7 @@ void os::pause() {
if (fd != -1) {
struct stat buf;
::close(fd);
while (::stat(filename, &buf) == 0) {
while (os::stat(filename, &buf) == 0) {
(void)::poll(NULL, 0, 100);
}
} else {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -2212,17 +2212,17 @@ bool os::dir_is_empty(const char* path) {
DIR *dir = NULL;
struct dirent *ptr;

dir = opendir(path);
dir = os::opendir(path);
if (dir == NULL) return true;

// Scan the directory
bool result = true;
while (result && (ptr = readdir(dir)) != NULL) {
while (result && (ptr = os::readdir(dir)) != NULL) {
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
result = false;
}
}
closedir(dir);
os::closedir(dir);
return result;
}

@@ -2300,12 +2300,12 @@ int os::create_binary_file(const char* path, bool rewrite_existing) {

// return current position of file pointer
jlong os::current_file_offset(int fd) {
return (jlong)::lseek(fd, (off_t)0, SEEK_CUR);
return (jlong)os::lseek(fd, (off_t)0, SEEK_CUR);
}

// move file pointer to the specified offset
jlong os::seek_to_file_offset(int fd, jlong offset) {
return (jlong)::lseek(fd, (off_t)offset, SEEK_SET);
return (jlong)os::lseek(fd, (off_t)offset, SEEK_SET);
}

// This code originates from JDK's sysAvailable
@@ -2326,11 +2326,11 @@ int os::available(int fd, jlong *bytes) {
}
}
}
if ((cur = ::lseek(fd, 0L, SEEK_CUR)) == -1) {
if ((cur = os::lseek(fd, 0L, SEEK_CUR)) == -1) {
return 0;
} else if ((end = ::lseek(fd, 0L, SEEK_END)) == -1) {
} else if ((end = os::lseek(fd, 0L, SEEK_END)) == -1) {
return 0;
} else if (::lseek(fd, cur, SEEK_SET) == -1) {
} else if (os::lseek(fd, cur, SEEK_SET) == -1) {
return 0;
}
*bytes = end - cur;
@@ -2487,7 +2487,7 @@ void os::pause() {
if (fd != -1) {
struct stat buf;
::close(fd);
while (::stat(filename, &buf) == 0) {
while (os::stat(filename, &buf) == 0) {
(void)::poll(NULL, 0, 100);
}
} else {
@@ -385,7 +385,7 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() {
// write the given buffer to the socket
int LinuxAttachListener::write_fully(int s, char* buf, int len) {
do {
ssize_t n = ::write(s, buf, len);
ssize_t n = os::write(s, buf, len);
if (n == -1) {
if (errno != EINTR) return -1;
} else {
@@ -130,7 +130,7 @@ ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) :
}

// Truncate backing file
while (ftruncate(_fd, max_capacity) == -1) {
while (os::ftruncate(_fd, max_capacity) == -1) {
if (errno != EINTR) {
ZErrno err;
log_error_p(gc)("Failed to truncate backing file (%s)", err.to_string());
@@ -2608,9 +2608,9 @@ void linux_wrap_code(char* base, size_t size) {
int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);

if (fd != -1) {
off_t rv = ::lseek(fd, size-2, SEEK_SET);
off_t rv = os::lseek(fd, size-2, SEEK_SET);
if (rv != (off_t)-1) {
if (::write(fd, "", 1) == 1) {
if (os::write(fd, "", 1) == 1) {
mmap(base, size,
PROT_READ|PROT_WRITE|PROT_EXEC,
MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
@@ -3620,19 +3620,19 @@ static os::PageSizes scan_multiple_page_support() {
const char* sys_hugepages = "/sys/kernel/mm/hugepages";
os::PageSizes page_sizes;

DIR *dir = opendir(sys_hugepages);
DIR *dir = os::opendir(sys_hugepages);

struct dirent *entry;
size_t page_size;
while ((entry = readdir(dir)) != NULL) {
while ((entry = os::readdir(dir)) != NULL) {
if (entry->d_type == DT_DIR &&
sscanf(entry->d_name, "hugepages-%zukB", &page_size) == 1) {
// The kernel is using kB, hotspot uses bytes
// Add each found Large Page Size to page_sizes
page_sizes.add(page_size * K);
}
}
closedir(dir);
os::closedir(dir);

LogTarget(Debug, pagesize) lt;
if (lt.is_enabled()) {
@@ -4821,17 +4821,17 @@ bool os::dir_is_empty(const char* path) {
DIR *dir = NULL;
struct dirent *ptr;

dir = opendir(path);
dir = os::opendir(path);
if (dir == NULL) return true;

// Scan the directory
bool result = true;
while (result && (ptr = readdir(dir)) != NULL) {
while (result && (ptr = os::readdir(dir)) != NULL) {
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
result = false;
}
}
closedir(dir);
os::closedir(dir);
return result;
}

@@ -5144,7 +5144,7 @@ void os::pause() {
if (fd != -1) {
struct stat buf;
::close(fd);
while (::stat(filename, &buf) == 0) {
while (os::stat(filename, &buf) == 0) {
(void)::poll(NULL, 0, 100);
}
} else {
@@ -289,11 +289,11 @@ static int get_systemtype(void) {
}

// Check whether we have a task subdirectory
if ((taskDir = opendir("/proc/self/task")) == NULL) {
if ((taskDir = os::opendir("/proc/self/task")) == NULL) {
procEntriesType = UNDETECTABLE;
} else {
// The task subdirectory exists; we're on a Linux >= 2.6 system
closedir(taskDir);
os::closedir(taskDir);
procEntriesType = LINUX26_NPTL;
}

@@ -675,7 +675,7 @@ bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_dir(const char
struct stat mystat;
int ret_val = 0;

ret_val = stat(name, &mystat);
ret_val = os::stat(name, &mystat);
if (ret_val < 0) {
return false;
}
@@ -688,7 +688,7 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::fsize(const char*
size = 0;
struct stat fbuf;

if (stat(name, &fbuf) < 0) {
if (os::stat(name, &fbuf) < 0) {
return OS_ERR;
}
size = fbuf.st_size;
@@ -659,13 +659,19 @@ void os::dll_unload(void *lib) {
::dlclose(lib);
}

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(lseek);
jlong os::lseek(int fd, jlong offset, int whence) {
return (jlong) BSD_ONLY(::lseek) NOT_BSD(::lseek64)(fd, offset, whence);
}
PRAGMA_DIAG_POP

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(fsync);
int os::fsync(int fd) {
return ::fsync(fd);
}
PRAGMA_DIAG_POP

int os::ftruncate(int fd, jlong length) {
return BSD_ONLY(::ftruncate) NOT_BSD(::ftruncate64)(fd, length);
@@ -675,62 +681,92 @@ const char* os::get_current_directory(char *buf, size_t buflen) {
return getcwd(buf, buflen);
}

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(fdopen);
FILE* os::fdopen(int fd, const char* mode) {
return ::fdopen(fd, mode);
}
PRAGMA_DIAG_POP

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(write);
ssize_t os::write(int fd, const void *buf, unsigned int nBytes) {
ssize_t res;
RESTARTABLE(::write(fd, buf, (size_t) nBytes), res);
return res;
}
PRAGMA_DIAG_POP

ssize_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
return ::pread(fd, buf, nBytes, offset);
}

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(flockfile);
void os::flockfile(FILE* fp) {
::flockfile(fp);
}
PRAGMA_DIAG_POP

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(funlockfile);
void os::funlockfile(FILE* fp) {
::funlockfile(fp);
}
PRAGMA_DIAG_POP

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(opendir);
DIR* os::opendir(const char* dirname) {
assert(dirname != NULL, "just checking");
return ::opendir(dirname);
}
PRAGMA_DIAG_POP

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(readdir);
struct dirent* os::readdir(DIR* dirp) {
assert(dirp != NULL, "just checking");
return ::readdir(dirp);
}
PRAGMA_DIAG_POP

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(closedir);
int os::closedir(DIR *dirp) {
assert(dirp != NULL, "just checking");
return ::closedir(dirp);
}
PRAGMA_DIAG_POP

int os::socket_close(int fd) {
return ::close(fd);
}

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(recv);
int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
}
PRAGMA_DIAG_POP

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(send);
int os::send(int fd, char* buf, size_t nBytes, uint flags) {
RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
}
PRAGMA_DIAG_POP

int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
return os::send(fd, buf, nBytes, flags);
}

int os::connect(int fd, struct sockaddr* him, socklen_t len) {
PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(connect);
int os::connect(int fd, const struct sockaddr* him, socklen_t len) {
RESTARTABLE_RETURN_INT(::connect(fd, him, len));
}
PRAGMA_DIAG_POP

struct hostent* os::get_host_by_name(char* name) {
return ::gethostbyname(name);
@@ -861,9 +897,12 @@ char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen)

}

PRAGMA_DIAG_PUSH
PRAGMA_PERMIT_FORBIDDEN_C_FUNCTION(stat);
int os::stat(const char *path, struct stat *sbuf) {
return ::stat(path, sbuf);
}
PRAGMA_DIAG_POP

char * os::native_path(char *path) {
return path;
@@ -335,7 +335,7 @@ static DIR *open_directory_secure(const char* dirname) {
}

// Open the directory.
dirp = ::opendir(dirname);
dirp = os::opendir(dirname);
if (dirp == NULL) {
// The directory doesn't exist, close fd and return.
::close(fd);
@@ -868,7 +868,7 @@ static int create_sharedmem_resources(const char* dirname, const char* filename,
ssize_t result;

// truncate the file to get rid of any existing data
RESTARTABLE(::ftruncate(fd, (off_t)0), result);
RESTARTABLE(os::ftruncate(fd, (off_t)0), result);
if (result == OS_ERR) {
if (PrintMiscellaneous && Verbose) {
warning("could not truncate shared memory file: %s\n", os::strerror(errno));
@@ -877,7 +877,7 @@ static int create_sharedmem_resources(const char* dirname, const char* filename,
return -1;
}
// set the file size
RESTARTABLE(::ftruncate(fd, (off_t)size), result);
RESTARTABLE(os::ftruncate(fd, (off_t)size), result);
if (result == OS_ERR) {
if (PrintMiscellaneous && Verbose) {
warning("could not set shared memory file size: %s\n", os::strerror(errno));
@@ -5721,7 +5721,7 @@ int os::socket_close(int fd) {
return ::closesocket(fd);
}

int os::connect(int fd, struct sockaddr* him, socklen_t len) {
int os::connect(int fd, const struct sockaddr* him, socklen_t len) {
return ::connect(fd, him, len);
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012 Red Hat, Inc.
* Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -626,7 +626,7 @@ JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg))

tty->print_cr("FATAL ERROR in native method: %s", msg);
thread->print_stack();
os::abort(); // Dump core and abort
os::abort(true); // Dump core and abort
JNI_END