diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 89297cb79e3ace04ca702e5b66f46868a65da05b..0000000000000000000000000000000000000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -test/fixtures/lorem_ipsum.txt text eol=lf diff --git a/BUILD.gn b/BUILD.gn index 0ecc6061026460d38bd362f136dda63fcfc615b8..652217c78ade5e45d899c604d6375194c93bc795 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -305,9 +305,11 @@ if (defined(ohos_lite)) { "hitrace:hitrace_meter", ] } + if (is_ohos && enable_async_stack) { sources += [ "src/dfx/async_stack/libuv_async_stack.c" ] } + if (is_android) { sources += [ "src/win/log_win.c", diff --git a/include/uv.h b/include/uv.h index 418796d13312a1ffc7eb94cfad5af8613149d359..945c34ecabe9c56ce10d699a41f4cc5d135401ac 100644 --- a/include/uv.h +++ b/include/uv.h @@ -226,6 +226,7 @@ typedef enum { #define UV_EVENT_MAGIC_OFFSET 0x12345ULL #define UV_EVENT_MAGIC_OFFSETBITS 44 + /* Handle types. */ typedef struct uv_loop_s uv_loop_t; typedef struct uv_handle_s uv_handle_t; @@ -1953,6 +1954,7 @@ UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data); UV_EXTERN int uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* handler); UV_EXTERN int uv_unregister_task_to_event(struct uv_loop_s* loop); UV_EXTERN int uv_check_data_valid(struct uv_loop_data* data); + /* String utilities needed internally for dealing with Windows. */ size_t uv_utf16_length_as_wtf8(const uint16_t* utf16, ssize_t utf16_len); diff --git a/src/threadpool.c b/src/threadpool.c index 3035c4e7607e77888ecf94d98fc85b4a873c5922..af3ad3f901c1c6103f8659f55fa13d302e65c3eb 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -35,6 +35,9 @@ #include "ffrt_inner.h" #endif #include +#ifdef ASYNC_STACKTRACE +#include "dfx/async_stack/libuv_async_stack.h" +#endif #define MAX_THREADPOOL_SIZE 1024 #define UV_TRACE_NAME "UV_TRACE" @@ -54,10 +57,6 @@ static struct uv__queue run_slow_work_message; static struct uv__queue slow_io_pending_wq; -#ifdef ASYNC_STACKTRACE -#include "dfx/async_stack/libuv_async_stack.h" -#endif - #ifdef UV_STATISTIC #define MAX_DUMP_QUEUE_SIZE 200 static uv_mutex_t dump_queue_mutex; @@ -631,7 +630,7 @@ static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) { uv__loop_internal_fields_t* lfields = uv__get_internal_fields(w->loop); int qos = (ffrt_qos_t)(intptr_t)req->reserved[0]; - if (uv_check_data_valid((struct uv_loop_data*)(loop->data)) == 0) { + if (uv_check_data_valid((struct uv_loop_data*)(w->loop->data)) == 0) { int status = (w->work == uv__cancelled) ? UV_ECANCELED : 0; struct uv_loop_data* addr = (struct uv_loop_data*)((uint64_t)w->loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); @@ -663,7 +662,7 @@ void uv__work_done(uv_async_t* handle) { return; } rdunlock_closed_uv_loop_rwlock(); - + uv_mutex_lock(&loop->wq_mutex); #ifndef USE_FFRT uv__queue_move(&loop->wq, &wq); diff --git a/src/timer.c b/src/timer.c index 0734f43a0bc5e05c5e2cc428377fc18bd6801101..35548b421ca56f39ece914b2aafc17e540b47746 100644 --- a/src/timer.c +++ b/src/timer.c @@ -97,7 +97,6 @@ int uv_timer_start(uv_timer_t* handle, (struct heap_node*) &handle->heap_node, timer_less_than); uv__handle_start(handle); - #ifdef __linux__ if (uv_check_data_valid((struct uv_loop_data*)handle->loop->data) == 0) { uv_async_send(&handle->loop->wq_async); diff --git a/src/unix/core.c b/src/unix/core.c index e38ac559eb0a5a4681ba145a1fea19ced5ede785..339877f59376ccbbc8e4ea9525bbcbf9a814b46d 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -1954,13 +1954,13 @@ int uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* h #endif } + int uv_unregister_task_to_event(struct uv_loop_s* loop) { #if defined(__aarch64__) if (loop == NULL || loop->data == NULL || ((uint64_t)loop->data >> UV_EVENT_MAGIC_OFFSETBITS) != (uint64_t)(UV_EVENT_MAGIC_OFFSET)) return -1; - loop->data = (struct uv_loop_data*)((uint64_t)loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); free(loop->data); @@ -1971,6 +1971,7 @@ int uv_unregister_task_to_event(struct uv_loop_s* loop) #endif } + int uv_check_data_valid(struct uv_loop_data* data) { #if defined(__aarch64__) if (data == NULL || ((uint64_t)data >> UV_EVENT_MAGIC_OFFSETBITS) != (uint64_t)(UV_EVENT_MAGIC_OFFSET)) { @@ -1986,4 +1987,5 @@ int uv_check_data_valid(struct uv_loop_data* data) { #else return -1; #endif -} \ No newline at end of file +} + diff --git a/src/unix/signal.c b/src/unix/signal.c index bc4206e6d864c8eed412d3c50e47438968465bfd..d69829b27beeb4b4f45dae743f5cae1b0538bb69 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -20,6 +20,7 @@ #include "uv.h" #include "internal.h" +#include "uv_log.h" #include #include @@ -103,8 +104,14 @@ static void uv__signal_global_reinit(void) { if (uv__make_pipe(uv__signal_lock_pipefd, 0)) abort(); - if (uv__signal_unlock()) + if (uv__signal_unlock()) { +#ifdef USE_OHOS_DFX + UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[1] is %{public}d", errno, uv__signal_lock_pipefd[1]); + return; +#else abort(); +#endif + } } @@ -148,14 +155,26 @@ static void uv__signal_block_and_lock(sigset_t* saved_sigmask) { if (pthread_sigmask(SIG_SETMASK, &new_mask, saved_sigmask)) abort(); - if (uv__signal_lock()) + if (uv__signal_lock()) { +#ifdef USE_OHOS_DFX + UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[0] is %{public}d", errno, uv__signal_lock_pipefd[0]); + return; +#else abort(); +#endif + } } static void uv__signal_unlock_and_unblock(sigset_t* saved_sigmask) { - if (uv__signal_unlock()) + if (uv__signal_unlock()) { +#ifdef USE_OHOS_DFX + UV_LOGF("errno is %{public}d, uv__signal_lock_pipefd[1] is %{public}d", errno, uv__signal_lock_pipefd[1]); + return; +#else abort(); +#endif + } if (pthread_sigmask(SIG_SETMASK, saved_sigmask, NULL)) abort(); @@ -461,8 +480,14 @@ static void uv__signal_event(uv_loop_t* loop, } /* Other errors really should never happen. */ - if (r == -1) + if (r == -1) { +#ifdef USE_OHOS_DFX + UV_LOGF("errno is %{public}d, loop->signal_pipefd[0] is %{public}d", errno, loop->signal_pipefd[0]); + return; +#else abort(); +#endif + } bytes += r;