From 041bae34068cc475077036dbcd0ad4ea31418e9f Mon Sep 17 00:00:00 2001 From: yongyuan Date: Tue, 26 Mar 2024 19:20:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=AE=9A=E4=B9=89abort?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E6=89=93=E5=8D=B0errno?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yongyuan --- BUILD.gn | 4 ++++ include/uv.h | 12 ++++++++++++ libuv.gni | 1 + src/unix/async.c | 10 +++++++++- src/unix/epoll.c | 12 ++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index c9cbb46..a592a60 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -183,6 +183,10 @@ if (defined(ohos_lite)) { defines += [ "ASYNC_STACKTRACE" ] } + if (enable_print_errno_abort && is_ohos) { + defines += [ "PRINT_ERRNO_ABORT" ] + } + if (enable_uv_statisic && is_ohos) { defines += [ "UV_STATISTIC" ] cflags += diff --git a/include/uv.h b/include/uv.h index 49b5a48..7b13492 100644 --- a/include/uv.h +++ b/include/uv.h @@ -183,6 +183,18 @@ extern "C" { XX(GETNAMEINFO, getnameinfo) \ XX(RANDOM, random) \ +#ifdef PRINT_ERRNO_ABORT +#include "info/fatal_message.h" +#define UV_ERRNO_ABORT(errno) \ + do { \ + char errno_message[1024]; \ + snprintf(errno_message, sizeof(errno_message), \ + "errno is %d (%s: %s: %d)", errno, __FILE__, __func__, __LINE__); \ + set_fatal_message(errno_message); \ + abort(); \ + } while(0) +#endif + typedef enum { #define XX(code, _) UV_ ## code = UV__ ## code, UV_ERRNO_MAP(XX) diff --git a/libuv.gni b/libuv.gni index 71f9398..db75415 100644 --- a/libuv.gni +++ b/libuv.gni @@ -15,4 +15,5 @@ declare_args() { use_ffrt = false enable_async_stack = true enable_uv_statisic = false + enable_print_errno_abort = true } diff --git a/src/unix/async.c b/src/unix/async.c index 9e74d80..e11e2c8 100644 --- a/src/unix/async.c +++ b/src/unix/async.c @@ -106,7 +106,11 @@ static void uv__async_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) { if (errno == EINTR) continue; +#ifdef PRINT_ERRNO_ABORT + UV_ERRNO_ABORT(errno); +#else abort(); +#endif } QUEUE_MOVE(&loop->async_handles, &queue); @@ -159,7 +163,11 @@ static void uv__async_send(uv_async_t* handle) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) return; - abort(); +#ifdef PRINT_ERRNO_ABORT + UV_ERRNO_ABORT(errno); +#else + abort(); +#endif } diff --git a/src/unix/epoll.c b/src/unix/epoll.c index 97348e2..cc683ef 100644 --- a/src/unix/epoll.c +++ b/src/unix/epoll.c @@ -163,13 +163,21 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { */ if (epoll_ctl(loop->backend_fd, op, w->fd, &e)) { if (errno != EEXIST) +#ifdef PRINT_ERRNO_ABORT + UV_ERRNO_ABORT(errno); +#else abort(); +#endif assert(op == EPOLL_CTL_ADD); /* We've reactivated a file descriptor that's been watched before. */ if (epoll_ctl(loop->backend_fd, EPOLL_CTL_MOD, w->fd, &e)) +#ifdef PRINT_ERRNO_ABORT + UV_ERRNO_ABORT(errno); +#else abort(); +#endif } w->events = w->pevents; @@ -281,7 +289,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { } if (errno != EINTR) +#ifdef PRINT_ERRNO_ABORT + UV_ERRNO_ABORT(errno); +#else abort(); +#endif if (reset_timeout != 0) { timeout = user_timeout; -- Gitee