« Return to Thread: mmap/munmap with zero length

Re: mmap/munmap with zero length

by Nate Eldredge-3 :: Rate this Message:

Reply to Author | View in Thread

On Sun, 5 Jul 2009, Alexander Best wrote:

> i'm wondering why mmap and munmap behave differently when it comes to a length
> argument of zero. allocating memory with mmap for a zero length file returns a
> valid pointer to the mapped region.
>
> munmap however isn't able to remove a mapping with no length.
>
> wouldn't it be better to either forbid this in mmap or to allow it in munmap?

POSIX has an opinion:

http://www.opengroup.org/onlinepubs/9699919799/functions/mmap.html

"If len is zero, mmap() shall fail and no mapping shall be established."

http://www.opengroup.org/onlinepubs/9699919799/functions/munmap.html

"The munmap() function shall fail if:
...
[EINVAL]
     The len argument is 0."


--

Nate Eldredge
neldredge@...
_______________________________________________
freebsd-hackers@... mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@..."

 « Return to Thread: mmap/munmap with zero length