diff --git a/gum/gumcloak.c b/gum/gumcloak.c index 237657a448..6afaf70e02 100644 --- a/gum/gumcloak.c +++ b/gum/gumcloak.c @@ -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); +} diff --git a/gum/gumcloak.h b/gum/gumcloak.h index 0129cdc226..ce441e9f08 100644 --- a/gum/gumcloak.h +++ b/gum/gumcloak.h @@ -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); @@ -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 diff --git a/vapi/frida-gum-1.0.vapi b/vapi/frida-gum-1.0.vapi index 41fbc8875c..833d7414b4 100644 --- a/vapi/frida-gum-1.0.vapi +++ b/vapi/frida-gum-1.0.vapi @@ -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 {