Date: Tue, 30 Oct 2018 00:11:30 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339898 - head/lib/libc/amd64/sys Message-ID: <201810300011.w9U0BUui038857@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Tue Oct 30 00:11:30 2018 New Revision: 339898 URL: https://svnweb.freebsd.org/changeset/base/339898 Log: Convert amd64_get/set_fs/gsbase to ifunc. Note that this is the first use of ifuncs in our userspace. Sponsored by: The FreeBSD Foundation MFC after: 1 month Deleted: head/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.c head/lib/libc/amd64/sys/amd64_detect_rdfsgsbase.h Modified: head/lib/libc/amd64/sys/Makefile.inc head/lib/libc/amd64/sys/amd64_get_fsbase.c head/lib/libc/amd64/sys/amd64_get_gsbase.c head/lib/libc/amd64/sys/amd64_set_fsbase.c head/lib/libc/amd64/sys/amd64_set_gsbase.c Modified: head/lib/libc/amd64/sys/Makefile.inc ============================================================================== --- head/lib/libc/amd64/sys/Makefile.inc Mon Oct 29 23:59:26 2018 (r339897) +++ head/lib/libc/amd64/sys/Makefile.inc Tue Oct 30 00:11:30 2018 (r339898) @@ -2,7 +2,6 @@ # $FreeBSD$ SRCS+= \ - amd64_detect_rdfsgsbase.c \ amd64_get_fsbase.c \ amd64_get_gsbase.c \ amd64_set_fsbase.c \ Modified: head/lib/libc/amd64/sys/amd64_get_fsbase.c ============================================================================== --- head/lib/libc/amd64/sys/amd64_get_fsbase.c Mon Oct 29 23:59:26 2018 (r339897) +++ head/lib/libc/amd64/sys/amd64_get_fsbase.c Tue Oct 30 00:11:30 2018 (r339898) @@ -2,7 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2003 Peter Wemm - * Copyright (c) 2017 The FreeBSD Foundation + * Copyright (c) 2017, 2018 The FreeBSD Foundation * All rights reserved. * * Portions of this software were developed by Konstantin Belousov @@ -33,18 +33,35 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> +#define IN_RTLD 1 +#include <sys/param.h> +#undef IN_RTLD #include <machine/cpufunc.h> +#include <machine/specialreg.h> #include <machine/sysarch.h> -#include "amd64_detect_rdfsgsbase.h" +#include <x86/ifunc.h> +#include "libc_private.h" -int -amd64_get_fsbase(void **addr) +static int +amd64_get_fsbase_cpu(void **addr) { - if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { - *addr = (void *)rdfsbase(); - return (0); - } + *addr = (void *)rdfsbase(); + return (0); +} + +static int +amd64_get_fsbase_syscall(void **addr) +{ + return (sysarch(AMD64_GET_FSBASE, addr)); +} + +DEFINE_UIFUNC(, int, amd64_get_fsbase, (void **), static) +{ + + if (__getosreldate() >= P_OSREL_WRFSBASE && + (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0) + return (amd64_get_fsbase_cpu); + return (amd64_get_fsbase_syscall); } Modified: head/lib/libc/amd64/sys/amd64_get_gsbase.c ============================================================================== --- head/lib/libc/amd64/sys/amd64_get_gsbase.c Mon Oct 29 23:59:26 2018 (r339897) +++ head/lib/libc/amd64/sys/amd64_get_gsbase.c Tue Oct 30 00:11:30 2018 (r339898) @@ -2,7 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2003 Peter Wemm - * Copyright (c) 2017 The FreeBSD Foundation + * Copyright (c) 2017, 2018 The FreeBSD Foundation * All rights reserved. * * Portions of this software were developed by Konstantin Belousov @@ -33,18 +33,35 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> +#define IN_RTLD 1 +#include <sys/param.h> +#undef IN_RTLD #include <machine/cpufunc.h> +#include <machine/specialreg.h> #include <machine/sysarch.h> -#include "amd64_detect_rdfsgsbase.h" +#include <x86/ifunc.h> +#include "libc_private.h" -int -amd64_get_gsbase(void **addr) +static int +amd64_get_gsbase_cpu(void **addr) { - if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { - *addr = (void *)rdgsbase(); - return (0); - } + *addr = (void *)rdgsbase(); + return (0); +} + +static int +amd64_get_gsbase_syscall(void **addr) +{ + return (sysarch(AMD64_GET_GSBASE, addr)); +} + +DEFINE_UIFUNC(, int, amd64_get_gsbase, (void **), static) +{ + + if (__getosreldate() >= P_OSREL_WRFSBASE && + (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0) + return (amd64_get_gsbase_cpu); + return (amd64_get_gsbase_syscall); } Modified: head/lib/libc/amd64/sys/amd64_set_fsbase.c ============================================================================== --- head/lib/libc/amd64/sys/amd64_set_fsbase.c Mon Oct 29 23:59:26 2018 (r339897) +++ head/lib/libc/amd64/sys/amd64_set_fsbase.c Tue Oct 30 00:11:30 2018 (r339898) @@ -2,7 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2003 Peter Wemm - * Copyright (c) 2017 The FreeBSD Foundation + * Copyright (c) 2017, 2018 The FreeBSD Foundation * All rights reserved. * * Portions of this software were developed by Konstantin Belousov @@ -33,18 +33,35 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> +#define IN_RTLD 1 +#include <sys/param.h> +#undef IN_RTLD #include <machine/cpufunc.h> +#include <machine/specialreg.h> #include <machine/sysarch.h> -#include "amd64_detect_rdfsgsbase.h" +#include <x86/ifunc.h> +#include "libc_private.h" -int -amd64_set_fsbase(void *addr) +static int +amd64_set_fsbase_cpu(void *addr) { - if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { - wrfsbase((uintptr_t)addr); - return (0); - } + wrfsbase((uintptr_t)addr); + return (0); +} + +static int +amd64_set_fsbase_syscall(void *addr) +{ + return (sysarch(AMD64_SET_FSBASE, &addr)); +} + +DEFINE_UIFUNC(, int, amd64_set_fsbase, (void *), static) +{ + + if (__getosreldate() >= P_OSREL_WRFSBASE && + (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0) + return (amd64_set_fsbase_cpu); + return (amd64_set_fsbase_syscall); } Modified: head/lib/libc/amd64/sys/amd64_set_gsbase.c ============================================================================== --- head/lib/libc/amd64/sys/amd64_set_gsbase.c Mon Oct 29 23:59:26 2018 (r339897) +++ head/lib/libc/amd64/sys/amd64_set_gsbase.c Tue Oct 30 00:11:30 2018 (r339898) @@ -2,7 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2003 Peter Wemm - * Copyright (c) 2017 The FreeBSD Foundation + * Copyright (c) 2017, 2018 The FreeBSD Foundation * All rights reserved. * * Portions of this software were developed by Konstantin Belousov @@ -33,18 +33,35 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/types.h> +#define IN_RTLD 1 +#include <sys/param.h> +#undef IN_RTLD #include <machine/cpufunc.h> +#include <machine/specialreg.h> #include <machine/sysarch.h> -#include "amd64_detect_rdfsgsbase.h" +#include <x86/ifunc.h> +#include "libc_private.h" -int -amd64_set_gsbase(void *addr) +static int +amd64_set_gsbase_cpu(void *addr) { - if (amd64_detect_rdfsgsbase() == RDFSGS_SUPPORTED) { - wrgsbase((uintptr_t)addr); - return (0); - } + wrgsbase((uintptr_t)addr); + return (0); +} + +static int +amd64_set_gsbase_syscall(void *addr) +{ + return (sysarch(AMD64_SET_GSBASE, &addr)); +} + +DEFINE_UIFUNC(, int, amd64_set_gsbase, (void *), static) +{ + + if (__getosreldate() >= P_OSREL_WRFSBASE && + (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0) + return (amd64_set_gsbase_cpu); + return (amd64_set_gsbase_syscall); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810300011.w9U0BUui038857>