]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/mmap.cc
* cmdline/apt-get.cc:
[apt.git] / apt-pkg / contrib / mmap.cc
index ba4482131d4c1fd7b5ddc4388d3b16c9b93ed0a1..4d5fcf71e67c5bdda2ddf504cf9c39c90d0d1ed9 100644 (file)
@@ -137,7 +137,6 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop)
 }
                                                                        /*}}}*/
 
-                                                                       /*}}}*/
 // DynamicMMap::DynamicMMap - Constructor                              /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -173,15 +172,24 @@ 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);
-   if(Base != MAP_FAILED)
-      return;
-#endif
+   Base = (unsigned char*) mmap(0, WorkSpace, Prot, Map, -1, 0);
+
+   if(Base == MAP_FAILED)
+      _error->Errno("DynamicMMap",_("Couldn't make mmap of %lu bytes"),WorkSpace);
+#else
    // fallback to a static allocated space
    Base = new unsigned char[WorkSpace];
    memset(Base,0,WorkSpace);
+#endif
    iSize = 0;
 }
                                                                        /*}}}*/
@@ -309,7 +317,7 @@ unsigned long DynamicMMap::WriteString(const char *String,
    but why we should not at least try to grow it before we give up? */
 bool DynamicMMap::Grow()
 {
-#ifdef _POSIX_MAPPED_FILES
+#if defined(_POSIX_MAPPED_FILES) && defined(__linux__)
    unsigned long newSize = WorkSpace + 1024*1024;
 
    if(Fd != 0)