From nobody Sun Jan 02 19:08:10 2022 X-Original-To: dev-commits-src-branches@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 28B8C191F2EF; Sun, 2 Jan 2022 19:08:12 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JRpLM26prz4XlG; Sun, 2 Jan 2022 19:08:11 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 E52B31763B; Sun, 2 Jan 2022 19:08:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 202J8A4B057718; Sun, 2 Jan 2022 19:08:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 202J8Auw057717; Sun, 2 Jan 2022 19:08:10 GMT (envelope-from git) Date: Sun, 2 Jan 2022 19:08:10 GMT Message-Id: <202201021908.202J8Auw057717@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 203bcad73164 - stable/13 - amd64: wrap 64bit sigtramp into vdso List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 203bcad73164bf6e4f51edc4ffda7f2a3885b413 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641150491; 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=VwndAiNDPWvkys6oldf6yuyOBFtjbnDjDpzw6cE2Wvw=; b=AookMifISKjCf/mF006Orcv7hywuaLzTo/EEmu36HHWMYJdLw8dMG6PwTk0qCJ+59Md1Gc Iq6XHGnNmUlnE/8kQ788B7kQ3uyK2LFhKe2K9kNmwtER4mUO53DevUGUUbgvng03TAAhA/ KnUidePHBn5zwKK9KU9ijYZKnNnFPBu05CX3J0JcPjMZbDmV4GKc/Si3gEqUwEkaof5KCq LjaB7UzquaWkAIUx1Xxib0Wy0cJtc9JT4Mu/O0Ak7cWKvn7TTWsea2fk7MpQUWiHS4PwvR 0D/L6Z4e3DEK4TjFcrZ9VjzxsIZjoYO8evCvByFq4aUbIN+QE/NhsfBX/qw8hw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641150491; a=rsa-sha256; cv=none; b=ZTE/XuvcWuDKFvaYne2kB4F5UT+4uTl26oKNjAYdPT98x5eUlXPIHMAwqeKzaE4Xbv4niK ITvBNW/YdxKKDNCZCJCQhKCJZgsvK5P6MhURrwl6bxlnR03k6fZLDO++0nVbg7uZ/GPQd7 Be774ewGA2JFW1vwoif94i/d9Q0CSZMRSDWwuQZ/c7V839LFxxWNspaOpwGpRsdDzh5JsX l7SGBovBArAIKapv0MOE+/JX/gZf4soWl7waN8Hs8RSsnbT/brwzwYMgRhORD84vzt9set We3Hxx+3PbkB5+esKe+U6wo2VE1/8RDvRxn++XVc+7ArCop2OC5GFvuKV+5Edw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=203bcad73164bf6e4f51edc4ffda7f2a3885b413 commit 203bcad73164bf6e4f51edc4ffda7f2a3885b413 Author: Konstantin Belousov AuthorDate: 2021-11-05 08:07:24 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-02 16:43:01 +0000 amd64: wrap 64bit sigtramp into vdso (cherry picked from commit ab4524b3d7fba872a143b03c9346cb04c3670efa) --- sys/amd64/amd64/elf_machdep.c | 20 +++++++--- sys/amd64/amd64/sigtramp.S | 18 +++------ sys/compat/linux/linux_vdso.c | 4 +- sys/conf/files.amd64 | 7 +++- sys/conf/vdso_amd64.ldscript | 89 +++++++++++++++++++++++++++++++++++++++++++ sys/kern/kern_proc.c | 7 +++- sys/kern/kern_sharedpage.c | 18 ++++++++- sys/sys/sysent.h | 4 +- sys/tools/amd64_vdso.sh | 59 ++++++++++++++++++++++++++++ sys/tools/vdso_wrap.S | 48 +++++++++++++++++++++++ 10 files changed, 247 insertions(+), 27 deletions(-) diff --git a/sys/amd64/amd64/elf_machdep.c b/sys/amd64/amd64/elf_machdep.c index 445efa883fd2..6a4c25072962 100644 --- a/sys/amd64/amd64/elf_machdep.c +++ b/sys/amd64/amd64/elf_machdep.c @@ -49,14 +49,21 @@ __FBSDID("$FreeBSD$"); #include #include +#include "vdso_offsets.h" + +extern const char _binary_elf_vdso_so_1_start[]; +extern const char _binary_elf_vdso_so_1_end[]; +extern char _binary_elf_vdso_so_1_size; + struct sysentvec elf64_freebsd_sysvec_la48 = { .sv_size = SYS_MAXSYSCALL, .sv_table = sysent, .sv_transtrap = NULL, .sv_fixup = __elfN(freebsd_fixup), .sv_sendsig = sendsig, - .sv_sigcode = sigcode, - .sv_szsigcode = &szsigcode, + .sv_sigcode = _binary_elf_vdso_so_1_start, + .sv_szsigcode = (int *)&_binary_elf_vdso_so_1_size, + .sv_sigcodeoff = VDSO_SIGCODE_OFFSET, .sv_name = "FreeBSD ELF64", .sv_coredump = __elfN(coredump), .sv_imgact_try = NULL, @@ -72,7 +79,7 @@ struct sysentvec elf64_freebsd_sysvec_la48 = { .sv_fixlimit = NULL, .sv_maxssiz = NULL, .sv_flags = SV_ABI_FREEBSD | SV_ASLR | SV_LP64 | SV_SHP | - SV_TIMEKEEP | SV_RNG_SEED_VER, + SV_TIMEKEEP | SV_RNG_SEED_VER | SV_DSO_SIG, .sv_set_syscall_retval = cpu_set_syscall_retval, .sv_fetch_syscall_args = cpu_fetch_syscall_args, .sv_syscallnames = syscallnames, @@ -92,8 +99,9 @@ struct sysentvec elf64_freebsd_sysvec_la57 = { .sv_transtrap = NULL, .sv_fixup = __elfN(freebsd_fixup), .sv_sendsig = sendsig, - .sv_sigcode = sigcode, - .sv_szsigcode = &szsigcode, + .sv_sigcode = _binary_elf_vdso_so_1_start, + .sv_szsigcode = (int *)&_binary_elf_vdso_so_1_size, + .sv_sigcodeoff = VDSO_SIGCODE_OFFSET, .sv_name = "FreeBSD ELF64", .sv_coredump = __elfN(coredump), .sv_imgact_try = NULL, @@ -109,7 +117,7 @@ struct sysentvec elf64_freebsd_sysvec_la57 = { .sv_fixlimit = NULL, .sv_maxssiz = NULL, .sv_flags = SV_ABI_FREEBSD | SV_ASLR | SV_LP64 | SV_SHP | - SV_TIMEKEEP | SV_RNG_SEED_VER, + SV_TIMEKEEP | SV_RNG_SEED_VER | SV_DSO_SIG, .sv_set_syscall_retval = cpu_set_syscall_retval, .sv_fetch_syscall_args = cpu_fetch_syscall_args, .sv_syscallnames = syscallnames, diff --git a/sys/amd64/amd64/sigtramp.S b/sys/amd64/amd64/sigtramp.S index a249a1a646f2..05bf30293a9a 100644 --- a/sys/amd64/amd64/sigtramp.S +++ b/sys/amd64/amd64/sigtramp.S @@ -27,18 +27,15 @@ */ #include - #include #include "assym.inc" .text -/********************************************************************** - * - * Signal trampoline, copied to top of user stack - * +/* + * Signal trampoline, mapped as vdso into shared page. */ -NON_GPROF_ENTRY(sigcode) +ENTRY(__vdso_sigcode) call *SIGF_HANDLER(%rsp) /* call signal handler */ lea SIGF_UC(%rsp),%rdi /* get ucontext_t */ pushq $0 /* junk to fake return addr. */ @@ -46,11 +43,6 @@ NON_GPROF_ENTRY(sigcode) syscall /* enter kernel with args */ 0: hlt /* trap priviliged instruction */ jmp 0b +END(__vdso_sigcode) - ALIGN_TEXT -esigcode: - - .data - .globl szsigcode -szsigcode: - .long esigcode-sigcode + .section .note.GNU-stack,"",%progbits diff --git a/sys/compat/linux/linux_vdso.c b/sys/compat/linux/linux_vdso.c index a05c0b01ff40..ba828c1b6816 100644 --- a/sys/compat/linux/linux_vdso.c +++ b/sys/compat/linux/linux_vdso.c @@ -110,7 +110,7 @@ __elfN(linux_vdso_fixup)(struct sysentvec *sv) Elf_Shdr *shdr; int i; - ehdr = (Elf_Ehdr *) sv->sv_sigcode; + ehdr = __DECONST(Elf_Ehdr *, sv->sv_sigcode); if (!IS_ELF(*ehdr) || ehdr->e_ident[EI_CLASS] != ELF_TARG_CLASS || @@ -153,7 +153,7 @@ __elfN(linux_vdso_reloc)(struct sysentvec *sv) Elf_Sym *sym; int i, j, symcnt; - ehdr = (Elf_Ehdr *) sv->sv_sigcode; + ehdr = __DECONST(Elf_Ehdr *, sv->sv_sigcode); /* Adjust our so relative to the sigcode_base */ if (sv->sv_shared_page_base != 0) { diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 index 633d9125398c..f529ffeba7e8 100644 --- a/sys/conf/files.amd64 +++ b/sys/conf/files.amd64 @@ -12,6 +12,12 @@ include "conf/files.x86" # dependency lines other than the first are silently ignored. # # +elf-vdso.so.o standard \ + dependency "$S/amd64/amd64/sigtramp.S assym.inc $S/tools/amd64_vdso.sh" \ + compile-with "env AWK='${AWK}' NM='${NM}' LD='${LD}' CC='${CC}' OBJCOPY='${OBJCOPY}' S='${S}' sh $S/tools/amd64_vdso.sh" \ + no-implicit-rule before-depend \ + clean "elf-vdso.so.o elf-vdso.so.1 vdso_offsets.h sigtramp.pico" +# cloudabi32_vdso.o optional compat_cloudabi32 \ dependency "$S/contrib/cloudabi/cloudabi_vdso_i686_on_64bit.S" \ compile-with "${CC} -x assembler-with-cpp -m32 -shared -nostdinc -nostdlib -Wl,-T$S/compat/cloudabi/cloudabi_vdso.lds $S/contrib/cloudabi/cloudabi_vdso_i686_on_64bit.S -o ${.TARGET}" \ @@ -124,7 +130,6 @@ amd64/amd64/mpboot.S optional smp amd64/amd64/pmap.c standard amd64/amd64/prof_machdep.c optional profiling-routine amd64/amd64/ptrace_machdep.c standard -amd64/amd64/sigtramp.S standard amd64/amd64/support.S standard amd64/amd64/sys_machdep.c standard amd64/amd64/trap.c standard diff --git a/sys/conf/vdso_amd64.ldscript b/sys/conf/vdso_amd64.ldscript new file mode 100644 index 000000000000..d412abd4cd02 --- /dev/null +++ b/sys/conf/vdso_amd64.ldscript @@ -0,0 +1,89 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2021 The FreeBSD Foundation + * + * 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. + */ + +/* + * Linker script for amd64 vdso. + */ + +PHDRS +{ + text PT_LOAD FILEHDR PHDRS FLAGS(5); /* PF_R|PF_X */ + dynamic PT_DYNAMIC FLAGS(5); + eh_frame_hdr PT_GNU_EH_FRAME FLAGS(5); +} + +SECTIONS +{ + . = . + SIZEOF_HEADERS; + + .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } :text + .dynsym : { *(.dynsym) } :text + .dynstr : { *(.dynstr) } :text + .gnu.version : { *(.gnu.version) } :text + .gnu.version_d : { *(.gnu.version_d) } :text + .gnu.version_r : { *(.gnu.version_r) } :text + .eh_frame_hdr : { *(.eh_frame_hdr) } :text :eh_frame_hdr + .eh_frame : { KEEP (*(.eh_frame)) } :text + .dynamic : { *(.dynamic) } :text :dynamic + .rodata : { *(.rodata*) } :text + .data : { + *(.got.plt) *(.got) + } :text + /DISCARD/ /* .data */: { + *(.data*) + *(.sdata*) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + *(.ctors) + *(.dtors) + *(.jcr) + *(.init_array) + *(.init) + *(.fini) + *(.debug*) + *(.comment) + } + + . = ALIGN(0x10); + .text : { *(.text .text*) } :text =0x90909090 +} + +VERSION +{ + FBSD_1.7 { + global: + __vdso_sigcode; + local: + *; + }; +} diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 21af09265dd2..dc3068c29514 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -3100,7 +3100,9 @@ sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS) if (sv->sv_sigcode_base != 0) { kst32.ksigtramp_start = sv->sv_sigcode_base; kst32.ksigtramp_end = sv->sv_sigcode_base + - *sv->sv_szsigcode; + ((sv->sv_flags & SV_DSO_SIG) == 0 ? + *sv->sv_szsigcode : + (uintptr_t)sv->sv_szsigcode); } else { kst32.ksigtramp_start = sv->sv_psstrings - *sv->sv_szsigcode; @@ -3116,7 +3118,8 @@ sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS) if (sv->sv_sigcode_base != 0) { kst.ksigtramp_start = (char *)sv->sv_sigcode_base; kst.ksigtramp_end = (char *)sv->sv_sigcode_base + - *sv->sv_szsigcode; + ((sv->sv_flags & SV_DSO_SIG) == 0 ? *sv->sv_szsigcode : + (uintptr_t)sv->sv_szsigcode); } else { kst.ksigtramp_start = (char *)sv->sv_psstrings - *sv->sv_szsigcode; diff --git a/sys/kern/kern_sharedpage.c b/sys/kern/kern_sharedpage.c index e47fbbe62bb7..98f7b619e0b7 100644 --- a/sys/kern/kern_sharedpage.c +++ b/sys/kern/kern_sharedpage.c @@ -305,10 +305,12 @@ void exec_sysvec_init(void *param) { struct sysentvec *sv; + vm_offset_t sb; #ifdef RANDOM_FENESTRASX ptrdiff_t base; #endif u_int flags; + int res; sv = param; flags = sv->sv_flags; @@ -319,8 +321,20 @@ exec_sysvec_init(void *param) sv->sv_shared_page_obj = shared_page_obj; if ((flags & SV_ABI_MASK) == SV_ABI_FREEBSD) { - sv->sv_sigcode_base = sv->sv_shared_page_base + - shared_page_fill(*(sv->sv_szsigcode), 16, sv->sv_sigcode); + if ((flags & SV_DSO_SIG) != 0) { + sb = sv->sv_shared_page_base; + res = shared_page_fill((uintptr_t)sv->sv_szsigcode, + 16, sv->sv_sigcode); + if (res == -1) + panic("copying sigtramp to shared page"); + sb += res; + sb += sv->sv_sigcodeoff; + sv->sv_sigcode_base = sb; + } else { + sv->sv_sigcode_base = sv->sv_shared_page_base + + shared_page_fill(*(sv->sv_szsigcode), 16, + sv->sv_sigcode); + } } if ((flags & SV_TIMEKEEP) != 0) { #ifdef COMPAT_FREEBSD32 diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h index d95ea5cd9038..cc3f183ff7cd 100644 --- a/sys/sys/sysent.h +++ b/sys/sys/sysent.h @@ -108,8 +108,9 @@ struct sysentvec { /* stack fixup function */ void (*sv_sendsig)(void (*)(int), struct ksiginfo *, struct __sigset *); /* send signal */ - char *sv_sigcode; /* start of sigtramp code */ + const char *sv_sigcode; /* start of sigtramp code */ int *sv_szsigcode; /* size of sigtramp code */ + int sv_sigcodeoff; char *sv_name; /* name of binary type */ int (*sv_coredump)(struct thread *, struct vnode *, off_t, int); /* function to dump core, or NULL */ @@ -164,6 +165,7 @@ struct sysentvec { #define SV_RNG_SEED_VER 0x100000 /* random(4) reseed generation. */ #define SV_SIG_DISCIGN 0x200000 /* Do not discard ignored signals */ #define SV_SIG_WAITNDQ 0x400000 /* Wait does not dequeue SIGCHLD */ +#define SV_DSO_SIG 0x800000 /* Signal trampoline packed in dso */ #define SV_ABI_MASK 0xff #define SV_PROC_FLAG(p, x) ((p)->p_sysent->sv_flags & (x)) diff --git a/sys/tools/amd64_vdso.sh b/sys/tools/amd64_vdso.sh new file mode 100644 index 000000000000..39406eccd2ef --- /dev/null +++ b/sys/tools/amd64_vdso.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2021 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. + +set -e + +${CC} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \ + -o sigtramp.pico -I. -I"${S}" -include opt_global.h \ + "${S}"/amd64/amd64/sigtramp.S + +# We need to make vdso as compact as possible, for it to leave space +# for other things in the shared page. For this, we pack everything +# into single loadable segment. +# +# -z rodynamic is undocumented lld-specific option, seemingly required +# for lld to avoid putting dynamic into dedicated writeable segment, +# despite ldscript placement. It is ignored by ld.bfd but ldscript +# alone is enough there. +# +${LD} --shared -Bsymbolic -soname="elf-vdso.so.1" \ + -T "${S}"/conf/vdso_amd64.ldscript \ + --eh-frame-hdr --no-undefined -z rodynamic -z norelro -nmagic \ + --hash-style=sysv --fatal-warnings --strip-all \ + -o elf-vdso.so.1 sigtramp.pico + +${CC} -x assembler-with-cpp -DLOCORE -fPIC -nostdinc -c \ + -o elf-vdso.so.o -I. -I"${S}" -include opt_global.h \ + -DVDSO_NAME=elf_vdso_so_1 -DVDSO_FILE=elf-vdso.so.1 \ + "${S}"/tools/vdso_wrap.S + +${NM} -D elf-vdso.so.1 | \ + awk '/__vdso_sigcode/{printf "#define VDSO_SIGCODE_OFFSET 0x%s\n",$1}' \ + >vdso_offsets.h diff --git a/sys/tools/vdso_wrap.S b/sys/tools/vdso_wrap.S new file mode 100644 index 000000000000..807dcf9c06f4 --- /dev/null +++ b/sys/tools/vdso_wrap.S @@ -0,0 +1,48 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 The FreeBSD Foundation + * + * 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. + */ + +#include + +#define VDSO_BLOB_START(S) __CONCAT(_binary_, __CONCAT(S, _start)) +#define VDSO_BLOB_END(S) __CONCAT(_binary_, __CONCAT(S, _end)) +#define VDSO_BLOB_SIZE(S) __CONCAT(_binary_, __CONCAT(S, _size)) + + .section .rodata, "a", %progbits + .globl VDSO_BLOB_START(VDSO_NAME) + .type VDSO_BLOB_START(VDSO_NAME), %object + .size VDSO_BLOB_START(VDSO_NAME), 0 +VDSO_BLOB_START(VDSO_NAME): + .incbin __XSTRING(VDSO_FILE) + .globl VDSO_BLOB_END(VDSO_NAME) + .type VDSO_BLOB_END(VDSO_NAME), %object + .size VDSO_BLOB_END(VDSO_NAME), 0 +VDSO_BLOB_END(VDSO_NAME): + .globl VDSO_BLOB_SIZE(VDSO_NAME) + .set VDSO_BLOB_SIZE(VDSO_NAME), . - VDSO_BLOB_START(VDSO_NAME)