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 authored and oleavr committed May 10, 2024
1 parent af5c255 commit b29c935
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions gum/gumcloak.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2017-2023 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2024 Francesco Tamagni <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
*/
Expand Down Expand Up @@ -735,3 +736,22 @@ gum_fd_compare (gconstpointer element_a,
return -1;
return 1;
}

void
gum_cloak_with_lock_held (GumCloakLockedFunc func,
gpointer user_data)
{
gum_spinlock_acquire (&cloak_lock);
func (user_data);
gum_spinlock_release (&cloak_lock);
}

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

gum_spinlock_release (&cloak_lock);
return FALSE;
}
6 changes: 6 additions & 0 deletions gum/gumcloak.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2017-2023 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2024 Francesco Tamagni <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
*/
Expand All @@ -19,6 +20,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 +41,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 void gum_cloak_with_lock_held (GumCloakLockedFunc func,
gpointer user_data);
GUM_API gboolean gum_cloak_is_locked (void);

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 b29c935

Please sign in to comment.