Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Jun 1999 21:41:26 -0700 (PDT)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Zhihui Zhang <zzhang@cs.binghamton.edu>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Implementation of mmap() in FreeBSD
Message-ID:  <199906270441.VAA09854@apollo.backplane.com>
References:   <Pine.GSO.3.96.990626230627.15421B-100000@sol.cs.binghamton.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
   This is how mmap() is supposed to work.  mmap() may return an area larger
   then the one you specified due to page-alignment considerations.  It is
   not legal for you to write in an area which is outside the range you
   specified, but there is no way for the machine to enforce this except
   on page boundries.  Any writes you do within the page boundry, but outside
   the range you specified in the mmap() call, but inside the bounds of the
   file, will probably end up in the file.

					-Matt


:>From the source code of mmap(), it seems to me that FreeBSD can not handle
:mmap() when the specified file range [offset, offset + length] does not
:align with memory page boundary.  The mmap() automatically enlarges the
:mapped area on BOTH ends of the given range to a page boundary.  In the
:following figure, the two X areas are not specified by the user, they are
:included because we do rounding on both ends.
:
:       +---+----------+---------+-----+
:       | X |          |         |  X  |
:       +---+----------+---------+-----+
:       ^              ^               ^
:       |              |               |
:     page boundary  page boundary   page boundary
:
:Then a problem is what will happen if I read/write at the areas marked as
:X?  What will happen if I write into the area marked by the right X and
:that area lies beyond the end of the file?  According to the book by
:W. Richard Stevens, if we write to the area marked by the right X, the
:changes should not be reflected in the file (or expand the file).
:...
:
:All these situations seem to me are not handled by FreeBSD mmap() code. I
:hope I am wrong. I also wonder why we can not add some information to the

    No machine's mmap() code handles these situations.  It is a side effect
    of the way MMU's work and the way mmap() was defined - that is, in order
    for mmap() to be reasonably optimal it has to munge the boundry
    conditions.  It is an explicitly allowed case.

:Any help or hint is appreciated.
:
:--------------------------------------------------
:Zhihui Zhang.  Please visit http://www.freebsd.org
:--------------------------------------------------

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199906270441.VAA09854>