175 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
35 lines
1.4 KiB
C
35 lines
1.4 KiB
C
#include "realm_seam_page.h"
|
|
|
|
static int lazy_protected(const struct GwRealmInstallDiagnostic *page)
|
|
{
|
|
return page->page_query_bytes == sizeof(MEMORY_BASIC_INFORMATION) &&
|
|
page->page_state == MEM_COMMIT &&
|
|
page->page_protect == PAGE_NOACCESS &&
|
|
page->page_type == MEM_MAPPED &&
|
|
page->page_identity_bits == 7u;
|
|
}
|
|
|
|
int gw_realm_seam_page_prepare(uintptr_t site, size_t bytes, uintptr_t ret_stub,
|
|
GwRealmSeamProbe probe, volatile LONG *touch_once,
|
|
struct GwRealmInstallDiagnostic *out, int *touched)
|
|
{
|
|
struct GwRealmInstallDiagnostic page = {0};
|
|
if (touched) *touched = 0;
|
|
if (!probe || !out) return 2;
|
|
probe(site, bytes, &page);
|
|
if (lazy_protected(&page) && ret_stub && touch_once &&
|
|
(ret_stub & ~(uintptr_t)0xfff) == (site & ~(uintptr_t)0xfff) &&
|
|
InterlockedCompareExchange(touch_once, 1, 0) == 0) {
|
|
/* The pinned original byte at ret_stub is a lone C3 (seam epilogue
|
|
* 48 83 c4 40 5f c3); the existing pipe-return thunk already resumes
|
|
* there. Executing it changes no state besides the client's own
|
|
* first-execution page handling. */
|
|
((void (*)(void))ret_stub)();
|
|
if (touched) *touched = 1;
|
|
page = (struct GwRealmInstallDiagnostic){0};
|
|
probe(site, bytes, &page);
|
|
}
|
|
*out = page;
|
|
return lazy_protected(&page) ? 2 : 1;
|
|
}
|