Skip to content

Commit

Permalink
Add support for FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 26, 2024
1 parent f37384d commit d3a3e17
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 11 additions & 1 deletion gum/backend-freebsd/gumprocess-freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ucontext.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/thr.h>
#include <sys/types.h>
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/core/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/gumjs/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit d3a3e17

Please sign in to comment.