UnixProcess_md.c: avoid potential deadlock after vfork
opendir is not async-signal-safe and should not be called after forking.
This can cause a deadlock if both of these conditions are met:
- The program is running under a binary translation tool such as
Valgrind which emulates the vfork syscall using fork.
- The malloc mutex was locked at the time of the fork, which causes it
to remain permanently locked in the child process.
As a workaround, we access the directory directly with the getdents
syscall using a stack-allocated buffer.
Also, some applications have been found to hook the open/close libc
functions and end up deadlock in the child due to the use of locks in
the hooks. This is worked around by using raw syscalls in the child.
Bug: 230445494
Test: atest CtsLibcoreTestCases:org.apache.harmony.tests.java.lang.ProcessBuilderTest
Test: atest CtsLibcoreTestCases:libcore.java.lang.ProcessBuilderTest
Change-Id: I0f927c00f2a02f01be0e9f50388f5bc28dc693e1
Merged-In: I0f927c00f2a02f01be0e9f50388f5bc28dc693e1
(cherry picked from commit 3ed6e0b7f5c11a36b39e4d0867d95934fc03aef4)
1 file changed