Skip to content

Commit

Permalink
Merge pull request #2847 from krzycz/pmem-duplicate
Browse files Browse the repository at this point in the history
pmem: do not crash if duplicated pmem entry found
  • Loading branch information
krzycz authored Apr 12, 2018
2 parents 8a8522b + a64ace4 commit 42959a3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/common/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,13 @@ util_range_register(const void *addr, size_t len, const char *path,
LOG(3, "addr %p len %zu path %s type %d", addr, len, path, type);

/* check if not tracked already */
ASSERTeq(util_range_find((uintptr_t)addr, len), NULL);
if (util_range_find((uintptr_t)addr, len) != NULL) {
ERR(
"duplicated persistent memory range; presumably unmapped with munmap() instead of pmem_unmap(): addr %p len %zu",
addr, len);
errno = ENOMEM;
return -1;
}

struct map_tracker *mt;
mt = Malloc(sizeof(struct map_tracker));
Expand Down
6 changes: 5 additions & 1 deletion src/test/pmem_is_pmem_posix/TEST4
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ expect_normal_exit ./pmem_is_pmem_posix$EXESUFFIX\
t 0x000000020000 0x10000\
t 0x000000030000 0x10000\
t 0x000000040000 0x10000\
t 0x000000010000 0x40000
t 0x000000010000 0x40000\
a 0x000000030000 0x20000 DEV_DAX\
a 0x000000020000 0x20000 DEV_DAX\
t 0x000000030000 0x20000\
t 0x000000020000 0x20000

check

Expand Down
3 changes: 3 additions & 0 deletions src/test/pmem_is_pmem_posix/out4.log.match
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ addr 0x20000 len 65536 is_pmem 0
addr 0x30000 len 65536 is_pmem 0
addr 0x40000 len 65536 is_pmem 0
addr 0x10000 len 262144 is_pmem 0
duplicated persistent memory range; presumably unmapped with munmap() instead of pmem_unmap(): addr 0x20000 len 131072
addr 0x30000 len 131072 is_pmem 1
addr 0x20000 len 131072 is_pmem 0
pmem_is_pmem_posix/TEST4: DONE
3 changes: 2 additions & 1 deletion src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ main(int argc, char *argv[])
case 'a':
ret = util_range_register(addr, len, "",
str2type(argv[i + 3]));
UT_ASSERTeq(ret, 0);
if (ret != 0)
UT_OUT("%s", pmem_errormsg());
i += 4;
break;
case 'r':
Expand Down

0 comments on commit 42959a3

Please sign in to comment.