hi,
I am not sure if this is the proper list to ask this question. If not, I would appreciate if you can point me to the right place.
I am going to use pread64 open file as /proc/(pid)/mem, but failed with EIO error. The following is my code:
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <
string.h>
int main(void)
{
char *buf;
char filename[64];
int fd, len;
buf = (char *)malloc(4096);
sprintf (filename, "/proc/%d/mem", getpid());
fd = open64 (filename, O_RDONLY | O_LARGEFILE);
len = pread64(fd, buf, 52, 0xFFFFE000);
printf("len=%d\n", len);
}
The code is compiled with -D_FILE_OFFSET_BITS=64. But I still cannot get the pread64 from strace message. The following is the strace message I got.
> strace ./bar
execve("./bar", ["./bar"], [/* 55 vars */]) = 0
uname({sys="Linux", node="neocenter.unl.edu", ...}) = 0
brk(0) = 0x804a000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("tls/i686/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("i686/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/i686/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/tls/i686/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/tls/i686", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/tls/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/tls", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/i686/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/i686/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/i686", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/local/lib", {st_mode=S_IFDIR|0755, st_size=28672, ...}) = 0
open("/usr/lib/tls/i686/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/tls/i686/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/tls/i686", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/tls/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/tls/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/tls", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/i686/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/i686/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/i686", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib/sse2", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib", {st_mode=S_IFDIR|0755, st_size=98304, ...}) = 0
open("/usr/lib64/tls/i686/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib64/tls/i686/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib64/tls/i686", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib64/tls/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib64/tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib64/tls", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib64/i686/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib64/i686/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib64/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib64/i686", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib64/sse2/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib64/sse2", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/usr/lib64", 0xbfac9c18) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=98896, ...}) = 0
old_mmap(NULL, 98896, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f76000
close(3) = 0
open("/lib/tls/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 \3376\000"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1512400, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f75000
old_mmap(0x359000, 1207532, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x359000
old_mmap(0x47a000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x120000) = 0x47a000
old_mmap(0x47e000, 7404, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x47e000
close(3) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f74000
mprotect(0x47a000, 8192, PROT_READ) = 0
mprotect(0x355000, 4096, PROT_READ) = 0
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7f746c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
munmap(0xb7f76000, 98896) = 0
brk(0) = 0x804a000
brk(0x806c000) = 0x806c000
getpid() = 17545
open("/proc/17545/mem", O_RDONLY|O_LARGEFILE) = 3
pread(3, 0x804a008, 52, 4294959104) = -1 EIO (Input/output error)
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 7), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f8e000
write(1, "len=-1\n", 7len=-1
) = 7
munmap(0xb7f8e000, 4096) = 0
exit_group(7) = ?
My system information: (2.6.20-rc6) the latest kernel on Intel i386 32bit machine
> /lib/libc.so.6
GNU C Library stable release version 2.3.3, by Roland McGrath et al.
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3).
Compiled on a Linux 2.4.20 system on 2004-10-27.
Available extensions:
GNU libio by Per Bothner
crypt add-on version 2.1 by Michael Glad and others
linuxthreads-0.10 by Xavier Leroy
The C stubs add-on version 2.1.2.
BIND-8.2.3-T5B
NIS(YP)/NIS+ NSS modules
0.19 by Thorsten Kukuk
Glibc-2.0 compatibility add-on by Cristian Gafton
GNU Libidn by Simon Josefsson
libthread_db work sponsored by Alpha Processor Inc
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
Thanks,
Neo
--
I would remember that if researchers were not ambitious
probably today we haven't the technology we are using!