mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-25 05:45:11 +02:00
8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
Reviewed-by: stuefe, dsamersoff, dcubed
This commit is contained in:
parent
971e022093
commit
5c859405b5
4 changed files with 144 additions and 26 deletions
|
@ -5878,14 +5878,6 @@ void Parker::unpark() {
|
|||
|
||||
extern char** environ;
|
||||
|
||||
#ifndef __NR_fork
|
||||
#define __NR_fork IA32_ONLY(2) IA64_ONLY(not defined) AMD64_ONLY(57) AARCH64_ONLY(1079)
|
||||
#endif
|
||||
|
||||
#ifndef __NR_execve
|
||||
#define __NR_execve IA32_ONLY(11) IA64_ONLY(1033) AMD64_ONLY(59) AARCH64_ONLY(221)
|
||||
#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
|
||||
|
@ -5893,13 +5885,7 @@ extern char** environ;
|
|||
int os::fork_and_exec(char* cmd) {
|
||||
const char * argv[4] = {"sh", "-c", cmd, NULL};
|
||||
|
||||
// fork() in LinuxThreads/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 = NOT_IA64(syscall(__NR_fork);)
|
||||
IA64_ONLY(fork();)
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid < 0) {
|
||||
// fork failed
|
||||
|
@ -5908,15 +5894,7 @@ int os::fork_and_exec(char* cmd) {
|
|||
} else if (pid == 0) {
|
||||
// child process
|
||||
|
||||
// execve() in LinuxThreads 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.
|
||||
NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);)
|
||||
IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);)
|
||||
execve("/bin/sh", (char* const*)argv, environ);
|
||||
|
||||
// execve failed
|
||||
_exit(-1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue