public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Felix von Leitner <leitner@fefe.de>
To: linux-kernel@vger.kernel.org
Subject: question about pread
Date: Fri, 1 Dec 2000 02:23:52 +0100	[thread overview]
Message-ID: <20001201022352.C31770@convergence.de> (raw)

I am trying to implement pread for my diet libc.
This is my test program:

  #include <unistd.h>
  main() {
    char buf[1024];
    int fd=open("/etc/passwd",0);
    pread(fd,buf,30,32);
    close(fd);
    write(1,buf,32);
  }

I compiled it against diet libc and glibc and ran it on a powerpc box.
t is the test program linked against diet libc, t1 is the test program
linked against glibc.
Here is the result:

  $ strace ./t1
  execve("./t1", ["./t1"], [/* 19 vars */]) = 0
  brk(0)                                  = 0x100106a8
  mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x30014000
  open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or directory)
  open("/usr/local/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
  stat("/usr/local/lib", {st_mode=S_IFDIR|S_ISGID|0775, st_size=4096, ...}) = 0
  open("/usr/X11R6/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
  stat("/usr/X11R6/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
  open("/etc/ld.so.cache", O_RDONLY)      = 3
  fstat(3, {st_mode=S_IFREG|0644, st_size=9729, ...}) = 0
  mmap(NULL, 9729, PROT_READ, MAP_PRIVATE, 3, 0) = 0x30015000
  close(3)                                = 0
  open("/lib/libc.so.6", O_RDONLY)        = 3
  fstat(3, {st_mode=S_IFREG|0755, st_size=992080, ...}) = 0
  read(3, "\177ELF\1\2\1\0\0\0\0\0\0\0\0\0\0\3\0\24\0\0\0\1\0\2(\340"..., 4096) = 4096
  mmap(0xfeea000, 1072860, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xfeea000
  mprotect(0xffcb000, 151260, PROT_NONE)  = 0
  mmap(0xffda000, 69632, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0xe0000) = 0xffda000
  mmap(0xffeb000, 20188, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xffeb000
  close(3)                                = 0
  munmap(0x30015000, 9729)                = 0
  getpid()                                = 11304
  open("/etc/passwd", O_RDONLY)           = 3
  pread(3, "daemon:x:1:1:daemon:/usr/sbin:", 30, 137438953472) = 30
  close(3)                                = 0
  write(1, "daemon:x:1:1:daemon:/usr/sbin:j ", 32daemon:x:1:1:daemon:/usr/sbin:j ) = 32
  exit(32)                                = ?
  $ strace ./t
  execve("./t", ["./t"], [/* 19 vars */]) = 0
  open("/etc/passwd", O_RDONLY)           = 3
  pread(3, "", 30, 137438953472)          = 0
  close(3)                                = 0
  write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 32) = 32
  exit(32)                                = ?
  $

How can this be?  Both open the same file and call pread with the same arguments,
yet pread returns 30 for the glibc program and 0 for the diet libc one?!

Can anyone shed some light on this?  What exactly is the calling convention
for pread?  The diet libc pread code appears to work on x86 and sparc
but not on mips and ppc.

I used kernel 2.4.0-test10 on x86 and 2.2.17 on sparc and ppc, for what
it's worth.

stumped,

Felix
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

                 reply	other threads:[~2000-12-01  1:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20001201022352.C31770@convergence.de \
    --to=leitner@fefe.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox