]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/mmap.cc
merge with lp:apt/debian-sid
[apt.git] / apt-pkg / contrib / mmap.cc
index 229b18037c149ef2353ec2d5e4476e5f5704e0d7..aa52b4c3066ef923ee5c622a98f77a21c0714622 100644 (file)
@@ -137,7 +137,6 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop)
 }
                                                                        /*}}}*/
 
-                                                                       /*}}}*/
 // DynamicMMap::DynamicMMap - Constructor                              /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -173,11 +172,19 @@ DynamicMMap::DynamicMMap(unsigned long Flags,unsigned long WorkSpace) :
       return;
 
 #ifdef _POSIX_MAPPED_FILES
+   // Set the permissions.
+   int Prot = PROT_READ;
+   int Map = MAP_PRIVATE | MAP_ANONYMOUS;
+   if ((Flags & ReadOnly) != ReadOnly)
+      Prot |= PROT_WRITE;
+   if ((Flags & Public) == Public)
+      Map = MAP_SHARED | MAP_ANONYMOUS;
+
    // use anonymous mmap() to get the memory
-   Base = (unsigned char*) mmap(0, WorkSpace, PROT_READ|PROT_WRITE,
-                                MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+   Base = (unsigned char*) mmap(0, WorkSpace, Prot, Map, -1, 0);
+
    if(Base == MAP_FAILED)
-      return;
+      _error->Errno("DynamicMMap",_("Couldn't make mmap of %lu bytes"),WorkSpace);
 #else
    // fallback to a static allocated space
    Base = new unsigned char[WorkSpace];
@@ -194,7 +201,7 @@ DynamicMMap::~DynamicMMap()
    if (Fd == 0)
    {
 #ifdef _POSIX_MAPPED_FILES
-      if(munmap(Base, WorkSpace) < 0)
+      munmap(Base, WorkSpace);
 #else
       delete [] (unsigned char *)Base;
 #endif