From eb162ff79b93ea98380f4555e0fe3116993241fb Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 23 Jul 2009 14:05:41 +0200 Subject: [apt-pkg] yet another bit of mmap and pkgcachegen housekeeping * add mmap error message also to the dynamic mmap * remove some more {Ver,Desc} == 0 checks in for loops * try to respect the given flags to the dynamic mmap * open cached caches not as ReadOnly and not as Shared, so we always have a copy of the cache in the memory we can modify (e.g. set the hold state on-the-fly) --- apt-pkg/contrib/mmap.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'apt-pkg/contrib/mmap.cc') diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index ba4482131..aa52b4c30 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -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; } /*}}}*/ -- cgit v1.2.3