From: Ralf Baechle <ralf@linux-mips.org>
To: Rich Felker <dalias@aerifal.cx>
Cc: linux-mips@linux-mips.org
Subject: Re: Is r25 saved across syscalls?
Date: Tue, 11 Sep 2012 10:48:04 +0200 [thread overview]
Message-ID: <20120911084804.GE24448@linux-mips.org> (raw)
In-Reply-To: <20120910183720.GO27715@brightrain.aerifal.cx>
On Mon, Sep 10, 2012 at 02:37:20PM -0400, Rich Felker wrote:
> When a restartable system call is interrupted by a signal, the kernel
> must arrange for it to restart after the signal handler returns.
> While some other obscure variants with trampolines are conceivable,
> the canonical way to do this is to set PC back to the syscall
> instruction with all the relevant registers preserved. MIPS is a bit
> peculiar in that the kernel sets PC back to the _previous_ instruction
> and requires that instruction to reload $2. This requirement is part
> of the syscall ABI in that failure of the application to properly
> reload $2 in this slot will cause unpredictable behavior when a
> syscall needs to be resumed after a signal.
>
> While I asked about preserving $25 in general, my actual concern is
> about the syscall restarting situation. I don't care if the value of
> $25 (or $7 in my alternate version) is lost once the syscall returns;
> I only care that the value is still there if the kernel decides to
> point PC back at the instruction before syscall in order to implement
> restarting.
Yes. The kernel keeps a backup copy of $a3 around and uses it to restore
the old content of $a3 before returning to userland, even in old kernels.
A recent signal.c contains:
if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
regs->regs[2] = current->thread.abi->restart;
regs->regs[7] = regs->regs[26];
regs->cp0_epc -= 4;
}
Note that c0_epc is made to point back to the SYSCALL instruction,
not the one preceeding the SYSCALL instructions since 8f5a00eb4 [MIPS:
Sanitize restart logics] which went in for 2.6.36.
Relying on userland to reload $v0 was something ugly that Linux inherited
from god knows where and I'm happy to have gotten rid of that.
> The code I'm looking at seems to match what you cited from glibc.
>
> > >These are
> > >requirements beyond the normal function call convention (which does
> > >not require the callee preserve the values of r4-r7).
> >
> > I would assume these are clobbered (from glibc sources
> > ports/sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h):
> >
> > "$1", "$3", "$10", "$11", "$12", "$13", "$14", "$15", "$24", "$25",
> > "hi", "lo"
Which is correct but also means that the _syscallX() macros that were in
<asm/unistd.h> up to 2.6.19 were broken; the were lacking clobbers for
$25, $hi and $lo. Unfortunately these macros were copied into many
libraries and applications.
Ralf
next prev parent reply other threads:[~2012-09-11 8:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-09 19:30 Is r25 saved across syscalls? Rich Felker
2012-09-10 17:08 ` Ralf Baechle
2012-09-10 17:22 ` Rich Felker
2012-09-10 18:04 ` David Daney
2012-09-10 18:37 ` Rich Felker
2012-09-11 8:48 ` Ralf Baechle [this message]
2012-09-11 13:32 ` Rich Felker
2012-09-11 0:29 ` Maciej W. Rozycki
2012-09-11 1:04 ` Kevin D. Kissell
2012-09-11 1:27 ` David Daney
2012-09-11 2:28 ` Rich Felker
2012-09-11 8:58 ` Ralf Baechle
2012-09-11 8:12 ` Ralf Baechle
2012-09-11 13:44 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120911084804.GE24448@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=dalias@aerifal.cx \
--cc=linux-mips@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.