diff options
author | Brooks Davis <brooks@FreeBSD.org> | 2023-11-14 22:25:24 +0000 |
---|---|---|
committer | Brooks Davis <brooks@FreeBSD.org> | 2024-02-05 20:34:55 +0000 |
commit | 31a46e2cc84d7ebfc25ce5a33e54681057e9ed9a (patch) | |
tree | 1a981b5b613f833a45447445176e52d04063e674 /lib/libsys | |
parent | 19149b03b1b5ae3134a58bb6baafef07888181a5 (diff) | |
download | src-31a46e2cc84d7ebfc25ce5a33e54681057e9ed9a.tar.gz src-31a46e2cc84d7ebfc25ce5a33e54681057e9ed9a.zip |
Diffstat (limited to 'lib/libsys')
-rw-r--r-- | lib/libsys/Makefile.sys | 5 | ||||
-rw-r--r-- | lib/libsys/aarch64/Makefile.sys | 8 | ||||
-rw-r--r-- | lib/libsys/amd64/Makefile.sys | 7 | ||||
-rw-r--r-- | lib/libsys/arm/Makefile.sys | 4 | ||||
-rw-r--r-- | lib/libsys/i386/Makefile.sys | 12 | ||||
-rw-r--r-- | lib/libsys/powerpc/Makefile.sys | 4 | ||||
-rw-r--r-- | lib/libsys/powerpc64/Makefile.sys | 4 | ||||
-rw-r--r-- | lib/libsys/powerpcspe/Makefile.sys | 7 | ||||
-rw-r--r-- | lib/libsys/riscv/Makefile.sys | 6 | ||||
-rw-r--r-- | lib/libsys/x86/Makefile.sys | 22 | ||||
-rw-r--r-- | lib/libsys/x86/sched_getcpu_x86.c | 81 |
11 files changed, 159 insertions, 1 deletions
diff --git a/lib/libsys/Makefile.sys b/lib/libsys/Makefile.sys index 699117ff437b..7600c9ef2aae 100644 --- a/lib/libsys/Makefile.sys +++ b/lib/libsys/Makefile.sys @@ -20,7 +20,10 @@ NOASM= exit.o \ yield.o PSEUDO= _exit.o \ _getlogin.o -.sinclude "${LIBC_SRCTOP}/${LIBC_ARCH}/sys/Makefile.inc" +.include "${LIBSYS_SRCTOP}/${LIBC_ARCH}/Makefile.sys" +.if ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "amd64" +.include "${LIBSYS_SRCTOP}/x86/Makefile.sys" +.endif SRCS+= clock_gettime.c gettimeofday.c __vdso_gettimeofday.c NOASM+= clock_gettime.o gettimeofday.o diff --git a/lib/libsys/aarch64/Makefile.sys b/lib/libsys/aarch64/Makefile.sys new file mode 100644 index 000000000000..38eb13fb89be --- /dev/null +++ b/lib/libsys/aarch64/Makefile.sys @@ -0,0 +1,8 @@ +MIASM:= ${MIASM:Nfreebsd[467]_*} + +SRCS+= __vdso_gettc.c \ + sched_getcpu_gen.c + +MDASM= cerror.S \ + syscall.S \ + vfork.S diff --git a/lib/libsys/amd64/Makefile.sys b/lib/libsys/amd64/Makefile.sys new file mode 100644 index 000000000000..d4a767c90a5f --- /dev/null +++ b/lib/libsys/amd64/Makefile.sys @@ -0,0 +1,7 @@ +SRCS+= \ + amd64_get_fsbase.c \ + amd64_get_gsbase.c \ + amd64_set_fsbase.c \ + amd64_set_gsbase.c + +MDASM= vfork.S cerror.S getcontext.S diff --git a/lib/libsys/arm/Makefile.sys b/lib/libsys/arm/Makefile.sys new file mode 100644 index 000000000000..ccfaa03a201b --- /dev/null +++ b/lib/libsys/arm/Makefile.sys @@ -0,0 +1,4 @@ +SRCS+= __vdso_gettc.c \ + sched_getcpu_gen.c + +MDASM= vfork.S cerror.S syscall.S diff --git a/lib/libsys/i386/Makefile.sys b/lib/libsys/i386/Makefile.sys new file mode 100644 index 000000000000..bbc3497aa5a5 --- /dev/null +++ b/lib/libsys/i386/Makefile.sys @@ -0,0 +1,12 @@ +SRCS+= i386_get_fsbase.c i386_get_gsbase.c i386_get_ioperm.c i386_get_ldt.c \ + i386_set_fsbase.c i386_set_gsbase.c i386_set_ioperm.c i386_set_ldt.c \ + i386_clr_watch.c i386_set_watch.c i386_vm86.c + +MDASM= vfork.S cerror.S getcontext.S syscall.S + +MAN+= i386_get_ioperm.2 i386_get_ldt.2 i386_vm86.2 +MAN+= i386_set_watch.3 + +MLINKS+=i386_get_ioperm.2 i386_set_ioperm.2 +MLINKS+=i386_get_ldt.2 i386_set_ldt.2 +MLINKS+=i386_set_watch.3 i386_clr_watch.3 diff --git a/lib/libsys/powerpc/Makefile.sys b/lib/libsys/powerpc/Makefile.sys new file mode 100644 index 000000000000..9979d5179f51 --- /dev/null +++ b/lib/libsys/powerpc/Makefile.sys @@ -0,0 +1,4 @@ +SRCS+= __vdso_gettc.c \ + sched_getcpu_gen.c + +MDASM+= cerror.S diff --git a/lib/libsys/powerpc64/Makefile.sys b/lib/libsys/powerpc64/Makefile.sys new file mode 100644 index 000000000000..9979d5179f51 --- /dev/null +++ b/lib/libsys/powerpc64/Makefile.sys @@ -0,0 +1,4 @@ +SRCS+= __vdso_gettc.c \ + sched_getcpu_gen.c + +MDASM+= cerror.S diff --git a/lib/libsys/powerpcspe/Makefile.sys b/lib/libsys/powerpcspe/Makefile.sys new file mode 100644 index 000000000000..3862699ae8b2 --- /dev/null +++ b/lib/libsys/powerpcspe/Makefile.sys @@ -0,0 +1,7 @@ +CFLAGS+= -I${LIBC_SRCTOP}/powerpc +CFLAGS+= -I${LIBSYS_SRCTOP}/powerpc + +SYM_MAPS+= ${LIBSYS_SRCTOP}/powerpc/Symbol.map + +.PATH: ${LIBSYS_SRCTOP}/powerpc +.include "${LIBSYS_SRCTOP}/powerpc/Makefile.sys" diff --git a/lib/libsys/riscv/Makefile.sys b/lib/libsys/riscv/Makefile.sys new file mode 100644 index 000000000000..e4e66ba19bd6 --- /dev/null +++ b/lib/libsys/riscv/Makefile.sys @@ -0,0 +1,6 @@ +SRCS+= __vdso_gettc.c \ + sched_getcpu_gen.c + +MDASM= cerror.S \ + syscall.S \ + vfork.S diff --git a/lib/libsys/x86/Makefile.sys b/lib/libsys/x86/Makefile.sys new file mode 100644 index 000000000000..d5e4cd75e78b --- /dev/null +++ b/lib/libsys/x86/Makefile.sys @@ -0,0 +1,22 @@ +.PATH: ${LIBSYS_SRCTOP}/x86 + +SRCS+= \ + __vdso_gettc.c \ + pkru.c \ + sched_getcpu_x86.c + +MAN+= \ + pkru.3 + +# Note: vdso support for hyperv only on amd64 +.if ${MACHINE_CPUARCH} == "amd64" && ${MK_HYPERV} != "no" +CFLAGS+= -DWANT_HYPERV +.endif +# We can't use sanitizer instrumentation on ifuncs called during sanitizer +# runtime startup. +.if ${MK_ASAN} != "no" +CFLAGS.__vdso_gettc.c+=-fno-sanitize=address +.endif +.if ${MK_UBSAN} != "no" +CFLAGS.__vdso_gettc.c+=-fno-sanitize=undefined +.endif diff --git a/lib/libsys/x86/sched_getcpu_x86.c b/lib/libsys/x86/sched_getcpu_x86.c new file mode 100644 index 000000000000..13ba18ef5e36 --- /dev/null +++ b/lib/libsys/x86/sched_getcpu_x86.c @@ -0,0 +1,81 @@ +/*- + * Copyright (c) 2021 The FreeBSD Foundation + * + * This software were developed by Konstantin Belousov <kib@FreeBSD.org> + * 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. + */ + +#include <sys/param.h> +#include <machine/cpufunc.h> +#include <machine/specialreg.h> +#include <machine/sysarch.h> +#include <x86/ifunc.h> +#include <errno.h> +#include <sched.h> +#include "libc_private.h" + +static int +sched_getcpu_sys(void) +{ + return (__sys_sched_getcpu()); +} + +static int +sched_getcpu_rdpid(void) +{ + register_t res; + + __asm("rdpid %0" : "=r" (res)); + return ((int)res); +} + +static int +sched_getcpu_rdtscp(void) +{ + int res; + + __asm("rdtscp" : "=c" (res) : : "eax", "edx"); + return (res); +} + +DEFINE_UIFUNC(, int, sched_getcpu, (void)) +{ + u_int amd_feature, cpu_exthigh, p[4]; + + if ((cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0) + return (sched_getcpu_rdpid); + + amd_feature = 0; + if (cpu_feature != 0) { + do_cpuid(0x80000000, p); + cpu_exthigh = p[0]; + if (cpu_exthigh >= 0x80000001) { + do_cpuid(0x80000001, p); + amd_feature = p[3]; + } + } + + return ((amd_feature & AMDID_RDTSCP) == 0 ? + sched_getcpu_sys : sched_getcpu_rdtscp); +} |