From 70936510849164ec971e112ee9ef6863e66bc37b Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 8 Oct 2026 15:32:17 -0500 Subject: [PATCH] Make strace.c compile on more architectures. --- toys/pending/strace.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/toys/pending/strace.c b/toys/pending/strace.c index f612f07c..89f8beed 100644 --- a/toys/pending/strace.c +++ b/toys/pending/strace.c @@ -34,6 +34,7 @@ GLOBALS( ) // Syscall args from https://man7.org/linux/man-pages/man2/syscall.2.html +// or arch/$ARCH/include/asm/syscall.h // REG_ORDER is args 0-6, SYSCALL, RESULT #if defined(__arm__) static const char REG_ORDER[] = {0,1,2,3,4,5,7,0}; @@ -45,6 +46,16 @@ static const char REG_ORDER[] = {0,1,2,3,4,5,11,6}; #elif defined(__m68k__) // d1,d2,d3,d4,d5,a0,orig_d0,d0 static const char REG_ORDER[] = {0,1,2,3,4,7,16,14}; +#elif defined(__microblaze__) +static const char REG_ORDER[] = {5,6,7,8,9,10,12,3}; +#elif defined(__mips64) +#warning todo fix this +static const char REG_ORDER[] = {0,1,2,3,4,5,0,0}; +#elif defined(__mips__) +#warning this probably is not right: O32 vs N32 vs N64, v0 vs a0... +static const char REG_ORDER[] = {0,1,2,3,4,5,0,0}; +#elif defined(__or1k__) +static const char REG_ORDER[] = {3,4,5,6,7,8,11,11}; #elif defined(__PPC__) || defined(__PPC64__) static const char REG_ORDER[] = {3,4,5,6,7,8,0,3}; #elif defined(__riscv) @@ -282,14 +293,15 @@ static void print_struct(long addr) ptrace_struct(addr, &sb, sizeof(sb)); if (FLAG(v)) { // TODO: full atime/mtime/ctime dump. - fprintf(stderr, "{st_dev=makedev(%#x, %#x), st_ino=%ld, st_mode=", - dev_major(sb.st_dev), dev_minor(sb.st_dev), sb.st_ino); + fprintf(stderr, "{st_dev=makedev(%#x, %#x), st_ino=%lld, st_mode=", + dev_major(sb.st_dev), dev_minor(sb.st_dev), (long long)sb.st_ino); print_mode(sb.st_mode); fprintf(stderr, ", st_nlink=%ld, st_uid=%d, st_gid=%d, " - "st_blksize=%ld, st_blocks=%ld, st_size=%lld, st_atime=%ld, " - "st_mtime=%ld, st_ctime=%ld}", (long) sb.st_nlink, sb.st_uid, - sb.st_gid, (long) sb.st_blksize, sb.st_blocks, (long long)sb.st_size, - sb.st_atime, sb.st_mtime, sb.st_ctime); + "st_blksize=%ld, st_blocks=%lld, st_size=%lld, st_atime=%lld, " + "st_mtime=%lld, st_ctime=%lld}", (long) sb.st_nlink, sb.st_uid, + sb.st_gid, (long) sb.st_blksize, (long long)sb.st_blocks, + (long long)sb.st_size, (long long)sb.st_atime, (long long)sb.st_mtime, + (long long)sb.st_ctime); } else { fprintf(stderr, "{st_mode="); print_mode(sb.st_mode); @@ -503,7 +515,9 @@ static void print_enter(void) SC(arch_prctl, "dp"); #endif SC(brk, "p"); +#if defined(__NR_clock_nanosleep) SC(clock_nanosleep, "^clockid^d{timespec}/{timespec}"); +#endif SC(close, "d"); SC(connect, "fpd"); // TODO: sockaddr SC(dup, "f"); @@ -514,8 +528,12 @@ static void print_enter(void) SC(execve, "Fpp"); SC(exit_group, "d"); SC(faccessat, "fF|access|"); +#if defined(__NR_fcntl) SC(fcntl, "fdp"); // TODO: probably needs special case +#endif +#if defined(__NR_fstat) SC(fstat, "f/{stat}"); +#endif SC(futex, "pdxppx"); SC(getcwd, "/Fz"); SC(getdents64, "dpz"); @@ -528,12 +546,15 @@ static void print_enter(void) SC(getxattr, "Fspz"); SC(lgetxattr, "Fspz"); SC(fgetxattr, "fspz"); - +#if defined(__NR_lseek) SC(lseek, "fo^seek^"); +#endif #if defined(__NR_lstat) SC(lstat, "s/{stat}"); #endif +#if defined(__NR_mmap) SC(mmap, "pz|prot||mmap|fx"); +#endif SC(mprotect, "pz|prot|"); SC(mremap, "pzzdp"); // TODO: flags SC(munmap, "pz"); @@ -565,7 +586,9 @@ static void print_enter(void) #if defined(__NR_stat) SC(stat, "F/{stat}"); #endif +#if defined(__NR_statfs) SC(statfs, "Fp"); +#endif SC(sysinfo, "p"); SC(umask, "m"); SC(uname, "p"); @@ -587,6 +610,11 @@ static void print_exit(void) struct iovec v = {.iov_base=®s, .iov_len=sizeof(regs)}; long result; +// TODO fix this +#ifndef __NR_mmap +#define __NR_mmap __NR_mmap2 +#endif + // We read the registers into a local because we only want the result, // and don't want to clobber the argument that was in the same register // earlier (the first argument of getcwd(2), for example, gets printed -- 2.39.5