Skip to content

Commit

Permalink
Make mremap work after PR_SET_VMA_ANON_NAME.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuey committed Jun 2, 2024
1 parent 3f251e0 commit 7c5846e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/AddressSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class KernelMapping : public MemoryRange {
bool is_stack() const { return fsname().find("[stack") == 0; }
bool is_vvar() const { return fsname() == "[vvar]"; }
bool is_vsyscall() const { return fsname() == "[vsyscall]"; }
bool is_named_anonymous() const {
return fsname().find("[anon:") == 0 || fsname().find("[anon_shmem:") == 0;
}

struct stat fake_stat() const {
struct stat fake_stat;
Expand Down
3 changes: 2 additions & 1 deletion src/replay_syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,8 @@ static void process_mremap(ReplayTask* t, const TraceFrame& trace_frame,
auto f = mapping.emu_file;
if (f) {
f->ensure_size(mapping.map.file_offset_bytes() + new_size);
} else if (new_size > old_size && mapping.map.fsname().size() > 0) {
} else if (new_size > old_size && mapping.map.fsname().size() > 0 &&
!mapping.map.is_named_anonymous()) {
struct stat st;
int ret = stat(mapping.map.fsname().c_str(), &st);
if (ret != 0) {
Expand Down
8 changes: 8 additions & 0 deletions src/test/prctl_anon_vma_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ int main(void) {
test_assert(p2 != MAP_FAILED);
ret = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, p, page_size*4, "ghi");
test_assert(ret == -1 && errno == EBADF);

char* p3 = (char*)mmap(NULL, page_size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | (i ? MAP_SHARED : MAP_PRIVATE), -1, 0);
test_assert(p != MAP_FAILED);

ret = prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, p3, page_size, "don't blow up");
test_assert(ret == 0);
p3 = mremap(p3, page_size, 2*page_size, MREMAP_MAYMOVE);
}

atomic_puts("EXIT-SUCCESS");
Expand Down

0 comments on commit 7c5846e

Please sign in to comment.