[PATCH 0.9.33 0/7] Backport pread/pwrite fixes from master

Rich Felker dalias at aerifal.cx
Wed Aug 29 15:10:36 UTC 2012


On Wed, Aug 29, 2012 at 04:50:37PM +0200, Natanael Copa wrote:
> On Wed, Aug 29, 2012 at 2:42 PM, Johannes Stezenbach <js at sig21.net> wrote:
> > Hi Natanael,
> >
> > On Wed, Aug 29, 2012 at 09:18:57AM +0000, Natanael Copa wrote:
> >> I previously sent a bug report for pread/pwrite with a link to a
> >> patch that i hacked up quick and dirty. This showed up to be severly
> >> broken on x86_64 and corrupted several qemu disks images for me.
> >>
> >> I see that this bad patch made it into 0.9.33 stabel tree. I think it
> >> should be reverted and instead use cherry-picks from master. This is
> >> what we currently use with success in Alpine Linux.
> >>
> >> Tested on x86_64 and x86.
> >
> > I just built a toolchain for ARM from 0.9.33 stable branch
> > and I'm trying to figure out if the breakage is x86_64 only.
> > could you give more details what breaks and why?
> 
> It is only 64bit that is broke. On 64bit it should be an alias to the
> pread64/pwrite64 syscalls and not do the offset hi/lo stuff like it
> need to do on 32bit. The result was that offsets bigger than 4G (or
> 2G?) got cutted. Typical 64 bit vs 32 bit bug.

You might take a look at how we do it in musl; it's much simpler:

http://git.etalabs.net/cgi-bin/cgit.cgi?url=musl/tree/src/unistd/pread.c

The definition of __SYSCALL_LL_O expands correctly to put the long
long argument at the right slots for the target arch where there are
an odd number of arguments before the long long argument (it might
expand to a single long, for 64-bit archs, two longs, for 32-bit archs
with no alignment requirement, or 3 longs, the first being zero, for
32-bit archs where 64-bit arguments must be aligned on an even slot.

The same macro works for most syscalls that take long long arguments.

Rich


More information about the uClibc mailing list