From fb2e3453833f110f04a4920ca223d06cc14fe469 Mon Sep 17 00:00:00 2001 From: Matthieu Volat Date: Fri, 25 Nov 2016 09:36:33 +0100 Subject: [PATCH] Mark shared libraries private clean pages as non-writable on FreeBSD. This is how persmissions are with Linux, and later simgrid identifies mappings based on path and permissions, so the less restistance path is to present things more linux-like. --- src/xbt/memory_map.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/xbt/memory_map.cpp b/src/xbt/memory_map.cpp index fed4b2c572..e55ae03514 100644 --- a/src/xbt/memory_map.cpp +++ b/src/xbt/memory_map.cpp @@ -209,15 +209,13 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) memreg.end_addr = vmentries[i].kve_end; /* Permissions */ - memreg.prot = 0; + memreg.prot = PROT_NONE; if (vmentries[i].kve_protection & KVME_PROT_READ) memreg.prot |= PROT_READ; if (vmentries[i].kve_protection & KVME_PROT_WRITE) memreg.prot |= PROT_WRITE; if (vmentries[i].kve_protection & KVME_PROT_EXEC) memreg.prot |= PROT_EXEC; - if (memreg.prot == 0) - memreg.prot |= PROT_NONE; /* Private (copy-on-write) or shared? */ if (vmentries[i].kve_flags & KVME_FLAG_COW) @@ -250,6 +248,16 @@ XBT_PRIVATE std::vector get_memory_map(pid_t pid) && vmentries[i].kve_flags & KVME_FLAG_GROWS_DOWN) memreg.pathname = "[stack]"; + /* + * One last dirty modification: remove write permission from shared + * libraries private clean pages. This is necessary because simgrid + * later identifies mappings based on the permissions that are expected + * when running the Linux kernel. + */ + if (vmentries[i].kve_type == KVME_TYPE_VNODE + && ! (vmentries[i].kve_flags & KVME_FLAG_NEEDS_COPY)) + memreg.prot &= ~PROT_WRITE; + ret.push_back(std::move(memreg)); } procstat_freevmmap(prstat, vmentries); -- 2.20.1