* Allocate or get scratch. */
| 157 | * Allocate or get scratch. |
| 158 | */ |
| 159 | static 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 | |
| 174 | typedef intptr_t (*mmap_t)(void *, size_t, int, int, int, off_t); |
| 175 | typedef void (*init_t)(int, char **, char **, const void *, const void *); |