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

Function emitLoaderMap

src/e9patch/e9elf.cpp:332–366  ·  view source on GitHub ↗

* Emit a mapping. */

Source from the content-addressed store, hash-verified

330 * Emit a mapping.
331 */
332size_t emitLoaderMap(uint8_t *data, intptr_t addr, size_t len, off_t offset,
333 bool r, bool w, bool x, uint32_t type, intptr_t *ub)
334{
335 bool abs = IS_ABSOLUTE(addr);
336 if (ub != nullptr && !abs)
337 *ub = std::max(*ub, addr);
338 addr = BASE_ADDRESS(addr);
339
340 size_t size = 0;
341 struct e9_map_s *map = (struct e9_map_s *)data;
342 size += sizeof(struct e9_map_s);
343
344 addr /= (intptr_t)PAGE_SIZE;
345 len /= PAGE_SIZE;
346 offset /= PAGE_SIZE;
347
348 if (addr < INT32_MIN || addr > INT32_MAX)
349 error("mapping address (" ADDRESS_FORMAT ") %sflow detected",
350 ADDRESS(addr), (addr < 0? "under": "over"));
351 if (len >= (1 << 21))
352 error("mapping size (%zu) overflow detected", len);
353 if (offset > UINT32_MAX)
354 error("mapping offset (%+zd) overflow detected", offset);
355
356 map->addr = (int32_t)addr;
357 map->offset = (uint32_t)offset;
358 map->size = (uint16_t)len;
359 map->type = type;
360 map->r = (r? 1: 0);
361 map->w = (w? 1: 0);
362 map->x = (x? 1: 0);
363 map->abs = (abs? 1: 0);
364
365 return size;
366}
367
368/*
369 * Get the offset for an address.

Callers 2

emitElfFunction · 0.85
emitPEFunction · 0.85

Calls 1

errorFunction · 0.85

Tested by

no test coverage detected