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

Function e9scratch

src/e9patch/e9loader_elf.cpp:159–172  ·  view source on GitHub ↗

* Allocate or get scratch. */

Source from the content-addressed store, hash-verified

157 * Allocate or get scratch.
158 */
159static NO_INLINE struct e9scratch_s *e9scratch(const e9_config_s *config,
160 bool alloc)
161{
162 uint8_t *loader_base = (uint8_t *)config;
163 uint8_t *scratch = loader_base - PAGE_SIZE;
164 if (!alloc)
165 return (struct e9scratch_s *)scratch;
166 intptr_t r = e9mmap(scratch, PAGE_SIZE, PROT_READ | PROT_WRITE,
167 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
168 r = (r >= 0 && r != (intptr_t)scratch? -EAGAIN: r);
169 if (r < 0)
170 e9panic("mmap() scratch failed (errno=%u)", (unsigned)-r);
171 return (struct e9scratch_s *)scratch;
172}
173
174typedef intptr_t (*mmap_t)(void *, size_t, int, int, int, off_t);
175typedef void (*init_t)(int, char **, char **, const void *, const void *);

Callers 2

e9handlerFunction · 0.85
e9initFunction · 0.85

Calls 2

e9mmapFunction · 0.85
e9panicFunction · 0.70

Tested by

no test coverage detected