* Instruction set allocate. */
| 75 | * Instruction set allocate. |
| 76 | */ |
| 77 | void *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. |
no test coverage detected