void gum_spinlock_init (GumSpinlock * spinlock) { GumSpinlockImpl * self = (GumSpinlockImpl *) spinlock; GumX86Writer cw; gpointer try_again_label = "gum_spinlock_try_again"; gpointer beach_label = "gum_spinlock_beach"; self->is_held = FALSE; self->code = gum_alloc_n_pages (1, GUM_PAGE_RWX); gum_x86_writer_init (&cw, self->code); self->acquire_impl = GUM_POINTER_TO_FUNCPTR (GumSpinlockAcquireFunc, gum_x86_writer_cur (&cw)); gum_x86_writer_put_mov_reg_u32 (&cw, GUM_REG_EDX, 1); gum_x86_writer_put_label (&cw, try_again_label); gum_x86_writer_put_mov_reg_u32 (&cw, GUM_REG_EAX, 0); gum_x86_writer_put_lock_cmpxchg_reg_ptr_reg (&cw, GUM_REG_RCX, GUM_REG_EDX); gum_x86_writer_put_jcc_short_label (&cw, GUM_X86_JZ, beach_label, GUM_NO_HINT); gum_x86_writer_put_pause (&cw); gum_x86_writer_put_jmp_short_label (&cw, try_again_label); gum_x86_writer_put_label (&cw, beach_label); gum_x86_writer_put_ret (&cw); gum_x86_writer_free (&cw); }
static void test_code_writer_fixture_setup (TestCodeWriterFixture * fixture, gconstpointer data) { gum_x86_writer_init (&fixture->cw, fixture->output); gum_x86_writer_set_target_cpu (&fixture->cw, GUM_CPU_AMD64); gum_x86_writer_set_target_abi (&fixture->cw, GUM_ABI_WINDOWS); }
void lowlevel_helpers_init (void) { GumX86Writer cw; g_assert (clobber_test_function == NULL); clobber_test_function = GUM_POINTER_TO_FUNCPTR (ClobberTestFunc, gum_alloc_n_pages (1, GUM_PAGE_RWX)); gum_x86_writer_init (&cw, (gpointer) (gsize) clobber_test_function); gum_x86_writer_put_nop (&cw); gum_x86_writer_put_nop (&cw); gum_x86_writer_put_nop (&cw); gum_x86_writer_put_nop (&cw); gum_x86_writer_put_nop (&cw); gum_x86_writer_put_ret (&cw); gum_x86_writer_free (&cw); }
static void test_relocator_fixture_setup (TestRelocatorFixture * fixture, gconstpointer data) { guint page_size; guint8 stack_data[1] = { 42 }; GumAddressSpec as; page_size = gum_query_page_size (); as.near_address = (gpointer) stack_data; as.max_distance = G_MAXINT32 - page_size; fixture->output = (guint8 *) gum_alloc_n_pages_near (1, GUM_PAGE_RWX, &as); memset (fixture->output, 0, page_size); gum_x86_writer_init (&fixture->cw, fixture->output); }