From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631051927909865.5970702250074; Tue, 7 Sep 2021 14:58:47 -0700 (PDT) Received: from localhost ([::1]:39432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj78-00062N-SR for importer@patchew.org; Tue, 07 Sep 2021 17:58:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2I-0005YA-5K for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:46 -0400 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]:44756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2D-0000g3-1X for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:45 -0400 Received: by mail-io1-xd43.google.com with SMTP id g9so437030ioq.11 for ; Tue, 07 Sep 2021 14:53:40 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JiY2LSjoh75ub8VVneYrxWM+2JBoL2yaQmYAF6M1zUI=; b=bbqtVXq1pZTErUwkbIRfV00LVo32kQ8ioOSOotF35mdBf9GXfN6Azc0B7MyCtQBOAz RLf581ZHS4GYbZfnJYg0T6p7Ep+LS9ajCXmXgNbisUmC66wxuOIELG6YaYcfND12Y8yL kBKa3LHQKet8hYpamP8vSUh/cXnrzOdAU8MZbP+w07GoiKQM6kQeCoeMWkmmas7F9R9u VfL7dN/jA6kpnxQvLV/PPTBeXDgiEyRplw7Ym5esO9BJjh6eslBXX2o4wCHdTGnJ37wj fx9Mw1tHPCQ//X5gjhz6r116fy12TJdNn/Fotq6SzcGnXUQ1eVUyyYvW3pBMKdEjBgUu AG8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JiY2LSjoh75ub8VVneYrxWM+2JBoL2yaQmYAF6M1zUI=; b=PWp9pJ9dTAAdVDl6ugpVxM5k6d0LExsZxz22bBjDUaVw9LSvaOvfsrvyNxBgP2RkXu 2VAb6RE4MdBSOiIgbvFUV+lNvJQ/K4xJJfO4XWBctpX9ETSWxLfVILpYZz+9s8oeHwNc YHjd++lixYMKh4EUQpX7cfMWUPEsWCDMYSEKnatQD2Xf1Pw50KKx8p9p5yEJdapEwMDH 1QQO/FJQXn9FaOQSfUYKa+4wqB2UiBhCvMMfOZ2x+cKqVmBb8eWFPedpjjSR8ugHNGlm OdJgWxb+yTdhEU2p9XFHswzdE30hija7DtCMpx7FxQjhV7GrOWgGj6us4kuSJPnV1/hI psXA== X-Gm-Message-State: AOAM530a4i/vGUS8HmdHy2ZsSQB1fptnmJAOp5pP0W27BQ0gJU1z+LpR 07f1OBmaaAUCVVq/IYkzr8vEAD0KcnrieOkdeZ4= X-Google-Smtp-Source: ABdhPJxagvDyL2w7+HmlG8jVXRRIsNhK6LeOKvT6YtvYCka3kmGHm7xb50gJHHS6oJTbBzT7ROh5zA== X-Received: by 2002:a05:6638:b10:: with SMTP id a16mr435878jab.149.1631051619182; Tue, 07 Sep 2021 14:53:39 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 01/42] bsd-user: remove sparc and sparc64 Date: Tue, 7 Sep 2021 15:52:51 -0600 Message-Id: <20210907215332.30737-2-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d43; envelope-from=imp@bsdimp.com; helo=mail-io1-xd43.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631051929633100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh These are broken here and in the bsd-user fork. They won't be fixed as FreeBSD has dropped support for sparc. If people wish to support this in other BSDs, you're better off starting over than starting from these files. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 289 ------------------------- bsd-user/sparc/target_arch_sysarch.h | 52 ----- bsd-user/sparc/target_syscall.h | 36 --- bsd-user/sparc64/target_arch_sysarch.h | 52 ----- bsd-user/sparc64/target_syscall.h | 37 ---- bsd-user/syscall.c | 11 - 6 files changed, 477 deletions(-) delete mode 100644 bsd-user/sparc/target_arch_sysarch.h delete mode 100644 bsd-user/sparc/target_syscall.h delete mode 100644 bsd-user/sparc64/target_arch_sysarch.h delete mode 100644 bsd-user/sparc64/target_syscall.h diff --git a/bsd-user/main.c b/bsd-user/main.c index fe66204b6b..38185da111 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -261,274 +261,6 @@ void cpu_loop(CPUX86State *env) } #endif =20 -#ifdef TARGET_SPARC -#define SPARC64_STACK_BIAS 2047 - -/* #define DEBUG_WIN */ -/* - * WARNING: dealing with register windows _is_ complicated. More info - * can be found at http://www.sics.se/~psm/sparcstack.html - */ -static inline int get_reg_index(CPUSPARCState *env, int cwp, int index) -{ - index =3D (index + cwp * 16) % (16 * env->nwindows); - /* - * wrap handling : if cwp is on the last window, then we use the - * registers 'after' the end - */ - if (index < 8 && env->cwp =3D=3D env->nwindows - 1) { - index +=3D 16 * env->nwindows; - } - return index; -} - -/* save the register window 'cwp1' */ -static inline void save_window_offset(CPUSPARCState *env, int cwp1) -{ - unsigned int i; - abi_ulong sp_ptr; - - sp_ptr =3D env->regbase[get_reg_index(env, cwp1, 6)]; -#ifdef TARGET_SPARC64 - if (sp_ptr & 3) { - sp_ptr +=3D SPARC64_STACK_BIAS; - } -#endif -#if defined(DEBUG_WIN) - printf("win_overflow: sp_ptr=3D0x" TARGET_ABI_FMT_lx " save_cwp=3D%d\n= ", - sp_ptr, cwp1); -#endif - for (i =3D 0; i < 16; i++) { - /* FIXME - what to do if put_user() fails? */ - put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr= ); - sp_ptr +=3D sizeof(abi_ulong); - } -} - -static void save_window(CPUSPARCState *env) -{ -#ifndef TARGET_SPARC64 - unsigned int new_wim; - new_wim =3D ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) & - ((1LL << env->nwindows) - 1); - save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2)); - env->wim =3D new_wim; -#else - /* - * cansave is zero if the spill trap handler is triggered by `save` and - * nonzero if triggered by a `flushw` - */ - save_window_offset(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2)); - env->cansave++; - env->canrestore--; -#endif -} - -static void restore_window(CPUSPARCState *env) -{ -#ifndef TARGET_SPARC64 - unsigned int new_wim; -#endif - unsigned int i, cwp1; - abi_ulong sp_ptr; - -#ifndef TARGET_SPARC64 - new_wim =3D ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) & - ((1LL << env->nwindows) - 1); -#endif - - /* restore the invalid window */ - cwp1 =3D cpu_cwp_inc(env, env->cwp + 1); - sp_ptr =3D env->regbase[get_reg_index(env, cwp1, 6)]; -#ifdef TARGET_SPARC64 - if (sp_ptr & 3) { - sp_ptr +=3D SPARC64_STACK_BIAS; - } -#endif -#if defined(DEBUG_WIN) - printf("win_underflow: sp_ptr=3D0x" TARGET_ABI_FMT_lx " load_cwp=3D%d\= n", - sp_ptr, cwp1); -#endif - for (i =3D 0; i < 16; i++) { - /* FIXME - what to do if get_user() fails? */ - get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr= ); - sp_ptr +=3D sizeof(abi_ulong); - } -#ifdef TARGET_SPARC64 - env->canrestore++; - if (env->cleanwin < env->nwindows - 1) { - env->cleanwin++; - } - env->cansave--; -#else - env->wim =3D new_wim; -#endif -} - -static void flush_windows(CPUSPARCState *env) -{ - int offset, cwp1; - - offset =3D 1; - for (;;) { - /* if restore would invoke restore_window(), then we can stop */ - cwp1 =3D cpu_cwp_inc(env, env->cwp + offset); -#ifndef TARGET_SPARC64 - if (env->wim & (1 << cwp1)) { - break; - } -#else - if (env->canrestore =3D=3D 0) { - break; - } - env->cansave++; - env->canrestore--; -#endif - save_window_offset(env, cwp1); - offset++; - } - cwp1 =3D cpu_cwp_inc(env, env->cwp + 1); -#ifndef TARGET_SPARC64 - /* set wim so that restore will reload the registers */ - env->wim =3D 1 << cwp1; -#endif -#if defined(DEBUG_WIN) - printf("flush_windows: nb=3D%d\n", offset - 1); -#endif -} - -void cpu_loop(CPUSPARCState *env) -{ - CPUState *cs =3D env_cpu(env); - int trapnr, ret, syscall_nr; - /* target_siginfo_t info; */ - - while (1) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { -#ifndef TARGET_SPARC64 - case 0x80: -#else - /* FreeBSD uses 0x141 for syscalls too */ - case 0x141: - if (bsd_type !=3D target_freebsd) { - goto badtrap; - } - /* fallthrough */ - case 0x100: -#endif - syscall_nr =3D env->gregs[1]; - if (bsd_type =3D=3D target_freebsd) - ret =3D do_freebsd_syscall(env, syscall_nr, - env->regwptr[0], env->regwptr[1], - env->regwptr[2], env->regwptr[3], - env->regwptr[4], env->regwptr[5], - 0, 0); - else if (bsd_type =3D=3D target_netbsd) - ret =3D do_netbsd_syscall(env, syscall_nr, - env->regwptr[0], env->regwptr[1], - env->regwptr[2], env->regwptr[3], - env->regwptr[4], env->regwptr[5]); - else { /* if (bsd_type =3D=3D target_openbsd) */ -#if defined(TARGET_SPARC64) - syscall_nr &=3D ~(TARGET_OPENBSD_SYSCALL_G7RFLAG | - TARGET_OPENBSD_SYSCALL_G2RFLAG); -#endif - ret =3D do_openbsd_syscall(env, syscall_nr, - env->regwptr[0], env->regwptr[1], - env->regwptr[2], env->regwptr[3], - env->regwptr[4], env->regwptr[5]); - } - if ((unsigned int)ret >=3D (unsigned int)(-515)) { - ret =3D -ret; -#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) - env->xcc |=3D PSR_CARRY; -#else - env->psr |=3D PSR_CARRY; -#endif - } else { -#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) - env->xcc &=3D ~PSR_CARRY; -#else - env->psr &=3D ~PSR_CARRY; -#endif - } - env->regwptr[0] =3D ret; - /* next instruction */ -#if defined(TARGET_SPARC64) - if (bsd_type =3D=3D target_openbsd && - env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) { - env->pc =3D env->gregs[2]; - env->npc =3D env->pc + 4; - } else if (bsd_type =3D=3D target_openbsd && - env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) { - env->pc =3D env->gregs[7]; - env->npc =3D env->pc + 4; - } else { - env->pc =3D env->npc; - env->npc =3D env->npc + 4; - } -#else - env->pc =3D env->npc; - env->npc =3D env->npc + 4; -#endif - break; - case 0x83: /* flush windows */ -#ifdef TARGET_ABI32 - case 0x103: -#endif - flush_windows(env); - /* next instruction */ - env->pc =3D env->npc; - env->npc =3D env->npc + 4; - break; -#ifndef TARGET_SPARC64 - case TT_WIN_OVF: /* window overflow */ - save_window(env); - break; - case TT_WIN_UNF: /* window underflow */ - restore_window(env); - break; - case TT_TFAULT: - case TT_DFAULT: - break; -#else - case TT_SPILL: /* window overflow */ - save_window(env); - break; - case TT_FILL: /* window underflow */ - restore_window(env); - break; - case TT_TFAULT: - case TT_DFAULT: - break; -#endif - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - case EXCP_DEBUG: - { - gdb_handlesig(cs, TARGET_SIGTRAP); - } - break; - default: -#ifdef TARGET_SPARC64 - badtrap: -#endif - printf("Unhandled trap: 0x%x\n", trapnr); - cpu_dump_state(cs, stderr, 0); - exit(1); - } - process_pending_signals(env); - } -} - -#endif - static void usage(void) { printf("qemu-" TARGET_NAME " version " QEMU_FULL_VERSION @@ -779,12 +511,6 @@ int main(int argc, char **argv) #else cpu_model =3D "qemu32"; #endif -#elif defined(TARGET_SPARC) -#ifdef TARGET_SPARC64 - cpu_model =3D "TI UltraSparc II"; -#else - cpu_model =3D "Fujitsu MB86904"; -#endif #else cpu_model =3D "any"; #endif @@ -800,9 +526,7 @@ int main(int argc, char **argv) } cpu =3D cpu_create(cpu_type); env =3D cpu->env_ptr; -#if defined(TARGET_SPARC) || defined(TARGET_PPC) cpu_reset(cpu); -#endif thread_cpu =3D cpu; =20 if (getenv("QEMU_STRACE")) { @@ -1001,19 +725,6 @@ int main(int argc, char **argv) cpu_x86_load_seg(env, R_FS, 0); cpu_x86_load_seg(env, R_GS, 0); #endif -#elif defined(TARGET_SPARC) - { - int i; - env->pc =3D regs->pc; - env->npc =3D regs->npc; - env->y =3D regs->y; - for (i =3D 0; i < 8; i++) { - env->gregs[i] =3D regs->u_regs[i]; - } - for (i =3D 0; i < 8; i++) { - env->regwptr[i] =3D regs->u_regs[i + 8]; - } - } #else #error unsupported target CPU #endif diff --git a/bsd-user/sparc/target_arch_sysarch.h b/bsd-user/sparc/target_a= rch_sysarch.h deleted file mode 100644 index d0b85ef6bb..0000000000 --- a/bsd-user/sparc/target_arch_sysarch.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SPARC sysarch() system call emulation - * - * Copyright (c) 2013 Stacey D. Son - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#ifndef BSD_USER_ARCH_SYSARCH_H_ -#define BSD_USER_ARCH_SYSARCH_H_ - -#include "target_syscall.h" - -static inline abi_long do_freebsd_arch_sysarch(void *env, int op, - abi_ulong parms) -{ - int ret =3D 0; - - switch (op) { - case TARGET_SPARC_SIGTRAMP_INSTALL: - /* XXX not currently handled */ - case TARGET_SPARC_UTRAP_INSTALL: - /* XXX not currently handled */ - default: - ret =3D -TARGET_EINVAL; - break; - } - - return ret; -} - -static inline void do_freebsd_arch_print_sysarch( - const struct syscallname *name, abi_long arg1, abi_long arg2, - abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) -{ - - gemu_log("%s(%d, " TARGET_ABI_FMT_lx ", " TARGET_ABI_FMT_lx ", " - TARGET_ABI_FMT_lx ")", name->name, (int)arg1, arg2, arg3, arg4); -} - -#endif /*!BSD_USER_ARCH_SYSARCH_H_ */ diff --git a/bsd-user/sparc/target_syscall.h b/bsd-user/sparc/target_syscal= l.h deleted file mode 100644 index 151284754b..0000000000 --- a/bsd-user/sparc/target_syscall.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * sparc dependent system call definitions - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ -#ifndef TARGET_SYSCALL_H -#define TARGET_SYSCALL_H - -struct target_pt_regs { - abi_ulong psr; - abi_ulong pc; - abi_ulong npc; - abi_ulong y; - abi_ulong u_regs[16]; -}; - -#define UNAME_MACHINE "sun4" -#define TARGET_HW_MACHINE "sparc" -#define TARGET_HW_MACHINE_ARCH "sparc" - -#define TARGET_SPARC_UTRAP_INSTALL 1 -#define TARGET_SPARC_SIGTRAMP_INSTALL 2 - -#endif /* TARGET_SYSCALL_H */ diff --git a/bsd-user/sparc64/target_arch_sysarch.h b/bsd-user/sparc64/targ= et_arch_sysarch.h deleted file mode 100644 index e6f17c1504..0000000000 --- a/bsd-user/sparc64/target_arch_sysarch.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SPARC64 sysarch() system call emulation - * - * Copyright (c) 2013 Stacey D. Son - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#ifndef BSD_USER_ARCH_SYSARCH_H_ -#define BSD_USER_ARCH_SYSARCH_H_ - -#include "target_syscall.h" - -static inline abi_long do_freebsd_arch_sysarch(void *env, int op, - abi_ulong parms) -{ - int ret =3D 0; - - switch (op) { - case TARGET_SPARC_SIGTRAMP_INSTALL: - /* XXX not currently handled */ - case TARGET_SPARC_UTRAP_INSTALL: - /* XXX not currently handled */ - default: - ret =3D -TARGET_EINVAL; - break; - } - - return ret; -} - -static inline void do_freebsd_arch_print_sysarch( - const struct syscallname *name, abi_long arg1, abi_long arg2, - abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) -{ - - gemu_log("%s(%d, " TARGET_ABI_FMT_lx ", " TARGET_ABI_FMT_lx ", " - TARGET_ABI_FMT_lx ")", name->name, (int)arg1, arg2, arg3, arg4); -} - -#endif /*!BSD_USER_ARCH_SYSARCH_H_ */ diff --git a/bsd-user/sparc64/target_syscall.h b/bsd-user/sparc64/target_sy= scall.h deleted file mode 100644 index b7d986a76d..0000000000 --- a/bsd-user/sparc64/target_syscall.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * sparc64 dependent system call definitions - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ -#ifndef TARGET_SYSCALL_H -#define TARGET_SYSCALL_H - -struct target_pt_regs { - abi_ulong u_regs[16]; - abi_ulong tstate; - abi_ulong pc; - abi_ulong npc; - abi_ulong y; - abi_ulong fprs; -}; - -#define UNAME_MACHINE "sun4u" -#define TARGET_HW_MACHINE "sparc" -#define TARGET_HW_MACHINE_ARCH "sparc64" - -#define TARGET_SPARC_UTRAP_INSTALL 1 -#define TARGET_SPARC_SIGTRAMP_INSTALL 2 - -#endif /* TARGET_SYSCALL_H */ diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c index 3f44311396..372836d44d 100644 --- a/bsd-user/syscall.c +++ b/bsd-user/syscall.c @@ -138,17 +138,6 @@ static abi_long do_freebsd_sysarch(CPUX86State *env, i= nt op, abi_ulong parms) } #endif =20 -#ifdef TARGET_SPARC -static abi_long do_freebsd_sysarch(void *env, int op, abi_ulong parms) -{ - /* XXX handle - * TARGET_FREEBSD_SPARC_UTRAP_INSTALL, - * TARGET_FREEBSD_SPARC_SIGTRAMP_INSTALL - */ - return -TARGET_EINVAL; -} -#endif - #ifdef __FreeBSD__ /* * XXX this uses the undocumented oidfmt interface to find the kind of --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631051760227459.9859449366255; Tue, 7 Sep 2021 14:56:00 -0700 (PDT) Received: from localhost ([::1]:58686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj4Q-0008MB-Tg for importer@patchew.org; Tue, 07 Sep 2021 17:55:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2G-0005VS-IO for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:44 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:33656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2D-0000gK-29 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:44 -0400 Received: by mail-io1-xd42.google.com with SMTP id f6so536052iox.0 for ; Tue, 07 Sep 2021 14:53:40 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hJRZgQI+QtTgjpShWzcLDKaF2c/eXvqYd/GhPRaiuEQ=; b=cVwOc3leCb1qBayKsoDvzsS7MSG4mbs6CbBwBqcwYER8EJeQxhI7No57J3lsVGnFwE KyoDlbN32kdoZ7gQ8S5qMmILJ1Ysodxa0tqsazQ3uHrrtNUCi6hJ741UPfQ00ik7qTHV 7bdV/85jqlAYjpiaP+mVKqqFG69a9pt9da6CgQQgZYGXBARNNbovDEzf3cWYz1qvhQtp BzXZ3xG7VSO4GEibQMEV9KwPoV8Vz7iamuP5HWC35CPECPDh7tV+zhe7n7bsU4zxAPrE xZ/EZdBx6xp8tuyFSQBcmQ20UPeruE8pUTZwDsdcYpdSdN+mThbn/3zpbZ5TLDiRxxOX wasw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hJRZgQI+QtTgjpShWzcLDKaF2c/eXvqYd/GhPRaiuEQ=; b=i9+yKgDmKNMkusKbkvdU0HVLAUW1NEkATwa9P/WlvQ9i6+99cL8bkL4tseUGvYY8gi 2UNQReN1d/fe3hbwXWgMa+RsXk50SKSUXojyqKiZKocuXbxrd7+pWTrg9aXaoUcJ7Bd9 mOQ9uXnacfXFfi6TPDVAmQ0MssYzdypJAxbZ85VVOSsGXkxwnKdLz7Aud6Gqics6OyrJ NDZXtweWh2bzLB4BMilNTrNctyHAJR9AYjd5f0i/pVAZbnnrfNvEUt8FfDNx5sqyTmrK QlhdekhRXGeyLD3n6Ja1EkPzedJobSBYEpBqdxI8F9HywXfEsc77LbJCLhOzdlQE3635 UYsA== X-Gm-Message-State: AOAM533qLif+yT1wN9/pQEVIzi1jRL/Lsu2LfHyQ+/WqoCz41DbcX1U+ oyJuILB7CqQR6QDoctcwTfrMRk5C1HnfNzSJ6z4= X-Google-Smtp-Source: ABdhPJzqT9YX7AaSmppfDbxvnqQ6+c+E6/9SQtpk24q8l9tKDwV0F0aE4tc3tMnLTJQGBvxChISd7g== X-Received: by 2002:a05:6602:20ce:: with SMTP id 14mr285574ioz.204.1631051619853; Tue, 07 Sep 2021 14:53:39 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 02/42] bsd-user: add copyright header to elfload.c Date: Tue, 7 Sep 2021 15:52:52 -0600 Message-Id: <20210907215332.30737-3-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d42; envelope-from=imp@bsdimp.com; helo=mail-io1-xd42.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631051761260100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Add Stacey's copyright to elfload.c Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 6edceb3ea6..ae62f3aab3 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -1,4 +1,21 @@ -/* This is the Linux kernel elf-loading code, ported into user space */ +/* + * ELF loading code + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ =20 #include "qemu/osdep.h" =20 --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631051918497538.1373510115828; Tue, 7 Sep 2021 14:58:38 -0700 (PDT) Received: from localhost ([::1]:39054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj6z-0005mV-FH for importer@patchew.org; Tue, 07 Sep 2021 17:58:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2J-0005bM-Ea for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:47 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]:40900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2F-0000hN-6J for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:47 -0400 Received: by mail-io1-xd30.google.com with SMTP id z1so455040ioh.7 for ; Tue, 07 Sep 2021 14:53:41 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KMQsbMY5NaOGHicHu9VbpgyM/1xluEbSzTVfLIIvix4=; b=b2q/NpmzpNr32WJGHUK+038vXDhl8qe3ccjx0s+cCfda092jT1oOUzrZpa9+1c9Eyk LAowrOLxFxY83nl92ck5mPF6muJmU5eqPs4s13VxdDicLuXiStHAoknTTE0heK7hsYin UIvwgTUOPidoE1Cg1z12ql8N2GxwgTQV50VoawH0jBgIiyPwxxrv6nDvX0hn64J4zFpP FvDtkmtM7V2a01CnVXi1eXCdsDwySQu+/FH2fYi+d88Me/AKIZppZJmlth05I4XTfFhq 1y5z/aL/k/pOWILaRTHoSyxF9vqdBQPIFP89EGf4qEA2LGKLMzsrJ2zB73Lc5Jbasagg DMbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KMQsbMY5NaOGHicHu9VbpgyM/1xluEbSzTVfLIIvix4=; b=NahktRv4UUVwws8xfBsfrI001epohU0cysDK0T1JnyjqyCIJXHWFScmKowm1HmcL38 +cdq+GgQgxPyoeHr3aStmNFES5sn+L3vifb3cmIquWmWhqAEuhKYk95zvkZYzHYY/jil rOJ1DlcoDuieqOGkxCuTO6r1Y9f8uHVwgmOMo/VbYWbFs8R55E5UrqrRws605Xl9iWdk fnul/pw4yIRYSm8rBDJksNxextF7KIYKP7B9bbh7QRskNNVECsbVXq/VMWmmuIw7q1RQ HLUvjQnvBzyqH8XrLLtTEO7usY7JSBZ2CLckcygC5PmfE9gW/4r/OKHkWIpynSSonvqX 8m7w== X-Gm-Message-State: AOAM531L5ofm81QdSl1Eysmb1HrXa2NzADzYAQ49jlocnQEBWSS+4OzV dq0illfLkWt3+nSV2ypu8AFXRXbYXBWekASvN3A= X-Google-Smtp-Source: ABdhPJxEQo/INhRnMZm8oSuR38iQWT4oCzV2ROgV1Lhw7kugxOo6R9k6gqQ/semeYOIpoPfClkSEHw== X-Received: by 2002:a05:6638:5aa:: with SMTP id b10mr472812jar.76.1631051620932; Tue, 07 Sep 2021 14:53:40 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 03/42] bsd-user: Add Stacey's copyright to main.c Date: Tue, 7 Sep 2021 15:52:53 -0600 Message-Id: <20210907215332.30737-4-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631051919016100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Add Stacey's updated copyright to main.c Signed-off-by: Warner Losh Signed-off-by: Stacey Son Reviewed-by: Richard Henderson --- bsd-user/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 38185da111..39c4a0f33c 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -1,7 +1,8 @@ /* - * qemu user main + * qemu bsd user main * * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2013-14 Stacey Son * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631051762391461.84032137669067; Tue, 7 Sep 2021 14:56:02 -0700 (PDT) Received: from localhost ([::1]:58944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj4T-0008WE-Dv for importer@patchew.org; Tue, 07 Sep 2021 17:56:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2H-0005Xd-UR for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:45 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]:38556) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2F-0000i0-Ps for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:45 -0400 Received: by mail-io1-xd41.google.com with SMTP id a13so463605iol.5 for ; Tue, 07 Sep 2021 14:53:43 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lv7qzc+bwvqvCUY7KRQHdm4K9UxT525dj3NdW6F5N3A=; b=awhNazjkiWjn6vpXmSZuRBQGqEWb9NQLBT80TJi+AdV1wMHvVp5iTclBc0ZQnftMeq FjClOvklPEZzSgVFpHbfF9ejA6RzlNMqehRRwzq7yem5Al2Rxd0MHBnhr6Im0lF9T/+7 6G35/m6Be9TXvc6nXKr3gyZYWbyj9HFgrnwbHpZebihqdorBohQBQFF5WqH+mVmAXLuh X/vkmn08M0XZpDUzYbrzx1FCI+F1LAbedGfZqscnJ1x0Sfp/5dx3135e2CpdEn6/qyFt VyjsNQ/8x1wyC7i9rE5Vl6ZA7BhkOcfHO21x3WXMhCt6gJXzBPsG79DmsDWclIXlCkRN /zUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lv7qzc+bwvqvCUY7KRQHdm4K9UxT525dj3NdW6F5N3A=; b=q7yRe6HDsx64vfxnZM8geZStcyIg0BJXzc9ob9k+mElEjLanUhFFI/pnlEVdq+IYv0 VYHa00QamOZX0BTlgHfoMT1JC5Qo9R4vvivn/T7kpvl5SNImu6h/BLXcZ/lPk+EAnhXp 0auN/XrCPVQBo2ddHySLjRsS69xhQoy0h0LOXNK99hv0soOJtyhieILuOFqOTQCPTiH8 rjVU3+iwQ2joS5YAEwWlVoG8zvbWQFcyg8Ifzt3Lq+fGuQIxQpdLZoq7it26ZEwC89Ek n43scEvZ0F0hmUnABOijpqQ2JZnMIyD5Y2G8pH37ApYNFV5zuyVK3hEUx8C+X0XvGSVA hCzQ== X-Gm-Message-State: AOAM532JgSacEP6ks5rg2ONSHBHXJXUS/0r4boolxga+cC6av3O0jD8x nGCjlYaNwpT8lwEwNlUOUbNF3+3SO2I6cGdYgfU= X-Google-Smtp-Source: ABdhPJznRYSk2ZiOSYK+GK1aIpb7BEjYrDn+pxnN5BBMc9vZe//U0nLBobxsSKos/e5KP0xHZvyfpQ== X-Received: by 2002:a05:6638:e8f:: with SMTP id p15mr454456jas.114.1631051621647; Tue, 07 Sep 2021 14:53:41 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 04/42] bsd-user: add license to bsdload.c Date: Tue, 7 Sep 2021 15:52:54 -0600 Message-Id: <20210907215332.30737-5-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d41; envelope-from=imp@bsdimp.com; helo=mail-io1-xd41.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631051763182100005 Content-Type: text/plain; charset="utf-8" From: Warner Losh Pull in the license statement at the top of the bsdload.c file from the bsd-user fork version of this file. No functional changes. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsdload.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 8d83f21eda..0ade58b9e2 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -1,4 +1,19 @@ -/* Code for loading BSD executables. Mostly linux kernel code. */ +/* + * Load BSD executables. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ =20 #include "qemu/osdep.h" =20 --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631051918501319.3692331281695; Tue, 7 Sep 2021 14:58:38 -0700 (PDT) Received: from localhost ([::1]:39040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj6z-0005ls-Db for importer@patchew.org; Tue, 07 Sep 2021 17:58:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2H-0005WU-Aj for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:45 -0400 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]:37514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2F-0000iM-NC for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:45 -0400 Received: by mail-io1-xd31.google.com with SMTP id b7so472026iob.4 for ; Tue, 07 Sep 2021 14:53:43 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=okxKdJbOUcfEuQyncikhmmKgqqr7aQZgUfGvRlvwHSo=; b=fvbmt0/KgZdk5BI8LuSE+LA35revyjxtISv/IBgFwURxWkdOMpZUwtY8yUcY5+drC5 LL9jv+wlrSiVEggNF3lOOvuu0I1WAkB58ijgj/9COjGQtFD7fSaQolSbFNO3e7r4SOvb S0wbeH33DheNCMWAlQcple2BUfauqaKe+PqOFLxNeiDoJ7Z6jI1OEL+0r5rVG3fY+hN5 OeUv1y6UvxlnXmOzetbXsi9eJF+5qmcFNwzyMPhBjgUTmCjNNjWeInCpav9x8d2vqx97 eUv18JbyW6P/xE4Gclre0dYIH6uT6BDu1eTJRGFfMGtdk7VgwGEaU/todKHtllBQ6xd9 lWeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=okxKdJbOUcfEuQyncikhmmKgqqr7aQZgUfGvRlvwHSo=; b=HhhqEVIX06cEiTg2CjG+V9aBPPXnnD0sNNP53b6JmMqQc8tvsKlyPbNZ0DYaJsOIDg GUxhwuQFSLnaDWcm9Z6rPH6fE87ImCpxZVHWS3UTuIOoJIl+qvso2DZdJvyiPtJRcZ5+ zdU0bU4iGgiqR4sM4/NxGCEG1vCJfzqDvspkaiyPG538EZQbwl/zned5Y6V+9DjPMBGA a0ZQqDux1U+AOtXQ9GXtVydL0VINqJ+uNYMRrWotZFiSrZu6UZIq3pzvqjkiysvPe66/ SQGU9JNr1V3X4TVhLeBUykIf+8TXuIQMyJ7wsMkna1XbP+gGlKa7jTLi4Dgo4rg7F7/Q L+aw== X-Gm-Message-State: AOAM530EcFlZO15aRDZRVhhLiGR7SE41GCU0xF4iVlobeiysyxgbnOvt KngkFZH8FruKBoYf3RtyqTyFpczUbr0NUvkT5Aw= X-Google-Smtp-Source: ABdhPJzdSMIaQlYOHGhWbO0799BbqZ6hbYDZRrgWs0XP1xaUEm0fN7i3qwABESI2/tpr2jVHaoNvsA== X-Received: by 2002:a02:6a55:: with SMTP id m21mr467307jaf.74.1631051622494; Tue, 07 Sep 2021 14:53:42 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 05/42] bsd-user: style nits: bsdload.c whitespace to qemu standard Date: Tue, 7 Sep 2021 15:52:55 -0600 Message-Id: <20210907215332.30737-6-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d31; envelope-from=imp@bsdimp.com; helo=mail-io1-xd31.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631051919022100002 Content-Type: text/plain; charset="utf-8" From: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsdload.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 0ade58b9e2..ec71c5e923 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -140,7 +140,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_u= long sp, } =20 int loader_exec(const char *filename, char **argv, char **envp, - struct target_pt_regs *regs, struct image_info *infop) + struct target_pt_regs *regs, struct image_info *infop) { struct bsd_binprm bprm; int retval; @@ -148,7 +148,7 @@ int loader_exec(const char *filename, char **argv, char= **envp, =20 bprm.p =3D TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int); for (i =3D 0 ; i < MAX_ARG_PAGES ; i++) { /* clear page-table */ - bprm.page[i] =3D NULL; + bprm.page[i] =3D NULL; } retval =3D open(filename, O_RDONLY); if (retval < 0) { --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052105572498.5912376768198; Tue, 7 Sep 2021 15:01:45 -0700 (PDT) Received: from localhost ([::1]:48098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj9z-0003cJ-99 for importer@patchew.org; Tue, 07 Sep 2021 18:01:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2J-0005b4-82 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:47 -0400 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]:43622) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2G-0000jM-Na for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:46 -0400 Received: by mail-il1-x132.google.com with SMTP id v16so150372ilo.10 for ; Tue, 07 Sep 2021 14:53:44 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aHS6Rdb0mnIzaMMDe+TiCha8i0FkDadRF9jxmF4Q8IQ=; b=zpzB6D9geH7z9PvsDnZ7BNaIMBOKWI8jktmKqztzaeumJtr1yZ/lB/PdiNJYU4bGr+ 8jBmPOxXphoY3Ou4sOpfrmaQBIshLi1waJwP3NWTv8m6W8N+E/iR4/Z/isCNhgdfPNfO RrXJcOxsTQDLUuATt06KfY7pNJq5+lA0RsthowBB3aN398KnhzBh+Bn+5PArAScYSZ7l LuO3jd54HUZ60B/9iyuUONvm4Q0wKIyIdDG8Rpuqx6Q24oIY1bdqIaaFt1lnxq0kxgB8 VOpBgQerq0Klhq4d1CWVuab4cjDiPuMyVM/BPqGu6OqWzTjHXYahIDka4swAGtX+ghCI gDvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aHS6Rdb0mnIzaMMDe+TiCha8i0FkDadRF9jxmF4Q8IQ=; b=PW2i09YBDWR3IdU4FxgW0dgYHKF6odBn1vQPRKRrjbHUZQEH4RAYV6AGrm+URibfpn 1M3W5E23HRzVCp6CVW48Y9JhT8spcFqVA8+RPbmyx3ZPgx3KE+nUbc3Tf9QSJ+VC3/Um dpJFbLfuQtPay85GOlL9ep/67ATF2jl/2VaV4cPks8UHIQbHx+WFk4mrIWfCyMS0Cr4M f3ZFk/4ICSBjAh+U/FWqEejoxZ8BFBxPHu/lXrrMGpymI7ucfT/jWxZSTH/IOgUOsRyI NKs64lOQj6fKRC2oZs2y6Pm3HM90VEZPygzg7VU8SEMs5I7Wr5hkox+aY7B7A+iGunzy MZAQ== X-Gm-Message-State: AOAM533DGMgx01DkXHmsfdYIvAjt0TgI7ka+mlveANH1qOJob/HLar7t TZ9BQiZ4g5jQYQ4tn4NUj0L01judxJYptmQJV4Q= X-Google-Smtp-Source: ABdhPJxqHMVla7V34458/NLIR4U6ytipEP+EK5y9Puoy/Jnq54SoY7kwP7SH9iu2mBhB3x3ySBNcMQ== X-Received: by 2002:a92:b10:: with SMTP id b16mr304742ilf.182.1631051623382; Tue, 07 Sep 2021 14:53:43 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 06/42] bsd-user: Remove all non-x86 code from elfload.c Date: Tue, 7 Sep 2021 15:52:56 -0600 Message-Id: <20210907215332.30737-7-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::132; envelope-from=imp@bsdimp.com; helo=mail-il1-x132.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052107764100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh bsd-user only builds x86 at the moment. Remove all non x86 code from elfload.c. We'll move the x86 code to {i386,x86_64}/target_arch_elf.h and bring it that support code from the forked bsd-user when the time comes. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 347 +-------------------------------------------- 1 file changed, 2 insertions(+), 345 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index ae62f3aab3..fffa24f041 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -23,15 +23,6 @@ #include "disas/disas.h" #include "qemu/path.h" =20 -#ifdef _ARCH_PPC64 -#undef ARCH_DLINFO -#undef ELF_PLATFORM -#undef ELF_HWCAP -#undef ELF_CLASS -#undef ELF_DATA -#undef ELF_ARCH -#endif - /* from personality.h */ =20 /* @@ -144,7 +135,7 @@ static inline void init_thread(struct target_pt_regs *r= egs, struct image_info *i } } =20 -#else +#else /* !TARGET_X86_64 */ =20 #define ELF_START_MMAP 0x80000000 =20 @@ -174,343 +165,13 @@ static inline void init_thread(struct target_pt_regs= *regs, struct image_info *i A value of 0 tells we have no such handler. */ regs->edx =3D 0; } -#endif - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -#endif - -#ifdef TARGET_ARM - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch(x) ((x) =3D=3D EM_ARM) - -#define ELF_CLASS ELFCLASS32 -#ifdef TARGET_WORDS_BIGENDIAN -#define ELF_DATA ELFDATA2MSB -#else -#define ELF_DATA ELFDATA2LSB -#endif -#define ELF_ARCH EM_ARM - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - abi_long stack =3D infop->start_stack; - memset(regs, 0, sizeof(*regs)); - regs->ARM_cpsr =3D 0x10; - if (infop->entry & 1) - regs->ARM_cpsr |=3D CPSR_T; - regs->ARM_pc =3D infop->entry & 0xfffffffe; - regs->ARM_sp =3D infop->start_stack; - /* FIXME - what to for failure of get_user()? */ - get_user_ual(regs->ARM_r2, stack + 8); /* envp */ - get_user_ual(regs->ARM_r1, stack + 4); /* envp */ - /* XXX: it seems that r0 is zeroed after ! */ - regs->ARM_r0 =3D 0; - /* For uClinux PIC binaries. */ - /* XXX: Linux does this only on ARM with no MMU (do we care ?) */ - regs->ARM_r10 =3D infop->start_data; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -enum -{ - ARM_HWCAP_ARM_SWP =3D 1 << 0, - ARM_HWCAP_ARM_HALF =3D 1 << 1, - ARM_HWCAP_ARM_THUMB =3D 1 << 2, - ARM_HWCAP_ARM_26BIT =3D 1 << 3, - ARM_HWCAP_ARM_FAST_MULT =3D 1 << 4, - ARM_HWCAP_ARM_FPA =3D 1 << 5, - ARM_HWCAP_ARM_VFP =3D 1 << 6, - ARM_HWCAP_ARM_EDSP =3D 1 << 7, -}; - -#define ELF_HWCAP (ARM_HWCAP_ARM_SWP | ARM_HWCAP_ARM_HALF \ - | ARM_HWCAP_ARM_THUMB | ARM_HWCAP_ARM_FAST_MULT \ - | ARM_HWCAP_ARM_FPA | ARM_HWCAP_ARM_VFP) - -#endif - -#ifdef TARGET_SPARC -#ifdef TARGET_SPARC64 - -#define ELF_START_MMAP 0x80000000 - -#ifndef TARGET_ABI32 -#define elf_check_arch(x) ((x) =3D=3D EM_SPARCV9 || (x) =3D=3D EM_SPARC32P= LUS) -#else -#define elf_check_arch(x) ((x) =3D=3D EM_SPARC32PLUS || (x) =3D=3D EM_SPAR= C) -#endif - -#define ELF_CLASS ELFCLASS64 -#define ELF_DATA ELFDATA2MSB -#define ELF_ARCH EM_SPARCV9 - -#define STACK_BIAS 2047 - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ -#ifndef TARGET_ABI32 - regs->tstate =3D 0; -#endif - regs->pc =3D infop->entry; - regs->npc =3D regs->pc + 4; - regs->y =3D 0; -#ifdef TARGET_ABI32 - regs->u_regs[14] =3D infop->start_stack - 16 * 4; -#else - if (personality(infop->personality) =3D=3D PER_LINUX32) - regs->u_regs[14] =3D infop->start_stack - 16 * 4; - else { - regs->u_regs[14] =3D infop->start_stack - 16 * 8 - STACK_BIAS; - if (bsd_type =3D=3D target_freebsd) { - regs->u_regs[8] =3D infop->start_stack; - regs->u_regs[11] =3D infop->start_stack; - } - } -#endif -} - -#else -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch(x) ((x) =3D=3D EM_SPARC) - -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2MSB -#define ELF_ARCH EM_SPARC - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - regs->psr =3D 0; - regs->pc =3D infop->entry; - regs->npc =3D regs->pc + 4; - regs->y =3D 0; - regs->u_regs[14] =3D infop->start_stack - 16 * 4; -} - -#endif -#endif - -#ifdef TARGET_PPC - -#define ELF_START_MMAP 0x80000000 - -#if defined(TARGET_PPC64) && !defined(TARGET_ABI32) - -#define elf_check_arch(x) ((x) =3D=3D EM_PPC64) - -#define ELF_CLASS ELFCLASS64 - -#else - -#define elf_check_arch(x) ((x) =3D=3D EM_PPC) - -#define ELF_CLASS ELFCLASS32 - -#endif - -#ifdef TARGET_WORDS_BIGENDIAN -#define ELF_DATA ELFDATA2MSB -#else -#define ELF_DATA ELFDATA2LSB -#endif -#define ELF_ARCH EM_PPC - -/* - * We need to put in some extra aux table entries to tell glibc what - * the cache block size is, so it can use the dcbz instruction safely. - */ -#define AT_DCACHEBSIZE 19 -#define AT_ICACHEBSIZE 20 -#define AT_UCACHEBSIZE 21 -/* A special ignored type value for PPC, for glibc compatibility. */ -#define AT_IGNOREPPC 22 -/* - * The requirements here are: - * - keep the final alignment of sp (sp & 0xf) - * - make sure the 32-bit value at the first 16 byte aligned position of - * AUXV is greater than 16 for glibc compatibility. - * AT_IGNOREPPC is used for that. - * - for compatibility with glibc ARCH_DLINFO must always be defined on PP= C, - * even if DLINFO_ARCH_ITEMS goes to zero or is undefined. - */ -#define DLINFO_ARCH_ITEMS 5 -#define ARCH_DLINFO \ -do { \ - NEW_AUX_ENT(AT_DCACHEBSIZE, 0x20); \ - NEW_AUX_ENT(AT_ICACHEBSIZE, 0x20); \ - NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \ - /* \ - * Now handle glibc compatibility. \ - */ \ - NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \ - NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \ - } while (0) - -static inline void init_thread(struct target_pt_regs *_regs, struct image_= info *infop) -{ - abi_ulong pos =3D infop->start_stack; - abi_ulong tmp; -#if defined(TARGET_PPC64) && !defined(TARGET_ABI32) - abi_ulong entry, toc; -#endif - - _regs->gpr[1] =3D infop->start_stack; -#if defined(TARGET_PPC64) && !defined(TARGET_ABI32) - get_user_u64(entry, infop->entry); - entry +=3D infop->load_addr; - get_user_u64(toc, infop->entry + 8); - toc +=3D infop->load_addr; - _regs->gpr[2] =3D toc; - infop->entry =3D entry; -#endif - _regs->nip =3D infop->entry; - /* Note that isn't exactly what regular kernel does - * but this is what the ABI wants and is needed to allow - * execution of PPC BSD programs. - */ - /* FIXME - what to for failure of get_user()? */ - get_user_ual(_regs->gpr[3], pos); - pos +=3D sizeof(abi_ulong); - _regs->gpr[4] =3D pos; - for (tmp =3D 1; tmp !=3D 0; pos +=3D sizeof(abi_ulong)) { - get_user_ual(tmp, pos); - } - _regs->gpr[5] =3D pos; -} +#endif /* !TARGET_X86_64 */ =20 #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 =20 #endif =20 -#ifdef TARGET_MIPS - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch(x) ((x) =3D=3D EM_MIPS) - -#ifdef TARGET_MIPS64 -#define ELF_CLASS ELFCLASS64 -#else -#define ELF_CLASS ELFCLASS32 -#endif -#ifdef TARGET_WORDS_BIGENDIAN -#define ELF_DATA ELFDATA2MSB -#else -#define ELF_DATA ELFDATA2LSB -#endif -#define ELF_ARCH EM_MIPS - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - regs->cp0_status =3D 2 << CP0St_KSU; - regs->cp0_epc =3D infop->entry; - regs->regs[29] =3D infop->start_stack; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -#endif /* TARGET_MIPS */ - -#ifdef TARGET_SH4 - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch(x) ((x) =3D=3D EM_SH) - -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_SH - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - /* Check other registers XXXXX */ - regs->pc =3D infop->entry; - regs->regs[15] =3D infop->start_stack; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -#endif - -#ifdef TARGET_CRIS - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch(x) ((x) =3D=3D EM_CRIS) - -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_CRIS - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - regs->erp =3D infop->entry; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 8192 - -#endif - -#ifdef TARGET_M68K - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch(x) ((x) =3D=3D EM_68K) - -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2MSB -#define ELF_ARCH EM_68K - -/* ??? Does this need to do anything? -#define ELF_PLAT_INIT(_r) */ - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - regs->usp =3D infop->start_stack; - regs->sr =3D 0; - regs->pc =3D infop->entry; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 8192 - -#endif - -#ifdef TARGET_ALPHA - -#define ELF_START_MMAP (0x30000000000ULL) - -#define elf_check_arch(x) ((x) =3D=3D ELF_ARCH) - -#define ELF_CLASS ELFCLASS64 -#define ELF_DATA ELFDATA2MSB -#define ELF_ARCH EM_ALPHA - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - regs->pc =3D infop->entry; - regs->ps =3D 8; - regs->usp =3D infop->start_stack; - regs->unique =3D infop->start_data; /* ? */ - printf("Set unique value to " TARGET_FMT_lx " (" TARGET_FMT_lx ")\n", - regs->unique, infop->start_data); -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 8192 - -#endif /* TARGET_ALPHA */ - #ifndef ELF_PLATFORM #define ELF_PLATFORM (NULL) #endif @@ -1119,10 +780,6 @@ static void load_symbols(struct elfhdr *hdr, int fd) } continue; } -#if defined(TARGET_ARM) || defined(TARGET_MIPS) - /* The bottom address bit marks a Thumb or MIPS16 symbol. */ - syms[i].st_value &=3D ~(target_ulong)1; -#endif i++; } =20 --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052091901611.2617450021097; Tue, 7 Sep 2021 15:01:31 -0700 (PDT) Received: from localhost ([::1]:47300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj9m-00031E-78 for importer@patchew.org; Tue, 07 Sep 2021 18:01:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2J-0005cp-SL for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:47 -0400 Received: from mail-il1-x143.google.com ([2607:f8b0:4864:20::143]:38670) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2H-0000k5-Mc for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:47 -0400 Received: by mail-il1-x143.google.com with SMTP id u11so167506ilj.5 for ; Tue, 07 Sep 2021 14:53:45 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ylt7WV1TVCXXr9QQoMDNZUNuolzJegHkE/e8RkVXe1g=; b=Yz02ycoVDjFnOArdnanUUU71pU80obyRW2yBfE6i5ZB4pzK8X53Rfw9+jH4ctAhOGL NuQrnpy/juAE6W5429+LVUw98Coa4Sow078wAvdOEnjUbE28KKUJyuRPPi3lKvxngbEa OM8U+lL9Cv2j0BhjJ/m/43j26NlJssh0LXssqoTeoOOrz9e6J1IRpboRmJDU9moEdnbl 5KXbCahsbhinTyRlVxVSlEVq3nLn76fF8zLfJ5tFqaeVw5vdnv7Jq9RfAXLaaKgQDMQo lRoZTpB6iTNB9MpKLIl21pATr1PJ+wD2vILDhEOjKVA72rylma7YE4oHbKY+s7EDBArr doxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ylt7WV1TVCXXr9QQoMDNZUNuolzJegHkE/e8RkVXe1g=; b=Nolya50f5WoOBBM63ihmcD5WIp+DSzMetavNId4Gda7noxnT+1Lu//pDce7pZ5hQCO dFvGli/e4TYFiVT3GjnUWJe7hyelEQICj78JWhJ/7VaSkdonOChNofTjgC0nXI25PUzj EOU8DidOqBG66kLMAvicFnG3uuuE8wRCHdLYVf9wxfKaD6JFNRBRhE1lH+IWAt4vemIW xHw6ne0G/Bppp+dGk+6nnHu1FIlUMoJjViLCnbD9cv3AyHNtza+W+TKJfBWnSjGNgvEH k4PrzShWp/IWKrhGFaVj5tqW/3CRPRYeKIbiwN1BP4Rz9vMDGCnHTuPZMRx42lxlTz0A iIGg== X-Gm-Message-State: AOAM531bSdTEc2T3+iQ/O797ebNlrFznJw0fviE5FxnJRAWYr18V4XiR 9zkAYf+vsMALqK6MiBVzxQovfRWqZfv1D30VXec= X-Google-Smtp-Source: ABdhPJxMRpSNswlxFB1Qy7Tq2RrBI9PssqueKzg24mQDmCi4BqcBWDaRGtlmBPaXh7jaaEcdXGqjkg== X-Received: by 2002:a92:ad12:: with SMTP id w18mr8421ilh.181.1631051624327; Tue, 07 Sep 2021 14:53:44 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 07/42] bsd-user: move arch specific defines out of elfload.c Date: Tue, 7 Sep 2021 15:52:57 -0600 Message-Id: <20210907215332.30737-8-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::143; envelope-from=imp@bsdimp.com; helo=mail-il1-x143.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052092773100002 Content-Type: text/plain; charset="utf-8" From: Warner Losh Move the architecture specific defines to target_arch_elf.h and delete them from elfload.c. Only retain ifdefs appropriate for i386 and x86_64. Add the copyright/license comments, and guard ifdefs. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 81 +------------------------------ bsd-user/i386/target_arch_elf.h | 81 +++++++++++++++++++++++++++++++ bsd-user/x86_64/target_arch_elf.h | 67 +++++++++++++++++++++++++ slirp | 2 +- 4 files changed, 151 insertions(+), 80 deletions(-) create mode 100644 bsd-user/i386/target_arch_elf.h create mode 100644 bsd-user/x86_64/target_arch_elf.h diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index fffa24f041..639673f5b7 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -23,6 +23,8 @@ #include "disas/disas.h" #include "qemu/path.h" =20 +#include "target_arch_elf.h" + /* from personality.h */ =20 /* @@ -93,85 +95,6 @@ enum { #define ELIBBAD 80 #endif =20 -#ifdef TARGET_I386 - -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform(void) -{ - static char elf_platform[] =3D "i386"; - int family =3D object_property_get_int(OBJECT(thread_cpu), "family", N= ULL); - if (family > 6) - family =3D 6; - if (family >=3D 3) - elf_platform[1] =3D '0' + family; - return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap(void) -{ - X86CPU *cpu =3D X86_CPU(thread_cpu); - - return cpu->env.features[FEAT_1_EDX]; -} - -#ifdef TARGET_X86_64 -#define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch(x) (((x) =3D=3D ELF_ARCH)) - -#define ELF_CLASS ELFCLASS64 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_X86_64 - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - regs->rax =3D 0; - regs->rsp =3D infop->start_stack; - regs->rip =3D infop->entry; - if (bsd_type =3D=3D target_freebsd) { - regs->rdi =3D infop->start_stack; - } -} - -#else /* !TARGET_X86_64 */ - -#define ELF_START_MMAP 0x80000000 - -/* - * This is used to ensure we don't load something for the wrong architectu= re. - */ -#define elf_check_arch(x) (((x) =3D=3D EM_386) || ((x) =3D=3D EM_486)) - -/* - * These are used to set parameters in the core dumps. - */ -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_386 - -static inline void init_thread(struct target_pt_regs *regs, struct image_i= nfo *infop) -{ - regs->esp =3D infop->start_stack; - regs->eip =3D infop->entry; - - /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program - starts %edx contains a pointer to a function which might be - registered using `atexit'. This provides a mean for the - dynamic linker to call DT_FINI functions for shared libraries - that have been loaded before the code runs. - - A value of 0 tells we have no such handler. */ - regs->edx =3D 0; -} -#endif /* !TARGET_X86_64 */ - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -#endif - #ifndef ELF_PLATFORM #define ELF_PLATFORM (NULL) #endif diff --git a/bsd-user/i386/target_arch_elf.h b/bsd-user/i386/target_arch_el= f.h new file mode 100644 index 0000000000..84f61bd930 --- /dev/null +++ b/bsd-user/i386/target_arch_elf.h @@ -0,0 +1,81 @@ +/* + * i386 ELF definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_ARCH_ELF_H_ +#define _TARGET_ARCH_ELF_H_ + +#define ELF_PLATFORM get_elf_platform() + +static const char *get_elf_platform(void) +{ + static char elf_platform[] =3D "i386"; + int family =3D object_property_get_int(OBJECT(thread_cpu), "family", N= ULL); + if (family > 6) { + family =3D 6; + } + if (family >=3D 3) { + elf_platform[1] =3D '0' + family; + } + return elf_platform; +} + +#define ELF_HWCAP get_elf_hwcap() + +static uint32_t get_elf_hwcap(void) +{ + X86CPU *cpu =3D X86_CPU(thread_cpu); + + return cpu->env.features[FEAT_1_EDX]; +} + +#define ELF_START_MMAP 0x80000000 + +/* + * This is used to ensure we don't load something for the wrong architectu= re. + */ +#define elf_check_arch(x) (((x) =3D=3D EM_386) || ((x) =3D=3D EM_486)) + +/* + * These are used to set parameters in the core dumps. + */ +#define ELF_CLASS ELFCLASS32 +#define ELF_DATA ELFDATA2LSB +#define ELF_ARCH EM_386 + +static inline void init_thread(struct target_pt_regs *regs, + struct image_info *infop) +{ + regs->esp =3D infop->start_stack; + regs->eip =3D infop->entry; + + /* + * SVR4/i386 ABI (pages 3-31, 3-32) says that when the program + * starts %edx contains a pointer to a function which might be + * registered using `atexit'. This provides a mean for the + * dynamic linker to call DT_FINI functions for shared libraries + * that have been loaded before the code runs. + * + * A value of 0 tells we have no such handler. + */ + regs->edx =3D 0; +} + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 + +#endif /* _TARGET_ARCH_ELF_H_ */ diff --git a/bsd-user/x86_64/target_arch_elf.h b/bsd-user/x86_64/target_arc= h_elf.h new file mode 100644 index 0000000000..e7c8aa2755 --- /dev/null +++ b/bsd-user/x86_64/target_arch_elf.h @@ -0,0 +1,67 @@ +/* + * x86_64 ELF definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_ARCH_ELF_H_ +#define _TARGET_ARCH_ELF_H_ + +#define ELF_PLATFORM get_elf_platform() + +static const char *get_elf_platform(void) +{ + static char elf_platform[] =3D "i386"; + int family =3D object_property_get_int(OBJECT(thread_cpu), "family", N= ULL); + if (family > 6) { + family =3D 6; + } + if (family >=3D 3) { + elf_platform[1] =3D '0' + family; + } + return elf_platform; +} + +#define ELF_HWCAP get_elf_hwcap() + +static uint32_t get_elf_hwcap(void) +{ + X86CPU *cpu =3D X86_CPU(thread_cpu); + + return cpu->env.features[FEAT_1_EDX]; +} + +#define ELF_START_MMAP 0x2aaaaab000ULL +#define elf_check_arch(x) (((x) =3D=3D ELF_ARCH)) + +#define ELF_CLASS ELFCLASS64 +#define ELF_DATA ELFDATA2LSB +#define ELF_ARCH EM_X86_64 + +static inline void init_thread(struct target_pt_regs *regs, + struct image_info *infop) +{ + regs->rax =3D 0; + regs->rsp =3D infop->start_stack; + regs->rip =3D infop->entry; + if (bsd_type =3D=3D target_freebsd) { + regs->rdi =3D infop->start_stack; + } +} + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 + +#endif /* _TARGET_ARCH_ELF_H_ */ diff --git a/slirp b/slirp index a88d9ace23..8f43a99191 160000 --- a/slirp +++ b/slirp @@ -1 +1 @@ -Subproject commit a88d9ace234a24ce1c17189642ef9104799425e0 +Subproject commit 8f43a99191afb47ca3f3c6972f6306209f367ece --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052091659861.2603144756283; Tue, 7 Sep 2021 15:01:31 -0700 (PDT) Received: from localhost ([::1]:47138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj9m-0002uK-99 for importer@patchew.org; Tue, 07 Sep 2021 18:01:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2K-0005gF-Od for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:48 -0400 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]:41937) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2J-0000kp-1A for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:48 -0400 Received: by mail-il1-x132.google.com with SMTP id l10so156903ilh.8 for ; Tue, 07 Sep 2021 14:53:46 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=13uIwIKejgalnxws+XzFC57N6RAgVKudYeg7SEKXCvk=; b=ITrZlAbT4rxIO4orNcwAhKKqYSqBZU77nRjBf61WNM28NcetVBBxdH/3rl+g26sOEI 0+aYGaF7XY+3JlUhLqssm71eWLvEhycBpMv4rBMfdUdeynYM9/k6mXvXBTDbJoFDMveh LrHhg4oDqFzrkjpWBVjf9rzHp0BZ0/y7u2SOM+13an27e4sKF7t0A/ZlDEGFC2r1b86N 3WgO4XvmqNl+Grn3TMDEkToG5onnkIHdL4UzoR+4tf+U+N0pCQ9RPCtN66l+EwItvU7L mMNEm9xVtyN0ZhzU7fdh0JiD3mG8l8QLNuDN+YHxrJ8ZqzQ8Okh9gcShpE5yFBdbEZyB ws4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=13uIwIKejgalnxws+XzFC57N6RAgVKudYeg7SEKXCvk=; b=VUMOEsM4fKa1DFaMl/RyF9WOVzJQaVFtkRLtHvqwMUAr74sNvoTzLiEjLzXOqqZ0hQ NgEkiT/1dIFPOKfCvUyEkL642JiNqcXal2UJ2VP89UpPdgzYXAa+o6rG/R4P6QeT6dvr 9nd27WpRbvARR8/MlkwyekItU4cKHwlx6KrtqqxsUXRvVXqKTbTCPNPlYeuOvhnSIrXf PInfKWSnzftBA3scS5WodZXOQ/q1BZLTtbudLv+CPzpOPaWcJVcbxT3nCqP5lfWmRAHp SBKcNqsSc3RR/lu72309weSjo6PA8f4omLGPyF/B1rbeJurU37eawmOyyxCDD3amhc7E HUlg== X-Gm-Message-State: AOAM533V06bLFHLKYpuD2T6Tkl39zcRJtKXDVAAO1dbxeQqgFwOr4YSx fK6pDIev02Ke7Unq3qAGmqFgluJ3kQf+psIBa+U= X-Google-Smtp-Source: ABdhPJzM73cfAszFkcwvk5u8sX8l5nc1GyWDb6ifqYivY20UH7yej9xqnBKUbSm4ozmj56y4V4+QIA== X-Received: by 2002:a05:6e02:19ce:: with SMTP id r14mr313118ill.58.1631051625687; Tue, 07 Sep 2021 14:53:45 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 08/42] bsd-user: pass the bsd_param into loader_exec Date: Tue, 7 Sep 2021 15:52:58 -0600 Message-Id: <20210907215332.30737-9-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::132; envelope-from=imp@bsdimp.com; helo=mail-il1-x132.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052092744100001 From: Warner Losh Pass the bsd_param into loader_exec, and adjust. We use it to track the inital stack allocation and to set stack, open files, and other state shared between bsdload.c and elfload.c Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- bsd-user/bsdload.c | 37 +++++++++++++++++++------------------ bsd-user/main.c | 7 ++++++- bsd-user/qemu.h | 3 ++- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index ec71c5e923..5282a7c4f2 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -140,35 +140,36 @@ abi_ulong loader_build_argptr(int envc, int argc, abi= _ulong sp, } =20 int loader_exec(const char *filename, char **argv, char **envp, - struct target_pt_regs *regs, struct image_info *infop) + struct target_pt_regs *regs, struct image_info *infop, + struct bsd_binprm *bprm) { - struct bsd_binprm bprm; int retval; int i; =20 - bprm.p =3D TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int); - for (i =3D 0 ; i < MAX_ARG_PAGES ; i++) { /* clear page-table */ - bprm.page[i] =3D NULL; + bprm->p =3D TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int); + for (i =3D 0; i < MAX_ARG_PAGES; i++) { /* clear page-table */ + bprm->page[i] =3D NULL; } retval =3D open(filename, O_RDONLY); if (retval < 0) { return retval; } - bprm.fd =3D retval; - bprm.filename =3D (char *)filename; - bprm.argc =3D count(argv); - bprm.argv =3D argv; - bprm.envc =3D count(envp); - bprm.envp =3D envp; =20 - retval =3D prepare_binprm(&bprm); + bprm->fd =3D retval; + bprm->filename =3D (char *)filename; + bprm->argc =3D count(argv); + bprm->argv =3D argv; + bprm->envc =3D count(envp); + bprm->envp =3D envp; + + retval =3D prepare_binprm(bprm); =20 if (retval >=3D 0) { - if (bprm.buf[0] =3D=3D 0x7f - && bprm.buf[1] =3D=3D 'E' - && bprm.buf[2] =3D=3D 'L' - && bprm.buf[3] =3D=3D 'F') { - retval =3D load_elf_binary(&bprm, regs, infop); + if (bprm->buf[0] =3D=3D 0x7f + && bprm->buf[1] =3D=3D 'E' + && bprm->buf[2] =3D=3D 'L' + && bprm->buf[3] =3D=3D 'F') { + retval =3D load_elf_binary(bprm, regs, infop); } else { fprintf(stderr, "Unknown binary format\n"); return -1; @@ -183,7 +184,7 @@ int loader_exec(const char *filename, char **argv, char= **envp, =20 /* Something went wrong, return the inode and free the argument pages*/ for (i =3D 0 ; i < MAX_ARG_PAGES ; i++) { - g_free(bprm.page[i]); + g_free(bprm->page[i]); } return retval; } diff --git a/bsd-user/main.c b/bsd-user/main.c index 39c4a0f33c..1388c7a13d 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -343,6 +343,7 @@ int main(int argc, char **argv) const char *log_mask =3D NULL; struct target_pt_regs regs1, *regs =3D ®s1; struct image_info info1, *info =3D &info1; + struct bsd_binprm bprm; TaskState ts1, *ts =3D &ts1; CPUArchState *env; CPUState *cpu; @@ -499,6 +500,9 @@ int main(int argc, char **argv) /* Zero out regs */ memset(regs, 0, sizeof(struct target_pt_regs)); =20 + /* Zero bsd params */ + memset(&bprm, 0, sizeof(bprm)); + /* Zero out image_info */ memset(info, 0, sizeof(struct image_info)); =20 @@ -566,7 +570,8 @@ int main(int argc, char **argv) } } =20 - if (loader_exec(filename, argv + optind, target_environ, regs, info) != =3D 0) { + if (loader_exec(filename, argv + optind, target_environ, regs, info, + &bprm) !=3D 0) { printf("Error loading %s\n", filename); _exit(1); } diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index c02e8a5ca1..5237e35f9c 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -131,7 +131,8 @@ void do_init_thread(struct target_pt_regs *regs, struct= image_info *infop); abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, abi_ulong stringp, int push_ptr); int loader_exec(const char *filename, char **argv, char **envp, - struct target_pt_regs *regs, struct image_info *infop); + struct target_pt_regs *regs, struct image_info *infop, + struct bsd_binprm *bprm); =20 int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, struct image_info *info); --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631051775433368.80860958043047; Tue, 7 Sep 2021 14:56:15 -0700 (PDT) Received: from localhost ([::1]:59668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj4g-0000bB-Gu for importer@patchew.org; Tue, 07 Sep 2021 17:56:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2L-0005iT-8u for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:49 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]:43617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2J-0000lr-NZ for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:49 -0400 Received: by mail-il1-x12c.google.com with SMTP id v16so150492ilo.10 for ; Tue, 07 Sep 2021 14:53:47 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GiaQIIYvzMX3kBsTWafB+XsF4D6nhHn7w46Aapsrz8s=; b=cBEe+ihCDlFBfUGAmrSyLq40+gG5F2opVrXyU8kqo0AxxTTpzRhEDBRzu0RZOrpyTJ Kcx8ZeG07Ey6aaN9/yNTBK6nffQwaXuEjkAm2bgLpUvZiY5j+9wvBs3iN8lBvzF/nSPb gnFhu9MyVspPtKMim4BiQTYsTB63EtyjA+2Q0PFXqU2fYuxvrTWWtaSMgqfMfHQOksgn JFU1p37wIyjGH8PLdVhU0O/67NIr0VSquNnCHlIdRmpa0+ZCo23zkCav9/TQh9XWF/Bo 9Ccdluea2whzdEm4p2So+r/i2VkA3PZ26xyqeOwOuvdKyNOlXCKo9HU5PR6cuoooP312 K7Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GiaQIIYvzMX3kBsTWafB+XsF4D6nhHn7w46Aapsrz8s=; b=gIZcU80JjL+94nFc6+3yo7Vhqblz7z3C4HbAeHtz3vzZJIUajnVGkeP2erlevtgETO J81xsF/zimp1xFrK1dkOFq0djUB0b7YQ4ilYVDc3pErukYKsibhzayRpf3lrragh/34R GnEUy+VqcIEHDmCxm4fQHTEq7Vg7xyxvXc5sbEuuOp0EgtM9mZh7wITXjG2KdrVCezBa AcL3s7XjO3y2fO+19opSIcyZ5Ao62ZjjMCRoTEWPL09G0FsL1+9kyKBgjdjJ8WY7z2yu yy/MOpxAWb7+9lZCuMwT8CE0Ac3TMgjlSOUNIkAnHnXOgB0huDqCbCc5ssSqA28Uw1a5 RU5w== X-Gm-Message-State: AOAM530CZUa24S/DaH7MfEHCk7cDjMTSo7zZ6JGrNY3zYdqYFLMnZeEU SEzc1YJWeiJWKhNRs+a2+Arp9ksPRNDvyESMors= X-Google-Smtp-Source: ABdhPJynLcqyGFc3ugFjcwsnM1ZQkxTDEzZwy8MmySqYO4T3rzAWvTyMVX9uriL7nda+PEEAsvRHjw== X-Received: by 2002:a05:6e02:12c2:: with SMTP id i2mr287565ilm.261.1631051626474; Tue, 07 Sep 2021 14:53:46 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 09/42] bsd-user: Fix calculation of size to allocate Date: Tue, 7 Sep 2021 15:52:59 -0600 Message-Id: <20210907215332.30737-10-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631051776420100005 Content-Type: text/plain; charset="utf-8" From: Warner Losh It was incorrect to subtract off the size of an unsigned int here. In bsd-user fork, this change was made when moving the arch specific items to specific files. The size in BSD that's available for the arguments does not need a return address subtracted from it. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsdload.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 5282a7c4f2..379015c744 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -143,10 +143,9 @@ int loader_exec(const char *filename, char **argv, cha= r **envp, struct target_pt_regs *regs, struct image_info *infop, struct bsd_binprm *bprm) { - int retval; - int i; + int retval, i; =20 - bprm->p =3D TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int); + bprm->p =3D TARGET_PAGE_SIZE * MAX_ARG_PAGES; for (i =3D 0; i < MAX_ARG_PAGES; i++) { /* clear page-table */ bprm->page[i] =3D NULL; } --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163105223259192.04157326419056; Tue, 7 Sep 2021 15:03:52 -0700 (PDT) Received: from localhost ([::1]:55464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjC3-0000Fy-IP for importer@patchew.org; Tue, 07 Sep 2021 18:03:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2N-0005kq-Cc for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:52 -0400 Received: from mail-il1-x141.google.com ([2607:f8b0:4864:20::141]:36616) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2K-0000mZ-OB for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:51 -0400 Received: by mail-il1-x141.google.com with SMTP id x5so175461ill.3 for ; Tue, 07 Sep 2021 14:53:48 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=USbY3TMkmsnljwVWGizCiItJwGHI+n9Fqx3miK9oRCk=; b=UqhkH97EtjLrNJk6xDVKW2qHuF5t1KjbwHmkwW8Nm++lmfF6QfNSbsJ9xH2JNxiO2s /czMHZAv27Y7GGCkvFu5vB/Hh3nOWnnpyNFJdQSNnKKLCzbSUKOWBIEYeoHw2g+MwnNm 3vjy9Aj5prG7av0KAjex3Fy0vxIiOx7PMYZlC7nDywAnOe+DZ6PyrzmosfY8wm5tBdRV imnhge8474MA3ciPLaZSgegzRrFzImARukLtX3ox7aSpZrqOayiwEwQhYF46ehsndOeG onSfMLKgeEORUdt5ldo4chHZHUXo6GEts1sS5/0Pmtc4uQTgO8BFiwHfbtVCLcvwmKmv Vekg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=USbY3TMkmsnljwVWGizCiItJwGHI+n9Fqx3miK9oRCk=; b=G50ZwS9GabDn55mxC1TuGKWeil9X+5Vi8ZaLiMFzsC9p0ZxzD0VslWmwrON8qIPH35 yC/kAJhXVE8TwCY44LGx6sIk6eUND/HYAZ0Vz2VIRY5z5eXQMsnjrUmRRErXooCA6oyV wRsZiH1IPNFuZH40l6qg961uyX5/cudM0ppBABsKHBjmvlm19MHmy3BC8nWdDd5dmNNC HIx5EsCK/EV9xlKdGB3SjzMt91kC/IiLuhaGkETcqRVsnX6JoFG6XynyDksPCnE21Ro+ yLpG3y8bQPWHPrr4bScuSSdn4CIVqBNcSoW5Zp0yjW3K5/ChR6rjVSHyRtSkQaw7tNKz tTzA== X-Gm-Message-State: AOAM533CesWZpcMl9bCf0F29zp5d65LSuEVd6iw+T8xPD6Q9iyp4Zj+T 8i296VVE7pbYvMmgALxzdXIH3VHLQNsegxRKtRA= X-Google-Smtp-Source: ABdhPJwCHxPjqbPTWlYI+f320lQLn653+OpjNZAFRse2UOzKs+ES4ERUfMnm8xQeWC0PG5FSnrM0qw== X-Received: by 2002:a05:6e02:1e05:: with SMTP id g5mr316030ila.48.1631051627360; Tue, 07 Sep 2021 14:53:47 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 10/42] bsd-user: implement path searching Date: Tue, 7 Sep 2021 15:53:00 -0600 Message-Id: <20210907215332.30737-11-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::141; envelope-from=imp@bsdimp.com; helo=mail-il1-x141.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Stacey Son , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052233256100003 Content-Type: text/plain; charset="utf-8" From: Warner Losh Use the PATH to find the executable given a bare argument. We need to do this so we can implement mixing native and emulated binaries (e.g., execing a x86 native binary from an emulated arm binary to optimize parts of the build). By finding the binary, we will know how to exec it. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsdload.c | 36 +++++++++++++++++++++++++++++++++++- bsd-user/qemu.h | 3 ++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 379015c744..32f7fd5dec 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -139,21 +139,55 @@ abi_ulong loader_build_argptr(int envc, int argc, abi= _ulong sp, return sp; } =20 +static bool is_there(const char *candidate) +{ + struct stat fin; + + /* XXX work around access(2) false positives for superuser */ + if (access(candidate, X_OK) =3D=3D 0 && stat(candidate, &fin) =3D=3D 0= && + S_ISREG(fin.st_mode) && (getuid() !=3D 0 || + (fin.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) !=3D 0)) { + return true; + } + + return false; +} + int loader_exec(const char *filename, char **argv, char **envp, struct target_pt_regs *regs, struct image_info *infop, struct bsd_binprm *bprm) { + char *path, fullpath[PATH_MAX]; int retval, i; =20 bprm->p =3D TARGET_PAGE_SIZE * MAX_ARG_PAGES; for (i =3D 0; i < MAX_ARG_PAGES; i++) { /* clear page-table */ bprm->page[i] =3D NULL; } - retval =3D open(filename, O_RDONLY); + + if (strchr(filename, '/') !=3D NULL) { + path =3D realpath(filename, fullpath); + if (path =3D=3D NULL) { + /* Failed to resolve. */ + return -1; + } + if (!is_there(path)) { + return -1; + } + } else { + path =3D g_find_program_in_path(filename); + if (path =3D=3D NULL) { + return -1; + } + } + + retval =3D open(path, O_RDONLY); if (retval < 0) { + g_free(path); return retval; } =20 + bprm->fullpath =3D path; bprm->fd =3D retval; bprm->filename =3D (char *)filename; bprm->argc =3D count(argv); diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 5237e35f9c..6b601ce4b5 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -124,7 +124,8 @@ struct bsd_binprm { int argc, envc; char **argv; char **envp; - char *filename; /* Name of binary */ + char *filename; /* (Given) Name of binary */ + char *fullpath; /* Full path of binary */ }; =20 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052466687608.5204270126907; Tue, 7 Sep 2021 15:07:46 -0700 (PDT) Received: from localhost ([::1]:36586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjFp-00072G-Mi for importer@patchew.org; Tue, 07 Sep 2021 18:07:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35020) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2N-0005ks-P6 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:52 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]:40894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2M-0000nY-1Z for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:51 -0400 Received: by mail-io1-xd29.google.com with SMTP id z1so455468ioh.7 for ; Tue, 07 Sep 2021 14:53:49 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JbEdUvbo/mrg2leYF7EcbjbkdggBVAu4KQwCBbiNYLY=; b=yLNCkiZOVRZ3LXk+YeS3DY9IFvdSe2mxLTANEQMKGgj8xXdmOYPiCmWyoJjdDp0LVS SRjHjA/eC3kHIYonAr353GomjlsLpsNzrLiDPuML4z5rGiMdmH7FPpzPCFRuQNDFi1uv wn/8Ft44n5/s5w6HxzHMVCK62HCNu79geTaAYzkjUc5vh2kDEwp95uLYnVcLvZL5hBVv ikc6qhZn6AVzO+oN6eHjy6W7UdJClCQiFddRD/0bxoAidwHv8zfFEUjx/7b48ovybCSk ysa5jag3LB7n8UeKPwIvyxtiD152Ke3kB5r2YZ1EPtOdjOijHkLcTvli5yWzRPBV6NQB ZPpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JbEdUvbo/mrg2leYF7EcbjbkdggBVAu4KQwCBbiNYLY=; b=cVTiQ39AXbueV3jPj/rIDW1Nco8LM9bG0L4DH8FBM62y5GHpmh2azOQJEOFt53Ko8x 2WwIOqMdHPTUnL1PQIvylkXjOEGX9eWKhXxMk3zfE8642P5E/fzR/5xqIxSlsu4SenTL TtqL0Df/857nj5M/i6f3tXo2ZZJadp8nAQY1Lo+bPFyop2i3SHDOD4rQ3wsd4eTYEh6I onCpo1hME4jutGXqwm54vKhZbpkVNecg2kJ0IZfiIZNH+NlHGSbq/OHp9pO3krg4cpBG HYKMHMRxP+VUYqZUmiNoJJZpZM4ggPMnamTppwkcErK0QwQQWG53aK26iqRAeD1/dHoD fK8A== X-Gm-Message-State: AOAM531mlr+jyvUVVgHdhASmSQcVDcOH0bpslGtwnz5Vt+EhXcUGzy42 UUZxvy0xfjTEGLyd2bG7JH97GA7rVq6kmucsjlk= X-Google-Smtp-Source: ABdhPJzFhJgABGAVcWbgO/jG8mDYXO8U7pJbwhaXNlua4V3zIhk1/4bqS9A9MIBdPt2R4YYaHs14vw== X-Received: by 2002:a02:9542:: with SMTP id y60mr431670jah.87.1631051628189; Tue, 07 Sep 2021 14:53:48 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 11/42] bsd-user: Eliminate elf personality Date: Tue, 7 Sep 2021 15:53:01 -0600 Message-Id: <20210907215332.30737-12-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052467490100005 Content-Type: text/plain; charset="utf-8" From: Warner Losh The linux kernel supports a number of different ELF binaries. The Linux use= rland emulator inheritted some of that. And we inheritted it from there. However,= for BSD there's only one kind of ELF file supported per platform, so there's no= need to cope with historical quirks. Simply the code as a result. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 87 ---------------------------------------------- bsd-user/qemu.h | 1 - 2 files changed, 88 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 639673f5b7..e950732978 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -25,66 +25,6 @@ =20 #include "target_arch_elf.h" =20 -/* from personality.h */ - -/* - * Flags for bug emulation. - * - * These occupy the top three bytes. - */ -enum { - ADDR_NO_RANDOMIZE =3D 0x0040000, /* disable randomization= of VA space */ - FDPIC_FUNCPTRS =3D 0x0080000, /* userspace function pt= rs point to descriptors - * (signal handling) - */ - MMAP_PAGE_ZERO =3D 0x0100000, - ADDR_COMPAT_LAYOUT =3D 0x0200000, - READ_IMPLIES_EXEC =3D 0x0400000, - ADDR_LIMIT_32BIT =3D 0x0800000, - SHORT_INODE =3D 0x1000000, - WHOLE_SECONDS =3D 0x2000000, - STICKY_TIMEOUTS =3D 0x4000000, - ADDR_LIMIT_3GB =3D 0x8000000, -}; - -/* - * Personality types. - * - * These go in the low byte. Avoid using the top bit, it will - * conflict with error returns. - */ -enum { - PER_LINUX =3D 0x0000, - PER_LINUX_32BIT =3D 0x0000 | ADDR_LIMIT_32BIT, - PER_LINUX_FDPIC =3D 0x0000 | FDPIC_FUNCPTRS, - PER_SVR4 =3D 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZER= O, - PER_SVR3 =3D 0x0002 | STICKY_TIMEOUTS | SHORT_INODE, - PER_SCOSVR3 =3D 0x0003 | STICKY_TIMEOUTS | - WHOLE_SECONDS | SHORT_INODE, - PER_OSR5 =3D 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS, - PER_WYSEV386 =3D 0x0004 | STICKY_TIMEOUTS | SHORT_INODE, - PER_ISCR4 =3D 0x0005 | STICKY_TIMEOUTS, - PER_BSD =3D 0x0006, - PER_SUNOS =3D 0x0006 | STICKY_TIMEOUTS, - PER_XENIX =3D 0x0007 | STICKY_TIMEOUTS | SHORT_INODE, - PER_LINUX32 =3D 0x0008, - PER_LINUX32_3GB =3D 0x0008 | ADDR_LIMIT_3GB, - PER_IRIX32 =3D 0x0009 | STICKY_TIMEOUTS,/* IRIX5 32-bit= */ - PER_IRIXN32 =3D 0x000a | STICKY_TIMEOUTS,/* IRIX6 new 32= -bit */ - PER_IRIX64 =3D 0x000b | STICKY_TIMEOUTS,/* IRIX6 64-bit= */ - PER_RISCOS =3D 0x000c, - PER_SOLARIS =3D 0x000d | STICKY_TIMEOUTS, - PER_UW7 =3D 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZER= O, - PER_OSF4 =3D 0x000f, /* OSF/1 v4 */ - PER_HPUX =3D 0x0010, - PER_MASK =3D 0x00ff, -}; - -/* - * Return the base personality without flags. - */ -#define personality(pers) (pers & PER_MASK) - /* this flag is uneffective under linux too, should be deleted */ #ifndef MAP_DENYWRITE #define MAP_DENYWRITE 0 @@ -750,7 +690,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, abi_ulong load_addr, load_bias; int load_addr_set =3D 0; unsigned int interpreter_type =3D INTERPRETER_NONE; - unsigned char ibcs2_interpreter; int i; struct elf_phdr * elf_ppnt; struct elf_phdr *elf_phdata; @@ -765,7 +704,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, #endif char passed_fileno[6]; =20 - ibcs2_interpreter =3D 0; load_addr =3D 0; load_bias =3D 0; elf_ex =3D *((struct elfhdr *) bprm->buf); /* exec-header */ @@ -856,20 +794,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, exit(-1); } =20 - /* If the program interpreter is one of these two, - then assume an iBCS2 image. Otherwise assume - a native linux image. */ - - /* JRP - Need to add X86 lib dir stuff here... */ - - if (strcmp(elf_interpreter, "/usr/lib/libc.so.1") =3D=3D 0 || - strcmp(elf_interpreter, "/usr/lib/ld.so.1") =3D=3D 0) { - ibcs2_interpreter =3D 1; - } - -#if 0 - printf("Using ELF interpreter %s\n", path(elf_interpreter)); -#endif if (retval >=3D 0) { retval =3D open(path(elf_interpreter), O_RDONLY); if (retval >=3D 0) { @@ -1099,7 +1023,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, load_symbols(&elf_ex, bprm->fd); =20 if (interpreter_type !=3D INTERPRETER_AOUT) close(bprm->fd); - info->personality =3D (ibcs2_interpreter ? PER_SVR4 : PER_LINUX); =20 #ifdef LOW_ELF_STACK info->start_stack =3D bprm->p =3D elf_stack - 4; @@ -1135,16 +1058,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct = target_pt_regs *regs, printf("(brk) %x\n" , info->brk); #endif =20 - if (info->personality =3D=3D PER_SVR4) - { - /* Why this, you ask??? Well SVr4 maps page 0 as read-only, - and some applications "depend" upon this behavior. - Since we do not have the power to recompile these, we - emulate the SVr4 behavior. Sigh. */ - target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE, -1, 0); - } - info->entry =3D elf_entry; =20 return 0; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 6b601ce4b5..e85c164bab 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -66,7 +66,6 @@ struct image_info { abi_ulong entry; abi_ulong code_offset; abi_ulong data_offset; - int personality; }; =20 #define MAX_SIGQUEUE_SIZE 1024 --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052231293648.122602531464; Tue, 7 Sep 2021 15:03:51 -0700 (PDT) Received: from localhost ([::1]:55576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjC2-0000Kj-9K for importer@patchew.org; Tue, 07 Sep 2021 18:03:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2P-0005lp-H2 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:54 -0400 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]:43620) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2M-0000nq-PW for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:53 -0400 Received: by mail-il1-x12f.google.com with SMTP id v16so150582ilo.10 for ; Tue, 07 Sep 2021 14:53:50 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PMz+5ER2t5fUTW7WHAivqWR4OLzMPh8lmfQ/oyNPgnk=; b=xtq504ZJ8oD4dFQW1fSQPaP5fg7FgyGZtqezBVZ2PHsa+Dn5hXrm02xn2Q4H6pr9Ou KydCYcIIOYG1UQFy7H1+6poo97wzwZ9w79oeBztlNI/rHNaS2VdiW9rmzdC3iQnJLYY5 CbnWeheIsMsME9n0R07f50P641cp9BfyST0QSG03j+Ob0WhHV1pdSve2JPLw4YPg8PXf BcMtVTQvy+gUWw1Xb3CL4Ojq5Sorx4B4c8vD+YTkR4Ges0Ry4/t5TN73+Go/KUvwxoNh gEeN2PYoWSpY/OwkgBY5FD7NwS3qwcY6wXu9Rvu8PXyRNFLoVuvK9ZJG1InOvEs/mcKN FUzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PMz+5ER2t5fUTW7WHAivqWR4OLzMPh8lmfQ/oyNPgnk=; b=LUQXL1vgY7v9R0hQSJ9PH3mNjS6sP6dDyRPIPJQP4TRs25IzrbBEt7a0OlCohdNwQc tVFUzoEg1sJw+VNAOxATTnR++6HfcrevCZhLKVyluSUZUoxY7R7V+/GHJXow97jVY94c bj8c/7YumS/sUTIDpUi4vJKZCqNaYQnxX3j9eRswahc/q7O57UmQ8kVMSgCIc4v2RWV3 v+dnOGZptiWsywS8Va/6Wxv5RtQGH0ZT3XW085ZsGAbBorBqbl+4DWdjqe9mjvK68Pkn CNlHi/XwCjx0N+Y071jUMaM7D3MzjnlmSUgKmKQ3lm3FrV9/MRJw463utnmDLtxwhdrO lQjA== X-Gm-Message-State: AOAM530/8jjdALJrkK3bXPwg9nHdNcbRH456rnX1pqRP6OgOEcVUbWMB OfmXqunlBz/2Yjg/F0VzYnv30n4iQpkEvI7EA8E= X-Google-Smtp-Source: ABdhPJySigL6XvispN5LW1bKT3WDpae16cHszjtl396vilx/Vswf/5CrdKdfFhRxpcYxNRImo/NcTw== X-Received: by 2002:a92:a801:: with SMTP id o1mr277529ilh.128.1631051628984; Tue, 07 Sep 2021 14:53:48 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 12/42] bsd-user: remove a.out support Date: Tue, 7 Sep 2021 15:53:02 -0600 Message-Id: <20210907215332.30737-13-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12f; envelope-from=imp@bsdimp.com; helo=mail-il1-x12f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052233106100001 From: Warner Losh Remove still-born a.out support. The BSDs switched from a.out to ELF 20+ ye= ars ago. It's out of scope for bsd-user, and what little support there was would simply wind up at a not-implemented message. Simplify the whole mess by rem= oving it entirely. Should future support be required, it would be better to start= from scratch. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- bsd-user/bsdload.c | 9 +--- bsd-user/elfload.c | 105 ++++++++------------------------------------- bsd-user/qemu.h | 2 +- 3 files changed, 21 insertions(+), 95 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 32f7fd5dec..6aefc7a28b 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -98,7 +98,7 @@ static int prepare_binprm(struct bsd_binprm *bprm) =20 /* Construct the envp and argv tables on the target stack. */ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, - abi_ulong stringp, int push_ptr) + abi_ulong stringp) { int n =3D sizeof(abi_ulong); abi_ulong envp; @@ -108,13 +108,6 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_= ulong sp, envp =3D sp; sp -=3D (argc + 1) * n; argv =3D sp; - if (push_ptr) { - /* FIXME - handle put_user() failures */ - sp -=3D n; - put_user_ual(envp, sp); - sp -=3D n; - put_user_ual(argv, sp); - } sp -=3D n; /* FIXME - handle put_user() failures */ put_user_ual(argc, sp); diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index e950732978..4f3fa83c2c 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -52,25 +52,6 @@ =20 #include "elf.h" =20 -struct exec -{ - unsigned int a_info; /* Use macros N_MAGIC, etc for access */ - unsigned int a_text; /* length of text, in bytes */ - unsigned int a_data; /* length of data, in bytes */ - unsigned int a_bss; /* length of uninitialized data area, in bytes */ - unsigned int a_syms; /* length of symbol table data in file, in bytes = */ - unsigned int a_entry; /* start address */ - unsigned int a_trsize; /* length of relocation info for text, in bytes */ - unsigned int a_drsize; /* length of relocation info for data, in bytes */ -}; - - -#define N_MAGIC(exec) ((exec).a_info & 0xffff) -#define OMAGIC 0407 -#define NMAGIC 0410 -#define ZMAGIC 0413 -#define QMAGIC 0314 - /* max code+data+bss space allocated to elf interpreter */ #define INTERP_MAP_SIZE (32 * 1024 * 1024) =20 @@ -82,10 +63,6 @@ struct exec #define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_= PAGESIZE - 1)) #define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1)) =20 -#define INTERPRETER_NONE 0 -#define INTERPRETER_AOUT 1 -#define INTERPRETER_ELF 2 - #define DLINFO_ITEMS 12 =20 static inline void memcpy_fromfs(void *to, const void *from, unsigned long= n) @@ -93,8 +70,6 @@ static inline void memcpy_fromfs(void *to, const void *fr= om, unsigned long n) memcpy(to, from, n); } =20 -static int load_aout_interp(void *exptr, int interp_fd); - #ifdef BSWAP_NEEDED static void bswap_ehdr(struct elfhdr *ehdr) { @@ -300,7 +275,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int arg= c, int envc, struct elfhdr * exec, abi_ulong load_addr, abi_ulong load_bias, - abi_ulong interp_load_addr, int ibcs, + abi_ulong interp_load_addr, struct image_info *info) { abi_ulong sp; @@ -330,7 +305,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int arg= c, int envc, size +=3D DLINFO_ARCH_ITEMS * 2; #endif size +=3D envc + argc + 2; - size +=3D (!ibcs ? 3 : 1); /* argc itself */ + size +=3D 1; /* argc itself */ size *=3D n; if (size & 15) sp -=3D 16 - (size & 15); @@ -370,7 +345,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int arg= c, int envc, #endif #undef NEW_AUX_ENT =20 - sp =3D loader_build_argptr(envc, argc, sp, p, !ibcs); + sp =3D loader_build_argptr(envc, argc, sp, p); return sp; } =20 @@ -432,7 +407,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_= elf_ex, if (retval < 0) { perror("load_elf_interp"); exit(-1); - free (elf_phdata); + free(elf_phdata); return retval; } #ifdef BSWAP_NEEDED @@ -685,11 +660,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, { struct elfhdr elf_ex; struct elfhdr interp_elf_ex; - struct exec interp_ex; int interpreter_fd =3D -1; /* avoid warning */ abi_ulong load_addr, load_bias; int load_addr_set =3D 0; - unsigned int interpreter_type =3D INTERPRETER_NONE; int i; struct elf_phdr * elf_ppnt; struct elf_phdr *elf_phdata; @@ -702,7 +675,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, #ifdef LOW_ELF_STACK abi_ulong elf_stack =3D ~((abi_ulong)0UL); #endif - char passed_fileno[6]; =20 load_addr =3D 0; load_bias =3D 0; @@ -760,7 +732,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, end_code =3D 0; start_data =3D 0; end_data =3D 0; - interp_ex.a_info =3D 0; =20 for (i =3D 0;i < elf_ex.e_phnum; i++) { if (elf_ppnt->p_type =3D=3D PT_INTERP) { @@ -813,7 +784,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, } } if (retval >=3D 0) { - interp_ex =3D *((struct exec *) bprm->buf); /* aout exec-h= eader */ interp_elf_ex =3D *((struct elfhdr *) bprm->buf); /* elf e= xec-header */ } if (retval < 0) { @@ -830,20 +800,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, =20 /* Some simple consistency checks for the interpreter */ if (elf_interpreter) { - interpreter_type =3D INTERPRETER_ELF | INTERPRETER_AOUT; - - /* Now figure out which format our binary is */ - if ((N_MAGIC(interp_ex) !=3D OMAGIC) && (N_MAGIC(interp_ex) !=3D Z= MAGIC) && - (N_MAGIC(interp_ex) !=3D QMAGIC)) { - interpreter_type =3D INTERPRETER_ELF; - } - if (interp_elf_ex.e_ident[0] !=3D 0x7f || - strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) !=3D = 0) { - interpreter_type &=3D ~INTERPRETER_ELF; - } - - if (!interpreter_type) { + strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) !=3D 0) { free(elf_interpreter); free(elf_phdata); close(bprm->fd); @@ -854,24 +812,11 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, /* OK, we are done with that, now set up the arg stuff, and then start this sucker up */ =20 - { - char *passed_p; - - if (interpreter_type =3D=3D INTERPRETER_AOUT) { - snprintf(passed_fileno, sizeof(passed_fileno), "%d", bprm->fd); - passed_p =3D passed_fileno; - - if (elf_interpreter) { - bprm->p =3D copy_elf_strings(1, &passed_p, bprm->page, bpr= m->p); - bprm->argc++; - } - } - if (!bprm->p) { - free(elf_interpreter); - free(elf_phdata); - close(bprm->fd); - return -E2BIG; - } + if (!bprm->p) { + free(elf_interpreter); + free(elf_phdata); + close(bprm->fd); + return -E2BIG; } =20 /* OK, This is the point of no return */ @@ -997,13 +942,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, end_data +=3D load_bias; =20 if (elf_interpreter) { - if (interpreter_type & 1) { - elf_entry =3D load_aout_interp(&interp_ex, interpreter_fd); - } - else if (interpreter_type & 2) { - elf_entry =3D load_elf_interp(&interp_elf_ex, interpreter_fd, - &interp_load_addr); - } + elf_entry =3D load_elf_interp(&interp_elf_ex, interpreter_fd, + &interp_load_addr); reloc_func_desc =3D interp_load_addr; =20 close(interpreter_fd); @@ -1022,19 +962,18 @@ int load_elf_binary(struct bsd_binprm *bprm, struct = target_pt_regs *regs, if (qemu_log_enabled()) load_symbols(&elf_ex, bprm->fd); =20 - if (interpreter_type !=3D INTERPRETER_AOUT) close(bprm->fd); + close(bprm->fd); =20 #ifdef LOW_ELF_STACK info->start_stack =3D bprm->p =3D elf_stack - 4; #endif bprm->p =3D create_elf_tables(bprm->p, - bprm->argc, - bprm->envc, - &elf_ex, - load_addr, load_bias, - interp_load_addr, - (interpreter_type =3D=3D INTERPRETER_AOUT ? 0 : 1), - info); + bprm->argc, + bprm->envc, + &elf_ex, + load_addr, load_bias, + interp_load_addr, + info); info->load_addr =3D reloc_func_desc; info->start_brk =3D info->brk =3D elf_brk; info->end_code =3D end_code; @@ -1063,12 +1002,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct = target_pt_regs *regs, return 0; } =20 -static int load_aout_interp(void *exptr, int interp_fd) -{ - printf("a.out interpreter not yet supported\n"); - return(0); -} - void do_init_thread(struct target_pt_regs *regs, struct image_info *infop) { init_thread(regs, infop); diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index e85c164bab..d1ab58a8eb 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -129,7 +129,7 @@ struct bsd_binprm { =20 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, - abi_ulong stringp, int push_ptr); + abi_ulong stringp); int loader_exec(const char *filename, char **argv, char **envp, struct target_pt_regs *regs, struct image_info *infop, struct bsd_binprm *bprm); --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052275890869.6019174358952; Tue, 7 Sep 2021 15:04:35 -0700 (PDT) Received: from localhost ([::1]:56466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjCk-0000wk-Qc for importer@patchew.org; Tue, 07 Sep 2021 18:04:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2O-0005kt-JK for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:52 -0400 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]:46602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2N-0000pM-8X for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:52 -0400 Received: by mail-io1-xd34.google.com with SMTP id b200so430644iof.13 for ; Tue, 07 Sep 2021 14:53:50 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CEg6wJwrnKiOhib5Am1C2mO4WW7vLNd0w5q7DtkUois=; b=t9Q3kC5bpbubo0dNuT/Mu4EIxDa5RvhAAX8hvzrUbNkxi1T420yY0sNZhT4O613cog eejhUsPsh0TJwJbPjJDgJ4KjTz4+D7H07w/3JTqDyo5iBwivEfR1tJg24DQvYFT7Vtn1 QXVWTfsxKYlnGqaOIZuy4y4EyXWdHfMXhgM7f3sXMzGV89yV+U9O2Ks7VUllkvi85Bsu FXmINQKsZ30McEk8gwCuq3T2TSDPPrnmtesHnCW0ivyOKmmM8Ero5s1kEPhMK11m02e7 o0Ir4WAN1fD3zZje32zob3WnvzXAyffMen8qe4hvsRkrxtAFoxhMFvd/+yKGSXoi37P8 9d9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CEg6wJwrnKiOhib5Am1C2mO4WW7vLNd0w5q7DtkUois=; b=OXYcomSd8WF1dP1agUl+tRhhVIQfTetASKPJWG6vzQtj0jjcuVUH+zIB2wMNmpGQGC 1nDp3m6bzC17vjvGLoy+H6VrZJ32O/tf0LpvDJ6LS4GXRbLekdazi4lqccJrS/rQwaxl hnBPQnMdMMoLUCsbJ6bTx00sgoHMYhF3Mxbp/EhriaUDx8ma1HV3yTIUor5D+F+prc97 bhZmSZIzC9F+rMaH5AZMRlZCR85qE9oqsfAI+e883ORN/jzANaNz7IFQlWzqf7Bl/rIz SkH2j44f1NKaHsuKy45pyDKwsD3Ih5i/rqUu+hBl9u8U26MSx9GafdAzp/SKKQLykaIo sn9A== X-Gm-Message-State: AOAM532/V6xjZ2ahREl4GqLSYnZY+ZFxIbWVIECXQ+zjTbt7HPzqQ4uH 4NRIjK0B1V2SOIxuLHatyKX7+H/WtqSZjQwEowI= X-Google-Smtp-Source: ABdhPJzFGyts2GDBqZNGMKaC9nwBsawMave3cWDGxgHHaCyLYlokxPj6T/iuW2Ton36q1oa5myVuLw== X-Received: by 2002:a02:8189:: with SMTP id n9mr428281jag.107.1631051629853; Tue, 07 Sep 2021 14:53:49 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 13/42] bsd-user: TARGET_NGROUPS unused in this file, remove Date: Tue, 7 Sep 2021 15:53:03 -0600 Message-Id: <20210907215332.30737-14-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d34; envelope-from=imp@bsdimp.com; helo=mail-io1-xd34.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052277306100005 Content-Type: text/plain; charset="utf-8" From: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsdload.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 6aefc7a28b..5b3c061a45 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -19,8 +19,6 @@ =20 #include "qemu.h" =20 -#define TARGET_NGROUPS 32 - /* ??? This should really be somewhere else. */ abi_long memcpy_to_target(abi_ulong dest, const void *src, unsigned long len) --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052454129633.7474889741651; Tue, 7 Sep 2021 15:07:34 -0700 (PDT) Received: from localhost ([::1]:35546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjFd-0006Iq-4N for importer@patchew.org; Tue, 07 Sep 2021 18:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2P-0005mC-OO for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:54 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]:44713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2O-0000r4-1R for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:53 -0400 Received: by mail-il1-x12d.google.com with SMTP id b4so147345ilr.11 for ; Tue, 07 Sep 2021 14:53:51 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eOAZSGqkpjDabAtvYukqX2GF+50RlQa86m0q01cBJbQ=; b=b0mSh6fN1+kK9YOuXNsVM8Aa6bCysYnW81bav8TzhQODDMBwtI4u7vEC6VTfpxzaFJ P/QJm7wQTjmppzohHWGkoLlGnVuMBOyK1MlHA/wcLCH12negERHXa1+K7Dy0ygkAGyLi 3hATP/m+9WR6Mj7Z9JtXs11jwjX2OOCRj/uasSknyHJYt7k2AlWHAIe8gSRitfSs0Q0v NUGmF0Oz3wmzYMTYy0PQsw4CumAFB183khH9FWdDFxPWLttz0VmpQmXr+m7IjSPnYAE9 pRiZZbJ7aHbNYJRdQ3bv2F+MXhXYIv+nhTykIEk6ZUvWTfatR0OsfBbs7puAZrj0LcfL +kYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eOAZSGqkpjDabAtvYukqX2GF+50RlQa86m0q01cBJbQ=; b=c3uGqFoTf/DnXIfuidAT694tafCXbJmXDw8QwWCbJLQmepCzG8tHZrxe0dlupyNgeV EIBkqqBv+4DKX76sNf4EQoV/zquZOOipktM58WT3pARk3tNRJnydh9CBvVFIurle57Bo xPlqA21LZ1LWCtDS5ESHw9Bi8/p3fvZKrxWv3Iu+kOUAaj/biXVRlfo/4PIuHHv52Tqr rhX9/ZTA6ci63YNAHauYmA2ib7xiFgMimk18WqnMpNB9bF5NlfNLZwNaXtznml5JHv8p IV+7Wu1XapHNsRZPfvhcRP0Xp/Hw1T6TSzdB+CHrLecc0QAku1w+rkux5yZFaEZefsmG 4txw== X-Gm-Message-State: AOAM533c6p4ItHzuZqrMcSLXqBkc8xIsSJhkcwreWLT+GcZ2SeM+Svgo QDcagit4DEaefhxvP/w341ZSTGKs30bMVpdbAI8= X-Google-Smtp-Source: ABdhPJx5bZmVmbFBSglvnNRr1kOXVtxstiOmthEUGSvqkE9t0Fe5k4T0s5PDUU8hE1GyLaxrVbZ3Tw== X-Received: by 2002:a05:6e02:134e:: with SMTP id k14mr290955ilr.39.1631051630697; Tue, 07 Sep 2021 14:53:50 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 14/42] bsd-user: elfload: simplify bswap a bit. Date: Tue, 7 Sep 2021 15:53:04 -0600 Message-Id: <20210907215332.30737-15-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052454701100002 Content-Type: text/plain; charset="utf-8" From: Warner Losh Reduce the number of ifdefs by always calling the swapping routine, but making them empty when swapping isn't needed. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 97 ++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 50 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 4f3fa83c2c..ccb1744800 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -67,13 +67,13 @@ =20 static inline void memcpy_fromfs(void *to, const void *from, unsigned long= n) { - memcpy(to, from, n); + memcpy(to, from, n); } =20 #ifdef BSWAP_NEEDED static void bswap_ehdr(struct elfhdr *ehdr) { - bswap16s(&ehdr->e_type); /* Object file type */ + bswap16s(&ehdr->e_type); /* Object file type */ bswap16s(&ehdr->e_machine); /* Architecture */ bswap32s(&ehdr->e_version); /* Object file version */ bswaptls(&ehdr->e_entry); /* Entry point virtual address */ @@ -81,37 +81,45 @@ static void bswap_ehdr(struct elfhdr *ehdr) bswaptls(&ehdr->e_shoff); /* Section header table file offse= t */ bswap32s(&ehdr->e_flags); /* Processor-specific flags */ bswap16s(&ehdr->e_ehsize); /* ELF header size in bytes */ - bswap16s(&ehdr->e_phentsize); /* Program header table en= try size */ + bswap16s(&ehdr->e_phentsize); /* Program header table entry size= */ bswap16s(&ehdr->e_phnum); /* Program header table entry coun= t */ - bswap16s(&ehdr->e_shentsize); /* Section header table en= try size */ + bswap16s(&ehdr->e_shentsize); /* Section header table entry size= */ bswap16s(&ehdr->e_shnum); /* Section header table entry coun= t */ - bswap16s(&ehdr->e_shstrndx); /* Section header string t= able index */ + bswap16s(&ehdr->e_shstrndx); /* Section header string table ind= ex */ } =20 -static void bswap_phdr(struct elf_phdr *phdr) +static void bswap_phdr(struct elf_phdr *phdr, int phnum) { - bswap32s(&phdr->p_type); /* Segment type */ - bswaptls(&phdr->p_offset); /* Segment file offset */ - bswaptls(&phdr->p_vaddr); /* Segment virtual address */ - bswaptls(&phdr->p_paddr); /* Segment physical address */ - bswaptls(&phdr->p_filesz); /* Segment size in file */ - bswaptls(&phdr->p_memsz); /* Segment size in memory */ - bswap32s(&phdr->p_flags); /* Segment flags */ - bswaptls(&phdr->p_align); /* Segment alignment */ + int i; + + for (i =3D 0; i < phnum; i++, phdr++) { + bswap32s(&phdr->p_type); /* Segment type */ + bswap32s(&phdr->p_flags); /* Segment flags */ + bswaptls(&phdr->p_offset); /* Segment file offset */ + bswaptls(&phdr->p_vaddr); /* Segment virtual address */ + bswaptls(&phdr->p_paddr); /* Segment physical address */ + bswaptls(&phdr->p_filesz); /* Segment size in file */ + bswaptls(&phdr->p_memsz); /* Segment size in memory */ + bswaptls(&phdr->p_align); /* Segment alignment */ + } } =20 -static void bswap_shdr(struct elf_shdr *shdr) +static void bswap_shdr(struct elf_shdr *shdr, int shnum) { - bswap32s(&shdr->sh_name); - bswap32s(&shdr->sh_type); - bswaptls(&shdr->sh_flags); - bswaptls(&shdr->sh_addr); - bswaptls(&shdr->sh_offset); - bswaptls(&shdr->sh_size); - bswap32s(&shdr->sh_link); - bswap32s(&shdr->sh_info); - bswaptls(&shdr->sh_addralign); - bswaptls(&shdr->sh_entsize); + int i; + + for (i =3D 0; i < shnum; i++, shdr++) { + bswap32s(&shdr->sh_name); + bswap32s(&shdr->sh_type); + bswaptls(&shdr->sh_flags); + bswaptls(&shdr->sh_addr); + bswaptls(&shdr->sh_offset); + bswaptls(&shdr->sh_size); + bswap32s(&shdr->sh_link); + bswap32s(&shdr->sh_info); + bswaptls(&shdr->sh_addralign); + bswaptls(&shdr->sh_entsize); + } } =20 static void bswap_sym(struct elf_sym *sym) @@ -121,7 +129,15 @@ static void bswap_sym(struct elf_sym *sym) bswaptls(&sym->st_size); bswap16s(&sym->st_shndx); } -#endif + +#else /* ! BSWAP_NEEDED */ + +static void bswap_ehdr(struct elfhdr *ehdr) { } +static void bswap_phdr(struct elf_phdr *phdr, int phnum) { } +static void bswap_shdr(struct elf_shdr *shdr, int shnum) { } +static void bswap_sym(struct elf_sym *sym) { } + +#endif /* ! BSWAP_NEEDED */ =20 /* * 'copy_elf_strings()' copies argument/envelope strings from user @@ -367,9 +383,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_= elf_ex, last_bss =3D 0; error =3D 0; =20 -#ifdef BSWAP_NEEDED bswap_ehdr(interp_elf_ex); -#endif /* First of all, some simple consistency checks */ if ((interp_elf_ex->e_type !=3D ET_EXEC && interp_elf_ex->e_type !=3D ET_DYN) || @@ -410,12 +424,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp= _elf_ex, free(elf_phdata); return retval; } -#ifdef BSWAP_NEEDED - eppnt =3D elf_phdata; - for (i =3D 0; ie_phnum; i++, eppnt++) { - bswap_phdr(eppnt); - } -#endif + bswap_phdr(elf_phdata, interp_elf_ex->e_phnum); =20 if (interp_elf_ex->e_type =3D=3D ET_DYN) { /* in order to avoid hardcoding the interpreter load @@ -560,9 +569,7 @@ static void load_symbols(struct elfhdr *hdr, int fd) for (i =3D 0; i < hdr->e_shnum; i++) { if (read(fd, &sechdr, sizeof(sechdr)) !=3D sizeof(sechdr)) return; -#ifdef BSWAP_NEEDED - bswap_shdr(&sechdr); -#endif + bswap_shdr(&sechdr, 1); if (sechdr.sh_type =3D=3D SHT_SYMTAB) { symtab =3D sechdr; lseek(fd, hdr->e_shoff @@ -570,9 +577,7 @@ static void load_symbols(struct elfhdr *hdr, int fd) if (read(fd, &strtab, sizeof(strtab)) !=3D sizeof(strtab)) return; -#ifdef BSWAP_NEEDED - bswap_shdr(&strtab); -#endif + bswap_shdr(&strtab, 1); goto found; } } @@ -605,9 +610,7 @@ static void load_symbols(struct elfhdr *hdr, int fd) =20 i =3D 0; while (i < nsyms) { -#ifdef BSWAP_NEEDED bswap_sym(syms + i); -#endif // Throw away entries which we do not need. if (syms[i].st_shndx =3D=3D SHN_UNDEF || syms[i].st_shndx >=3D SHN_LORESERVE || @@ -679,9 +682,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, load_addr =3D 0; load_bias =3D 0; elf_ex =3D *((struct elfhdr *) bprm->buf); /* exec-header */ -#ifdef BSWAP_NEEDED bswap_ehdr(&elf_ex); -#endif =20 /* First of all, some simple consistency checks */ if ((elf_ex.e_type !=3D ET_EXEC && elf_ex.e_type !=3D ET_DYN) || @@ -715,12 +716,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, return -errno; } =20 -#ifdef BSWAP_NEEDED - elf_ppnt =3D elf_phdata; - for (i =3D 0; i < elf_ex.e_phnum; i++, elf_ppnt++) { - bswap_phdr(elf_ppnt); - } -#endif + bswap_phdr(elf_phdata, elf_ex.e_phnum); + elf_ppnt =3D elf_phdata; =20 elf_bss =3D 0; --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631051931076736.5805118188542; Tue, 7 Sep 2021 14:58:51 -0700 (PDT) Received: from localhost ([::1]:39822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNj7B-0006II-Vm for importer@patchew.org; Tue, 07 Sep 2021 17:58:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2Q-0005mH-If for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:54 -0400 Received: from mail-il1-x12a.google.com ([2607:f8b0:4864:20::12a]:46800) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2P-0000rp-5d for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:54 -0400 Received: by mail-il1-x12a.google.com with SMTP id u17so141700ilm.13 for ; Tue, 07 Sep 2021 14:53:52 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+8JkNpfesdBOSdFjmNZn5gJ/TH6i2DvTMe8UnLYkrDo=; b=Gei2yzz7XZ7oH4ZXDddBsadV9cwNJoRmWJnOfmuUri7ajgZbdhxtxStBbzVqHQ+LNY r6dJpcQCilEWs1I69luuWjwi/VARmpzXpc03gI7ygE5c6j9tr/wCoWkTAVkNIlMuetPD +sIOyPhGksQibFqGjuCQYQnEFkIxqBW7lDDxPa+6guK0xVmgUcg1gjWGIp6+ZFGFPa6C ae8m0j8nLz+YlNjq7aS0YRRXdaxfcvL9bLoviD7E0jVHL5yMIlkexK5LYdJUmgPlJgw/ 2QA+L116leB4+4//Pe3Um4EaitrIBkrE+NG7LiHJ5rJl+Pe/oSspXi7KCmcq7KAShZKU 7hPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+8JkNpfesdBOSdFjmNZn5gJ/TH6i2DvTMe8UnLYkrDo=; b=fhGy4hrfPtSuSNYVMUvEJWZ6EZFdyxVXs78V3U67A1BaSv8/J6OAyajBfikh/xy/N0 Opx7P4jN0KHjKVol+5bFoVkTWQzlLWxB2ey0D7PfRyBUbpYMoQD+2iwVNaZiwt9xllIY v9GdskeGJmZaRi00XqmfRtCH/klcDR6DWKm3SEwfUhumt2u1kpuMJPmEki1faMs/TSJh 94dhMga91n7vwm+W7zPkiov6cfU6FPQY6zW9cso2OzTjaGO20x6+Utyb4u8afzmpCIkB weH5Dl5QEN6MCY0S0evFsvOTgO4kmSZaKQPu7Z3ckVFi8HJUKQNSTGBN2abEYLQv4deB 9BbA== X-Gm-Message-State: AOAM531HrkZefZWEXNv0FDq0aMLr4g++7KXNpCevywmd7Tp4dZ8RBkVV PIJ4bkXZkKVIC9GvBPSHaENHDvtW7VdWVHtOFHQ= X-Google-Smtp-Source: ABdhPJz6npR2nPrVyiXXwc11qopf2Yr4fDB4rTQV16pWdIp1glWO+q7dZyrhiAMiFxqYnltCHv7bTQ== X-Received: by 2002:a05:6e02:d0b:: with SMTP id g11mr252805ilj.321.1631051631652; Tue, 07 Sep 2021 14:53:51 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 15/42] bsd-user: assume pthreads and support of __thread Date: Tue, 7 Sep 2021 15:53:05 -0600 Message-Id: <20210907215332.30737-16-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12a; envelope-from=imp@bsdimp.com; helo=mail-il1-x12a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631051931805100001 From: Warner Losh All compilers for some time have supported this. Follow linux-user and eliminate the #define THREAD and unconditionally insert __thread where needed. Please insert: "(see 24cb36a61c6: "configure: Make NPTL non-optional")" Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- bsd-user/main.c | 2 +- bsd-user/qemu.h | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 1388c7a13d..e06cc7b414 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -309,7 +309,7 @@ static void usage(void) exit(1); } =20 -THREAD CPUState *thread_cpu; +__thread CPUState *thread_cpu; =20 bool qemu_cpu_is_self(CPUState *cpu) { diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index d1ab58a8eb..cf248ad3df 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -40,12 +40,6 @@ extern enum BSDType bsd_type; #include "target_syscall.h" #include "exec/gdbstub.h" =20 -#if defined(CONFIG_USE_NPTL) -#define THREAD __thread -#else -#define THREAD -#endif - /* * This struct is used to hold certain information about the image. Basic= ally, * it replicates in user space what would be certain task_struct fields in= the @@ -155,7 +149,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi= _long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6); void gemu_log(const char *fmt, ...) GCC_FMT_ATTR(1, 2); -extern THREAD CPUState *thread_cpu; +extern __thread CPUState *thread_cpu; void cpu_loop(CPUArchState *env); char *target_strerror(int err); int get_osversion(void); @@ -422,8 +416,6 @@ static inline void *lock_user_string(abi_ulong guest_ad= dr) #define unlock_user_struct(host_ptr, guest_addr, copy) \ unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0) =20 -#if defined(CONFIG_USE_NPTL) #include -#endif =20 #endif /* QEMU_H */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052642318314.84244988540763; Tue, 7 Sep 2021 15:10:42 -0700 (PDT) Received: from localhost ([::1]:44928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjIf-0004U1-Bm for importer@patchew.org; Tue, 07 Sep 2021 18:10:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2R-0005o6-HN for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:56 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]:47037) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2P-0000sp-S8 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:55 -0400 Received: by mail-io1-xd41.google.com with SMTP id b200so430783iof.13 for ; Tue, 07 Sep 2021 14:53:53 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rgX9EGZUhVCa+HvsyINfd4/gXyULb05Byjy3eWtljao=; b=Xi+QUXPPMC6nRhuP2MUzi2huW3t6l+3WARTJNXt2TkPbfGE7AnvINWaqQYY4C+hA8g sfoUfygII7hyJmEMfBN62woMiHq33zloeIbKxtAInTeRazZS/AEPG+kfZwfgd9+c+Csn sYbavlz3xaD2e4wGS3OWLA+2S4gzg6bjCarwi9fxtIu7ERH4yERZSrje/uNCxSSfiquC SaBa415lBYXgeQldVO80bYnMaXhXzBHkH+8akC5tJz/HRGS+ncO/uUDJ3tyvzVLwffmN ufVHdNpFo9ryS9bF1sHMAVgU2O/GDGIxyqZmT6BxrmiDKCjGAORdUbhgKTQrsB4yysFu tQfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rgX9EGZUhVCa+HvsyINfd4/gXyULb05Byjy3eWtljao=; b=kiOSGrM4cDvZGKBsb6J/uVz3VAvHdAXWCUdSTrgb/CgP+3qaqIMjmUAFsem3z6G/zV Q8LZBe51sNb32tszqVzcnL2mJb9AO+6NSTCKVLJL6OACJ52HmQGgDFYO4OGs4w5PLUhD /bqd02mJnlJgF/sOeaYiZN+D+oUFNgH/77r0hCB7bYdmvW9/tEGClWz4TUGnnVAglzmQ m8lZOHMqLiOTSDyWWEswgd0hchdOpLSWl8PrnUglbbdfubmvdI9Cq+HiLVCxkfr7dI4C CV3chFkED/w2BkD5myrFhFmCe/kqNWndKVIMGiig418wtYBry5MnwT/BbleZ2JAyB6Bm 52vQ== X-Gm-Message-State: AOAM530M+gmeDFB5iuDe9x59Ssuc/mTl5/um2JACdrFGpOYhzGOQ/4lH can2/5ABQ6OUpKfb/IVF4lZsWhoZ/yTnIoVIfFg= X-Google-Smtp-Source: ABdhPJxqjxn9iQ8NR6fVe6WbJs+wrjPivWZ7C7cy60ru+PVhm7NzYRTw1oxokF6J2Pp86KO+PpoTgw== X-Received: by 2002:a05:6638:1613:: with SMTP id x19mr436436jas.77.1631051632641; Tue, 07 Sep 2021 14:53:52 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 16/42] bsd-user: add host-os.h Date: Tue, 7 Sep 2021 15:53:06 -0600 Message-Id: <20210907215332.30737-17-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d41; envelope-from=imp@bsdimp.com; helo=mail-io1-xd41.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052644483100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Host OS specific bits for this implementation go in this file. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/host-os.h | 23 +++++++++++++++++++++++ bsd-user/netbsd/host-os.h | 23 +++++++++++++++++++++++ bsd-user/openbsd/host-os.h | 23 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 bsd-user/freebsd/host-os.h create mode 100644 bsd-user/netbsd/host-os.h create mode 100644 bsd-user/openbsd/host-os.h diff --git a/bsd-user/freebsd/host-os.h b/bsd-user/freebsd/host-os.h new file mode 100644 index 0000000000..bd3f2892db --- /dev/null +++ b/bsd-user/freebsd/host-os.h @@ -0,0 +1,23 @@ +/* + * FreeBSD host dependent code and definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _HOST_OS_H_ +#define _HOST_OS_H_ + +#endif /*!_HOST_OS_H_ */ diff --git a/bsd-user/netbsd/host-os.h b/bsd-user/netbsd/host-os.h new file mode 100644 index 0000000000..d4bbc7d58f --- /dev/null +++ b/bsd-user/netbsd/host-os.h @@ -0,0 +1,23 @@ +/* + * NetBSD host dependent code and definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _HOST_OS_H_ +#define _HOST_OS_H_ + +#endif /*!_HOST_OS_H_ */ diff --git a/bsd-user/openbsd/host-os.h b/bsd-user/openbsd/host-os.h new file mode 100644 index 0000000000..ae23bfef64 --- /dev/null +++ b/bsd-user/openbsd/host-os.h @@ -0,0 +1,23 @@ +/* + * OpenBSD host dependent code and definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _HOST_OS_H_ +#define _HOST_OS_H_ + +#endif /*!_HOST_OS_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052454093622.1781766677033; Tue, 7 Sep 2021 15:07:34 -0700 (PDT) Received: from localhost ([::1]:35610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjFd-0006LN-22 for importer@patchew.org; Tue, 07 Sep 2021 18:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2S-0005oC-Ln for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:56 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]:33384) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2Q-0000te-QZ for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:56 -0400 Received: by mail-io1-xd29.google.com with SMTP id f6so536750iox.0 for ; Tue, 07 Sep 2021 14:53:54 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I+3JXv1jQolF4HbQW+/G3IQp5iEJMYXKuexla/7K7h8=; b=ibwU/ovrvBIENngWKPnAwjwadKGjip5MhTTChdAROfLy991HtQvMJxewJlm5yUAYyS h/NK3mEw+9nMpiyDvO7OUbaA5sCV7xK+3Y3wJj40VcnFAXL9ti2+XCTSrW3RtwvyMbBq LxqHsRbcIEA+rSGOWHhtvIDUNvSuCm0wPNZqZTUTdBK9Aq0qb6pnABaLX3QCzc+eVMvP UQKSBWB5QA2f5adyGuVBe6uCDiK023dGI2KGwDZnGsm9MNjM6sTgcc+tWk9P1w6WNiFk oN24XLSxiNBwib5LXuJIEWhv/smBX1CF0uRPlfTdTTGbfTe0FhzUuEp+kx7jWaN8kQff wQXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I+3JXv1jQolF4HbQW+/G3IQp5iEJMYXKuexla/7K7h8=; b=bLX1+6IDY4fZ+/DrmHwKiboEFJJaj8gSMLwb56dnl7g0VWvii+Twpq4HKB+WEN5AiA MVNb0vi26pru8Qlmhr640DrhZvRVJQJu9YcgVk4ViV2SZlQv8vO9NKwOI+JRQOhKN29h AzhQe7wRYVaiYUmBzE2H1qQMsnIFdOOXfPPxJ1+NmC6JY254lg26ORD+jmEvDuaXvdyF ZxJZEF66GIAw9AjImrzLw6PPk63Amx49joHZeGLg4h4QkJG7YzPJ6aj5N7T4/V/Es/Se MFmRg97SK3HNHZTZmaeH/ydCgpE5FtZuxAhpK+iZNGjNTLLWCRUkyq5qnZmcOYQbNhHv 3HkQ== X-Gm-Message-State: AOAM530JXrczWCKSwbJwLzhE1G2SDF6GxIVyt7zUE1h4MPGA6kxvnCP4 0r+tZcRMul7ThFUWEIFVQeavIY/wrC9kE7FSnWg= X-Google-Smtp-Source: ABdhPJzV8m4xizAHbDTRK+AXFJIxT9R4SwUPNbdC2+FPfpIolb2CPBlRi/vYYFX/2w1E0ah2JPZTpQ== X-Received: by 2002:a02:9608:: with SMTP id c8mr437867jai.133.1631051633603; Tue, 07 Sep 2021 14:53:53 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 17/42] bsd-user: Include host-os.h from main Date: Tue, 7 Sep 2021 15:53:07 -0600 Message-Id: <20210907215332.30737-18-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052454670100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Include host-os.h from main.c to pick up the default OS to emulate. Set that default in main(). Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/host-os.h | 2 ++ bsd-user/main.c | 4 +++- bsd-user/netbsd/host-os.h | 2 ++ bsd-user/openbsd/host-os.h | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/host-os.h b/bsd-user/freebsd/host-os.h index bd3f2892db..dfb8344b7b 100644 --- a/bsd-user/freebsd/host-os.h +++ b/bsd-user/freebsd/host-os.h @@ -20,4 +20,6 @@ #ifndef _HOST_OS_H_ #define _HOST_OS_H_ =20 +#define HOST_DEFAULT_BSD_TYPE target_freebsd + #endif /*!_HOST_OS_H_ */ diff --git a/bsd-user/main.c b/bsd-user/main.c index e06cc7b414..607fdd8380 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -41,6 +41,8 @@ #include "exec/log.h" #include "trace/control.h" =20 +#include "host-os.h" + int singlestep; unsigned long mmap_min_addr; uintptr_t guest_base; @@ -352,7 +354,7 @@ int main(int argc, char **argv) const char *gdbstub =3D NULL; char **target_environ, **wrk; envlist_t *envlist =3D NULL; - bsd_type =3D target_openbsd; + bsd_type =3D HOST_DEFAULT_BSD_TYPE; =20 if (argc <=3D 1) { usage(); diff --git a/bsd-user/netbsd/host-os.h b/bsd-user/netbsd/host-os.h index d4bbc7d58f..c0be51a7ef 100644 --- a/bsd-user/netbsd/host-os.h +++ b/bsd-user/netbsd/host-os.h @@ -20,4 +20,6 @@ #ifndef _HOST_OS_H_ #define _HOST_OS_H_ =20 +#define HOST_DEFAULT_BSD_TYPE target_netbsd + #endif /*!_HOST_OS_H_ */ diff --git a/bsd-user/openbsd/host-os.h b/bsd-user/openbsd/host-os.h index ae23bfef64..eb8fdf1567 100644 --- a/bsd-user/openbsd/host-os.h +++ b/bsd-user/openbsd/host-os.h @@ -20,4 +20,6 @@ #ifndef _HOST_OS_H_ #define _HOST_OS_H_ =20 +#define HOST_DEFAULT_BSD_TYPE target_openbsd + #endif /*!_HOST_OS_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052106093260.58118933458036; Tue, 7 Sep 2021 15:01:46 -0700 (PDT) Received: from localhost ([::1]:48174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjA1-0003fe-2j for importer@patchew.org; Tue, 07 Sep 2021 18:01:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2T-0005pH-4R for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:58 -0400 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]:42830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2R-0000ub-NA for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:56 -0400 Received: by mail-io1-xd31.google.com with SMTP id b10so447485ioq.9 for ; Tue, 07 Sep 2021 14:53:55 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fibrjHiBo3BWeiBRUCFmwdLyefDsJC7g8aB8krYG+xI=; b=M6DRERTWmX8JVqHLIQb5C2vG4A8szHFR0zKKZpjtrO3DQAX6Oh2YrMZAM+BR9AeoOz v1ca7PwiXbCqiIh9AsCEFHKkcXxGwCAqgnRbzELFyQMnW0qoSDpiR+oxYhuaYavZtkTE UYRldymLGD28CS2HHN8zJbk+aLf1qklBQUEtSH86iPsEZwXv/nYtAiTCNtsazWxhxQS4 0cfb0eF3dqYR69OIwGmm58Urg3CCQs232bhjbBrBkN5gUUg3+rjj8dHJld4n4muMbTeQ CwsbTDWYAUqHannJ56Kk0x+zmwEMetwGNBbNv5c94OLPl0G4ZCh9twhCV8zh2AyOZ3aG CyZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fibrjHiBo3BWeiBRUCFmwdLyefDsJC7g8aB8krYG+xI=; b=sENrlzL6oj7uesasjK2s8+GzjaI60K3Kd5P6J0q+IxLp0FjSBaLAdj2QIboxGkJvcH 7uPRi72mQxqheGR1F/dNuaJH3XMf47JZHVbAjQJdkVC5E+gmM8p1Y5KslGu1z62EWU4Q TVuW/lsslPwLOgKLKD2XQx2A6sUMIQHap5rGFoukIMI3DL1o8z30E+l3rq23BrOqhMiJ eeSfra6fSMCE6pPSq77P2E+I/nXQRXh5XTwWh2vZEHcvk6qi7Y3cpYcheQXl9NiMP151 JXIKIcvwucsWv72iBP+IPLAWwBwQOeo5KCFphKo9jVPmzJ/9GV1JIWPswDQg/Epy2STc Aq0w== X-Gm-Message-State: AOAM530vvtz51dWfq1XLHz3aLK33fjEN3NxEcZLxYsSgTTbCOgPvY3Jr xxRv1urJJb9WXyH47VZRVU9rd3/QofEUxplsyDo= X-Google-Smtp-Source: ABdhPJw000Vx0F2zoxzox+ON5wtgSUHWKNfKA3ADZVPcU+OQ09YyM2p0yVkhLL0o9po4KSzpzcfCdw== X-Received: by 2002:a5d:9256:: with SMTP id e22mr307869iol.152.1631051634470; Tue, 07 Sep 2021 14:53:54 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 18/42] bsd-user: save the path to the qemu emulator Date: Tue, 7 Sep 2021 15:53:08 -0600 Message-Id: <20210907215332.30737-19-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d31; envelope-from=imp@bsdimp.com; helo=mail-io1-xd31.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , Richard Henderson , Stacey Son , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052107765100002 Content-Type: text/plain; charset="utf-8" From: Warner Losh Save the path to the qemu emulator. This will be used later when we have a more complete implementation of exec. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/main.c | 21 +++++++++++++++++++++ bsd-user/qemu.h | 1 + 2 files changed, 22 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 607fdd8380..d7c8a3e348 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -43,6 +43,8 @@ =20 #include "host-os.h" =20 +#include + int singlestep; unsigned long mmap_min_addr; uintptr_t guest_base; @@ -52,6 +54,7 @@ unsigned long reserved_va; static const char *interp_prefix =3D CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; enum BSDType bsd_type; +char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */ =20 /* * XXX: on x86 MAP_GROWSDOWN only works if ESP <=3D address + 32, so @@ -336,6 +339,22 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next =3D NULL; } =20 +static void save_proc_pathname(char *argv0) +{ + int mib[4]; + size_t len; + + mib[0] =3D CTL_KERN; + mib[1] =3D KERN_PROC; + mib[2] =3D KERN_PROC_PATHNAME; + mib[3] =3D -1; + + len =3D sizeof(qemu_proc_pathname); + if (sysctl(mib, 4, qemu_proc_pathname, &len, NULL, 0)) { + perror("sysctl"); + } +} + int main(int argc, char **argv) { const char *filename; @@ -360,6 +379,8 @@ int main(int argc, char **argv) usage(); } =20 + save_proc_pathname(argv[0]); + error_init(argv[0]); module_call_init(MODULE_INIT_TRACE); qemu_init_cpu_list(); diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index cf248ad3df..6c4ec61d76 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -207,6 +207,7 @@ void mmap_fork_start(void); void mmap_fork_end(int child); =20 /* main.c */ +extern char qemu_proc_pathname[]; extern unsigned long x86_stack_size; =20 /* user access */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052380639858.8264169951137; Tue, 7 Sep 2021 15:06:20 -0700 (PDT) Received: from localhost ([::1]:59196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjER-0002qj-H5 for importer@patchew.org; Tue, 07 Sep 2021 18:06:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2W-0005qd-7J for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:00 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:43919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2T-0000vd-4I for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:53:59 -0400 Received: by mail-io1-xd44.google.com with SMTP id n24so444860ion.10 for ; Tue, 07 Sep 2021 14:53:56 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bf3A6AvJp14kGD1giAicYh55HeGN2doZRnv3w4ggO2w=; b=DvlF6TR3+6Frq+wTiSFwGM4L0teT5ku7Vio9nCp/2wIUIJpgwz3p1QuNyaT3IWoErZ rIJ6stbciT89PgS99Apfoslo5aQHPKhcCWx1XDhQxi8G1LoASvGu5mTZcwvUF+hxTcvt JDUSUTfBSOPzoupTFblQANdqQrCF6pa7V833aJ4gZhKfUXHFUSQTj6q31TlWcHjsvrNl 6aeM0Jm1jOFgL75eCzO7G9LxqtT2fqdoW/+NtmZ+Nrb+1qdpJytybrEbdbx2CBrMgnxR pNIOsRUYe1CQWHbDCMjjYLEg4DBGglv4TuG9HQcOMSmiNKXKEMYWp+2WcyfdIMI+cQjV 1RRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bf3A6AvJp14kGD1giAicYh55HeGN2doZRnv3w4ggO2w=; b=q+0hBwGNcKGPtWof40MSiiwxnMcCE1h7NZinWxg9JTP8Rh2gbxQUIvBWsBaj+e14bv Ad8o0WU2RId9QGC4LvjryMIh9Qe1KOFLCAyBYsyepIGmrjeEjlDPyx4FABZcYND4hDAH fvm3jUJZ78iVy5MTu3iDmbJQaLVVz4xRqVyQOG22JKwiI/pmR4b3W2XicxDuChWbIKEl NW8SkLvt4i1oRzDa34eSoOZDaNa5r4gAKxkM/M0Swvk532650KR03qktPDerOavFdHvR 3cHCWNbbBXGh1+dleVHyD8Tb/Dp4dwg8pcKVXj7AcjieTh3BDDaXTkhohJzhPxiBjO2K 92EQ== X-Gm-Message-State: AOAM5308zULbJyhMRd89IDOW7NJtV/zI0ogmTpkYxzwEp8E8aUXy6X0k 1U23FaSoD2o4eYLPEzgY/G6m8b2yaOu2fL6lu7I= X-Google-Smtp-Source: ABdhPJxqWk3xHdygKe1ntAvHHN0E6pbNQ7muT5ZWRu+/+14qh2thXKym42M6WBAP5+uijIunmmEXRw== X-Received: by 2002:a6b:5819:: with SMTP id m25mr282693iob.105.1631051635521; Tue, 07 Sep 2021 14:53:55 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 19/42] bsd-user: start to move target CPU functions to target_arch* Date: Tue, 7 Sep 2021 15:53:09 -0600 Message-Id: <20210907215332.30737-20-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d44; envelope-from=imp@bsdimp.com; helo=mail-io1-xd44.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052381619100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Move the CPU functions into target_arch_cpu.c that are unique to each CPU. These are defined in target_arch.h. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/i386/target_arch.h | 31 +++++++++++++ bsd-user/i386/target_arch_cpu.c | 75 +++++++++++++++++++++++++++++++ bsd-user/main.c | 35 --------------- bsd-user/x86_64/target_arch.h | 31 +++++++++++++ bsd-user/x86_64/target_arch_cpu.c | 75 +++++++++++++++++++++++++++++++ configure | 7 +-- meson.build | 7 ++- 7 files changed, 218 insertions(+), 43 deletions(-) create mode 100644 bsd-user/i386/target_arch.h create mode 100644 bsd-user/i386/target_arch_cpu.c create mode 100644 bsd-user/x86_64/target_arch.h create mode 100644 bsd-user/x86_64/target_arch_cpu.c diff --git a/bsd-user/i386/target_arch.h b/bsd-user/i386/target_arch.h new file mode 100644 index 0000000000..73e9a028fe --- /dev/null +++ b/bsd-user/i386/target_arch.h @@ -0,0 +1,31 @@ +/* + * Intel x86 specific prototypes for bsd-user + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_ARCH_H_ +#define _TARGET_ARCH_H_ + +/* target_arch_cpu.c */ +void bsd_i386_write_dt(void *ptr, unsigned long addr, unsigned long limit, + int flags); +void bsd_i386_set_idt(int n, unsigned int dpl); +void bsd_i386_set_idt_base(uint64_t base); + +#define target_cpu_set_tls(env, newtls) + +#endif /* ! _TARGET_ARCH_H_ */ diff --git a/bsd-user/i386/target_arch_cpu.c b/bsd-user/i386/target_arch_cp= u.c new file mode 100644 index 0000000000..7f2f755a11 --- /dev/null +++ b/bsd-user/i386/target_arch_cpu.c @@ -0,0 +1,75 @@ +/* + * i386 cpu related code + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include + +#include "qemu/osdep.h" +#include "cpu.h" +#include "qemu.h" +#include "qemu/timer.h" + +#include "target_arch.h" + +static uint64_t *idt_table; + +uint64_t cpu_get_tsc(CPUX86State *env) +{ + return cpu_get_host_ticks(); +} + +int cpu_get_pic_interrupt(CPUX86State *env) +{ + return -1; +} + +void bsd_i386_write_dt(void *ptr, unsigned long addr, unsigned long limit, + int flags) +{ + unsigned int e1, e2; + uint32_t *p; + e1 =3D (addr << 16) | (limit & 0xffff); + e2 =3D ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f00= 00); + e2 |=3D flags; + p =3D ptr; + p[0] =3D tswap32(e1); + p[1] =3D tswap32(e2); +} + + +static void set_gate(void *ptr, unsigned int type, unsigned int dpl, + uint32_t addr, unsigned int sel) +{ + uint32_t *p, e1, e2; + e1 =3D (addr & 0xffff) | (sel << 16); + e2 =3D (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); + p =3D ptr; + p[0] =3D tswap32(e1); + p[1] =3D tswap32(e2); +} + +/* only dpl matters as we do only user space emulation */ +void bsd_i386_set_idt(int n, unsigned int dpl) +{ + set_gate(idt_table + n, 0, dpl, 0, 0); +} + +void bsd_i386_set_idt_base(uint64_t base) +{ + idt_table =3D g2h_untagged(base); +} + diff --git a/bsd-user/main.c b/bsd-user/main.c index d7c8a3e348..f7c75df64d 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -72,13 +72,6 @@ void gemu_log(const char *fmt, ...) va_end(ap); } =20 -#if defined(TARGET_I386) -int cpu_get_pic_interrupt(CPUX86State *env) -{ - return -1; -} -#endif - void fork_start(void) { } @@ -94,11 +87,6 @@ void fork_end(int child) /***********************************************************/ /* CPUX86 core interface */ =20 -uint64_t cpu_get_tsc(CPUX86State *env) -{ - return cpu_get_host_ticks(); -} - static void write_dt(void *ptr, unsigned long addr, unsigned long limit, int flags) { @@ -570,29 +558,6 @@ int main(int argc, char **argv) */ guest_base =3D HOST_PAGE_ALIGN(guest_base); =20 - /* - * Read in mmap_min_addr kernel parameter. This value is used - * When loading the ELF image to determine whether guest_base - * is needed. - * - * When user has explicitly set the quest base, we skip this - * test. - */ - if (!have_guest_base) { - FILE *fp; - - fp =3D fopen("/proc/sys/vm/mmap_min_addr", "r"); - if (fp !=3D NULL) { - unsigned long tmp; - if (fscanf(fp, "%lu", &tmp) =3D=3D 1) { - mmap_min_addr =3D tmp; - qemu_log_mask(CPU_LOG_PAGE, "host mmap_min_addr=3D0x%lx\n", - mmap_min_addr); - } - fclose(fp); - } - } - if (loader_exec(filename, argv + optind, target_environ, regs, info, &bprm) !=3D 0) { printf("Error loading %s\n", filename); diff --git a/bsd-user/x86_64/target_arch.h b/bsd-user/x86_64/target_arch.h new file mode 100644 index 0000000000..e558e1b956 --- /dev/null +++ b/bsd-user/x86_64/target_arch.h @@ -0,0 +1,31 @@ +/* + * Intel x86_64 specific prototypes for bsd-user + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_ARCH_H_ +#define _TARGET_ARCH_H_ + +/* target_arch_cpu.c */ +void bsd_x86_64_write_dt(void *ptr, unsigned long addr, unsigned long limi= t, + int flags); +void bsd_x86_64_set_idt(int n, unsigned int dpl); +void bsd_x86_64_set_idt_base(uint64_t base); + +#define target_cpu_set_tls(env, newtls) + +#endif /* !_TARGET_ARCH_H_ */ diff --git a/bsd-user/x86_64/target_arch_cpu.c b/bsd-user/x86_64/target_arc= h_cpu.c new file mode 100644 index 0000000000..a2c5b176a4 --- /dev/null +++ b/bsd-user/x86_64/target_arch_cpu.c @@ -0,0 +1,75 @@ +/* + * x86_64 cpu related code + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include + +#include "qemu/osdep.h" +#include "cpu.h" +#include "qemu.h" +#include "qemu/timer.h" + +#include "target_arch.h" + +static uint64_t *idt_table; + +uint64_t cpu_get_tsc(CPUX86State *env) +{ + return cpu_get_host_ticks(); +} + +int cpu_get_pic_interrupt(CPUX86State *env) +{ + return -1; +} + +void bsd_x86_64_write_dt(void *ptr, unsigned long addr, + unsigned long limit, int flags) +{ + unsigned int e1, e2; + uint32_t *p; + e1 =3D (addr << 16) | (limit & 0xffff); + e2 =3D ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f00= 00); + e2 |=3D flags; + p =3D ptr; + p[0] =3D tswap32(e1); + p[1] =3D tswap32(e2); +} + +static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, + uint64_t addr, unsigned int sel) +{ + uint32_t *p, e1, e2; + e1 =3D (addr & 0xffff) | (sel << 16); + e2 =3D (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); + p =3D ptr; + p[0] =3D tswap32(e1); + p[1] =3D tswap32(e2); + p[2] =3D tswap32(addr >> 32); + p[3] =3D 0; +} + +/* only dpl matters as we do only user space emulation */ +void bsd_x86_64_set_idt(int n, unsigned int dpl) +{ + set_gate64(idt_table + n * 2, 0, dpl, 0, 0); +} + +void bsd_x86_64_set_idt_base(uint64_t base) +{ + idt_table =3D g2h_untagged(base); +} diff --git a/configure b/configure index 8adf2127c3..da2501489f 100755 --- a/configure +++ b/configure @@ -721,6 +721,7 @@ GNU/kFreeBSD) ;; FreeBSD) bsd=3D"yes" + bsd_user=3D"yes" make=3D"${MAKE-gmake}" audio_drv_list=3D"oss try-sdl" audio_possible_drivers=3D"oss sdl pa" @@ -782,12 +783,6 @@ Linux) ;; esac =20 -if [ "$bsd" =3D "yes" ] ; then - if [ "$darwin" !=3D "yes" ] ; then - bsd_user=3D"yes" - fi -fi - : ${make=3D${MAKE-make}} =20 # We prefer python 3.x. A bare 'python' is traditionally diff --git a/meson.build b/meson.build index 7e58e6279b..9a64d16943 100644 --- a/meson.build +++ b/meson.build @@ -2569,9 +2569,12 @@ foreach target : target_dirs if 'CONFIG_LINUX_USER' in config_target base_dir =3D 'linux-user' target_inc +=3D include_directories('linux-user/host/' / config_host= ['ARCH']) - else + endif + if 'CONFIG_BSD_USER' in config_target base_dir =3D 'bsd-user' - target_inc +=3D include_directories('bsd-user/freebsd') + target_inc +=3D include_directories('bsd-user/' / targetos) + dir =3D base_dir / abi + arch_srcs +=3D files(dir / 'target_arch_cpu.c') endif target_inc +=3D include_directories( base_dir, --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052701124584.2149342190689; Tue, 7 Sep 2021 15:11:41 -0700 (PDT) Received: from localhost ([::1]:47688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjJb-0006S6-Om for importer@patchew.org; Tue, 07 Sep 2021 18:11:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2f-00064U-PO for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:09 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:41481) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2U-0000wn-D6 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:09 -0400 Received: by mail-io1-xd42.google.com with SMTP id j18so453010ioj.8 for ; Tue, 07 Sep 2021 14:53:58 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vq6CA2Skof4BMio6HYdQyJSVux89jIDwLTtCW3Th/WY=; b=S622FI1CaRO5/a61Cv7Y5X9ijh4vJH3rJ36qVuuY4HEWeFnuCLjWK00ps4H60dd747 nORIpwsNO7g6e8ylLtb6cZOPgZGjZUKcnE75KtqqvDoohRwrO+J6FhKRO5udMzIde4OO lLgBoY6etc96m/lDwYJzS1b9MtbfnwWjKHwyKv/it/m1sU/UTyHCHfbJdmqHmS5e7aBn kfyR1WH+Rg82WIX7gXrDkBrXi6OQ6UzRloIOIZXJA0/rA5Uu45+OV56hRVpoZMv+hHjd meIt2KWOeBtIXfIjB1a5QX0VZcuO45J7nLrSLC73Pns9spix1u1tpnwSvzJshpC4B6XH CdUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vq6CA2Skof4BMio6HYdQyJSVux89jIDwLTtCW3Th/WY=; b=o5FplxuzxAhHQsNRW+OiOfTNM7WKg1YeMHwPsU3XEPNZz7B9a8VMsNFktgWzvvWJvr ThG4ftKRNLJi4Q7Brbe4BPKLi8zpq9DrYs+K7qRGMFKPvXex7sq+BPc/twBoyR5Jq5qN f+jRxnVG0Ub4ismqILc8RdDMcO3SCpE4Dspo4aSxdzBEG21lvMqnRDU3KIBSq6JJLQ5/ h8ykScv6ZawSnqKZogv4aMseXbCldN4QSeSxwh8Vc24D14vHCoRi+Ndxp6R4rq5mxRD8 0NyrkmImB89HA8B9a7F/ESNbCUuowMpQrPd8j684zDQ/xbOmRW7E5w6xDY+//e3P/kgb vB4w== X-Gm-Message-State: AOAM533f3p5BALntY+T9ZQiEuCHX3oJa/0blgSzfXmaY15sv+RG3hsz3 LcCNi5HmWZhjKO3+WNDcaiWVgnzEzga5Pa3VI+w= X-Google-Smtp-Source: ABdhPJzRa+TaUG0iAkpsQGht3GrbAEUyIQHKNO7tIcIChu9VPAYDm41C1S27MLblaatf4IFNvoTOrg== X-Received: by 2002:a5d:9e0f:: with SMTP id h15mr261924ioh.133.1631051636736; Tue, 07 Sep 2021 14:53:56 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 20/42] bsd-user: Move per-cpu code into target_arch_cpu.h Date: Tue, 7 Sep 2021 15:53:10 -0600 Message-Id: <20210907215332.30737-21-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d42; envelope-from=imp@bsdimp.com; helo=mail-io1-xd42.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052702523100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Move cpu_loop() into target_cpu_loop(), and put that in target_arch_cpu.h for each architecture. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/i386/target_arch_cpu.c | 1 + bsd-user/i386/target_arch_cpu.h | 209 ++++++++++++++++++++ bsd-user/main.c | 317 ++---------------------------- bsd-user/qemu.h | 1 + bsd-user/x86_64/target_arch_cpu.c | 1 + bsd-user/x86_64/target_arch_cpu.h | 247 +++++++++++++++++++++++ 6 files changed, 473 insertions(+), 303 deletions(-) create mode 100644 bsd-user/i386/target_arch_cpu.h create mode 100644 bsd-user/x86_64/target_arch_cpu.h diff --git a/bsd-user/i386/target_arch_cpu.c b/bsd-user/i386/target_arch_cp= u.c index 7f2f755a11..71998e5ba5 100644 --- a/bsd-user/i386/target_arch_cpu.c +++ b/bsd-user/i386/target_arch_cpu.c @@ -1,6 +1,7 @@ /* * i386 cpu related code * + * Copyright (c) 2013 Stacey Son * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/bsd-user/i386/target_arch_cpu.h b/bsd-user/i386/target_arch_cp= u.h new file mode 100644 index 0000000000..978e8066af --- /dev/null +++ b/bsd-user/i386/target_arch_cpu.h @@ -0,0 +1,209 @@ +/* + * i386 cpu init and loop + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_ARCH_CPU_H_ +#define _TARGET_ARCH_CPU_H_ + +#include "target_arch.h" + +#define TARGET_DEFAULT_CPU_MODEL "qemu32" + +#define TARGET_CPU_RESET(cpu) + +static inline void target_cpu_init(CPUX86State *env, + struct target_pt_regs *regs) +{ + uint64_t *gdt_table; + + env->cr[0] =3D CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; + env->hflags |=3D HF_PE_MASK | HF_CPL_MASK; + if (env->features[FEAT_1_EDX] & CPUID_SSE) { + env->cr[4] |=3D CR4_OSFXSR_MASK; + env->hflags |=3D HF_OSFXSR_MASK; + } + + /* flags setup : we activate the IRQs by default as in user mode */ + env->eflags |=3D IF_MASK; + + /* register setup */ + env->regs[R_EAX] =3D regs->eax; + env->regs[R_EBX] =3D regs->ebx; + env->regs[R_ECX] =3D regs->ecx; + env->regs[R_EDX] =3D regs->edx; + env->regs[R_ESI] =3D regs->esi; + env->regs[R_EDI] =3D regs->edi; + env->regs[R_EBP] =3D regs->ebp; + env->regs[R_ESP] =3D regs->esp; + env->eip =3D regs->eip; + + /* interrupt setup */ + env->idt.limit =3D 255; + + env->idt.base =3D target_mmap(0, sizeof(uint64_t) * (env->idt.limit + = 1), + PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + bsd_i386_set_idt_base(env->idt.base); + bsd_i386_set_idt(0, 0); + bsd_i386_set_idt(1, 0); + bsd_i386_set_idt(2, 0); + bsd_i386_set_idt(3, 3); + bsd_i386_set_idt(4, 3); + bsd_i386_set_idt(5, 0); + bsd_i386_set_idt(6, 0); + bsd_i386_set_idt(7, 0); + bsd_i386_set_idt(8, 0); + bsd_i386_set_idt(9, 0); + bsd_i386_set_idt(10, 0); + bsd_i386_set_idt(11, 0); + bsd_i386_set_idt(12, 0); + bsd_i386_set_idt(13, 0); + bsd_i386_set_idt(14, 0); + bsd_i386_set_idt(15, 0); + bsd_i386_set_idt(16, 0); + bsd_i386_set_idt(17, 0); + bsd_i386_set_idt(18, 0); + bsd_i386_set_idt(19, 0); + bsd_i386_set_idt(0x80, 3); + + /* segment setup */ + env->gdt.base =3D target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, + PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + env->gdt.limit =3D sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; + gdt_table =3D g2h_untagged(env->gdt.base); + + bsd_i386_write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | + (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); + + bsd_i386_write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | + (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); + + cpu_x86_load_seg(env, R_CS, __USER_CS); + cpu_x86_load_seg(env, R_SS, __USER_DS); + cpu_x86_load_seg(env, R_DS, __USER_DS); + cpu_x86_load_seg(env, R_ES, __USER_DS); + cpu_x86_load_seg(env, R_FS, __USER_DS); + cpu_x86_load_seg(env, R_GS, __USER_DS); + /* This hack makes Wine work... */ + env->segs[R_FS].selector =3D 0; +} + +static inline void target_cpu_loop(CPUX86State *env) +{ + CPUState *cs =3D env_cpu(env); + int trapnr; + abi_ulong pc; + /* target_siginfo_t info; */ + + for (;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case 0x80: + /* syscall from int $0x80 */ + if (bsd_type =3D=3D target_freebsd) { + abi_ulong params =3D (abi_ulong) env->regs[R_ESP] + + sizeof(int32_t); + int32_t syscall_nr =3D env->regs[R_EAX]; + int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; + + if (syscall_nr =3D=3D TARGET_FREEBSD_NR_syscall) { + get_user_s32(syscall_nr, params); + params +=3D sizeof(int32_t); + } else if (syscall_nr =3D=3D TARGET_FREEBSD_NR___syscall) { + get_user_s32(syscall_nr, params); + params +=3D sizeof(int64_t); + } + get_user_s32(arg1, params); + params +=3D sizeof(int32_t); + get_user_s32(arg2, params); + params +=3D sizeof(int32_t); + get_user_s32(arg3, params); + params +=3D sizeof(int32_t); + get_user_s32(arg4, params); + params +=3D sizeof(int32_t); + get_user_s32(arg5, params); + params +=3D sizeof(int32_t); + get_user_s32(arg6, params); + params +=3D sizeof(int32_t); + get_user_s32(arg7, params); + params +=3D sizeof(int32_t); + get_user_s32(arg8, params); + env->regs[R_EAX] =3D do_freebsd_syscall(env, + syscall_nr, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + } else { /* if (bsd_type =3D=3D target_openbsd) */ + env->regs[R_EAX] =3D do_openbsd_syscall(env, + env->regs[R_EAX], + env->regs[R_EBX], + env->regs[R_ECX], + env->regs[R_EDX], + env->regs[R_ESI], + env->regs[R_EDI], + env->regs[R_EBP]); + } + if (((abi_ulong)env->regs[R_EAX]) >=3D (abi_ulong)(-515)) { + env->regs[R_EAX] =3D -env->regs[R_EAX]; + env->eflags |=3D CC_C; + } else { + env->eflags &=3D ~CC_C; + } + break; + + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + + default: + pc =3D env->segs[R_CS].base + env->eip; + fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x -= " + "aborting\n", (long)pc, trapnr); + abort(); + } + process_pending_signals(env); + } +} + +static inline void target_cpu_clone_regs(CPUX86State *env, target_ulong ne= wsp) +{ + if (newsp) { + env->regs[R_ESP] =3D newsp; + } + env->regs[R_EAX] =3D 0; +} + +static inline void target_cpu_reset(CPUArchState *cpu) +{ + cpu_reset(env_cpu(cpu)); +} + +#endif /* ! _TARGET_ARCH_CPU_H_ */ diff --git a/bsd-user/main.c b/bsd-user/main.c index f7c75df64d..3d4ed202a0 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -42,6 +42,7 @@ #include "trace/control.h" =20 #include "host-os.h" +#include "target_arch_cpu.h" =20 #include =20 @@ -83,178 +84,11 @@ void fork_end(int child) } } =20 -#ifdef TARGET_I386 -/***********************************************************/ -/* CPUX86 core interface */ - -static void write_dt(void *ptr, unsigned long addr, unsigned long limit, - int flags) -{ - unsigned int e1, e2; - uint32_t *p; - e1 =3D (addr << 16) | (limit & 0xffff); - e2 =3D ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f00= 00); - e2 |=3D flags; - p =3D ptr; - p[0] =3D tswap32(e1); - p[1] =3D tswap32(e2); -} - -static uint64_t *idt_table; -#ifdef TARGET_X86_64 -static void set_gate64(void *ptr, unsigned int type, unsigned int dpl, - uint64_t addr, unsigned int sel) -{ - uint32_t *p, e1, e2; - e1 =3D (addr & 0xffff) | (sel << 16); - e2 =3D (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); - p =3D ptr; - p[0] =3D tswap32(e1); - p[1] =3D tswap32(e2); - p[2] =3D tswap32(addr >> 32); - p[3] =3D 0; -} -/* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) -{ - set_gate64(idt_table + n * 2, 0, dpl, 0, 0); -} -#else -static void set_gate(void *ptr, unsigned int type, unsigned int dpl, - uint32_t addr, unsigned int sel) +void cpu_loop(CPUArchState *env) { - uint32_t *p, e1, e2; - e1 =3D (addr & 0xffff) | (sel << 16); - e2 =3D (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); - p =3D ptr; - p[0] =3D tswap32(e1); - p[1] =3D tswap32(e2); + target_cpu_loop(env); } =20 -/* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) -{ - set_gate(idt_table + n, 0, dpl, 0, 0); -} -#endif - -void cpu_loop(CPUX86State *env) -{ - CPUState *cs =3D env_cpu(env); - int trapnr; - abi_ulong pc; - /* target_siginfo_t info; */ - - for (;;) { - cpu_exec_start(cs); - trapnr =3D cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case 0x80: - /* syscall from int $0x80 */ - if (bsd_type =3D=3D target_freebsd) { - abi_ulong params =3D (abi_ulong) env->regs[R_ESP] + - sizeof(int32_t); - int32_t syscall_nr =3D env->regs[R_EAX]; - int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; - - if (syscall_nr =3D=3D TARGET_FREEBSD_NR_syscall) { - get_user_s32(syscall_nr, params); - params +=3D sizeof(int32_t); - } else if (syscall_nr =3D=3D TARGET_FREEBSD_NR___syscall) { - get_user_s32(syscall_nr, params); - params +=3D sizeof(int64_t); - } - get_user_s32(arg1, params); - params +=3D sizeof(int32_t); - get_user_s32(arg2, params); - params +=3D sizeof(int32_t); - get_user_s32(arg3, params); - params +=3D sizeof(int32_t); - get_user_s32(arg4, params); - params +=3D sizeof(int32_t); - get_user_s32(arg5, params); - params +=3D sizeof(int32_t); - get_user_s32(arg6, params); - params +=3D sizeof(int32_t); - get_user_s32(arg7, params); - params +=3D sizeof(int32_t); - get_user_s32(arg8, params); - env->regs[R_EAX] =3D do_freebsd_syscall(env, - syscall_nr, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8); - } else { /* if (bsd_type =3D=3D target_openbsd) */ - env->regs[R_EAX] =3D do_openbsd_syscall(env, - env->regs[R_EAX], - env->regs[R_EBX], - env->regs[R_ECX], - env->regs[R_EDX], - env->regs[R_ESI], - env->regs[R_EDI], - env->regs[R_EBP]); - } - if (((abi_ulong)env->regs[R_EAX]) >=3D (abi_ulong)(-515)) { - env->regs[R_EAX] =3D -env->regs[R_EAX]; - env->eflags |=3D CC_C; - } else { - env->eflags &=3D ~CC_C; - } - break; -#ifndef TARGET_ABI32 - case EXCP_SYSCALL: - /* syscall from syscall instruction */ - if (bsd_type =3D=3D target_freebsd) { - env->regs[R_EAX] =3D do_freebsd_syscall(env, - env->regs[R_EAX], - env->regs[R_EDI], - env->regs[R_ESI], - env->regs[R_EDX], - env->regs[R_ECX], - env->regs[8], - env->regs[9], 0, 0); - } else { /* if (bsd_type =3D=3D target_openbsd) */ - env->regs[R_EAX] =3D do_openbsd_syscall(env, - env->regs[R_EAX], - env->regs[R_EDI], - env->regs[R_ESI], - env->regs[R_EDX], - env->regs[10], - env->regs[8], - env->regs[9]); - } - env->eip =3D env->exception_next_eip; - if (((abi_ulong)env->regs[R_EAX]) >=3D (abi_ulong)(-515)) { - env->regs[R_EAX] =3D -env->regs[R_EAX]; - env->eflags |=3D CC_C; - } else { - env->eflags &=3D ~CC_C; - } - break; -#endif - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - default: - pc =3D env->segs[R_CS].base + env->eip; - fprintf(stderr, - "qemu: 0x%08lx: unhandled CPU exception 0x%x - abortin= g\n", - (long)pc, trapnr); - abort(); - } - process_pending_signals(env); - } -} -#endif - static void usage(void) { printf("qemu-" TARGET_NAME " version " QEMU_FULL_VERSION @@ -353,7 +187,7 @@ int main(int argc, char **argv) struct target_pt_regs regs1, *regs =3D ®s1; struct image_info info1, *info =3D &info1; struct bsd_binprm bprm; - TaskState ts1, *ts =3D &ts1; + TaskState *ts; CPUArchState *env; CPUState *cpu; int optind, rv; @@ -521,18 +355,11 @@ int main(int argc, char **argv) init_paths(interp_prefix); =20 if (cpu_model =3D=3D NULL) { -#if defined(TARGET_I386) -#ifdef TARGET_X86_64 - cpu_model =3D "qemu64"; -#else - cpu_model =3D "qemu32"; -#endif -#else - cpu_model =3D "any"; -#endif + cpu_model =3D TARGET_DEFAULT_CPU_MODEL; } =20 cpu_type =3D parse_cpu_option(cpu_model); + /* init tcg before creating CPUs and to get qemu_host_page_size */ { AccelClass *ac =3D ACCEL_GET_CLASS(current_accel()); @@ -587,6 +414,13 @@ int main(int argc, char **argv) qemu_log("entry 0x" TARGET_ABI_FMT_lx "\n", info->entry); } =20 + /* build Task State */ + ts =3D g_new0(TaskState, 1); + init_task_state(ts); + ts->info =3D info; + ts->bprm =3D &bprm; + cpu->opaque =3D ts; + target_set_brk(info->brk); syscall_init(); signal_init(); @@ -598,130 +432,7 @@ int main(int argc, char **argv) */ tcg_prologue_init(tcg_ctx); =20 - /* build Task State */ - memset(ts, 0, sizeof(TaskState)); - init_task_state(ts); - ts->info =3D info; - cpu->opaque =3D ts; - -#if defined(TARGET_I386) - env->cr[0] =3D CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; - env->hflags |=3D HF_PE_MASK | HF_CPL_MASK; - if (env->features[FEAT_1_EDX] & CPUID_SSE) { - env->cr[4] |=3D CR4_OSFXSR_MASK; - env->hflags |=3D HF_OSFXSR_MASK; - } -#ifndef TARGET_ABI32 - /* enable 64 bit mode if possible */ - if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) { - fprintf(stderr, "The selected x86 CPU does not support 64 bit mode= \n"); - exit(1); - } - env->cr[4] |=3D CR4_PAE_MASK; - env->efer |=3D MSR_EFER_LMA | MSR_EFER_LME; - env->hflags |=3D HF_LMA_MASK; -#endif - - /* flags setup : we activate the IRQs by default as in user mode */ - env->eflags |=3D IF_MASK; - - /* linux register setup */ -#ifndef TARGET_ABI32 - env->regs[R_EAX] =3D regs->rax; - env->regs[R_EBX] =3D regs->rbx; - env->regs[R_ECX] =3D regs->rcx; - env->regs[R_EDX] =3D regs->rdx; - env->regs[R_ESI] =3D regs->rsi; - env->regs[R_EDI] =3D regs->rdi; - env->regs[R_EBP] =3D regs->rbp; - env->regs[R_ESP] =3D regs->rsp; - env->eip =3D regs->rip; -#else - env->regs[R_EAX] =3D regs->eax; - env->regs[R_EBX] =3D regs->ebx; - env->regs[R_ECX] =3D regs->ecx; - env->regs[R_EDX] =3D regs->edx; - env->regs[R_ESI] =3D regs->esi; - env->regs[R_EDI] =3D regs->edi; - env->regs[R_EBP] =3D regs->ebp; - env->regs[R_ESP] =3D regs->esp; - env->eip =3D regs->eip; -#endif - - /* linux interrupt setup */ -#ifndef TARGET_ABI32 - env->idt.limit =3D 511; -#else - env->idt.limit =3D 255; -#endif - env->idt.base =3D target_mmap(0, sizeof(uint64_t) * (env->idt.limit + = 1), - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - idt_table =3D g2h_untagged(env->idt.base); - set_idt(0, 0); - set_idt(1, 0); - set_idt(2, 0); - set_idt(3, 3); - set_idt(4, 3); - set_idt(5, 0); - set_idt(6, 0); - set_idt(7, 0); - set_idt(8, 0); - set_idt(9, 0); - set_idt(10, 0); - set_idt(11, 0); - set_idt(12, 0); - set_idt(13, 0); - set_idt(14, 0); - set_idt(15, 0); - set_idt(16, 0); - set_idt(17, 0); - set_idt(18, 0); - set_idt(19, 0); - set_idt(0x80, 3); - - /* linux segment setup */ - { - uint64_t *gdt_table; - env->gdt.base =3D target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENT= RIES, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - env->gdt.limit =3D sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; - gdt_table =3D g2h_untagged(env->gdt.base); -#ifdef TARGET_ABI32 - write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, - DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | - (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); -#else - /* 64 bit code segment */ - write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, - DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | - DESC_L_MASK | - (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); -#endif - write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, - DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | - (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); - } - - cpu_x86_load_seg(env, R_CS, __USER_CS); - cpu_x86_load_seg(env, R_SS, __USER_DS); -#ifdef TARGET_ABI32 - cpu_x86_load_seg(env, R_DS, __USER_DS); - cpu_x86_load_seg(env, R_ES, __USER_DS); - cpu_x86_load_seg(env, R_FS, __USER_DS); - cpu_x86_load_seg(env, R_GS, __USER_DS); - /* This hack makes Wine work... */ - env->segs[R_FS].selector =3D 0; -#else - cpu_x86_load_seg(env, R_DS, 0); - cpu_x86_load_seg(env, R_ES, 0); - cpu_x86_load_seg(env, R_FS, 0); - cpu_x86_load_seg(env, R_GS, 0); -#endif -#else -#error unsupported target CPU -#endif + target_cpu_init(env, regs); =20 if (gdbstub) { gdbserver_start(gdbstub); diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 6c4ec61d76..5e4cbb40d4 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -82,6 +82,7 @@ typedef struct TaskState { pid_t ts_tid; /* tid (or pid) of this task */ =20 struct TaskState *next; + struct bsd_binprm *bprm; int used; /* non zero if used */ struct image_info *info; =20 diff --git a/bsd-user/x86_64/target_arch_cpu.c b/bsd-user/x86_64/target_arc= h_cpu.c index a2c5b176a4..db822e54c6 100644 --- a/bsd-user/x86_64/target_arch_cpu.c +++ b/bsd-user/x86_64/target_arch_cpu.c @@ -1,6 +1,7 @@ /* * x86_64 cpu related code * + * Copyright (c) 2013 Stacey Son * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/bsd-user/x86_64/target_arch_cpu.h b/bsd-user/x86_64/target_arc= h_cpu.h new file mode 100644 index 0000000000..5f5ee602f9 --- /dev/null +++ b/bsd-user/x86_64/target_arch_cpu.h @@ -0,0 +1,247 @@ +/* + * x86_64 cpu init and loop + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_ARCH_CPU_H_ +#define _TARGET_ARCH_CPU_H_ + +#include "target_arch.h" + +#define TARGET_DEFAULT_CPU_MODEL "qemu64" + +#define TARGET_CPU_RESET(cpu) + +static inline void target_cpu_init(CPUX86State *env, + struct target_pt_regs *regs) +{ + uint64_t *gdt_table; + + env->cr[0] =3D CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; + env->hflags |=3D HF_PE_MASK | HF_CPL_MASK; + if (env->features[FEAT_1_EDX] & CPUID_SSE) { + env->cr[4] |=3D CR4_OSFXSR_MASK; + env->hflags |=3D HF_OSFXSR_MASK; + } + + /* enable 64 bit mode if possible */ + if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) { + fprintf(stderr, "The selected x86 CPU does not support 64 bit mode= \n"); + exit(1); + } + env->cr[4] |=3D CR4_PAE_MASK; + env->efer |=3D MSR_EFER_LMA | MSR_EFER_LME; + env->hflags |=3D HF_LMA_MASK; + + /* flags setup : we activate the IRQs by default as in user mode */ + env->eflags |=3D IF_MASK; + + /* register setup */ + env->regs[R_EAX] =3D regs->rax; + env->regs[R_EBX] =3D regs->rbx; + env->regs[R_ECX] =3D regs->rcx; + env->regs[R_EDX] =3D regs->rdx; + env->regs[R_ESI] =3D regs->rsi; + env->regs[R_EDI] =3D regs->rdi; + env->regs[R_EBP] =3D regs->rbp; + env->regs[R_ESP] =3D regs->rsp; + env->eip =3D regs->rip; + + /* interrupt setup */ + env->idt.limit =3D 511; + + env->idt.base =3D target_mmap(0, sizeof(uint64_t) * (env->idt.limit + = 1), + PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + bsd_x86_64_set_idt_base(env->idt.base); + bsd_x86_64_set_idt(0, 0); + bsd_x86_64_set_idt(1, 0); + bsd_x86_64_set_idt(2, 0); + bsd_x86_64_set_idt(3, 3); + bsd_x86_64_set_idt(4, 3); + bsd_x86_64_set_idt(5, 0); + bsd_x86_64_set_idt(6, 0); + bsd_x86_64_set_idt(7, 0); + bsd_x86_64_set_idt(8, 0); + bsd_x86_64_set_idt(9, 0); + bsd_x86_64_set_idt(10, 0); + bsd_x86_64_set_idt(11, 0); + bsd_x86_64_set_idt(12, 0); + bsd_x86_64_set_idt(13, 0); + bsd_x86_64_set_idt(14, 0); + bsd_x86_64_set_idt(15, 0); + bsd_x86_64_set_idt(16, 0); + bsd_x86_64_set_idt(17, 0); + bsd_x86_64_set_idt(18, 0); + bsd_x86_64_set_idt(19, 0); + bsd_x86_64_set_idt(0x80, 3); + + /* segment setup */ + env->gdt.base =3D target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, + PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + env->gdt.limit =3D sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; + gdt_table =3D g2h_untagged(env->gdt.base); + + /* 64 bit code segment */ + bsd_x86_64_write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | DESC_L= _MASK + | (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); + + bsd_x86_64_write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | + (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); + + cpu_x86_load_seg(env, R_CS, __USER_CS); + cpu_x86_load_seg(env, R_SS, __USER_DS); + cpu_x86_load_seg(env, R_DS, 0); + cpu_x86_load_seg(env, R_ES, 0); + cpu_x86_load_seg(env, R_FS, 0); + cpu_x86_load_seg(env, R_GS, 0); +} + +static inline void target_cpu_loop(CPUX86State *env) +{ + CPUState *cs =3D env_cpu(env); + int trapnr; + abi_ulong pc; + /* target_siginfo_t info; */ + + for (;;) { + cpu_exec_start(cs); + trapnr =3D cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case 0x80: + /* syscall from int $0x80 */ + if (bsd_type =3D=3D target_freebsd) { + abi_ulong params =3D (abi_ulong) env->regs[R_ESP] + + sizeof(int32_t); + int32_t syscall_nr =3D env->regs[R_EAX]; + int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; + + if (syscall_nr =3D=3D TARGET_FREEBSD_NR_syscall) { + get_user_s32(syscall_nr, params); + params +=3D sizeof(int32_t); + } else if (syscall_nr =3D=3D TARGET_FREEBSD_NR___syscall) { + get_user_s32(syscall_nr, params); + params +=3D sizeof(int64_t); + } + get_user_s32(arg1, params); + params +=3D sizeof(int32_t); + get_user_s32(arg2, params); + params +=3D sizeof(int32_t); + get_user_s32(arg3, params); + params +=3D sizeof(int32_t); + get_user_s32(arg4, params); + params +=3D sizeof(int32_t); + get_user_s32(arg5, params); + params +=3D sizeof(int32_t); + get_user_s32(arg6, params); + params +=3D sizeof(int32_t); + get_user_s32(arg7, params); + params +=3D sizeof(int32_t); + get_user_s32(arg8, params); + env->regs[R_EAX] =3D do_freebsd_syscall(env, + syscall_nr, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + } else { /* if (bsd_type =3D=3D target_openbsd) */ + env->regs[R_EAX] =3D do_openbsd_syscall(env, + env->regs[R_EAX], + env->regs[R_EBX], + env->regs[R_ECX], + env->regs[R_EDX], + env->regs[R_ESI], + env->regs[R_EDI], + env->regs[R_EBP]); + } + if (((abi_ulong)env->regs[R_EAX]) >=3D (abi_ulong)(-515)) { + env->regs[R_EAX] =3D -env->regs[R_EAX]; + env->eflags |=3D CC_C; + } else { + env->eflags &=3D ~CC_C; + } + break; + + case EXCP_SYSCALL: + /* syscall from syscall instruction */ + if (bsd_type =3D=3D target_freebsd) { + env->regs[R_EAX] =3D do_freebsd_syscall(env, + env->regs[R_EAX], + env->regs[R_EDI], + env->regs[R_ESI], + env->regs[R_EDX], + env->regs[R_ECX], + env->regs[8], + env->regs[9], 0, 0); + } else { /* if (bsd_type =3D=3D target_openbsd) */ + env->regs[R_EAX] =3D do_openbsd_syscall(env, + env->regs[R_EAX], + env->regs[R_EDI], + env->regs[R_ESI], + env->regs[R_EDX], + env->regs[10], + env->regs[8], + env->regs[9]); + } + env->eip =3D env->exception_next_eip; + if (((abi_ulong)env->regs[R_EAX]) >=3D (abi_ulong)(-515)) { + env->regs[R_EAX] =3D -env->regs[R_EAX]; + env->eflags |=3D CC_C; + } else { + env->eflags &=3D ~CC_C; + } + break; + + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + + default: + pc =3D env->segs[R_CS].base + env->eip; + fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x -= " + "aborting\n", (long)pc, trapnr); + abort(); + } + process_pending_signals(env); + } +} + +static inline void target_cpu_clone_regs(CPUX86State *env, target_ulong ne= wsp) +{ + if (newsp) { + env->regs[R_ESP] =3D newsp; + } + env->regs[R_EAX] =3D 0; +} + +static inline void target_cpu_reset(CPUArchState *cpu) +{ + cpu_reset(env_cpu(cpu)); +} + +#endif /* ! _TARGET_ARCH_CPU_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052612241330.935817796944; Tue, 7 Sep 2021 15:10:12 -0700 (PDT) Received: from localhost ([::1]:43964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjIA-0003pl-RL for importer@patchew.org; Tue, 07 Sep 2021 18:10:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2Y-0005sp-EG for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:02 -0400 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]:39473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2U-0000x9-Ph for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:02 -0400 Received: by mail-io1-xd43.google.com with SMTP id m11so459267ioo.6 for ; Tue, 07 Sep 2021 14:53:58 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZtO1Zm+1jW1Gj7N4CZcgDYS/zvf6MWQlvacqPoQB55M=; b=sTh0kaqKB5nP+lMPtgaRKDV2UcruJEe7CpSXt1/E+7aD/7TwAOO2KRO6ALXAEIV18f VM9G5hXFjb6m2ug0GBlMZcqqcFS39xznetFD7VFJNKv4LCC5eMZc4JWyy9J+amHwy7jb /b0RYDFsz99Euw2O+UPiUUc+rxaWbQ00f4h42yObUtPsfqkWItNdTJhwsJdWk2enqU6H QpoyWxzDmbFhYnbJWYjF/Ik5kauDnRMjyK6QaU6b1aT2WDXWd4wbwQtit46t8SqIiNCu YezImrJMl+Z/peTHOJPp3UAdSEeY5eRg2fkdiNekuF2dv5aZwJzWwubhtXEBKeir/sxF ryEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZtO1Zm+1jW1Gj7N4CZcgDYS/zvf6MWQlvacqPoQB55M=; b=khLxq5Ys/1Ifb2PViBzZEyjcJfrwaJAihZI/hBZ0HT8oGrgnzkBDgv4EzxSAz3S3ev NXm4nRsrkNgtVP8Y5T/j4MtHXHbMkdQIjD5tOIdXWuTsj8x3rEdda/Ezr9HUbhjh4aPs piggxbvkkXozKJwOy+KizulpbKTlOBe2mYVO3QhiRg9uk6Bde3iQyp762bvQH9llabqL H3QfJkoERKY/tJu/yoF60PJP+rJZoKdtSdIfv9F26CfToDRhEUzmP2YJkG/4pNMB6WCz JLJ10Fbkm2r5qfTMFUZT9Ac/x+bzFoKKhZa1Q1R2sKmDsmZrTKmFYacpvvNNFoWsB7Ex j2cg== X-Gm-Message-State: AOAM530zAuAmoPOJZI+03Iq1iKXQ1MbbT5YosTUtidzVJMWwQZ9DusL2 mv18omR4QsjpWqAi6HvGuy30cEJE/GJKICzrZrE= X-Google-Smtp-Source: ABdhPJw1tDavNLUyz7JLr1OfDg14BouFFpI6v0rD+qlOxglvprkIu8MlvLSRjfTA8gl6qzNDDwmP9w== X-Received: by 2002:a5d:851a:: with SMTP id q26mr266373ion.163.1631051637431; Tue, 07 Sep 2021 14:53:57 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 21/42] bsd-user: pull in target_arch_thread.h update target_arch_elf.h Date: Tue, 7 Sep 2021 15:53:11 -0600 Message-Id: <20210907215332.30737-22-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d43; envelope-from=imp@bsdimp.com; helo=mail-io1-xd43.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052612844100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Update target_arch_elf.h to remove thread_init. Move its contents to target_arch_thread.h and rename to target_thread_init(). Update elfload.c to call it. Create thread_os_thread.h to hold the os specific parts of the thread and threat manipulation routines. Currently, it just includes target_arch_thread.h. target_arch_thread.h contains the at the moment unused target_thread_set_upcall which will be used in the future when creating actual thread (i386 has this stubbed, but other architectures in the bsd-user tree have real ones). FreeBSD doesn't do AT_HWCAP, so remove that code. Linux does, and this code came from there. These changes are all interrelated and could be brokend down, but seem to represent a reviewable changeset since most of the change is boiler plate. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Kyle Evans --- bsd-user/elfload.c | 4 ++- bsd-user/freebsd/target_os_thread.h | 25 +++++++++++++ bsd-user/i386/target_arch_elf.h | 52 ++-------------------------- bsd-user/i386/target_arch_thread.h | 47 +++++++++++++++++++++++++ bsd-user/netbsd/target_os_thread.h | 25 +++++++++++++ bsd-user/openbsd/target_os_thread.h | 25 +++++++++++++ bsd-user/x86_64/target_arch_elf.h | 38 ++------------------ bsd-user/x86_64/target_arch_thread.h | 40 +++++++++++++++++++++ 8 files changed, 171 insertions(+), 85 deletions(-) create mode 100644 bsd-user/freebsd/target_os_thread.h create mode 100644 bsd-user/i386/target_arch_thread.h create mode 100644 bsd-user/netbsd/target_os_thread.h create mode 100644 bsd-user/openbsd/target_os_thread.h create mode 100644 bsd-user/x86_64/target_arch_thread.h diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index ccb1744800..c28ef34143 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -24,6 +24,7 @@ #include "qemu/path.h" =20 #include "target_arch_elf.h" +#include "target_os_thread.h" =20 /* this flag is uneffective under linux too, should be deleted */ #ifndef MAP_DENYWRITE @@ -1001,5 +1002,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, =20 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop) { - init_thread(regs, infop); + + target_thread_init(regs, infop); } diff --git a/bsd-user/freebsd/target_os_thread.h b/bsd-user/freebsd/target_= os_thread.h new file mode 100644 index 0000000000..77433acdff --- /dev/null +++ b/bsd-user/freebsd/target_os_thread.h @@ -0,0 +1,25 @@ +/* + * FreeBSD thread dependent code and definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_OS_THREAD_H_ +#define _TARGET_OS_THREAD_H_ + +#include "target_arch_thread.h" + +#endif /* !_TARGET_OS_THREAD_H_ */ diff --git a/bsd-user/i386/target_arch_elf.h b/bsd-user/i386/target_arch_el= f.h index 84f61bd930..eb760e07fa 100644 --- a/bsd-user/i386/target_arch_elf.h +++ b/bsd-user/i386/target_arch_elf.h @@ -19,62 +19,16 @@ #ifndef _TARGET_ARCH_ELF_H_ #define _TARGET_ARCH_ELF_H_ =20 -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform(void) -{ - static char elf_platform[] =3D "i386"; - int family =3D object_property_get_int(OBJECT(thread_cpu), "family", N= ULL); - if (family > 6) { - family =3D 6; - } - if (family >=3D 3) { - elf_platform[1] =3D '0' + family; - } - return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap(void) -{ - X86CPU *cpu =3D X86_CPU(thread_cpu); - - return cpu->env.features[FEAT_1_EDX]; -} - #define ELF_START_MMAP 0x80000000 - -/* - * This is used to ensure we don't load something for the wrong architectu= re. - */ +#define ELF_ET_DYN_LOAD_ADDR 0x01001000 #define elf_check_arch(x) (((x) =3D=3D EM_386) || ((x) =3D=3D EM_486)) =20 -/* - * These are used to set parameters in the core dumps. - */ +#define ELF_HWCAP 0 /* FreeBSD doesn't do AT_HWCAP{,2} on x86 */ + #define ELF_CLASS ELFCLASS32 #define ELF_DATA ELFDATA2LSB #define ELF_ARCH EM_386 =20 -static inline void init_thread(struct target_pt_regs *regs, - struct image_info *infop) -{ - regs->esp =3D infop->start_stack; - regs->eip =3D infop->entry; - - /* - * SVR4/i386 ABI (pages 3-31, 3-32) says that when the program - * starts %edx contains a pointer to a function which might be - * registered using `atexit'. This provides a mean for the - * dynamic linker to call DT_FINI functions for shared libraries - * that have been loaded before the code runs. - * - * A value of 0 tells we have no such handler. - */ - regs->edx =3D 0; -} - #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 =20 diff --git a/bsd-user/i386/target_arch_thread.h b/bsd-user/i386/target_arch= _thread.h new file mode 100644 index 0000000000..e65e476f75 --- /dev/null +++ b/bsd-user/i386/target_arch_thread.h @@ -0,0 +1,47 @@ +/* + * i386 thread support + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_ARCH_THREAD_H_ +#define _TARGET_ARCH_THREAD_H_ + +/* Compare to vm_machdep.c cpu_set_upcall_kse() */ +static inline void target_thread_set_upcall(CPUX86State *regs, abi_ulong e= ntry, + abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size) +{ + /* XXX */ +} + +static inline void target_thread_init(struct target_pt_regs *regs, + struct image_info *infop) +{ + regs->esp =3D infop->start_stack; + regs->eip =3D infop->entry; + + /* + * SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts = %edx + * contains a pointer to a function which might be registered using + * `atexit'. This provides a mean for the dynamic linker to call DT_F= INI + * functions for shared libraries that have been loaded before the code + * runs. + * + * A value of 0 tells we have no such handler. + */ + regs->edx =3D 0; +} + +#endif /* !_TARGET_ARCH_THREAD_H_ */ diff --git a/bsd-user/netbsd/target_os_thread.h b/bsd-user/netbsd/target_os= _thread.h new file mode 100644 index 0000000000..904dd1bf78 --- /dev/null +++ b/bsd-user/netbsd/target_os_thread.h @@ -0,0 +1,25 @@ +/* + * NetBSD thread dependent code and definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_OS_THREAD_H_ +#define _TARGET_OS_THREAD_H_ + +#include "target_arch_thread.h" + +#endif /* !_TARGET_OS_THREAD_H_ */ diff --git a/bsd-user/openbsd/target_os_thread.h b/bsd-user/openbsd/target_= os_thread.h new file mode 100644 index 0000000000..01ed0d9fc8 --- /dev/null +++ b/bsd-user/openbsd/target_os_thread.h @@ -0,0 +1,25 @@ +/* + * OpenBSD thread dependent code and definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_OS_THREAD_H_ +#define _TARGET_OS_THREAD_H_ + +#include "target_arch_thread.h" + +#endif /* !_TARGET_OS_THREAD_H_ */ diff --git a/bsd-user/x86_64/target_arch_elf.h b/bsd-user/x86_64/target_arc= h_elf.h index e7c8aa2755..c2f8553962 100644 --- a/bsd-user/x86_64/target_arch_elf.h +++ b/bsd-user/x86_64/target_arch_elf.h @@ -19,48 +19,16 @@ #ifndef _TARGET_ARCH_ELF_H_ #define _TARGET_ARCH_ELF_H_ =20 -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform(void) -{ - static char elf_platform[] =3D "i386"; - int family =3D object_property_get_int(OBJECT(thread_cpu), "family", N= ULL); - if (family > 6) { - family =3D 6; - } - if (family >=3D 3) { - elf_platform[1] =3D '0' + family; - } - return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap(void) -{ - X86CPU *cpu =3D X86_CPU(thread_cpu); - - return cpu->env.features[FEAT_1_EDX]; -} - #define ELF_START_MMAP 0x2aaaaab000ULL +#define ELF_ET_DYN_LOAD_ADDR 0x01021000 #define elf_check_arch(x) (((x) =3D=3D ELF_ARCH)) =20 +#define ELF_HWCAP 0 /* FreeBSD doesn't do AT_HWCAP{,2} on x86 */ + #define ELF_CLASS ELFCLASS64 #define ELF_DATA ELFDATA2LSB #define ELF_ARCH EM_X86_64 =20 -static inline void init_thread(struct target_pt_regs *regs, - struct image_info *infop) -{ - regs->rax =3D 0; - regs->rsp =3D infop->start_stack; - regs->rip =3D infop->entry; - if (bsd_type =3D=3D target_freebsd) { - regs->rdi =3D infop->start_stack; - } -} - #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 =20 diff --git a/bsd-user/x86_64/target_arch_thread.h b/bsd-user/x86_64/target_= arch_thread.h new file mode 100644 index 0000000000..d105e43fd3 --- /dev/null +++ b/bsd-user/x86_64/target_arch_thread.h @@ -0,0 +1,40 @@ +/* + * x86_64 thread support + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_ARCH_THREAD_H_ +#define _TARGET_ARCH_THREAD_H_ + +/* Compare to vm_machdep.c cpu_set_upcall_kse() */ +static inline void target_thread_set_upcall(CPUX86State *regs, abi_ulong e= ntry, + abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size) +{ + /* XXX */ +} + +static inline void target_thread_init(struct target_pt_regs *regs, + struct image_info *infop) +{ + regs->rax =3D 0; + regs->rsp =3D infop->start_stack; + regs->rip =3D infop->entry; + if (bsd_type =3D=3D target_freebsd) { + regs->rdi =3D infop->start_stack; + } +} + +#endif /* !_TARGET_ARCH_THREAD_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052815801950.511464058853; Tue, 7 Sep 2021 15:13:35 -0700 (PDT) Received: from localhost ([::1]:52972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjLS-0001d6-M9 for importer@patchew.org; Tue, 07 Sep 2021 18:13:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2X-0005sl-Hu for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:02 -0400 Received: from mail-il1-x12c.google.com ([2607:f8b0:4864:20::12c]:41933) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2V-0000xQ-UO for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:01 -0400 Received: by mail-il1-x12c.google.com with SMTP id l10so157378ilh.8 for ; Tue, 07 Sep 2021 14:53:59 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fTBjf6x0isJLv0ohb+3+66WCltin+WfJuhYt3u89IiA=; b=VaTfr+FqqGcVblhtOv0+gmxy/mqwEIslp3oqV7/z3CoMUYqWVQ7sDabcoLqh2Va5mP v5on7Y+HGuPlswAf99mnibbDZxOFs2vAZkv8p478yHmRc1TMLLZloFU5tREcy+PxLd45 2FCM3TAquX+wui551e+wEABNvV27kMLK6Xq2cZaQG17Mc8qzTAn1963gBk//F/1Lo7vu 8Ak2hMms4IVqiBmjEA7D+VeyrZaYEaAv6APM65bs1ouk0yUSfBg9kCqgFahoIQXhJAvm eHz1V0IJqVxfyx5ZTraB87ydZEAqQTYMggVrpc0td0mrezyZlp9PdHFvFy78ala20Uqw 1cwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fTBjf6x0isJLv0ohb+3+66WCltin+WfJuhYt3u89IiA=; b=KagthyVvSsa7uYStMzgBUvjL2CslxsI+3tQaHcYaNuk0rT2lI5QE9n6fAum+aAL5Au HOFyOw781iNu1zV8n224NJf97YW+4KikzaMW4u3thfK6lRL8oz2S+NtO6vpMvpBgfZa4 hkRdv2GWMXFTe5OUc6pvAqbkzmbjftkS0UlqtPHEE9DG1SAJCKRrtEBf2oZvyHQ7g4TL tsuqBKJ5R/c8yU7Nsr3IFZU4Lb75UeJKi+W5/ZvGBRy3o8eLPOG/NUZhwZtb9GDC1y4+ HCzTprmebbd9gYMZYFLvcmSPaxOJw/KikCjgMR1l9miDJt6oWLdCZ2qM4zkXsfrK3jeb 41uw== X-Gm-Message-State: AOAM532ImLEt2+1svk3pKvdvTDcmUZVaUZW9AyYXmoVH7I2SvlZpOeqA I7ftiMMAoww13ON5V0jggTFIFM5UuQLH1hAHPS0= X-Google-Smtp-Source: ABdhPJzerRNABdHnxml78sH+bFI3eOvdsJxMJ7U/MUwzElaa44gLv5/wg3V+nuEP68sRN04DXyUI7Q== X-Received: by 2002:a92:d410:: with SMTP id q16mr275591ilm.71.1631051638417; Tue, 07 Sep 2021 14:53:58 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 22/42] bsd-user: Include more things in qemu.h Date: Tue, 7 Sep 2021 15:53:12 -0600 Message-Id: <20210907215332.30737-23-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::12c; envelope-from=imp@bsdimp.com; helo=mail-il1-x12c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052816752100003 Content-Type: text/plain; charset="utf-8" From: Warner Losh Include more header files to match bsd-user fork. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 5e4cbb40d4..55d71130bb 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -18,12 +18,12 @@ #define QEMU_H =20 =20 +#include "qemu/osdep.h" #include "cpu.h" #include "exec/cpu_ldst.h" +#include "exec/exec-all.h" =20 #undef DEBUG_REMAP -#ifdef DEBUG_REMAP -#endif /* DEBUG_REMAP */ =20 #include "exec/user/abitypes.h" =20 @@ -36,6 +36,8 @@ enum BSDType { }; extern enum BSDType bsd_type; =20 +#include "exec/user/thunk.h" +#include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h" #include "exec/gdbstub.h" --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052604981149.1248044818534; Tue, 7 Sep 2021 15:10:04 -0700 (PDT) Received: from localhost ([::1]:43710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjI4-0003e0-0U for importer@patchew.org; Tue, 07 Sep 2021 18:10:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2Y-0005sn-4d for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:02 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]:39436) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2W-0000y6-Gx for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:01 -0400 Received: by mail-io1-xd2d.google.com with SMTP id m11so459351ioo.6 for ; Tue, 07 Sep 2021 14:54:00 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LfrE81ZrxSCq64hVLSr9n7zzdJ11Q73sKolgD5sAWUM=; b=dlq5UuBbYrs3+XFRYKna4/1h7OmlHwlUl5qdC2E+K5zzDA6jMesWJy9YbKQE589thR C4bmGnb7oIWOEdfZciG345bykhSqTMwRxax9vVo3Gbf0XbdLf4XiLG8iYqYqs3Co8zKP xCYTZnVL6ct3eEXL8wPd4bAw5jLZQkvdfBDoB8ojlLM8C4xmvOZGKTVD9VGKCFUrsUsP hDT7HLb/G0SmOunR9VUJO8zPX1+KZKgrGcjTU9m8cSpQUtJ2DBAUk8iZSfJ2PlGQ034Z b2IWtb+lMAiyQLKwCfqnNrOuw2xPg+gOSHtEovN9oMdFDnJVZA0poBSIWIjQUWxW/YLS cvAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LfrE81ZrxSCq64hVLSr9n7zzdJ11Q73sKolgD5sAWUM=; b=lEL42m82vE3QejGFfT8Z0Yi6bl0I3xyi9Yujhtvx9Ct8k7e3rPYEDMMvHLx2h8pWdO qgyAWzKy873xSquTXVINtGXMsnyaOpWW4TG3cbBO0ngm8BiddjRKX8V0r8FfEusgyCmQ pmgYM6OjrxZbprhoCguRQeMlou6ng9MVI4SXOUhmwxafzmZrdrZ0mAV4bOIaI13vaCrF /sDxTrU86pZSOlk4iWSbz1BrtKEEHKK3psH8RxNKn6w9G26tLx5QlFb8Jz/avy1Mo+Q+ 4IMfZbKvKuJCfk6AvyOMvsP2dteBsGs0UqwlVSJtpQDJnZBsLmOWdyKmeUd/ynUUejcd 70GQ== X-Gm-Message-State: AOAM5327/2eDDMq9EV1Xen4jQ1nsVmvfXJ/IIMXhjwLaU85gA2Sd5F9d 9MIvXyl96I/Ust3Rt5pNMedhdkeGoktK8zvzbHE= X-Google-Smtp-Source: ABdhPJzQ/m7EXz0aWwGX4tSl5p17oJJelVNcYyX/AS/LOwo8xTDaR36scNb8/mHDOnTsEkmb7pF+ug== X-Received: by 2002:a02:c055:: with SMTP id u21mr438269jam.113.1631051639161; Tue, 07 Sep 2021 14:53:59 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 23/42] bsd-user: define max args in terms of pages Date: Tue, 7 Sep 2021 15:53:13 -0600 Message-Id: <20210907215332.30737-24-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052606490100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh For 32-bit platforms, pass in up to 256k of args. For 64-bit, bump that to 512k. Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/qemu.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 55d71130bb..fea1a167e4 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" #include "cpu.h" +#include "qemu/units.h" #include "exec/cpu_ldst.h" #include "exec/exec-all.h" =20 @@ -101,11 +102,17 @@ extern const char *qemu_uname_release; extern unsigned long mmap_min_addr; =20 /* - * MAX_ARG_PAGES defines the number of pages allocated for arguments - * and envelope for the new program. 32 should suffice, this gives - * a maximum env+arg of 128kB w/4KB pages! + * TARGET_ARG_MAX defines the number of bytes allocated for arguments + * and envelope for the new program. 256k should suffice for a reasonable + * maxiumum env+arg in 32-bit environments, bump it up to 512k for !ILP32 + * platforms. */ -#define MAX_ARG_PAGES 32 +#if TARGET_ABI_BITS > 32 +#define TARGET_ARG_MAX (512 * KiB) +#else +#define TARGET_ARG_MAX (256 * KiB) +#endif +#define MAX_ARG_PAGES (TARGET_ARG_MAX / TARGET_PAGE_SIZE) =20 /* * This structure is used to hold the arguments that are --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052947417757.4014013592522; Tue, 7 Sep 2021 15:15:47 -0700 (PDT) Received: from localhost ([::1]:33332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjNZ-0007LZ-B3 for importer@patchew.org; Tue, 07 Sep 2021 18:15:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2Z-0005uF-9U for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:04 -0400 Received: from mail-il1-x142.google.com ([2607:f8b0:4864:20::142]:38672) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2X-0000yY-9F for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:03 -0400 Received: by mail-il1-x142.google.com with SMTP id u11so168043ilj.5 for ; Tue, 07 Sep 2021 14:54:00 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/alk5dhNog11lYeAdIDLuwiTsPArXCiZibQ+tOSdZPs=; b=R9CZcuIHaYn2OcdRT0jCyHgdH6JO3/OPeJ9QyJFfKvli4h9xPioFJGTdbgw83SJFwL Iv2LpjgK+ZBnynffulXV1TbKh1NBf6ABivUHTDuzpTkeRsdMojdMpFAuZ1ANCv5iQeJl +QHsGZw7THv4yQzDDznQkLFxcQYz05YfnzksxrZc1FU9rf5AigzmnWLktV/HR/nHQxl/ DirVyVl8wfGHCzmRrb6xIVhhfj7f5fmwcl5/UucJzACsmnjm4Wv2z/YYIKJuv8GMnl9L RU10xktvecONVORvDfJbV+fJuY9pIl5fkiEPjanwjeeSyEMpUJXxPK9cSm/IAfTsMsW9 /NWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/alk5dhNog11lYeAdIDLuwiTsPArXCiZibQ+tOSdZPs=; b=GXkN0MbEZd2ajJeHspIWGqGlk2t27TbLmIIsvix4a+Zt7dQirNTs0qrZsDJTVELLIz qferbL+IC/yIwO0Af1tzLhKToRCpl/aAuUVal6eWU0FbJ8TZ1nSK4JzE5zG3YbrO79HJ KQKYU/iumeawV4zDvb+s8/WANZzumD1wgx8WPrti/cvI5r5B9xx3m9kmE7i1CNhbB9dN wxMGvxJQnbvfntirF0HrbOC/Sxd1yPdDRTFLkW42diX8BZw/+gtdkUdHopyjQcegCRia qiepjEmzpSwIDbgwVGMap/KPNzw2QSgKiyn70GKS0WYF0g3L9kihnENubRPaceUd2K3k P4hA== X-Gm-Message-State: AOAM531GkmEOSAkl9FAa84ahoBiPYlx7lo+p4/B8CGRQWap24Linh+w0 EusvWWYxySPI/6qwGbaXPR54aXxG5EJehpQRDkA= X-Google-Smtp-Source: ABdhPJzp4wMmU27mhuwTJfOHqtOfRhc+HgOvfNmyg3sqe5eywMrHHbqRboT7E/WEOXTtruaHC0zLCw== X-Received: by 2002:a92:db06:: with SMTP id b6mr265511iln.305.1631051640002; Tue, 07 Sep 2021 14:54:00 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 24/42] bsd-user: Create target specific vmparam.h Date: Tue, 7 Sep 2021 15:53:14 -0600 Message-Id: <20210907215332.30737-25-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::142; envelope-from=imp@bsdimp.com; helo=mail-il1-x142.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052948893100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Target specific values for vm parameters and details. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/target_os_vmparam.h | 38 ++++++++++++++++++++++ bsd-user/i386/target_arch_vmparam.h | 46 +++++++++++++++++++++++++++ bsd-user/qemu.h | 1 + bsd-user/x86_64/target_arch_vmparam.h | 46 +++++++++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 bsd-user/freebsd/target_os_vmparam.h create mode 100644 bsd-user/i386/target_arch_vmparam.h create mode 100644 bsd-user/x86_64/target_arch_vmparam.h diff --git a/bsd-user/freebsd/target_os_vmparam.h b/bsd-user/freebsd/target= _os_vmparam.h new file mode 100644 index 0000000000..990300c619 --- /dev/null +++ b/bsd-user/freebsd/target_os_vmparam.h @@ -0,0 +1,38 @@ +/* + * FreeBSD VM parameters definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_OS_VMPARAM_H_ +#define _TARGET_OS_VMPARAM_H_ + +#include "target_arch_vmparam.h" + +/* Compare to sys/exec.h */ +struct target_ps_strings { + abi_ulong ps_argvstr; + uint32_t ps_nargvstr; + abi_ulong ps_envstr; + uint32_t ps_nenvstr; +}; + +extern abi_ulong target_stkbas; +extern abi_ulong target_stksiz; + +#define TARGET_PS_STRINGS ((target_stkbas + target_stksiz) - \ + sizeof(struct target_ps_strings)) + +#endif /* !TARGET_OS_VMPARAM_H_ */ diff --git a/bsd-user/i386/target_arch_vmparam.h b/bsd-user/i386/target_arc= h_vmparam.h new file mode 100644 index 0000000000..bb7718265b --- /dev/null +++ b/bsd-user/i386/target_arch_vmparam.h @@ -0,0 +1,46 @@ +/* + * i386 VM parameters definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_ARCH_VMPARAM_H_ +#define _TARGET_ARCH_VMPARAM_H_ + +#include "cpu.h" + +/* compare to i386/include/vmparam.h */ +#define TARGET_MAXTSIZ (128 * MiB) /* max text size */ +#define TARGET_DFLDSIZ (128 * MiB) /* initial data size limit= */ +#define TARGET_MAXDSIZ (512 * MiB) /* max data size */ +#define TARGET_DFLSSIZ (8 * MiB) /* initial stack size limi= t */ +#define TARGET_MAXSSIZ (64 * MiB) /* max stack size */ +#define TARGET_SGROWSIZ (128 * KiB) /* amount to grow stack */ + +#define TARGET_RESERVED_VA 0xf7000000 + +#define TARGET_USRSTACK (0xbfc00000) + +static inline abi_ulong get_sp_from_cpustate(CPUX86State *state) +{ + return state->regs[R_ESP]; +} + +static inline void set_second_rval(CPUX86State *state, abi_ulong retval2) +{ + state->regs[R_EDX] =3D retval2; +} + +#endif /* !_TARGET_ARCH_VMPARAM_H_ */ diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index fea1a167e4..1b37757e06 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -41,6 +41,7 @@ extern enum BSDType bsd_type; #include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h" +#include "target_os_vmparam.h" #include "exec/gdbstub.h" =20 /* diff --git a/bsd-user/x86_64/target_arch_vmparam.h b/bsd-user/x86_64/target= _arch_vmparam.h new file mode 100644 index 0000000000..81a915f2e5 --- /dev/null +++ b/bsd-user/x86_64/target_arch_vmparam.h @@ -0,0 +1,46 @@ +/* + * Intel x86_64 VM parameters definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_ARCH_VMPARAM_H_ +#define _TARGET_ARCH_VMPARAM_H_ + +#include "cpu.h" + +/* compare to amd64/include/vmparam.h */ +#define TARGET_MAXTSIZ (128 * MiB) /* max text size */ +#define TARGET_DFLDSIZ (32 * GiB) /* initial data size limit= */ +#define TARGET_MAXDSIZ (32 * GiB) /* max data size */ +#define TARGET_DFLSSIZ (8 * MiB) /* initial stack size limi= t */ +#define TARGET_MAXSSIZ (512 * MiB) /* max stack size */ +#define TARGET_SGROWSIZ (128 * KiB) /* amount to grow stack */ + +#define TARGET_VM_MAXUSER_ADDRESS (0x00007fffff000000UL) + +#define TARGET_USRSTACK (TARGET_VM_MAXUSER_ADDRESS - TARGET_PAGE_SIZE) + +static inline abi_ulong get_sp_from_cpustate(CPUX86State *state) +{ + return state->regs[R_ESP]; +} + +static inline void set_second_rval(CPUX86State *state, abi_ulong retval2) +{ + state->regs[R_EDX] =3D retval2; +} + +#endif /* !_TARGET_ARCH_VMPARAM_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052502141244.16652238751362; Tue, 7 Sep 2021 15:08:22 -0700 (PDT) Received: from localhost ([::1]:39330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjGP-0000XO-4F for importer@patchew.org; Tue, 07 Sep 2021 18:08:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2Z-0005uP-Rz for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:04 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:39473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2X-0000zh-SL for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:03 -0400 Received: by mail-io1-xd42.google.com with SMTP id m11so459417ioo.6 for ; Tue, 07 Sep 2021 14:54:01 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sA5QHzmZM8n6t08NS5xsgqcfTBm3Za7WlXfug3IWldc=; b=ftMhVQgIyBdwld+I8He1yn9HaP2xFO0IKa/GLOpf8D0UhXpOeuXHukj0DcmVOSMz35 ildbyu4F03yRFFGB0ZWiH/qJdbCYQiIC/GTLOjj8ETbqH9lsrUlngFlG88InsaAL+oXy wqgr+8r3V/YDj5v8hUBEKLHdCUOf5Uuk2Qe0WkxSeU8A2DLtugmqfn+1vpIX/jtL0y3u wqJCRLIusvYricUdlw7ebNWPOBcJArS42mZfGkXVnJ4h7ZrT0O1ofz4p9FaROOg4PLh+ 7zcToHPF/AMNBdJmASiKbybp+W9j4epmfeWOoPGZ/HJd0aF79Xsrxqp+UXV6Q5oXMVI8 IMrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sA5QHzmZM8n6t08NS5xsgqcfTBm3Za7WlXfug3IWldc=; b=t7gUE3fFDtD+M82AOwIBkLw2VK4YLwkII3iS1fknCD6wsvnDF9pUyyKENGGlKb0kby Hjb6xfiRQtp2GBxr1xXbZ3EMvytJgV76fSfiOpmQm/35GYyxJuDYVk6uT/MahhtJrkNF Kdp3UNIdFPgQQNrtfygjOzI3OkQ7sY5wXaYEaF2WPV1I3O0iuBXpqC5TCF0fZPMA+dHa pixzzrm1xVR5ibH6rzFnMHXTBDwgTpfGHZqPcxKDWy9nHtILNZg4NnzLJlYJ88P4nIWe JMs/waqbyjOzrjseNjPqIfvg1CkomD8hVD4NT525QVPfpN4Q6lRRFkogSjm/tPWpTAX7 OcbQ== X-Gm-Message-State: AOAM530jsV3wvV0+xHuyXRHbUGz7mCMq7wxj/ExBnnOluq4k5pHHi01E CvXRBntHNtcNN54z2C5g+5q5D4A7s0LDnXuo8D8= X-Google-Smtp-Source: ABdhPJx4r57MNhpmoH/zkRw6YIeaoJDgfjrqFvI6AMvoa0qTpZ1DbBctdygyGwEpQtIvBRSP1yTQdA== X-Received: by 2002:a05:6638:1491:: with SMTP id j17mr434385jak.75.1631051640716; Tue, 07 Sep 2021 14:54:00 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 25/42] bsd-user: Add system independent stack, data and text limiting Date: Tue, 7 Sep 2021 15:53:15 -0600 Message-Id: <20210907215332.30737-26-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d42; envelope-from=imp@bsdimp.com; helo=mail-io1-xd42.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052504123100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Eliminate the x86 specific stack stuff in favor of more generic control over the process size: target_maxtsiz max text size target_dfldsiz initial data size limit target_maxdsiz max data size target_dflssiz initial stack size limit target_maxssiz max stack size target_sgrowsiz amount to grow stack These can be set on a per-arch basis, and the stack size can be set on the command line. Adjust the stack size parameters at startup. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 2 +- bsd-user/main.c | 52 +++++++++++++++++++++++++++++++++------------- bsd-user/qemu.h | 7 ++++++- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index c28ef34143..59465b71d4 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -204,7 +204,7 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct bs= d_binprm *bprm, /* Create enough stack to hold everything. If we don't use * it for args, we'll use it for something else... */ - size =3D x86_stack_size; + size =3D target_dflssiz; if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE) size =3D MAX_ARG_PAGES * TARGET_PAGE_SIZE; error =3D target_mmap(0, diff --git a/bsd-user/main.c b/bsd-user/main.c index 3d4ed202a0..19bf3a09a7 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -18,6 +18,11 @@ * along with this program; if not, see . */ =20 +#include +#include +#include +#include + #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/units.h" @@ -44,8 +49,6 @@ #include "host-os.h" #include "target_arch_cpu.h" =20 -#include - int singlestep; unsigned long mmap_min_addr; uintptr_t guest_base; @@ -57,12 +60,12 @@ const char *qemu_uname_release; enum BSDType bsd_type; char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */ =20 -/* - * XXX: on x86 MAP_GROWSDOWN only works if ESP <=3D address + 32, so - * we allocate a bigger stack. Need a better solution, for example - * by remapping the process stack directly at the right place - */ -unsigned long x86_stack_size =3D 512 * 1024; +unsigned long target_maxtsiz =3D TARGET_MAXTSIZ; /* max text size */ +unsigned long target_dfldsiz =3D TARGET_DFLDSIZ; /* initial data size li= mit */ +unsigned long target_maxdsiz =3D TARGET_MAXDSIZ; /* max data size */ +unsigned long target_dflssiz =3D TARGET_DFLSSIZ; /* initial data size li= mit */ +unsigned long target_maxssiz =3D TARGET_MAXSSIZ; /* max stack size */ +unsigned long target_sgrowsiz =3D TARGET_SGROWSIZ; /* amount to grow stack= */ =20 void gemu_log(const char *fmt, ...) { @@ -112,7 +115,6 @@ static void usage(void) "-d item1[,...] enable logging of specified items\n" " (use '-d help' for a list of log items)\n" "-D logfile write logs to 'logfile' (default stderr)\n" - "-p pagesize set the host page size to 'pagesize'\n" "-singlestep always run in singlestep mode\n" "-strace log system calls\n" "-trace [[enable=3D]][,events=3D][,fi= le=3D]\n" @@ -132,7 +134,7 @@ static void usage(void) , TARGET_NAME, interp_prefix, - x86_stack_size); + target_dflssiz); exit(1); } =20 @@ -161,6 +163,23 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next =3D NULL; } =20 +static void +adjust_ssize(void) +{ + struct rlimit rl; + + if (getrlimit(RLIMIT_STACK, &rl) !=3D 0) { + return; + } + + target_maxssiz =3D MIN(target_maxssiz, rl.rlim_max); + target_dflssiz =3D MIN(MAX(target_dflssiz, rl.rlim_cur), target_maxssi= z); + + rl.rlim_max =3D target_maxssiz; + rl.rlim_cur =3D target_dflssiz; + setrlimit(RLIMIT_STACK, &rl); +} + static void save_proc_pathname(char *argv0) { int mib[4]; @@ -197,6 +216,8 @@ int main(int argc, char **argv) envlist_t *envlist =3D NULL; bsd_type =3D HOST_DEFAULT_BSD_TYPE; =20 + adjust_ssize(); + if (argc <=3D 1) { usage(); } @@ -257,14 +278,17 @@ int main(int argc, char **argv) } } else if (!strcmp(r, "s")) { r =3D argv[optind++]; - rv =3D qemu_strtoul(r, &r, 0, &x86_stack_size); - if (rv < 0 || x86_stack_size <=3D 0) { + rv =3D qemu_strtoul(r, &r, 0, &target_dflssiz); + if (rv < 0 || target_dflssiz <=3D 0) { usage(); } if (*r =3D=3D 'M') { - x86_stack_size *=3D MiB; + target_dflssiz *=3D 1024 * 1024; } else if (*r =3D=3D 'k' || *r =3D=3D 'K') { - x86_stack_size *=3D KiB; + target_dflssiz *=3D 1024; + } + if (target_dflssiz > target_maxssiz) { + usage(); } } else if (!strcmp(r, "L")) { interp_prefix =3D argv[optind++]; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 1b37757e06..21efa7d777 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -219,7 +219,12 @@ void mmap_fork_end(int child); =20 /* main.c */ extern char qemu_proc_pathname[]; -extern unsigned long x86_stack_size; +extern unsigned long target_maxtsiz; +extern unsigned long target_dfldsiz; +extern unsigned long target_maxdsiz; +extern unsigned long target_dflssiz; +extern unsigned long target_maxssiz; +extern unsigned long target_sgrowsiz; =20 /* user access */ =20 --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053281674442.2402707526171; Tue, 7 Sep 2021 15:21:21 -0700 (PDT) Received: from localhost ([::1]:46000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjSy-0007ZV-Hs for importer@patchew.org; Tue, 07 Sep 2021 18:21:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2f-00060v-1U for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:09 -0400 Received: from mail-il1-x144.google.com ([2607:f8b0:4864:20::144]:37824) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2Z-00010i-MM for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:08 -0400 Received: by mail-il1-x144.google.com with SMTP id i13so173684ilm.4 for ; Tue, 07 Sep 2021 14:54:03 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ja4NleW1T9pWkVlrgBpTYndoQ+8tFJoJqwwFIeXzY0A=; b=ogB/1exBIf3Pz35HDTsVOj36iQI4OeNRGSK7H95DjzMufo3sqryrV0jo7jloKB5uqY 8tkOsp8UYswnaE/JK2FpMBxoZiqaJQ0DvX2ceHNWqGxjduHgHnoBhtR2IzSueHEwScNB CypGJz5UIIKJRN8qTHcEXJ1UC0kQizNsLOuqvflGPXGniYIU/r6s4rP5DBQ+Mhg3RF0u RuZpU6ZFcrkXGo+4cluU1Yfpol/4K6RqcR5GeIQ74mz/POC6yNLgCBN/aIRY6OpJ7MzG ITnP/cSRGxbmG1v4xRE7jWd8CL9XnFhaII4dutEcSTitrdVIMkTBUvmv7odWJXEWjuP8 NKmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ja4NleW1T9pWkVlrgBpTYndoQ+8tFJoJqwwFIeXzY0A=; b=UgWy+hsGUAMZ3xSS+D5TQLTrO/wY+GzWRh3c1ayiTLFylsiTm9/BWhGxge7Spjpscc LE8AkoDWi9D9+nBqeJ4iOuXNB/lcPaFqlD83/hE28B1h+MJJhvk4qqNzay3XrdDrPHo8 aoGK1OX1Daxp6kVVQ37sgEHAv07nUP4JOOkHwWzZQ3/OMyO7Av9mvEyBfH+wNk3ruR0r b+OquopG6Uwaqxeg5lO4gmil4O9dE2ResZk65ZdoQne0CTEh/B9xwj357TGWWzba8u+a 1sRrWDwkIemgB3On1ski8RxUQ+bDvUQiK5UWmoGR5OtqrlqoQpwEinJUwuoLWZiRXQ05 0Epw== X-Gm-Message-State: AOAM532PKYIqGmGp5QYEW0cx+4wx468jKOXCsKz2HDS0dFgSAnGVHgGy 2gAQQHuo69TPnIuPYnwvraiL3Agw/K2fSfacjXc= X-Google-Smtp-Source: ABdhPJyKP8SQ9NWS5TeR7s6EzaEJdWUqcaoIXm154HvwfPuBJIavAsk2jedI530QhjPugGx3vVyCLA== X-Received: by 2002:a05:6e02:928:: with SMTP id o8mr267809ilt.37.1631051641912; Tue, 07 Sep 2021 14:54:01 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 26/42] bsd-user: *BSD specific siginfo defintions Date: Tue, 7 Sep 2021 15:53:16 -0600 Message-Id: <20210907215332.30737-27-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::144; envelope-from=imp@bsdimp.com; helo=mail-il1-x144.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053281935100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Add FreeBSD, NetBSD and OpenBSD values for the various signal info types and defines to decode different signals to discover more information about the specific signal types. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/freebsd/target_os_siginfo.h | 145 +++++++++++++++++++++++++++ bsd-user/freebsd/target_os_signal.h | 78 ++++++++++++++ bsd-user/i386/target_arch_signal.h | 94 +++++++++++++++++ bsd-user/netbsd/target_os_siginfo.h | 82 +++++++++++++++ bsd-user/netbsd/target_os_signal.h | 69 +++++++++++++ bsd-user/openbsd/target_os_siginfo.h | 82 +++++++++++++++ bsd-user/openbsd/target_os_signal.h | 69 +++++++++++++ bsd-user/qemu.h | 1 + bsd-user/syscall_defs.h | 10 -- bsd-user/x86_64/target_arch_signal.h | 94 +++++++++++++++++ 10 files changed, 714 insertions(+), 10 deletions(-) create mode 100644 bsd-user/freebsd/target_os_siginfo.h create mode 100644 bsd-user/freebsd/target_os_signal.h create mode 100644 bsd-user/i386/target_arch_signal.h create mode 100644 bsd-user/netbsd/target_os_siginfo.h create mode 100644 bsd-user/netbsd/target_os_signal.h create mode 100644 bsd-user/openbsd/target_os_siginfo.h create mode 100644 bsd-user/openbsd/target_os_signal.h create mode 100644 bsd-user/x86_64/target_arch_signal.h diff --git a/bsd-user/freebsd/target_os_siginfo.h b/bsd-user/freebsd/target= _os_siginfo.h new file mode 100644 index 0000000000..84944faa4d --- /dev/null +++ b/bsd-user/freebsd/target_os_siginfo.h @@ -0,0 +1,145 @@ +/* + * FreeBSD siginfo related definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_OS_SIGINFO_H_ +#define _TARGET_OS_SIGINFO_H_ + +#define TARGET_NSIG 128 +#define TARGET_NSIG_BPW (sizeof(uint32_t) * 8) +#define TARGET_NSIG_WORDS (TARGET_NSIG / TARGET_NSIG_BPW) + +/* this struct defines a stack used during syscall handling */ +typedef struct target_sigaltstack { + abi_long ss_sp; + abi_ulong ss_size; + abi_long ss_flags; +} target_stack_t; + +typedef struct { + uint32_t __bits[TARGET_NSIG_WORDS]; +} target_sigset_t; + +struct target_sigaction { + abi_ulong _sa_handler; + int32_t sa_flags; + target_sigset_t sa_mask; +}; + +typedef union target_sigval { + int32_t sival_int; + abi_ulong sival_ptr; + int32_t sigval_int; + abi_ulong sigval_ptr; +} target_sigval_t; + +typedef struct target_siginfo { + int32_t si_signo; /* signal number */ + int32_t si_errno; /* errno association */ + int32_t si_code; /* signal code */ + int32_t si_pid; /* sending process */ + int32_t si_uid; /* sender's ruid */ + int32_t si_status; /* exit value */ + abi_ulong si_addr; /* faulting instruction */ + union target_sigval si_value; /* signal value */ + union { + struct { + int32_t _trapno; /* machine specific trap code */ + } _fault; + + /* POSIX.1b timers */ + struct { + int32_t _timerid; + int32_t _overrun; + } _timer; + + struct { + int32_t _mqd; + } _mesgp; + + /* SIGPOLL */ + struct { + int _band; /* POLL_IN, POLL_OUT, POLL_MSG */ + } _poll; + + struct { + abi_long __spare1__; + int32_t __spare2_[7]; + } __spare__; + } _reason; +} target_siginfo_t; + +struct target_sigevent { + abi_int sigev_notify; + abi_int sigev_signo; + target_sigval_t sigev_value; + union { + abi_int _threadid; + + /* + * The kernel (and thus QEMU) never looks at these; + * they're only used as part of the ABI between a + * userspace program and libc. + */ + struct { + abi_ulong _function; + abi_ulong _attribute; + } _sigev_thread; + abi_ushort _kevent_flags; + abi_long _pad[8]; + } _sigev_un; +}; + +#define target_si_signo si_signo +#define target_si_code si_code +#define target_si_errno si_errno +#define target_si_addr si_addr + +/* SIGILL si_codes */ +#define TARGET_ILL_ILLOPC (1) /* Illegal opcode. */ +#define TARGET_ILL_ILLOPN (2) /* Illegal operand. */ +#define TARGET_ILL_ILLADR (3) /* Illegal addressing mode. */ +#define TARGET_ILL_ILLTRP (4) /* Illegal trap. */ +#define TARGET_ILL_PRVOPC (5) /* Privileged opcode. */ +#define TARGET_ILL_PRVREG (6) /* Privileged register. */ +#define TARGET_ILL_COPROC (7) /* Coprocessor error. */ +#define TARGET_ILL_BADSTK (8) /* Internal stack error. */ + +/* SIGSEGV si_codes */ +#define TARGET_SEGV_MAPERR (1) /* address not mapped to object */ +#define TARGET_SEGV_ACCERR (2) /* invalid permissions for mapped object */ + +/* SIGTRAP si_codes */ +#define TARGET_TRAP_BRKPT (1) /* process beakpoint */ +#define TARGET_TRAP_TRACE (2) /* process trace trap */ + +/* SIGBUS si_codes */ +#define TARGET_BUS_ADRALN (1) +#define TARGET_BUS_ADRERR (2) +#define TARGET_BUS_OBJERR (3) + +/* SIGFPE codes */ +#define TARGET_FPE_INTOVF (1) /* Integer overflow. */ +#define TARGET_FPE_INTDIV (2) /* Integer divide by zero. */ +#define TARGET_FPE_FLTDIV (3) /* Floating point divide by zero. */ +#define TARGET_FPE_FLTOVF (4) /* Floating point overflow. */ +#define TARGET_FPE_FLTUND (5) /* Floating point underflow. */ +#define TARGET_FPE_FLTRES (6) /* Floating point inexact result. */ +#define TARGET_FPE_FLTINV (7) /* Invalid floating point operation. */ +#define TARGET_FPE_FLTSUB (8) /* Subscript out of range. */ + +#endif /* !_TARGET_OS_SIGINFO_H_ */ diff --git a/bsd-user/freebsd/target_os_signal.h b/bsd-user/freebsd/target_= os_signal.h new file mode 100644 index 0000000000..3ed454e086 --- /dev/null +++ b/bsd-user/freebsd/target_os_signal.h @@ -0,0 +1,78 @@ +#ifndef _TARGET_OS_SIGNAL_H_ +#define _TARGET_OS_SIGNAL_H_ + +#include "target_os_siginfo.h" +#include "target_arch_signal.h" + +/* Compare to sys/signal.h */ +#define TARGET_SIGHUP 1 /* hangup */ +#define TARGET_SIGINT 2 /* interrupt */ +#define TARGET_SIGQUIT 3 /* quit */ +#define TARGET_SIGILL 4 /* illegal instruction (not reset when caug= ht) */ +#define TARGET_SIGTRAP 5 /* trace trap (not reset when caught) */ +#define TARGET_SIGABRT 6 /* abort() */ +#define TARGET_SIGIOT SIGABRT /* compatibility */ +#define TARGET_SIGEMT 7 /* EMT instruction */ +#define TARGET_SIGFPE 8 /* floating point exception */ +#define TARGET_SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define TARGET_SIGBUS 10 /* bus error */ +#define TARGET_SIGSEGV 11 /* segmentation violation */ +#define TARGET_SIGSYS 12 /* bad argument to system call */ +#define TARGET_SIGPIPE 13 /* write on a pipe with no one to read it */ +#define TARGET_SIGALRM 14 /* alarm clock */ +#define TARGET_SIGTERM 15 /* software termination signal from kill */ +#define TARGET_SIGURG 16 /* urgent condition on IO channel */ +#define TARGET_SIGSTOP 17 /* sendable stop signal not from tty */ +#define TARGET_SIGTSTP 18 /* stop signal from tty */ +#define TARGET_SIGCONT 19 /* continue a stopped process */ +#define TARGET_SIGCHLD 20 /* to parent on child stop or exit */ +#define TARGET_SIGTTIN 21 /* to readers pgrp upon background tty read= */ +#define TARGET_SIGTTOU 22 /* like TTIN for output if(tp->t_local<OS= TOP)*/ +#define TARGET_SIGIO 23 /* input/output possible signal */ +#define TARGET_SIGXCPU 24 /* exceeded CPU time limit */ +#define TARGET_SIGXFSZ 25 /* exceeded file size limit */ +#define TARGET_SIGVTALRM 26 /* virtual time alarm */ +#define TARGET_SIGPROF 27 /* profiling time alarm */ +#define TARGET_SIGWINCH 28 /* window size changes */ +#define TARGET_SIGINFO 29 /* information request */ +#define TARGET_SIGUSR1 30 /* user defined signal 1 */ +#define TARGET_SIGUSR2 31 /* user defined signal 2 */ +#define TARGET_SIGTHR 32 /* reserved by thread library */ +#define TARGET_SIGLWP SIGTHR /* compatibility */ +#define TARGET_SIGLIBRT 33 /* reserved by the real-time library */ +#define TARGET_SIGRTMIN 65 +#define TARGET_SIGRTMAX 126 + +/* + * Language spec says we must list exactly one parameter, even though we + * actually supply three. Ugh! + */ +#define TARGET_SIG_DFL ((abi_long)0) /* default signal handling */ +#define TARGET_SIG_IGN ((abi_long)1) /* ignore signal */ +#define TARGET_SIG_ERR ((abi_long)-1) /* error return from signal */ + +#define TARGET_SA_ONSTACK 0x0001 /* take signal on signal stack */ +#define TARGET_SA_RESTART 0x0002 /* restart system on signal return */ +#define TARGET_SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal= */ +#define TARGET_SA_NODEFER 0x0010 /* don't mask the signal we're deliver= ing */ +#define TARGET_SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to pid= 1) */ +#define TARGET_SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp= */ +#define TARGET_SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child st= op */ +#define TARGET_SA_SIGINFO 0x0040 /* generate siginfo_t */ + +/* + * Flags for sigprocmask: + */ +#define TARGET_SIG_BLOCK 1 /* block specified signal set */ +#define TARGET_SIG_UNBLOCK 2 /* unblock specified signal set */ +#define TARGET_SIG_SETMASK 3 /* set specified signal set */ + +#define TARGET_BADSIG SIG_ERR + +/* + * sigaltstack control + */ +#define TARGET_SS_ONSTACK 0x0001 /* take signals on alternate stack */ +#define TARGET_SS_DISABLE 0x0004 /* disable taking signals on alternate s= tack*/ + +#endif /* !_TARGET_OS_SIGNAL_H_ */ diff --git a/bsd-user/i386/target_arch_signal.h b/bsd-user/i386/target_arch= _signal.h new file mode 100644 index 0000000000..9812c6b034 --- /dev/null +++ b/bsd-user/i386/target_arch_signal.h @@ -0,0 +1,94 @@ +/* + * i386 dependent signal definitions + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef TARGET_ARCH_SIGNAL_H +#define TARGET_ARCH_SIGNAL_H + +#include "cpu.h" + +/* Size of the signal trampolin code placed on the stack. */ +#define TARGET_SZSIGCODE 0 + +/* compare to x86/include/_limits.h */ +#define TARGET_MINSIGSTKSZ (512 * 4) /* min sig stack size = */ +#define TARGET_SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended size */ + +#define TARGET_MC_GET_CLEAR_RET 0x0001 + +struct target_sigcontext { + /* to be added */ +}; + +typedef struct target_mcontext { +} target_mcontext_t; + +typedef struct target_ucontext { + target_sigset_t uc_sigmask; + target_mcontext_t uc_mcontext; + abi_ulong uc_link; + target_stack_t uc_stack; + int32_t uc_flags; + int32_t __spare__[4]; +} target_ucontext_t; + +struct target_sigframe { + abi_ulong sf_signum; + abi_ulong sf_siginfo; /* code or pointer to sf_si */ + abi_ulong sf_ucontext; /* points to sf_uc */ + abi_ulong sf_addr; /* undocumented 4th arg */ + target_ucontext_t sf_uc; /* =3D *sf_uncontext */ + target_siginfo_t sf_si; /* =3D *sf_siginfo (SA_SIGINFO case)*/ + uint32_t __spare__[2]; +}; + +/* + * Compare to i386/i386/machdep.c sendsig() + * Assumes that target stack frame memory is locked. + */ +static inline abi_long set_sigtramp_args(CPUX86State *regs, + int sig, struct target_sigframe *frame, abi_ulong frame_addr, + struct target_sigaction *ka) +{ + /* XXX return -TARGET_EOPNOTSUPP; */ + return 0; +} + +/* Compare to i386/i386/machdep.c get_mcontext() */ +static inline abi_long get_mcontext(CPUX86State *regs, + target_mcontext_t *mcp, int flags) +{ + /* XXX */ + return -TARGET_EOPNOTSUPP; +} + +/* Compare to i386/i386/machdep.c set_mcontext() */ +static inline abi_long set_mcontext(CPUX86State *regs, + target_mcontext_t *mcp, int srflag) +{ + /* XXX */ + return -TARGET_EOPNOTSUPP; +} + +static inline abi_long get_ucontext_sigreturn(CPUX86State *regs, + abi_ulong target_sf, abi_ulong *target_uc) +{ + /* XXX */ + *target_uc =3D 0; + return -TARGET_EOPNOTSUPP; +} + +#endif /* TARGET_ARCH_SIGNAL_H */ diff --git a/bsd-user/netbsd/target_os_siginfo.h b/bsd-user/netbsd/target_o= s_siginfo.h new file mode 100644 index 0000000000..667c19cc7c --- /dev/null +++ b/bsd-user/netbsd/target_os_siginfo.h @@ -0,0 +1,82 @@ +#ifndef _TARGET_OS_SIGINFO_H_ +#define _TARGET_OS_SIGINFO_H_ + +#define TARGET_NSIG 32 /* counting 0; could be 33 (mask is 1-32) */ +#define TARGET_NSIG_BPW (sizeof(uint32_t) * 8) +#define TARGET_NSIG_WORDS (TARGET_NSIG / TARGET_NSIG_BPW) + +/* this struct defines a stack used during syscall handling */ +typedef struct target_sigaltstack { + abi_long ss_sp; + abi_ulong ss_size; + abi_long ss_flags; +} target_stack_t; + +typedef struct { + uint32_t __bits[TARGET_NSIG_WORDS]; +} target_sigset_t + +struct target_sigaction { + abi_ulong _sa_handler; + int32_t sa_flags; + target_sigset_t sa_mask; +}; + +/* Compare to sys/siginfo.h */ +typedef union target_sigval { + int sival_int; + abi_ulong sival_ptr; +} target_sigval_t; + +struct target_ksiginfo { + int32_t _signo; + int32_t _code; + int32_t _errno; +#if TARGET_ABI_BITS =3D=3D 64 + int32_t _pad; +#endif + union { + struct { + int32_t _pid; + int32_t _uid; + target_sigval_t _value; + } _rt; + + struct { + int32_t _pid; + int32_t _uid; + int32_t _struct; + /* clock_t _utime; */ + /* clock_t _stime; */ + } _child; + + struct { + abi_ulong _addr; + int32_t _trap; + } _fault; + + struct { + long _band; + int _fd; + } _poll; + } _reason; +}; + +typedef union target_siginfo { + int8_t si_pad[128]; + struct target_ksiginfo _info; +} target_siginfo_t; + +#define target_si_signo _info._signo +#define target_si_code _info._code +#define target_si_errno _info._errno +#define target_si_addr _info._reason._fault._addr + +#define TARGET_SEGV_MAPERR 1 +#define TARGET_SEGV_ACCERR 2 + +#define TARGET_TRAP_BRKPT 1 +#define TARGET_TRAP_TRACE 2 + + +#endif /* ! _TARGET_OS_SIGINFO_H_ */ diff --git a/bsd-user/netbsd/target_os_signal.h b/bsd-user/netbsd/target_os= _signal.h new file mode 100644 index 0000000000..a373922f7e --- /dev/null +++ b/bsd-user/netbsd/target_os_signal.h @@ -0,0 +1,69 @@ +#ifndef _TARGET_OS_SIGNAL_H_ +#define _TARGET_OS_SIGNAL_H_ + +#include "target_os_siginfo.h" +#include "target_arch_signal.h" + +#define TARGET_SIGHUP 1 /* hangup */ +#define TARGET_SIGINT 2 /* interrupt */ +#define TARGET_SIGQUIT 3 /* quit */ +#define TARGET_SIGILL 4 /* illegal instruction (not reset when caug= ht) */ +#define TARGET_SIGTRAP 5 /* trace trap (not reset when caught) */ +#define TARGET_SIGABRT 6 /* abort() */ +#define TARGET_SIGIOT SIGABRT /* compatibility */ +#define TARGET_SIGEMT 7 /* EMT instruction */ +#define TARGET_SIGFPE 8 /* floating point exception */ +#define TARGET_SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define TARGET_SIGBUS 10 /* bus error */ +#define TARGET_SIGSEGV 11 /* segmentation violation */ +#define TARGET_SIGSYS 12 /* bad argument to system call */ +#define TARGET_SIGPIPE 13 /* write on a pipe with no one to read it */ +#define TARGET_SIGALRM 14 /* alarm clock */ +#define TARGET_SIGTERM 15 /* software termination signal from kill */ +#define TARGET_SIGURG 16 /* urgent condition on IO channel */ +#define TARGET_SIGSTOP 17 /* sendable stop signal not from tty */ +#define TARGET_SIGTSTP 18 /* stop signal from tty */ +#define TARGET_SIGCONT 19 /* continue a stopped process */ +#define TARGET_SIGCHLD 20 /* to parent on child stop or exit */ +#define TARGET_SIGTTIN 21 /* to readers pgrp upon background tty read= */ +#define TARGET_SIGTTOU 22 /* like TTIN for out if (tp->t_local<OSTO= P) */ +#define TARGET_SIGIO 23 /* input/output possible signal */ +#define TARGET_SIGXCPU 24 /* exceeded CPU time limit */ +#define TARGET_SIGXFSZ 25 /* exceeded file size limit */ +#define TARGET_SIGVTALRM 26 /* virtual time alarm */ +#define TARGET_SIGPROF 27 /* profiling time alarm */ +#define TARGET_SIGWINCH 28 /* window size changes */ +#define TARGET_SIGINFO 29 /* information request */ +#define TARGET_SIGUSR1 30 /* user defined signal 1 */ +#define TARGET_SIGUSR2 31 /* user defined signal 2 */ + +/* + * Language spec says we must list exactly one parameter, even though we + * actually supply three. Ugh! + */ +#define TARGET_SIG_DFL ((void (*)(int))0) +#define TARGET_SIG_IGN ((void (*)(int))1) +#define TARGET_SIG_ERR ((void (*)(int))-1) + +#define TARGET_SA_ONSTACK 0x0001 /* take signal on signal stack */ +#define TARGET_SA_RESTART 0x0002 /* restart system on signal return */ +#define TARGET_SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal= */ +#define TARGET_SA_NODEFER 0x0010 /* don't mask the signal we're deliver= ing */ +#define TARGET_SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to pid= 1) */ +#define TARGET_SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp= */ +#define TARGET_SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child st= op */ +#define TARGET_SA_SIGINFO 0x0040 /* generate siginfo_t */ + +/* + * Flags for sigprocmask: + */ +#define TARGET_SIG_BLOCK 1 /* block specified signal set */ +#define TARGET_SIG_UNBLOCK 2 /* unblock specified signal set */ +#define TARGET_SIG_SETMASK 3 /* set specified signal set */ + +#define TARGET_BADSIG SIG_ERR + +#define TARGET_SS_ONSTACK 0x0001 /* take signals on alternate stack */ +#define TARGET_SS_DISABLE 0x0004 /* disable taking signals on alternate st= ack */ + +#endif /* !_TARGET_OS_SIGNAL_H_ */ diff --git a/bsd-user/openbsd/target_os_siginfo.h b/bsd-user/openbsd/target= _os_siginfo.h new file mode 100644 index 0000000000..baf646a5ab --- /dev/null +++ b/bsd-user/openbsd/target_os_siginfo.h @@ -0,0 +1,82 @@ +#ifndef _TARGET_OS_SIGINFO_H_ +#define _TARGET_OS_SIGINFO_H_ + +#define TARGET_NSIG 32 /* counting 0; could be 33 (mask is 1-32) */ +#define TARGET_NSIG_BPW (sizeof(uint32_t) * 8) +#define TARGET_NSIG_WORDS (TARGET_NSIG / TARGET_NSIG_BPW) + +/* this struct defines a stack used during syscall handling */ +typedef struct target_sigaltstack { + abi_long ss_sp; + abi_ulong ss_size; + abi_long ss_flags; +} target_stack_t; + +typedef struct { + uint32_t __bits[TARGET_NSIG_WORDS]; +} target_sigset_t + +struct target_sigaction { + abi_ulong _sa_handler; + int32_t sa_flags; + target_sigset_t sa_mask; +}; + +/* Compare to sys/siginfo.h */ +typedef union target_sigval { + int sival_int; + abi_ulong sival_ptr; +} target_sigval_t; + +struct target_ksiginfo { + int32_t _signo; + int32_t _code; + int32_t _errno; +#if TARGET_ABI_BITS =3D=3D 64 + int32_t _pad; +#endif + union { + struct { + int32_t _pid; + int32_t _uid; + target_sigval_t _value; + } _rt; + + struct { + int32_t _pid; + int32_t _uid; + int32_t _struct; + /* clock_t _utime; */ + /* clock_t _stime; */ + } _child; + + struct { + abi_ulong _addr; + int32_t _trap; + } _fault; + + struct { + long _band; + int _fd; + } _poll; + } _reason; +}; + +typedef union target_siginfo { + int8_t si_pad[128]; + struct target_ksiginfo _info; +} target_siginfo_t; + +#define target_si_signo _info._signo +#define target_si_code _info._code +#define target_si_errno _info._errno +#define target_si_addr _info._reason._fault._addr + +#define TARGET_SEGV_MAPERR 1 +#define TARGET_SEGV_ACCERR 2 + +#define TARGET_TRAP_BRKPT 1 +#define TARGET_TRAP_TRACE 2 + + +#endif /* ! _TARGET_OS_SIGINFO_H_ */ diff --git a/bsd-user/openbsd/target_os_signal.h b/bsd-user/openbsd/target_= os_signal.h new file mode 100644 index 0000000000..a373922f7e --- /dev/null +++ b/bsd-user/openbsd/target_os_signal.h @@ -0,0 +1,69 @@ +#ifndef _TARGET_OS_SIGNAL_H_ +#define _TARGET_OS_SIGNAL_H_ + +#include "target_os_siginfo.h" +#include "target_arch_signal.h" + +#define TARGET_SIGHUP 1 /* hangup */ +#define TARGET_SIGINT 2 /* interrupt */ +#define TARGET_SIGQUIT 3 /* quit */ +#define TARGET_SIGILL 4 /* illegal instruction (not reset when caug= ht) */ +#define TARGET_SIGTRAP 5 /* trace trap (not reset when caught) */ +#define TARGET_SIGABRT 6 /* abort() */ +#define TARGET_SIGIOT SIGABRT /* compatibility */ +#define TARGET_SIGEMT 7 /* EMT instruction */ +#define TARGET_SIGFPE 8 /* floating point exception */ +#define TARGET_SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define TARGET_SIGBUS 10 /* bus error */ +#define TARGET_SIGSEGV 11 /* segmentation violation */ +#define TARGET_SIGSYS 12 /* bad argument to system call */ +#define TARGET_SIGPIPE 13 /* write on a pipe with no one to read it */ +#define TARGET_SIGALRM 14 /* alarm clock */ +#define TARGET_SIGTERM 15 /* software termination signal from kill */ +#define TARGET_SIGURG 16 /* urgent condition on IO channel */ +#define TARGET_SIGSTOP 17 /* sendable stop signal not from tty */ +#define TARGET_SIGTSTP 18 /* stop signal from tty */ +#define TARGET_SIGCONT 19 /* continue a stopped process */ +#define TARGET_SIGCHLD 20 /* to parent on child stop or exit */ +#define TARGET_SIGTTIN 21 /* to readers pgrp upon background tty read= */ +#define TARGET_SIGTTOU 22 /* like TTIN for out if (tp->t_local<OSTO= P) */ +#define TARGET_SIGIO 23 /* input/output possible signal */ +#define TARGET_SIGXCPU 24 /* exceeded CPU time limit */ +#define TARGET_SIGXFSZ 25 /* exceeded file size limit */ +#define TARGET_SIGVTALRM 26 /* virtual time alarm */ +#define TARGET_SIGPROF 27 /* profiling time alarm */ +#define TARGET_SIGWINCH 28 /* window size changes */ +#define TARGET_SIGINFO 29 /* information request */ +#define TARGET_SIGUSR1 30 /* user defined signal 1 */ +#define TARGET_SIGUSR2 31 /* user defined signal 2 */ + +/* + * Language spec says we must list exactly one parameter, even though we + * actually supply three. Ugh! + */ +#define TARGET_SIG_DFL ((void (*)(int))0) +#define TARGET_SIG_IGN ((void (*)(int))1) +#define TARGET_SIG_ERR ((void (*)(int))-1) + +#define TARGET_SA_ONSTACK 0x0001 /* take signal on signal stack */ +#define TARGET_SA_RESTART 0x0002 /* restart system on signal return */ +#define TARGET_SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal= */ +#define TARGET_SA_NODEFER 0x0010 /* don't mask the signal we're deliver= ing */ +#define TARGET_SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to pid= 1) */ +#define TARGET_SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp= */ +#define TARGET_SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child st= op */ +#define TARGET_SA_SIGINFO 0x0040 /* generate siginfo_t */ + +/* + * Flags for sigprocmask: + */ +#define TARGET_SIG_BLOCK 1 /* block specified signal set */ +#define TARGET_SIG_UNBLOCK 2 /* unblock specified signal set */ +#define TARGET_SIG_SETMASK 3 /* set specified signal set */ + +#define TARGET_BADSIG SIG_ERR + +#define TARGET_SS_ONSTACK 0x0001 /* take signals on alternate stack */ +#define TARGET_SS_DISABLE 0x0004 /* disable taking signals on alternate st= ack */ + +#endif /* !_TARGET_OS_SIGNAL_H_ */ diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 21efa7d777..3e3bd96cff 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -42,6 +42,7 @@ extern enum BSDType bsd_type; #include "syscall_defs.h" #include "target_syscall.h" #include "target_os_vmparam.h" +#include "target_os_signal.h" #include "exec/gdbstub.h" =20 /* diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index 207ddeecbf..eb7d1da9b0 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -37,8 +37,6 @@ * @(#)signal.h 8.2 (Berkeley) 1/21/94 */ =20 -#define TARGET_NSIG 32 /* counting 0; could be 33 (mask i= s 1-32) */ - #define TARGET_SIGHUP 1 /* hangup */ #define TARGET_SIGINT 2 /* interrupt */ #define TARGET_SIGQUIT 3 /* quit */ @@ -72,14 +70,6 @@ #define TARGET_SIGUSR1 30 /* user defined signal 1 */ #define TARGET_SIGUSR2 31 /* user defined signal 2 */ =20 -/* - * Language spec says we must list exactly one parameter, even though we - * actually supply three. Ugh! - */ -#define TARGET_SIG_DFL (void (*)(int))0 -#define TARGET_SIG_IGN (void (*)(int))1 -#define TARGET_SIG_ERR (void (*)(int))-1 - #define TARGET_SA_ONSTACK 0x0001 /* take signal on signal stack */ #define TARGET_SA_RESTART 0x0002 /* restart system on signal return= */ #define TARGET_SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking si= gnal */ diff --git a/bsd-user/x86_64/target_arch_signal.h b/bsd-user/x86_64/target_= arch_signal.h new file mode 100644 index 0000000000..4c1ff0e5ba --- /dev/null +++ b/bsd-user/x86_64/target_arch_signal.h @@ -0,0 +1,94 @@ +/* + * x86_64 signal definitions + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_ARCH_SIGNAL_H_ +#define _TARGET_ARCH_SIGNAL_H_ + +#include "cpu.h" + +/* Size of the signal trampolin code placed on the stack. */ +#define TARGET_SZSIGCODE 0 + +/* compare to x86/include/_limits.h */ +#define TARGET_MINSIGSTKSZ (512 * 4) /* min sig stack size = */ +#define TARGET_SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended size */ + +#define TARGET_MC_GET_CLEAR_RET 0x0001 + +struct target_sigcontext { + /* to be added */ +}; + +typedef struct target_mcontext { +} target_mcontext_t; + +typedef struct target_ucontext { + target_sigset_t uc_sigmask; + target_mcontext_t uc_mcontext; + abi_ulong uc_link; + target_stack_t uc_stack; + int32_t uc_flags; + int32_t __spare__[4]; +} target_ucontext_t; + +struct target_sigframe { + abi_ulong sf_signum; + abi_ulong sf_siginfo; /* code or pointer to sf_si */ + abi_ulong sf_ucontext; /* points to sf_uc */ + abi_ulong sf_addr; /* undocumented 4th arg */ + target_ucontext_t sf_uc; /* =3D *sf_uncontext */ + target_siginfo_t sf_si; /* =3D *sf_siginfo (SA_SIGINFO case)*/ + uint32_t __spare__[2]; +}; + +/* + * Compare to amd64/amd64/machdep.c sendsig() + * Assumes that target stack frame memory is locked. + */ +static inline abi_long set_sigtramp_args(CPUX86State *regs, + int sig, struct target_sigframe *frame, abi_ulong frame_addr, + struct target_sigaction *ka) +{ + /* XXX return -TARGET_EOPNOTSUPP; */ + return 0; +} + +/* Compare to amd64/amd64/machdep.c get_mcontext() */ +static inline abi_long get_mcontext(CPUX86State *regs, + target_mcontext_t *mcp, int flags) +{ + /* XXX */ + return -TARGET_EOPNOTSUPP; +} + +/* Compare to amd64/amd64/machdep.c set_mcontext() */ +static inline abi_long set_mcontext(CPUX86State *regs, + target_mcontext_t *mcp, int srflag) +{ + /* XXX */ + return -TARGET_EOPNOTSUPP; +} + +static inline abi_long get_ucontext_sigreturn(CPUX86State *regs, + abi_ulong target_sf, abi_ulong *target_uc) +{ + /* XXX */ + *target_uc =3D 0; + return -TARGET_EOPNOTSUPP; +} + +#endif /* !TARGET_ARCH_SIGNAL_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053123462807.3098631521768; Tue, 7 Sep 2021 15:18:43 -0700 (PDT) Received: from localhost ([::1]:39648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjQQ-0003FY-B9 for importer@patchew.org; Tue, 07 Sep 2021 18:18:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2c-0005wv-DK for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:08 -0400 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]:46594) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2a-00010m-C0 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:06 -0400 Received: by mail-io1-xd2a.google.com with SMTP id b200so431221iof.13 for ; Tue, 07 Sep 2021 14:54:03 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oB7YQS6n+Ad0k22+YCJB5aT2A3DAQAm+CIuWvIJbrCw=; b=rZbTopgmmVljBpLNjBKnTGXFmyzXVF3kGEGnZRbCpdOdMZD43t3pkV6OcD3t91mcTg IJyJf3UXODYMcwXpmTG0Y1XIar7dr3A+zo12Sb0gXoHkf407eO9xPYEJrKbnmYKaSkVi lTFOD/4wo+kdGn/gw34IAHDNUp4vUP4ArPU8pUXKpljMHz3orF/Ku6d54rjF2stW6xiq HUFnxks98Rvabes2aj3tv66tnyX3wEYfxmwEBrfBDP4OpXGwEGCN69k/zTmE7Pir7ct2 QzQXwlTNfqfAqJ7tzAOOrcJ7X/1xNqpmdYwG96nNPlTaaPyaDa1LLIAJOByWgsxAG4St y3xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oB7YQS6n+Ad0k22+YCJB5aT2A3DAQAm+CIuWvIJbrCw=; b=N6CstoMrJiCbn8bO5NgdERuiG14Tp3UvoT1mJKGzcm/QRguoknUWlEapjx+I8BlWbH gGiuSEUA6wMsQLugJOv/Nv7DM3104IOpWLEoahtBg/Z+Ik1shvkKtoHplKjt2/fQv+m6 rQUJfODuPgca207ScZfsVUbsDaJ20j8iu+d6QaYaIp8bCoqL4NvJOwgBDZU4lr6BWM1g cGC+1e9K+2w39I6X4gAWCB5q53KZZPXPTVj8PYbWu9d9psDhLwWgNqGJwqaiwCTjGbdS iQJw0v3CUwuL+tb4N203ibIeAdBVZ3wZTlBaRqJfpZ9Ubn5hp+tcAoA1JTNDtp7SGIhy TKfQ== X-Gm-Message-State: AOAM532ECKX8RBhgQHWfBHvGpTGxeBvqqfWFWzjHnrswz2e2FNgmqCwk m3SVby4xGmX6Oi+n1O78p0uEw+X5NWs+OxSMtHI= X-Google-Smtp-Source: ABdhPJycJ19tsVc43CX5uBONGfgq2u+SsjbgG0MOGKL7z2SupcpmDg10TWaMZEbewqDA7bwNAZH+2w== X-Received: by 2002:a02:2b14:: with SMTP id h20mr453472jaa.116.1631051642521; Tue, 07 Sep 2021 14:54:02 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 27/42] bsd-user: Implement --seed and initialize random state Date: Tue, 7 Sep 2021 15:53:17 -0600 Message-Id: <20210907215332.30737-28-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d2a; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053125580100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Copy --seed implementation (translated from linux-user's newer command line scheme to the older one bsd-user still uses). Initialize the randomness with the glib if a specific seed is specified or use the qcrypto library if not. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 19bf3a09a7..71fd9d5aba 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -45,6 +45,8 @@ #include "qemu/cutils.h" #include "exec/log.h" #include "trace/control.h" +#include "crypto/init.h" +#include "qemu/guest-random.h" =20 #include "host-os.h" #include "target_arch_cpu.h" @@ -203,6 +205,7 @@ int main(int argc, char **argv) const char *cpu_type; const char *log_file =3D NULL; const char *log_mask =3D NULL; + const char *seed_optarg =3D NULL; struct target_pt_regs regs1, *regs =3D ®s1; struct image_info info1, *info =3D &info1; struct bsd_binprm bprm; @@ -331,6 +334,8 @@ int main(int argc, char **argv) usage(); } optind++; + } else if (!strcmp(r, "seed")) { + seed_optarg =3D optarg; } else if (!strcmp(r, "singlestep")) { singlestep =3D 1; } else if (!strcmp(r, "strace")) { @@ -403,6 +408,19 @@ int main(int argc, char **argv) target_environ =3D envlist_to_environ(envlist, NULL); envlist_free(envlist); =20 + { + Error *err =3D NULL; + if (seed_optarg !=3D NULL) { + qemu_guest_random_seed_main(seed_optarg, &err); + } else { + qcrypto_init(&err); + } + if (err) { + error_reportf_err(err, "cannot initialize crypto: "); + exit(1); + } + } + /* * Now that page sizes are configured we can do * proper page alignment for guest_base. --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052842181831.2055189726432; Tue, 7 Sep 2021 15:14:02 -0700 (PDT) Received: from localhost ([::1]:55116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjLt-00036E-3W for importer@patchew.org; Tue, 07 Sep 2021 18:14:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2o-0006aS-1i for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:18 -0400 Received: from mail-il1-x144.google.com ([2607:f8b0:4864:20::144]:36621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2a-00011Z-Rj for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:17 -0400 Received: by mail-il1-x144.google.com with SMTP id x5so176058ill.3 for ; Tue, 07 Sep 2021 14:54:04 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p8wFbjVq5zO3wyTMiSXNG8FjHa8BNCmoaasDs0yUEaU=; b=dVteRuzK7BSDEP380Zyn80IMqXkq0WgTqGt/SYiGJwwAxDzCfoBzpw2VV9UwNO2sRd vthkENxPdPw9jmY3e6XfZyJEppEM8LcD65J77Dnb2JcuENIlGWoMS8R05q0V05WddPrs bMyjR7xVvW3wH6fMijPAauruzCOlMbxdxUvF3i9cFDL6xlVGfA1LCqE8lojvD62IoQBH 8nlqTdkFRByFSQEFQB6n9aZr/qZXf+U78dHndfp6xzG09j9vQbhJ5zUF9381ia+OduBp 21tAZ6t5HJ4lz4OQoOgKW/xdxkATxAK1ZpTQwfI9F5bXCzglMPFUH8z9/HM8VLiTPlBr ymJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p8wFbjVq5zO3wyTMiSXNG8FjHa8BNCmoaasDs0yUEaU=; b=Y00VOOmTNUJFAy9MYL9qOy/xfRifMKn0FnR4WB4KFLY9/gm9UNIzdzAxgoKHjd9Vhj Xq7JfYzVd+B9KrVEs0QwKZCF4fnFxp39GPIcKq1w4RUClTVWG03ucrtLphuYHwFyJGvn ucegMZjxPuUN8PVi2tjEG1uLlEHdDXRg3F1eo8UEWBmbA/5JisqPkLc8Un7hD9kugh27 FFKG2jtfhqQv9M4FsV+zmXpRlTB7FlSR7ac7ir9qXXn2i1f//TJ621LlKCWl92U4JUtA QglW+aCVqVwqkFyQFO0wdYOrSGNOsv0drA2nGG0VQvLyR2Xbhx/iJKN/Y8J4zDvxs+F3 whCQ== X-Gm-Message-State: AOAM533slV9QnWm2HU6Lc8UEhAdxqNPo/bULTUrenEAw7lvZSfdXB4Uz Go8kfglRYQMLukCbns7abqdQCuzcCXcR1h7y460= X-Google-Smtp-Source: ABdhPJxfKaPnNIXVgs3tSWlvoS5+EfuyLb5BDgPAOgIb/6MC91F1TTnYHwYUJBo+7hzJk5iaVWE5nQ== X-Received: by 2002:a05:6e02:2163:: with SMTP id s3mr322477ilv.172.1631051643458; Tue, 07 Sep 2021 14:54:03 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 28/42] bsd-user: Move stack initializtion into a per-os file. Date: Tue, 7 Sep 2021 15:53:18 -0600 Message-Id: <20210907215332.30737-29-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::144; envelope-from=imp@bsdimp.com; helo=mail-il1-x144.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052842557100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Move all of the stack initialization into target_os_stack.h. Each BSD sets up processes a little differently. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/freebsd/target_os_stack.h | 181 +++++++++++++++++++++++++++++ bsd-user/netbsd/target_os_stack.h | 56 +++++++++ bsd-user/openbsd/target_os_stack.h | 56 +++++++++ 3 files changed, 293 insertions(+) create mode 100644 bsd-user/freebsd/target_os_stack.h create mode 100644 bsd-user/netbsd/target_os_stack.h create mode 100644 bsd-user/openbsd/target_os_stack.h diff --git a/bsd-user/freebsd/target_os_stack.h b/bsd-user/freebsd/target_o= s_stack.h new file mode 100644 index 0000000000..1bb1a2bf56 --- /dev/null +++ b/bsd-user/freebsd/target_os_stack.h @@ -0,0 +1,181 @@ +/* + * FreeBSD setup_initial_stack() implementation. + * + * Copyright (c) 2013-14 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_OS_STACK_H_ +#define _TARGET_OS_STACK_H_ + +#include +#include "target_arch_sigtramp.h" +#include "qemu/guest-random.h" + +/* + * The inital FreeBSD stack is as follows: + * (see kern/kern_exec.c exec_copyout_strings() ) + * + * Hi Address -> char **ps_argvstr (struct ps_strings for ps, w, etc.) + * unsigned ps_nargvstr + * char **ps_envstr + * PS_STRINGS -> unsigned ps_nenvstr + * + * machine dependent sigcode (sv_sigcode of size + * sv_szsigcode) + * + * execpath (absolute image path for rtld) + * + * SSP Canary (sizeof(long) * 8) + * + * page sizes array (usually sizeof(u_long) ) + * + * "destp" -> argv, env strings (up to 262144 bytes) + */ +static inline int setup_initial_stack(struct bsd_binprm *bprm, + abi_ulong *ret_addr, abi_ulong *stringp) +{ + int i; + abi_ulong stack_hi_addr; + size_t execpath_len, stringspace; + abi_ulong destp, argvp, envp, p; + struct target_ps_strings ps_strs; + char canary[sizeof(abi_long) * 8]; + + stack_hi_addr =3D p =3D target_stkbas + target_stksiz; + + /* Save some space for ps_strings. */ + p -=3D sizeof(struct target_ps_strings); + + /* Add machine depedent sigcode. */ + p -=3D TARGET_SZSIGCODE; + if (setup_sigtramp(p, (unsigned)offsetof(struct target_sigframe, sf_uc= ), + TARGET_FREEBSD_NR_sigreturn)) { + errno =3D EFAULT; + return -1; + } + if (bprm->fullpath) { + execpath_len =3D strlen(bprm->fullpath) + 1; + p -=3D roundup(execpath_len, sizeof(abi_ulong)); + if (memcpy_to_target(p, bprm->fullpath, execpath_len)) { + errno =3D EFAULT; + return -1; + } + } + /* Add canary for SSP. */ + qemu_guest_getrandom_nofail(canary, sizeof(canary)); + p -=3D roundup(sizeof(canary), sizeof(abi_ulong)); + if (memcpy_to_target(p, canary, sizeof(canary))) { + errno =3D EFAULT; + return -1; + } + /* Add page sizes array. */ + p -=3D sizeof(abi_ulong); + if (put_user_ual(TARGET_PAGE_SIZE, p)) { + errno =3D EFAULT; + return -1; + } + /* + * Deviate from FreeBSD stack layout: force stack to new page here + * so that signal trampoline is not sharing the page with user stack + * frames. This is actively harmful in qemu as it marks pages with + * code it translated as read-only, which is somewhat problematic + * for user trying to use the stack as intended. + */ + p =3D rounddown(p, TARGET_PAGE_SIZE); + + /* Calculate the string space needed */ + stringspace =3D 0; + for (i =3D 0; i < bprm->argc; ++i) { + stringspace +=3D strlen(bprm->argv[i]) + 1; + } + for (i =3D 0; i < bprm->envc; ++i) { + stringspace +=3D strlen(bprm->envp[i]) + 1; + } + if (stringspace > TARGET_ARG_MAX) { + errno =3D ENOMEM; + return -1; + } + /* Make room for the argv and envp strings */ + destp =3D rounddown(p - stringspace, sizeof(abi_ulong)); + p =3D argvp =3D destp - (bprm->argc + bprm->envc + 2) * sizeof(abi_ulo= ng); + /* Remember the strings pointer */ + if (stringp) { + *stringp =3D destp; + } + /* + * Add argv strings. Note that the argv[] vectors are added by + * loader_build_argptr() + */ + /* XXX need to make room for auxargs */ + ps_strs.ps_argvstr =3D tswapl(argvp); + ps_strs.ps_nargvstr =3D tswap32(bprm->argc); + for (i =3D 0; i < bprm->argc; ++i) { + size_t len =3D strlen(bprm->argv[i]) + 1; + + if (memcpy_to_target(destp, bprm->argv[i], len)) { + errno =3D EFAULT; + return -1; + } + if (put_user_ual(destp, argvp)) { + errno =3D EFAULT; + return -1; + } + argvp +=3D sizeof(abi_ulong); + destp +=3D len; + } + if (put_user_ual(0, argvp)) { + errno =3D EFAULT; + return -1; + } + /* + * Add env strings. Note that the envp[] vectors are added by + * loader_build_argptr(). + */ + envp =3D argvp + sizeof(abi_ulong); + ps_strs.ps_envstr =3D tswapl(envp); + ps_strs.ps_nenvstr =3D tswap32(bprm->envc); + for (i =3D 0; i < bprm->envc; ++i) { + size_t len =3D strlen(bprm->envp[i]) + 1; + + if (memcpy_to_target(destp, bprm->envp[i], len)) { + errno =3D EFAULT; + return -1; + } + if (put_user_ual(destp, envp)) { + errno =3D EFAULT; + return -1; + } + envp +=3D sizeof(abi_ulong); + destp +=3D len; + } + if (put_user_ual(0, envp)) { + errno =3D EFAULT; + return -1; + } + if (memcpy_to_target(stack_hi_addr - sizeof(ps_strs), &ps_strs, + sizeof(ps_strs))) { + errno =3D EFAULT; + return -1; + } + + if (ret_addr) { + *ret_addr =3D p; + } + + return 0; + } + +#endif /* !_TARGET_OS_STACK_H_ */ diff --git a/bsd-user/netbsd/target_os_stack.h b/bsd-user/netbsd/target_os_= stack.h new file mode 100644 index 0000000000..503279c1a9 --- /dev/null +++ b/bsd-user/netbsd/target_os_stack.h @@ -0,0 +1,56 @@ +/* + * NetBSD setup_initial_stack() implementation. + * + * Copyright (c) 2013-14 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_OS_STACK_H_ +#define _TARGET_OS_STACK_H_ + +#include "target_arch_sigtramp.h" + +static inline int setup_initial_stack(struct bsd_binprm *bprm, abi_ulong *= p, + abi_ulong *stringp) +{ + int i; + abi_ulong stack_base; + + stack_base =3D (target_stkbas + target_stksiz) - + MAX_ARG_PAGES * TARGET_PAGE_SIZE; + if (p) { + *p =3D stack_base; + } + if (stringp) { + *stringp =3D stack_base; + } + + for (i =3D 0; i < MAX_ARG_PAGES; i++) { + if (bprm->page[i]) { + info->rss++; + if (!memcpy_to_target(stack_base, bprm->page[i], + TARGET_PAGE_SIZE)) { + errno =3D EFAULT; + return -1; + } + g_free(bprm->page[i]); + } + stack_base +=3D TARGET_PAGE_SIZE; + } + + return 0; +} + +#endif /* !_TARGET_OS_STACK_H_ */ diff --git a/bsd-user/openbsd/target_os_stack.h b/bsd-user/openbsd/target_o= s_stack.h new file mode 100644 index 0000000000..4b37955d3b --- /dev/null +++ b/bsd-user/openbsd/target_os_stack.h @@ -0,0 +1,56 @@ +/* + * OpenBSD setup_initial_stack() implementation. + * + * Copyright (c) 2013-14 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_OS_STACK_H_ +#define _TARGET_OS_STACK_H_ + +#include "target_arch_sigtramp.h" + +static inline int setup_initial_stack(struct bsd_binprm *bprm, abi_ulong *= p, + abi_ulong *stringp) +{ + int i; + abi_ulong stack_base; + + stack_base =3D (target_stkbas + target_stksiz) - + MAX_ARG_PAGES * TARGET_PAGE_SIZE; + if (p) { + *p =3D stack_base; + } + if (stringp) { + *stringp =3D stack_base; + } + + for (i =3D 0; i < MAX_ARG_PAGES; i++) { + if (bprm->page[i]) { + info->rss++; + if (!memcpy_to_target(stack_base, bprm->page[i], + TARGET_PAGE_SIZE)) { + errno =3D EFAULT; + return -1; + } + g_free(bprm->page[i]); + } + stack_base +=3D TARGET_PAGE_SIZE; + } + + return 0; +} + +#endif /* !_TARGET_OS_STACK_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052803580524.2516048278869; Tue, 7 Sep 2021 15:13:23 -0700 (PDT) Received: from localhost ([::1]:52102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjLG-00013C-FO for importer@patchew.org; Tue, 07 Sep 2021 18:13:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2e-0005xT-4D for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:08 -0400 Received: from mail-il1-x144.google.com ([2607:f8b0:4864:20::144]:35577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2c-00012K-3d for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:07 -0400 Received: by mail-il1-x144.google.com with SMTP id h29so181734ila.2 for ; Tue, 07 Sep 2021 14:54:05 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Su9ozr1Od3G7lDBmllWnVlZNz8wmzbdSw3TgujzER3k=; b=XrJZzTJAepr98j7NNF89NFG4bi4dFF4Ue4nOEdz0PyMFeqAZizrKp6JZ7imdMIY/Ue PZea5HCBxe3+EHIVE925/my29a1lXkKhMlojC9KMmT+TfV6dcUBDxR9iAoDJ7KhBtcqv j4p7c/ktEinDzmy9uhN5Ih0MupXBwNu0L4ceCBbFXZNyQOX9L30irySey9pDy8XhNVj9 ndXK80ExxbmvqLV/jQd2/0i70sqXK/fHueACtcQcIxP/UgmT2i0zlJmLvSV36Yjgrmy8 02sYu2sW/hEhvnSv8yoSOoF3gCWdWZD0vase5wJjhzm/MW8NQ4dYAOIzmX93cYaMpEjk pzmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Su9ozr1Od3G7lDBmllWnVlZNz8wmzbdSw3TgujzER3k=; b=eApjOkBOOMHnDlwgHRqJ4MGCtct06Ig+D0UFMgEXp2fE+YfXAgoGvNhziofwGYEYeI E98pzK+1X4HooG8zLrVWsm3gbTfrnHFBP9ZLEUzAArHYzQVEceJKg7Dxe5HFYgP49JWC iU7Pxh7JQ0FEt9nmQghNkbo6j8e/xXsQ3lGOzhP0W3mihr0EHnC/ww0gPyfHSalWakvO HfRULYYzj7vB47VHr1hhH2Z4ITaKhixz8v8AaX60BjWthhus8khs7/cwFtypOI3ADZW+ k1O8OB/4XV4O/0qcAzWR8nwbFj/lA48w/fXOpH4blQWa9aVso61b62XfyzqAwn97z7pI o1tg== X-Gm-Message-State: AOAM533bYY1ZnpW1yu/5liWFdVUw9lnyjDU1J7TX6625kHuaydq5+IJp ivdHu7NGCQ2LpNM6YO+5NUx1c1Y1LiKafVrqYVw= X-Google-Smtp-Source: ABdhPJytlCggziWNucLIxs/UCDMXaB4WPaJfTfwi34E5hIcq0NUpZwaGuRcC2M2R1vzzx7ArPW7xTQ== X-Received: by 2002:a92:c70e:: with SMTP id a14mr246711ilp.299.1631051644356; Tue, 07 Sep 2021 14:54:04 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 29/42] bsd-user: Add architecture specific signal tramp code Date: Tue, 7 Sep 2021 15:53:19 -0600 Message-Id: <20210907215332.30737-30-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::144; envelope-from=imp@bsdimp.com; helo=mail-il1-x144.google.com X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052804091100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Add a stubbed out version of setup_sigtramp. This is not yet used for x86, but is used for other architectures. This will be connected in future commits. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/i386/target_arch_sigtramp.h | 29 ++++++++++++++++++++++++++ bsd-user/x86_64/target_arch_sigtramp.h | 29 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 bsd-user/i386/target_arch_sigtramp.h create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h diff --git a/bsd-user/i386/target_arch_sigtramp.h b/bsd-user/i386/target_ar= ch_sigtramp.h new file mode 100644 index 0000000000..cb4e89b0b0 --- /dev/null +++ b/bsd-user/i386/target_arch_sigtramp.h @@ -0,0 +1,29 @@ +/* + * Intel i386 sigcode for bsd-user + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_ARCH_SIGTRAMP_H_ +#define _TARGET_ARCH_SIGTRAMP_H_ + +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, + unsigned sys_sigreturn) +{ + + return 0; +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */ diff --git a/bsd-user/x86_64/target_arch_sigtramp.h b/bsd-user/x86_64/targe= t_arch_sigtramp.h new file mode 100644 index 0000000000..29d4a8b55f --- /dev/null +++ b/bsd-user/x86_64/target_arch_sigtramp.h @@ -0,0 +1,29 @@ +/* + * Intel x86_64 sigcode for bsd-user + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_ARCH_SIGTRAMP_H_ +#define _TARGET_ARCH_SIGTRAMP_H_ + +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, + unsigned sys_sigreturn) +{ + + return 0; +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052854325694.4100169789658; Tue, 7 Sep 2021 15:14:14 -0700 (PDT) Received: from localhost ([::1]:56134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjM5-0003m7-8Q for importer@patchew.org; Tue, 07 Sep 2021 18:14:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2h-0006B6-Bp for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:11 -0400 Received: from mail-il1-x143.google.com ([2607:f8b0:4864:20::143]:35577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2c-000131-TX for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:11 -0400 Received: by mail-il1-x143.google.com with SMTP id h29so181799ila.2 for ; Tue, 07 Sep 2021 14:54:06 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mOuc+aTxmXS4Xzci+ZKxd8ePXV2O6mlBgpzrJQBNngE=; b=RyVVyj8vPgPDiyXqgvnD8fNfPJq92PyQWUNzHZulP3oWzhcqP9LNWmKysZstsVTrkb xstaxsJ9ilABOOc6Tuaz1lCUdM8rPJa+WshKWhdL2W+5EgAiyw+K0BhdLZk1e03ijru2 uaeOJnPqDYQx1ujUDyVbwi14BCuA/sSTxjk4E3nJvST8ytoR2U7F8UuadqXIbVqnKiSD 1i8UjVvWxXELre5Dg+5wun6vwtukcKwQv8KI/ezw4LHE6suzdDcDs3YEHqA7ClMD+cSZ tjET3GMvXcd48uRhcdeuuLvDDbgV5Dkmbj4t1GXuBGgHVymBt2lATst7LXZzaASOWiaz xVvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mOuc+aTxmXS4Xzci+ZKxd8ePXV2O6mlBgpzrJQBNngE=; b=EuA9zp6evi84unbS79EJAZzWxirX6ezGnnyCogEg282jeMvIBmtkDzCyFZgo8oohaL +9SBIHuI2WU/UUjtFzH1MbCWEnpXUY9kAP5nb8ouabKq1Li2+a2gCMC4P8cu8OVEnaKK 7DKvdKCA1OT6yf3PjYF/MApkiKJb/KX2iTxUode+9SpAbC0Fp6MCCsnAuqLioBujiKBB V48SwVybYIQ6BxvPQbc/Itv0KesFfVeHcCsLSv13U9LtZASP/TAbl+WBSDF/mSsWQ3PN Ji/DWxGBRWZYcd4ERIszdjYrjmfsaWgeArorF/RWXv3XO5Nln8ikz177vdzx+JRvA/Rb RQVg== X-Gm-Message-State: AOAM531uegmhyCYWNcUE+TDeflhuNwVUvuBwTLGEMLx4SlxP0y/BxNCn Zo+5lImqyeHB3wMCVUKF4GCGTmwhcnh3aYlWHfU= X-Google-Smtp-Source: ABdhPJzt0apdBSxFi6qlsWWrbXFhLcL4jBJrxkHxHvrKA0Uzb2RNeXAePicHGonX7ZAdMfmOa6XWZw== X-Received: by 2002:a92:c884:: with SMTP id w4mr282854ilo.268.1631051645369; Tue, 07 Sep 2021 14:54:05 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 30/42] bsd-user: elf cleanup Date: Tue, 7 Sep 2021 15:53:20 -0600 Message-Id: <20210907215332.30737-31-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::143; envelope-from=imp@bsdimp.com; helo=mail-il1-x143.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stacey Son , Justin Hibbits , Alexander Kabaev , Kyle Evans , Richard Henderson , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052855550100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Move OS-dependent defines into target_os_elf.h. Move the architectural dependent stuff into target_arch_elf.h. Adjust elfload.c to use target_create_elf_tables instead of create_elf_tables. Signed-off-by: Warner Losh Signed-off-by: Stacey Son Signed-off-by: Kyle Evans Signed-off-by: Justin Hibbits Signed-off-by: Alexander Kabaev Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/elfload.c | 191 ++++--------------------------- bsd-user/freebsd/target_os_elf.h | 137 ++++++++++++++++++++++ bsd-user/netbsd/target_os_elf.h | 146 +++++++++++++++++++++++ bsd-user/openbsd/target_os_elf.h | 146 +++++++++++++++++++++++ bsd-user/qemu.h | 1 + 5 files changed, 454 insertions(+), 167 deletions(-) create mode 100644 bsd-user/freebsd/target_os_elf.h create mode 100644 bsd-user/netbsd/target_os_elf.h create mode 100644 bsd-user/openbsd/target_os_elf.h diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 59465b71d4..6156f9775d 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -23,48 +23,17 @@ #include "disas/disas.h" #include "qemu/path.h" =20 -#include "target_arch_elf.h" -#include "target_os_thread.h" - -/* this flag is uneffective under linux too, should be deleted */ -#ifndef MAP_DENYWRITE -#define MAP_DENYWRITE 0 -#endif - -/* should probably go in elf.h */ -#ifndef ELIBBAD -#define ELIBBAD 80 -#endif - -#ifndef ELF_PLATFORM -#define ELF_PLATFORM (NULL) -#endif - -#ifndef ELF_HWCAP -#define ELF_HWCAP 0 -#endif +static abi_ulong target_auxents; /* Where the AUX entries are in target = */ +static size_t target_auxents_sz; /* Size of AUX entries including AT_NUL= L */ =20 -#ifdef TARGET_ABI32 -#undef ELF_CLASS -#define ELF_CLASS ELFCLASS32 -#undef bswaptls -#define bswaptls(ptr) bswap32s(ptr) -#endif +#include "target_os_elf.h" +#include "target_os_stack.h" +#include "target_os_thread.h" =20 #include "elf.h" =20 -/* max code+data+bss space allocated to elf interpreter */ -#define INTERP_MAP_SIZE (32 * 1024 * 1024) - -/* max code+data+bss+brk space allocated to ET_DYN executables */ -#define ET_DYN_MAP_SIZE (128 * 1024 * 1024) - -/* Necessary parameters */ -#define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE -#define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_= PAGESIZE - 1)) -#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1)) - -#define DLINFO_ITEMS 12 +abi_ulong target_stksiz; +abi_ulong target_stkbas; =20 static inline void memcpy_fromfs(void *to, const void *from, unsigned long= n) { @@ -195,43 +164,36 @@ static abi_ulong copy_elf_strings(int argc, char **ar= gv, void **page, return p; } =20 -static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm, - struct image_info *info) +static void setup_arg_pages(struct bsd_binprm *bprm, struct image_info *in= fo, + abi_ulong *stackp, abi_ulong *stringp) { - abi_ulong stack_base, size, error; - int i; + abi_ulong stack_base, size; + abi_long addr; =20 /* Create enough stack to hold everything. If we don't use * it for args, we'll use it for something else... */ size =3D target_dflssiz; - if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE) - size =3D MAX_ARG_PAGES * TARGET_PAGE_SIZE; - error =3D target_mmap(0, + stack_base =3D TARGET_USRSTACK - size; + addr =3D target_mmap(stack_base, size + qemu_host_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); - if (error =3D=3D -1) { + if (addr =3D=3D -1) { perror("stk mmap"); exit(-1); } /* we reserve one extra page at the top of the stack as guard */ - target_mprotect(error + size, qemu_host_page_size, PROT_NONE); + target_mprotect(addr + size, qemu_host_page_size, PROT_NONE); =20 - stack_base =3D error + size - MAX_ARG_PAGES * TARGET_PAGE_SIZE; - p +=3D stack_base; + target_stksiz =3D size; + target_stkbas =3D addr; =20 - for (i =3D 0 ; i < MAX_ARG_PAGES ; i++) { - if (bprm->page[i]) { - info->rss++; - /* FIXME - check return value of memcpy_to_target() for failur= e */ - memcpy_to_target(stack_base, bprm->page[i], TARGET_PAGE_SIZE); - g_free(bprm->page[i]); - } - stack_base +=3D TARGET_PAGE_SIZE; + if (setup_initial_stack(bprm, stackp, stringp) !=3D 0) { + perror("stk setup"); + exit(-1); } - return p; } =20 static void set_brk(abi_ulong start, abi_ulong end) @@ -287,86 +249,6 @@ static void padzero(abi_ulong elf_bss, abi_ulong last_= bss) } } =20 - -static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, - struct elfhdr * exec, - abi_ulong load_addr, - abi_ulong load_bias, - abi_ulong interp_load_addr, - struct image_info *info) -{ - abi_ulong sp; - int size; - abi_ulong u_platform; - const char *k_platform; - const int n =3D sizeof(elf_addr_t); - - sp =3D p; - u_platform =3D 0; - k_platform =3D ELF_PLATFORM; - if (k_platform) { - size_t len =3D strlen(k_platform) + 1; - sp -=3D (len + n - 1) & ~(n - 1); - u_platform =3D sp; - /* FIXME - check return value of memcpy_to_target() for failur= e */ - memcpy_to_target(sp, k_platform, len); - } - /* - * Force 16 byte _final_ alignment here for generality. - */ - sp =3D sp & ~(abi_ulong)15; - size =3D (DLINFO_ITEMS + 1) * 2; - if (k_platform) - size +=3D 2; -#ifdef DLINFO_ARCH_ITEMS - size +=3D DLINFO_ARCH_ITEMS * 2; -#endif - size +=3D envc + argc + 2; - size +=3D 1; /* argc itself */ - size *=3D n; - if (size & 15) - sp -=3D 16 - (size & 15); - - /* This is correct because Linux defines - * elf_addr_t as Elf32_Off / Elf64_Off - */ -#define NEW_AUX_ENT(id, val) do { \ - sp -=3D n; put_user_ual(val, sp); \ - sp -=3D n; put_user_ual(id, sp); \ - } while (0) - - NEW_AUX_ENT(AT_NULL, 0); - - /* There must be exactly DLINFO_ITEMS entries here. */ - NEW_AUX_ENT(AT_PHDR, (abi_ulong)(load_addr + exec->e_phoff)); - NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof(struct elf_phdr))); - NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum)); - NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE)); - NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_load_addr)); - NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0); - NEW_AUX_ENT(AT_ENTRY, load_bias + exec->e_entry); - NEW_AUX_ENT(AT_UID, (abi_ulong) getuid()); - NEW_AUX_ENT(AT_EUID, (abi_ulong) geteuid()); - NEW_AUX_ENT(AT_GID, (abi_ulong) getgid()); - NEW_AUX_ENT(AT_EGID, (abi_ulong) getegid()); - NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP); - NEW_AUX_ENT(AT_CLKTCK, (abi_ulong) sysconf(_SC_CLK_TCK)); - if (k_platform) - NEW_AUX_ENT(AT_PLATFORM, u_platform); -#ifdef ARCH_DLINFO - /* - * ARCH_DLINFO must come last so platform specific code can enforce - * special alignment requirements on the AUXV if necessary (eg. PP= C). - */ - ARCH_DLINFO; -#endif -#undef NEW_AUX_ENT - - sp =3D loader_build_argptr(envc, argc, sp, p); - return sp; -} - - static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, int interpreter_fd, abi_ulong *interp_load_addr) @@ -824,31 +706,10 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, info->mmap =3D 0; elf_entry =3D (abi_ulong) elf_ex.e_entry; =20 - /* - * In case where user has not explicitly set the guest_base, we - * probe here that should we set it automatically. - */ - if (!have_guest_base) { - /* - * Go through ELF program header table and find out whether - * any of the segments drop below our current mmap_min_addr and - * in that case set guest_base to corresponding address. - */ - for (i =3D 0, elf_ppnt =3D elf_phdata; i < elf_ex.e_phnum; - i++, elf_ppnt++) { - if (elf_ppnt->p_type !=3D PT_LOAD) - continue; - if (HOST_PAGE_ALIGN(elf_ppnt->p_vaddr) < mmap_min_addr) { - guest_base =3D HOST_PAGE_ALIGN(mmap_min_addr); - break; - } - } - } - /* Do this so that we can load the interpreter, if need be. We will change some of these later */ info->rss =3D 0; - bprm->p =3D setup_arg_pages(bprm->p, bprm, info); + setup_arg_pages(bprm, info, &bprm->p, &bprm->stringp); info->start_stack =3D bprm->p; =20 /* Now we do a little grungy work by mmaping the ELF image into @@ -965,13 +826,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, #ifdef LOW_ELF_STACK info->start_stack =3D bprm->p =3D elf_stack - 4; #endif - bprm->p =3D create_elf_tables(bprm->p, - bprm->argc, - bprm->envc, - &elf_ex, - load_addr, load_bias, - interp_load_addr, - info); + bprm->p =3D target_create_elf_tables(bprm->p, bprm->argc, bprm->envc, + bprm->stringp, &elf_ex, load_addr, + load_bias, interp_load_addr, info); info->load_addr =3D reloc_func_desc; info->start_brk =3D info->brk =3D elf_brk; info->end_code =3D end_code; diff --git a/bsd-user/freebsd/target_os_elf.h b/bsd-user/freebsd/target_os_= elf.h new file mode 100644 index 0000000000..2d03a883aa --- /dev/null +++ b/bsd-user/freebsd/target_os_elf.h @@ -0,0 +1,137 @@ +/* + * freebsd ELF definitions + * + * Copyright (c) 2013-15 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_OS_ELF_H_ +#define _TARGET_OS_ELF_H_ + +#include "target_arch_elf.h" +#include "elf.h" + +#define bsd_get_ncpu() 1 /* until we pull in bsd-proc.[hc] */ + +/* this flag is uneffective under linux too, should be deleted */ +#ifndef MAP_DENYWRITE +#define MAP_DENYWRITE 0 +#endif + +/* should probably go in elf.h */ +#ifndef ELIBBAD +#define ELIBBAD 80 +#endif + +#ifndef ELF_PLATFORM +#define ELF_PLATFORM (NULL) +#endif + +#ifndef ELF_HWCAP +#define ELF_HWCAP 0 +#endif + +/* XXX Look at the other conflicting AT_* values. */ +#define FREEBSD_AT_NCPUS 19 +#define FREEBSD_AT_HWCAP 25 +#define FREEBSD_AT_HWCAP2 26 + +#ifdef TARGET_ABI32 +#undef ELF_CLASS +#define ELF_CLASS ELFCLASS32 +#undef bswaptls +#define bswaptls(ptr) bswap32s(ptr) +#endif + +/* max code+data+bss space allocated to elf interpreter */ +#define INTERP_MAP_SIZE (32 * 1024 * 1024) + +/* max code+data+bss+brk space allocated to ET_DYN executables */ +#define ET_DYN_MAP_SIZE (128 * 1024 * 1024) + +/* Necessary parameters */ +#define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE +#define TARGET_ELF_PAGESTART(_v) ((_v) & \ + ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1)) +#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1)) + +#define DLINFO_ITEMS 14 + +static abi_ulong target_create_elf_tables(abi_ulong p, int argc, int envc, + abi_ulong stringp, + struct elfhdr *exec, + abi_ulong load_addr, + abi_ulong load_bias, + abi_ulong interp_load_addr, + struct image_info *info) +{ + abi_ulong features, sp; + int size; + const int n =3D sizeof(elf_addr_t); + + target_auxents_sz =3D 0; + sp =3D p; + /* + * Force 16 byte _final_ alignment here for generality. + */ + sp =3D sp & ~(abi_ulong)15; + size =3D (DLINFO_ITEMS + 1) * 2; + size +=3D envc + argc + 2; + size +=3D 1; /* argc itself */ + size *=3D n; + if (size & 15) { + sp -=3D 16 - (size & 15); + } + + /* + * FreeBSD defines elf_addr_t as Elf32_Off / Elf64_Off + */ +#define NEW_AUX_ENT(id, val) do { \ + sp -=3D n; put_user_ual(val, sp); \ + sp -=3D n; put_user_ual(id, sp); \ + target_auxents_sz +=3D 2 * n; \ + } while (0) + + NEW_AUX_ENT(AT_NULL, 0); + + /* There must be exactly DLINFO_ITEMS entries here. */ + NEW_AUX_ENT(AT_PHDR, (abi_ulong)(load_addr + exec->e_phoff)); + NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof(struct elf_phdr))); + NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum)); + NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE)); + NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_load_addr)); + NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0); + NEW_AUX_ENT(FREEBSD_AT_NCPUS, (abi_ulong)bsd_get_ncpu()); + NEW_AUX_ENT(AT_ENTRY, load_bias + exec->e_entry); + NEW_AUX_ENT(AT_UID, (abi_ulong)getuid()); + NEW_AUX_ENT(AT_EUID, (abi_ulong)geteuid()); + NEW_AUX_ENT(AT_GID, (abi_ulong)getgid()); + NEW_AUX_ENT(AT_EGID, (abi_ulong)getegid()); + features =3D ELF_HWCAP; + NEW_AUX_ENT(FREEBSD_AT_HWCAP, features); + target_auxents =3D sp; /* Note where the aux entries are in the ta= rget */ +#ifdef ARCH_DLINFO + /* + * ARCH_DLINFO must come last so platform specific code can enforce + * special alignment requirements on the AUXV if necessary (eg. PP= C). + */ + ARCH_DLINFO; +#endif +#undef NEW_AUX_ENT + + sp =3D loader_build_argptr(envc, argc, sp, stringp); + return sp; +} + +#endif /* _TARGET_OS_ELF_H_ */ diff --git a/bsd-user/netbsd/target_os_elf.h b/bsd-user/netbsd/target_os_el= f.h new file mode 100644 index 0000000000..21b475f458 --- /dev/null +++ b/bsd-user/netbsd/target_os_elf.h @@ -0,0 +1,146 @@ +/* + * netbsd ELF definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_OS_ELF_H_ +#define _TARGET_OS_ELF_H_ + +#include "target_arch_elf.h" +#include "elf.h" + +/* this flag is uneffective under linux too, should be deleted */ +#ifndef MAP_DENYWRITE +#define MAP_DENYWRITE 0 +#endif + +/* should probably go in elf.h */ +#ifndef ELIBBAD +#define ELIBBAD 80 +#endif + +#ifndef ELF_PLATFORM +#define ELF_PLATFORM (NULL) +#endif + +#ifndef ELF_HWCAP +#define ELF_HWCAP 0 +#endif + +#ifdef TARGET_ABI32 +#undef ELF_CLASS +#define ELF_CLASS ELFCLASS32 +#undef bswaptls +#define bswaptls(ptr) bswap32s(ptr) +#endif + +/* max code+data+bss space allocated to elf interpreter */ +#define INTERP_MAP_SIZE (32 * 1024 * 1024) + +/* max code+data+bss+brk space allocated to ET_DYN executables */ +#define ET_DYN_MAP_SIZE (128 * 1024 * 1024) + +/* Necessary parameters */ +#define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE +#define TARGET_ELF_PAGESTART(_v) ((_v) & \ + ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1)) +#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1)) + +#define DLINFO_ITEMS 12 + +static abi_ulong target_create_elf_tables(abi_ulong p, int argc, int envc, + abi_ulong stringp, + struct elfhdr *exec, + abi_ulong load_addr, + abi_ulong load_bias, + abi_ulong interp_load_addr, + struct image_info *info) +{ + abi_ulong sp; + int size; + abi_ulong u_platform; + const char *k_platform; + const int n =3D sizeof(elf_addr_t); + + sp =3D p; + u_platform =3D 0; + k_platform =3D ELF_PLATFORM; + if (k_platform) { + size_t len =3D strlen(k_platform) + 1; + sp -=3D (len + n - 1) & ~(n - 1); + u_platform =3D sp; + /* FIXME - check return value of memcpy_to_target() for failur= e */ + memcpy_to_target(sp, k_platform, len); + } + /* + * Force 16 byte _final_ alignment here for generality. + */ + sp =3D sp & ~(abi_ulong)15; + size =3D (DLINFO_ITEMS + 1) * 2; + if (k_platform) { + size +=3D 2; + } +#ifdef DLINFO_ARCH_ITEMS + size +=3D DLINFO_ARCH_ITEMS * 2; +#endif + size +=3D envc + argc + 2; + size +=3D 1; /* argc itself */ + size *=3D n; + if (size & 15) { + sp -=3D 16 - (size & 15); + } + + /* + * NetBSD defines elf_addr_t as Elf32_Off / Elf64_Off + */ +#define NEW_AUX_ENT(id, val) do { \ + sp -=3D n; put_user_ual(val, sp); \ + sp -=3D n; put_user_ual(id, sp); \ + } while (0) + + NEW_AUX_ENT(AT_NULL, 0); + + /* There must be exactly DLINFO_ITEMS entries here. */ + NEW_AUX_ENT(AT_PHDR, (abi_ulong)(load_addr + exec->e_phoff)); + NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof(struct elf_phdr))); + NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum)); + NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE)); + NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_load_addr)); + NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0); + NEW_AUX_ENT(AT_ENTRY, load_bias + exec->e_entry); + NEW_AUX_ENT(AT_UID, (abi_ulong)getuid()); + NEW_AUX_ENT(AT_EUID, (abi_ulong)geteuid()); + NEW_AUX_ENT(AT_GID, (abi_ulong)getgid()); + NEW_AUX_ENT(AT_EGID, (abi_ulong)getegid()); + NEW_AUX_ENT(AT_HWCAP, (abi_ulong)ELF_HWCAP); + NEW_AUX_ENT(AT_CLKTCK, (abi_ulong)sysconf(_SC_CLK_TCK)); + if (k_platform) { + NEW_AUX_ENT(AT_PLATFORM, u_platform); + } +#ifdef ARCH_DLINFO + /* + * ARCH_DLINFO must come last so platform specific code can enforce + * special alignment requirements on the AUXV if necessary (eg. PP= C). + */ + ARCH_DLINFO; +#endif +#undef NEW_AUX_ENT + + sp =3D loader_build_argptr(envc, argc, sp, stringp); + return sp; +} + +#endif /* _TARGET_OS_ELF_H_ */ diff --git a/bsd-user/openbsd/target_os_elf.h b/bsd-user/openbsd/target_os_= elf.h new file mode 100644 index 0000000000..a5cfcd3aff --- /dev/null +++ b/bsd-user/openbsd/target_os_elf.h @@ -0,0 +1,146 @@ +/* + * openbsd ELF definitions + * + * Copyright (c) 2013 Stacey D. Son + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#ifndef _TARGET_OS_ELF_H_ +#define _TARGET_OS_ELF_H_ + +#include "target_arch_elf.h" +#include "elf.h" + +/* this flag is uneffective under linux too, should be deleted */ +#ifndef MAP_DENYWRITE +#define MAP_DENYWRITE 0 +#endif + +/* should probably go in elf.h */ +#ifndef ELIBBAD +#define ELIBBAD 80 +#endif + +#ifndef ELF_PLATFORM +#define ELF_PLATFORM (NULL) +#endif + +#ifndef ELF_HWCAP +#define ELF_HWCAP 0 +#endif + +#ifdef TARGET_ABI32 +#undef ELF_CLASS +#define ELF_CLASS ELFCLASS32 +#undef bswaptls +#define bswaptls(ptr) bswap32s(ptr) +#endif + +/* max code+data+bss space allocated to elf interpreter */ +#define INTERP_MAP_SIZE (32 * 1024 * 1024) + +/* max code+data+bss+brk space allocated to ET_DYN executables */ +#define ET_DYN_MAP_SIZE (128 * 1024 * 1024) + +/* Necessary parameters */ +#define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE +#define TARGET_ELF_PAGESTART(_v) ((_v) & \ + ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1)) +#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1)) + +#define DLINFO_ITEMS 12 + +static abi_ulong target_create_elf_tables(abi_ulong p, int argc, int envc, + abi_ulong stringp, + struct elfhdr *exec, + abi_ulong load_addr, + abi_ulong load_bias, + abi_ulong interp_load_addr, + struct image_info *info) +{ + abi_ulong sp; + int size; + abi_ulong u_platform; + const char *k_platform; + const int n =3D sizeof(elf_addr_t); + + sp =3D p; + u_platform =3D 0; + k_platform =3D ELF_PLATFORM; + if (k_platform) { + size_t len =3D strlen(k_platform) + 1; + sp -=3D (len + n - 1) & ~(n - 1); + u_platform =3D sp; + /* FIXME - check return value of memcpy_to_target() for failur= e */ + memcpy_to_target(sp, k_platform, len); + } + /* + * Force 16 byte _final_ alignment here for generality. + */ + sp =3D sp & ~(abi_ulong)15; + size =3D (DLINFO_ITEMS + 1) * 2; + if (k_platform) { + size +=3D 2; + } +#ifdef DLINFO_ARCH_ITEMS + size +=3D DLINFO_ARCH_ITEMS * 2; +#endif + size +=3D envc + argc + 2; + size +=3D 1; /* argc itself */ + size *=3D n; + if (size & 15) { + sp -=3D 16 - (size & 15); + } + + /* + * OpenBSD defines elf_addr_t as Elf32_Off / Elf64_Off + */ +#define NEW_AUX_ENT(id, val) do { \ + sp -=3D n; put_user_ual(val, sp); \ + sp -=3D n; put_user_ual(id, sp); \ + } while (0) + + NEW_AUX_ENT(AT_NULL, 0); + + /* There must be exactly DLINFO_ITEMS entries here. */ + NEW_AUX_ENT(AT_PHDR, (abi_ulong)(load_addr + exec->e_phoff)); + NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof(struct elf_phdr))); + NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum)); + NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE)); + NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_load_addr)); + NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0); + NEW_AUX_ENT(AT_ENTRY, load_bias + exec->e_entry); + NEW_AUX_ENT(AT_UID, (abi_ulong)getuid()); + NEW_AUX_ENT(AT_EUID, (abi_ulong)geteuid()); + NEW_AUX_ENT(AT_GID, (abi_ulong)getgid()); + NEW_AUX_ENT(AT_EGID, (abi_ulong)getegid()); + NEW_AUX_ENT(AT_HWCAP, (abi_ulong)ELF_HWCAP); + NEW_AUX_ENT(AT_CLKTCK, (abi_ulong)sysconf(_SC_CLK_TCK)); + if (k_platform) { + NEW_AUX_ENT(AT_PLATFORM, u_platform); + } +#ifdef ARCH_DLINFO + /* + * ARCH_DLINFO must come last so platform specific code can enforce + * special alignment requirements on the AUXV if necessary (eg. PP= C). + */ + ARCH_DLINFO; +#endif +#undef NEW_AUX_ENT + + sp =3D loader_build_argptr(envc, argc, sp, stringp); + return sp; +} + +#endif /* _TARGET_OS_ELF_H_ */ diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 3e3bd96cff..3685156123 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -124,6 +124,7 @@ struct bsd_binprm { char buf[128]; void *page[MAX_ARG_PAGES]; abi_ulong p; + abi_ulong stringp; int fd; int e_uid, e_gid; int argc, envc; --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631052922814425.2876976375661; Tue, 7 Sep 2021 15:15:22 -0700 (PDT) Received: from localhost ([::1]:60320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjNB-0006Xg-RJ for importer@patchew.org; Tue, 07 Sep 2021 18:15:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2g-00067N-ER for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:10 -0400 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]:43627) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2d-000134-U3 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:10 -0400 Received: by mail-il1-x135.google.com with SMTP id v16so151219ilo.10 for ; Tue, 07 Sep 2021 14:54:06 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mHgTeAaYz/lEdKsPhpVfOQ7pF/fy2xdIJ54PjrTVY8s=; b=wybpeZibAXIRPzIPv9NhGT7eu69HFXdzbyrrvkOTh8Yei4s8nj5WrlnlVsSFbfSVCI P7YfCqRT1vREpMmuRm+Ua10LHlzRAGXzxAy2dHf56qFn7QEbSNHFaR0c31Olm/Vi/cbW NGFnwzNLWJhx4ew+5rHy9lwSwDvfepbDVceJNYAvZ6rjnoynt1hrbM8X5sKNlSQM+KHW 8ksOrFt3zxIDOJOFjaQnQqlKuz1HH3+usQ5nsA08ol1XSaXp1vO5yU6+pdjefgXndf1F BnqVCi8eewhSqPCor0ObUvEafLDdQ3dSyhnKqt/nh0mVfdHWOc/JkrPtQZzRrum19G6u sa1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mHgTeAaYz/lEdKsPhpVfOQ7pF/fy2xdIJ54PjrTVY8s=; b=tqn0zT0ljagIxdohpeRdbBLKU39YM/M2FPiY/eClCiydi/BcrqsU/4o0kl+Efk4LtP esNkElKbRiGlqbmEWr7kIBJYMLLvg/v8gtENsR9IV+hdpgNcHaCxL5zB0NesROeUoyAE ReZyNDgjTNZ2p2IK3l7HzeZo09IVrYKHWerVAegIfd5bqEx53H6/kkPj4sKsdXtpxRIU gQZAlye2olpcT8VEEEXI+1HBYNuZjf3OsJcDMvFdoAYQPVtM9/uCrQXtyeCcK75/4ZJP agbR+8pyugTZjMpXsyr+t4BtKqVEmj7qdeRclBqa28qe0oitLnZG+uFiXsJCqG4ZWRk4 617Q== X-Gm-Message-State: AOAM532ymYsaMgweJcxAdsCToe5TWxGqFkQbxdlQnafXxqSppvZW2iV0 YNL+j+vt88qSGKybfBFURe5T7OYAaWc1E5qWMuk= X-Google-Smtp-Source: ABdhPJy3/UotqAJOGCUp9J9JE28IKMOWfwSS6YHencfnhjPBFhjr52lFfcy2HJXptDzDpx0AVVul6g== X-Received: by 2002:a92:cb12:: with SMTP id s18mr294116ilo.32.1631051646041; Tue, 07 Sep 2021 14:54:06 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 31/42] bsd-user: Remove dead #ifdefs from elfload.c Date: Tue, 7 Sep 2021 15:53:21 -0600 Message-Id: <20210907215332.30737-32-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::135; envelope-from=imp@bsdimp.com; helo=mail-il1-x135.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631052924194100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh LOW_ELF_STACK doesn't exist on FreeBSD and likely never will. Remove it. Likewise, remove an #if 0 block that's not useful Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 6156f9775d..11ca813c7a 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -558,9 +558,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, abi_ulong elf_entry, interp_load_addr =3D 0; abi_ulong start_code, end_code, start_data, end_data; abi_ulong reloc_func_desc =3D 0; -#ifdef LOW_ELF_STACK - abi_ulong elf_stack =3D ~((abi_ulong)0UL); -#endif =20 load_addr =3D 0; load_bias =3D 0; @@ -761,11 +758,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, exit(-1); } =20 -#ifdef LOW_ELF_STACK - if (TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack) - elf_stack =3D TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr); -#endif - if (!load_addr_set) { load_addr_set =3D 1; load_addr =3D elf_ppnt->p_vaddr - elf_ppnt->p_offset; @@ -823,9 +815,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, =20 close(bprm->fd); =20 -#ifdef LOW_ELF_STACK - info->start_stack =3D bprm->p =3D elf_stack - 4; -#endif bprm->p =3D target_create_elf_tables(bprm->p, bprm->argc, bprm->envc, bprm->stringp, &elf_ex, load_addr, load_bias, interp_load_addr, info); @@ -843,15 +832,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, =20 padzero(elf_bss, elf_brk); =20 -#if 0 - printf("(start_brk) %x\n" , info->start_brk); - printf("(end_code) %x\n" , info->end_code); - printf("(start_code) %x\n" , info->start_code); - printf("(end_data) %x\n" , info->end_data); - printf("(start_stack) %x\n" , info->start_stack); - printf("(brk) %x\n" , info->brk); -#endif - info->entry =3D elf_entry; =20 return 0; --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053035153459.43108285051244; Tue, 7 Sep 2021 15:17:15 -0700 (PDT) Received: from localhost ([::1]:35784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjOz-0000ez-UE for importer@patchew.org; Tue, 07 Sep 2021 18:17:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2i-0006G5-Qa for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:12 -0400 Received: from mail-il1-x141.google.com ([2607:f8b0:4864:20::141]:41829) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2e-000144-G9 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:12 -0400 Received: by mail-il1-x141.google.com with SMTP id l10so157724ilh.8 for ; Tue, 07 Sep 2021 14:54:08 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ApDGbRaCrCkDANlTmPExz0UBKFsSKhdbhfclyYQH1BQ=; b=DqZrTnSU9QHY+PtWL60dXNN5YnJYu+YOQTh+wf9J73TI8/ew4yIM6IFWUnJz6ilPHX IsjnNRJKxRHAMu7+Q4AwzVtQdcgwzAGmjnLju1dh/8gG44HabEWhfCAXfWcRpWeST7xv +FQfUx3czxZfTWozhfctFKBYlFrFVMYxsdtmWgfT0ZcQIY0Vhjkauq2bMOK0VvTB/eE9 bYBaTbGO1FrJy0jM8zrKWWjTQfP/jCGtK2VGQHvEmlOcUox2nj431y9Dcyxfaj+bevI+ WIiR6rb+lBpwBT/55cEBO8JVHfQN/DJoWTp6LktoPmiLjPe1EjP10fq4QtYJ3c+oK/Ar ChFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ApDGbRaCrCkDANlTmPExz0UBKFsSKhdbhfclyYQH1BQ=; b=sip2G/ZunNJ2RUBPlETlsGAAmBI4S2KpsoDg2Gl/9LJhb7K3e1/69I8ivkH2GuQK81 lvy5sU52MS9sI1enbHnXeXEMJHpVMaCLd/f/XW7N47s7Q24i+tASQhX0SKv5iEnFvvBO +9bPLiKwcSLayjcyejSeuYCfC5FV99jglbudlgMyjGejSLyuGk05U70Ax/eAwuT6uY4G NTVCMcPzt6W1lxwrBMtleOkCHHLfj658NwJ/t28WBGvi9ikplYIMZtgpciVQjQuGFqUY MBW13I531og/vnvdG2Wk1fBLDMHGTMSpAD6xwBWj1cK1wok4CsVEDjQV1qsloMg4v0Bh 1yVw== X-Gm-Message-State: AOAM5305gZVzFERXv3U3n0sHAvohVkPFIoducPIgmzadNKP6t9MnQovM J05Q0OL9GvfxBBuT8C6F3KjSp1Jrc0m7L8csbEw= X-Google-Smtp-Source: ABdhPJwPIzRCegLeqY4ueMiwu69LaHdObMtgUj/zu9mjPNQDwWpyHXkqDnwAs9fVhNrftd5nx94ouw== X-Received: by 2002:a92:d60f:: with SMTP id w15mr285681ilm.209.1631051647054; Tue, 07 Sep 2021 14:54:07 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 32/42] bsd-user: Rewrite target system call definintion glue Date: Tue, 7 Sep 2021 15:53:22 -0600 Message-Id: <20210907215332.30737-33-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::141; envelope-from=imp@bsdimp.com; helo=mail-il1-x141.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053035698100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Rewrite target definnitions to interface with the FreeBSD system calls. This covers basic types (time_t, iovec, umtx_time, timespec, timeval, rusage, rwusage) and basic defines (mmap, rusage). Also included are FreeBSD version-specific variations. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/bsd-mman.h | 121 -------------------- bsd-user/mmap.c | 2 - bsd-user/syscall_defs.h | 247 ++++++++++++++++++++++++++-------------- 3 files changed, 162 insertions(+), 208 deletions(-) delete mode 100644 bsd-user/bsd-mman.h diff --git a/bsd-user/bsd-mman.h b/bsd-user/bsd-mman.h deleted file mode 100644 index 910e8c1921..0000000000 --- a/bsd-user/bsd-mman.h +++ /dev/null @@ -1,121 +0,0 @@ -/*- - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * 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. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 PURP= OSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL - * 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, STR= ICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mman.h 8.2 (Berkeley) 1/9/95 - * $FreeBSD: src/sys/sys/mman.h,v 1.42 2008/03/28 04:29:27 ps Exp $ - */ - -#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplement= ed MAP_INHERIT */ -#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemente= d MAP_NOEXTEND */ -#define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like= a stack */ -#define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync= underlying file */ - -#define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7 - -/* $NetBSD: mman.h,v 1.42 2008/11/18 22:13:49 ad Exp $ */ - -/*- - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 PURP= OSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL - * 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, STR= ICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mman.h 8.2 (Berkeley) 1/9/95 - */ -#define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained afte= r exec */ -#define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, ev= en within break */ -#define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it= is established */ - -#define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, = swap space (stack) */ - -#define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7 - -/* $OpenBSD: mman.h,v 1.18 2003/07/21 22:52:19 tedu Exp $ */ -/* $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc Exp $ */ - -/*- - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 PURP= OSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL - * 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, STR= ICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mman.h 8.1 (Berkeley) 6/2/93 - */ - -#define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained afte= r exec */ -#define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't cha= nge file size */ -#define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, e= ven within heap */ - -#define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7 - -// XXX -#define TARGET_BSD_MAP_FLAGMASK 0x3ff7 diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 0ac1b92706..03119b1f20 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -20,8 +20,6 @@ =20 #include "qemu.h" #include "qemu-common.h" -#include "bsd-mman.h" -#include "exec/exec-all.h" =20 //#define DEBUG_MMAP =20 diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index eb7d1da9b0..04a1a886d7 100644 --- a/bsd-user/syscall_defs.h +++ b/bsd-user/syscall_defs.h @@ -1,95 +1,26 @@ -/* $OpenBSD: signal.h,v 1.19 2006/01/08 14:20:16 millert Exp $ */ -/* $NetBSD: signal.h,v 1.21 1996/02/09 18:25:32 christos Exp $ */ - /* - * Copyright (c) 1982, 1986, 1989, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. + * System call related declarations * - * 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * Copyright (c) 2013-15 Stacey D. Son (sson at FreeBSD) * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 PURP= OSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL - * 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, STR= ICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * @(#)signal.h 8.2 (Berkeley) 1/21/94 - */ - -#define TARGET_SIGHUP 1 /* hangup */ -#define TARGET_SIGINT 2 /* interrupt */ -#define TARGET_SIGQUIT 3 /* quit */ -#define TARGET_SIGILL 4 /* illegal instruction (not reset when caug= ht) */ -#define TARGET_SIGTRAP 5 /* trace trap (not reset when caught) */ -#define TARGET_SIGABRT 6 /* abort() */ -#define TARGET_SIGIOT SIGABRT /* compatibility */ -#define TARGET_SIGEMT 7 /* EMT instruction */ -#define TARGET_SIGFPE 8 /* floating point exception */ -#define TARGET_SIGKILL 9 /* kill (cannot be caught or ignored) */ -#define TARGET_SIGBUS 10 /* bus error */ -#define TARGET_SIGSEGV 11 /* segmentation violation */ -#define TARGET_SIGSYS 12 /* bad argument to system call */ -#define TARGET_SIGPIPE 13 /* write on a pipe with no one to read it */ -#define TARGET_SIGALRM 14 /* alarm clock */ -#define TARGET_SIGTERM 15 /* software termination signal from kill */ -#define TARGET_SIGURG 16 /* urgent condition on IO channel */ -#define TARGET_SIGSTOP 17 /* sendable stop signal not from tty */ -#define TARGET_SIGTSTP 18 /* stop signal from tty */ -#define TARGET_SIGCONT 19 /* continue a stopped process */ -#define TARGET_SIGCHLD 20 /* to parent on child stop or exit */ -#define TARGET_SIGTTIN 21 /* to readers pgrp upon background tty read= */ -#define TARGET_SIGTTOU 22 /* like TTIN for output if (tp->t_local<O= STOP) */ -#define TARGET_SIGIO 23 /* input/output possible signal */ -#define TARGET_SIGXCPU 24 /* exceeded CPU time limit */ -#define TARGET_SIGXFSZ 25 /* exceeded file size limit */ -#define TARGET_SIGVTALRM 26 /* virtual time alarm */ -#define TARGET_SIGPROF 27 /* profiling time alarm */ -#define TARGET_SIGWINCH 28 /* window size changes */ -#define TARGET_SIGINFO 29 /* information request */ -#define TARGET_SIGUSR1 30 /* user defined signal 1 */ -#define TARGET_SIGUSR2 31 /* user defined signal 2 */ - -#define TARGET_SA_ONSTACK 0x0001 /* take signal on signal stack */ -#define TARGET_SA_RESTART 0x0002 /* restart system on signal return= */ -#define TARGET_SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking si= gnal */ -#define TARGET_SA_NODEFER 0x0010 /* don't mask the signal we're del= ivering */ -#define TARGET_SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to= pid 1) */ -#define TARGET_SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtr= amp */ -#define TARGET_SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on chil= d stop */ -#define TARGET_SA_SIGINFO 0x0040 /* generate siginfo_t */ - -/* - * Flags for sigprocmask: + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . */ -#define TARGET_SIG_BLOCK 1 /* block specified signal set */ -#define TARGET_SIG_UNBLOCK 2 /* unblock specified signal set */ -#define TARGET_SIG_SETMASK 3 /* set specified signal set */ =20 -#define TARGET_BADSIG SIG_ERR +#ifndef _SYSCALL_DEFS_H_ +#define _SYSCALL_DEFS_H_ =20 -#define TARGET_SS_ONSTACK 0x0001 /* take signals on alternate stack= */ -#define TARGET_SS_DISABLE 0x0004 /* disable taking signals on alter= nate stack */ +#include =20 #include "errno_defs.h" =20 @@ -97,8 +28,154 @@ #include "netbsd/syscall_nr.h" #include "openbsd/syscall_nr.h" =20 +/* + * machine/_types.h + * or x86/_types.h + */ + +/* + * time_t seems to be very inconsistly defined for the different *BSD's... + * + * FreeBSD uses a 64bits time_t except on i386 + * so we have to add a special case here. + * + * On NetBSD time_t is always defined as an int64_t. On OpenBSD time_t + * is always defined as an int. + * + */ +#if (!defined(TARGET_I386)) +typedef int64_t target_freebsd_time_t; +#else +typedef int32_t target_freebsd_time_t; +#endif + struct target_iovec { abi_long iov_base; /* Starting address */ abi_long iov_len; /* Number of bytes */ }; =20 +/* + * sys/mman.h + */ +#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplement= ed */ + /* MAP_INHERIT */ +#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemente= d */ + /* MAP_NOEXTEND */ +#define TARGET_FREEBSD_MAP_STACK 0x0400 /* region grows down, like= a */ + /* stack */ +#define TARGET_FREEBSD_MAP_NOSYNC 0x0800 /* page to but do not sync= */ + /* underlying file */ + +#define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7 + +#define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained afte= r */ + /* exec */ +#define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, e= ven */ + /* within break */ +#define TARGET_NETBSD_MAP_WIRED 0x0800 /* mlock() mapping when it= is */ + /* established */ + +#define TARGET_NETBSD_MAP_STACK 0x2000 /* allocated from memory, = */ + /* swap space (stack) */ + +#define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7 + +#define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained afte= r */ + /* exec */ +#define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't cha= nge */ + /* file size */ +#define TARGET_OPENBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, */ + /* even within heap */ + +#define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7 + +/* XXX */ +#define TARGET_BSD_MAP_FLAGMASK 0x3ff7 + +/* + * sys/time.h + * sys/timex.h + */ + +typedef abi_long target_freebsd_suseconds_t; + +/* compare to sys/timespec.h */ +struct target_freebsd_timespec { + target_freebsd_time_t tv_sec; /* seconds */ + abi_long tv_nsec; /* and nanoseconds */ +#if !defined(TARGET_I386) && TARGET_ABI_BITS =3D=3D 32 + abi_long _pad; +#endif +}; + +#define TARGET_CPUCLOCK_WHICH_PID 0 +#define TARGET_CPUCLOCK_WHICH_TID 1 + +/* sys/umtx.h */ +struct target_freebsd__umtx_time { + struct target_freebsd_timespec _timeout; + uint32_t _flags; + uint32_t _clockid; +}; + +struct target_freebsd_timeval { + target_freebsd_time_t tv_sec; /* seconds */ + target_freebsd_suseconds_t tv_usec;/* and microseconds */ +#if !defined(TARGET_I386) && TARGET_ABI_BITS =3D=3D 32 + abi_long _pad; +#endif +}; + +/* + * sys/resource.h + */ +#if defined(__FreeBSD__) +#define TARGET_RLIM_INFINITY RLIM_INFINITY +#else +#define TARGET_RLIM_INFINITY ((abi_ulong)-1) +#endif + +#define TARGET_RLIMIT_CPU 0 +#define TARGET_RLIMIT_FSIZE 1 +#define TARGET_RLIMIT_DATA 2 +#define TARGET_RLIMIT_STACK 3 +#define TARGET_RLIMIT_CORE 4 +#define TARGET_RLIMIT_RSS 5 +#define TARGET_RLIMIT_MEMLOCK 6 +#define TARGET_RLIMIT_NPROC 7 +#define TARGET_RLIMIT_NOFILE 8 +#define TARGET_RLIMIT_SBSIZE 9 +#define TARGET_RLIMIT_AS 10 +#define TARGET_RLIMIT_NPTS 11 +#define TARGET_RLIMIT_SWAP 12 + +struct target_rlimit { + uint64_t rlim_cur; + uint64_t rlim_max; +}; + +struct target_freebsd_rusage { + struct target_freebsd_timeval ru_utime; /* user time used */ + struct target_freebsd_timeval ru_stime; /* system time used */ + abi_long ru_maxrss; /* maximum resident set size */ + abi_long ru_ixrss; /* integral shared memory size */ + abi_long ru_idrss; /* integral unshared data size */ + abi_long ru_isrss; /* integral unshared stack size */ + abi_long ru_minflt; /* page reclaims */ + abi_long ru_majflt; /* page faults */ + abi_long ru_nswap; /* swaps */ + abi_long ru_inblock; /* block input operations */ + abi_long ru_oublock; /* block output operations */ + abi_long ru_msgsnd; /* messages sent */ + abi_long ru_msgrcv; /* messages received */ + abi_long ru_nsignals; /* signals received */ + abi_long ru_nvcsw; /* voluntary context switches */ + abi_long ru_nivcsw; /* involuntary context switches */ +}; + +struct target_freebsd__wrusage { + struct target_freebsd_rusage wru_self; + struct target_freebsd_rusage wru_children; +}; + +#endif /* ! _SYSCALL_DEFS_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053413982895.10261073879; Tue, 7 Sep 2021 15:23:33 -0700 (PDT) Received: from localhost ([::1]:52468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjV6-0003Rq-UE for importer@patchew.org; Tue, 07 Sep 2021 18:23:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2h-0006Cx-R0 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:11 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]:46596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2f-000159-EK for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:11 -0400 Received: by mail-io1-xd2b.google.com with SMTP id b200so431518iof.13 for ; Tue, 07 Sep 2021 14:54:09 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DDD16qQzNSsAOOrAI+aSsqOe63HjiHPP2KkxWUxig74=; b=m1PpUbi25v7YSrSR1EKHuisLLI8nlDJA6Pf/nLyY7coMg+8AfM8nEwCUq1Ea8vnqT4 IYrwvfyj8Nv8PyjBnci0KJmtW1hlZ29J/YJ3H+kJUC9WROwEebcx1wg08SshsNthmcL8 jou6FS/RyS+WOpksd235lqTvvbzosb7KL0U2akeWiLBkbkLGXPuUJnaDtmrhvmlsu0SS rY6Slyciv/Tz1lFJs+twIzRxl/ml57djHp/0IEaV71IItnVrY3popEwG9s5S32uAcjYY jLrea/PFSjcClq47oS0YyOlPMa735iNFu3rmGMFHQX7gdz5V5fiaH6mUVmoQidNSHjRg /B4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DDD16qQzNSsAOOrAI+aSsqOe63HjiHPP2KkxWUxig74=; b=i2K2CiQZczpIjAnm4nIaovTqqPwvp+9c6Vxb3cAE9/YfBW+mLMiHyy/N1qWC9kr7ex 4P2tg9A/OONEGSsvrcE79A38QLnS9OCmcoaOIEFXvcNNiP5lZ4oVySP5NJnIKd2wTEco Y5aoieGTbivONU7+5MZ71ZCk0igd6spkgsbu2j12XXqoi4hE3344/yraWlWbPZzJe4Bp mPWIfJndap4oUxawY0PJth4Tnw6KKrFVhsPCPdCXC3q1Pr4yoa0hlRjd1aZkyeLpHS0Z vBnFFChvf4B9ujvksJuHoMCwy9YjRlckSwNvDbpGZp8mdhO+IIzmM9WXtgPnxMmtM3oT kzGw== X-Gm-Message-State: AOAM531Eu2kXDFb8mZ53+DV+rPho0nCaFFsIa7PdXwjaa+Yb2BlkxFgR 1eld2KzTZXUBitCQJP3k4vx5DYQpk5cpQHCyec8= X-Google-Smtp-Source: ABdhPJxPiBFQL9lGYMGDfEiWnC9GKdCDBQyKEfauBfqCidiHu1atdDnlfsb95Rj1jHoO/pJG3b0uGA== X-Received: by 2002:a05:6602:2219:: with SMTP id n25mr269574ion.185.1631051648049; Tue, 07 Sep 2021 14:54:08 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 33/42] bsd-user: update debugging in mmap.c Date: Tue, 7 Sep 2021 15:53:23 -0600 Message-Id: <20210907215332.30737-34-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d2b; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , Richard Henderson , Sean Bruno , =?UTF-8?q?Mika=C3=ABl=20Urankar?= , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053415684100001 From: Warner Losh Update the debugging code for new features and different targets. Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Sean Bruno Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/mmap.c | 55 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 03119b1f20..8918c4ae68 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -68,8 +68,8 @@ int target_mprotect(abi_ulong start, abi_ulong len, int p= rot) int prot1, ret; =20 #ifdef DEBUG_MMAP - printf("mprotect: start=3D0x" TARGET_FMT_lx - " len=3D0x" TARGET_FMT_lx " prot=3D%c%c%c\n", start, len, + printf("mprotect: start=3D0x" TARGET_ABI_FMT_lx + "len=3D0x" TARGET_ABI_FMT_lx " prot=3D%c%c%c\n", start, len, prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); @@ -250,28 +250,47 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, mmap_lock(); #ifdef DEBUG_MMAP { - printf("mmap: start=3D0x" TARGET_FMT_lx - " len=3D0x" TARGET_FMT_lx " prot=3D%c%c%c flags=3D", + printf("mmap: start=3D0x" TARGET_ABI_FMT_lx + " len=3D0x" TARGET_ABI_FMT_lx " prot=3D%c%c%c flags=3D", start, len, prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); - if (flags & MAP_FIXED) + if (flags & MAP_ALIGNMENT_MASK) { + printf("MAP_ALIGNED(%u) ", (flags & MAP_ALIGNMENT_MASK) + >> MAP_ALIGNMENT_SHIFT); + } +#if MAP_GUARD + if (flags & MAP_GUARD) { + printf("MAP_GUARD "); + } +#endif + if (flags & MAP_FIXED) { printf("MAP_FIXED "); - if (flags & MAP_ANON) + } + if (flags & MAP_ANONYMOUS) { printf("MAP_ANON "); - switch (flags & TARGET_BSD_MAP_FLAGMASK) { - case MAP_PRIVATE: + } +#ifdef MAP_EXCL + if (flags & MAP_EXCL) { + printf("MAP_EXCL "); + } +#endif + if (flags & MAP_PRIVATE) { printf("MAP_PRIVATE "); - break; - case MAP_SHARED: + } + if (flags & MAP_SHARED) { printf("MAP_SHARED "); - break; - default: - printf("[MAP_FLAGMASK=3D0x%x] ", flags & TARGET_BSD_MAP_FLAGMA= SK); - break; } - printf("fd=3D%d offset=3D" TARGET_FMT_lx "\n", fd, offset); + if (flags & MAP_NOCORE) { + printf("MAP_NOCORE "); + } +#ifdef MAP_STACK + if (flags & MAP_STACK) { + printf("MAP_STACK "); + } +#endif + printf("fd=3D%d offset=3D0x%llx\n", fd, offset); } #endif =20 @@ -399,7 +418,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, page_set_flags(start, start + len, prot | PAGE_VALID); the_end: #ifdef DEBUG_MMAP - printf("ret=3D0x" TARGET_FMT_lx "\n", start); + printf("ret=3D0x" TARGET_ABI_FMT_lx "\n", start); page_dump(stdout); printf("\n"); #endif @@ -416,7 +435,9 @@ int target_munmap(abi_ulong start, abi_ulong len) int prot, ret; =20 #ifdef DEBUG_MMAP - printf("munmap: start=3D0x%lx len=3D0x%lx\n", start, len); + printf("munmap: start=3D0x" TARGET_ABI_FMT_lx " len=3D0x" + TARGET_ABI_FMT_lx "\n", + start, len); #endif if (start & ~TARGET_PAGE_MASK) return -EINVAL; --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053521302342.1217928532699; Tue, 7 Sep 2021 15:25:21 -0700 (PDT) Received: from localhost ([::1]:57986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjWq-000782-8n for importer@patchew.org; Tue, 07 Sep 2021 18:25:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2j-0006GT-1E for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:13 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:38562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2g-00015N-I6 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:12 -0400 Received: by mail-io1-xd42.google.com with SMTP id a13so464852iol.5 for ; Tue, 07 Sep 2021 14:54:09 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LNbH1I77zy3cQ+KkOf+Ir3agYJUL7LCubRGwYCm4scg=; b=RW+OSXaXxKd4JQH4B91wEBmkzKuI6nLlIHYE9kGiK0bkX4xsUiMQE+BRXjpYS+11Rk qfH+uL6O9VuDyEuqN1kTU5cukUy7CTHFbNL3QcmXARfLKcJxPd4c5BjzCPzGM4QRSTDJ pALl8DhwtTKeOjmGNvU/JRtWkcUBXULgixbm0IUrUx2MK5O04opthMwItWvpD1/2vHQ+ v2PZVDsB2YQbMC66cwn/eYSKuiADUbgB4KUcB0fuW2RztDNjaZWiQUYQ4orHCxVS8WSx SHQnJ9KeAzAbdVWu1E1XmuhnwljenC/x2AdqtfzWnBVSfmWnpbtsgemDx+A1oIbtBNlh uJwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LNbH1I77zy3cQ+KkOf+Ir3agYJUL7LCubRGwYCm4scg=; b=UQpWoy0F74LJ5zCIbEZ50hI33kGQ7DULc/d0IQltPfdVRvTLHxxhBJY5Pmf73FWmgI au+Mp0+4N/9449FWCKeZyEzJ5/q8JspWcUJtCDYKgFtkIetSWJgezZyc99eKCM63gKkR 141vAezJvhq90SMfZdLUS3VSoZ4B/uVv6iSiZ4xPbu0OkAKttjQB0zbl7t65jfOpLYEt /C6t8rFYTUrr3CRQIYKbypSrV25leouXbEZnZpNL29M9sTvQiuBap7O9bo9sW+ePMBaL 7AbGtNHsk9+NxxXz5mgIpAU3hUHMpaGMh9MDKlhFcfNMVVSOPm3LP3qdiXvFE4emk/fY 4yDw== X-Gm-Message-State: AOAM530xoxfVpKAEWULu59/Z/PawjTdVYwSc27ahyU+8LGTAUdOu5DD3 9aUNxaDCSpoUaanUN5KRmpNSkHtPXj5PETh2SXs= X-Google-Smtp-Source: ABdhPJyXmSFFpDrj3nHhokdQG5Y3hlTuVDEiHOQesbvevFgDIQ6qWTHFkecpByiMetWFynsqlPsuqA== X-Received: by 2002:a5e:db06:: with SMTP id q6mr285155iop.129.1631051648873; Tue, 07 Sep 2021 14:54:08 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 34/42] bsd-user: Add target_arch_reg to describe a target's register set Date: Tue, 7 Sep 2021 15:53:24 -0600 Message-Id: <20210907215332.30737-35-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d42; envelope-from=imp@bsdimp.com; helo=mail-io1-xd42.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053522066100003 Content-Type: text/plain; charset="utf-8" From: Warner Losh target_reg_t is the normal register. target_fpreg_t is the floating point registers. target_copy_regs copies the registers out of CPU context for things like core dumps. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/i386/target_arch_reg.h | 82 +++++++++++++++++++++++++++ bsd-user/x86_64/target_arch_reg.h | 92 +++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 bsd-user/i386/target_arch_reg.h create mode 100644 bsd-user/x86_64/target_arch_reg.h diff --git a/bsd-user/i386/target_arch_reg.h b/bsd-user/i386/target_arch_re= g.h new file mode 100644 index 0000000000..1fce1daf01 --- /dev/null +++ b/bsd-user/i386/target_arch_reg.h @@ -0,0 +1,82 @@ +/* + * FreeBSD i386 register structures + * + * Copyright (c) 2015 Stacey Son + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_ARCH_REG_H_ +#define _TARGET_ARCH_REG_H_ + +/* See sys/i386/include/reg.h */ +typedef struct target_reg { + uint32_t r_fs; + uint32_t r_es; + uint32_t r_ds; + uint32_t r_edi; + uint32_t r_esi; + uint32_t r_ebp; + uint32_t r_isp; + uint32_t r_ebx; + uint32_t r_edx; + uint32_t r_ecx; + uint32_t r_eax; + uint32_t r_trapno; + uint32_t r_err; + uint32_t r_eip; + uint32_t r_cs; + uint32_t r_eflags; + uint32_t r_esp; + uint32_t r_ss; + uint32_t r_gs; +} target_reg_t; + +typedef struct target_fpreg { + uint32_t fpr_env[7]; + uint8_t fpr_acc[8][10]; + uint32_t fpr_ex_sw; + uint8_t fpr_pad[64]; +} target_fpreg_t; + +static inline void target_copy_regs(target_reg_t *regs, const CPUX86State = *env) +{ + + regs->r_fs =3D env->segs[R_FS].selector & 0xffff; + regs->r_es =3D env->segs[R_ES].selector & 0xffff; + regs->r_ds =3D env->segs[R_DS].selector & 0xffff; + + regs->r_edi =3D env->regs[R_EDI]; + regs->r_esi =3D env->regs[R_ESI]; + regs->r_ebp =3D env->regs[R_EBP]; + /* regs->r_isp =3D env->regs[R_ISP]; XXX */ + regs->r_ebx =3D env->regs[R_EBX]; + regs->r_edx =3D env->regs[R_EDX]; + regs->r_ecx =3D env->regs[R_ECX]; + regs->r_eax =3D env->regs[R_EAX]; + /* regs->r_trapno =3D env->regs[R_TRAPNO]; XXX */ + regs->r_err =3D env->error_code; /* XXX ? */ + regs->r_eip =3D env->eip; + + regs->r_cs =3D env->segs[R_CS].selector & 0xffff; + + regs->r_eflags =3D env->eflags; + regs->r_esp =3D env->regs[R_ESP]; + + regs->r_ss =3D env->segs[R_SS].selector & 0xffff; + regs->r_gs =3D env->segs[R_GS].selector & 0xffff; +} + +#endif /* !_TARGET_ARCH_REG_H_ */ diff --git a/bsd-user/x86_64/target_arch_reg.h b/bsd-user/x86_64/target_arc= h_reg.h new file mode 100644 index 0000000000..00e9624517 --- /dev/null +++ b/bsd-user/x86_64/target_arch_reg.h @@ -0,0 +1,92 @@ +/* + * FreeBSD amd64 register structures + * + * Copyright (c) 2015 Stacey Son + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_ARCH_REG_H_ +#define _TARGET_ARCH_REG_H_ + +/* See sys/amd64/include/reg.h */ +typedef struct target_reg { + uint64_t r_r15; + uint64_t r_r14; + uint64_t r_r13; + uint64_t r_r12; + uint64_t r_r11; + uint64_t r_r10; + uint64_t r_r9; + uint64_t r_r8; + uint64_t r_rdi; + uint64_t r_rsi; + uint64_t r_rbp; + uint64_t r_rbx; + uint64_t r_rdx; + uint64_t r_rcx; + uint64_t r_rax; + uint32_t r_trapno; + uint16_t r_fs; + uint16_t r_gs; + uint32_t r_err; + uint16_t r_es; + uint16_t r_ds; + uint64_t r_rip; + uint64_t r_cs; + uint64_t r_rflags; + uint64_t r_rsp; + uint64_t r_ss; +} target_reg_t; + +typedef struct target_fpreg { + uint64_t fpr_env[4]; + uint8_t fpr_acc[8][16]; + uint8_t fpr_xacc[16][16]; + uint64_t fpr_spare[12]; +} target_fpreg_t; + +static inline void target_copy_regs(target_reg_t *regs, const CPUX86State = *env) +{ + + regs->r_r15 =3D env->regs[15]; + regs->r_r14 =3D env->regs[14]; + regs->r_r13 =3D env->regs[13]; + regs->r_r12 =3D env->regs[12]; + regs->r_r11 =3D env->regs[11]; + regs->r_r10 =3D env->regs[10]; + regs->r_r9 =3D env->regs[9]; + regs->r_r8 =3D env->regs[8]; + regs->r_rdi =3D env->regs[R_EDI]; + regs->r_rsi =3D env->regs[R_ESI]; + regs->r_rbp =3D env->regs[R_EBP]; + regs->r_rbx =3D env->regs[R_EBX]; + regs->r_rdx =3D env->regs[R_EDX]; + regs->r_rcx =3D env->regs[R_ECX]; + regs->r_rax =3D env->regs[R_EAX]; + /* regs->r_trapno =3D env->regs[R_TRAPNO]; XXX */ + regs->r_fs =3D env->segs[R_FS].selector & 0xffff; + regs->r_gs =3D env->segs[R_GS].selector & 0xffff; + regs->r_err =3D env->error_code; /* XXX ? */ + regs->r_es =3D env->segs[R_ES].selector & 0xffff; + regs->r_ds =3D env->segs[R_DS].selector & 0xffff; + regs->r_rip =3D env->eip; + regs->r_cs =3D env->segs[R_CS].selector & 0xffff; + regs->r_rflags =3D env->eflags; + regs->r_rsp =3D env->regs[R_ESP]; + regs->r_ss =3D env->segs[R_SS].selector & 0xffff; +} + +#endif /* !_TARGET_ARCH_REG_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16310533042712.009584036383444; Tue, 7 Sep 2021 15:21:44 -0700 (PDT) Received: from localhost ([::1]:47478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjTL-00006u-5w for importer@patchew.org; Tue, 07 Sep 2021 18:21:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2l-0006PK-DZ for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:15 -0400 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]:35443) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2i-000186-Ha for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:15 -0400 Received: by mail-io1-xd43.google.com with SMTP id a15so485938iot.2 for ; Tue, 07 Sep 2021 14:54:12 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aK1vwiLGQrx/20e5uuXs9W42kVBUJFAZXD9PFttUnN4=; b=MqCgWn7AcAm1Yn1eZ5PrDkQqiqSkkCNJOVlDjxbOoOX3saAPtJywm2iUAUrkEnCQLS u82IT16v0rA76JsPKl5XZUEC1KLr9XdGccMgXO/BPackeCAOGqXmt3XN0S988ozMSSxI z8XvdEYauHj+F/7R7Ur9H7yMQmjXbcxwqMTGzkKVF3+CgPnvGHygBy/TGrW5veKEE0NE pMYq2OBjjc8Bgb2PKUJkZuLaoJEqbPu7Pd8nu6Fpv564aae00S0YOBRYvcwWPDlme7Ng HmEbvkN2fVb5xL1xfTpwtpNFXQ4nq19zXvF7ImHIb/V4dpkjwDAUqmKnx+mKp6RAc1w0 8pNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aK1vwiLGQrx/20e5uuXs9W42kVBUJFAZXD9PFttUnN4=; b=ZDI2lUakvvCWl2uZP9cMjTJ4u2H8cZYQEDjgLYa4rFIdZ1vGa+DbxDEqoyWVu1Ju8H JYlfSmbjOdsgs6xScZCMWMNmnLv10gqt3xvZ99esW9s89h8SVvG+/61R0LHSt0FzP7Of kCtQbBZCIvC70XPa+WIOYc/9LfD3/Kj54W18pqCpnzOVCBKXJ+RegZX9nwVEhTpMK8BM RlyuDjGlkkEbt5nDKM3l5kHne7Vjq6Quf0uf7UCzuUtGImWeOUmMuhoEICmjgcRWagtw ru5CdxelNDi776GGpsOCrlFYHLFJrBh/b7tDEsKBZUau1QYVYH6oOtJ13blzf2fN4D/7 Yz1A== X-Gm-Message-State: AOAM531mrICZtekXmfdCEouYNErYjv7ec+Vlbce0TvKY650Ym3HJ647w 5e5RsqP3qguadnpP/Pzmx4DJYkRb1iL6ewckMaU= X-Google-Smtp-Source: ABdhPJwN93mGyGz8nTD9/U1exkonjxaJly5goNDWA22nWU7uRgrnN1UXS98L8bOUIhomvbt87UYu0A== X-Received: by 2002:a02:6a24:: with SMTP id l36mr488046jac.24.1631051649920; Tue, 07 Sep 2021 14:54:09 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 35/42] bsd-user: Add target_os_user.h to capture the user/kernel structures Date: Tue, 7 Sep 2021 15:53:25 -0600 Message-Id: <20210907215332.30737-36-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d43; envelope-from=imp@bsdimp.com; helo=mail-io1-xd43.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal Meloun , Kyle Evans , Richard Henderson , Stacey Son , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053305598100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh This file evolved over the years to capture the user/kernel interfaces, including those that changed over time. Signed-off-by: Stacey Son Signed-off-by: Michal Meloun Signed-off-by: Warner Losh Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/freebsd/target_os_user.h | 427 ++++++++++++++++++++++++++++++ 1 file changed, 427 insertions(+) create mode 100644 bsd-user/freebsd/target_os_user.h diff --git a/bsd-user/freebsd/target_os_user.h b/bsd-user/freebsd/target_os= _user.h new file mode 100644 index 0000000000..95b1fa9f99 --- /dev/null +++ b/bsd-user/freebsd/target_os_user.h @@ -0,0 +1,427 @@ +/* + * sys/user.h definitions + * + * Copyright (c) 2015 Stacey D. Son (sson at FreeBSD) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef _TARGET_OS_USER_H_ +#define _TARGET_OS_USER_H_ + +/* + * from sys/priority.h + */ +struct target_priority { + uint8_t pri_class; /* Scheduling class. */ + uint8_t pri_level; /* Normal priority level. */ + uint8_t pri_native; /* Priority before propogation. */ + uint8_t pri_user; /* User priority based on p_cpu and p_nice= . */ +}; + +/* + * sys/caprights.h + */ +#define TARGET_CAP_RIGHTS_VERSION 0 + +typedef struct target_cap_rights { + uint64_t cr_rights[TARGET_CAP_RIGHTS_VERSION + 2]; +} target_cap_rights_t; + +/* + * From sys/_socketaddr_storage.h + * + */ +#define TARGET_SS_MAXSIZE 128U +#define TARGET_SS_ALIGNSIZE (sizeof(__int64_t)) +#define TARGET_SS_PAD1SIZE (TARGET_SS_ALIGNSIZE - sizeof(unsigned char)= - \ + sizeof(uint8_t)) +#define TARGET_SS_PAD2SIZE (TARGET_SS_MAXSIZE - sizeof(unsigned char) -= \ + sizeof(uint8_t) - TARGET_SS_PAD1SIZE - TARGET_SS_ALIGNSIZE) + +struct target_sockaddr_storage { + unsigned char ss_len; /* address length */ + uint8_t ss_family; /* address family */ + char __ss_pad1[TARGET_SS_PAD1SIZE]; + __int64_t __ss_align; /* force desired struct alignment */ + char __ss_pad2[TARGET_SS_PAD2SIZE]; +}; + +/* + * from sys/user.h + */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 +#define TARGET_KI_NSPARE_INT 2 +#elif defined(__FreeBSD_version) && __FreeBSD_version >=3D 1100000 +#define TARGET_KI_NSPARE_INT 4 +#elif defined(__FreeBSD_version) && __FreeBSD_version >=3D 1000000 +#define TARGET_KI_NSPARE_INT 7 +#else +#define TARGET_KI_NSPARE_INT 9 +#endif /* ! __FreeBSD_version >=3D 1000000 */ +#define TARGET_KI_NSPARE_LONG 12 +#define TARGET_KI_NSPARE_PTR 6 + +#define TARGET_WMESGLEN 8 +#define TARGET_LOCKNAMELEN 8 +#define TARGET_TDNAMLEN 16 +#define TARGET_COMMLEN 19 +#define TARGET_KI_EMULNAMELEN 16 +#define TARGET_KI_NGROUPS 16 +#define TARGET_LOGNAMELEN 17 +#define TARGET_LOGINCLASSLEN 17 + +#define TARGET_KF_TYPE_NONE 0 +#define TARGET_KF_TYPE_VNODE 1 +#define TARGET_KF_TYPE_SOCKET 2 +#define TARGET_KF_TYPE_PIPE 3 +#define TARGET_KF_TYPE_FIFO 4 +#define TARGET_KF_TYPE_KQUEUE 5 +#define TARGET_KF_TYPE_CRYPTO 6 +#define TARGET_KF_TYPE_MQUEUE 7 +#define TARGET_KF_TYPE_SHM 8 +#define TARGET_KF_TYPE_SEM 9 +#define TARGET_KF_TYPE_PTS 10 +#define TARGET_KF_TYPE_PROCDESC 11 +#define TARGET_KF_TYPE_DEV 12 +#define TARGET_KF_TYPE_UNKNOWN 255 + +struct target_kinfo_proc { + int32_t ki_structsize; /* size of this structure */ + int32_t ki_layout; /* reserved: layout identifier */ + abi_ulong ki_args; /* address of command arguments */ + abi_ulong ki_paddr; /* address of proc */ + abi_ulong ki_addr; /* kernel virtual addr of u-area */ + abi_ulong ki_tracep; /* pointer to trace file */ + abi_ulong ki_textvp; /* pointer to executable file */ + abi_ulong ki_fd; /* pointer to open file info */ + abi_ulong ki_vmspace; /* pointer to kernel vmspace struct */ + abi_ulong ki_wchan; /* sleep address */ + int32_t ki_pid; /* Process identifier */ + int32_t ki_ppid; /* parent process id */ + int32_t ki_pgid; /* process group id */ + int32_t ki_tpgid; /* tty process group id */ + int32_t ki_sid; /* Process session ID */ + int32_t ki_tsid; /* Terminal session ID */ + int16_t ki_jobc; /* job control counter */ + int16_t ki_spare_short1; /* unused (just here for alignment) */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + int32_t ki_tdev__freebsd11; /* controlling tty dev */ +#else + int32_t ki_tdev; /* controlling tty dev */ +#endif + target_sigset_t ki_siglist; /* Signals arrived but not delivered */ + target_sigset_t ki_sigmask; /* Current signal mask */ + target_sigset_t ki_sigignore; /* Signals being ignored */ + target_sigset_t ki_sigcatch; /* Signals being caught by user */ + + int32_t ki_uid; /* effective user id */ + int32_t ki_ruid; /* Real user id */ + int32_t ki_svuid; /* Saved effective user id */ + int32_t ki_rgid; /* Real group id */ + int32_t ki_svgid; /* Saved effective group id */ + int16_t ki_ngroups; /* number of groups */ + int16_t ki_spare_short2; /* unused (just here for alignment) */ + int32_t ki_groups[TARGET_KI_NGROUPS]; /* groups */ + + abi_long ki_size; /* virtual size */ + + abi_long ki_rssize; /* current resident set size in pages = */ + abi_long ki_swrss; /* resident set size before last swap = */ + abi_long ki_tsize; /* text size (pages) XXX */ + abi_long ki_dsize; /* data size (pages) XXX */ + abi_long ki_ssize; /* stack size (pages) */ + + uint16_t ki_xstat; /* Exit status for wait & stop signal = */ + uint16_t ki_acflag; /* Accounting flags */ + + uint32_t ki_pctcpu; /* %cpu for process during ki_swtime */ + + uint32_t ki_estcpu; /* Time averaged value of ki_cpticks */ + uint32_t ki_slptime; /* Time since last blocked */ + uint32_t ki_swtime; /* Time swapped in or out */ + uint32_t ki_cow; /* number of copy-on-write faults */ + uint64_t ki_runtime; /* Real time in microsec */ + + struct target_freebsd_timeval ki_start; /* starting time */ + struct target_freebsd_timeval ki_childtime; /* time used by process c= hildren */ + + abi_long ki_flag; /* P_* flags */ + abi_long ki_kiflag; /* KI_* flags (below) */ + int32_t ki_traceflag; /* Kernel trace points */ + char ki_stat; /* S* process status */ + int8_t ki_nice; /* Process "nice" value */ + char ki_lock; /* Process lock (prevent swap) count */ + char ki_rqindex; /* Run queue index */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1100000 + u_char ki_oncpu_old; /* Which cpu we are on (legacy) */ + u_char ki_lastcpu_old; /* Last cpu we were on (legacy) */ +#else + u_char ki_oncpu; /* Which cpu we are on */ + u_char ki_lastcpu; /* Last cpu we were on */ +#endif /* ! __FreeBSD_version >=3D 1100000 */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 900000 + char ki_tdname[TARGET_TDNAMLEN + 1]; /* thread name */ +#else + char ki_ocomm[TARGET_TDNAMLEN + 1]; /* thread name */ +#endif /* ! __FreeBSD_version >=3D 900000 */ + char ki_wmesg[TARGET_WMESGLEN + 1]; /* wchan message */ + char ki_login[TARGET_LOGNAMELEN + 1]; /* setlogin name */ + char ki_lockname[TARGET_LOCKNAMELEN + 1]; /* lock name */ + char ki_comm[TARGET_COMMLEN + 1]; /* command name */ + char ki_emul[TARGET_KI_EMULNAMELEN + 1]; /* emulation name */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 900000 + char ki_loginclass[TARGET_LOGINCLASSLEN + 1]; /* login class */ +#endif /* ! __FreeBSD_version >=3D 900000 */ + +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 900000 + char ki_sparestrings[50]; /* spare string space */ +#else + char ki_sparestrings[68]; /* spare string space */ +#endif /* ! __FreeBSD_version >=3D 900000 */ + int32_t ki_spareints[TARGET_KI_NSPARE_INT]; /* spare room for grow= th */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + uint64_t ki_tdev; /* controlling tty dev */ +#endif +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1100000 + int32_t ki_oncpu; /* Which cpu we are on */ + int32_t ki_lastcpu; /* Last cpu we were on */ + int32_t ki_tracer; /* Pid of tracing process */ +#endif /* __FreeBSD_version >=3D 1100000 */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 900000 + int32_t ki_flag2; /* P2_* flags */ + int32_t ki_fibnum; /* Default FIB number */ +#endif /* ! __FreeBSD_version >=3D 900000 */ + uint32_t ki_cr_flags; /* Credential flags */ + int32_t ki_jid; /* Process jail ID */ + int32_t ki_numthreads; /* XXXKSE number of threads in total */ + + int32_t ki_tid; /* XXXKSE thread id */ + + struct target_priority ki_pri; /* process priority */ + struct target_freebsd_rusage ki_rusage; /* process rusage statistics= */ + /* XXX - most fields in ki_rusage_ch are not (yet) filled in */ + struct target_freebsd_rusage ki_rusage_ch; /* rusage of children proc= esses */ + + + abi_ulong ki_pcb; /* kernel virtual addr of pcb */ + abi_ulong ki_kstack; /* kernel virtual addr of stack */ + abi_ulong ki_udata; /* User convenience pointer */ + abi_ulong ki_tdaddr; /* address of thread */ + + abi_ulong ki_spareptrs[TARGET_KI_NSPARE_PTR]; /* spare room for gro= wth */ + abi_long ki_sparelongs[TARGET_KI_NSPARE_LONG];/* spare room for gro= wth */ + abi_long ki_sflag; /* PS_* flags */ + abi_long ki_tdflags; /* XXXKSE kthread flag */ +}; + +struct target_kinfo_file { + int32_t kf_structsize; /* Variable size of record. */ + int32_t kf_type; /* Descriptor type. */ + int32_t kf_fd; /* Array index. */ + int32_t kf_ref_count; /* Reference count. */ + int32_t kf_flags; /* Flags. */ + int32_t kf_pad0; /* Round to 64 bit alignment. */ + int64_t kf_offset; /* Seek location. */ +#if defined(__FreeBSD_version) && __FreeBSD_version < 1200031 + int32_t kf_vnode_type; /* Vnode type. */ + int32_t kf_sock_domain; /* Socket domain. */ + int32_t kf_sock_type; /* Socket type. */ + int32_t kf_sock_protocol; /* Socket protocol. */ + struct target_sockaddr_storage kf_sa_local; /* Socket address. */ + struct target_sockaddr_storage kf_sa_peer; /* Peer address. */ +#endif +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 900000 + union { + struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + uint32_t kf_spareint; + /* Socket domain. */ + int kf_sock_domain0; + /* Socket type. */ + int kf_sock_type0; + /* Socket protocol. */ + int kf_sock_protocol0; + /* Socket address. */ + struct sockaddr_storage kf_sa_local; + /* Peer address. */ + struct sockaddr_storage kf_sa_peer; +#endif + /* Address of so_pcb. */ + uint64_t kf_sock_pcb; + /* Address of inp_ppcb. */ + uint64_t kf_sock_inpcb; + /* Address of unp_conn. */ + uint64_t kf_sock_unpconn; + /* Send buffer state. */ + uint16_t kf_sock_snd_sb_state; + /* Receive buffer state. */ + uint16_t kf_sock_rcv_sb_state; + /* Round to 64 bit alignment. */ + uint32_t kf_sock_pad0; + } kf_sock; + struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + /* Vnode type. */ + int kf_file_type; + /* Space for future use */ + int kf_spareint[3]; + uint64_t kf_spareint64[30]; + /* Vnode filesystem id. */ + uint64_t kf_file_fsid; + /* File device. */ + uint64_t kf_file_rdev; + /* Global file id. */ + uint64_t kf_file_fileid; + /* File size. */ + uint64_t kf_file_size; + /* Vnode filesystem id, FreeBSD 11 compat. */ + uint32_t kf_file_fsid_freebsd11; + /* File device, FreeBSD 11 compat. */ + uint32_t kf_file_rdev_freebsd11; +#else + /* Global file id. */ + uint64_t kf_file_fileid; + /* File size. */ + uint64_t kf_file_size; + /* Vnode filesystem id. */ + uint32_t kf_file_fsid; + /* File device. */ + uint32_t kf_file_rdev; +#endif + /* File mode. */ + uint16_t kf_file_mode; + /* Round to 64 bit alignment. */ + uint16_t kf_file_pad0; + uint32_t kf_file_pad1; + } kf_file; + struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + uint32_t kf_spareint[4]; + uint64_t kf_spareint64[32]; +#endif + uint32_t kf_sem_value; + uint16_t kf_sem_mode; + } kf_sem; + struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + uint32_t kf_spareint[4]; + uint64_t kf_spareint64[32]; +#endif + uint64_t kf_pipe_addr; + uint64_t kf_pipe_peer; + uint32_t kf_pipe_buffer_cnt; + /* Round to 64 bit alignment. */ + uint32_t kf_pipe_pad0[3]; + } kf_pipe; + struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + uint32_t kf_spareint[4]; + uint64_t kf_spareint64[32]; + uint32_t kf_pts_dev_freebsd11; + uint32_t kf_pts_pad0; + uint64_t kf_pts_dev; + /* Round to 64 bit alignment. */ + uint32_t kf_pts_pad1[4]; +#else + uint32_t kf_pts_dev; + /* Round to 64 bit alignment. */ + uint32_t kf_pts_pad0[7]; +#endif + } kf_pts; + struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + uint32_t kf_spareint[4]; + uint64_t kf_spareint64[32]; +#endif + int32_t kf_pid; + } kf_proc; + } kf_un; + uint16_t kf_status; /* Status flags. */ + uint16_t kf_pad1; /* Round to 32 bit alignment. */ + int32_t _kf_ispare0; /* Space for more stuff. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1000000 + target_cap_rights_t kf_cap_rights; /* Capability rights. */ + uint64_t _kf_cap_spare; /* Space for future cap_rights_t. */ +#else /* ! __FreeBSD_version >=3D 1000000 */ + uint64_t kf_cap_rights; + int _kf_ispare[4]; +#endif /* ! __FreeBSD_version >=3D 1000000 */ + +#else /* ! __FreeBSD_version >=3D 900000 */ + int _kf_ispare[16]; +#endif /* ! __FreeBSD_version >=3D 900000 */ + /* Truncated before copyout in sysctl */ + char kf_path[PATH_MAX]; /* Path to file, if any. */ +}; + +struct target_kinfo_vmentry { + int32_t kve_structsize; /* Variable size of record. */ + int32_t kve_type; /* Type of map entry. */ + uint64_t kve_start; /* Starting address. */ + uint64_t kve_end; /* Finishing address. */ + uint64_t kve_offset; /* Mapping offset in object */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 900000 + uint64_t kve_vn_fileid; /* inode number if vnode */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + uint32_t kve_vn_fsid_freebsd11; /* dev_t of vnode location */ +#else + uint32_t kve_vn_fsid; /* dev_t of vnode location */ +#endif +#else /* ! __FreeBSD_version >=3D 900000 */ + uint64_t kve_fileid; /* inode number if vnode */ + uint32_t kve_fsid; /* dev_t of vnode location */ +#endif /* ! __FreeBSD_version >=3D 900000 */ + int32_t kve_flags; /* Flags on map entry. */ + int32_t kve_resident; /* Number of resident pages. */ + int32_t kve_private_resident; /* Number of private pages. */ + int32_t kve_protection; /* Protection bitmask. */ + int32_t kve_ref_count; /* VM obj ref count. */ + int32_t kve_shadow_count; /* VM obj shadow count. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 900000 + int32_t kve_vn_type; /* Vnode type. */ + uint64_t kve_vn_size; /* File size. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 + uint32_t kve_vn_rdev_freebsd11; /* Device id if device. */ +#else + uint32_t kve_vn_rdev; /* Device id if device. */ +#endif + uint16_t kve_vn_mode; /* File mode. */ + uint16_t kve_status; /* Status flags. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=3D 1200031 +#if (__FreeBSD_version >=3D 1300501 && __FreeBSD_version < 1400000) || \ + __FreeBSD_version >=3D 1400009 + union { + uint64_t _kve_vn_fsid; /* dev_t of vnode location */ + uint64_t _kve_obj; /* handle of anon obj */ + } kve_type_spec; +#define kve_vn_fsid kve_type_spec._kve_vn_fsid +#define kve_obj kve_type_spec._kve_obj +#else + uint64_t kve_vn_fsid; /* dev_t of vnode location */ +#endif + uint64_t kve_vn_rdev; /* Device id if device. */ + int _kve_ispare[8]; /* Space for more stuff. */ +#else + int32_t _kve_ispare[12]; /* Space for more stuff. */ +#endif +#else /* ! __FreeBSD_version >=3D 900000 */ + int _kve_pad0; + int32_t _kve_ispare[16]; /* Space for more stuff. */ +#endif /* ! __FreeBSD_version >=3D 900000 */ + /* Truncated before copyout in sysctl */ + char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ +}; + +#endif /* ! _TARGET_OS_USER_H_ */ --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053672773689.9371840406192; Tue, 7 Sep 2021 15:27:52 -0700 (PDT) Received: from localhost ([::1]:33964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjZH-0001eG-Op for importer@patchew.org; Tue, 07 Sep 2021 18:27:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2j-0006Iz-Lx for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:13 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]:34528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2h-00017B-P7 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:13 -0400 Received: by mail-io1-xd30.google.com with SMTP id y18so492082ioc.1 for ; Tue, 07 Sep 2021 14:54:11 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G8945Zd8kDZW6p/UTjbT8SXhPAZvCOiuECeA3/aKaO8=; b=HrcGJcO1VJRDIBYP8IQH+c3ioNb8xWbLdnoQP5DvwJ64pUX7l25EuLiN83PYUxvUWb cCMZ1b+uMozS5lNVUa7m9WdH0OsTbn0irmL7GJIlgiGOfLjB+mQ6AXIyhwnjdS9cEHlm bwhY3AueX4QCYF5Pxb2wHF4f1PKt85ptoYVx23cbbobkprWDvQ1JhTU6SZXC7e86Keq8 4mexbaEodfK+Q8Ju2LgdW7tsdNYVLFZlydY/anIVDdtJI6R3xaQQHW0QFLZ4IEB77X3u aPH+cbC/gjQcmmcmGHD9l8OPg9iZPeXmGcG5ZbtOLd2l085azjLgGegwx51htb4g0oEt V1uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G8945Zd8kDZW6p/UTjbT8SXhPAZvCOiuECeA3/aKaO8=; b=H7LdEtKcQ2GY3mlkGZt9PFKilbN0viQ/XlaCXKidg0VrJU6+VBvBVm5ZmrO53CqoT6 v/EDTqIMhTsKXVLLLDZTirl190FGrsXfsKIPRvR2dT72WLDGDOBr9hdpIpX5gde0Ej8S uEKatPxteoe6h7vA7FnnL5wk30e1f8WZIAj1orW7kVXboVJeMu0SNIxClu8jCHBw87WH 53G4phAHz+LzoKsDqv5Oi5E/zumCntVuF5YDJn47trBSt7PfFTuNm1oHS07iNUcFYFTY efWvSscGBljvHsHp1narQ25DV6wojzXSlKvt4aP4tQ9xXyM9EHIv2JEYQlTIL5UWPAAY herQ== X-Gm-Message-State: AOAM532TSUhidbUTkRwy8Am0+x0dthm4mo6lzk957w9KhuHuslY4NtDj lQAGRUa9fFplj8EBB3gctMMOlJU6YW+exFNfMFU= X-Google-Smtp-Source: ABdhPJzz6Kx9ntnt6sNxP9i0AeHf82F4ZAmnLKTJjeLG2FLyjm5Uu0guscBnKm0LKWF15NRUUpM1XA== X-Received: by 2002:a5d:8484:: with SMTP id t4mr298781iom.126.1631051650532; Tue, 07 Sep 2021 14:54:10 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 36/42] bsd-user: add stubbed out core dump support Date: Tue, 7 Sep 2021 15:53:26 -0600 Message-Id: <20210907215332.30737-37-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053674757100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Add a stubbed-out version of the bsd-user fork's core dump support. This allows elfload.c to be almost the same between what's upstream and what's in qemu-project upstream w/o the burden of reviewing the core dump support. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfcore.c | 10 ++++++++++ bsd-user/elfload.c | 22 ++++++++++++++++++++-- bsd-user/qemu.h | 6 ++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 bsd-user/elfcore.c diff --git a/bsd-user/elfcore.c b/bsd-user/elfcore.c new file mode 100644 index 0000000000..c49d9280e2 --- /dev/null +++ b/bsd-user/elfcore.c @@ -0,0 +1,10 @@ +/* Stubbed out version of core dump support, explicitly in public domain */ + +static int elf_core_dump(int signr, CPUArchState *env) +{ + struct elf_note en =3D { 0 }; + + bswap_note(&en); + + return 0; +} diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 11ca813c7a..05751f3ce7 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -26,15 +26,17 @@ static abi_ulong target_auxents; /* Where the AUX entries are in target = */ static size_t target_auxents_sz; /* Size of AUX entries including AT_NUL= L */ =20 +#include "target_arch_reg.h" #include "target_os_elf.h" #include "target_os_stack.h" #include "target_os_thread.h" - -#include "elf.h" +#include "target_os_user.h" =20 abi_ulong target_stksiz; abi_ulong target_stkbas; =20 +static int elf_core_dump(int signr, CPUArchState *env); + static inline void memcpy_fromfs(void *to, const void *from, unsigned long= n) { memcpy(to, from, n); @@ -100,15 +102,25 @@ static void bswap_sym(struct elf_sym *sym) bswap16s(&sym->st_shndx); } =20 +static void bswap_note(struct elf_note *en) +{ + bswap32s(&en->n_namesz); + bswap32s(&en->n_descsz); + bswap32s(&en->n_type); +} + #else /* ! BSWAP_NEEDED */ =20 static void bswap_ehdr(struct elfhdr *ehdr) { } static void bswap_phdr(struct elf_phdr *phdr, int phnum) { } static void bswap_shdr(struct elf_shdr *shdr, int shnum) { } static void bswap_sym(struct elf_sym *sym) { } +static void bswap_note(struct elf_note *en) { } =20 #endif /* ! BSWAP_NEEDED */ =20 +#include "elfcore.c" + /* * 'copy_elf_strings()' copies argument/envelope strings from user * memory to free pages in kernel mem. These are in a format ready @@ -834,6 +846,12 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, =20 info->entry =3D elf_entry; =20 +#ifdef USE_ELF_CORE_DUMP + bprm->core_dump =3D &elf_core_dump; +#else + bprm->core_dump =3D NULL; +#endif + return 0; } =20 diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 3685156123..8d20554688 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -51,6 +51,7 @@ extern enum BSDType bsd_type; * kernel */ struct image_info { + abi_ulong load_bias; abi_ulong load_addr; abi_ulong start_code; abi_ulong end_code; @@ -65,6 +66,9 @@ struct image_info { abi_ulong entry; abi_ulong code_offset; abi_ulong data_offset; + abi_ulong arg_start; + abi_ulong arg_end; + uint32_t elf_flags; }; =20 #define MAX_SIGQUEUE_SIZE 1024 @@ -132,6 +136,7 @@ struct bsd_binprm { char **envp; char *filename; /* (Given) Name of binary */ char *fullpath; /* Full path of binary */ + int (*core_dump)(int, CPUArchState *); }; =20 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); @@ -145,6 +150,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, struct image_info *info); int load_flt_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, struct image_info *info); +int is_target_elf_binary(int fd); =20 abi_long memcpy_to_target(abi_ulong dest, const void *src, unsigned long len); --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163105314712499.81338119802263; Tue, 7 Sep 2021 15:19:07 -0700 (PDT) Received: from localhost ([::1]:41022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjQn-0004Bl-Um for importer@patchew.org; Tue, 07 Sep 2021 18:19:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2l-0006OG-6c for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:15 -0400 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]:38869) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2i-00018D-MS for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:14 -0400 Received: by mail-io1-xd2c.google.com with SMTP id a13so464959iol.5 for ; Tue, 07 Sep 2021 14:54:12 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CR10JlOlEAQKf3unljvg+q/iEV0fpRG0cHSgOERU434=; b=mK/Kp6/nPrJzQgaZXkh2e//dX28ZKvrhkBRzU6OOIoLQta7TCjNJ4h2zGQukt7hXvg G0VQJpGCACa3GAKvjMaM6ArBcmUcr8HqzfOPpjvkR6asXeNzFd3izXNvZNCejsoGiH2U yhJ2SLuT5JUkeeCR7RHFIKBxwjKHI5FQWF9vo5RpBDl9e86hmg3C4AOxV3lEN/R6Befd GrHqj0WzjwXbA0pc4iTMVFOflPb7viC9CntQC67b1j1hNNo57lVUzGib9rOrDOGQRc/3 yIqAmRarfRPC8gN78XoYUP2SvPw/08RdG6hOJPyLHbzexv39S9hEjgQJt7qq7i5MCAEb HhqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CR10JlOlEAQKf3unljvg+q/iEV0fpRG0cHSgOERU434=; b=ub/y6T2NAbxzYzSoG9Gla+O+VkOAIdGuXytWZrXBxeXKHbu5hztkS34RC+D0FeTSDm DCwqER6yuzmpxVLZmOE8hgemDq9xvlZZbrM0Cij81sUEyujAABI8j84JjXcJlrqrpw1g IVPRjtWnQGB3zdNDc2p+poOWASu9OFc+V17xIHhIv9qpNhzfGpBAGnM2AqGOa+T6tMa6 ATBoRrCr7utfw7A09T5mza3RS28FRdpPLpyv7yI/l8B2LZ5pVgOMXQ17rCIqB/F/YKiJ 2XoHL57ZwFIQPkwpNVc+hWQbZEZxes/I8QSd0l9Lbvd0C/+xPGP6l/oIL/UPf55ZcVCg h8pg== X-Gm-Message-State: AOAM5313QQnqPfJrGnM+lY7M4sFuNv1Rko8Prt8NnZWfa2EyYie6u2H1 QjUbViEMLnFDS+VhsMRQ2naujLx/Fl+xY9VRA4E= X-Google-Smtp-Source: ABdhPJz3o5Jzc29DvRzNyo/S14B7xqm4P0ViXujiIy3dPOG0xsilmoAPKybvFiyL24Z25PdU4I+ceQ== X-Received: by 2002:a05:6638:348e:: with SMTP id t14mr489963jal.66.1631051651301; Tue, 07 Sep 2021 14:54:11 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 37/42] bsd-user: elfload.c style catch up patch Date: Tue, 7 Sep 2021 15:53:27 -0600 Message-Id: <20210907215332.30737-38-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d2c; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2c.google.com X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053147704100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Various style fixes to elfload.c that were too painful to make earlier in this series. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 208 ++++++++++++++++++++++----------------------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 05751f3ce7..3660961582 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -143,10 +143,12 @@ static abi_ulong copy_elf_strings(int argc, char **ar= gv, void **page, exit(-1); } tmp1 =3D tmp; - while (*tmp++); + while (*tmp++) { + continue; + } len =3D tmp - tmp1; if (p < len) { /* this shouldn't happen - 128kB */ - return 0; + return 0; } while (len) { --p; --tmp; --len; @@ -156,14 +158,14 @@ static abi_ulong copy_elf_strings(int argc, char **ar= gv, void **page, if (!pag) { pag =3D g_try_malloc0(TARGET_PAGE_SIZE); page[p / TARGET_PAGE_SIZE] =3D pag; - if (!pag) + if (!pag) { return 0; + } } } if (len =3D=3D 0 || offset =3D=3D 0) { *(pag + offset) =3D *tmp; - } - else { + } else { int bytes_to_copy =3D (len > offset) ? offset : len; tmp -=3D bytes_to_copy; p -=3D bytes_to_copy; @@ -182,16 +184,14 @@ static void setup_arg_pages(struct bsd_binprm *bprm, = struct image_info *info, abi_ulong stack_base, size; abi_long addr; =20 - /* Create enough stack to hold everything. If we don't use - * it for args, we'll use it for something else... + /* + * Create enough stack to hold everything. If we don't use it for arg= s, + * we'll use it for something else... */ size =3D target_dflssiz; stack_base =3D TARGET_USRSTACK - size; - addr =3D target_mmap(stack_base, - size + qemu_host_page_size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANON, - -1, 0); + addr =3D target_mmap(stack_base , size + qemu_host_page_size, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (addr =3D=3D -1) { perror("stk mmap"); exit(-1); @@ -210,55 +210,60 @@ static void setup_arg_pages(struct bsd_binprm *bprm, = struct image_info *info, =20 static void set_brk(abi_ulong start, abi_ulong end) { - /* page-align the start and end addresses... */ - start =3D HOST_PAGE_ALIGN(start); - end =3D HOST_PAGE_ALIGN(end); - if (end <=3D start) - return; - if (target_mmap(start, end - start, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) =3D=3D -= 1) { - perror("cannot mmap brk"); - exit(-1); - } + /* page-align the start and end addresses... */ + start =3D HOST_PAGE_ALIGN(start); + end =3D HOST_PAGE_ALIGN(end); + if (end <=3D start) { + return; + } + if (target_mmap(start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) =3D=3D -1) { + perror("cannot mmap brk"); + exit(-1); + } } =20 =20 -/* We need to explicitly zero any fractional pages after the data - section (i.e. bss). This would contain the junk from the file that - should not be in memory. */ +/* + * We need to explicitly zero any fractional pages after the data + * section (i.e. bss). This would contain the junk from the file that + * should not be in memory. + */ static void padzero(abi_ulong elf_bss, abi_ulong last_bss) { - abi_ulong nbyte; + abi_ulong nbyte; =20 - if (elf_bss >=3D last_bss) - return; + if (elf_bss >=3D last_bss) { + return; + } =20 - /* XXX: this is really a hack : if the real host page size is - smaller than the target page size, some pages after the end - of the file may not be mapped. A better fix would be to - patch target_mmap(), but it is more complicated as the file - size must be known */ - if (qemu_real_host_page_size < qemu_host_page_size) { - abi_ulong end_addr, end_addr1; - end_addr1 =3D REAL_HOST_PAGE_ALIGN(elf_bss); - end_addr =3D HOST_PAGE_ALIGN(elf_bss); - if (end_addr1 < end_addr) { - mmap((void *)g2h_untagged(end_addr1), end_addr - end_addr1, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); - } + /* + * XXX: this is really a hack : if the real host page size is + * smaller than the target page size, some pages after the end + * of the file may not be mapped. A better fix would be to + * patch target_mmap(), but it is more complicated as the file + * size must be known. + */ + if (qemu_real_host_page_size < qemu_host_page_size) { + abi_ulong end_addr, end_addr1; + end_addr1 =3D REAL_HOST_PAGE_ALIGN(elf_bss); + end_addr =3D HOST_PAGE_ALIGN(elf_bss); + if (end_addr1 < end_addr) { + mmap((void *)g2h_untagged(end_addr1), end_addr - end_addr1, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); } + } =20 - nbyte =3D elf_bss & (qemu_host_page_size - 1); - if (nbyte) { - nbyte =3D qemu_host_page_size - nbyte; - do { - /* FIXME - what to do if put_user() fails? */ - put_user_u8(0, elf_bss); - elf_bss++; - } while (--nbyte); - } + nbyte =3D elf_bss & (qemu_host_page_size - 1); + if (nbyte) { + nbyte =3D qemu_host_page_size - nbyte; + do { + /* FIXME - what to do if put_user() fails? */ + put_user_u8(0, elf_bss); + elf_bss++; + } while (--nbyte); + } } =20 static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, @@ -280,23 +285,23 @@ static abi_ulong load_elf_interp(struct elfhdr *inter= p_elf_ex, =20 bswap_ehdr(interp_elf_ex); /* First of all, some simple consistency checks */ - if ((interp_elf_ex->e_type !=3D ET_EXEC && - interp_elf_ex->e_type !=3D ET_DYN) || - !elf_check_arch(interp_elf_ex->e_machine)) { + if ((interp_elf_ex->e_type !=3D ET_EXEC && interp_elf_ex->e_type !=3D = ET_DYN) || + !elf_check_arch(interp_elf_ex->e_machine)) { return ~((abi_ulong)0UL); } =20 =20 /* Now read in all of the header information */ - - if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZ= E) + if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZ= E) { return ~(abi_ulong)0UL; + } =20 - elf_phdata =3D (struct elf_phdr *) - malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); + elf_phdata =3D (struct elf_phdr *) malloc(sizeof(struct elf_phdr) * + interp_elf_ex->e_phnum); =20 - if (!elf_phdata) + if (!elf_phdata) { return ~((abi_ulong)0UL); + } =20 /* * If the size of this structure has changed, then punt, since @@ -309,9 +314,8 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_= elf_ex, =20 retval =3D lseek(interpreter_fd, interp_elf_ex->e_phoff, SEEK_SET); if (retval >=3D 0) { - retval =3D read(interpreter_fd, - (char *) elf_phdata, - sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); + retval =3D read(interpreter_fd, (char *) elf_phdata, + sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); } if (retval < 0) { perror("load_elf_interp"); @@ -322,11 +326,12 @@ static abi_ulong load_elf_interp(struct elfhdr *inter= p_elf_ex, bswap_phdr(elf_phdata, interp_elf_ex->e_phnum); =20 if (interp_elf_ex->e_type =3D=3D ET_DYN) { - /* in order to avoid hardcoding the interpreter load - address in qemu, we allocate a big enough memory zone */ - error =3D target_mmap(0, INTERP_MAP_SIZE, - PROT_NONE, MAP_PRIVATE | MAP_ANON, - -1, 0); + /* + * In order to avoid hardcoding the interpreter load + * address in qemu, we allocate a big enough memory zone. + */ + error =3D target_mmap(0, INTERP_MAP_SIZE, PROT_NONE, + MAP_PRIVATE | MAP_ANON, -1, 0); if (error =3D=3D -1) { perror("mmap"); exit(-1); @@ -430,7 +435,7 @@ static const char *lookup_symbolxx(struct syminfo *s, t= arget_ulong orig_addr) struct elf_sym *syms =3D s->disas_symtab.elf64; #endif =20 - // binary search + /* binary search */ struct elf_sym *sym; =20 sym =3D bsearch(&orig_addr, syms, s->disas_num_syms, sizeof(*syms), sy= mfind); @@ -446,9 +451,8 @@ static int symcmp(const void *s0, const void *s1) { struct elf_sym *sym0 =3D (struct elf_sym *)s0; struct elf_sym *sym1 =3D (struct elf_sym *)s1; - return (sym0->st_value < sym1->st_value) - ? -1 - : ((sym0->st_value > sym1->st_value) ? 1 : 0); + return (sym0->st_value < sym1->st_value) ? -1 : + ((sym0->st_value > sym1->st_value) ? 1 : 0); } =20 /* Best attempt to load symbols from this ELF object. */ @@ -462,23 +466,24 @@ static void load_symbols(struct elfhdr *hdr, int fd) =20 lseek(fd, hdr->e_shoff, SEEK_SET); for (i =3D 0; i < hdr->e_shnum; i++) { - if (read(fd, &sechdr, sizeof(sechdr)) !=3D sizeof(sechdr)) + if (read(fd, &sechdr, sizeof(sechdr)) !=3D sizeof(sechdr)) { return; + } bswap_shdr(&sechdr, 1); if (sechdr.sh_type =3D=3D SHT_SYMTAB) { symtab =3D sechdr; - lseek(fd, hdr->e_shoff - + sizeof(sechdr) * sechdr.sh_link, SEEK_SET); - if (read(fd, &strtab, sizeof(strtab)) - !=3D sizeof(strtab)) + lseek(fd, hdr->e_shoff + sizeof(sechdr) * sechdr.sh_link, + SEEK_SET); + if (read(fd, &strtab, sizeof(strtab)) !=3D sizeof(strtab)) { return; + } bswap_shdr(&strtab, 1); goto found; } } return; /* Shouldn't happen... */ =20 - found: +found: /* Now know where the strtab and symtab are. Snarf them. */ s =3D malloc(sizeof(*s)); syms =3D malloc(symtab.sh_size); @@ -506,7 +511,7 @@ static void load_symbols(struct elfhdr *hdr, int fd) i =3D 0; while (i < nsyms) { bswap_sym(syms + i); - // Throw away entries which we do not need. + /* Throw away entries which we do not need. */ if (syms[i].st_shndx =3D=3D SHN_UNDEF || syms[i].st_shndx >=3D SHN_LORESERVE || ELF_ST_TYPE(syms[i].st_info) !=3D STT_FUNC) { @@ -519,10 +524,12 @@ static void load_symbols(struct elfhdr *hdr, int fd) i++; } =20 - /* Attempt to free the storage associated with the local symbols - that we threw away. Whether or not this has any effect on the - memory allocation depends on the malloc implementation and how - many symbols we managed to discard. */ + /* + * Attempt to free the storage associated with the local symbols + * that we threw away. Whether or not this has any effect on the + * memory allocation depends on the malloc implementation and how + * many symbols we managed to discard. + */ new_syms =3D realloc(syms, nsyms * sizeof(*syms)); if (new_syms =3D=3D NULL) { free(s); @@ -578,19 +585,19 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, =20 /* First of all, some simple consistency checks */ if ((elf_ex.e_type !=3D ET_EXEC && elf_ex.e_type !=3D ET_DYN) || - (!elf_check_arch(elf_ex.e_machine))) { + (!elf_check_arch(elf_ex.e_machine))) { return -ENOEXEC; } =20 bprm->p =3D copy_elf_strings(1, &bprm->filename, bprm->page, bprm->p); - bprm->p =3D copy_elf_strings(bprm->envc, bprm->envp, bprm->page,bprm->= p); - bprm->p =3D copy_elf_strings(bprm->argc, bprm->argv, bprm->page,bprm->= p); + bprm->p =3D copy_elf_strings(bprm->envc, bprm->envp, bprm->page, bprm-= >p); + bprm->p =3D copy_elf_strings(bprm->argc, bprm->argv, bprm->page, bprm-= >p); if (!bprm->p) { retval =3D -E2BIG; } =20 /* Now read in all of the header information */ - elf_phdata =3D (struct elf_phdr *)malloc(elf_ex.e_phentsize*elf_ex.e_p= hnum); + elf_phdata =3D (struct elf_phdr *)malloc(elf_ex.e_phentsize * elf_ex.e= _phnum); if (elf_phdata =3D=3D NULL) { return -ENOMEM; } @@ -609,7 +616,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, } =20 bswap_phdr(elf_phdata, elf_ex.e_phnum); - elf_ppnt =3D elf_phdata; =20 elf_bss =3D 0; @@ -622,23 +628,16 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, start_data =3D 0; end_data =3D 0; =20 - for (i =3D 0;i < elf_ex.e_phnum; i++) { + for (i =3D 0; i < elf_ex.e_phnum; i++) { if (elf_ppnt->p_type =3D=3D PT_INTERP) { - if (elf_interpreter !=3D NULL) - { + if (elf_interpreter !=3D NULL) { free(elf_phdata); free(elf_interpreter); close(bprm->fd); return -EINVAL; } =20 - /* This is the program interpreter used for - * shared libraries - for now assume that this - * is an a.out format binary - */ - elf_interpreter =3D (char *)malloc(elf_ppnt->p_filesz); - if (elf_interpreter =3D=3D NULL) { free(elf_phdata); close(bprm->fd); @@ -658,8 +657,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, retval =3D open(path(elf_interpreter), O_RDONLY); if (retval >=3D 0) { interpreter_fd =3D retval; - } - else { + } else { perror(elf_interpreter); exit(-1); /* retval =3D -errno; */ @@ -673,7 +671,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, } } if (retval >=3D 0) { - interp_elf_ex =3D *((struct elfhdr *) bprm->buf); /* elf e= xec-header */ + interp_elf_ex =3D *((struct elfhdr *) bprm->buf); } if (retval < 0) { perror("load_elf_binary3"); @@ -698,9 +696,10 @@ int load_elf_binary(struct bsd_binprm *bprm, struct ta= rget_pt_regs *regs, } } =20 - /* OK, we are done with that, now set up the arg stuff, - and then start this sucker up */ - + /* + * OK, we are done with that, now set up the arg stuff, and then start= this + * sucker up + */ if (!bprm->p) { free(elf_interpreter); free(elf_phdata); @@ -822,8 +821,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, =20 free(elf_phdata); =20 - if (qemu_log_enabled()) + if (qemu_log_enabled()) { load_symbols(&elf_ex, bprm->fd); + } =20 close(bprm->fd); =20 --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053789917189.22937828707052; Tue, 7 Sep 2021 15:29:49 -0700 (PDT) Received: from localhost ([::1]:36480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjbA-0003L5-8X for importer@patchew.org; Tue, 07 Sep 2021 18:29:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2m-0006T2-5c for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:16 -0400 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]:42830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2j-00019X-Of for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:15 -0400 Received: by mail-io1-xd2f.google.com with SMTP id b10so448367ioq.9 for ; Tue, 07 Sep 2021 14:54:13 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1hvbDDVDLB8bV56hPrTylG/XTnP573lDLx1A3kp56z4=; b=eoRZDre02blw8e3pEr2MLRq/vq5N3jMoKkgEmNtgo9EjdDubyxyyrNCDdRL3rd+2MW c/Lmo1Z8EvNBQZ4DXyT5uNESOrP+bBjJV8NSri9Tdhf7IaEaPZLoBcKiVudnK+hM5/+G UPOm0Q8dzTrKJ2ndOLaztI/WC4uqGndjCcZeUnk3YqzG9TMnB2RMTYwL2X5icv/Z/5xD 3i0cBrYytPnXi5RSq5v4vk98HT3jYp/AkKgJEBYNUOwNUC+1R3KhDhTwq103Y+sL6CQq qrjqD0YxbYhyOGrHOvPNpXfdBNs8xkRG2FM5wu2x08QozZ/J/ANHHyMxy2Q4cHOAwvg0 rFHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1hvbDDVDLB8bV56hPrTylG/XTnP573lDLx1A3kp56z4=; b=LdZDCnDv627ZwyLexLBasE6amaV1Gfa4AywaHgIyttKITzywRRz7P2llL1W1UruGG+ bmv6pZRQ8F3jxy3t6UDCwwDPrIqZ6G0qrO9fH+fL+ORoS+M12QVKmbN3JJszIEKT6ZBY JL0qtTgw93pINQHaNCRndrZb/0PLznPMmTSsvsrF7Jh0mAp7xrenZ5dnHVNZIXGkajyb WJNemSfe0kgQ1zp4Vkvnw9WqMZMdNncpr+4yrsb5Yv6rcYpUbzNm8ZQ1mhTKOS4f9Gic fZbAjTIVGaSPWJgNtjxRhImElrvAvc0s/z4AV7vvykaY6I8fEgViWb4sMsjfsgxaG7/e azqw== X-Gm-Message-State: AOAM530KivRvzxXUbuAeRqgqcVa1V/kDoxgu4r83/1a5sw7mrugOsx1q ftMOHrq+EOihRYcK7+6AfMkroucQROBXrcn5ePI= X-Google-Smtp-Source: ABdhPJxQwKcfXixw41GZjZXG50oIrqNmPIl6MzGZ9X0o5zpOY8Hio8eoK2wBPszIOMTBloTJMlxmBw== X-Received: by 2002:a05:6602:1210:: with SMTP id y16mr268893iot.159.1631051652276; Tue, 07 Sep 2021 14:54:12 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 38/42] bsd-user: Refactor load_elf_sections and is_target_elf_binary Date: Tue, 7 Sep 2021 15:53:28 -0600 Message-Id: <20210907215332.30737-39-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d2f; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , Warner Losh , Warner Losh , =?UTF-8?q?Mika=C3=ABl=20Urankar?= , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053790421100001 From: Warner Losh Factor out load_elf_sections and is_target_elf_binary out of load_elf_interp. Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Kyle Evans --- bsd-user/elfload.c | 344 +++++++++++++++++++++------------------------ 1 file changed, 158 insertions(+), 186 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 3660961582..142a5bfac2 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -36,6 +36,8 @@ abi_ulong target_stksiz; abi_ulong target_stkbas; =20 static int elf_core_dump(int signr, CPUArchState *env); +static int load_elf_sections(const struct elfhdr *hdr, struct elf_phdr *ph= dr, + int fd, abi_ulong rbase, abi_ulong *baddrp); =20 static inline void memcpy_fromfs(void *to, const void *from, unsigned long= n) { @@ -271,16 +273,10 @@ static abi_ulong load_elf_interp(struct elfhdr *inter= p_elf_ex, abi_ulong *interp_load_addr) { struct elf_phdr *elf_phdata =3D NULL; - struct elf_phdr *eppnt; - abi_ulong load_addr =3D 0; - int load_addr_set =3D 0; + abi_ulong rbase; int retval; - abi_ulong last_bss, elf_bss; - abi_ulong error; - int i; + abi_ulong baddr, error; =20 - elf_bss =3D 0; - last_bss =3D 0; error =3D 0; =20 bswap_ehdr(interp_elf_ex); @@ -325,93 +321,33 @@ static abi_ulong load_elf_interp(struct elfhdr *inter= p_elf_ex, } bswap_phdr(elf_phdata, interp_elf_ex->e_phnum); =20 + rbase =3D 0; if (interp_elf_ex->e_type =3D=3D ET_DYN) { /* * In order to avoid hardcoding the interpreter load * address in qemu, we allocate a big enough memory zone. */ - error =3D target_mmap(0, INTERP_MAP_SIZE, PROT_NONE, + rbase =3D target_mmap(0, INTERP_MAP_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0); - if (error =3D=3D -1) { + if (rbase =3D=3D -1) { perror("mmap"); exit(-1); } - load_addr =3D error; - load_addr_set =3D 1; - } - - eppnt =3D elf_phdata; - for (i =3D 0; i < interp_elf_ex->e_phnum; i++, eppnt++) - if (eppnt->p_type =3D=3D PT_LOAD) { - int elf_type =3D MAP_PRIVATE | MAP_DENYWRITE; - int elf_prot =3D 0; - abi_ulong vaddr =3D 0; - abi_ulong k; - - if (eppnt->p_flags & PF_R) elf_prot =3D PROT_READ; - if (eppnt->p_flags & PF_W) elf_prot |=3D PROT_WRITE; - if (eppnt->p_flags & PF_X) elf_prot |=3D PROT_EXEC; - if (interp_elf_ex->e_type =3D=3D ET_EXEC || load_addr_set) { - elf_type |=3D MAP_FIXED; - vaddr =3D eppnt->p_vaddr; - } - error =3D target_mmap(load_addr + TARGET_ELF_PAGESTART(vaddr), - eppnt->p_filesz + TARGET_ELF_PAGEOFFSET(ep= pnt->p_vaddr), - elf_prot, - elf_type, - interpreter_fd, - eppnt->p_offset - TARGET_ELF_PAGEOFFSET(ep= pnt->p_vaddr)); - - if (error =3D=3D -1) { - /* Real error */ - close(interpreter_fd); - free(elf_phdata); - return ~((abi_ulong)0UL); - } - - if (!load_addr_set && interp_elf_ex->e_type =3D=3D ET_DYN) { - load_addr =3D error; - load_addr_set =3D 1; - } - - /* - * Find the end of the file mapping for this phdr, and keep - * track of the largest address we see for this. - */ - k =3D load_addr + eppnt->p_vaddr + eppnt->p_filesz; - if (k > elf_bss) elf_bss =3D k; + } =20 - /* - * Do the same thing for the memory mapping - between - * elf_bss and last_bss is the bss section. - */ - k =3D load_addr + eppnt->p_memsz + eppnt->p_vaddr; - if (k > last_bss) last_bss =3D k; - } + error =3D load_elf_sections(interp_elf_ex, elf_phdata, interpreter_fd,= rbase, + &baddr); + if (error !=3D 0) { + perror("load_elf_sections"); + exit(-1); + } =20 /* Now use mmap to map the library into memory. */ - close(interpreter_fd); - - /* - * Now fill out the bss section. First pad the last page up - * to the page boundary, and then perform a mmap to make sure - * that there are zeromapped pages up to and including the last - * bss page. - */ - padzero(elf_bss, last_bss); - elf_bss =3D TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); /= * What we have mapped so far */ - - /* Map the last of the bss segment */ - if (last_bss > elf_bss) { - target_mmap(elf_bss, last_bss - elf_bss, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); - } free(elf_phdata); =20 - *interp_load_addr =3D load_addr; - return ((abi_ulong) interp_elf_ex->e_entry) + load_addr; + *interp_load_addr =3D baddr; + return ((abi_ulong) interp_elf_ex->e_entry) + rbase; } =20 static int symfind(const void *s0, const void *s1) @@ -521,6 +457,10 @@ found: } continue; } +#if defined(TARGET_ARM) || defined(TARGET_MIPS) + /* The bottom address bit marks a Thumb or MIPS16 symbol. */ + syms[i].st_value &=3D ~(target_ulong)1; +#endif i++; } =20 @@ -560,26 +500,119 @@ found: syminfos =3D s; } =20 +/* Check the elf header and see if this a target elf binary. */ +int is_target_elf_binary(int fd) +{ + uint8_t buf[128]; + struct elfhdr elf_ex; + + if (lseek(fd, 0L, SEEK_SET) < 0) { + return 0; + } + if (read(fd, buf, sizeof(buf)) < 0) { + return 0; + } + + elf_ex =3D *((struct elfhdr *)buf); + bswap_ehdr(&elf_ex); + + if ((elf_ex.e_type !=3D ET_EXEC && elf_ex.e_type !=3D ET_DYN) || + (!elf_check_arch(elf_ex.e_machine))) { + return 0; + } else { + return 1; + } +} + +static int +load_elf_sections(const struct elfhdr *hdr, struct elf_phdr *phdr, int fd, + abi_ulong rbase, abi_ulong *baddrp) +{ + struct elf_phdr *elf_ppnt; + abi_ulong baddr; + int i; + bool first; + + /* + * Now we do a little grungy work by mmaping the ELF image into + * the correct location in memory. At this point, we assume that + * the image should be loaded at fixed address, not at a variable + * address. + */ + first =3D true; + for (i =3D 0, elf_ppnt =3D phdr; i < hdr->e_phnum; i++, elf_ppnt++) { + int elf_prot =3D 0; + abi_ulong error; + + /* XXX Skip memsz =3D=3D 0. */ + if (elf_ppnt->p_type !=3D PT_LOAD) { + continue; + } + + if (elf_ppnt->p_flags & PF_R) { + elf_prot |=3D PROT_READ; + } + if (elf_ppnt->p_flags & PF_W) { + elf_prot |=3D PROT_WRITE; + } + if (elf_ppnt->p_flags & PF_X) { + elf_prot |=3D PROT_EXEC; + } + + error =3D target_mmap(TARGET_ELF_PAGESTART(rbase + elf_ppnt->p_vad= dr), + (elf_ppnt->p_filesz + + TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr)), + elf_prot, + (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE), + fd, + (elf_ppnt->p_offset - + TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr))); + if (error =3D=3D -1) { + perror("mmap"); + exit(-1); + } else if (elf_ppnt->p_memsz !=3D elf_ppnt->p_filesz) { + abi_ulong start_bss, end_bss; + + start_bss =3D rbase + elf_ppnt->p_vaddr + elf_ppnt->p_filesz; + end_bss =3D rbase + elf_ppnt->p_vaddr + elf_ppnt->p_memsz; + + /* + * Calling set_brk effectively mmaps the pages that we need fo= r the + * bss and break sections. + */ + set_brk(start_bss, end_bss); + padzero(start_bss, end_bss); + } + + if (first) { + baddr =3D TARGET_ELF_PAGESTART(rbase + elf_ppnt->p_vaddr); + first =3D false; + } + } + + if (baddrp !=3D NULL) { + *baddrp =3D baddr; + } + return 0; +} + int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, struct image_info *info) { struct elfhdr elf_ex; struct elfhdr interp_elf_ex; int interpreter_fd =3D -1; /* avoid warning */ - abi_ulong load_addr, load_bias; - int load_addr_set =3D 0; + abi_ulong load_addr; int i; - struct elf_phdr * elf_ppnt; + struct elf_phdr *elf_ppnt; struct elf_phdr *elf_phdata; - abi_ulong elf_bss, k, elf_brk; - int retval; - char * elf_interpreter; - abi_ulong elf_entry, interp_load_addr =3D 0; - abi_ulong start_code, end_code, start_data, end_data; + abi_ulong elf_brk; + int error, retval; + char *elf_interpreter; + abi_ulong baddr, elf_entry, et_dyn_addr, interp_load_addr =3D 0; abi_ulong reloc_func_desc =3D 0; =20 load_addr =3D 0; - load_bias =3D 0; elf_ex =3D *((struct elfhdr *) bprm->buf); /* exec-header */ bswap_ehdr(&elf_ex); =20 @@ -618,16 +651,10 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, bswap_phdr(elf_phdata, elf_ex.e_phnum); elf_ppnt =3D elf_phdata; =20 - elf_bss =3D 0; elf_brk =3D 0; =20 =20 elf_interpreter =3D NULL; - start_code =3D ~((abi_ulong)0UL); - end_code =3D 0; - start_data =3D 0; - end_data =3D 0; - for (i =3D 0; i < elf_ex.e_phnum; i++) { if (elf_ppnt->p_type =3D=3D PT_INTERP) { if (elf_interpreter !=3D NULL) { @@ -714,94 +741,45 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, info->mmap =3D 0; elf_entry =3D (abi_ulong) elf_ex.e_entry; =20 - /* Do this so that we can load the interpreter, if need be. We will - change some of these later */ + /* XXX Join this with PT_INTERP search? */ + baddr =3D 0; + for (i =3D 0, elf_ppnt =3D elf_phdata; i < elf_ex.e_phnum; i++, elf_pp= nt++) { + if (elf_ppnt->p_type !=3D PT_LOAD) { + continue; + } + baddr =3D elf_ppnt->p_vaddr; + break; + } + + et_dyn_addr =3D 0; + if (elf_ex.e_type =3D=3D ET_DYN && baddr =3D=3D 0) { + et_dyn_addr =3D ELF_ET_DYN_LOAD_ADDR; + } + + /* + * Do this so that we can load the interpreter, if need be. We will + * change some of these later + */ info->rss =3D 0; setup_arg_pages(bprm, info, &bprm->p, &bprm->stringp); info->start_stack =3D bprm->p; =20 - /* Now we do a little grungy work by mmaping the ELF image into - * the correct location in memory. At this point, we assume that - * the image should be loaded at fixed address, not at a variable - * address. - */ + info->elf_flags =3D elf_ex.e_flags; =20 + error =3D load_elf_sections(&elf_ex, elf_phdata, bprm->fd, et_dyn_addr, + &load_addr); for (i =3D 0, elf_ppnt =3D elf_phdata; i < elf_ex.e_phnum; i++, elf_pp= nt++) { - int elf_prot =3D 0; - int elf_flags =3D 0; - abi_ulong error; - - if (elf_ppnt->p_type !=3D PT_LOAD) + if (elf_ppnt->p_type !=3D PT_LOAD) { continue; - - if (elf_ppnt->p_flags & PF_R) elf_prot |=3D PROT_READ; - if (elf_ppnt->p_flags & PF_W) elf_prot |=3D PROT_WRITE; - if (elf_ppnt->p_flags & PF_X) elf_prot |=3D PROT_EXEC; - elf_flags =3D MAP_PRIVATE | MAP_DENYWRITE; - if (elf_ex.e_type =3D=3D ET_EXEC || load_addr_set) { - elf_flags |=3D MAP_FIXED; - } else if (elf_ex.e_type =3D=3D ET_DYN) { - /* Try and get dynamic programs out of the way of the default = mmap - base, as well as whatever program they might try to exec. = This - is because the brk will follow the loader, and is not movab= le. */ - /* NOTE: for qemu, we do a big mmap to get enough space - without hardcoding any address */ - error =3D target_mmap(0, ET_DYN_MAP_SIZE, - PROT_NONE, MAP_PRIVATE | MAP_ANON, - -1, 0); - if (error =3D=3D -1) { - perror("mmap"); - exit(-1); - } - load_bias =3D TARGET_ELF_PAGESTART(error - elf_ppnt->p_vaddr); } - - error =3D target_mmap(TARGET_ELF_PAGESTART(load_bias + elf_ppnt->p= _vaddr), - (elf_ppnt->p_filesz + - TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr)), - elf_prot, - (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE), - bprm->fd, - (elf_ppnt->p_offset - - TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr))); - if (error =3D=3D -1) { - perror("mmap"); - exit(-1); - } - - if (!load_addr_set) { - load_addr_set =3D 1; - load_addr =3D elf_ppnt->p_vaddr - elf_ppnt->p_offset; - if (elf_ex.e_type =3D=3D ET_DYN) { - load_bias +=3D error - - TARGET_ELF_PAGESTART(load_bias + elf_ppnt->p_vaddr); - load_addr +=3D load_bias; - reloc_func_desc =3D load_bias; - } - } - k =3D elf_ppnt->p_vaddr; - if (k < start_code) - start_code =3D k; - if (start_data < k) - start_data =3D k; - k =3D elf_ppnt->p_vaddr + elf_ppnt->p_filesz; - if (k > elf_bss) - elf_bss =3D k; - if ((elf_ppnt->p_flags & PF_X) && end_code < k) - end_code =3D k; - if (end_data < k) - end_data =3D k; - k =3D elf_ppnt->p_vaddr + elf_ppnt->p_memsz; - if (k > elf_brk) elf_brk =3D k; - } - - elf_entry +=3D load_bias; - elf_bss +=3D load_bias; - elf_brk +=3D load_bias; - start_code +=3D load_bias; - end_code +=3D load_bias; - start_data +=3D load_bias; - end_data +=3D load_bias; + if (elf_ppnt->p_memsz > elf_ppnt->p_filesz) + elf_brk =3D MAX(elf_brk, et_dyn_addr + elf_ppnt->p_vaddr + + elf_ppnt->p_memsz); + } + if (error !=3D 0) { + perror("load_elf_sections"); + exit(-1); + } =20 if (elf_interpreter) { elf_entry =3D load_elf_interp(&interp_elf_ex, interpreter_fd, @@ -817,6 +795,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct tar= get_pt_regs *regs, exit(-1); return 0; } + } else { + interp_load_addr =3D et_dyn_addr; + elf_entry +=3D interp_load_addr; } =20 free(elf_phdata); @@ -829,20 +810,11 @@ int load_elf_binary(struct bsd_binprm *bprm, struct t= arget_pt_regs *regs, =20 bprm->p =3D target_create_elf_tables(bprm->p, bprm->argc, bprm->envc, bprm->stringp, &elf_ex, load_addr, - load_bias, interp_load_addr, info); + et_dyn_addr, interp_load_addr, info= ); info->load_addr =3D reloc_func_desc; info->start_brk =3D info->brk =3D elf_brk; - info->end_code =3D end_code; - info->start_code =3D start_code; - info->start_data =3D start_data; - info->end_data =3D end_data; info->start_stack =3D bprm->p; - - /* Calling set_brk effectively mmaps the pages that we need for the bs= s and break - sections */ - set_brk(elf_bss, elf_brk); - - padzero(elf_bss, elf_brk); + info->load_bias =3D 0; =20 info->entry =3D elf_entry; =20 --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053446369112.31993647094339; Tue, 7 Sep 2021 15:24:06 -0700 (PDT) Received: from localhost ([::1]:53888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjVd-0004PI-Cp for importer@patchew.org; Tue, 07 Sep 2021 18:24:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2m-0006VL-Ks for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:16 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]:42834) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2k-0001A5-Hh for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:16 -0400 Received: by mail-io1-xd33.google.com with SMTP id b10so448406ioq.9 for ; Tue, 07 Sep 2021 14:54:14 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ckTKsGW/QnQijAk34vZp6jDIsYDaGSbM0MJQvmd7lmk=; b=0G+gPREqkLCSrbNsTKDHliojlX4XrJBFI6Iichfpyu+T9z1YXO1z8GZQzf/qgZX/DW wHoNDGdgmtSGAX2F/c5PyH6NS2u8sOEU1EHr7hOSTJujfcNUtjiylJbHFIGISYlo1fLS ToJ7daAKPuXqaQIoibnI5UyKLB0wb6fLREe/RuqfR6XcPD6HsYPfZc0I4Kj1PQe7P7kT hYkxqEnEb96y3Sn1tNlabeM4oh6Zr0rhJcd5rVayrbpigoNOUDmGXZty1jL07exIqwJ5 zV50SEjtlcSN6Dt8xIXPGJ78sMxgcj7lNTrSyL1RypbNu/YrTfp4yT5IWZDgQOAG0r+E 1p9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ckTKsGW/QnQijAk34vZp6jDIsYDaGSbM0MJQvmd7lmk=; b=HAX+90kdnHFyJ6qqRagwaa3P/fgKX8ezpnqjs7QPhC/amaoiWa6WW2tvcn/cMelul6 yuATj2ztoqIV3bB14vPWdtKPFJ5HXqpYbhCr69duX9W33BtjU91DZO1TCpTmpX910HrM dwpbqOS+w62b2qqViopohY8m/bQ6rTsSKYMXH4VoJlBvzSowvlS9eLAXnbu+m+wfaU5L vHS8o3hIRYh9qoeTcnrro9vGAUfLOPEwQIyE5S1CEynlv3+wgFuP2x513kskLwlz/k8C bJfBncRaJMisIouVF5Y0Ibt3Xqh/mgv9XWI9OOJuEnO+XpxMTYn2yAUIBcOcs9QzkQji j+TA== X-Gm-Message-State: AOAM532rxdOP17m9zu+236WkgG6Kn8yY5fCa58gOeyG/I7U1mx56/yy+ hHD6Bt2QpE4Jz2FF+Wz8TKEV34CWJoxXKwUn9sk= X-Google-Smtp-Source: ABdhPJxcaxmLjwhaoC8o4t+QAbd9nSeW0qTdrYHHPTOvglD5LpIIdIcz+1+hsAHuWDvRyYM5u6KP+w== X-Received: by 2002:a6b:be02:: with SMTP id o2mr275060iof.103.1631051653162; Tue, 07 Sep 2021 14:54:13 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 39/42] bsd-user: move gemu_log to later in the file Date: Tue, 7 Sep 2021 15:53:29 -0600 Message-Id: <20210907215332.30737-40-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d33; envelope-from=imp@bsdimp.com; helo=mail-io1-xd33.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , Richard Henderson , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053448447100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Signed-off-by: Warner Losh Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/main.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 71fd9d5aba..768f4ee41e 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -69,14 +69,6 @@ unsigned long target_dflssiz =3D TARGET_DFLSSIZ; /* in= itial data size limit */ unsigned long target_maxssiz =3D TARGET_MAXSSIZ; /* max stack size */ unsigned long target_sgrowsiz =3D TARGET_SGROWSIZ; /* amount to grow stack= */ =20 -void gemu_log(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); -} =20 void fork_start(void) { @@ -165,6 +157,15 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next =3D NULL; } =20 +void gemu_log(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + static void adjust_ssize(void) { --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053573101445.90437117470435; Tue, 7 Sep 2021 15:26:13 -0700 (PDT) Received: from localhost ([::1]:58882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjXg-0007iT-3e for importer@patchew.org; Tue, 07 Sep 2021 18:26:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2n-0006YU-Ht for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:17 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]:38873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2l-0001AU-Ab for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:17 -0400 Received: by mail-io1-xd30.google.com with SMTP id a13so465091iol.5 for ; Tue, 07 Sep 2021 14:54:14 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CxhQtk7C61C53+7/JcUhiUB/ovxqI2TDiE1M4q5e7Do=; b=uLBx45n3Mk4FSjFHzeH+rkffSE3x/a0KGg3Z6tPQG3iC8LvrOlMlH/9E0Hs1cxDFk5 WMAG3rvETHODxyAzR0O07dX89chsI59C0QRTPExvVNeOeVq7pIytwx1u9vcY7PrdXZcO EoPtYnX0AcWa5h2UnpSiPe8lBdDUa8MuodRoyS5ky+YZQNqKzfAXRODbFGjeNwsgfR8a YkJZsUh8VXv9Qbfb80/vxx06yGOy2dvWKOPSIARQCHkL/4FQM21ILkgvNbom18hu0WWh MIhw8hcLgi2jlgYTLhXha8HEy/q8kFCk4X4CjnnLmC7ft1sVHjTeM0hY0JXg2oiTunqm xU5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CxhQtk7C61C53+7/JcUhiUB/ovxqI2TDiE1M4q5e7Do=; b=PwOrS9juurzp4B1XpEeW2e6BfYPGi6umE8UMw7yQyiq5XSgSn06IqPtfjrlTXX0Tpj v/pj6gPru7En6gpfgiacUnbB7jINm62er0FpwJF2i8ISXgIxewn/FpJoqOvvMeZlTogw Ja9T1zcVphGSGuBf5HzoiKSezk1iQDH+wx3l4QSko1be88EEuOAv/vOnMEEVVtFLoDDF +QTZT9miLl/not/Nj8AUq/w+tFfalcvPsH/ML4at2UFzyuRbJkAIwvm1twPurNN+5T18 Fm0weD3WZfVqfQaMzJmkVbdf1+/Wz7w+INiVCllPL6NnRSE5IVmtgany4YOeCOsbT+pc nuXA== X-Gm-Message-State: AOAM5300zRcFjRQL2B2hP3G7f0s85pbWHD7gmMIrMaSFKdua8xwW+jEQ nKm9ZMYAKZk14a2OO20I0ELChP9vj+qIJf/8gSU= X-Google-Smtp-Source: ABdhPJx1F3U3eOZaCytAdJUUzH/43Aie9yZqOzzQsVr6NPa294uiP9GCN5DBs8uuWmvoEYM31n0QyQ== X-Received: by 2002:a02:90d0:: with SMTP id c16mr468011jag.106.1631051654110; Tue, 07 Sep 2021 14:54:14 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 40/42] bsd-user: Implement interlock for atomic operations Date: Tue, 7 Sep 2021 15:53:30 -0600 Message-Id: <20210907215332.30737-41-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d30; envelope-from=imp@bsdimp.com; helo=mail-io1-xd30.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Richard Henderson , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053573515100001 Content-Type: text/plain; charset="utf-8" From: Warner Losh Implement the internlock in fork_start() and fork_end() to properly cope with atomic operations and to safely keep state for parent and child processes. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 768f4ee41e..659dd2b512 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -69,15 +69,39 @@ unsigned long target_dflssiz =3D TARGET_DFLSSIZ; /* i= nitial data size limit */ unsigned long target_maxssiz =3D TARGET_MAXSSIZ; /* max stack size */ unsigned long target_sgrowsiz =3D TARGET_SGROWSIZ; /* amount to grow stack= */ =20 +/* Helper routines for implementing atomic operations. */ =20 void fork_start(void) { + start_exclusive(); + cpu_list_lock(); + mmap_fork_start(); } =20 void fork_end(int child) { if (child) { + CPUState *cpu, *next_cpu; + /* + * Child processes created by fork() only have a single thread. D= iscard + * information about the parent threads. + */ + CPU_FOREACH_SAFE(cpu, next_cpu) { + if (cpu !=3D thread_cpu) { + QTAILQ_REMOVE_RCU(&cpus, cpu, node); + } + } + mmap_fork_end(child); + /* + * qemu_init_cpu_list() takes care of reinitializing the exclusive + * state, so we don't need to end_exclusive() here. + */ + qemu_init_cpu_list(); gdbserver_fork(thread_cpu); + } else { + mmap_fork_end(child); + cpu_list_unlock(); + end_exclusive(); } } =20 --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053169817327.7678783494489; Tue, 7 Sep 2021 15:19:29 -0700 (PDT) Received: from localhost ([::1]:42238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjRA-0004yl-Q8 for importer@patchew.org; Tue, 07 Sep 2021 18:19:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2n-0006a2-UY for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:17 -0400 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]:44834) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2m-0001Ba-4a for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:17 -0400 Received: by mail-io1-xd2f.google.com with SMTP id g9so438703ioq.11 for ; Tue, 07 Sep 2021 14:54:15 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gZ1GIZjdhmw+PtxEgB45jDBjSRzqt+uOkvQ7QNISVeo=; b=e8ypGLfx3d253MFW0CzmQW+X645TF7Ab/A1Qrl7A6FVJ6WjKSkOcrlJi/iKuF+8hOX DRlK2ftFskSntezJsoH3kfjLlIvc1ZyENFZQP7huv1LBdA8k9DzPN0wVXPTAvWpTuBvq XD+9xl5otRRdkyw4FUfvd140sO1Q81skFlHi32DjEz5KsxUPGhNBoPKL3lueIh347aNU fL7ilYI0Iy3CN5hLA5Z/SaU/V9bwd6UvNsBImaQ/mm2SdQGPk8MrRBo4T6ktbAqE9eNH C/kEe12mrYxLQ2i93dxeNF3PfDTI1tHJGcFW4ZlscUi4WMZThFHR8KxQNBST+idcJiP1 /o6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gZ1GIZjdhmw+PtxEgB45jDBjSRzqt+uOkvQ7QNISVeo=; b=tj/RotregVnanyS0lVMkBYMfQKs220ci4vnqim0eOFZR7OGng6dZ9Izpb4ZHjwStY4 iyK4yrFJR1uRDX+FRhor2BDnuqk5IXtewDuxsIuGtBZLvsDG/h+AfMUIOw5d7RMdAhLA jw298WahLlqVuuZe3cpujmjzjPFuFvopfRr21jH8Rj7rqrML0vI+5t6+lKw57V1VCVgu aQZiwOXxDTOJVb0nodl5MpgvvDJGPWhnBE/wb4ifFDjdR/BmiF9nTHCdFZ+gFBKE5uQs CJ1AKjC3zb5XPAdLriuoGClai+/uhkwXdrM52RAN18DrLk76IEOGkHBRTh1XMwtHjYP3 Gamw== X-Gm-Message-State: AOAM533dwBisJ7uSMZddmZ2gJWHvjVEz5Z0p1LCMJbTLpTFgO7bzJKKe 4WcLYySghTvgQAW4xzq53wjZMDusPeBAU/aVQ8U= X-Google-Smtp-Source: ABdhPJwTdr/8ffZ9Qawgbngx+xw13yNU4mSJzdZuiigqtmDFA8uNA3ugj5JyGZf7GHh+aas328j01w== X-Received: by 2002:a05:6638:381e:: with SMTP id i30mr453640jav.9.1631051654850; Tue, 07 Sep 2021 14:54:14 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 41/42] bsd-user: Add '-0 argv0' option to bsd-user/main.c Date: Tue, 7 Sep 2021 15:53:31 -0600 Message-Id: <20210907215332.30737-42-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d2f; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Colin Percival , Richard Henderson , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053171362100001 Content-Type: text/plain; charset="utf-8" From: Colin Percival Previously it was impossible to emulate a program with a file name different from its argv[0]. With this change, you can run qemu -0 fakename realname args which runs the program "realname" with an argv of "fakename args". Signed-off-by: Colin Percival Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 659dd2b512..6df4f4f011 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -243,6 +243,7 @@ int main(int argc, char **argv) char **target_environ, **wrk; envlist_t *envlist =3D NULL; bsd_type =3D HOST_DEFAULT_BSD_TYPE; + char *argv0 =3D NULL; =20 adjust_ssize(); =20 @@ -367,6 +368,8 @@ int main(int argc, char **argv) do_strace =3D 1; } else if (!strcmp(r, "trace")) { trace_opt_parse(optarg); + } else if (!strcmp(r, "0")) { + argv0 =3D argv[optind++]; } else { usage(); } @@ -390,6 +393,9 @@ int main(int argc, char **argv) usage(); } filename =3D argv[optind]; + if (argv0) { + argv[optind] =3D argv0; + } =20 if (!trace_init_backends()) { exit(1); --=20 2.32.0 From nobody Sun Apr 28 19:21:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1631053949229164.51207920760885; Tue, 7 Sep 2021 15:32:29 -0700 (PDT) Received: from localhost ([::1]:38822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNjdk-00050p-01 for importer@patchew.org; Tue, 07 Sep 2021 18:32:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNj2q-0006jE-C7 for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:20 -0400 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]:34628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNj2n-0001CV-II for qemu-devel@nongnu.org; Tue, 07 Sep 2021 17:54:20 -0400 Received: by mail-io1-xd43.google.com with SMTP id y18so492446ioc.1 for ; Tue, 07 Sep 2021 14:54:17 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id t17sm192477iln.24.2021.09.07.14.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 14:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qx/VzLtbsVoiAcayWvMx8RQL5UeVXBQwPj1coyekThM=; b=VGLZ7DGKxvtjioO5IP71VJmWJ6s3uT6Fpimy3ztJijEtpvw4ReoxJLx5X+zObOlXy9 7eXex8zpKxEsUGruFQiy4W7TwMVic9xOEEh7IlrRTNxo/hCPk4TFIzLMuxyigLwSOH3K sehwn+42sMZ0n2B+wh+nocjlSsiEC+ZmeY3QQlUynKup0p+an4jULY6p6Y3I+piWugeG YHe+zLiDnQKFtXcnWh824yvfCZi2kjZsrG9/6ToZTETRz7CvBN3iu1y7kgLLAmkvJRIK OXhd1cz7cbbIUnrUwot+gjx/XstveznyDA/G60j7LmeLEnV+9nDUTSP8JjmYc7rM/Z1g cboA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qx/VzLtbsVoiAcayWvMx8RQL5UeVXBQwPj1coyekThM=; b=Mfy+WanOBIZIMU7OO6heoQ21SHPB+4EZKHJpdKpiidYBZXkWXecfpy+xNhpEfrWDD+ Q+WKO1OTmPCASlYbn0vIfv8w/fVAvaqqW6XQ+7EbGD/41jSW+9a+YxnPaDx9TlVA/pVD xEV4VHEBLjemWVnxPkuLE0OybaA8zYhQ6XgiQ+6krZBGaXM6Mt/QOw4GGYkxvdXSTGjZ vg3ZKmypWZ9tdNZBke9YA52qVjQj7zGnNQ/6DOkgANybtCO6jaCtEHZrrzZv8lLL3/02 k5M03U5DvR+n5ZgZUMu1FYZlGEogRBj6N5kzyqmZR7M8kionMeKevu/28Q/Vw1CXUstM QaAw== X-Gm-Message-State: AOAM533+URzNRDhURWZCxeLBKM/DrikOpf3QoSnJyQI+geNayBzx647i 1J7TNvpuinwygiHIRGgjt9JZsPoCQgCig9XZBO8= X-Google-Smtp-Source: ABdhPJxax/xCEW64Ifv5txff+qjdV0IvPqfErvyoc1OvP72/3mRTblx1FVmfqFDRPN/SXBR2+WPaDw== X-Received: by 2002:a6b:c80f:: with SMTP id y15mr306657iof.80.1631051656140; Tue, 07 Sep 2021 14:54:16 -0700 (PDT) From: imp@bsdimp.com To: qemu-devel@nongnu.org Subject: [PULL 42/42] bsd-user: Update mapping to handle reserved and starting conditions Date: Tue, 7 Sep 2021 15:53:32 -0600 Message-Id: <20210907215332.30737-43-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210907215332.30737-1-imp@bsdimp.com> References: <20210907215332.30737-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d43; envelope-from=imp@bsdimp.com; helo=mail-io1-xd43.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stacey Son , Kyle Evans , Richard Henderson , =?UTF-8?q?Mika=C3=ABl=20Urankar?= , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1631053951182100001 From: Warner Losh Update the reserved base based on what platform we're on, as well as the start of the mmap range. Update routines that find va ranges to interact with the reserved ranges as well as properly align the mapping (this is especially important for targets whose page size does not match the host's). Loop where appropriate when the initial address space offered by mmap does not meet the contraints. This has 18e80c55bb6 from linux-user folded in to the upstream bsd-user code as well. Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Stacey Son Signed-off-by: Warner Losh Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/main.c | 43 ++++- bsd-user/mmap.c | 415 ++++++++++++++++++++++++++++++++++++++++-------- bsd-user/qemu.h | 5 +- 3 files changed, 392 insertions(+), 71 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 6df4f4f011..48643eeabc 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -52,10 +52,47 @@ #include "target_arch_cpu.h" =20 int singlestep; -unsigned long mmap_min_addr; uintptr_t guest_base; bool have_guest_base; +/* + * When running 32-on-64 we should make sure we can fit all of the possible + * guest address space into a contiguous chunk of virtual host memory. + * + * This way we will never overlap with our own libraries or binaries or st= ack + * or anything else that QEMU maps. + * + * Many cpus reserve the high bit (or more than one for some 64-bit cpus) + * of the address for the kernel. Some cpus rely on this and user space + * uses the high bit(s) for pointer tagging and the like. For them, we + * must preserve the expected address space. + */ +#ifndef MAX_RESERVED_VA +# if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS +# if TARGET_VIRT_ADDR_SPACE_BITS =3D=3D 32 && \ + (TARGET_LONG_BITS =3D=3D 32 || defined(TARGET_ABI32)) +/* + * There are a number of places where we assign reserved_va to a variable + * of type abi_ulong and expect it to fit. Avoid the last page. + */ +# define MAX_RESERVED_VA (0xfffffffful & TARGET_PAGE_MASK) +# else +# define MAX_RESERVED_VA (1ul << TARGET_VIRT_ADDR_SPACE_BITS) +# endif +# else +# define MAX_RESERVED_VA 0 +# endif +#endif + +/* + * That said, reserving *too* much vm space via mmap can run into problems + * with rlimits, oom due to page table creation, etc. We will still try i= t, + * if directed by the command-line option, but not by default. + */ +#if HOST_LONG_BITS =3D=3D 64 && TARGET_VIRT_ADDR_SPACE_BITS <=3D 32 +unsigned long reserved_va =3D MAX_RESERVED_VA; +#else unsigned long reserved_va; +#endif =20 static const char *interp_prefix =3D CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; @@ -439,6 +476,10 @@ int main(int argc, char **argv) target_environ =3D envlist_to_environ(envlist, NULL); envlist_free(envlist); =20 + if (reserved_va) { + mmap_next_start =3D reserved_va; + } + { Error *err =3D NULL; if (seed_optarg !=3D NULL) { diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 8918c4ae68..b40ab9045f 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -188,64 +188,207 @@ static int mmap_frag(abi_ulong real_start, return 0; } =20 -static abi_ulong mmap_next_start =3D 0x40000000; +#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 64 +# define TASK_UNMAPPED_BASE (1ul << 38) +#else +# define TASK_UNMAPPED_BASE 0x40000000 +#endif +abi_ulong mmap_next_start =3D TASK_UNMAPPED_BASE; =20 unsigned long last_brk; =20 -/* find a free memory area of size 'size'. The search starts at - 'start'. If 'start' =3D=3D 0, then a default start address is used. - Return -1 if error. -*/ -/* page_init() marks pages used by the host as reserved to be sure not - to use them. */ -static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) +/* + * Subroutine of mmap_find_vma, used when we have pre-allocated a chunk of= guest + * address space. + */ +static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size, + abi_ulong alignment) { - abi_ulong addr, addr1, addr_start; + abi_ulong addr; + abi_ulong end_addr; int prot; - unsigned long new_brk; + int looped =3D 0; + + if (size > reserved_va) { + return (abi_ulong)-1; + } + + size =3D HOST_PAGE_ALIGN(size) + alignment; + end_addr =3D start + size; + if (end_addr > reserved_va) { + end_addr =3D reserved_va; + } + addr =3D end_addr - qemu_host_page_size; =20 - new_brk =3D (unsigned long)sbrk(0); - if (last_brk && last_brk < new_brk && last_brk =3D=3D (target_ulong)la= st_brk) { - /* This is a hack to catch the host allocating memory with brk(). - If it uses mmap then we loose. - FIXME: We really want to avoid the host allocating memory in - the first place, and maybe leave some slack to avoid switching - to mmap. */ - page_set_flags(last_brk & TARGET_PAGE_MASK, - TARGET_PAGE_ALIGN(new_brk), - PAGE_RESERVED); + while (1) { + if (addr > end_addr) { + if (looped) { + return (abi_ulong)-1; + } + end_addr =3D reserved_va; + addr =3D end_addr - qemu_host_page_size; + looped =3D 1; + continue; + } + prot =3D page_get_flags(addr); + if (prot) { + end_addr =3D addr; + } + if (end_addr - addr >=3D size) { + break; + } + addr -=3D qemu_host_page_size; + } + + if (start =3D=3D mmap_next_start) { + mmap_next_start =3D addr; + } + /* addr is sufficiently low to align it up */ + if (alignment !=3D 0) { + addr =3D (addr + alignment) & ~(alignment - 1); + } + return addr; +} + +/* + * Find and reserve a free memory area of size 'size'. The search + * starts at 'start'. + * It must be called with mmap_lock() held. + * Return -1 if error. + */ +static abi_ulong mmap_find_vma_aligned(abi_ulong start, abi_ulong size, + abi_ulong alignment) +{ + void *ptr, *prev; + abi_ulong addr; + int flags; + int wrapped, repeat; + + /* If 'start' =3D=3D 0, then a default start address is used. */ + if (start =3D=3D 0) { + start =3D mmap_next_start; + } else { + start &=3D qemu_host_page_mask; } - last_brk =3D new_brk; =20 size =3D HOST_PAGE_ALIGN(size); - start =3D start & qemu_host_page_mask; + + if (reserved_va) { + return mmap_find_vma_reserved(start, size, + (alignment !=3D 0 ? 1 << alignment : 0)); + } + addr =3D start; - if (addr =3D=3D 0) - addr =3D mmap_next_start; - addr_start =3D addr; - for (;;) { - prot =3D 0; - for (addr1 =3D addr; addr1 < (addr + size); addr1 +=3D TARGET_PAGE= _SIZE) { - prot |=3D page_get_flags(addr1); + wrapped =3D repeat =3D 0; + prev =3D 0; + flags =3D MAP_ANONYMOUS | MAP_PRIVATE; +#ifdef MAP_ALIGNED + if (alignment !=3D 0) { + flags |=3D MAP_ALIGNED(alignment); + } +#else + /* XXX TODO */ +#endif + + for (;; prev =3D ptr) { + /* + * Reserve needed memory area to avoid a race. + * It should be discarded using: + * - mmap() with MAP_FIXED flag + * - mremap() with MREMAP_FIXED flag + * - shmat() with SHM_REMAP flag + */ + ptr =3D mmap(g2h_untagged(addr), size, PROT_NONE, + flags, -1, 0); + + /* ENOMEM, if host address space has no memory */ + if (ptr =3D=3D MAP_FAILED) { + return (abi_ulong)-1; } - if (prot =3D=3D 0) - break; - addr +=3D qemu_host_page_size; - /* we found nothing */ - if (addr =3D=3D addr_start) + + /* + * Count the number of sequential returns of the same address. + * This is used to modify the search algorithm below. + */ + repeat =3D (ptr =3D=3D prev ? repeat + 1 : 0); + + if (h2g_valid(ptr + size - 1)) { + addr =3D h2g(ptr); + + if ((addr & ~TARGET_PAGE_MASK) =3D=3D 0) { + /* Success. */ + if (start =3D=3D mmap_next_start && addr >=3D TASK_UNMAPPE= D_BASE) { + mmap_next_start =3D addr + size; + } + return addr; + } + + /* The address is not properly aligned for the target. */ + switch (repeat) { + case 0: + /* + * Assume the result that the kernel gave us is the + * first with enough free space, so start again at the + * next higher target page. + */ + addr =3D TARGET_PAGE_ALIGN(addr); + break; + case 1: + /* + * Sometimes the kernel decides to perform the allocation + * at the top end of memory instead. + */ + addr &=3D TARGET_PAGE_MASK; + break; + case 2: + /* Start over at low memory. */ + addr =3D 0; + break; + default: + /* Fail. This unaligned block must the last. */ + addr =3D -1; + break; + } + } else { + /* + * Since the result the kernel gave didn't fit, start + * again at low memory. If any repetition, fail. + */ + addr =3D (repeat ? -1 : 0); + } + + /* Unmap and try again. */ + munmap(ptr, size); + + /* ENOMEM if we checked the whole of the target address space. */ + if (addr =3D=3D (abi_ulong)-1) { + return (abi_ulong)-1; + } else if (addr =3D=3D 0) { + if (wrapped) { + return (abi_ulong)-1; + } + wrapped =3D 1; + /* + * Don't actually use 0 when wrapping, instead indicate + * that we'd truly like an allocation in low memory. + */ + addr =3D TARGET_PAGE_SIZE; + } else if (wrapped && addr >=3D start) { return (abi_ulong)-1; + } } - if (start =3D=3D 0) - mmap_next_start =3D addr + size; - return addr; +} + +abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) +{ + return mmap_find_vma_aligned(start, size, 0); } =20 /* NOTE: all the constants are the HOST ones */ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, - int flags, int fd, abi_ulong offset) + int flags, int fd, off_t offset) { abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_l= en; - unsigned long host_start; =20 mmap_lock(); #ifdef DEBUG_MMAP @@ -294,43 +437,121 @@ abi_long target_mmap(abi_ulong start, abi_ulong len,= int prot, } #endif =20 + if ((flags & MAP_ANONYMOUS) && fd !=3D -1) { + errno =3D EINVAL; + goto fail; + } +#ifdef MAP_STACK + if (flags & MAP_STACK) { + if ((fd !=3D -1) || ((prot & (PROT_READ | PROT_WRITE)) !=3D + (PROT_READ | PROT_WRITE))) { + errno =3D EINVAL; + goto fail; + } + } +#endif /* MAP_STACK */ +#ifdef MAP_GUARD + if ((flags & MAP_GUARD) && (prot !=3D PROT_NONE || fd !=3D -1 || + offset !=3D 0 || (flags & (MAP_SHARED | MAP_PRIVATE | + /* MAP_PREFAULT | */ /* MAP_PREFAULT not in mman.h */ + MAP_PREFAULT_READ | MAP_ANON | MAP_STACK)) !=3D 0)) { + errno =3D EINVAL; + goto fail; + } +#endif + if (offset & ~TARGET_PAGE_MASK) { errno =3D EINVAL; goto fail; } =20 len =3D TARGET_PAGE_ALIGN(len); - if (len =3D=3D 0) - goto the_end; + if (len =3D=3D 0) { + errno =3D EINVAL; + goto fail; + } real_start =3D start & qemu_host_page_mask; + host_offset =3D offset & qemu_host_page_mask; =20 + /* + * If the user is asking for the kernel to find a location, do that + * before we truncate the length for mapping files below. + */ if (!(flags & MAP_FIXED)) { - abi_ulong mmap_start; - void *p; - host_offset =3D offset & qemu_host_page_mask; host_len =3D len + offset - host_offset; host_len =3D HOST_PAGE_ALIGN(host_len); - mmap_start =3D mmap_find_vma(real_start, host_len); - if (mmap_start =3D=3D (abi_ulong)-1) { + if ((flags & MAP_ALIGNMENT_MASK) !=3D 0) + start =3D mmap_find_vma_aligned(real_start, host_len, + (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); + else + start =3D mmap_find_vma(real_start, host_len); + if (start =3D=3D (abi_ulong)-1) { errno =3D ENOMEM; goto fail; } - /* Note: we prefer to control the mapping address. It is - especially important if qemu_host_page_size > - qemu_real_host_page_size */ - p =3D mmap(g2h_untagged(mmap_start), - host_len, prot, flags | MAP_FIXED, fd, host_offset); + } + + /* + * When mapping files into a memory area larger than the file, accesses + * to pages beyond the file size will cause a SIGBUS. + * + * For example, if mmaping a file of 100 bytes on a host with 4K pages + * emulating a target with 8K pages, the target expects to be able to + * access the first 8K. But the host will trap us on any access beyond + * 4K. + * + * When emulating a target with a larger page-size than the hosts, we + * may need to truncate file maps at EOF and add extra anonymous pages + * up to the targets page boundary. + */ + + if ((qemu_real_host_page_size < qemu_host_page_size) && fd !=3D -1) { + struct stat sb; + + if (fstat(fd, &sb) =3D=3D -1) { + goto fail; + } + + /* Are we trying to create a map beyond EOF?. */ + if (offset + len > sb.st_size) { + /* + * If so, truncate the file map at eof aligned with + * the hosts real pagesize. Additional anonymous maps + * will be created beyond EOF. + */ + len =3D REAL_HOST_PAGE_ALIGN(sb.st_size - offset); + } + } + + if (!(flags & MAP_FIXED)) { + unsigned long host_start; + void *p; + + host_len =3D len + offset - host_offset; + host_len =3D HOST_PAGE_ALIGN(host_len); + + /* + * Note: we prefer to control the mapping address. It is + * especially important if qemu_host_page_size > + * qemu_real_host_page_size + */ + p =3D mmap(g2h_untagged(start), host_len, prot, + flags | MAP_FIXED | ((fd !=3D -1) ? MAP_ANONYMOUS : 0), -= 1, 0); if (p =3D=3D MAP_FAILED) goto fail; /* update start so that it points to the file position at 'offset'= */ host_start =3D (unsigned long)p; - if (!(flags & MAP_ANON)) + if (fd !=3D -1) { + p =3D mmap(g2h_untagged(start), len, prot, + flags | MAP_FIXED, fd, host_offset); + if (p =3D=3D MAP_FAILED) { + munmap(g2h_untagged(start), host_len); + goto fail; + } host_start +=3D offset - host_offset; + } start =3D h2g(host_start); } else { - int flg; - target_ulong addr; - if (start & ~TARGET_PAGE_MASK) { errno =3D EINVAL; goto fail; @@ -338,20 +559,28 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, end =3D start + len; real_end =3D HOST_PAGE_ALIGN(end); =20 - for (addr =3D real_start; addr < real_end; addr +=3D TARGET_PAGE_S= IZE) { - flg =3D page_get_flags(addr); - if (flg & PAGE_RESERVED) { - errno =3D ENXIO; - goto fail; - } + /* + * Test if requested memory area fits target address space + * It can fail only on 64-bit host with 32-bit target. + * On any other target/host host mmap() handles this error correct= ly. + */ +#if TARGET_ABI_BITS =3D=3D 32 && HOST_LONG_BITS =3D=3D 64 + if ((unsigned long)start + len - 1 > (abi_ulong) -1) { + errno =3D EINVAL; + goto fail; } +#endif =20 - /* worst case: we cannot map the file because the offset is not - aligned, so we read it */ + /* + * worst case: we cannot map the file because the offset is not + * aligned, so we read it + */ if (!(flags & MAP_ANON) && (offset & ~qemu_host_page_mask) !=3D (start & ~qemu_host_page_= mask)) { - /* msync() won't work here, so we return an error if write is - possible while it is a shared mapping */ + /* + * msync() won't work here, so we return an error if write is + * possible while it is a shared mapping + */ if ((flags & TARGET_BSD_MAP_FLAGMASK) =3D=3D MAP_SHARED && (prot & PROT_WRITE)) { errno =3D EINVAL; @@ -392,7 +621,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, /* handle the end of the mapping */ if (end < real_end) { ret =3D mmap_frag(real_end - qemu_host_page_size, - real_end - qemu_host_page_size, real_end, + real_end - qemu_host_page_size, end, prot, flags, fd, offset + real_end - qemu_host_page_size - star= t); if (ret =3D=3D -1) @@ -422,6 +651,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, page_dump(stdout); printf("\n"); #endif + tb_invalidate_phys_range(start, start + len); mmap_unlock(); return start; fail: @@ -429,6 +659,49 @@ fail: return -1; } =20 +static void mmap_reserve(abi_ulong start, abi_ulong size) +{ + abi_ulong real_start; + abi_ulong real_end; + abi_ulong addr; + abi_ulong end; + int prot; + + real_start =3D start & qemu_host_page_mask; + real_end =3D HOST_PAGE_ALIGN(start + size); + end =3D start + size; + if (start > real_start) { + /* handle host page containing start */ + prot =3D 0; + for (addr =3D real_start; addr < start; addr +=3D TARGET_PAGE_SIZE= ) { + prot |=3D page_get_flags(addr); + } + if (real_end =3D=3D real_start + qemu_host_page_size) { + for (addr =3D end; addr < real_end; addr +=3D TARGET_PAGE_SIZE= ) { + prot |=3D page_get_flags(addr); + } + end =3D real_end; + } + if (prot !=3D 0) { + real_start +=3D qemu_host_page_size; + } + } + if (end < real_end) { + prot =3D 0; + for (addr =3D end; addr < real_end; addr +=3D TARGET_PAGE_SIZE) { + prot |=3D page_get_flags(addr); + } + if (prot !=3D 0) { + real_end -=3D qemu_host_page_size; + } + } + if (real_start !=3D real_end) { + mmap(g2h_untagged(real_start), real_end - real_start, PROT_NONE, + MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, + -1, 0); + } +} + int target_munmap(abi_ulong start, abi_ulong len) { abi_ulong end, real_start, real_end, addr; @@ -476,11 +749,17 @@ int target_munmap(abi_ulong start, abi_ulong len) ret =3D 0; /* unmap what we can */ if (real_start < real_end) { - ret =3D munmap(g2h_untagged(real_start), real_end - real_start); + if (reserved_va) { + mmap_reserve(real_start, real_end - real_start); + } else { + ret =3D munmap(g2h_untagged(real_start), real_end - real_start= ); + } } =20 - if (ret =3D=3D 0) + if (ret =3D=3D 0) { page_set_flags(start, start + len, 0); + tb_invalidate_phys_range(start, start + len); + } mmap_unlock(); return ret; } diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 8d20554688..522d6c4031 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -105,7 +105,6 @@ typedef struct TaskState { =20 void init_task_state(TaskState *ts); extern const char *qemu_uname_release; -extern unsigned long mmap_min_addr; =20 /* * TARGET_ARG_MAX defines the number of bytes allocated for arguments @@ -215,13 +214,15 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong= uoss_addr, abi_ulong sp); /* mmap.c */ int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, - int flags, int fd, abi_ulong offset); + int flags, int fd, off_t offset); int target_munmap(abi_ulong start, abi_ulong len); abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); int target_msync(abi_ulong start, abi_ulong len, int flags); extern unsigned long last_brk; +extern abi_ulong mmap_next_start; +abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size); void mmap_fork_start(void); void mmap_fork_end(int child); =20 --=20 2.32.0