20 #if !defined(__linux__) || defined(__ANDROID__) 23 namespace debugging_internal {
34 #include <sys/syscall.h> 43 namespace debugging_internal {
47 static uint64_t Pack(uint64_t pid, uint64_t read_fd, uint64_t write_fd) {
50 return (pid << 48) | ((read_fd & 0xffffff) << 24) | (write_fd & 0xffffff);
55 static void Unpack(uint64_t x,
int *pid,
int *read_fd,
int *write_fd) {
57 *read_fd = (x >> 24) & 0xffffff;
58 *write_fd = x & 0xffffff;
65 static std::atomic<uint64_t> pid_and_fds;
67 int save_errno = errno;
79 int current_pid = getpid() & 0xffff;
84 uint64_t local_pid_and_fds = pid_and_fds.load(std::memory_order_relaxed);
85 Unpack(local_pid_and_fds, &pid, &read_fd, &write_fd);
86 while (current_pid != pid) {
90 ABSL_RAW_LOG(FATAL,
"Failed to create pipe, errno=%d", errno);
92 fcntl(p[0], F_SETFD, FD_CLOEXEC);
93 fcntl(p[1], F_SETFD, FD_CLOEXEC);
94 uint64_t new_pid_and_fds = Pack(current_pid, p[0], p[1]);
95 if (pid_and_fds.compare_exchange_strong(
96 local_pid_and_fds, new_pid_and_fds, std::memory_order_relaxed,
97 std::memory_order_relaxed)) {
98 local_pid_and_fds = new_pid_and_fds;
102 local_pid_and_fds = pid_and_fds.load(std::memory_order_relaxed);
104 Unpack(local_pid_and_fds, &pid, &read_fd, &write_fd);
111 bytes_written = syscall(SYS_write, write_fd, addr, 1);
112 }
while (bytes_written == -1 && errno == EINTR);
113 if (bytes_written == 1) {
115 while (read(read_fd, &c, 1) == -1 && errno == EINTR) {
118 if (errno == EBADF) {
121 pid_and_fds.compare_exchange_strong(local_pid_and_fds, 0,
122 std::memory_order_relaxed,
123 std::memory_order_relaxed);
125 }
while (errno == EBADF);
127 return bytes_written == 1;
#define ABSL_RAW_LOG(severity,...)
#define ABSL_RAW_CHECK(condition, message)
bool AddressIsReadable(const void *)