apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sander Striker" <stri...@apache.org>
Subject RE: mmap bug?
Date Thu, 27 Feb 2003 15:14:50 GMT
> From: Jeff Trawick [mailto:trawick@attglobal.net]
> Sent: Thursday, February 27, 2003 2:41 PM

> Sander Striker wrote:
[...]
>>   rv = apr_mmap_delete(mm);
>>
>>   [failure, rv == 22 (EINVAL?)]
>>
>> My guess is that munmap doesn't like the 0 passed in for size.  It
>> strikes me as odd though that mmap doesn't seem to care about that.
>>
>> Is there a known issue with mmapping 0 sized files?
>>
>> FYI, I'm on Linux 2.4.20, glibc 2.3.1.
> 
> does strace show that it is kernel behavior in question rather than 
> something questionable that APR may be doing?

Something questionable at both ends ;)

kernel returns NULL on an mmap of a 0 sized file (even though the mmap
manpage tells us that'll never happen):
mmap2(NULL, 0, PROT_READ, MAP_SHARED, 5, 0) = 0

apr calls this on apr_mmap_delete (because it stored the NULL in apr_mmap_t.mm):
munmap(0, 0)                            = -1 EINVAL (Invalid argument)


This patch seems like a working fix:

Index: mmap/unix/mmap.c
===================================================================
RCS file: /home/cvs/apr/mmap/unix/mmap.c,v
retrieving revision 1.47
diff -u -r1.47 mmap.c
--- mmap/unix/mmap.c    7 Jan 2003 00:52:55 -0000       1.47
+++ mmap/unix/mmap.c    27 Feb 2003 15:12:59 -0000
@@ -99,7 +99,10 @@
 #ifdef BEOS
     rv = delete_area(mm->area);
 #else
-    rv = munmap(mm->mm, mm->size);
+    if (mm->mm != NULL)
+      rv = munmap(mm->mm, mm->size);
+    else
+      rv = APR_SUCCESS;
 #endif
     mm->mm = (void *)-1;


Someone with some more mmap-fu, please review.

Thanks,

Sander

Mime
View raw message