static GumCodePage * gum_code_allocator_new_page_near (GumCodeAllocator * self, gpointer address) { GumPageProtection prot; GumAddressSpec spec; GumCodePage * cp; guint slice_idx; prot = gum_query_is_rwx_supported () ? GUM_PAGE_RWX : GUM_PAGE_RW; spec.near_address = address; spec.max_distance = GUM_CODE_ALLOCATOR_MAX_DISTANCE; cp = (GumCodePage *) gum_alloc_n_pages_near (1, prot, &spec); for (slice_idx = 0; slice_idx != self->slices_per_page; slice_idx++) { GumCodeSlice * slice = &cp->slice[slice_idx]; slice->data = (guint8 *) cp + self->header_size + (slice_idx * self->slice_size); slice->size = self->slice_size; gum_code_slice_mark_free (slice); } return cp; }
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); }