Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Mark shared libraries private clean pages as non-writable on FreeBSD.
authorMatthieu Volat <mazhe@alkumuna.eu>
Fri, 25 Nov 2016 08:36:33 +0000 (09:36 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Mon, 28 Nov 2016 09:55:07 +0000 (10:55 +0100)
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

index fed4b2c..e55ae03 100644 (file)
@@ -209,15 +209,13 @@ XBT_PRIVATE std::vector<VmMap> 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<VmMap> 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);