diff --git a/gum/guminterceptor.c b/gum/guminterceptor.c index aa0a7f6f1..d8148285d 100644 --- a/gum/guminterceptor.c +++ b/gum/guminterceptor.c @@ -1,6 +1,7 @@ /* * Copyright (C) 2008-2022 Ole André Vadla Ravnås * Copyright (C) 2008 Christian Berentsen + * Copyright (C) 2024 Francesco Tamagni * * Licence: wxWindows Library Licence, Version 3.1 */ @@ -809,6 +810,26 @@ gum_interceptor_restore (GumInvocationState * state) g_array_set_size (stack, old_depth); } +void +gum_interceptor_with_lock_held (GumInterceptor * self, + GumInterceptorLockedFunc func, + gpointer user_data) +{ + GUM_INTERCEPTOR_LOCK (self); + func (user_data); + GUM_INTERCEPTOR_UNLOCK (self); +} + +gboolean +gum_interceptor_is_locked (GumInterceptor * self) +{ + if (!g_rec_mutex_trylock (&self->mutex)) + return TRUE; + + GUM_INTERCEPTOR_UNLOCK (self); + return FALSE; +} + gpointer _gum_interceptor_peek_top_caller_return_address (void) { diff --git a/gum/guminterceptor.h b/gum/guminterceptor.h index eba2e73dc..ae002d09e 100644 --- a/gum/guminterceptor.h +++ b/gum/guminterceptor.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2008-2022 Ole André Vadla Ravnås * Copyright (C) 2008 Christian Berentsen + * Copyright (C) 2024 Francesco Tamagni * * Licence: wxWindows Library Licence, Version 3.1 */ @@ -19,6 +20,7 @@ GUM_DECLARE_FINAL_TYPE (GumInterceptor, gum_interceptor, GUM, INTERCEPTOR, typedef GArray GumInvocationStack; typedef guint GumInvocationState; +typedef void (* GumInterceptorLockedFunc) (gpointer user_data); typedef enum { @@ -76,6 +78,10 @@ GUM_API gpointer gum_invocation_stack_translate (GumInvocationStack * self, GUM_API void gum_interceptor_save (GumInvocationState * state); GUM_API void gum_interceptor_restore (GumInvocationState * state); +GUM_API void gum_interceptor_with_lock_held (GumInterceptor * self, + GumInterceptorLockedFunc func, gpointer user_data); +GUM_API gboolean gum_interceptor_is_locked (GumInterceptor * self); + G_END_DECLS #endif diff --git a/vapi/frida-gum-1.0.vapi b/vapi/frida-gum-1.0.vapi index 171f4f5b7..0dd1858b9 100644 --- a/vapi/frida-gum-1.0.vapi +++ b/vapi/frida-gum-1.0.vapi @@ -154,6 +154,11 @@ namespace Gum { public void ignore_other_threads (); public void unignore_other_threads (); + + public void with_lock_held (Gum.Interceptor.LockedFunc func); + public bool is_locked (); + + public delegate void LockedFunc (); } [CCode (type_cname = "GumInvocationListenerInterface")]