MCPcopy Create free account
hub / github.com/GJDuck/e9patch / InstrSet

Method InstrSet

src/e9patch/e9misc.cpp:44–72  ·  view source on GitHub ↗

* Instruction set constructor. */

Source from the content-addressed store, hash-verified

42 * Instruction set constructor.
43 */
44InstrSet::InstrSet()
45{
46 static uintptr_t base = 0x0;
47 if (base == 0x0)
48 {
49 base = BASE;
50 uintptr_t r;
51 syscall(SYS_getrandom, &r, sizeof(r), 0);
52 base |= (r & MASK);
53 base -= (base % PAGE_SIZE);
54 }
55 else
56 base += INC;
57
58 ub = (Instr *)base;
59 ub--; // Allocate sentinel.
60 lb = ub;
61
62 base -= extend * PAGE_SIZE;
63 errno = 0;
64 void *ptr = mmap((void *)base, extend * PAGE_SIZE, PROT_READ | PROT_WRITE,
65 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
66 if (ptr != (void *)base && errno != 0)
67 error("failed to allocate instruction buffer: %s", strerror(errno));
68 if (ptr != (void *)base && errno == 0)
69 error("failed to allocate instruction buffer; expected %p, got %p",
70 (void *)base, ptr);
71 limit = ptr;
72}
73
74/*
75 * Instruction set allocate.

Callers

nothing calls this directly

Calls 3

mmapFunction · 0.85
errorFunction · 0.85
strerrorFunction · 0.85

Tested by

no test coverage detected