From d3a3e171cf03e1052a52cffcfd77a8f91296f7f0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 26 Feb 2024 13:33:01 +0000 Subject: [PATCH] Add support for FreeBSD --- gum/backend-freebsd/gumprocess-freebsd.c | 12 +++++++++++- tests/core/process.c | 6 +++--- tests/gumjs/script.c | 6 +++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gum/backend-freebsd/gumprocess-freebsd.c b/gum/backend-freebsd/gumprocess-freebsd.c index 1797b2333..5f40b08fc 100644 --- a/gum/backend-freebsd/gumprocess-freebsd.c +++ b/gum/backend-freebsd/gumprocess-freebsd.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -719,7 +720,16 @@ gum_thread_resume (GumThreadId thread_id, guint64 gum_thead_get_user_time (void) { - return 0; + guint64 user_time = 0; + struct rusage usage; + + if (getrusage (RUSAGE_THREAD, &usage) == 0) + { + user_time = (usage.ru_utime.tv_sec * G_USEC_PER_SEC) + + usage.ru_utime.tv_usec; + } + + return user_time; } gboolean diff --git a/tests/core/process.c b/tests/core/process.c index 259130c22..b1f248003 100644 --- a/tests/core/process.c +++ b/tests/core/process.c @@ -309,7 +309,7 @@ TESTCASE (process_threads_get_user_time) do_work (); user_time_b = gum_thead_get_user_time (); -#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) +#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) g_assert_cmpuint (user_time_a, !=, 0); g_assert_cmpuint (user_time_b, >, user_time_a); #else @@ -331,7 +331,7 @@ TESTCASE (process_threads_get_user_time_by_id_self) do_work (); user_time_b = gum_thead_get_user_time_by_id (tid); -#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) +#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) g_assert_cmpuint (user_time_a, !=, 0); g_assert_cmpuint (user_time_b, >, user_time_a); #else @@ -360,7 +360,7 @@ TESTCASE (process_threads_get_user_time_by_id_other) g_usleep (250000); user_time_b = gum_thead_get_user_time_by_id (d.id); -#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) +#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) g_assert_cmpuint (user_time_a, !=, 0); g_assert_cmpuint (user_time_b, >, user_time_a); #else diff --git a/tests/gumjs/script.c b/tests/gumjs/script.c index e93e0dfa1..64846273d 100644 --- a/tests/gumjs/script.c +++ b/tests/gumjs/script.c @@ -5183,7 +5183,7 @@ TESTCASE (process_threads_get_user_time) ); EXPECT_NO_MESSAGES (); -#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) +#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) g_assert_true (user_time_a != 0); g_assert_true (user_time_b > user_time_a); #else @@ -5251,7 +5251,7 @@ TESTCASE (process_threads_get_user_time_other_thread) g_async_queue_unref (ctx.sleeper_messages); g_async_queue_unref (ctx.controller_messages); -#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) +#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) g_assert_true (user_time_a != 0); g_assert_true (user_time_b > user_time_a); #else @@ -5361,7 +5361,7 @@ TESTCASE (process_threads_find_busy_thread) g_async_queue_unref (ctx[i].controller_messages); } -#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) +#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) EXPECT_SEND_MESSAGE_WITH ("%" G_GSIZE_MODIFIER "u", ctx[rand].id); #endif }