Linux powerpc new system call instruction and ABI
Nicholas Piggin
npiggin at gmail.com
Wed May 19 20:59:05 AEST 2021
Excerpts from Dmitry V. Levin's message of May 19, 2021 8:24 pm:
> On Wed, May 19, 2021 at 12:50:24PM +1000, Nicholas Piggin wrote:
> [...]
>> With this patch, I think the ptrace ABI should mostly be fixed. I think
>> a problem remains with applications that look at system call return
>> registers directly and have powerpc specific error cases. Those probably
>> will just need to be updated unfortunately. Michael thought it might be
>> possible to return an indication via ptrace somehow that the syscall is
>> using a new ABI, so such apps can be updated to test for it. I don't
>> know how that would be done.
>
> Is there any sane way for these applications to handle the scv case?
> How can they tell that the scv semantics is being used for the given
> syscall invocation? Can this information be obtained e.g. from struct
> pt_regs?
Not that I know of. Michael suggested there might be a way to add
something. ptrace_syscall_info has some pad bytes, could
we use one for flags bits and set a bit for "new system call ABI"?
As a more hacky thing you could make a syscall with -1 and see how
the error looks, and then assume all syscalls will be the same.
Thanks,
Nick
>
> For example, in strace we have the following powerpc-specific code used
> for syscall tampering:
>
> $ cat src/linux/powerpc/set_error.c
> /*
> * Copyright (c) 2016-2021 The strace developers.
> * All rights reserved.
> *
> * SPDX-License-Identifier: LGPL-2.1-or-later
> */
>
> static int
> arch_set_r3_ccr(struct tcb *tcp, const unsigned long r3,
> const unsigned long ccr_set, const unsigned long ccr_clear)
> {
> if (ptrace_syscall_info_is_valid() &&
> upeek(tcp, sizeof(long) * PT_CCR, &ppc_regs.ccr))
> return -1;
> const unsigned long old_ccr = ppc_regs.ccr;
> ppc_regs.gpr[3] = r3;
> ppc_regs.ccr |= ccr_set;
> ppc_regs.ccr &= ~ccr_clear;
> if (ppc_regs.ccr != old_ccr &&
> upoke(tcp, sizeof(long) * PT_CCR, ppc_regs.ccr))
> return -1;
> return upoke(tcp, sizeof(long) * (PT_R0 + 3), ppc_regs.gpr[3]);
> }
>
> static int
> arch_set_error(struct tcb *tcp)
> {
> return arch_set_r3_ccr(tcp, tcp->u_error, 0x10000000, 0);
> }
>
> static int
> arch_set_success(struct tcb *tcp)
> {
> return arch_set_r3_ccr(tcp, tcp->u_rval, 0, 0x10000000);
> }
>
>
> --
> ldv
>
More information about the Linuxppc-dev
mailing list