Skip to content

Commit

Permalink
cloak: Add with_lock_held and is_locked
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmacete committed Apr 8, 2024
1 parent 959047b commit d3166a7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gum/gumcloak.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,3 +735,22 @@ gum_fd_compare (gconstpointer element_a,
return -1;
return 1;
}

gboolean
gum_cloak_is_locked (void)
{
if (!gum_spinlock_try_acquire (&cloak_lock))
return TRUE;

gum_spinlock_release (&cloak_lock);
return FALSE;
}

void
gum_cloak_with_lock_held (GumCloakLockedFunc func,
gpointer user_data)
{
gum_spinlock_acquire (&cloak_lock);
func (user_data);
gum_spinlock_release (&cloak_lock);
}
5 changes: 5 additions & 0 deletions gum/gumcloak.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef gboolean (* GumCloakFoundThreadFunc) (GumThreadId id,
typedef gboolean (* GumCloakFoundRangeFunc) (const GumMemoryRange * range,
gpointer user_data);
typedef gboolean (* GumCloakFoundFDFunc) (gint fd, gpointer user_data);
typedef void (* GumCloakLockedFunc) (gpointer user_data);

GUM_API void gum_cloak_add_thread (GumThreadId id);
GUM_API void gum_cloak_remove_thread (GumThreadId id);
Expand All @@ -39,6 +40,10 @@ GUM_API gboolean gum_cloak_has_file_descriptor (gint fd);
GUM_API void gum_cloak_enumerate_file_descriptors (GumCloakFoundFDFunc func,
gpointer user_data);

GUM_API gboolean gum_cloak_is_locked (void);
GUM_API void gum_cloak_with_lock_held (GumCloakLockedFunc func,
gpointer user_data);

G_END_DECLS

#endif
4 changes: 4 additions & 0 deletions vapi/frida-gum-1.0.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,13 @@ namespace Gum {
public bool has_file_descriptor (int fd);
public void enumerate_file_descriptors (Gum.Cloak.FoundFDFunc func);

public void with_lock_held (Gum.Cloak.LockedFunc func);
public bool is_locked ();

public delegate bool FoundThreadFunc (Gum.ThreadId id);
public delegate bool FoundRangeFunc (Gum.MemoryRange range);
public delegate bool FoundFDFunc (int fd);
public delegate void LockedFunc ();
}

public struct CpuContext {
Expand Down

0 comments on commit d3166a7

Please sign in to comment.