Skip to contentSkip to conversation

Advice for 32 bit compatibility problem with pread(2) on x86_64

DISCUSSION Earl Chew 1 participant 1 message Jan 18, 2012

lore
Share & tools
lore

Earl Chew

author
#0 lore raw

pread(2) in 32 bit mode (x86_64) seems to leave the file in a crummy state causing the next pread(2) to fail.

I'd like a hint as to where to look for the root cause.

I'm running:

	Linux ixbu-lnxbld-vm 2.6.32-33-generic #72-Ubuntu SMP Fri Jul 29 21:07:13 UTC 2011 x86_64 GNU/Linux

Here is the test program (use syscall() to try give glibc an alibi):

Quoted 5 lines

#include <fcntl.h>
#include <sys/syscall.h>

int main()

Quoted 9 lines
{
    char buf[8192];
    int fd = open("/proc/self/maps", O_RDONLY);

    syscall(SYS_pread64, fd, buf, 8192, 0, 0);
    syscall(SYS_pread64, fd, buf, 8192, 0, 0);

    return 0;
}

Compiling with -m32 and running with strace(), the 2nd pread() return zero !

Quoted 3 lines

open("/proc/self/maps", O_RDONLY) = 3
pread64(3, "08048000-08049000 r-xp 00000000 "..., 8192, 0) = 1189
pread64(3, "", 8192, 0) = 0

Compiling for 64 bit I get the expected:

Quoted 3 lines

open("/proc/self/maps", O_RDONLY) = 3
pread(3, "00400000-00401000 r-xp 00000000 "..., 8192, 0) = 1332 pread(3, "00400000-00401000 r-xp 00000000 "..., 8192, 0) = 1332

Huh ?

Earl