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 authored and oleavr committed May 10, 2024
1 parent 6b15d01 commit 071eccf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions gum/guminterceptor.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2008-2022 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2008 Christian Berentsen <[email protected]>
* Copyright (C) 2024 Francesco Tamagni <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
*/
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions gum/guminterceptor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2008-2022 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2008 Christian Berentsen <[email protected]>
* Copyright (C) 2024 Francesco Tamagni <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
*/
Expand All @@ -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
{
Expand Down Expand Up @@ -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
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 071eccf

Please sign in to comment.