[uClibc]bug with mmap64

Aurelien JACOBS aurel at gnuage.org
Thu May 15 23:25:44 UTC 2003


Hello,

I've encountered a bug with the mmap function (which is in fact mmap64).
This bug appear with mplayer and particularly the vidix drivers part of
mplayer. The particularity of this is that it try to mmap the file
/dev/mem
with an offset greater than 2GB (but less than 4GB) to directly access
the
memory of the video card.

Your implementation (libc/sysdeps/linux/common/mmap64) begin with this
test:

__ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd,
               __off64_t offset)
{
    if (offset != (off_t) offset || (offset + len) != (off_t) (offset +
len))
    {
        __set_errno (EINVAL);
        return MAP_FAILED;
    }

The problem is that offset is first shortened from 64 bits to 32 bits
and then it is re-expended to 64 bits to do the comparison.
As off_t is a signed type, ((off_t) offset) is negative and the
expansion
to 64 bits keep the sign giving a negative 64 bits number which is
obviously
not equal to offset.

I tried to remove this 'if' from mmap64 and then it worked very nicely.
I don't know if this test is useful in some way (but if you've done it,
it should :-).

So the question is maybe if mmap should really consider offset as a
signed
integer, but as mplayer is working perfectly with the glibc, I assume
that
what it does is valid and so the mmap should be able to use an offset
greater than 2GB.

I hope you will find a proper fix.
Anyway, Thanks for your great work on this great lib.

Aurelien Jacobs


More information about the uClibc mailing list