MCPcopy Index your code
hub / github.com/GJDuck/e9patch / alloc

Method alloc

src/e9patch/e9misc.cpp:77–100  ·  view source on GitHub ↗

* Instruction set allocate. */

Source from the content-addressed store, hash-verified

75 * Instruction set allocate.
76 */
77void *InstrSet::alloc()
78{
79 lb--;
80 Instr *I = lb;
81 Instr *S = I - 1;
82
83 if ((void *)S < limit)
84 {
85 intptr_t base = (uintptr_t)limit;
86 extend = (extend >= 256? 256: 2 * extend);
87 base -= extend * PAGE_SIZE;
88 errno = 0;
89 void *ptr =
90 mmap((void *)base, extend * PAGE_SIZE, PROT_READ | PROT_WRITE,
91 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
92 if (ptr != (void *)base && errno != 0)
93 error("failed to extend instruction buffer: %s", strerror(errno));
94 if (ptr != (void *)base && errno == 0)
95 error("failed to extend instruction buffer; expected %p, got %p",
96 (void *)base, ptr);
97 limit = ptr;
98 }
99 return (void *)I;
100}
101
102/*
103 * Find the first instruction >= the offset.

Callers 1

parseInstructionFunction · 0.80

Calls 3

mmapFunction · 0.85
errorFunction · 0.85
strerrorFunction · 0.85

Tested by

no test coverage detected