From nobody Wed May 28 11:11:44 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4b6mzP5kFTz5xKtx; Wed, 28 May 2025 11:11:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b6mzN5v28z42Rx; Wed, 28 May 2025 11:11:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748430704; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=33pI4upBaLJNGSi61EDPRqxJhXf4K5JLiPdxMt65Eg4=; b=ZfvJToSeRWVrQ88UH3iIqPtZD8XibOFCd/I6Tkl4Tvn5NOTj7CVB7KjADAtxYZheebqzeL FemccdKJkzRLMgWX2UEhnHDsnhPcGjdcEGXNZNu04MKEo5OeVoTsDXc7a1I5x/G0p/kap5 fkaw3jR19ztADc6ZLeureMaTvl/HufmBk/WgMT8zz8sUoBxs7klkFPKXTjoKq6KOOdzlE8 eL6BzHavlw++V5m1bI33vsjsdAw8fK7kFqefKeuczzaqamT0F8INHkDqK6Ie6R4C2DbGJv eLiAo9AF+DiVQLffCZAMaPo053myxDzcIlebGNRtEra81TN18z0LGfZP2vnk0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1748430704; a=rsa-sha256; cv=none; b=yZjlNsH5tR62ks8TpLcqVkCW1qrvN4bBkSG59zD7M0yW+rjXbWEvWAuZK6hZbodT/fCGe0 BF3Sv7+yyKmAO3TkEdI1NNaTDDogExXFGSsgL08FUliJuus+9sH5JdUxJ1+AHcip9e9TAf LeoXG0xnY45xDwcoEFGntK32u5No1tEFzQsr+6DvmU0z6ONR+4trpY61v4OjQF+tq8qALI PVNGZSbWX1MQS3DivG/0IaKwlaebP1ZdV1QpyuFLUcgdHwtF/4V52ZkH+WA2iEN9ehVqsV UhJNdNVD4E2W86zMbA5nbJ1j38oXaiKXrykeEpp2nbc04DKFSW0v1/EQADC6VQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748430704; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=33pI4upBaLJNGSi61EDPRqxJhXf4K5JLiPdxMt65Eg4=; b=EbJV9OuJ+cxNCP3S36+4iFLWUBPyEyVxWNNIktM7TANfvp5mabgRgZiVUuBSPWszRGbdo1 019UNpbjqV30qOuLGUMMCCaJ6DuZTd+E9GGZnq2Nf/Yn+XBvO6ihfFoiD4iFbPS4NPdLfp SCC00kG1WMfoSZ1h9g0dsIcdfcKCIVM3n8cS1qK/YoD7YGTC8qCvBLhBhj0rX4hErO1s+d iu4QOsDsdR/n/wjShzikOK0AGrPfUevwiSQbbOH7APvjd5LqIPr5bpbRsHu70M8IfwTq9w Wofx2r1EPcAvmQzYZRHgFVrR+cqrFysOKW2bkN/i2d3tvDRM+Mo4ZBdHluv+lw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4b6mzN58XDzbw9; Wed, 28 May 2025 11:11:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54SBBi1Z049661; Wed, 28 May 2025 11:11:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54SBBiKf049658; Wed, 28 May 2025 11:11:44 GMT (envelope-from git) Date: Wed, 28 May 2025 11:11:44 GMT Message-Id: <202505281111.54SBBiKf049658@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 2e7cf772a411 - main - amd64: add amd64_set_tlsbase(3) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2e7cf772a4114b78eb0ab2687d91d563de89e206 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=2e7cf772a4114b78eb0ab2687d91d563de89e206 commit 2e7cf772a4114b78eb0ab2687d91d563de89e206 Author: Konstantin Belousov AuthorDate: 2025-05-22 04:32:03 +0000 Commit: Konstantin Belousov CommitDate: 2025-05-28 11:11:23 +0000 amd64: add amd64_set_tlsbase(3) Tested by: pho Reviewed by: olce Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D50482 --- lib/libsys/amd64/Makefile.sys | 1 + lib/libsys/amd64/Symbol.sys.map | 4 +++ lib/libsys/amd64/amd64_set_tlsbase.c | 51 ++++++++++++++++++++++++++++++++++++ sys/x86/include/sysarch.h | 1 + 4 files changed, 57 insertions(+) diff --git a/lib/libsys/amd64/Makefile.sys b/lib/libsys/amd64/Makefile.sys index 09947d998480..8134bdc422a6 100644 --- a/lib/libsys/amd64/Makefile.sys +++ b/lib/libsys/amd64/Makefile.sys @@ -3,6 +3,7 @@ SRCS+= \ amd64_get_gsbase.c \ amd64_set_fsbase.c \ amd64_set_gsbase.c \ + amd64_set_tlsbase.c \ rfork_thread.S MDASM= vfork.S cerror.S getcontext.S diff --git a/lib/libsys/amd64/Symbol.sys.map b/lib/libsys/amd64/Symbol.sys.map index 5f463c85f872..11e0507b6613 100644 --- a/lib/libsys/amd64/Symbol.sys.map +++ b/lib/libsys/amd64/Symbol.sys.map @@ -13,6 +13,10 @@ FBSD_1.6 { x86_pkru_unprotect_range; }; +FBSD_1.8 { + amd64_set_tlsbase; +}; + FBSDprivate_1.0 { _vfork; }; diff --git a/lib/libsys/amd64/amd64_set_tlsbase.c b/lib/libsys/amd64/amd64_set_tlsbase.c new file mode 100644 index 000000000000..a28441fbfc5d --- /dev/null +++ b/lib/libsys/amd64/amd64_set_tlsbase.c @@ -0,0 +1,51 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2025 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Konstantin Belousov + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#define _WANT_P_OSREL +#include +#include +#include +#include +#include +#include "libc_private.h" + +static int +amd64_set_tlsbase_syscall(void *addr) +{ + return (sysarch(AMD64_SET_TLSBASE, &addr)); +} + +DEFINE_UIFUNC(, int, amd64_set_tlsbase, (void *)) +{ + if (__getosreldate() >= P_OSREL_TLSBASE) + return (amd64_set_tlsbase_syscall); + return (amd64_set_fsbase); +} diff --git a/sys/x86/include/sysarch.h b/sys/x86/include/sysarch.h index 61f559f4bd23..a67e5c2265a3 100644 --- a/sys/x86/include/sysarch.h +++ b/sys/x86/include/sysarch.h @@ -142,6 +142,7 @@ int amd64_get_fsbase(void **); int amd64_get_gsbase(void **); int amd64_set_fsbase(void *); int amd64_set_gsbase(void *); +int amd64_set_tlsbase(void *); int x86_pkru_get_perm(unsigned int keyidx, int *access, int *modify); int x86_pkru_set_perm(unsigned int keyidx, int access, int modify); int x86_pkru_protect_range(void *addr, unsigned long len, unsigned int keyidx,