uClibc Digest, Vol 21, Issue 11

Michel Benoit murpme at gmail.com
Fri Apr 13 17:42:13 UTC 2007


> /* check if offset is page aligned */
>     if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
>         return MAP_FAILED;
>   return (__ptr_t) _mmap (addr, len, prot, flags,
>                                                   fd,(off_t) (((1 <<
> MMAP2_PAGE_SHIFT) -1 )&(offset >> MMAP2_PAGE_SHIFT)))
>
>

The right shift operation here is arithmetic not logical.  The type
off_t is signed so with offset set t0 0xFxxxx000 an invalid value is
sent to mmap().  The idea of the shift is to send teh page offset.  If
you run your program with strace you will see that mmap2() is called
with a bogus value 0xFFFFxxxx instead of 0x000Fxxxx.

Try this:

 * check if offset is page aligned */
     if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
         return MAP_FAILED;
   return (__ptr_t) _mmap (addr, len, prot, flags,
                                                   fd,(off_t)
((unsigned int)offset >> MMAP2_PAGE_SHIFT)))

Also have a look at the linux arm newsgroup where this issue has been
discussed in a number of different threads.

Michel



More information about the uClibc mailing list