public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
To: Godmar Back via Libc-help <libc-help@sourceware.org>
Cc: Godmar Back <godmar@gmail.com>
Subject: Re: curiosity question about swapcontext libc implementation on x86_64
Date: Sun, 25 Feb 2024 12:27:25 +0100	[thread overview]
Message-ID: <87bk84eqci.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <CAB4+JYKx0+6r=pVzymV24O3LHSdVBCZUXJKM9LAmVkwEEgAJeA@mail.gmail.com> (Godmar Back via Libc-help's message of "Thu, 1 Feb 2024 10:23:37 -0500")

* Godmar Back via Libc-help:

> The implementation of the obsolescent makecontext/getcontext/swapcontext
> family of functions on x86_64 [1] appears to save a selection of registers.
>
> These include callee-saved regs like rbx, rbp, r12-r15, but also
> caller-saved regs like rdi, rsi, rdx, rcx. On the floating point side, it
> saves mxcsr, the x87 FPU state via fnstenv, but not the xmm SSE register.
> All of these floating point registers are callee-saved based on the AMD64
> ABI [2].

%rdi, %rsi, %rdx, %rcx are argument registers and need to be restored
for makecontext to work correctly.  As far as I can see, getcontext
wouldn't need to save them, but they need to be restored.

The handling of what is now considered per-thread state (such as
floating point control words or signal masks) is inconsistent.  I
think this is just due to the age of these interfaces, and not
something that was designed explicitly.

      reply	other threads:[~2024-02-25 11:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01 15:23 Godmar Back
2024-02-25 11:27 ` Florian Weimer [this message]

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=87bk84eqci.fsf@mid.deneb.enyo.de \
    --to=fw@deneb.enyo.de \
    --cc=godmar@gmail.com \
    --cc=libc-help@sourceware.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).