Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit

Permalink
Automatic merge of jdk:master into master
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed Mar 10, 2021
2 parents be067d4 + d0c1aec commit 8ba59cf
Show file tree
Hide file tree
Showing 67 changed files with 859 additions and 1,143 deletions.
61 changes: 1 addition & 60 deletions src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#include "runtime/os.hpp"
#include "runtime/osThread.hpp"
#include "runtime/perfMemory.hpp"
#include "runtime/safefetch.hpp"
#include "runtime/safefetch.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/statSampler.hpp"
#include "runtime/thread.inline.hpp"
Expand Down Expand Up @@ -108,7 +108,6 @@
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/vminfo.h>
#include <sys/wait.h>

// Missing prototypes for various system APIs.
extern "C"
Expand Down Expand Up @@ -3150,64 +3149,6 @@ size_t os::current_stack_size() {
return s;
}

extern char** environ;

// Run the specified command in a separate process. Return its exit value,
// or -1 on failure (e.g. can't fork a new process).
// Unlike system(), this function can be called from signal handler. It
// doesn't block SIGINT et al.
int os::fork_and_exec(char* cmd, bool use_vfork_if_available) {
char* argv[4] = { (char*)"sh", (char*)"-c", cmd, NULL};

pid_t pid = fork();

if (pid < 0) {
// fork failed
return -1;

} else if (pid == 0) {
// child process

// Try to be consistent with system(), which uses "/usr/bin/sh" on AIX.
execve("/usr/bin/sh", argv, environ);

// execve failed
_exit(-1);

} else {
// copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
// care about the actual exit code, for now.

int status;

// Wait for the child process to exit. This returns immediately if
// the child has already exited. */
while (waitpid(pid, &status, 0) < 0) {
switch (errno) {
case ECHILD: return 0;
case EINTR: break;
default: return -1;
}
}

if (WIFEXITED(status)) {
// The child exited normally; get its exit code.
return WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
// The child exited because of a signal.
// The best value to return is 0x80 + signal number,
// because that is what all Unix shells do, and because
// it allows callers to distinguish between process exit and
// process death by signal.
return 0x80 + WTERMSIG(status);
} else {
// Unknown exit code; pass it through.
return status;
}
}
return -1;
}

// Get the default path to the core file
// Returns the length of the string
int os::get_core_path(char* buffer, size_t bufferSize) {
Expand Down
75 changes: 0 additions & 75 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
# include <sys/time.h>
# include <sys/times.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <time.h>
# include <unistd.h>

Expand Down Expand Up @@ -2610,80 +2609,6 @@ void os::pause() {
}
}

// Darwin has no "environ" in a dynamic library.
#ifdef __APPLE__
#include <crt_externs.h>
#define environ (*_NSGetEnviron())
#else
extern char** environ;
#endif

// Run the specified command in a separate process. Return its exit value,
// or -1 on failure (e.g. can't fork a new process).
// Unlike system(), this function can be called from signal handler. It
// doesn't block SIGINT et al.
int os::fork_and_exec(char* cmd, bool use_vfork_if_available) {
const char * argv[4] = {"sh", "-c", cmd, NULL};

// fork() in BsdThreads/NPTL is not async-safe. It needs to run
// pthread_atfork handlers and reset pthread library. All we need is a
// separate process to execve. Make a direct syscall to fork process.
// On IA64 there's no fork syscall, we have to use fork() and hope for
// the best...
pid_t pid = fork();

if (pid < 0) {
// fork failed
return -1;

} else if (pid == 0) {
// child process

// execve() in BsdThreads will call pthread_kill_other_threads_np()
// first to kill every thread on the thread list. Because this list is
// not reset by fork() (see notes above), execve() will instead kill
// every thread in the parent process. We know this is the only thread
// in the new process, so make a system call directly.
// IA64 should use normal execve() from glibc to match the glibc fork()
// above.
execve("/bin/sh", (char* const*)argv, environ);

// execve failed
_exit(-1);

} else {
// copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
// care about the actual exit code, for now.

int status;

// Wait for the child process to exit. This returns immediately if
// the child has already exited. */
while (waitpid(pid, &status, 0) < 0) {
switch (errno) {
case ECHILD: return 0;
case EINTR: break;
default: return -1;
}
}

if (WIFEXITED(status)) {
// The child exited normally; get its exit code.
return WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
// The child exited because of a signal
// The best value to return is 0x80 + signal number,
// because that is what all Unix shells do, and because
// it allows callers to distinguish between process exit and
// process death by signal.
return 0x80 + WTERMSIG(status);
} else {
// Unknown exit code; pass it through
return status;
}
}
}

// Get the kern.corefile setting, or otherwise the default path to the core file
// Returns the length of the string
int os::get_core_path(char* buffer, size_t bufferSize) {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "logging/log.hpp"
#include "runtime/init.hpp"
#include "runtime/os.hpp"
#include "runtime/safefetch.hpp"
#include "runtime/safefetch.inline.hpp"
#include "utilities/align.hpp"
#include "utilities/debug.hpp"
#include "utilities/growableArray.hpp"
Expand Down
63 changes: 0 additions & 63 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
# include <sys/times.h>
# include <sys/utsname.h>
# include <sys/socket.h>
# include <sys/wait.h>
# include <pwd.h>
# include <poll.h>
# include <fcntl.h>
Expand Down Expand Up @@ -5219,68 +5218,6 @@ void os::pause() {
}
}

extern char** environ;

// Run the specified command in a separate process. Return its exit value,
// or -1 on failure (e.g. can't fork a new process).
// Unlike system(), this function can be called from signal handler. It
// doesn't block SIGINT et al.
int os::fork_and_exec(char* cmd, bool use_vfork_if_available) {
const char * argv[4] = {"sh", "-c", cmd, NULL};

pid_t pid ;

if (use_vfork_if_available) {
pid = vfork();
} else {
pid = fork();
}

if (pid < 0) {
// fork failed
return -1;

} else if (pid == 0) {
// child process

execve("/bin/sh", (char* const*)argv, environ);

// execve failed
_exit(-1);

} else {
// copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
// care about the actual exit code, for now.

int status;

// Wait for the child process to exit. This returns immediately if
// the child has already exited. */
while (waitpid(pid, &status, 0) < 0) {
switch (errno) {
case ECHILD: return 0;
case EINTR: break;
default: return -1;
}
}

if (WIFEXITED(status)) {
// The child exited normally; get its exit code.
return WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
// The child exited because of a signal
// The best value to return is 0x80 + signal number,
// because that is what all Unix shells do, and because
// it allows callers to distinguish between process exit and
// process death by signal.
return 0x80 + WTERMSIG(status);
} else {
// Unknown exit code; pass it through
return status;
}
}
}

// Get the default path to the core file
// Returns the length of the string
int os::get_core_path(char* buffer, size_t bufferSize) {
Expand Down
78 changes: 78 additions & 0 deletions src/hotspot/os/posix/os_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@
#include <signal.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <utmpx.h>

#ifdef __APPLE__
#include <crt_externs.h>
#endif

#define ROOT_UID 0

#ifndef MAP_ANONYMOUS
Expand Down Expand Up @@ -1765,3 +1771,75 @@ int os::PlatformMonitor::wait(jlong millis) {
return OS_OK;
}
}

// Darwin has no "environ" in a dynamic library.
#ifdef __APPLE__
#define environ (*_NSGetEnviron())
#else
extern char** environ;
#endif

char** os::get_environ() { return environ; }

// Run the specified command in a separate process. Return its exit value,
// or -1 on failure (e.g. can't fork a new process).
// Notes: -Unlike system(), this function can be called from signal handler. It
// doesn't block SIGINT et al.
// -this function is unsafe to use in non-error situations, mainly
// because the child process will inherit all parent descriptors.
int os::fork_and_exec(const char* cmd, bool prefer_vfork) {
const char * argv[4] = {"sh", "-c", cmd, NULL};

pid_t pid ;

char** env = os::get_environ();

// Use always vfork on AIX, since its safe and helps with analyzing OOM situations.
// Otherwise leave it up to the caller.
AIX_ONLY(prefer_vfork = true;)
pid = prefer_vfork ? ::vfork() : ::fork();

if (pid < 0) {
// fork failed
return -1;

} else if (pid == 0) {
// child process

::execve("/bin/sh", (char* const*)argv, env);

// execve failed
::_exit(-1);

} else {
// copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
// care about the actual exit code, for now.

int status;

// Wait for the child process to exit. This returns immediately if
// the child has already exited. */
while (::waitpid(pid, &status, 0) < 0) {
switch (errno) {
case ECHILD: return 0;
case EINTR: break;
default: return -1;
}
}

if (WIFEXITED(status)) {
// The child exited normally; get its exit code.
return WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
// The child exited because of a signal
// The best value to return is 0x80 + signal number,
// because that is what all Unix shells do, and because
// it allows callers to distinguish between process exit and
// process death by signal.
return 0x80 + WTERMSIG(status);
} else {
// Unknown exit code; pass it through
return status;
}
}
}
6 changes: 4 additions & 2 deletions src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#include "runtime/orderAccess.hpp"
#include "runtime/osThread.hpp"
#include "runtime/perfMemory.hpp"
#include "runtime/safefetch.hpp"
#include "runtime/safefetch.inline.hpp"
#include "runtime/safepointMechanism.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/statSampler.hpp"
Expand Down Expand Up @@ -266,6 +266,8 @@ bool os::unsetenv(const char* name) {
return (SetEnvironmentVariable(name, NULL) == TRUE);
}

char** os::get_environ() { return _environ; }

// No setuid programs under Windows.
bool os::have_special_privileges() {
return false;
Expand Down Expand Up @@ -5512,7 +5514,7 @@ int os::PlatformMonitor::wait(jlong millis) {

// Run the specified command in a separate process. Return its exit value,
// or -1 on failure (e.g. can't create a new process).
int os::fork_and_exec(char* cmd, bool use_vfork_if_available) {
int os::fork_and_exec(const char* cmd, bool dummy /* ignored */) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD exit_code;
Expand Down
Loading

0 comments on commit 8ba59cf

Please sign in to comment.