-
-
Save azat/fcbd8b6c26afd505ae5f3387fc15f0e2 to your computer and use it in GitHub Desktop.
readlink qemu linux-user handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo arch-chroot ./ /qemu-x86_64-static /main | |
==> WARNING: ./ is not a mountpoint. This may have undesirable side effects. | |
readlink(/proc/self/exe) => /main (len: 5) | |
readlink(/proc/self) => 27679 (len: 5) | |
readlink(/proc/1/exe) => /main (len: 5) | |
realpath(/proc/self/exe) => /qemu-x86_64-static | |
AT_EXECFN = /main | |
$ sudo arch-chroot ./ /qemu-x86_64-static -strace /main | |
==> WARNING: ./ is not a mountpoint. This may have undesirable side effects. | |
1 arch_prctl(12289,274886296688,4320976,2561,3,2048) = -1 errno=22 (Invalid argument) | |
1 brk(NULL) = 0x00000000004aa888 | |
1 brk(0x00000000004ab588) = 0x00000000004ab588 | |
1 arch_prctl(4098,4893760,24,2561,2,4892808) = 0 | |
1 set_tid_address(0x4aaf10) = 1 | |
1 set_robust_list(0x4aaf20,24) = -1 errno=38 (Function not implemented) | |
1 Unknown syscall 334 | |
1 prlimit64(0,RLIMIT_STACK,NULL,0x0000004000800390) = 0 ({rlim_cur=8388608,rlim_max=-1}) | |
1 readlinkat(-100,"/proc/self/exe",0x00000040007ff310,4096) = 5 | |
1 getrandom(0x4a9d70,8,1) = 8 | |
1 brk(NULL) = 0x00000000004ab588 | |
1 brk(0x00000000004cc588) = 0x00000000004cc588 | |
1 brk(0x00000000004cd000) = 0x00000000004cd000 | |
1 mprotect(0x000000000049f000,16384,PROT_READ) = 0 | |
1 readlink("/proc/self/exe",0x00000040007fd2b0,4096) = 5 | |
1 newfstatat(1,"",0x00000040007fcf00,0x1000) = 0 | |
1 write(1,0x4aba70,43)readlink(/proc/self/exe) => /main (len: 5) | |
= 43 | |
1 readlink("/proc/self",0x00000040007fd2b0,4096) = 5 | |
1 write(1,0x4aba70,39)readlink(/proc/self) => 27806 (len: 5) | |
= 39 | |
1 getpid() = 1 | |
1 readlink("/proc/1/exe",0x00000040007fd2b0,4096) = 5 | |
1 write(1,0x4aba70,40)readlink(/proc/1/exe) => /main (len: 5) | |
= 40 | |
1 readlink("/proc",0x00000040007fde80,1023) = -1 errno=22 (Invalid argument) | |
1 readlink("/proc/self",0x00000040007fde80,1023) = 5 | |
1 readlink("/proc/27806",0x00000040007fde80,1023) = -1 errno=22 (Invalid argument) | |
1 readlink("/proc/27806/exe",0x00000040007fde80,1023) = 19 | |
1 readlink("/qemu-x86_64-static",0x00000040007fde80,1023) = -1 errno=22 (Invalid argument) | |
1 write(1,0x4aba70,48)realpath(/proc/self/exe) => /qemu-x86_64-static | |
= 48 | |
1 write(1,0x4aba70,18)AT_EXECFN = /main | |
= 18 | |
1 exit_group(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <limits.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <errno.h> | |
#include <sys/auxv.h> | |
void do_readlink(const char * path) | |
{ | |
char buf[PATH_MAX]; | |
ssize_t len = readlink(path, buf, PATH_MAX); | |
if (len > 0) | |
printf("readlink(%s) => %.*s (len: %zu)\n", path, (int)len, buf, len); | |
else | |
printf("readlink(%s) = -%s\n", path, strerror(errno)); | |
} | |
int main() | |
{ | |
do_readlink("/proc/self/exe"); | |
do_readlink("/proc/self"); | |
{ | |
char path[PATH_MAX]; | |
snprintf(path, PATH_MAX, "/proc/%d/exe", getpid()); | |
do_readlink(path); | |
} | |
{ | |
char exe[PATH_MAX]; | |
realpath("/proc/self/exe", exe); | |
printf("realpath(/proc/self/exe) => %s\n", exe); | |
} | |
const char * execfn = (char *)getauxval(AT_EXECFN); | |
printf("AT_EXECFN = %s\n", execfn); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment