Skip to content

Commit 79ff2c4

Browse files
popcornmixpelwell
authored andcommitted
vclog: Handle mmap pagesize properly
If the vclog is less aligned than the system pagesize vclog will fail. Handle the alignment requirements properly.
1 parent c172b48 commit 79ff2c4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

vclog/vclog.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,24 @@ static bool prepare_vc_mapping(uint32_t vc_start, uint32_t vc_size)
377377

378378
if ((fd = open(mem_filename, O_RDONLY)) >= 0)
379379
{
380-
vc_map = mmap(NULL, vc_size, PROT_READ, MAP_PRIVATE,
381-
fd, (uintptr_t)vc_start);
380+
long page_size = sysconf(_SC_PAGE_SIZE);
381+
382+
/* find start and end addresses aligned down and up to pagesize respectively */
383+
off_t mmap_start = (uintptr_t)vc_start & ~(page_size - 1);
384+
off_t mmap_end = ((uintptr_t)vc_start + vc_size + page_size - 1) & ~(page_size -1);
385+
386+
vc_map = mmap(NULL, mmap_end - mmap_start, PROT_READ, MAP_PRIVATE,
387+
fd, (uintptr_t)mmap_start);
382388
close(fd);
383389
if (vc_map != MAP_FAILED)
384390
{
385-
id = *(uint32_t *)vc_map;
391+
id = *(uint32_t *)(vc_map + vc_start - mmap_start);
386392
if (id == LOG_ID)
393+
{
394+
vc_start = mmap_start;
395+
vc_size = mmap_end - mmap_start;
387396
goto success;
397+
}
388398
}
389399
}
390400

0 commit comments

Comments
 (0)