Merge "async_safe: don't call libc's socket." am: 1e0d28b9c2

Original change: https://android-review.googlesource.com/c/platform/bionic/+/1406411

Change-Id: I11b3694cf294406f7badbd08a8d758eb86351f74
This commit is contained in:
Josh Gao 2020-08-21 23:54:26 +00:00 committed by Automerger Merge Worker
commit 2206289fe6

View file

@ -30,6 +30,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/net.h>
#include <pthread.h>
#include <stdarg.h>
#include <stddef.h>
@ -51,12 +52,22 @@
#include "private/ErrnoRestorer.h"
#include "private/ScopedPthreadMutexLocker.h"
// Don't call libc's close, since it might call back into us as a result of fdsan.
// Don't call libc's close or socket, since it might call back into us as a result of fdsan/fdtrack.
#pragma GCC poison close
static int __close(int fd) {
return syscall(__NR_close, fd);
}
static int __socket(int domain, int type, int protocol) {
#if defined(__i386__)
unsigned long args[3] = {static_cast<unsigned long>(domain), static_cast<unsigned long>(type),
static_cast<unsigned long>(protocol)};
return syscall(__NR_socketcall, SYS_SOCKET, &args);
#else
return syscall(__NR_socket, domain, type, protocol);
#endif
}
// Must be kept in sync with frameworks/base/core/java/android/util/EventLog.java.
enum AndroidEventLogType {
EVENT_TYPE_INT = 0,
@ -460,7 +471,7 @@ static int open_log_socket() {
// found that all logd crashes thus far have had no problem stuffing
// the UNIX domain socket and moving on so not critical *today*.
int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
int log_fd = TEMP_FAILURE_RETRY(__socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
if (log_fd == -1) {
return -1;
}