Subject: Re: mmap() lossage??
To: Paul Kranenburg <pk@cs.few.eur.nl>
From: Brian C. Grayson <bgrayson@ece.utexas.edu>
List: netbsd-help
Date: 04/26/1997 12:51:12
Paul Kranenburg wrote:
> 
> >   Is there anything I am forgetting to do in this program?  I
> > thought munmap() should do everything I want.
> > 
> 
> > void * mmapalloc(size_t len) {
> >   void * p;
> >   p = (void*) mmap(0, len+0x0fff, PROT_READ|PROT_WRITE,
> 			    ^^^^^^
> 
> You're mapping more than you're unmapping later.
> 
> This not only keeps addresses (which you've not touched) in your process
> address space, but due to an artifact in the VM system, also holds on
> to the memory allocated for the one page (per iteration) that you do
> touch.

  Thanks a lot!  I had forgotten about that bit of code.  At some
point, I thought I had seen that if one tried to mmap 10 bytes,
future accesses to that region would segfault, so I added that
+0xfff so that at least one full page would always be allocated. 
Now that I try mmap() with 10 bytes, it works, so there must
have been another bug at the time that I removed between now
and then.

  Brian
-- 
Brian Grayson (bgrayson@ece.utexas.edu)
Graduate Student, Electrical and Computer Engineering
The University of Texas at Austin
Office:  ENS 406       (512) 471-8011
Finger bgrayson@orac.ece.utexas.edu for PGP key.