From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cygnus.enyo.de (cygnus.enyo.de [79.140.189.114]) by sourceware.org (Postfix) with ESMTPS id F12AA3858295 for ; Sun, 25 Feb 2024 11:27:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F12AA3858295 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=deneb.enyo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=deneb.enyo.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F12AA3858295 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=79.140.189.114 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708860449; cv=none; b=CkVcViZGrgi9sc6DlP8+tfPBRyA3DRPGOfEnKxAL8DKZ9WpYtJ/32dEF3VOFPI6QQocY//6t/lJ8nvm9xMLg57NqZrSa5Oz/HxZEsB2jzBXTGMVKYBRF/vwS4NxLEAPx0+dmj43QrzxLFbjaQAqzpNewPSWtpgrr5jZHK2qiiTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708860449; c=relaxed/simple; bh=R8SJjr3zGVt4e3Cg7kdQxFX0kPJnVv9/MPPxBihJlOg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZQn4B6tX796DEu4T/zpZtVy8YlnswZNk5aTDGYFz2JfWoiOzGt+yfTsamctnNFPzHteLCcZbDBbEf8ExxcbGDdvlKTwRmM38MQT0vEy8TSxOB0lq9slFngOkA9gqIvE344/JVyqp34vz1XKCIoxpAoAFwwdDfUORESB3S7D+u90= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [172.17.203.2] (port=45497 helo=deneb.enyo.de) by albireo.enyo.de ([172.17.140.2]) with esmtps (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) id 1reCfE-007tw3-8S; Sun, 25 Feb 2024 11:27:25 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.96) (envelope-from ) id 1reCfF-0004E3-15; Sun, 25 Feb 2024 12:27:25 +0100 From: Florian Weimer To: Godmar Back via Libc-help Cc: Godmar Back Subject: Re: curiosity question about swapcontext libc implementation on x86_64 References: Date: Sun, 25 Feb 2024 12:27:25 +0100 In-Reply-To: (Godmar Back via Libc-help's message of "Thu, 1 Feb 2024 10:23:37 -0500") Message-ID: <87bk84eqci.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_NUMSUBJECT,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: * 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.