On Wednesday 2023-03-01 16:42, Antonio Diaz Diaz wrote: >> >> $ strace -fe lseek ddrescue -f /proc/self/mem /dev/zero -s $[0x4040] >> ... >> lseek(3, 0, SEEK_END) = -1 EINVAL (Invalid argument) >> ... >> >> procfs is known to be... special. What is your opinion, is it worth >> making this work? > > Maybe it is worth, but I don't know how to make it work. 'dd' does not work > either: > $ dd if=/proc/self/mem of=/dev/zero > dd: error reading '/proc/self/mem': Input/output error
dd fails to work for a different reason. (Judging from strace output alone without source review), it uses fstat() instead of lseek(SEEK_END) to determine the file size -- and then gets confused because stat.st_size < lseek: $ strace -f dd if=/proc/self/mem of=/dev/zero skip=$[0x4000] ... lseek(0, 16384, SEEK_CUR) = 16384 newfstatat(0, "", {st_mode=S_IFREG|0600, st_size=0, ...}, AT_EMPTY_PATH) = 0 cannot skip to specified offset > In fact, nothing seems to work with /proc/self/mem: > $ cat /proc/self/mem > /dev/zero > cat: /proc/self/mem: Input/output error The prerequisite for the special file is that one must seek to a position where something is mapped. Offset 0, corresponding to mapping address 0x0, is seldomly mapped. > $ file /proc/self/mem > /proc/self/mem: empty Once again a result of checking st_size. As said, st_size is 0 because the size of the process cannot be determined. (Well, it *could* be determined, but perhaps it's seen as "too expensive" to count all segments whenever the file is stat'ed.)