Subject: Re: munmap(2) fails on previously mmaped large files
To: Nicolas Joly <njoly@pasteur.fr>
From: Antti Kantee <pooka@cs.hut.fi>
List: current-users
Date: 05/11/2007 22:35:22
On Fri May 11 2007 at 21:08:44 +0200, Nicolas Joly wrote:
> njoly@lanfeust [embl/blastwu]> ls -l embl.*
> -rw-r--r--  1 997  997  12882733250 May  9 00:17 embl.xnd
> -rw-r--r--  1 997  997  42205936685 May  9 00:17 embl.xns
> -rw-r--r--  1 997  997    914661870 May  9 00:17 embl.xnt
> 
> njoly@lanfeust [embl/blastwu]> ~/mmap ./embl.xnt 
> njoly@lanfeust [embl/blastwu]> ~/mmap ./embl.xnd
> mmap: munmap failed: Invalid argument
> njoly@lanfeust [embl/blastwu]> ~/mmap ./embl.xns
> mmap: munmap failed: Invalid argument
> 
> Here follow the ktrace output for the last command:
> 
>   8950      1 mmap     CALL  open(0x7f7fffffed19,0,0x7f7fffffeba0)
>   8950      1 mmap     NAMI  "./embl.xns"
>   8950      1 mmap     RET   open 3
>   8950      1 mmap     CALL  __fstat30(3,0x7f7fffffeaa0)
>   8950      1 mmap     RET   __fstat30 0
>   8950      1 mmap     CALL  mmap(0,0x9d3ab7c2d,1,1,3,0,0)
>   8950      1 mmap     RET   mmap 140145487806464/0x7f762a048000
>   8950      1 mmap     CALL  munmap(0x7f762a048000,0x9d3ab7c2d)
>   8950      1 mmap     RET   munmap -1 errno 22 Invalid argument

Does the following patch help?  FWIW, I have no idea why the check is
in there.

Index: uvm_mmap.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_mmap.c,v
retrieving revision 1.108
diff -u -p -r1.108 uvm_mmap.c
--- uvm_mmap.c	4 Mar 2007 06:03:48 -0000	1.108
+++ uvm_mmap.c	11 May 2007 19:34:10 -0000
@@ -664,8 +664,6 @@ sys_munmap(struct lwp *l, void *v, regis
 	size += pageoff;
 	size = (vsize_t)round_page(size);
 
-	if ((int)size < 0)
-		return (EINVAL);
 	if (size == 0)
 		return (0);

-- 
Antti Kantee <pooka@iki.fi>                     Of course he runs NetBSD
http://www.iki.fi/pooka/                          http://www.NetBSD.org/
    "la qualité la plus indispensable du cuisinier est l'exactitude"