From dim@tensor.xs4all.nl  Wed Nov 12 11:52:47 2003
Return-Path: <dim@tensor.xs4all.nl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 10F6916A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Nov 2003 11:52:47 -0800 (PST)
Received: from tensor.xs4all.nl (tensor.xs4all.nl [194.109.160.97])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6207743FA3
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 12 Nov 2003 11:52:46 -0800 (PST)
	(envelope-from dim@tensor.xs4all.nl)
Received: by tensor.xs4all.nl (Postfix, from userid 1000)
	id E974F2285D; Wed, 12 Nov 2003 20:52:44 +0100 (CET)
Message-Id: <20031112195244.E974F2285D@tensor.xs4all.nl>
Date: Wed, 12 Nov 2003 20:52:44 +0100 (CET)
From: Dimitry Andric <dim@tensor.xs4all.nl>
Reply-To: Dimitry Andric <dimitry@andric.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: munmap semantics change break cp (and possibly other stuff)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         59225
>Category:       bin
>Synopsis:       munmap semantics change break cp (and possibly other stuff)
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 12 12:00:39 PST 2003
>Closed-Date:    Thu Nov 13 20:22:55 PST 2003
>Last-Modified:  Thu Nov 13 20:22:55 PST 2003
>Originator:     Dimitry Andric
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
n/a
>Environment:
System: FreeBSD tensor.xs4all.nl 5.1-CURRENT FreeBSD 5.1-CURRENT #0: Tue Nov 11 12:27:59 CET 2003 root@vfbsd5.dim:/usr/obj/usr/src/sys/TENSOR i386
>Description:
In the log for src/sys/vm/vm_map.c, rev 1.321, it says:
  - The Open Group Base Specifications Issue 6 specifies that an munmap(2)
    must return EINVAL if size is zero.  Submitted by: tegge

This breaks cp(2) on zero-sized files, since it uses mmap/munmap for
small (<8MB) files by default.

Note that there may be other programs which use mmapping of zero-sized
files, these will probably break too, unless they ignore munmap's
return value.
>How-To-Repeat:
- Upgrade to -CURRENT after Mon Nov 10 01:37:40 2003 UTC.
- Try to cp a zero-byte regular file.
- Observe error: "cp: Invalid argument".
>Fix:
The simplest fix is to disable the memory mapping stuff in cp, by
commenting the line:

  CFLAGS+= -DVM_AND_BUFFER_CACHE_SYNCHRONIZED

in src/bin/cp/Makefile. However, it would be nicer to fix it properly.
How that should be done, when mmap'ing zero bytes succeeds, but
munmap'ing it doesn't, isn't entirely clear... Maybe it's better to
wait until the mmap API stabilizes. :)
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: alc 
State-Changed-When: Thu Nov 13 20:21:43 PST 2003 
State-Changed-Why:  
Fix applied. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=59225 
>Unformatted:
