* Emit a mapping. */
| 330 | * Emit a mapping. |
| 331 | */ |
| 332 | size_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. |