From owner-freebsd-hackers Sat Jun 26 21:41:30 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from apollo.backplane.com (apollo.backplane.com [209.157.86.2]) by hub.freebsd.org (Postfix) with ESMTP id AE12014DC7 for ; Sat, 26 Jun 1999 21:41:28 -0700 (PDT) (envelope-from dillon@apollo.backplane.com) Received: (from dillon@localhost) by apollo.backplane.com (8.9.3/8.9.1) id VAA09854; Sat, 26 Jun 1999 21:41:26 -0700 (PDT) (envelope-from dillon) Date: Sat, 26 Jun 1999 21:41:26 -0700 (PDT) From: Matthew Dillon Message-Id: <199906270441.VAA09854@apollo.backplane.com> To: Zhihui Zhang Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Implementation of mmap() in FreeBSD References: Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message