On 21 Dec 2015 02:31, Dmitry V. Levin wrote: > On Sun, Dec 20, 2015 at 12:47:54AM -0500, Mike Frysinger wrote: > > i've been playing with ptrace on sparc and trying to use it to watch and > > cancel specific syscalls. i have this working for other arches already. > [...] > > i'm having trouble with canceling of the syscall itself. seems like > > no matter what i stuff into o0, the kernel executes the unlink. i've > > tried tracing arch/sparc/kernel/syscalls.S and kernel/head_64.S, the > > the entry is linux_sparc_syscall32 which calls linux_syscall_trace32, > > but it seems like the o0 stuff doesn't seem to work for me. my sparc > > asm foo isn't strong enough to figure out what's going wrong :/. > > Yes, sparc is odd in this respect: whatever you write to u_regs[] on > entering syscall, it doesn't affect syscall number or syscall arguments. looks like the bug is in arch/sparc/kernel/syscalls.S:linux_syscall_trace32 (and linux_syscall_trace). they don't reload the args from the pt_regs struct after calling syscall_trace_enter. i put in a small hack: linux_syscall_trace32: call syscall_trace_enter add %sp, PTREGS_OFF, %o0 brnz,pn %o0, 3f mov -ENOSYS, %o0 + + ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1 + cmp %g1, NR_syscalls = bgeu,pn %xcc, 3f + mov -ENOSYS, %o0 + srl %i0, 0, %o0 srl %i4, 0, %o4 ... it's enough for my use case (cancel the call), but it's not entirely correct. i think it needs to re-initialize %l7 with the final syscall pointer via the syscall table, and it needs to reload PT_V9_I{0..5}. i have no idea which regs need stuffing though, especially in light of the %l7 optimization. and i'm not familiar at all with the apparent parallelism via IEU0/IEU1 groups. so i won't bother with trying to write a full patch. hopefully sparc guys will notice & post a fix ;). i'm attaching my simple test in case it helps. just do: $ gcc ptrace-test.c && ./a.out the logging output should indicate when things are passing. -mike