this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mldr: Unmap reservation before mapping in actual contents

This is necessary as a result of the changes from 0e552ab5454c6c45005f0e8abfa34323c6025d3a.
We do want to make sure we don't replace any previous memory we didn't
load ourselves, so in order to keep that, we just unmap the memory we reserve,
since there's no race condition like there could have been when we were
doing this in the LKM. No one else can be allocating memory in our
process but us.

+9 -1
+9 -1
src/startup/mldr/loader.c
··· 123 123 exit(1); 124 124 } 125 125 126 + // unmap it so we can map the actual segments later using MAP_FIXED_NOREPLACE; 127 + // we're the only thread running, so there's no chance this memory range will become occupied from now until then 128 + munmap((void*)slide, mmapSize); 129 + 126 130 if (slide + mmapSize > lr->vm_addr_max) 127 131 lr->vm_addr_max = lr->base = slide + mmapSize; 128 132 slide -= base; ··· 196 200 if (seg->filesize > 0) 197 201 { 198 202 unsigned long addr = seg->vmaddr + slide; 203 + int flag = MAP_FIXED_NOREPLACE; 204 + if (seg->filesize < seg->vmsize) { 205 + flag = MAP_FIXED; 206 + } 199 207 rv = mmap((void*)addr, seg->filesize, useprot, 200 - MAP_FIXED_NOREPLACE | MAP_PRIVATE, fd, seg->fileoff + fat_offset); 208 + flag | MAP_PRIVATE, fd, seg->fileoff + fat_offset); 201 209 if (rv == (void*)MAP_FAILED) 202 210 { 203 211 fprintf(stderr, "Cannot mmap segment %s at %p: %s\n", seg->segname, (void*)(uintptr_t)seg->vmaddr, strerror(errno));