Skip to content

Commit

Permalink
interceptor: Add with_lock_held and is_locked
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmacete committed Apr 11, 2024
1 parent e1023c5 commit 8719585
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions gum/guminterceptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2061,3 +2061,23 @@ gum_page_address_compare (gconstpointer a,
{
return GPOINTER_TO_SIZE (a) - GPOINTER_TO_SIZE (b);
}

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;
}
4 changes: 4 additions & 0 deletions gum/guminterceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ G_BEGIN_DECLS
GUM_DECLARE_FINAL_TYPE (GumInterceptor, gum_interceptor, GUM, INTERCEPTOR,
GObject)

typedef void (* GumInterceptorLockedFunc) (gpointer user_data);
typedef GArray GumInvocationStack;
typedef guint GumInvocationState;

Expand Down Expand Up @@ -76,6 +77,9 @@ 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
5 changes: 5 additions & 0 deletions vapi/frida-gum-1.0.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 8719585

Please sign in to comment.