Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 26, 2024
1 parent 16c7074 commit b93ae26
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
6 changes: 4 additions & 2 deletions gum/backend-linux/gumprocess-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@
#ifdef HAVE_SYS_USER_H
# include <sys/user.h>
#endif
#ifdef HAVE_LINUX
#include <sys/time.h>
#include <sys/resource.h>
#endif

#define GUM_PAGE_START(value, page_size) \
(GUM_ADDRESS (value) & ~GUM_ADDRESS (page_size - 1))
Expand Down Expand Up @@ -90,6 +89,9 @@
#ifndef NT_PRSTATUS
# define NT_PRSTATUS 1
#endif
#ifndef RUSAGE_THREAD
# define RUSAGE_THREAD 1
#endif

#define GUM_TEMP_FAILURE_RETRY(expression) \
({ \
Expand Down
4 changes: 2 additions & 2 deletions gum/backend-windows/gumprocess-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ gum_thread_resume (GumThreadId thread_id,
guint64
gum_thead_get_user_time (void)
{
static gboolean initialized = false;
static gboolean initialized = FALSE;
static GetThreadTimesFunc get_thread_times = NULL;

HMODULE mod;
Expand All @@ -668,7 +668,7 @@ gum_thead_get_user_time (void)
if (!get_thread_times (GetCurrentThread (), NULL, NULL, NULL, &userTime))
return 0;

result = ((guint64) userTime.dwHighDateTime) << 32 + userTime.dwLowDateTime;
result = (((guint64) userTime.dwHighDateTime) << 32) + userTime.dwLowDateTime;

/* Timings on Windows are to 100-nanosecond granularity. Convert to u-secs */
return result / 10;
Expand Down
32 changes: 20 additions & 12 deletions tests/gumjs/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -5195,22 +5195,25 @@ TESTCASE (process_threads_get_user_time)

TESTCASE (process_threads_get_user_time_other_thread)
{
#if defined (HAVE_LINUX) && !defined (HAVE_PTHREAD_SETNAME_NP)
g_print ("<skipping, libc is too old> ");
#else
GumNamedSleeperContext ctx;
GThread * thread;
double user_time_a = 0, user_time_b = 0;

#ifdef HAVE_LINUX
# ifdef HAVE_LINUX
if (!check_exception_handling_testable ())
return;
#endif
# endif

#ifdef HAVE_MIPS
# ifdef HAVE_MIPS
if (!g_test_slow ())
{
g_print ("<skipping, run in slow mode> ");
return;
}
#endif
# endif

ctx.controller_messages = g_async_queue_new ();
ctx.sleeper_messages = g_async_queue_new ();
Expand Down Expand Up @@ -5252,13 +5255,14 @@ 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) || defined (HAVE_FREEBSD) \
# if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) \
|| defined (HAVE_WINDOWS)
g_assert_true (user_time_a != 0);
g_assert_true (user_time_b > user_time_a);
#else
# else
g_assert_cmpuint (user_time_a, ==, 0);
g_assert_cmpuint (user_time_b, ==, 0);
# endif
#endif
}

Expand All @@ -5272,7 +5276,7 @@ user_time (gpointer data)
* to GLib potentially having been prebuilt against an old libc. Therefore we
* set the name manually using pthreads.
*/
#ifdef HAVE_LINUX
#if defined (HAVE_LINUX) && defined (HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np (pthread_self (), "user-time");
#endif

Expand Down Expand Up @@ -5305,21 +5309,24 @@ do_work (void)

TESTCASE (process_threads_find_busy_thread)
{
#if defined (HAVE_LINUX) && !defined (HAVE_PTHREAD_SETNAME_NP)
g_print ("<skipping, libc is too old> ");
#else
GumHotNamedSleeperContext ctx[NUM_THREADS];
GThread * thread[NUM_THREADS];

#ifdef HAVE_LINUX
# ifdef HAVE_LINUX
if (!check_exception_handling_testable ())
return;
#endif
# endif

#ifdef HAVE_MIPS
# ifdef HAVE_MIPS
if (!g_test_slow ())
{
g_print ("<skipping, run in slow mode> ");
return;
}
#endif
# endif

guint rand = g_random_int_range (0, 10);

Expand Down Expand Up @@ -5363,9 +5370,10 @@ TESTCASE (process_threads_find_busy_thread)
g_async_queue_unref (ctx[i].controller_messages);
}

#if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) \
# if defined (HAVE_LINUX) || defined (HAVE_DARWIN) || defined (HAVE_FREEBSD) \
|| defined (HAVE_WINDOWS)
EXPECT_SEND_MESSAGE_WITH ("%" G_GSIZE_MODIFIER "u", ctx[rand].id);
# endif
#endif
}

Expand Down

0 comments on commit b93ae26

Please sign in to comment.