From patchwork Sat Aug 7 21:41:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514710 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=zsAT/J4m; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwnr5QQzz9sWl for ; Sun, 8 Aug 2021 07:43:27 +1000 (AEST) Received: from localhost ([::1]:33122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCU6G-000685-Od for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:43:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5o-00067i-J1 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:56 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:42651) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5m-0004eo-3m for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:56 -0400 Received: by mail-io1-xd44.google.com with SMTP id h1so19880139iol.9 for ; Sat, 07 Aug 2021 14:42: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=eC7+Z/L6xH/uBXCFkT4h126cvXl8PyJyoXAYaw6KWA4=; b=zsAT/J4mU8g9INzpgZJi4Nlq8G/otxRP/AAUg+0yrxC9Mq6AaKLxn17ovRB16VIjvY Xic6b2xKj1BCQ9R2jOQCl+uEAxHmrR30ePfbjKl/yPahhU9Z8sviAF4Z8TwnSbKjhtI7 iCG7ri70Q7LlDZJKpGSUuQDeFEVVyPflGAQ4EJ9djY+o1s1/5qT16lCexjZcRUTDiPXs fJwCNoEyZ48WMCJzbel1Zxj+MUWs2Z7WUkglgjTgHKgiXXpuA5/Jsle/sdtzlTwegyBL dmadxa3O8WtBjH3EVWZXU+nFJStvKCM9ddJ5E/1PnEd6+k+eAdasFM142CpDP4YymJaS qv0g== 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=eC7+Z/L6xH/uBXCFkT4h126cvXl8PyJyoXAYaw6KWA4=; b=VbsVtdBW1hLtuVa5EEGNxwrak2RcjatGKHM7W+SLMow/9dj5/0oiUdBzoqShvoJhSi 9esqIwt2lb/+/rpegvoZxYeyP+gmN4R81iV1Lks5+nFuskoFp5ozUngKGyzpIZAM8FWI 3Aso5ey9aAIv867GE8Rxx2xRtQl5zhZEByWkbXGn7VpC0XN9ngRGUQZ2Uie9xjvyF8GE 3WmuKXdPC+ZWnvks9rXh+G0fsDMIGTM5ahQ1SL5RZcLk12rkmcFHKQEEWerDnyXUyeAF hvq5+UMoedxm/weSthguMtLTpwTswaD0jQAP8RBjX7oVrzrIfI7FC82rJUUcyiO+Bkl4 s7CA== X-Gm-Message-State: AOAM532yTE/0FXAvWht5XXn/UyLCP19vAXsD2rQpQ/j+1q7forwaO6ne 4clEAKB5Ro8YONsuzDMsgfDxN2oJEhpBDc1Y X-Google-Smtp-Source: ABdhPJwUjyiC96F6ig+FIMUEkLG+KLXdFk9RCWkR8RhB1YXgM58fhkujCdkRxGjeIX+pZhWNd0o4fA== X-Received: by 2002:a6b:8f08:: with SMTP id r8mr291990iod.42.1628372572412; Sat, 07 Aug 2021 14:42: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 a17sm8062827ios.36.2021.08.07.14.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:51 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 01/49] bsd-user: remove sparc and sparc64 Date: Sat, 7 Aug 2021 15:41:54 -0600 Message-Id: <20210807214242.82385-2-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 290 ------------------------- 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, 478 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..8e1ac5d042 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -261,274 +261,6 @@ void cpu_loop(CPUX86State *env) } #endif -#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 = (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 == env->nwindows - 1) { - index += 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 = env->regbase[get_reg_index(env, cwp1, 6)]; -#ifdef TARGET_SPARC64 - if (sp_ptr & 3) { - sp_ptr += SPARC64_STACK_BIAS; - } -#endif -#if defined(DEBUG_WIN) - printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n", - sp_ptr, cwp1); -#endif - for (i = 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 += sizeof(abi_ulong); - } -} - -static void save_window(CPUSPARCState *env) -{ -#ifndef TARGET_SPARC64 - unsigned int new_wim; - new_wim = ((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 = 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 = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) & - ((1LL << env->nwindows) - 1); -#endif - - /* restore the invalid window */ - cwp1 = cpu_cwp_inc(env, env->cwp + 1); - sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)]; -#ifdef TARGET_SPARC64 - if (sp_ptr & 3) { - sp_ptr += SPARC64_STACK_BIAS; - } -#endif -#if defined(DEBUG_WIN) - printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n", - sp_ptr, cwp1); -#endif - for (i = 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 += sizeof(abi_ulong); - } -#ifdef TARGET_SPARC64 - env->canrestore++; - if (env->cleanwin < env->nwindows - 1) { - env->cleanwin++; - } - env->cansave--; -#else - env->wim = new_wim; -#endif -} - -static void flush_windows(CPUSPARCState *env) -{ - int offset, cwp1; - - offset = 1; - for (;;) { - /* if restore would invoke restore_window(), then we can stop */ - cwp1 = cpu_cwp_inc(env, env->cwp + offset); -#ifndef TARGET_SPARC64 - if (env->wim & (1 << cwp1)) { - break; - } -#else - if (env->canrestore == 0) { - break; - } - env->cansave++; - env->canrestore--; -#endif - save_window_offset(env, cwp1); - offset++; - } - cwp1 = cpu_cwp_inc(env, env->cwp + 1); -#ifndef TARGET_SPARC64 - /* set wim so that restore will reload the registers */ - env->wim = 1 << cwp1; -#endif -#if defined(DEBUG_WIN) - printf("flush_windows: nb=%d\n", offset - 1); -#endif -} - -void cpu_loop(CPUSPARCState *env) -{ - CPUState *cs = env_cpu(env); - int trapnr, ret, syscall_nr; - /* target_siginfo_t info; */ - - while (1) { - cpu_exec_start(cs); - trapnr = 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 != target_freebsd) { - goto badtrap; - } - /* fallthrough */ - case 0x100: -#endif - syscall_nr = env->gregs[1]; - if (bsd_type == target_freebsd) - ret = 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 == target_netbsd) - ret = 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 == target_openbsd) */ -#if defined(TARGET_SPARC64) - syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG | - TARGET_OPENBSD_SYSCALL_G2RFLAG); -#endif - ret = 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 >= (unsigned int)(-515)) { - ret = -ret; -#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) - env->xcc |= PSR_CARRY; -#else - env->psr |= PSR_CARRY; -#endif - } else { -#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) - env->xcc &= ~PSR_CARRY; -#else - env->psr &= ~PSR_CARRY; -#endif - } - env->regwptr[0] = ret; - /* next instruction */ -#if defined(TARGET_SPARC64) - if (bsd_type == target_openbsd && - env->gregs[1] & TARGET_OPENBSD_SYSCALL_G2RFLAG) { - env->pc = env->gregs[2]; - env->npc = env->pc + 4; - } else if (bsd_type == target_openbsd && - env->gregs[1] & TARGET_OPENBSD_SYSCALL_G7RFLAG) { - env->pc = env->gregs[7]; - env->npc = env->pc + 4; - } else { - env->pc = env->npc; - env->npc = env->npc + 4; - } -#else - env->pc = env->npc; - env->npc = env->npc + 4; -#endif - break; - case 0x83: /* flush windows */ -#ifdef TARGET_ABI32 - case 0x103: -#endif - flush_windows(env); - /* next instruction */ - env->pc = env->npc; - env->npc = 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 = "qemu32"; #endif -#elif defined(TARGET_SPARC) -#ifdef TARGET_SPARC64 - cpu_model = "TI UltraSparc II"; -#else - cpu_model = "Fujitsu MB86904"; -#endif #else cpu_model = "any"; #endif @@ -800,9 +526,6 @@ int main(int argc, char **argv) } cpu = cpu_create(cpu_type); env = cpu->env_ptr; -#if defined(TARGET_SPARC) || defined(TARGET_PPC) - cpu_reset(cpu); -#endif thread_cpu = cpu; if (getenv("QEMU_STRACE")) { @@ -1001,19 +724,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 = regs->pc; - env->npc = regs->npc; - env->y = regs->y; - for (i = 0; i < 8; i++) { - env->gregs[i] = regs->u_regs[i]; - } - for (i = 0; i < 8; i++) { - env->regwptr[i] = 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_arch_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 = 0; - - switch (op) { - case TARGET_SPARC_SIGTRAMP_INSTALL: - /* XXX not currently handled */ - case TARGET_SPARC_UTRAP_INSTALL: - /* XXX not currently handled */ - default: - ret = -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_syscall.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/target_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 = 0; - - switch (op) { - case TARGET_SPARC_SIGTRAMP_INSTALL: - /* XXX not currently handled */ - case TARGET_SPARC_UTRAP_INSTALL: - /* XXX not currently handled */ - default: - ret = -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_syscall.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, int op, abi_ulong parms) } #endif -#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 From patchwork Sat Aug 7 21:41:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514709 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=AX3hBIRr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwnr57Fjz9sWX for ; Sun, 8 Aug 2021 07:43:27 +1000 (AEST) Received: from localhost ([::1]:33150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCU6G-00069p-CS for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:43:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5p-00067s-Ee for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:57 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:33422) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5m-0004g1-Ha for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:57 -0400 Received: by mail-io1-xd42.google.com with SMTP id n19so20054407ioz.0 for ; Sat, 07 Aug 2021 14:42:54 -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=QksrBu28ckIho2yVl203igA97c5wMaCvQfUOlaWYLx0=; b=AX3hBIRrThyzoxNrxQrChXEb0SxybbUfqeQAjZp68qhs74HdilTTm1LJzoXmK73K3r IB4nVbOT+Rg1nUXYkmab6B51FxqLf5CVBP53sYEnMPNEq4IRN2zKXNeuBvTHAzntfb2i 6345WTYaeZpA1yKieaH48KvHjT3jnJlgw5WRJsqetWfeL5ZUw4/Ra2JvjCdo3yBjdBlE kMlmG0NsFkuCAhQ34wqmSPoUoHvVWWkAYt9dgI54ZdIp4NJoY2esoAchqDr56TWQGEZE GLz04iCx4mSOWvWxA44awb4uvFeVQ3xOZ+ORQ4hNkBT5fyTncM6i18hvOQXV9f/PGvIu NmAw== 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=QksrBu28ckIho2yVl203igA97c5wMaCvQfUOlaWYLx0=; b=miX60tNgvD/dIcHtxIae8bzO2H/eaegpX/oW5WoH7iyMY2j8H/PIWiscVNCGEqGJVj tbyUWOIOvtlaMekkHVir+dplDjUSv/cxsZXWNiQ1cdfuhdTr9US+ctFRXOfOq2893ivz DQyKG9oirQ776SwUHNgHrK4XiBcVyy/BwvklVKNgcBgRW5tfpMxdUE3sXRKcFYSV6ugB zga2hwNEknWk8l/aXJxFDlnWE/Ez9UFs7aDvQlRDpMoaQcH12Qn3jQQPea4nE26rycu0 nIS+8gyDEN2F+ay684f/l/ZzpmB9i0VbzdQtX8hQankd4WMdDC0wFDfcR7I8Kb38tqGH 5eog== X-Gm-Message-State: AOAM5300OqUxcSsBJzBEAJsrRfiHQnnvTILVmc9g5kdQNftz3b8SUZxQ c3V9qSmMhVpXRNd9s39iuNziPSjXxdSi+G+x X-Google-Smtp-Source: ABdhPJwkkc+CnF1ijycFUsPzDRJgoesYnA9JTQxy5fj7UdCEAIJ0mn8566nPeW6ro/fbrtUAFgXcKQ== X-Received: by 2002:a5d:8e11:: with SMTP id e17mr39328iod.138.1628372573369; Sat, 07 Aug 2021 14:42: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 a17sm8062827ios.36.2021.08.07.14.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:52 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 02/49] bsd-user: add copyright header to elfload.c Date: Sat, 7 Aug 2021 15:41:55 -0600 Message-Id: <20210807214242.82385-3-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 . + */ #include "qemu/osdep.h" From patchwork Sat Aug 7 21:41:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514715 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=gCjqBe40; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwr21KKpz9sWX for ; Sun, 8 Aug 2021 07:45:22 +1000 (AEST) Received: from localhost ([::1]:41742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCU87-0003hL-RZ for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:45:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5p-00067r-BG for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:57 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]:41827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5n-0004gd-K5 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:57 -0400 Received: by mail-io1-xd2e.google.com with SMTP id 188so18231863ioa.8 for ; Sat, 07 Aug 2021 14:42: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=xIovx0fvyMsu13YfHfz0Wj9FSUDvRJdk8XVPKqOBnHc=; b=gCjqBe40ZmTzjPaP2AkOYwfw2OUNWRk0TPHioScD+RuOCK4n2j/tG/vjqaGdsPGDBQ 2T/EpdrVvsF07l9//G5VoPrmWIEqJjMFN5IssHdZHnAURvJfsQOq03xT4odLt8KzznOK FtVS6NFgm8RjunJa8oQH0XhAhSQMbTydLyrxocle2KPzFACC4H4EKBAGxIzI4jusbEaV BDGr+49550Zo/VL/ZRXZNqhQIjHu6/gZaMmRrbV+LED0JTLys5+tbdDCxQbORMA0CsKQ XYxY0v5A2OeIWVcEO2niOpKaeq3axZu66CuaE2bti2Nlzt00qy1WKunLKT2rzjV6FDpI 0zLw== 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=xIovx0fvyMsu13YfHfz0Wj9FSUDvRJdk8XVPKqOBnHc=; b=p+yeDqDrc+LfCCVgc3zvCHiNkMeEpcTvCjRXn6y7nfBm5MS32DeDhy5peLv+9bhUhW 7AGJb0cISKnBEY84U9ysAwOfVxVCtkJej3EnFVVNnZWN5gIFHTN/f2tCBY5UX9pmol2E kKqd2Burl3jIi8cktaVuYX3D2uZVzt8I9Rhlk2T3qOwkvhVtzOyi6NR6PEhAqzperWUA Eg3Xd+8t52ElPXV/UaijcrD3YIPYE8icP9x9U/J6LaWXNs8G2E3x5VB4ksY+b3C86yxg VcZaLEponRMksMk9Hj7jDRvih6RsOaJnwPfQ+uAIWLHAajgJSdXeep47kqfLDupaSqp6 a6hg== X-Gm-Message-State: AOAM530p41DQgX2tMNUYUFg0apTTtgfvhiGupT837lBrRT/SdcUaCpol SrbVUds9acYoM4GdcMp1rblJ0BVwySSvg2B2 X-Google-Smtp-Source: ABdhPJw/S3RhTa/w5D67ogC1LXrjLYzZZp67eFJ1FQgecDIVj/oOKRkb3aneUYDABrqt6su0R7fNpQ== X-Received: by 2002:a5d:91c2:: with SMTP id k2mr83129ior.117.1628372574338; Sat, 07 Aug 2021 14:42: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 a17sm8062827ios.36.2021.08.07.14.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:53 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 03/49] bsd-user: Add Stacey's copyright to main.c Date: Sat, 7 Aug 2021 15:41:56 -0600 Message-Id: <20210807214242.82385-4-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Add Stacey's updated copyright to main.c Signed-off-by: Warner Losh Signed-off-by: Stacey Son Sponsored by: Netflix 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 8e1ac5d042..5c579d7c2c 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 From patchwork Sat Aug 7 21:41:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=ZXTEUCLI; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhwtN0zMkz9sWl for ; Sun, 8 Aug 2021 07:47:24 +1000 (AEST) Received: from localhost ([::1]:50328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUA5-00012W-Sa for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:47:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5q-0006As-MR for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:58 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]:35601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5o-0004gq-OY for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:58 -0400 Received: by mail-io1-xd2b.google.com with SMTP id s184so20001761ios.2 for ; Sat, 07 Aug 2021 14:42:56 -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=hy5Pq9zOeJk0/w9QUIbXa2LdX+WCtfarhN0ncIfi8kQ=; b=ZXTEUCLImg8zw5odzrM/9XHyw3lxch7f65Z6TEk4aPD+G1aC1krGw06cmjp/E2ZR+T 918CHIxdZ4F0Kuw90UKyFLAtLcuHXuy8+EuHKGXTj0u+S7Db6GH2G2bEj0TnhZyuovEM kj2GQdoYKuOeRDrQ0rLq8mIavTkt0LEtYMIBe0iP1Rk2nnp8IYPQV4mmAv96oNanlTLu JGOCn6UqmkUnXzhcXBKXv8XX/SIZKplTbV9h9HTcSPaa5T2WubuX0pkZIaorrKBkkFx8 66mI0JTKIbTAmq2JdNZLwgqrj4k7JuHI5slo+8w7prthJ7WfHglkMNLPYuPAQipx6DEj gSNg== 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=hy5Pq9zOeJk0/w9QUIbXa2LdX+WCtfarhN0ncIfi8kQ=; b=lBi0DPu8/3aIBKfJ4l9PEC/4aFIY5Na8XMHB7YZ3K69xIufmG9sRmkJ0AOacp6u2RR KHCKW2RuBckho9bt8K4P55TqE5v7YFJ1HkVgYdaTFUohEQHPySR+IDMe9kRN1qy36aia r9lxJzD8mcpTMYJpksJrYz8PoMOAbcZTIsDvlNA6PJWMUmmynt21CB401vYOQ1tX8D0v U4p9W/BzKPyKFY4tJwrz2hbwg5s+5pINn+KM2dDGQ7CStESEds+sk9BiVbYVjBYhjWoA CtD36Bs8np9mi1dOo7JlWcS+rn2AKdE8B45na0jRx9xetfsPZHT06Yka/OjzPSG0BqCm rm6A== X-Gm-Message-State: AOAM531BKb4Q2BH5e0iUdrl+fdFawShpE4UNJdmghch9oRqRaPVJhKFG TVlhBSJdhE5+WHDuaWzoi6h8ASbjkbkPvFcK X-Google-Smtp-Source: ABdhPJxZ5ZZ3XS3awsSCaM4FN/vYbNMuZPa+4Ltv5lW5nzKWSswQ6EtM6m2whRz/sSLmIRt8yxMyWA== X-Received: by 2002:a05:6602:1210:: with SMTP id y16mr124378iot.159.1628372575323; Sat, 07 Aug 2021 14:42: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 a17sm8062827ios.36.2021.08.07.14.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:54 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 04/49] bsd-user: Remove all non-x86 code from elfload.c Date: Sat, 7 Aug 2021 15:41:57 -0600 Message-Id: <20210807214242.82385-5-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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: kevans@freebsd.org, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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" -#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 */ /* @@ -144,7 +135,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i } } -#else +#else /* !TARGET_X86_64 */ #define ELF_START_MMAP 0x80000000 @@ -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 = 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) == 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_info *infop) -{ - abi_long stack = infop->start_stack; - memset(regs, 0, sizeof(*regs)); - regs->ARM_cpsr = 0x10; - if (infop->entry & 1) - regs->ARM_cpsr |= CPSR_T; - regs->ARM_pc = infop->entry & 0xfffffffe; - regs->ARM_sp = 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 = 0; - /* For uClinux PIC binaries. */ - /* XXX: Linux does this only on ARM with no MMU (do we care ?) */ - regs->ARM_r10 = infop->start_data; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -enum -{ - ARM_HWCAP_ARM_SWP = 1 << 0, - ARM_HWCAP_ARM_HALF = 1 << 1, - ARM_HWCAP_ARM_THUMB = 1 << 2, - ARM_HWCAP_ARM_26BIT = 1 << 3, - ARM_HWCAP_ARM_FAST_MULT = 1 << 4, - ARM_HWCAP_ARM_FPA = 1 << 5, - ARM_HWCAP_ARM_VFP = 1 << 6, - ARM_HWCAP_ARM_EDSP = 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) == EM_SPARCV9 || (x) == EM_SPARC32PLUS) -#else -#define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC) -#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_info *infop) -{ -#ifndef TARGET_ABI32 - regs->tstate = 0; -#endif - regs->pc = infop->entry; - regs->npc = regs->pc + 4; - regs->y = 0; -#ifdef TARGET_ABI32 - regs->u_regs[14] = infop->start_stack - 16 * 4; -#else - if (personality(infop->personality) == PER_LINUX32) - regs->u_regs[14] = infop->start_stack - 16 * 4; - else { - regs->u_regs[14] = infop->start_stack - 16 * 8 - STACK_BIAS; - if (bsd_type == target_freebsd) { - regs->u_regs[8] = infop->start_stack; - regs->u_regs[11] = infop->start_stack; - } - } -#endif -} - -#else -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch(x) ((x) == 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_info *infop) -{ - regs->psr = 0; - regs->pc = infop->entry; - regs->npc = regs->pc + 4; - regs->y = 0; - regs->u_regs[14] = 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) == EM_PPC64) - -#define ELF_CLASS ELFCLASS64 - -#else - -#define elf_check_arch(x) ((x) == 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 PPC, - * 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 = infop->start_stack; - abi_ulong tmp; -#if defined(TARGET_PPC64) && !defined(TARGET_ABI32) - abi_ulong entry, toc; -#endif - - _regs->gpr[1] = infop->start_stack; -#if defined(TARGET_PPC64) && !defined(TARGET_ABI32) - get_user_u64(entry, infop->entry); - entry += infop->load_addr; - get_user_u64(toc, infop->entry + 8); - toc += infop->load_addr; - _regs->gpr[2] = toc; - infop->entry = entry; -#endif - _regs->nip = 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 += sizeof(abi_ulong); - _regs->gpr[4] = pos; - for (tmp = 1; tmp != 0; pos += sizeof(abi_ulong)) { - get_user_ual(tmp, pos); - } - _regs->gpr[5] = pos; -} +#endif /* !TARGET_X86_64 */ #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 #endif -#ifdef TARGET_MIPS - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch(x) ((x) == 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_info *infop) -{ - regs->cp0_status = 2 << CP0St_KSU; - regs->cp0_epc = infop->entry; - regs->regs[29] = 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) == 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_info *infop) -{ - /* Check other registers XXXXX */ - regs->pc = infop->entry; - regs->regs[15] = 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) == 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_info *infop) -{ - regs->erp = 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) == 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_info *infop) -{ - regs->usp = infop->start_stack; - regs->sr = 0; - regs->pc = 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) == 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_info *infop) -{ - regs->pc = infop->entry; - regs->ps = 8; - regs->usp = infop->start_stack; - regs->unique = 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 &= ~(target_ulong)1; -#endif i++; } From patchwork Sat Aug 7 21:41:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=ZZALewH4; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwr13NrFz9sWl for ; Sun, 8 Aug 2021 07:45:21 +1000 (AEST) Received: from localhost ([::1]:41556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCU87-0003Zn-26 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:45:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5s-0006GW-5W for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:00 -0400 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]:40770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5p-0004i9-Gx for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:42:59 -0400 Received: by mail-io1-xd32.google.com with SMTP id m13so19894083iol.7 for ; Sat, 07 Aug 2021 14:42: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=PT+wrBvlddpGOiPWMW8ZY3I3hc4zlWNJO/ROaM0a72c=; b=ZZALewH4vy7V5fFqQw06B4Q1gdW366pW36NkKwowNL0K849/EHNtUL4zoYeCEBIF0t y8C1snt3Ez77n+9d7LJ8LzqShdhgtiLhJtRsXOvhf9J3OO6HLOZCKroWxuyeqETISLVl v/KaiMr2y99ejVp5OWFenyPiEwc2uxAuQYFPWOjPyYjXJUNhVAYyWHfP16MIvtlkRZPa b1i0xCpZEk3qHw0PpEfj76T/pyoN8LDwjFo9mQ4ps1ywNu/1a+xzi7PPRtw/uYQIoBoH VDMXolRB/jlT7CGfzH1Mk52nZafoyqw6tyw673PaT3xTa5XovuNwtbOgTL2tFT5HRjMA BB/A== 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=PT+wrBvlddpGOiPWMW8ZY3I3hc4zlWNJO/ROaM0a72c=; b=kiZC82xzwojKHC9mVz4N+Iuhg0b2/1+tw0BJmdMF133frYQl+doYS7hg6kBkOXvJJS KwXtC5+7X7U7MeJHfGE8DeDGfm4YMVAOuRkM0jNUqoRjKIhbHc4ixx7w5hsg6C/h5hYf pC+Fi/Fq8uFy4T4GUNfhTIdq0Ff1YHuY7Cd2LZSViWF0wXGpKzPunNH7Np8eYseK6vOL XiSZ4TW0b7QYcBi5KKuGq5aSBKErqtlHuJk/VF1towpqj7hL4mlmtRTtdeaPVzoK7mVe 0qaaHBjE9e37rV5YVEbjw5j9EKmdY3ucxKTVzyyT9AW88wjjVl0+RAt/2AmsDTkPdFWf rtJA== X-Gm-Message-State: AOAM5307PTIAllwL1qCFzanSxARkAcqsECZt6QHZA1WxdjPjTn2vdtO+ 3UZRuZrHkySkzhAQjJm+pq8cg7VFoBWehtNP X-Google-Smtp-Source: ABdhPJwk1t9ApaGkjvAhWOMhfupDhdceLJzP2WMK2AYmzlsmjN/p77m5OjNaMI9JTKDvUAsMqtn88g== X-Received: by 2002:a5e:d80e:: with SMTP id l14mr203090iok.79.1628372576326; Sat, 07 Aug 2021 14:42: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 a17sm8062827ios.36.2021.08.07.14.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:55 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 05/49] bsd-user: move arch specific defines out of elfload.c Date: Sat, 7 Aug 2021 15:41:58 -0600 Message-Id: <20210807214242.82385-6-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Move the arcitecture specific defines to target_arch_elf.h and delete them from elfload.c. unifdef as appropriate for i386 vs x86_64 versions. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 81 +------------------------------ bsd-user/i386/target_arch_elf.h | 54 +++++++++++++++++++++ bsd-user/x86_64/target_arch_elf.h | 41 ++++++++++++++++ 3 files changed, 97 insertions(+), 79 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" +#include "target_arch_elf.h" + /* from personality.h */ /* @@ -93,85 +95,6 @@ enum { #define ELIBBAD 80 #endif -#ifdef TARGET_I386 - -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform(void) -{ - static char elf_platform[] = "i386"; - int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL); - if (family > 6) - family = 6; - if (family >= 3) - elf_platform[1] = '0' + family; - return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap(void) -{ - X86CPU *cpu = 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) == 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 = 0; - regs->rsp = infop->start_stack; - regs->rip = infop->entry; - if (bsd_type == target_freebsd) { - regs->rdi = 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 architecture. - */ -#define elf_check_arch(x) (((x) == EM_386) || ((x) == 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 = infop->start_stack; - regs->eip = 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 = 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_elf.h new file mode 100644 index 0000000000..084c9a7814 --- /dev/null +++ b/bsd-user/i386/target_arch_elf.h @@ -0,0 +1,54 @@ + +#define ELF_PLATFORM get_elf_platform() + +static const char *get_elf_platform(void) +{ + static char elf_platform[] = "i386"; + int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL); + if (family > 6) + family = 6; + if (family >= 3) + elf_platform[1] = '0' + family; + return elf_platform; +} + +#define ELF_HWCAP get_elf_hwcap() + +static uint32_t get_elf_hwcap(void) +{ + X86CPU *cpu = 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 architecture. + */ +#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == 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 = infop->start_stack; + regs->eip = 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 = 0; +} + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 diff --git a/bsd-user/x86_64/target_arch_elf.h b/bsd-user/x86_64/target_arch_elf.h new file mode 100644 index 0000000000..08a86da1a5 --- /dev/null +++ b/bsd-user/x86_64/target_arch_elf.h @@ -0,0 +1,41 @@ +#define ELF_PLATFORM get_elf_platform() + +static const char *get_elf_platform(void) +{ + static char elf_platform[] = "i386"; + int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL); + if (family > 6) + family = 6; + if (family >= 3) + elf_platform[1] = '0' + family; + return elf_platform; +} + +#define ELF_HWCAP get_elf_hwcap() + +static uint32_t get_elf_hwcap(void) +{ + X86CPU *cpu = X86_CPU(thread_cpu); + + return cpu->env.features[FEAT_1_EDX]; +} + +#define ELF_START_MMAP 0x2aaaaab000ULL +#define elf_check_arch(x) ( ((x) == 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 = 0; + regs->rsp = infop->start_stack; + regs->rip = infop->entry; + if (bsd_type == target_freebsd) { + regs->rdi = infop->start_stack; + } +} + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 From patchwork Sat Aug 7 21:41:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=YMAZs9No; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhwtN6Z8Bz9sWX for ; Sun, 8 Aug 2021 07:47:24 +1000 (AEST) Received: from localhost ([::1]:50374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUA6-00014N-LB for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:47:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5t-0006JZ-0F for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:01 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]:33422) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5q-0004iP-I2 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:00 -0400 Received: by mail-io1-xd41.google.com with SMTP id n19so20054643ioz.0 for ; Sat, 07 Aug 2021 14:42: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=w22VXCkHbqUvOP5ZDRCDaOrYu5LDO7rbH2N3Pl/PXGA=; b=YMAZs9NolUJngRhcmg1B965kBu3Rf7Q86A7PMzONbCCd29TTEoDJtOJBe5aYwrDITo lXyMl7QTsRYRhUflMQE8qDG3+/SaXnkJLD+3oiE3VsYh6PXSafgLdceFAQBnii3++OGP 2Oh0YiRAZ3sS/uChp6JPX6ijYATB/5Z5Y/XiP+bSQfNa3bO+rA98UvGFOyzBmJ2U20rq ouS9EFUsv203Hyf2k5/fD/Nx52Cs8qx1RWM+v2eWe/NDiy/szpeZFUBTL3pNy3UarEGd Ws2zqccX8Ra2MU1k63whIFnJz279hIKR8QsAjmChWvO41drwTDD24e9I7I1wHCpjZ53k CGnQ== 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=w22VXCkHbqUvOP5ZDRCDaOrYu5LDO7rbH2N3Pl/PXGA=; b=Hl0b36yaEqkiwlBAc5Ei3Cs8x4mo+AleBmmy20cZfK2SRn0+6pW7xzmhrx3UN6GXOR VjMv/IqJJ/9LhC4K8i8DP4TyiYZEAsVx40Wj+E6z6t7riT6h3MWZ2MRGHsMBd84goNUc Qo2uir39cj6lJKUB8zSUvNACE/4OUudBW3/NAyBuZjxg4YUdRab1HaCHCChSMvIdC98S 1geNjVHSCD3fRE4/OIaqGDV2A1oELNGFMk4rYJHgVRhs636TScOEDo4u8OqmDVo2P7zg nA7hIZpViI2hLv9BB2qoSUhVGXDBHyNhs6yYdiRDTt9IPNKLYAbT2v2B1IUz1ZRnDgNG y7qg== X-Gm-Message-State: AOAM5312o/I9HIbydLlwRnQe0f/XS7qLCMZQbhn0BuuHhEy57Z4jc5jj o+tH7ZU8ng2jMfa0ZdTXlQ2CT+3obGbBzyUv X-Google-Smtp-Source: ABdhPJzkgI3mKpOKRnsCV0rSqWT36pHfA8NceYxPwHTNBPgBB5Yd46EA8eXUYMBFSgC6XySWDPIjNw== X-Received: by 2002:a6b:4406:: with SMTP id r6mr50049ioa.192.1628372577181; Sat, 07 Aug 2021 14:42:57 -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 a17sm8062827ios.36.2021.08.07.14.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:56 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 06/49] bsd-user: merge comments and guards from bsd-user fork Date: Sat, 7 Aug 2021 15:41:59 -0600 Message-Id: <20210807214242.82385-7-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Diff reduction against bsd-user fork: bring in the copyright/license comments, and guard ifdefs. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/i386/target_arch_elf.h | 22 ++++++++++++++++++++++ bsd-user/x86_64/target_arch_elf.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/bsd-user/i386/target_arch_elf.h b/bsd-user/i386/target_arch_elf.h index 084c9a7814..20ef0ccbdb 100644 --- a/bsd-user/i386/target_arch_elf.h +++ b/bsd-user/i386/target_arch_elf.h @@ -1,3 +1,23 @@ +/* + * 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() @@ -52,3 +72,5 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i #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_arch_elf.h index 08a86da1a5..d3c139c7a9 100644 --- a/bsd-user/x86_64/target_arch_elf.h +++ b/bsd-user/x86_64/target_arch_elf.h @@ -1,3 +1,24 @@ +/* + * 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) @@ -39,3 +60,5 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 + +#endif /* _TARGET_ARCH_ELF_H_ */ From patchwork Sat Aug 7 21:42:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514712 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=rB/UeJT5; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwnv5DPsz9sWX for ; Sun, 8 Aug 2021 07:43:31 +1000 (AEST) Received: from localhost ([::1]:33510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCU6L-0006Qs-9N for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:43:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5t-0006LF-Et for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:01 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]:35603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5r-0004kO-GO for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:01 -0400 Received: by mail-io1-xd2d.google.com with SMTP id s184so20001911ios.2 for ; Sat, 07 Aug 2021 14:42: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=BZr8mJ1mJ66M5MXwN6/HePswNTldWfKVbwj4u/xapbY=; b=rB/UeJT5/eO3l18ZhVaHV8ZEhSsfEcqor5wDkMH9YzJt3uBEJff5928CuGdPR0xSO0 KYVuXAlK4z8rCHi9904rkr8/XRbeo4SwLOowtY27l/XEXYMbrMujjc3OL8qj84kZf9jL ZmzBWeihGoIqrOI6Ies1jMnbm1HDEm/cBsYwzkPMAuMpJSY9rcnAl53qbIfSepWjZmhL ZZFGrmoy/SecngwoPuTYufo5FZ9p+0PHfno6Z7lwoVz1o4hAgm+58VpqZojmDJxao/Qd P9WbSVH3/7nYTAPAJD0hWu+IOHSBO/fdUzcSJVkjtO6ddvc6XcSBPQFARDqXLG5iJwhd 0Xjw== 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=BZr8mJ1mJ66M5MXwN6/HePswNTldWfKVbwj4u/xapbY=; b=gyO2bxvD8jSwXt5C/qpA0JEg8UrPueHya40zFKCaR1LUn51whaUtDfsKZnTxU33Eve OCYinGmuO6roQCWPhpT/rgCM8T9zIEhfLtNeuKERdPKzgssstu8qjVtUYQq6yd/2OU/j Wi7m2QpGEyahwZijBqDlUpXKTcfG7o1oDK+OxVGlH/KIqDDzoEb498LDC3J+ox2DvF4p cMEBzmuaZLcrZKbzcXoUgL+0hdUPWTDZht4xgBj2wgOHOD21SY3ejutJHISqNi72XUXd vEGNcrphRIg0BAosjdB/KEuFYw/mEM2trP2xYW1L+Ei6jHmrUJ0sZuInoKrjCbbVry/C 8miQ== X-Gm-Message-State: AOAM533npAxpURciFEE5kZhMRXdue9lZ/bSOUiGT9ZWB+3aZkFl21G5x eaEBoG5i9bM3L7M0IGNHpRIPC5J7kqcgjmpx X-Google-Smtp-Source: ABdhPJy7WRHLHzrg2s8kzCbc7n4vWbMj+D5lyevZyHok8jHGy3+FPu8C3px1f6F2lAwopnjg0Mit3w== X-Received: by 2002:a92:2e12:: with SMTP id v18mr69568ile.100.1628372578235; Sat, 07 Aug 2021 14:42: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 a17sm8062827ios.36.2021.08.07.14.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:57 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 07/49] bsd-user: style nits: apply qemu style to these files Date: Sat, 7 Aug 2021 15:42:00 -0600 Message-Id: <20210807214242.82385-8-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Fix style wrt {} placement, spaces around () and line lengths. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/i386/target_arch_elf.h | 27 ++++++++++++++++----------- bsd-user/x86_64/target_arch_elf.h | 11 +++++++---- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/bsd-user/i386/target_arch_elf.h b/bsd-user/i386/target_arch_elf.h index 20ef0ccbdb..f322fc174b 100644 --- a/bsd-user/i386/target_arch_elf.h +++ b/bsd-user/i386/target_arch_elf.h @@ -25,10 +25,12 @@ static const char *get_elf_platform(void) { static char elf_platform[] = "i386"; int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL); - if (family > 6) + if (family > 6) { family = 6; - if (family >= 3) + } + if (family >= 3) { elf_platform[1] = '0' + family; + } return elf_platform; } @@ -46,7 +48,7 @@ static uint32_t get_elf_hwcap(void) /* * This is used to ensure we don't load something for the wrong architecture. */ -#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) ) +#define elf_check_arch(x) (((x) == EM_386) || ((x) == EM_486)) /* * These are used to set parameters in the core dumps. @@ -55,18 +57,21 @@ static uint32_t get_elf_hwcap(void) #define ELF_DATA ELFDATA2LSB #define ELF_ARCH EM_386 -static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) +static inline void init_thread(struct target_pt_regs *regs, + struct image_info *infop) { regs->esp = infop->start_stack; regs->eip = 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. */ + /* + * 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 = 0; } diff --git a/bsd-user/x86_64/target_arch_elf.h b/bsd-user/x86_64/target_arch_elf.h index d3c139c7a9..e7c8aa2755 100644 --- a/bsd-user/x86_64/target_arch_elf.h +++ b/bsd-user/x86_64/target_arch_elf.h @@ -25,10 +25,12 @@ static const char *get_elf_platform(void) { static char elf_platform[] = "i386"; int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL); - if (family > 6) + if (family > 6) { family = 6; - if (family >= 3) + } + if (family >= 3) { elf_platform[1] = '0' + family; + } return elf_platform; } @@ -42,13 +44,14 @@ static uint32_t get_elf_hwcap(void) } #define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch(x) ( ((x) == ELF_ARCH) ) +#define elf_check_arch(x) (((x) == 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) +static inline void init_thread(struct target_pt_regs *regs, + struct image_info *infop) { regs->rax = 0; regs->rsp = infop->start_stack; From patchwork Sat Aug 7 21:42:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=CuW8wr4F; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwr52zHpz9sWX for ; Sun, 8 Aug 2021 07:45:25 +1000 (AEST) Received: from localhost ([::1]:42038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCU8B-0003sg-4N for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:45:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5t-0006Mz-SY for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:01 -0400 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]:43542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5s-0004lJ-Bl for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:01 -0400 Received: by mail-io1-xd2c.google.com with SMTP id y1so19934770iod.10 for ; Sat, 07 Aug 2021 14:42: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=nOSUvgH5f74ZfkyvhQajEnSvPZqEVu6yJTk1v/dSPeA=; b=CuW8wr4FELZBpLNUv7wXScasImLjI+il+QEGvRmeVij6KOSUI+sIn/J1VK2EptZkoB t61zIGdy/r8VzvLwOmyFk70/W/w1DS2s4MjX5zmM+uqqfkpQ8i35p5h+pLbiTAQrNXkv Sm2UQ9qWl2ajgYX2J84kq0lnxvEmXnbs2T1xiJthJxg3pFE8SbsUAelu6uLRUS+S6/UA iOOVdFUVkDBDlwwOJXr3nXwCwxztwjPQploCzkwEWNZ/BZFwcUfbc0c62FEc64/XpMNs kHzGprpWXhLBvgrJyO8iUAIzBg64ya6DZbUvitYHRc1qqbictPeD4j+JZjHBjo900BuT mIEQ== 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=nOSUvgH5f74ZfkyvhQajEnSvPZqEVu6yJTk1v/dSPeA=; b=KPpeQ6LVYi7VS+wwj59Kb/fpXsNA0rGAIgVZEK+DOTvVkon4iswfpxuqPX5GIzJnc2 YkihcQN8BKYUddJ+VoS1fTXZy+oHzZJmdH6bfmjTzSj6/tyAJ83XDx4VIsxV8wSVA77U bY54p78kBXJ+Idxabgk7BBbkoRDMdnUPuHEvxcYmqO3y7hBFEwtwW7yfTRqYB4Bl0/2a QhByUmAjTbchHnCX4qs50+4B3uizRP2vbX8h9QM3/VAk4W2iKIgCB//TkoUH4pXLRoSD fmVfrAaiADQPPIqI5eR/M1HANOPvZgwdeUSuASsr42bOqwaTFANt6hSyvEOhv9tR9yd1 CPJw== X-Gm-Message-State: AOAM532QhbXCgkviK5Spm3h/q+zvBS7KHd6KRvmnvMA2b6Qf4taDitX1 J2mlSSC7++BuJAuPNEqwK3f0k7YtVj1jN/sk X-Google-Smtp-Source: ABdhPJwN/KQJyvb+uHZD63l2r72jX7ertRVHAv2GtFUm4TqVyptk4C/qu0vboRwYjvPgnPZ76F870w== X-Received: by 2002:a05:6602:2044:: with SMTP id z4mr1138887iod.128.1628372579026; Sat, 07 Aug 2021 14:42: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 a17sm8062827ios.36.2021.08.07.14.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:58 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 08/49] bsd-user: style nits: fix whitespace issues to be qemu standard Date: Sat, 7 Aug 2021 15:42:01 -0600 Message-Id: <20210807214242.82385-9-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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: -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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 8d83f21eda..39098170d5 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -125,7 +125,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, } 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; @@ -133,7 +133,7 @@ int loader_exec(const char *filename, char **argv, char **envp, bprm.p = TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int); for (i = 0 ; i < MAX_ARG_PAGES ; i++) { /* clear page-table */ - bprm.page[i] = NULL; + bprm.page[i] = NULL; } retval = open(filename, O_RDONLY); if (retval < 0) { From patchwork Sat Aug 7 21:42:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=bNEraeqF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwr05rSqz9sWX for ; Sun, 8 Aug 2021 07:45:20 +1000 (AEST) Received: from localhost ([::1]:41544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCU86-0003ZT-DG for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:45:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5u-0006QZ-S5 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:02 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:33425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5t-0004lq-CQ for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:02 -0400 Received: by mail-io1-xd44.google.com with SMTP id n19so20054796ioz.0 for ; Sat, 07 Aug 2021 14:43: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=HmdJUuoeEaAxOp6Dr3RmowtyHKMDOBstjrvo58dyLJo=; b=bNEraeqFEOi5gfqU21qjjmZjQ1zA+zDyfWT7YUiHUrp4HJAI0yjnM8KboepABU2f2G h7ErDq7YdgqJHmGi8/n5BQ2UZwDaI0Qdaaj8jovItgIuDCl6aggtzf4Up/QZBiYEqwUF vhIzCC4p1h3NoML4aL6ZqjZD2KaOEZoWNGA+rB/ZF61rl0le+XhWIdiRpgrwRyOrfTYj mOA+Kioa/Bn0UHrY5Pi/Gn2cMmIhVdoc2obwW0tEHWNdfkqdFWo27yx9lC2ZI9HRE/2d 9O36M9PVOl6MaXPAwvKeK3fHB8nPScC8V+f4hkEQGUheq9AYJixvgMEJjtLBgDkT2cfz RAog== 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=HmdJUuoeEaAxOp6Dr3RmowtyHKMDOBstjrvo58dyLJo=; b=Hg47ATy5Oexlszl8pSnazgoDI/WPo1/cIX/nzulBx1fP8iUheOKludYChKO0XcPdAI iuFG/+saQxPidZRtLWAuj5fdl6NeGZLvct/aaVIL9rKyqfGleWnEdDwMdYGtYo1seg0U 3Q3UQTw1923++lr6dxBeL6rrM9f9okIYAucCurngoFY+Ifjo6+rkXpg5vvmXEKgYWyVw 8HipxybxwJfvyDGrk9qiBpbAdA8pxxYzGNV5CrMneHUmQ8HJosyMUBbd48fDbhHDPK/d AcEBs6lEysA3VB7ng3SbVXXfxctBL+pn6Dg3dzQt8i4t6fVjTLEdi6tiySedqg3PdOlk hEiw== X-Gm-Message-State: AOAM5309w01OcqLOZUqKdGhi58LqYqHm/7XFgB5gEjZJNYyqbkbJt9yZ pi3erpnu7pbL9ZK8D5bcDaBiyRTiscUL7zv/ X-Google-Smtp-Source: ABdhPJya1bVQxyFGRRuXbNN3gIMUINzBQGmmwCl/B7KszYUKKHQFqTng0pBRrSRV45mJ0K7ZmOxPGQ== X-Received: by 2002:a92:6803:: with SMTP id d3mr83469ilc.145.1628372580118; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:42:59 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 09/49] bsd-user: add license Date: Sat, 7 Aug 2021 15:42:02 -0600 Message-Id: <20210807214242.82385-10-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 39098170d5..ec71c5e923 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 . + */ #include "qemu/osdep.h" From patchwork Sat Aug 7 21:42:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=sguoURSK; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwwb1Wnkz9sWl for ; Sun, 8 Aug 2021 07:49:17 +1000 (AEST) Received: from localhost ([::1]:59010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUBv-0006nG-2N for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:49:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5v-0006VN-RH for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:03 -0400 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]:37708) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5u-0004mi-9x for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:03 -0400 Received: by mail-io1-xd2f.google.com with SMTP id l20so17747665iom.4 for ; Sat, 07 Aug 2021 14:43: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=dePqRfLieOh5IHKSbQnDO4W7oo5sOeCIO/RCpBHQhuk=; b=sguoURSKSfvxvOkzXYw63YmXfnAHpfOdXQIG30HGiH/Ec1KyB/oOibpcat+YXdZ9YL dyPleshKlaWwtyMjUVAYAhajzZGwAQctzxDW9m94n/qVc+mPRcSLMwIzR/PaICL8MQiW 1JPyybJRPGeO5VWsi9PDdAfYq4co9w+CRJz60ON+oSdLDPRYMOS7kMK8HczXoLI2k1nQ /ZNbrFL8sTD5qttBqzSAMw39LzScRgwoI4mTKHLHx121hCwxw0dnotn2kw49yEC3MoOw dNufwH1ifuWMyeiluFQabbiptQ29WC1ZLtOHAoQGqMMn7XTkSMfG9XsqnHdAsid1LMo3 vZHQ== 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=dePqRfLieOh5IHKSbQnDO4W7oo5sOeCIO/RCpBHQhuk=; b=COuSu9UVxSlfJIx+Yy0C+G4Gs237gwKC+I+Ka02/NzZWqZRosl1USpkvQsvvih/QT6 6gW1XFgx0UiwsCiOfM9WiMzmzRJ1DoffpyYcEfok+yBsqgvqb4ugDEyolbGp+1NQ0mID Z1ciw8lpHqLerXMJAvumObs5z5n+5IHnh3BUqHvWwQdAgLOwhj9uOuTsjgFizDTsxhos turIY66675ENgmkF8JvQSnD5gYufdXNjEJORXgJhxVmwvJxbUQY98x3qN/BxQxWoTQrZ cWWkYm4C56MNjUgIf0eoc5V+V2tZwYQTrbcZRW/URPsvJsJA61RXApjX4hrtIeP2/Lf+ NaZg== X-Gm-Message-State: AOAM532lwVOVlsyRRkXbxL5rGFuUkJfkMYobcd3wWYHxSFGiBaculLlD IbB0HWar08mFbvm96MD6XB/zH4K+/3+q9eOe X-Google-Smtp-Source: ABdhPJwT6tC/dyvuLqQo01HemOBZvI/fm/zO6vHL/629ac08bLR+/Pc4vhJpjZxn3chEX5qeQ4x1JQ== X-Received: by 2002:a92:6909:: with SMTP id e9mr16360ilc.231.1628372580849; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:00 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 10/49] bsd-user: pass the bsd_param into loader_exec Date: Sat, 7 Aug 2021 15:42:03 -0600 Message-Id: <20210807214242.82385-11-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Pass the bsd_param into loader_exec, and adjust. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- 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, } 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; - bprm.p = TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int); - for (i = 0 ; i < MAX_ARG_PAGES ; i++) { /* clear page-table */ - bprm.page[i] = NULL; + bprm->p = TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int); + for (i = 0; i < MAX_ARG_PAGES; i++) { /* clear page-table */ + bprm->page[i] = NULL; } retval = open(filename, O_RDONLY); if (retval < 0) { return retval; } - bprm.fd = retval; - bprm.filename = (char *)filename; - bprm.argc = count(argv); - bprm.argv = argv; - bprm.envc = count(envp); - bprm.envp = envp; - retval = prepare_binprm(&bprm); + bprm->fd = retval; + bprm->filename = (char *)filename; + bprm->argc = count(argv); + bprm->argv = argv; + bprm->envc = count(envp); + bprm->envp = envp; + + retval = prepare_binprm(bprm); if (retval >= 0) { - if (bprm.buf[0] == 0x7f - && bprm.buf[1] == 'E' - && bprm.buf[2] == 'L' - && bprm.buf[3] == 'F') { - retval = load_elf_binary(&bprm, regs, infop); + if (bprm->buf[0] == 0x7f + && bprm->buf[1] == 'E' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'F') { + retval = 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, /* Something went wrong, return the inode and free the argument pages*/ for (i = 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 5c579d7c2c..65958729f1 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 = NULL; struct target_pt_regs regs1, *regs = ®s1; struct image_info info1, *info = &info1; + struct bsd_binprm bprm; TaskState ts1, *ts = &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)); + /* Zero bsd params */ + memset(&bprm, 0, sizeof(bprm)); + /* Zero out image_info */ memset(info, 0, sizeof(struct image_info)); @@ -565,7 +569,8 @@ int main(int argc, char **argv) } } - if (loader_exec(filename, argv + optind, target_environ, regs, info) != 0) { + if (loader_exec(filename, argv+optind, target_environ, regs, info, + &bprm) != 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); int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, struct image_info *info); From patchwork Sat Aug 7 21:42:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Snnet+Qb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhwtM4Z6kz9sWX for ; Sun, 8 Aug 2021 07:47:23 +1000 (AEST) Received: from localhost ([::1]:50278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUA5-00010W-BK for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:47:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5w-0006Xa-EM for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:04 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:46887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5v-0004mu-3E for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:04 -0400 Received: by mail-io1-xd36.google.com with SMTP id x10so9096552iop.13 for ; Sat, 07 Aug 2021 14:43: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=d/SzdmCxbDbx37uUlzLl6leaezBFWr4q0LzmRZIBccw=; b=Snnet+QbUAdAQq/OSdn9XgOnTfM60AzctVSLZ9Q7SBaSDO4RALd1r1a0ckgD+/H5Ay m+rzHeAAkVjoJJtks915zdgtCW0Tx4Su9bx4VmAehV4IBOsTdr/9FmaHBa5Wpy8IrKSJ cDv1587P6MWif1eu8Esj6IzRrQ3BiOXYSeQoUv9B9XhNy5c9fWXFKWkhi+CZk+fPIwLi JKGWiyDbvI594rW/c+ugadZyM3qUJvFr9oGwI/9EqB8n4I8QfPdCXTP9O+zoo62xDOtT 6JIKBgcv6macoTJdo/2qjlubnIIq+rW9rNot6i5V0BppgMSQ6ifiBRq1q3ow82Lcwnyk BUOQ== 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=d/SzdmCxbDbx37uUlzLl6leaezBFWr4q0LzmRZIBccw=; b=MiSvbaVKLRZY6q/tRBI7+Bm61sueFmcMEH6NWpa76GO9WkQWmSez2OFXQiN+1kxRtR HV8RGeO9TbYfn8BtFV2pI1bm9CH8cc8SAAnkqqVp7aH1gA/gp16QD252yzPDA3DqITWZ QXvUKLmKhavsY3Iic6r70x4IgA+Qse4WZkYqZ26rN8QTO76KIG3aZpng2sMEAdmWr00z cVy7zxssEkBMLwSP21Bp7nrVsWs/VQUXtGXPZiCby7kGAx+htHvfHwwBOluXTOGsFZlJ XFt+WU3qFGIiNVW4wFZg8EalaA12w8n3A80l6G1sklkR+cLtkwpAyxScYG9FIkND0Ume sCdg== X-Gm-Message-State: AOAM532QQJZNSVww8qpUPmx+hV48S00uXLaFs1ES3XoB7bGgLTV707SR mZPV+e9SWZWPv4LeFxJAYzvOfVN5v+vMZL7d X-Google-Smtp-Source: ABdhPJyRZbrzZYFFF43yOEk4F88iJ2ASi/lzIIvQKN7bGLxzTtL7MDp4L6ElNQNKI10XYd5ftJhWPA== X-Received: by 2002:a05:6e02:107:: with SMTP id t7mr97029ilm.77.1628372581832; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:01 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 11/49] bsd-user: Fix calculation of size to allocate Date: Sat, 7 Aug 2021 15:42:04 -0600 Message-Id: <20210807214242.82385-12-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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, char **envp, struct target_pt_regs *regs, struct image_info *infop, struct bsd_binprm *bprm) { - int retval; - int i; + int retval, i; - bprm->p = TARGET_PAGE_SIZE * MAX_ARG_PAGES - sizeof(unsigned int); + bprm->p = TARGET_PAGE_SIZE * MAX_ARG_PAGES; for (i = 0; i < MAX_ARG_PAGES; i++) { /* clear page-table */ bprm->page[i] = NULL; } From patchwork Sat Aug 7 21:42:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=d3/wHM+r; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwwb1L8sz9sWX for ; Sun, 8 Aug 2021 07:49:17 +1000 (AEST) Received: from localhost ([::1]:58838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUBu-0006fP-27 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:49:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5x-0006be-DP for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:05 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:43945) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5v-0004oA-U1 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:05 -0400 Received: by mail-io1-xd42.google.com with SMTP id y1so19935003iod.10 for ; Sat, 07 Aug 2021 14:43: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=/m+LrsTqQXACGZ2lhzaNittRoT4FuKArZPmmbyQaTCo=; b=d3/wHM+rSJyrWFYXEth2fvEu1tE2SHhDyZv+GqG8iMOQSvXW4DyLe0AR2vwg1pxEse FMC84+I5DKoy7mmiDw6Lh36WaoDY1jXMZeW1tSWXRZgB1pJhYGm35TmFcTpcckh7sCDQ 9ju2TXwSLrNLlHR03+NDafkNs1Uvb1skSaaQLONnpmckXSHjqxFuKoHNsZ+OgF/AWvwO VOOH1JEf8TusgI1TQnYuiCbRkjoHGLuYRXIkSMzZaP155zhzrb+BcwpdVcWTPd/vJbIc RH+k/GJRpy9p+icjzqza0fZEJrOqEUfAn2lDnXDWDhRinKcqTkJinSC2eKKaMV2HdwB5 5jhA== 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=/m+LrsTqQXACGZ2lhzaNittRoT4FuKArZPmmbyQaTCo=; b=ENC8GL9iF63RBBawE2GyXSWTEepBwsIxpowGErYH8/SGRcak38xMJ9RvlyDs3ILput 5vhuJOdTBQGvZm5rtwXO6jc9u7RaA7Kse04eq8ULkBUD0tTEES9BlObAWbLBknL7FCwF 7lH95TKIY+MjhGH7gHtqyqtmnHQ+rQB+OGtvw4nZJjsgGFc9IbNaiOI5zf9vBiwX8m5m H77uz4DFQ7SzgSZqziJs44UEQv2OtXGGHbt/jqVgrv3ZzvnYYVCv1Mw5q/J6KpqdixNu DPSdrDcjaAHey8Dgv+ZJpfQBR1YgZvDt8lx1et/ZtNdEKhIgRuTvliAizM1IBQXJnSYO O6NA== X-Gm-Message-State: AOAM531gXjMyn1LAJfTO+lNJe30NvVYTqKDSA/TXQTpCZ3mOKwHwhj5e G9DNSpdFbjoLoiTWhwgHmz4lFWPPICL0jZcl X-Google-Smtp-Source: ABdhPJwOTRpJToYwZvjyX3WrkCAnELNDMpg33YH1yX5aXWf1wIzP1ErTsbJ4tY3MthvXx9BNYPWnfQ== X-Received: by 2002:a05:6e02:190d:: with SMTP id w13mr100884ilu.53.1628372582772; Sat, 07 Aug 2021 14:43:02 -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 a17sm8062827ios.36.2021.08.07.14.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:02 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 12/49] bsd-user: implement path searching Date: Sat, 7 Aug 2021 15:42:05 -0600 Message-Id: <20210807214242.82385-13-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Stacey Son , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use the PATH to find the executable given a bare argument. Signed-off-by: Stacey Son Signed-off-by: Warner Losh --- bsd-user/bsdload.c | 73 +++++++++++++++++++++++++++++++++++++++++++++- bsd-user/qemu.h | 3 +- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 379015c744..f8030d72bc 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -139,17 +139,88 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, return sp; } +static bool is_there(const char *candidate) +{ + struct stat fin; + + /* XXX work around access(2) false positives for superuser */ + if (access(candidate, X_OK) == 0 && stat(candidate, &fin) == 0 && + S_ISREG(fin.st_mode) && (getuid() != 0 || + (fin.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0)) { + return true; + } + + return false; +} + +static bool find_in_path(char *path, const char *filename, char *retpath, + size_t rpsize) +{ + const char *d; + + while ((d = strsep(&path, ":")) != NULL) { + if (*d == '\0') { + d = "."; + } + if (snprintf(retpath, rpsize, "%s/%s", d, filename) >= (int)rpsize) { + continue; + } + if (is_there((const char *)retpath)) { + 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 *p, *path = NULL, fullpath[PATH_MAX]; int retval, i; bprm->p = TARGET_PAGE_SIZE * MAX_ARG_PAGES; for (i = 0; i < MAX_ARG_PAGES; i++) { /* clear page-table */ bprm->page[i] = NULL; } - retval = open(filename, O_RDONLY); + + if (strchr(filename, '/') != NULL) { + path = realpath(filename, fullpath); + if (path == NULL) { + /* Failed to resolve. */ + return -1; + } + if (!is_there(path)) { + return -1; + } + retval = open(path, O_RDONLY); + bprm->fullpath = g_strdup(path); + } else { + p = getenv("PATH"); + if (p == NULL) { + return -1; + } + + path = g_strdup(p); + if (path == NULL) { + fprintf(stderr, "Out of memory\n"); + return -1; + } + + if (!find_in_path(path, filename, fullpath, sizeof(fullpath))) { + return -1; + } + retval = open(fullpath, O_RDONLY); + bprm->fullpath = g_strdup(fullpath); + + g_free(path); + } + + /* bprm->fullpath must be populated. */ + if (bprm->fullpath == NULL) { + fprintf(stderr, "Out of memory\n"); + return -1; + } if (retval < 0) { return retval; } 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 */ }; void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); From patchwork Sat Aug 7 21:42:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514725 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=fjPomm/8; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhwtR3FgVz9sWX for ; Sun, 8 Aug 2021 07:47:27 +1000 (AEST) Received: from localhost ([::1]:50644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUA8-0001GM-T9 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:47:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU5y-0006iR-Lj for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:06 -0400 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]:33364) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5w-0004oM-Qk for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:06 -0400 Received: by mail-io1-xd34.google.com with SMTP id n19so20055012ioz.0 for ; Sat, 07 Aug 2021 14:43:04 -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=vgjTCAQowlCVaAJa2bIQiBMowZ7EIsXDX0deg8KnEcc=; b=fjPomm/8SM5bohubpBLG/RsG3Yy+RxnvV+4jH5HOgYD0YNpinDeJm3pFdjuUTgDPOr MW+0sIKShvQMkRLSQRQh+psYmpuJ/nN7L+8C5pxLYN+dpW1Wc4TxbrgsQNiDxGJqQv0u zo+7wPPupspCg0y7xEExSEM9gmg95TBPvjTMNA37NxGQu52aVr7g5zkSUAL2ivYTE+B6 Rm0/PZSEhubpYpXSv1/x6KbsRTuf+KnIEACRvqXMa1oqyOCkTYD7ogdpkWL0fpQIUORy pMk9nQ/j6NEt8NZjiR15Cz930x5uQfDQEpsC/pFpRR3bjvIxhtwNlzMI9TGAmChNgMv1 hGYQ== 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=vgjTCAQowlCVaAJa2bIQiBMowZ7EIsXDX0deg8KnEcc=; b=ke3TfGk0LHZ0YxsTMIuqsDmLC3BMWmte6SzWsL1qlCGtiU547EqLuppp3XAlZfv1HU EtYN1lBoItEn8HRmlMzfedOdth48xEK/g3CBzI9ox3KvLOMMsiBRQRWUMp78YO+zPuE9 1GLyXLZTDNsiWi7cDyIdajAoER2lsk1aDwD64m9Vcfh0YbyQM7woVkVEzWaQHKQ6nJoW dw2uJ1OAEQh6zPUcEDyk3SAtnbWx3QM7uRp7oDY6cimMa+Y3F77KIgUdPEWC041uTXAK i4i4+fzJFSJq+9B482LZ06O6fNKGfo3LQ0ub2x0jntGlaO65s80PLK07gMOJShQPbz4Z odrA== X-Gm-Message-State: AOAM532b6CZR9Ptpzuaf8oOjjbut30+X64VZSttaXR19KZEBTF6Sk/0O ihadE7r7PbEeHGXU1Qvgmt6YYy36nqeWfpxk X-Google-Smtp-Source: ABdhPJy2t9Q9GWsmLUJzUv86DbbzSMOJhDtQIDlg3k0gW9rtlUfcuC4FClLraVojdII/8G7RjyDM/w== X-Received: by 2002:a92:c266:: with SMTP id h6mr507338ild.273.1628372583482; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:03 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 13/49] bsd-user: Eliminate elf personality Date: Sat, 7 Aug 2021 15:42:06 -0600 Message-Id: <20210807214242.82385-14-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The linux kernel supports a number of different ELF binaries. The Linux userland 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 @@ #include "target_arch_elf.h" -/* from personality.h */ - -/* - * Flags for bug emulation. - * - * These occupy the top three bytes. - */ -enum { - ADDR_NO_RANDOMIZE = 0x0040000, /* disable randomization of VA space */ - FDPIC_FUNCPTRS = 0x0080000, /* userspace function ptrs point to descriptors - * (signal handling) - */ - MMAP_PAGE_ZERO = 0x0100000, - ADDR_COMPAT_LAYOUT = 0x0200000, - READ_IMPLIES_EXEC = 0x0400000, - ADDR_LIMIT_32BIT = 0x0800000, - SHORT_INODE = 0x1000000, - WHOLE_SECONDS = 0x2000000, - STICKY_TIMEOUTS = 0x4000000, - ADDR_LIMIT_3GB = 0x8000000, -}; - -/* - * Personality types. - * - * These go in the low byte. Avoid using the top bit, it will - * conflict with error returns. - */ -enum { - PER_LINUX = 0x0000, - PER_LINUX_32BIT = 0x0000 | ADDR_LIMIT_32BIT, - PER_LINUX_FDPIC = 0x0000 | FDPIC_FUNCPTRS, - PER_SVR4 = 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO, - PER_SVR3 = 0x0002 | STICKY_TIMEOUTS | SHORT_INODE, - PER_SCOSVR3 = 0x0003 | STICKY_TIMEOUTS | - WHOLE_SECONDS | SHORT_INODE, - PER_OSR5 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS, - PER_WYSEV386 = 0x0004 | STICKY_TIMEOUTS | SHORT_INODE, - PER_ISCR4 = 0x0005 | STICKY_TIMEOUTS, - PER_BSD = 0x0006, - PER_SUNOS = 0x0006 | STICKY_TIMEOUTS, - PER_XENIX = 0x0007 | STICKY_TIMEOUTS | SHORT_INODE, - PER_LINUX32 = 0x0008, - PER_LINUX32_3GB = 0x0008 | ADDR_LIMIT_3GB, - PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS,/* IRIX5 32-bit */ - PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS,/* IRIX6 new 32-bit */ - PER_IRIX64 = 0x000b | STICKY_TIMEOUTS,/* IRIX6 64-bit */ - PER_RISCOS = 0x000c, - PER_SOLARIS = 0x000d | STICKY_TIMEOUTS, - PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO, - PER_OSF4 = 0x000f, /* OSF/1 v4 */ - PER_HPUX = 0x0010, - PER_MASK = 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 target_pt_regs *regs, abi_ulong load_addr, load_bias; int load_addr_set = 0; unsigned int interpreter_type = 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 target_pt_regs *regs, #endif char passed_fileno[6]; - ibcs2_interpreter = 0; load_addr = 0; load_bias = 0; elf_ex = *((struct elfhdr *) bprm->buf); /* exec-header */ @@ -856,20 +794,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, exit(-1); } - /* 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") == 0 || - strcmp(elf_interpreter, "/usr/lib/ld.so.1") == 0) { - ibcs2_interpreter = 1; - } - -#if 0 - printf("Using ELF interpreter %s\n", path(elf_interpreter)); -#endif if (retval >= 0) { retval = open(path(elf_interpreter), O_RDONLY); if (retval >= 0) { @@ -1099,7 +1023,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, load_symbols(&elf_ex, bprm->fd); if (interpreter_type != INTERPRETER_AOUT) close(bprm->fd); - info->personality = (ibcs2_interpreter ? PER_SVR4 : PER_LINUX); #ifdef LOW_ELF_STACK info->start_stack = bprm->p = 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 - if (info->personality == 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 = elf_entry; 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; }; #define MAX_SIGQUEUE_SIZE 1024 From patchwork Sat Aug 7 21:42:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514730 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=HG5ocVKc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwwc1Mvkz9sWX for ; Sun, 8 Aug 2021 07:49:20 +1000 (AEST) Received: from localhost ([::1]:59240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUBx-0006wd-T9 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:49:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU60-0006nZ-20 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:08 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]:43542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5y-0004p9-1V for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:07 -0400 Received: by mail-io1-xd2b.google.com with SMTP id y1so19935143iod.10 for ; Sat, 07 Aug 2021 14:43: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=Vp5f7S90DTvEQ1BO9I5cNE8X1x32WxFaXNsHwFc0TRw=; b=HG5ocVKcCBfbbC3r/ly/NamjNG4VNNQu/1SWt7Fl+4a91CCK/LZUuio1lLatWqkkhL XEzDptcnlnuE8DN05ikSRQMABunjrl06ntjd1RyMjXfNpAIrQUpYAuObdms94SGJPExf TjE4Q2XBWU+iPYdAeTQUui+PV//cbVgnan/5qyB8mClQA8lK6hMqcxbxXS0LhWB+cWMU Uw9W49d0qcl9KVlGRJJxOKw0skh7jU4FL4jrzAJnAFbklCS3GCKSIxKDE+8eXAivEn9U 5MP2Tvuz/qAvPfTvWo/GjycXOCAhIaPYTc/tvTZQjom6W4y3K5cBLPpG4Xn3b70/ISjR 12xg== 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=Vp5f7S90DTvEQ1BO9I5cNE8X1x32WxFaXNsHwFc0TRw=; b=YNH/IbQ6bREqQOzb5P7XgyLTVKNwAjxGgDW0WWc+Y5IziR8kw0UDrLmzj5nGI9k8oc h0NP5M1sTaSbuQYeS1HilJDB4a9otRrtEGZTsWEiBLDVeJN78bwLnXMNqezaO2wFhDA9 sqPuSlYWHCkz2roTtK3Wd6D1te9aeWggYS1qWIFNGNI6fo15zDWhaQ42Mu/lZyWtlcUg 7HJlu/QwxJLHvmqN/QGFCkc599kte2QgVVatZWPEBet/whiRp3WGnG/iGvo6/mMsM7aG r2qq3bFNGOYWYX9GwvUsI/8Dg21VM0eGKB2kmOZYXfGnfD/p0iykT8glS/Kszq1nzzpr ShdA== X-Gm-Message-State: AOAM533/wKxEelVD5RAWpGCCoSSV+c8XHQ37QCumOOdS4nLiNL3oSyY5 L0MaQ2yv8F412XkF7e0SOS64ENJ/RoJIl1ol X-Google-Smtp-Source: ABdhPJxsrE5rjtxkYfM9FfEu3bTOaKGs7F4aDF4n8+geBj0JeRwiHW/q8JcIIiW+d9qtLnk3LYWdqg== X-Received: by 2002:a92:1e10:: with SMTP id e16mr211808ile.266.1628372584780; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:03 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 14/49] bsd-user: remove a.out support Date: Sat, 7 Aug 2021 15:42:07 -0600 Message-Id: <20210807214242.82385-15-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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: kevans@freebsd.org, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Remove still-born a.out support. The BSDs switched from a.out to ELF 20+ years 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 removing it entirely. Should future support be required, it would be better to start from scratch. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- 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 f8030d72bc..df81e36d88 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -98,7 +98,7 @@ static int prepare_binprm(struct bsd_binprm *bprm) /* 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 = sizeof(abi_ulong); abi_ulong envp; @@ -108,13 +108,6 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, envp = sp; sp -= (argc + 1) * n; argv = sp; - if (push_ptr) { - /* FIXME - handle put_user() failures */ - sp -= n; - put_user_ual(envp, sp); - sp -= n; - put_user_ual(argv, sp); - } sp -= 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..9c34e2ffcb 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -52,25 +52,6 @@ #include "elf.h" -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) @@ -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)) -#define INTERPRETER_NONE 0 -#define INTERPRETER_AOUT 1 -#define INTERPRETER_ELF 2 - #define DLINFO_ITEMS 12 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 *from, unsigned long n) memcpy(to, from, n); } -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 argc, 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 argc, int envc, size += DLINFO_ARCH_ITEMS * 2; #endif size += envc + argc + 2; - size += (!ibcs ? 3 : 1); /* argc itself */ + size += 1; /* argc itself */ size *= n; if (size & 15) sp -= 16 - (size & 15); @@ -370,7 +345,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, #endif #undef NEW_AUX_ENT - sp = loader_build_argptr(envc, argc, sp, p, !ibcs); + sp = loader_build_argptr(envc, argc, sp, p); return sp; } @@ -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 target_pt_regs *regs, { struct elfhdr elf_ex; struct elfhdr interp_elf_ex; - struct exec interp_ex; int interpreter_fd = -1; /* avoid warning */ abi_ulong load_addr, load_bias; int load_addr_set = 0; - unsigned int interpreter_type = 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 target_pt_regs *regs, #ifdef LOW_ELF_STACK abi_ulong elf_stack = ~((abi_ulong)0UL); #endif - char passed_fileno[6]; load_addr = 0; load_bias = 0; @@ -760,7 +732,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, end_code = 0; start_data = 0; end_data = 0; - interp_ex.a_info = 0; for (i = 0;i < elf_ex.e_phnum; i++) { if (elf_ppnt->p_type == PT_INTERP) { @@ -813,7 +784,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, } } if (retval >= 0) { - interp_ex = *((struct exec *) bprm->buf); /* aout exec-header */ interp_elf_ex = *((struct elfhdr *) bprm->buf); /* elf exec-header */ } if (retval < 0) { @@ -830,20 +800,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, /* Some simple consistency checks for the interpreter */ if (elf_interpreter) { - interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT; - - /* Now figure out which format our binary is */ - if ((N_MAGIC(interp_ex) != OMAGIC) && (N_MAGIC(interp_ex) != ZMAGIC) && - (N_MAGIC(interp_ex) != QMAGIC)) { - interpreter_type = INTERPRETER_ELF; - } - if (interp_elf_ex.e_ident[0] != 0x7f || - strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) != 0) { - interpreter_type &= ~INTERPRETER_ELF; - } - - if (!interpreter_type) { + strncmp((char *)&interp_elf_ex.e_ident[1], "ELF",3) != 0) { free(elf_interpreter); free(elf_phdata); close(bprm->fd); @@ -854,24 +812,11 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, /* OK, we are done with that, now set up the arg stuff, and then start this sucker up */ - { - char *passed_p; - - if (interpreter_type == INTERPRETER_AOUT) { - snprintf(passed_fileno, sizeof(passed_fileno), "%d", bprm->fd); - passed_p = passed_fileno; - - if (elf_interpreter) { - bprm->p = copy_elf_strings(1, &passed_p, bprm->page, bprm->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; } /* OK, This is the point of no return */ @@ -997,13 +942,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, end_data += load_bias; if (elf_interpreter) { - if (interpreter_type & 1) { - elf_entry = load_aout_interp(&interp_ex, interpreter_fd); - } - else if (interpreter_type & 2) { - elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd, - &interp_load_addr); - } + elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd, + &interp_load_addr); reloc_func_desc = interp_load_addr; 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); - if (interpreter_type != INTERPRETER_AOUT) close(bprm->fd); + close(bprm->fd); #ifdef LOW_ELF_STACK info->start_stack = bprm->p = elf_stack - 4; #endif bprm->p = create_elf_tables(bprm->p, - bprm->argc, - bprm->envc, - &elf_ex, - load_addr, load_bias, - interp_load_addr, - (interpreter_type == INTERPRETER_AOUT ? 0 : 1), - info); + bprm->argc, + bprm->envc, + &elf_ex, + load_addr, load_bias, + interp_load_addr, + info); info->load_addr = reloc_func_desc; info->start_brk = info->brk = elf_brk; info->end_code = end_code; @@ -1063,12 +1002,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, return 0; } -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 { 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); From patchwork Sat Aug 7 21:42:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=SNgbpArS; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwwc42J4z9sWl for ; Sun, 8 Aug 2021 07:49:20 +1000 (AEST) Received: from localhost ([::1]:59310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUBy-0006z9-97 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:49:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU60-0006qk-Pv for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:08 -0400 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]:37704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU5z-0004qN-BA for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:08 -0400 Received: by mail-io1-xd2a.google.com with SMTP id l20so17748005iom.4 for ; Sat, 07 Aug 2021 14:43: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=xXwZ9rhUpq9Gt/ZMCIP1uv3uRc6hw3LhHitwZ8QAHYE=; b=SNgbpArSE0ZAIcBexeapcUQTq3JIB/i63uPZmStmgTVq1inuq/6QQJAIa718oug2oV vDMyv1xsAECKHOB9uLHnskfNewuGG7eiLVz4iDansKLPk7dzSuc0y6+KmHyj5DdVigZ3 9wMkg6icK+bSdxVJiDXTwk49B3A79nJegMdNuQlROMk1T5rYiAaJp6G1a5wOIvjRPM5n wcwS5YlO4fZ8yf/QzT1ZOsiHS4Dobwuzlfccm0xqPNZp6sNYqVSyKtjNPUjH3GBdMT6k MXg5VLJsO17WQzFkeXprv+vPzJiDAhA283jHKLyx/bOzyyyy6ef4KRZceit3CA7dGkea uUxA== 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=xXwZ9rhUpq9Gt/ZMCIP1uv3uRc6hw3LhHitwZ8QAHYE=; b=izm6qrcBAiKNcpE2FreHlvAMZR+A6TVsIFTiz5tSkVW866aM7a87dSY40K+YlVA3gP UkPwlRlJ1HrmNemUxJ6UUyuCUGZfr6uSODcPD4DW0Ik3Pd9jSRPONxmA3SJxH0E4iStN dKlRtT297oef7CV6iZxlk/9PZVdLfzMWexZG7xWAzA5yirEfHfrl/3qMrFBX0IHA7MPx 3ebvyk6lzZp2tizQbWCzodLoxxh5fPFM6ltiP6gSYjsLb+HpkqKR/6Y+f/xlRW6sqM/8 8GbRHyQbbfIvuQ2ef6MFPAjjtirRTUFOfwjC6dzCV5jfUKwlBtulqstFeflq6aVUTXCE E9aA== X-Gm-Message-State: AOAM531asivdzUrHBJOMwFQpy9uQMMMzsEEgKdVZ9EcpA4wU3O0VkS4n bmBpnHTfd/O+6kmRKNWsRggGlawy3E9P8KFz X-Google-Smtp-Source: ABdhPJx3q9SeJM38z6o+GAxrqCizrlVk3g+KppgYjpecqRTO/mRYLBeDuALjKswbN59Ni0xX4yfsGw== X-Received: by 2002:a92:cb4d:: with SMTP id f13mr473224ilq.57.1628372585842; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:05 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 15/49] bsd-user: TARGET_NGROUPS unused in this file, remove Date: Sat, 7 Aug 2021 15:42:08 -0600 Message-Id: <20210807214242.82385-16-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 df81e36d88..006e19cf3f 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -19,8 +19,6 @@ #include "qemu.h" -#define TARGET_NGROUPS 32 - /* ??? This should really be somewhere else. */ abi_long memcpy_to_target(abi_ulong dest, const void *src, unsigned long len) From patchwork Sat Aug 7 21:42:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=v42mg8uo; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhwyP1TJtz9sWX for ; Sun, 8 Aug 2021 07:50:53 +1000 (AEST) Received: from localhost ([::1]:39304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUDS-00042B-TR for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:50:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU61-0006vc-R3 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:09 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:39695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU60-0004qZ-1M for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:09 -0400 Received: by mail-io1-xd36.google.com with SMTP id r72so5854634iod.6 for ; Sat, 07 Aug 2021 14:43: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=2AZgZDX4LsZq+UoPxf8T2BJxQGH5PAB104ChPJfXbEA=; b=v42mg8uo9h/k6AJ/BVX34NZAAnzC2SgRCA4kIQXMTfs/J6HeR1bMD13p4pr8dAqcB/ yxZCldwHCWfi+T0j9iCyv0e32nPen2wq+pr//nadi6IQAuXYiCcDZXQz6wxqAPU+nYPC 5XY1Qgn0Btqef7Dvxqdc0pIq3JAFvPUgbb0ESmKgMBTLIfkKjt6cnCdOW31tq+whsZhO W96UCsG8nhvOXQeeMNpuC2TsyUx9Td/t1I7CW4JKNqHA9dCL/5wnlZLX4xsesrNzYh0w KTs6FaHQHpottU2m4/ViSRP36+qd5tFj4fVfWf3qBiKExk1dSUfybOfrLlBLQ6ulg1I4 V4nA== 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=2AZgZDX4LsZq+UoPxf8T2BJxQGH5PAB104ChPJfXbEA=; b=H0fmtJdRH/5u0Bjd0LHQSlc0pr/VUDClXpCEuEzL8BWnic7RNVNhaYgwQHQh56I8gN O69u7Qd0Eejsxea/K/RWSSk111G67dpgQSBRcTqaTjC28xnDgBnwHSeKhyXk30snd04P Zu8zfAYSdqPG3xsuXP5SIVKeopYMMrufGed+bwFDMt8FcpmHqc2cfkM+QwZRPueEhyda 0K2N96BX2fJN0JmtTbv6BAYcdLOmFN8y5ebr+NEVmkUn6UD2DG8ZypzU8i2O9inUvZrk RkrYifhe3runK9DQKT7xqVscNsuaJ6pc3Kw4ChfXqefh+z4ayuBG5t6DO56BsYy/7BHa 1lMw== X-Gm-Message-State: AOAM531VB6MEJX6gvCfrR+zWwnsraqUvGsPtBls+LtCKgij+aqGX0a3Q E4h9N7URmjnRebmIXvuAbCdlSLmm5p5kvanH X-Google-Smtp-Source: ABdhPJwvtN7PvRYXHV9MA2xnwDKFBJczCTu8TahC8Dh0SkVgs960BXfZn5IAnZOCHkaajdZgz+sY2Q== X-Received: by 2002:a92:d5cb:: with SMTP id d11mr5647ilq.133.1628372586787; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:06 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 16/49] bsd-user: elfload: simplify bswap a bit. Date: Sat, 7 Aug 2021 15:42:09 -0600 Message-Id: <20210807214242.82385-17-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 9c34e2ffcb..8a6a72bf05 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -67,13 +67,13 @@ static inline void memcpy_fromfs(void *to, const void *from, unsigned long n) { - memcpy(to, from, n); + memcpy(to, from, n); } #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 offset */ bswap32s(&ehdr->e_flags); /* Processor-specific flags */ bswap16s(&ehdr->e_ehsize); /* ELF header size in bytes */ - bswap16s(&ehdr->e_phentsize); /* Program header table entry size */ + bswap16s(&ehdr->e_phentsize); /* Program header table entry size */ bswap16s(&ehdr->e_phnum); /* Program header table entry count */ - bswap16s(&ehdr->e_shentsize); /* Section header table entry size */ + bswap16s(&ehdr->e_shentsize); /* Section header table entry size */ bswap16s(&ehdr->e_shnum); /* Section header table entry count */ - bswap16s(&ehdr->e_shstrndx); /* Section header string table index */ + bswap16s(&ehdr->e_shstrndx); /* Section header string table index */ } -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 = 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 */ + } } -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 = 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); + } } 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 */ /* * '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 = 0; error = 0; -#ifdef BSWAP_NEEDED bswap_ehdr(interp_elf_ex); -#endif /* First of all, some simple consistency checks */ if ((interp_elf_ex->e_type != ET_EXEC && interp_elf_ex->e_type != 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 = elf_phdata; - for (i = 0; ie_phnum; i++, eppnt++) { - bswap_phdr(eppnt); - } -#endif + bswap_phdr(elf_phdata, interp_elf_ex->e_phnum); if (interp_elf_ex->e_type == 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 = 0; i < hdr->e_shnum; i++) { if (read(fd, &sechdr, sizeof(sechdr)) != sizeof(sechdr)) return; -#ifdef BSWAP_NEEDED - bswap_shdr(&sechdr); -#endif + bswap_shdr(&sechdr, 1); if (sechdr.sh_type == SHT_SYMTAB) { symtab = 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)) != 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) i = 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 == SHN_UNDEF || syms[i].st_shndx >= SHN_LORESERVE || @@ -679,9 +682,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, load_addr = 0; load_bias = 0; elf_ex = *((struct elfhdr *) bprm->buf); /* exec-header */ -#ifdef BSWAP_NEEDED bswap_ehdr(&elf_ex); -#endif /* First of all, some simple consistency checks */ if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) || @@ -715,12 +716,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, return -errno; } -#ifdef BSWAP_NEEDED - elf_ppnt = elf_phdata; - for (i = 0; i < elf_ex.e_phnum; i++, elf_ppnt++) { - bswap_phdr(elf_ppnt); - } -#endif + bswap_phdr(elf_phdata, elf_ex.e_phnum); + elf_ppnt = elf_phdata; elf_bss = 0; From patchwork Sat Aug 7 21:42:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=tChnutsj; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhwyR2hhwz9sWX for ; Sun, 8 Aug 2021 07:50:55 +1000 (AEST) Received: from localhost ([::1]:39588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUDV-0004EP-2y for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:50:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU63-000724-7M for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:11 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:36832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU61-0004rJ-1U for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:10 -0400 Received: by mail-io1-xd36.google.com with SMTP id f11so19875899ioj.3 for ; Sat, 07 Aug 2021 14:43: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=Myl5Kg/hYpTADGYYXyFryFopq7pZ0lkHu9eYZSvu+pg=; b=tChnutsjKbf4Xj0+IdhM5AbaXQG1uEria6Y4V7qBFC9uJhNuVp1pcYF93OPnbwWpph fccjd6oaXW9JJZkeUfeyhHAeh5SCFDTMhmKt+7p6gIiFhI1okKNMRuv7YF2k7iL1ZONw hpHVGQBGbAoL0pD42NPOGtp+XCs96URtsh7strXhX+41pe3oSceZtjE5QsrKx1GP6wbh xPkmZGu58FHBvLF6IbMTEYWeGVQ5Wv+L5uwQEcDcaNj5G8NC3P5m54yOsfKpe5E4wTzk cbAKfvj/wQuPE+LcM4OFZrhy82dlwVVx5ia2TqvnfUd41q2XG5RVqjpqB5Jm3+niuwKa rmLQ== 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=Myl5Kg/hYpTADGYYXyFryFopq7pZ0lkHu9eYZSvu+pg=; b=MH+jkdwPaOp0VZrLcvd96B44wYw0pXCmgEnNwqiemlCEd+cOvtWnlR4Q0egOvVGmDY W6wtNFEkve+aHcGqQ+7Zc8wS6E0F+ByYNj1+gy6ezD7Vqq8JJwKQaOxudt1tNyKP9cqT qeRN2/HxUOMdXCJZXeOoDePOKwRWOdKIxp2DimW8+p2ecOiUbZvZrIdrBIZ7weyMeEc3 tFgnS3pm0QQSLTCHeFe0O3Euh/ydq950Pm/wgaSVWkttPuSpM/tkqZTc+sX1mCqQ4mBz +EeZMIdPFxiWu+sdcJM01DRf5O3Jor+bp6qUZMR9EsmMeffg1TVbsVtjJyMWPi1LDRdZ W2+Q== X-Gm-Message-State: AOAM530hQGPY/3Re6M2JbqW1t5AZ02ELyM4CAWPjM6yk0dzxnxjUzvKT nl9Eq8RoEdDMMmphQJbMxmMd2q2fbyElfe5F X-Google-Smtp-Source: ABdhPJyqCRY0uyC2/sfUiFHUZgRhuClCbOoyemKHLk03toulPdDBK612VkICNTftuBckBD+wklbrQA== X-Received: by 2002:a02:a581:: with SMTP id b1mr15918116jam.84.1628372587743; Sat, 07 Aug 2021 14:43:07 -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 a17sm8062827ios.36.2021.08.07.14.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:07 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 17/49] bsd-user: assume pthreads and support of __thread Date: Sat, 7 Aug 2021 15:42:10 -0600 Message-Id: <20210807214242.82385-18-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.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, Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" All compilers for some time have supported this. Follow linux-user and eliminate the #define THREAD and unconditionally insert __thread where needed. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- 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 65958729f1..9166049c5a 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -309,7 +309,7 @@ static void usage(void) exit(1); } -THREAD CPUState *thread_cpu; +__thread CPUState *thread_cpu; 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" -#if defined(CONFIG_USE_NPTL) -#define THREAD __thread -#else -#define THREAD -#endif - /* * This struct is used to hold certain information about the image. Basically, * 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_addr) #define unlock_user_struct(host_ptr, guest_addr, copy) \ unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0) -#if defined(CONFIG_USE_NPTL) #include -#endif #endif /* QEMU_H */ From patchwork Sat Aug 7 21:42:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514733 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Gg0+CJur; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhwyS6LvMz9sWX for ; Sun, 8 Aug 2021 07:50:56 +1000 (AEST) Received: from localhost ([::1]:39654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUDW-0004HM-JH for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:50:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43406) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU63-00074J-Pu for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:11 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:33427) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU62-0004sb-8B for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:11 -0400 Received: by mail-io1-xd44.google.com with SMTP id n19so20055392ioz.0 for ; Sat, 07 Aug 2021 14:43: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=fffwkuyOJdVnhGXC/B1gg3Dw6R62PN5p41n4wCJVr3Y=; b=Gg0+CJurbgGeau2wiwQU2O3xuMN2LUM/7hlzX0wMuESEC9sL9VPMRSh2maGDoVVO1O Tvmn25o/YpwwpLIe8JuS0brgSozlvYZ4L6fSVYSfYFH9xcYFIfadkbleFAEBtHeKgEBm /MVWIJAA9XIZ13PQQUjXpzkEt7yDusAlUlPNXDXYCxoEpHD+SlOadYkjsv+woAPDmwXs 26vUKSz+FqGV0+pffIrhKKfHDFCD6AZp5VC89KSAlYnS/aTIqG+yr+wk9TrUDok6pTvV K1c+JsSldVYAwkCfeC9tm/t8o/NMOfJY41NVaIkzJqSZg6Rffp2J8Cmdt2jooFV7qtNC x20g== 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=fffwkuyOJdVnhGXC/B1gg3Dw6R62PN5p41n4wCJVr3Y=; b=nI0KUekNq3GirGurnJo9JtGtZjmPJfun2PTo80lsURXz3DwNlqaQRHWYf/4IXXL8KA KnSMC8xsev9L0Z4QeRDzqHwyEpqFRKeLB20bOtjcmYRWQnHSfcgrCGOgvNlnXMRthrlu 1lBcpD24ToehMCKHb7zME09mqAXWpspHNEZAn88ZzOSfl3DmUdzpklRpUvYT9h4o6SyR BI84L8f21Oi1Er8jFWcXOp5rwNQx4/2B4NXoL6hG6uG7YphJH6YIkIDgSFjnloZLwvUa kkauyTPJ83o2zGBrpupNzo4woDOPD3MoGlbIBRAc1pQn1N7Xfg6Cb2dpimfseM4u1UfR hKRA== X-Gm-Message-State: AOAM533aOR7JZplA+QfLCM9Qthd/dsDqNMTqc7G4xkagcoZi1H+Hc7er To2fj3zi2qM4Wb5bP4YTRSC6G1OGe1Dw1wqy X-Google-Smtp-Source: ABdhPJywaYJI51UT4mDWOY9DoxQifRXqYJ3QNv5F7TnfjaSgmLss6NRRxmaXkywuMZEt7YSfWQqnRw== X-Received: by 2002:a6b:e706:: with SMTP id b6mr175837ioh.202.1628372588878; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:08 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 18/49] bsd-user: add host-os.h Date: Sat, 7 Aug 2021 15:42:11 -0600 Message-Id: <20210807214242.82385-19-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Stacey Son , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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..a799164324 --- /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..b44cb7fdda --- /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..9083555f26 --- /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_ */ From patchwork Sat Aug 7 21:42:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514736 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=1gwyh1Yc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx0T3dtQz9sWX for ; Sun, 8 Aug 2021 07:52:41 +1000 (AEST) Received: from localhost ([::1]:48166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUFB-0001Ww-R0 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:52:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU65-00079p-3l for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:13 -0400 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]:34508) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU63-0004tM-LN for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:12 -0400 Received: by mail-io1-xd2f.google.com with SMTP id i7so13719022iow.1 for ; Sat, 07 Aug 2021 14:43: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=qDu3yCQrTbca9PIzdC+muV0f2JJWzFWzaLb4L/j0/WM=; b=1gwyh1YcOla24TL23ibqyCtnIAYuaekVNI2vgnm4/XSclKrjRzn7RCICt/kwJwO92u yQp3DHAzmt30FxT+lISsNwmQMJCLCrBZjmqrYjMWogdqG2wc3kYk8TTKQRT8eCZC7yu7 RtONXd5Ykdv0qijwPYvwwxAminAQQNcYe/R9VuXFk+tuFDgMVMpoqfLwtjBsbk/n/h+x +HB2+i0SMGs7RKos46tHMZcu0pay3gQsvRN0f+0kMRhWmiplhJkht22wZedxMUiVEb8o TDEA7PKvTWJmXwUBgzZoH1F04aCeNkmwPVyiLgNWHufS3WvRjiZ/n5AAT5HCeYx8w5ME Y7XQ== 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=qDu3yCQrTbca9PIzdC+muV0f2JJWzFWzaLb4L/j0/WM=; b=IzoLLdj4/dVReT3tCy2w0R6R3BUoKKho6jDuKUTnrq2f7DmuaTOEMl8hBF8YeIjpd8 x445Uxf0r3onOghtrnPpBmEFKj0aPOHbtRJ+Ym3HEMKVqoygdBIrnwo1TMKS8OTT05Hy oXpvCS5bTe9yVrcnFMOQojNCwjrF8wfiKq2BLvwqs395ClNwkYV/WAMqzjdxxZs0Co9l sEadWh7N1sKDqE1GuHLC17gufocG9UTPVuiJ5sOt4VBpcvFjotVg8vFZ9DbObPZ4zBPk cd6pzrvhLicOPP+U6j9IhtrFy/XaBMgRhliD9ylJOy/IG3yTAROp9XMtMH+wneAr4bO/ Mmcw== X-Gm-Message-State: AOAM533bMam9MD9hRnEea6Js1JU9/N6Ii5zXjb1F4a3Cu2rEslthGOlF 3jdZZ2VoMVN6OLVYZRlNax6FYRa3Ssj/yar/ X-Google-Smtp-Source: ABdhPJzh0f1EctCorGKIaDYzBpzgYpasdEgNfb25fRs2F6Pja9S8XWNZAYq/E8YRe0nY8q+HvAHwtg== X-Received: by 2002:a05:6e02:1bc1:: with SMTP id x1mr100440ilv.33.1628372590153; Sat, 07 Aug 2021 14:43:10 -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 a17sm8062827ios.36.2021.08.07.14.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:09 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 19/49] bsd-user: Include host-os.h from main Date: Sat, 7 Aug 2021 15:42:12 -0600 Message-Id: <20210807214242.82385-20-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Stacey Son , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 a799164324..ceb1543d06 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_ +#define HOST_DEFAULT_BSD_TYPE target_freebsd + #endif /*!__HOST_OS_H_ */ diff --git a/bsd-user/main.c b/bsd-user/main.c index 9166049c5a..d9965e6611 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -41,6 +41,8 @@ #include "exec/log.h" #include "trace/control.h" +#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 = NULL; char **target_environ, **wrk; envlist_t *envlist = NULL; - bsd_type = target_openbsd; + bsd_type = HOST_DEFAULT_BSD_TYPE; if (argc <= 1) { usage(); diff --git a/bsd-user/netbsd/host-os.h b/bsd-user/netbsd/host-os.h index b44cb7fdda..ccbea076e6 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_ +#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 9083555f26..79468073e4 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_ +#define HOST_DEFAULT_BSD_TYPE target_openbsd + #endif /*!__HOST_OS_H_ */ From patchwork Sat Aug 7 21:42:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=AJG+mD+i; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx0P3j03z9sWX for ; Sun, 8 Aug 2021 07:52:37 +1000 (AEST) Received: from localhost ([::1]:47888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUF9-0001I7-7d for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:52:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU66-0007Ei-8e for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:14 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]:38738) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU64-0004tt-Nu for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:14 -0400 Received: by mail-io1-xd29.google.com with SMTP id a13so19904670iol.5 for ; Sat, 07 Aug 2021 14:43: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=BTHyu9k2kFrGG65EoJAfC+s4flP2ULxollHRiXJphB0=; b=AJG+mD+i0cEmr1c1q8Vvte7OEJUzGlQLJNI09FTUnNQjmpK65qK1ln5mOywNd1cPLy Nism9cp2EWmKn76V6EB3DUkF0T0YtDbhrTHHH+muGy/NwQVazaRUJQi8S8KNcp99Fd2w q3VfHdn1nqxN9i3vZMASINlf2vYzqIgsJRN8b6Kz/BPbzVL/WUSEDB+RkLj8b+Nd9cS1 fv0dk4xkdzlmia25F3AVkyeTKGhd7k4DkVJO8nvVgDnFYnHae4iS3H+RgxOTJKYjKnAW uQV9cywemEqv2Sf+/17MR+7wksiC5ZrZC9XQ98K22Dlgs6UliK2ShZJO0+Y5waGMP3u3 cupQ== 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=BTHyu9k2kFrGG65EoJAfC+s4flP2ULxollHRiXJphB0=; b=SqkuBooqCGE7slJ/z1HZ/tjQl0alNLR/lGhSKCmx01JWM+wckxprnfaIpOJwlABtLJ USbnXhnDqn6uAVwecCPs0qWfIQlJxttoweBX95fRWwPHkR4gt6cMfCym+ygz1MMKuJQM SMeT04kmFZS93OjGYRKns2kDmcWevrcw3+EUOb3Gx6rwdLLXF5s1j6RUEC1pVh4p6W0Z 5Zlea+3oQKhzve3MIYPVvaqI5DG5a4GfQ7s7KUkX2kzp6kkBh4t354dMjn9H2n0htfN1 x7QUEtgXN8838oDzjTYIzJUGD+AK+skiiyfKZYS5y1x6/i9OUnGTzA4Zv0TKroKomzq/ IVCg== X-Gm-Message-State: AOAM531bNh90swr4CCar2fNI2T4FkoJ24Vqh6/WP8vjrly1Im5uABLWw yfx3//h3tc7GuEN/SEXm6rgyyN90kJVF1NRA X-Google-Smtp-Source: ABdhPJzQQuYVcTj/6YRysNGh/zneZ/VbKeTjk4hhEbGxFwckGRDVbvWflAywpKdcdW9Ov2z21eN8yw== X-Received: by 2002:a02:1cc5:: with SMTP id c188mr15543023jac.46.1628372591370; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:11 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 20/49] bsd-user: save the path the qemu emulator Date: Sat, 7 Aug 2021 15:42:13 -0600 Message-Id: <20210807214242.82385-21-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Stacey Son , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 d9965e6611..c59edad155 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -43,6 +43,8 @@ #include "host-os.h" +#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 = CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; enum BSDType bsd_type; +char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */ /* * XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so @@ -336,6 +339,22 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next = NULL; } +static void save_proc_pathname(char *argv0) +{ + int mib[4]; + size_t len; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + + len = PATH_MAX; + 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(); } + 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); /* main.c */ +extern char qemu_proc_pathname[]; extern unsigned long x86_stack_size; /* user access */ From patchwork Sat Aug 7 21:42:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=bSA0QymQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx2J54j0z9sWX for ; Sun, 8 Aug 2021 07:54:16 +1000 (AEST) Received: from localhost ([::1]:56654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUGk-0007bn-55 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:54:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU68-0007OE-I5 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:16 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:43949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU66-0004ux-7Q for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:16 -0400 Received: by mail-io1-xd44.google.com with SMTP id y1so19935617iod.10 for ; Sat, 07 Aug 2021 14:43: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=Eh62M1LCPH1ciwgXY/g56qTwt7JRl2T85rnBwwigqK0=; b=bSA0QymQ7WbLrpE7l4wMF7cL6l0jwXB/L0bm0Yj9cyjH916DLJNlCFvmxmuUy1aun+ AJ5c2qJmgSg6ESr1HPvbtP63TUtzJbZQg0qYqsPMaA9VrLGBIzCOkj0E3JLzZsH+Prb+ 5Q5xgvugesPCATT4uLW/0whSo9sfY9sSbCQPccl71GBu6LYCzm2xR4DSWP9G6PZLS7NP g2x8b0H3efIF9tdqhdW4QZShlFFgILxs5U+xcnTrIlhdvgTvFDgqhuzQPUKC1Ac9huXT j9QWaeMyWbEvPIU2BJ5J5Fz3fRckdja6XYRqByDGeNSSBGr9V/YUQ/Uyg4XoaI4O95h9 r3Jw== 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=Eh62M1LCPH1ciwgXY/g56qTwt7JRl2T85rnBwwigqK0=; b=FzOEAKMC+jQ5HIZxahlRWgYDNF2ke+Bv+2xRjVCtk5FCFVSdAT1HECYXnMnJmNBzF0 xrfp/WgRI348s4ZPiW0aBMHWakJzJG08Kj7gPzVpRlq89BU7F5CoJYhp2eYXjphQZ1Bg S3bXrFEYAare/9tPpC15yJjdpFoVtMaC5RUvM2DvOC+B31E347zqnxZ22DGcxZ/ppeVH Rej++wbt9No8ON+BFnJxFuMO5NkWN4pOZxF/Yv8kSBHoXvZCnOQhyqJWwArRnXSrM4c2 7DVgnZoWrGwHo9Jf8ld+ddvjBD/P7JRoiT1RPQ5v/06Q48I6hnFx0P+ethMd5l9vFIlk z8pQ== X-Gm-Message-State: AOAM533HBsEIyE1UoK8+thqUUESvnEnXDJQncsHRS80I/FJZKf8HhGnX szWrSE32a4rLdRVuYpmtUc2DSkasRgP1if4H X-Google-Smtp-Source: ABdhPJxT23Vl4IPSZsVoFOUDKOU/CZ9hYjnABGZ7CSUS7iTNzyJf/CIZ0CwKCr/SG1zeFTIzaOBzng== X-Received: by 2002:a05:6638:358b:: with SMTP id v11mr3545762jal.128.1628372592587; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:12 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 21/49] bsd-user: start to move target CPU functions to target_arch* Date: Sat, 7 Aug 2021 15:42:14 -0600 Message-Id: <20210807214242.82385-22-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Move the CPU functons 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 --- bsd-user/i386/target_arch.h | 31 +++++++++++++ bsd-user/i386/target_arch_cpu.c | 75 +++++++++++++++++++++++++++++++ bsd-user/main.c | 12 ----- bsd-user/x86_64/target_arch.h | 31 +++++++++++++ bsd-user/x86_64/target_arch_cpu.c | 75 +++++++++++++++++++++++++++++++ meson.build | 8 +++- 6 files changed, 218 insertions(+), 14 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_cpu.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 = (addr << 16) | (limit & 0xffff); + e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000); + e2 |= flags; + p = ptr; + p[0] = tswap32(e1); + p[1] = 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 = (addr & 0xffff) | (sel << 16); + e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); + p = ptr; + p[0] = tswap32(e1); + p[1] = 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 = g2h_untagged(base); +} + diff --git a/bsd-user/main.c b/bsd-user/main.c index c59edad155..ac435b216a 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -72,13 +72,6 @@ void gemu_log(const char *fmt, ...) va_end(ap); } -#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 */ -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) { 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 limit, + 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_arch_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 = (addr << 16) | (limit & 0xffff); + e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000); + e2 |= flags; + p = ptr; + p[0] = tswap32(e1); + p[1] = 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 = (addr & 0xffff) | (sel << 16); + e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); + p = ptr; + p[0] = tswap32(e1); + p[1] = tswap32(e2); + p[2] = tswap32(addr >> 32); + p[3] = 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 = g2h_untagged(base); +} diff --git a/meson.build b/meson.build index f2e148eaf9..5fe6b4aae6 100644 --- a/meson.build +++ b/meson.build @@ -2560,9 +2560,13 @@ foreach target : target_dirs if 'CONFIG_LINUX_USER' in config_target base_dir = 'linux-user' target_inc += include_directories('linux-user/host/' / config_host['ARCH']) - else + endif + if 'CONFIG_BSD_USER' in config_target base_dir = 'bsd-user' - target_inc += include_directories('bsd-user/freebsd') + target_inc += include_directories('bsd-user/' / targetos) +# target_inc += include_directories('bsd-user/host/' / config_host['ARCH']) + dir = base_dir / abi + arch_srcs += files(dir / 'target_arch_cpu.c') endif target_inc += include_directories( base_dir, From patchwork Sat Aug 7 21:42:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=JW5GL89W; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx6X2TQVz9sWX for ; Sun, 8 Aug 2021 07:57:56 +1000 (AEST) Received: from localhost ([::1]:45248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUKI-0002ci-1i for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:57:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6B-0007YC-8L for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:19 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:43951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU67-0004vk-Lm for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:18 -0400 Received: by mail-io1-xd44.google.com with SMTP id y1so19935727iod.10 for ; Sat, 07 Aug 2021 14:43: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=4iLTEXYEJykh2bTTlKZWJe6xVVV8G6cWYxMWjURtoLo=; b=JW5GL89WfBOcRzc6TFUykctsUeZj1e0EIANM0jrNbTWpV1Mt2pHli5f7yvWzkDwYXe /N/0W4aoAS4Fw1PBrsblSQPxqisFGc0xiDetbHP82NrxsJb/Np5E72UuVE++IKh9i+hP 5H3PIW+nbycFeQ2sqt6h0sWZuU7dllkjQYUJofnXnPOlOyi/5lOeJUFoVQsiyBLqFt0d a+Nr9cd917xOgNQmBw+OBnhbYiFBEz549sSRWQihUw4dwH67sFEHPW7eDi0e1P+H70TV Ip9DB0MTsQhD7O0wtHgZOidrjoox3KOF7HruT6rYRf6OFHX3WJguP66eteiJAQMSJwg7 WLbQ== 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=4iLTEXYEJykh2bTTlKZWJe6xVVV8G6cWYxMWjURtoLo=; b=SMhlruiLgCpPmWVClboN6o9HZqqDn8DtPv8P1YUslmWxpznbeTzfKixtyrcUSlOAd6 C8aTtiR1wkz2+apipGRF7jOhtaukamVVsq0IoWcdF06na3dK4L3d4LLyHBmTQgCnRMCm 9YxlW6MTPEGyU4blk5J+Sw9+tlapE3R5rlOWsn6qi+qco2fMNRTCTa7YfKfvfUoUZujd j7+di2Mg32+cRBBjs8UyYuiNzZpTKWbpil1i9Xc868GlmkMS3oJSftSYaMplkcK75TDt lHjvixePLIlLoqOegeHWHUXs9051pQhQtUQFj25KOj36Hp7VgdX0Wks1nzvEBgsqySWA ikdg== X-Gm-Message-State: AOAM533AIivEgEZ0WBKv/sXBlLE6F3WTv13cZmeZMOKyPotNuFqjGT6v 4ooZk/7SSdTj9437nZVYLZ0gs1YiPIxHGCjh X-Google-Smtp-Source: ABdhPJxo2trWTUQvYHqRfTPboAvaUrxNczTN1SoxqtsVj2cFTAB3A8iuX1O033VvB9r939NS+hCSXQ== X-Received: by 2002:a05:6e02:525:: with SMTP id h5mr444165ils.114.1628372594292; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:13 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 22/49] bsd-user: Move per-cpu code into target_arch_cpu.h Date: Sat, 7 Aug 2021 15:42:15 -0600 Message-Id: <20210807214242.82385-23-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- bsd-user/i386/target_arch_cpu.c | 1 + bsd-user/i386/target_arch_cpu.h | 306 ++++++++++++++++++++++++++++ bsd-user/main.c | 309 ++-------------------------- bsd-user/x86_64/target_arch_cpu.c | 1 + bsd-user/x86_64/target_arch_cpu.h | 328 ++++++++++++++++++++++++++++++ 5 files changed, 651 insertions(+), 294 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_cpu.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_cpu.h new file mode 100644 index 0000000000..c7603d4ec6 --- /dev/null +++ b/bsd-user/i386/target_arch_cpu.h @@ -0,0 +1,306 @@ +/* + * 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] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; + env->hflags |= HF_PE_MASK | HF_CPL_MASK; + if (env->features[FEAT_1_EDX] & CPUID_SSE) { + env->cr[4] |= CR4_OSFXSR_MASK; + env->hflags |= HF_OSFXSR_MASK; + } + + /* flags setup : we activate the IRQs by default as in user mode */ + env->eflags |= IF_MASK; + + /* register setup */ + env->regs[R_EAX] = regs->eax; + env->regs[R_EBX] = regs->ebx; + env->regs[R_ECX] = regs->ecx; + env->regs[R_EDX] = regs->edx; + env->regs[R_ESI] = regs->esi; + env->regs[R_EDI] = regs->edi; + env->regs[R_EBP] = regs->ebp; + env->regs[R_ESP] = regs->esp; + env->eip = regs->eip; + + /* interrupt setup */ + env->idt.limit = 255; + + env->idt.base = 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 = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, + PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; + gdt_table = 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 = 0; +} + +static inline void target_cpu_loop(CPUX86State *env) +{ + CPUState *cs = env_cpu(env); + int trapnr; + abi_ulong pc; + /* target_siginfo_t info; */ + + for (;;) { + cpu_exec_start(cs); + trapnr = cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case 0x80: + /* syscall from int $0x80 */ + if (bsd_type == target_freebsd) { + abi_ulong params = (abi_ulong) env->regs[R_ESP] + + sizeof(int32_t); + int32_t syscall_nr = env->regs[R_EAX]; + int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; + + if (syscall_nr == TARGET_FREEBSD_NR_syscall) { + get_user_s32(syscall_nr, params); + params += sizeof(int32_t); + } else if (syscall_nr == TARGET_FREEBSD_NR___syscall) { + get_user_s32(syscall_nr, params); + params += sizeof(int64_t); + } + get_user_s32(arg1, params); + params += sizeof(int32_t); + get_user_s32(arg2, params); + params += sizeof(int32_t); + get_user_s32(arg3, params); + params += sizeof(int32_t); + get_user_s32(arg4, params); + params += sizeof(int32_t); + get_user_s32(arg5, params); + params += sizeof(int32_t); + get_user_s32(arg6, params); + params += sizeof(int32_t); + get_user_s32(arg7, params); + params += sizeof(int32_t); + get_user_s32(arg8, params); + env->regs[R_EAX] = do_freebsd_syscall(env, + syscall_nr, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + } else { /* if (bsd_type == target_openbsd) */ + env->regs[R_EAX] = 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]) >= (abi_ulong)(-515)) { + env->regs[R_EAX] = -env->regs[R_EAX]; + env->eflags |= CC_C; + } else { + env->eflags &= ~CC_C; + } + break; + +#if 0 + case EXCP0B_NOSEG: + case EXCP0C_STACK: + info.si_signo = TARGET_SIGBUS; + info.si_errno = 0; + info.si_code = TARGET_SI_KERNEL; + info._sifields._sigfault._addr = 0; + queue_signal(env, info.si_signo, &info); + break; + + case EXCP0D_GPF: + /* XXX: potential problem if ABI32 */ + if (env->eflags & VM_MASK) { + handle_vm86_fault(env); + } else { + info.si_signo = TARGET_SIGSEGV; + info.si_errno = 0; + info.si_code = TARGET_SI_KERNEL; + info._sifields._sigfault._addr = 0; + queue_signal(env, info.si_signo, &info); + } + break; + + case EXCP0E_PAGE: + info.si_signo = TARGET_SIGSEGV; + info.si_errno = 0; + if (!(env->error_code & 1)) { + info.si_code = TARGET_SEGV_MAPERR; + } else { + info.si_code = TARGET_SEGV_ACCERR; + } + info._sifields._sigfault._addr = env->cr[2]; + queue_signal(env, info.si_signo, &info); + break; + + case EXCP00_DIVZ: + if (env->eflags & VM_MASK) { + handle_vm86_trap(env, trapnr); + } else { + /* division by zero */ + info.si_signo = TARGET_SIGFPE; + info.si_errno = 0; + info.si_code = TARGET_FPE_INTDIV; + info._sifields._sigfault._addr = env->eip; + queue_signal(env, info.si_signo, &info); + } + break; + + case EXCP01_DB: + case EXCP03_INT3: + if (env->eflags & VM_MASK) { + handle_vm86_trap(env, trapnr); + } else { + info.si_signo = TARGET_SIGTRAP; + info.si_errno = 0; + if (trapnr == EXCP01_DB) { + info.si_code = TARGET_TRAP_BRKPT; + info._sifields._sigfault._addr = env->eip; + } else { + info.si_code = TARGET_SI_KERNEL; + info._sifields._sigfault._addr = 0; + } + queue_signal(env, info.si_signo, &info); + } + break; + + case EXCP04_INTO: + case EXCP05_BOUND: + if (env->eflags & VM_MASK) { + handle_vm86_trap(env, trapnr); + } else { + info.si_signo = TARGET_SIGSEGV; + info.si_errno = 0; + info.si_code = TARGET_SI_KERNEL; + info._sifields._sigfault._addr = 0; + queue_signal(env, info.si_signo, &info); + } + break; + + case EXCP06_ILLOP: + info.si_signo = TARGET_SIGILL; + info.si_errno = 0; + info.si_code = TARGET_ILL_ILLOPN; + info._sifields._sigfault._addr = env->eip; + queue_signal(env, info.si_signo, &info); + break; +#endif + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; +#if 0 + case EXCP_DEBUG: + { + + info.si_signo = TARGET_SIGTRAP; + info.si_errno = 0; + info.si_code = TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, &info); + } + break; +#endif + + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + + default: + pc = 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 newsp) +{ + if (newsp) + env->regs[R_ESP] = newsp; + env->regs[R_EAX] = 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 ac435b216a..91e6abb6e4 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -42,6 +42,7 @@ #include "trace/control.h" #include "host-os.h" +#include "target_arch_cpu.h" #include @@ -83,177 +84,10 @@ void fork_end(int child) } } -#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 = (addr << 16) | (limit & 0xffff); - e2 = ((addr >> 16) & 0xff) | (addr & 0xff000000) | (limit & 0x000f0000); - e2 |= flags; - p = ptr; - p[0] = tswap32(e1); - p[1] = 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 = (addr & 0xffff) | (sel << 16); - e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); - p = ptr; - p[0] = tswap32(e1); - p[1] = tswap32(e2); - p[2] = tswap32(addr >> 32); - p[3] = 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) -{ - uint32_t *p, e1, e2; - e1 = (addr & 0xffff) | (sel << 16); - e2 = (addr & 0xffff0000) | 0x8000 | (dpl << 13) | (type << 8); - p = ptr; - p[0] = tswap32(e1); - p[1] = tswap32(e2); -} - -/* only dpl matters as we do only user space emulation */ -static void set_idt(int n, unsigned int dpl) +void cpu_loop(CPUArchState *env) { - set_gate(idt_table + n, 0, dpl, 0, 0); -} -#endif - -void cpu_loop(CPUX86State *env) -{ - CPUState *cs = env_cpu(env); - int trapnr; - abi_ulong pc; - /* target_siginfo_t info; */ - - for (;;) { - cpu_exec_start(cs); - trapnr = cpu_exec(cs); - cpu_exec_end(cs); - process_queued_cpu_work(cs); - - switch (trapnr) { - case 0x80: - /* syscall from int $0x80 */ - if (bsd_type == target_freebsd) { - abi_ulong params = (abi_ulong) env->regs[R_ESP] + - sizeof(int32_t); - int32_t syscall_nr = env->regs[R_EAX]; - int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; - - if (syscall_nr == TARGET_FREEBSD_NR_syscall) { - get_user_s32(syscall_nr, params); - params += sizeof(int32_t); - } else if (syscall_nr == TARGET_FREEBSD_NR___syscall) { - get_user_s32(syscall_nr, params); - params += sizeof(int64_t); - } - get_user_s32(arg1, params); - params += sizeof(int32_t); - get_user_s32(arg2, params); - params += sizeof(int32_t); - get_user_s32(arg3, params); - params += sizeof(int32_t); - get_user_s32(arg4, params); - params += sizeof(int32_t); - get_user_s32(arg5, params); - params += sizeof(int32_t); - get_user_s32(arg6, params); - params += sizeof(int32_t); - get_user_s32(arg7, params); - params += sizeof(int32_t); - get_user_s32(arg8, params); - env->regs[R_EAX] = do_freebsd_syscall(env, - syscall_nr, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8); - } else { /* if (bsd_type == target_openbsd) */ - env->regs[R_EAX] = 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]) >= (abi_ulong)(-515)) { - env->regs[R_EAX] = -env->regs[R_EAX]; - env->eflags |= CC_C; - } else { - env->eflags &= ~CC_C; - } - break; -#ifndef TARGET_ABI32 - case EXCP_SYSCALL: - /* syscall from syscall instruction */ - if (bsd_type == target_freebsd) { - env->regs[R_EAX] = 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 == target_openbsd) */ - env->regs[R_EAX] = 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 = env->exception_next_eip; - if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) { - env->regs[R_EAX] = -env->regs[R_EAX]; - env->eflags |= CC_C; - } else { - env->eflags &= ~CC_C; - } - break; -#endif - case EXCP_INTERRUPT: - /* just indicate that signals should be handled asap */ - break; - default: - pc = 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); - } + target_cpu_loop(env); } -#endif static void usage(void) { @@ -521,18 +355,11 @@ int main(int argc, char **argv) init_paths(interp_prefix); if (cpu_model == NULL) { -#if defined(TARGET_I386) -#ifdef TARGET_X86_64 - cpu_model = "qemu64"; -#else - cpu_model = "qemu32"; -#endif -#else - cpu_model = "any"; -#endif + cpu_model = TARGET_DEFAULT_CPU_MODEL; } cpu_type = parse_cpu_option(cpu_model); + /* init tcg before creating CPUs and to get qemu_host_page_size */ { AccelClass *ac = ACCEL_GET_CLASS(current_accel()); @@ -626,124 +453,18 @@ int main(int argc, char **argv) ts->info = info; cpu->opaque = ts; -#if defined(TARGET_I386) - env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; - env->hflags |= HF_PE_MASK | HF_CPL_MASK; - if (env->features[FEAT_1_EDX] & CPUID_SSE) { - env->cr[4] |= CR4_OSFXSR_MASK; - env->hflags |= 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] |= CR4_PAE_MASK; - env->efer |= MSR_EFER_LMA | MSR_EFER_LME; - env->hflags |= HF_LMA_MASK; -#endif - - /* flags setup : we activate the IRQs by default as in user mode */ - env->eflags |= IF_MASK; - - /* linux register setup */ -#ifndef TARGET_ABI32 - env->regs[R_EAX] = regs->rax; - env->regs[R_EBX] = regs->rbx; - env->regs[R_ECX] = regs->rcx; - env->regs[R_EDX] = regs->rdx; - env->regs[R_ESI] = regs->rsi; - env->regs[R_EDI] = regs->rdi; - env->regs[R_EBP] = regs->rbp; - env->regs[R_ESP] = regs->rsp; - env->eip = regs->rip; -#else - env->regs[R_EAX] = regs->eax; - env->regs[R_EBX] = regs->ebx; - env->regs[R_ECX] = regs->ecx; - env->regs[R_EDX] = regs->edx; - env->regs[R_ESI] = regs->esi; - env->regs[R_EDI] = regs->edi; - env->regs[R_EBP] = regs->ebp; - env->regs[R_ESP] = regs->esp; - env->eip = regs->eip; -#endif + target_set_brk(info->brk); + syscall_init(); + signal_init(); - /* linux interrupt setup */ -#ifndef TARGET_ABI32 - env->idt.limit = 511; -#else - env->idt.limit = 255; -#endif - env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - idt_table = 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 = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; - gdt_table = 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)); - } + /* + * Now that we've loaded the binary, GUEST_BASE is fixed. Delay + * generating the prologue until now so that the prologue can take + * the real value of GUEST_BASE into account. + */ + tcg_prologue_init(tcg_ctx); - 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 = 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); if (gdbstub) { gdbserver_start(gdbstub); diff --git a/bsd-user/x86_64/target_arch_cpu.c b/bsd-user/x86_64/target_arch_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_arch_cpu.h new file mode 100644 index 0000000000..ba0533ea0c --- /dev/null +++ b/bsd-user/x86_64/target_arch_cpu.h @@ -0,0 +1,328 @@ +/* + * 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] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; + env->hflags |= HF_PE_MASK | HF_CPL_MASK; + if (env->features[FEAT_1_EDX] & CPUID_SSE) { + env->cr[4] |= CR4_OSFXSR_MASK; + env->hflags |= 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] |= CR4_PAE_MASK; + env->efer |= MSR_EFER_LMA | MSR_EFER_LME; + env->hflags |= HF_LMA_MASK; + + /* flags setup : we activate the IRQs by default as in user mode */ + env->eflags |= IF_MASK; + + /* register setup */ + env->regs[R_EAX] = regs->rax; + env->regs[R_EBX] = regs->rbx; + env->regs[R_ECX] = regs->rcx; + env->regs[R_EDX] = regs->rdx; + env->regs[R_ESI] = regs->rsi; + env->regs[R_EDI] = regs->rdi; + env->regs[R_EBP] = regs->rbp; + env->regs[R_ESP] = regs->rsp; + env->eip = regs->rip; + + /* interrupt setup */ + env->idt.limit = 511; + + env->idt.base = 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 = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, + PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; + gdt_table = 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 = env_cpu(env); + int trapnr; + abi_ulong pc; + /* target_siginfo_t info; */ + + for (;;) { + cpu_exec_start(cs); + trapnr = cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case 0x80: + /* syscall from int $0x80 */ + if (bsd_type == target_freebsd) { + abi_ulong params = (abi_ulong) env->regs[R_ESP] + + sizeof(int32_t); + int32_t syscall_nr = env->regs[R_EAX]; + int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; + + if (syscall_nr == TARGET_FREEBSD_NR_syscall) { + get_user_s32(syscall_nr, params); + params += sizeof(int32_t); + } else if (syscall_nr == TARGET_FREEBSD_NR___syscall) { + get_user_s32(syscall_nr, params); + params += sizeof(int64_t); + } + get_user_s32(arg1, params); + params += sizeof(int32_t); + get_user_s32(arg2, params); + params += sizeof(int32_t); + get_user_s32(arg3, params); + params += sizeof(int32_t); + get_user_s32(arg4, params); + params += sizeof(int32_t); + get_user_s32(arg5, params); + params += sizeof(int32_t); + get_user_s32(arg6, params); + params += sizeof(int32_t); + get_user_s32(arg7, params); + params += sizeof(int32_t); + get_user_s32(arg8, params); + env->regs[R_EAX] = do_freebsd_syscall(env, + syscall_nr, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + } else { /* if (bsd_type == target_openbsd) */ + env->regs[R_EAX] = 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]) >= (abi_ulong)(-515)) { + env->regs[R_EAX] = -env->regs[R_EAX]; + env->eflags |= CC_C; + } else { + env->eflags &= ~CC_C; + } + break; + + case EXCP_SYSCALL: + /* syscall from syscall instruction */ + if (bsd_type == target_freebsd) { + env->regs[R_EAX] = 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 == target_openbsd) */ + env->regs[R_EAX] = 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 = env->exception_next_eip; + if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) { + env->regs[R_EAX] = -env->regs[R_EAX]; + env->eflags |= CC_C; + } else { + env->eflags &= ~CC_C; + } + break; + +#if 0 + case EXCP0B_NOSEG: + case EXCP0C_STACK: + info.si_signo = TARGET_SIGBUS; + info.si_errno = 0; + info.si_code = TARGET_SI_KERNEL; + info._sifields._sigfault._addr = 0; + queue_signal(env, info.si_signo, &info); + break; + + case EXCP0D_GPF: + /* XXX: potential problem if ABI32 */ + info.si_signo = TARGET_SIGSEGV; + info.si_errno = 0; + info.si_code = TARGET_SI_KERNEL; + info._sifields._sigfault._addr = 0; + queue_signal(env, info.si_signo, &info); + break; + + case EXCP0E_PAGE: + info.si_signo = TARGET_SIGSEGV; + info.si_errno = 0; + if (!(env->error_code & 1)) { + info.si_code = TARGET_SEGV_MAPERR; + } else { + info.si_code = TARGET_SEGV_ACCERR; + } + info._sifields._sigfault._addr = env->cr[2]; + queue_signal(env, info.si_signo, &info); + break; + + case EXCP00_DIVZ: + /* division by zero */ + info.si_signo = TARGET_SIGFPE; + info.si_errno = 0; + info.si_code = TARGET_FPE_INTDIV; + info._sifields._sigfault._addr = env->eip; + queue_signal(env, info.si_signo, &info); + break; + + case EXCP01_DB: + case EXCP03_INT3: + info.si_signo = TARGET_SIGTRAP; + info.si_errno = 0; + if (trapnr == EXCP01_DB) { + info.si_code = TARGET_TRAP_BRKPT; + info._sifields._sigfault._addr = env->eip; + } else { + info.si_code = TARGET_SI_KERNEL; + info._sifields._sigfault._addr = 0; + } + queue_signal(env, info.si_signo, &info); + break; + + case EXCP04_INTO: + case EXCP05_BOUND: + info.si_signo = TARGET_SIGSEGV; + info.si_errno = 0; + info.si_code = TARGET_SI_KERNEL; + info._sifields._sigfault._addr = 0; + queue_signal(env, info.si_signo, &info); + break; + + case EXCP06_ILLOP: + info.si_signo = TARGET_SIGILL; + info.si_errno = 0; + info.si_code = TARGET_ILL_ILLOPN; + info._sifields._sigfault._addr = env->eip; + queue_signal(env, info.si_signo, &info); + break; +#endif + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; +#if 0 + case EXCP_DEBUG: + { + + info.si_signo = TARGET_SIGTRAP; + info.si_errno = 0; + info.si_code = TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, &info); + } + break; +#endif + + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + + default: + pc = 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 newsp) +{ + if (newsp) + env->regs[R_ESP] = newsp; + env->regs[R_EAX] = 0; +} + +static inline void target_cpu_reset(CPUArchState *cpu) +{ + cpu_reset(env_cpu(cpu)); +} + +#endif /* ! _TARGET_ARCH_CPU_H_ */ From patchwork Sat Aug 7 21:42:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514744 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=l2Kf0PNF; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx4G6vvkz9sWl for ; Sun, 8 Aug 2021 07:55:58 +1000 (AEST) Received: from localhost ([::1]:36952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUIN-0005Bw-Rz for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:55:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6B-0007XK-1O for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:19 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:34321) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU68-0004yU-Ju for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:18 -0400 Received: by mail-io1-xd42.google.com with SMTP id i7so13719339iow.1 for ; Sat, 07 Aug 2021 14:43:16 -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=yFsI4djxg/V3HTkQhqunboDRE0OyTH5J7IXvZuWzJ0g=; b=l2Kf0PNFuksvjmNlkyok1Ryc2qChDs1WG7efNRpsX3lt7qbeJ7CBWC49LG6VNtV76E ZuDpP5N7VItAlu+nmZm/kAH9JnM3/9XuyWZdMW8rxbZY558HWiVpgk47FmmhmGnjDRu+ rWVaF/M3A+l3Pq7CZ4J16NkvchtLmovLdTRcKdGH9H2KxENB3/DOyUbLoAnPXN+YxQEc n8GhRvHPLtDo6oNMNHEO6lz0XNBffmxxYvUPUFRLK7QN4TSxCOzi8aL46BQQ+Ornf8Y+ EnhJY4ZqP65YUzr31T8Vttp1/I52xVGKO5qYcczHh1SdqUx36NmruZisCPqTV7kUKZY2 WWnw== 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=yFsI4djxg/V3HTkQhqunboDRE0OyTH5J7IXvZuWzJ0g=; b=uAiRb6s+qj5z/IiTzortsDzjMjyrXbySq51ylEa6JYxRISjAZwJjdeKttNYTLCeDIs bw/fu6uxHD1ASwP1GhHcJC3rqtvibrbGWJB/nEu81NJpOxt4fyQQetGhmdfMDmydfRqC keEQfWulbL+vICUlPbGGGejCGXJUq8rQPIix4P7JiMeXFTrJk7Nj7Ub5uI6FnB3Y5oj5 lK7+1fMy57qeghuDyv7D/6cBJsKjAc5t8QpsGol0ATHX2w+2yiA4e3YcgXBhSZqSgkR0 XvZukFQWNLDaDaGFAbq07lCn/0FGO95JNwmSEfltKv2B39DLskhaUp3RqdfF3Uho/9hq Q/5A== X-Gm-Message-State: AOAM531x7RhKObZxgwXOV/E8cr4VeOfH4SScUHqOA3lkYag7NzUpLdJH w6r4PU/0eG3DZbNp+4342RhpmaQZL0LqvNLR X-Google-Smtp-Source: ABdhPJwI/MJ+B2zUbisHYXYo1qComF4gD876D7SQHwma6Spb+n4lKwbh0WTtl5eTIlfbB4dm0UPz8g== X-Received: by 2002:a02:9386:: with SMTP id z6mr15898728jah.100.1628372595183; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:14 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 23/49] bsd-user: pull in target_arch_thread.h update target_arch_elf.h Date: Sat, 7 Aug 2021 15:42:16 -0600 Message-Id: <20210807214242.82385-24-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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). These changes are all interrelated and could be brokend own, 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: Richard Henderson --- 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, 169 insertions(+), 87 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 8a6a72bf05..70a0f81f3d 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -24,6 +24,7 @@ #include "qemu/path.h" #include "target_arch_elf.h" +#include "target_os_thread.h" /* 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 target_pt_regs *regs, 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_elf.h index f322fc174b..7a9744140f 100644 --- a/bsd-user/i386/target_arch_elf.h +++ b/bsd-user/i386/target_arch_elf.h @@ -19,62 +19,14 @@ #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[] = "i386"; - int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL); - if (family > 6) { - family = 6; - } - if (family >= 3) { - elf_platform[1] = '0' + family; - } - return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap(void) -{ - X86CPU *cpu = X86_CPU(thread_cpu); - - return cpu->env.features[FEAT_1_EDX]; -} - #define ELF_START_MMAP 0x80000000 +#define ELF_ET_DYN_LOAD_ADDR 0x01001000 +#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) ) -/* - * This is used to ensure we don't load something for the wrong architecture. - */ -#define elf_check_arch(x) (((x) == EM_386) || ((x) == 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 = infop->start_stack; - regs->eip = 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 = 0; -} - #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 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 entry, + 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 = infop->start_stack; + regs->eip = 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 = 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_arch_elf.h index e7c8aa2755..180ec77a5f 100644 --- a/bsd-user/x86_64/target_arch_elf.h +++ b/bsd-user/x86_64/target_arch_elf.h @@ -19,48 +19,14 @@ #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[] = "i386"; - int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL); - if (family > 6) { - family = 6; - } - if (family >= 3) { - elf_platform[1] = '0' + family; - } - return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap(void) -{ - X86CPU *cpu = X86_CPU(thread_cpu); - - return cpu->env.features[FEAT_1_EDX]; -} - #define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch(x) (((x) == ELF_ARCH)) +#define ELF_ET_DYN_LOAD_ADDR 0x01021000 +#define elf_check_arch(x) ( ((x) == 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 = 0; - regs->rsp = infop->start_stack; - regs->rip = infop->entry; - if (bsd_type == target_freebsd) { - regs->rdi = infop->start_stack; - } -} - #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 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 entry, + 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 = 0; + regs->rsp = infop->start_stack; + regs->rip = infop->entry; + if (bsd_type == target_freebsd) { + regs->rdi = infop->start_stack; + } +} + +#endif /* !_TARGET_ARCH_THREAD_H_ */ From patchwork Sat Aug 7 21:42:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=XBIrWku2; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx2G0wfKz9sWX for ; Sun, 8 Aug 2021 07:54:14 +1000 (AEST) Received: from localhost ([::1]:56470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUGh-0007Th-RK for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:54:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6C-0007bx-5t for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:20 -0400 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]:46879) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU69-0004yi-FU for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:19 -0400 Received: by mail-io1-xd2a.google.com with SMTP id x10so9097420iop.13 for ; Sat, 07 Aug 2021 14:43:17 -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=OpW9OtKEIHGLi60Nnl3ufVXKZFtdnv/u5brokEZV4oc=; b=XBIrWku2ljZ0/brF4xhFkV1peY2+34eDX0nMcOXZJ075cHkw8NthMETWzicrE8X1WE 5h/Fx3aRqk78bnpdhjxmt8DYJ2FZ0ZvcXVzatCcY+Vw26MQ56WAr7O10mTiUz88qBrwK +exR5UC8SaCkyeCPfQDzdk4XmlzQ0r34xGK0JZAx8j8oeS/e1IQ322GOhrgsvjhOkqor XI7w0rVdGF6sXe/rSclb+dpsdYC85+QW3b2MqvY3o9HHoaATYnv4SWNK5sUvw1Eh5fzC HQ9fTzaROVYju+AqA/LXrVHcIvdLDtECrEjf5TyFuFxuRs9vYkrQ59bH2d+iCyrlhfv6 /0vg== 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=OpW9OtKEIHGLi60Nnl3ufVXKZFtdnv/u5brokEZV4oc=; b=pyDsLfBvLBQ6wDH0xASwbh/yBEC8Qe873FywP0ija7EjUt7Fu7nZqEzyA7vRlMWyeB cYul4kZU50Ik+rwC2c+ROGvTTz7peQVoEo1EekMLdMDVDHx62p/jaKtDcVRWsLSQsLz1 jDq+5pmtvKmsGJsAgyahm+3wW4m4xZ6NdE52Vgw5QRlcnjGcrwYBjqyclsdqtNmaZvzF Wr0UopBrc97WJ2lWYvyb0XVAotXe25axKwIgDooEoM2JF4SHHy/yN6HyCj3DJ287yKqL 0Iy8BlQP9fBHx8oScBagcR1hYK279fjnuNQhsy6UsDXEiBRVY5BSEBsJ8cfpuh2dhaIQ vpIA== X-Gm-Message-State: AOAM533ucRmg6uFX3jcxfE/9NyESoeU4RdIBducgJT62a08dywPZ7tbr 369AFn9QC4gaIPn1zCo01vMc0cy0+syENHe2 X-Google-Smtp-Source: ABdhPJxFseufeD3Qv4TS3M7uryEm895X0ZgcAmYwiLy5dKncuIrL0HlVchLx/f/6gROp7IdYEtGPXw== X-Received: by 2002:a02:cc21:: with SMTP id o1mr15872180jap.114.1628372596196; Sat, 07 Aug 2021 14:43:16 -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 a17sm8062827ios.36.2021.08.07.14.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:15 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 24/49] bsd-user: Include more things in qemu.h Date: Sat, 7 Aug 2021 15:42:17 -0600 Message-Id: <20210807214242.82385-25-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Include more header files to match bsd-user fork. Signed-off-by: Warner Losh --- bsd-user/qemu.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 6c4ec61d76..02e6e8327a 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -18,11 +18,15 @@ #define QEMU_H +#include "qemu/osdep.h" #include "cpu.h" #include "exec/cpu_ldst.h" +#include "exec/exec-all.h" +//#include "trace/trace-bsd_user.h" #undef DEBUG_REMAP #ifdef DEBUG_REMAP +#include #endif /* DEBUG_REMAP */ #include "exec/user/abitypes.h" @@ -36,8 +40,13 @@ enum BSDType { }; extern enum BSDType bsd_type; +#include "exec/user/thunk.h" +#include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h" +//#include "target_os_vmparam.h" +//#include "target_os_signal.h" +//#include "hostdep.h" #include "exec/gdbstub.h" /* From patchwork Sat Aug 7 21:42:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=jP5dvwGi; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx161SRgz9sWX for ; Sun, 8 Aug 2021 07:53:14 +1000 (AEST) Received: from localhost ([::1]:51072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUFj-0003R9-TA for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:53:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6C-0007ce-DO for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:20 -0400 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]:36830) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6A-00050C-8E for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:20 -0400 Received: by mail-io1-xd32.google.com with SMTP id f11so19876520ioj.3 for ; Sat, 07 Aug 2021 14:43:17 -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=zZ2V1vsBzx1QDxkiUAUegs9PmelXvmX9ctk5L5IAdd8=; b=jP5dvwGi3qdfRNweydk9U1o2FUZy2yHfyB/xTmTkxPQGUM/AU+mQqJpHyH2/7onpQQ Ad6QiCSndpLxTFeb7+bNBCfzN5XKsfm5PgA4ihsn3z8je/QnsuqaEys24JuBjthJlc0l U2x6nEY77vCAoQAIWpRUVRtN7CY7m+9aalDqIN4TSaJRD1XVvO96xL6p3upibHiSyvkp xAiuvJtkKFE8HQvz4a3G2e6xoYvJGwORX4hqEMioVCLx9WdLINGh7108vqBg8opObb8Q LR5K9CY7WKrkpxnKHWNiW5lx5xjNJZtC9iW2AbwOy2a04/S648YgV+ZfpyKjUHey6zZx CIlw== 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=zZ2V1vsBzx1QDxkiUAUegs9PmelXvmX9ctk5L5IAdd8=; b=YXzz3uTorc5y9JzMghH4e4WNfeybBRr6RwldlQYnm9byYZxmKz3SSIjfNBW7VDOBlQ udgiSxajoZAYb7IEPOz9GpQi0q1+hwelK3yktqLgowDUe+j+6661kfwN8Ff7mqBE1oR8 +/LClXRUQJVcvaFHbW/OqFf4moY4YaPhgod0Ivft2fR4O0Nl2/CfShwZOVaIPhAmdCe8 UfYgdjmnvIisKJF94jLpJYbdninM4QXOQe6Ikfmyvi4f7uYpNGxJlGFc6+RlrvEXdrq4 kX4hEH6iOEs6ig9rSuZu74efww1BVKdRJbuspDok3Yk1DtmTzK16eMCzzp3khlLGqs4I UGQQ== X-Gm-Message-State: AOAM533yXXedf7D2XU6DHVlymWnZ1I1HEdq5W45DV5xPrOFKbN928+9z PuZVua689r2IycnkPaVvxn3zWhEc+El7v6CO X-Google-Smtp-Source: ABdhPJxQDs1K/uhxEsKw/8S3JC3L1YdfNJvVuZTFO6DDPcIPdQDCFygeYST31eex06jqizXoJra5Rg== X-Received: by 2002:a92:ae03:: with SMTP id s3mr63395ilh.248.1628372597041; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:16 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 25/49] bsd-user: define max args in terms of pages Date: Sat, 7 Aug 2021 15:42:18 -0600 Message-Id: <20210807214242.82385-26-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 02e6e8327a..9322187891 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -107,11 +107,17 @@ extern const char *qemu_uname_release; extern unsigned long mmap_min_addr; /* - * 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 * 1024) +#else +#define TARGET_ARG_MAX (256 * 1024) +#endif +#define MAX_ARG_PAGES (TARGET_ARG_MAX / TARGET_PAGE_SIZE) /* * This structure is used to hold the arguments that are From patchwork Sat Aug 7 21:42:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514741 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Oaw44+Eq; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx372WT4z9sWq for ; Sun, 8 Aug 2021 07:54:59 +1000 (AEST) Received: from localhost ([::1]:59510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUHR-0001AK-1E for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:54:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6D-0007ff-72 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:21 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:33428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6B-00050K-5x for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:20 -0400 Received: by mail-io1-xd42.google.com with SMTP id n19so20055851ioz.0 for ; Sat, 07 Aug 2021 14:43:18 -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=0HKY4/GdCAuZdXZ+sZtb65CygtqaDscQyIFstkbna0Y=; b=Oaw44+Eq2NkPObSwrzzYQk+zfCVY8jCPtMrDCQ/SXU/DHvLhlYA/I2jEdoIn7JxAmb VUbu+G2tzP73eSl1Ue4BpHawsrYmyiunk06eREB+E76YZWfXTlzP2Ud8VzXqRiBisI5t Ev6fraHsn5w6YQm7/g6TUgAPAkVRYtpjOY7nBgNERkenJUN3nrmcWIuJ/RY4drzl0F53 TMwNXBcD0XjroHhhneMYN89ddlMOvV9n/ymCCw+sXGZGyYxKgDB8/48qS3/0O75CXvGR ycwNooZwaY7fUF2fiSgwrTYPOBeKxP/nPi2SDwlKJSIW/EmcNKcYc5+9lXXxibnQ55kC gEtg== 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=0HKY4/GdCAuZdXZ+sZtb65CygtqaDscQyIFstkbna0Y=; b=qC04Bc4ssOJ1+tITdufuy8DdY/QOt9LJ+Ltt4kRYkpFeFwd14kNiJyxhG/3PG+qGed a8kOAH2iB9vDyqB+4kNdLjMWGwSR43LQI58fHtv2KTKBd9fPeRFzIq+6izHbZt/+basn Edh1uhqzAZg/+F+6GHIAH2U/WydKj40oqZvbGaRNWw1GJCX1Ys16xWTt4enewD8i8I0Q CvXsu85LGlGSS/32UxCO84/7B0wEQA9rr8NMwqenEGUEcz9izofbrKcVEk39E8IB3SDD 5o234rIfdwM17SYYjElN0OBHdEdkc7NZE4Tce1wOeT/EprhF2DcuqWJTxYc63HrpSuZx 1oOg== X-Gm-Message-State: AOAM533Fq0x4jI3dEAp14NRzbc9KgsY64zdgVuE7UD53DkEIyDE7AThT tkxb9xrZpx84zugDwsFVqEAMTJjm3KK9AbND X-Google-Smtp-Source: ABdhPJwQXuHQSKsnMMBR1vX0P0R07CayDLr/8ZavK7R+Efco8CKEp7uYnCDOmfmzCSawWoX+HqN1OA== X-Received: by 2002:a6b:6609:: with SMTP id a9mr412706ioc.8.1628372597974; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:17 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 26/49] bsd-user: Create target specific vmparam.h Date: Sat, 7 Aug 2021 15:42:19 -0600 Message-Id: <20210807214242.82385-27-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Richard Henderson --- bsd-user/freebsd/target_os_vmparam.h | 38 ++++++++++++++++++++++ bsd-user/i386/target_arch_vmparam.h | 46 +++++++++++++++++++++++++++ bsd-user/qemu.h | 2 +- bsd-user/x86_64/target_arch_vmparam.h | 46 +++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) 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..d7ad149137 --- /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_arch_vmparam.h new file mode 100644 index 0000000000..c42ec87d54 --- /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 (128UL*1024*1024) /* max text size */ +#define TARGET_DFLDSIZ (128UL*1024*1024) /* initial data size limit */ +#define TARGET_MAXDSIZ (512UL*1024*1024) /* max data size */ +#define TARGET_DFLSSIZ (8UL*1024*1024) /* initial stack size limit */ +#define TARGET_MAXSSIZ (64UL*1024*1024) /* max stack size */ +#define TARGET_SGROWSIZ (128UL*1024) /* 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] = retval2; +} + +#endif /* !_TARGET_ARCH_VMPARAM_H_ */ diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 9322187891..c5414c7b4c 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -44,7 +44,7 @@ extern enum BSDType bsd_type; #include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h" -//#include "target_os_vmparam.h" +#include "target_os_vmparam.h" //#include "target_os_signal.h" //#include "hostdep.h" #include "exec/gdbstub.h" 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..addb68fa94 --- /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 (128UL*1024*1024) /* max text size */ +#define TARGET_DFLDSIZ (32768UL*1024*1024) /* initial data size limit */ +#define TARGET_MAXDSIZ (32768UL*1024*1024) /* max data size */ +#define TARGET_DFLSSIZ (8UL*1024*1024) /* initial stack size limit */ +#define TARGET_MAXSSIZ (512UL*1024*1024) /* max stack size */ +#define TARGET_SGROWSIZ (128UL*1024) /* 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] = retval2; +} + +#endif /* !_TARGET_ARCH_VMPARAM_H_ */ From patchwork Sat Aug 7 21:42:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514745 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=lDiC7Y1I; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx503QqYz9sWl for ; Sun, 8 Aug 2021 07:56:36 +1000 (AEST) Received: from localhost ([::1]:39834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUJ0-0007Si-7J for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:56:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6E-0007mc-Sd for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:23 -0400 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]:37533) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6C-00052f-4g for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:22 -0400 Received: by mail-io1-xd43.google.com with SMTP id l20so17748824iom.4 for ; Sat, 07 Aug 2021 14:43:19 -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=titql1TQTfAX2LZLdfzyWbfniKgOICKkvHCEKJpDN8U=; b=lDiC7Y1IneLHtdiRrENofwWSjegcbm9KxjjjfMrAqAxhZ+Ih/zZIMDALNH2pjpYBav +ADuGwl0oY9mzdGTt+dHfKrK8IZFpX+GEX+t1bJlSGb6qkrB0Y0vwzpyT+xJ7M+hTnpV BRL1bokMUR9lAi7YSxvWoxH0W+OlPeFS4tpFGjXdGsjaW7sX2QtAg+R2I3OhcQeETMDL SbWJvORoJYWZ81KwYdmLVOBS13redajs2dRu4iXtQKeXzIZOjGv5MqLmIwpbO9FNZerp qUulluE7ntr8HRaJfPbOGoYI3H5WEPypB8dxXeHr+fjOwmvnBV3j+eQNuZbSqMtKMGt/ o6pQ== 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=titql1TQTfAX2LZLdfzyWbfniKgOICKkvHCEKJpDN8U=; b=O1ZLDDQ5V2ydXieoCtG0HCPloZQP9jlE4F3fb21oLmH0S97dPNg3mZlDal18gQITp1 4pCIE/hQSJzdpNbZ9CZiCGmnuB87BFOMHYLVwu3C3gNAGeBKpCvx7R+mmqDKoGhyJX0N fO9eMZjmJvUl2YINI1j9TJRznHCu6lG4jtDpsngO9c48FuupMaMIg4n+g6kA2lhzqw4Y qiQCW6zSQpuIlqaMJqzYBAzmgCyYpMm+7JPyOgnakIJJufa7cxrXeflGYavEbZMJ5M4n 0aL68zICcd2LCBvYaiQT9hk5NvTvVFN/ECtzmPrnwKgd32HjJOUOFvOMX6nC96+/DUvQ DbCg== X-Gm-Message-State: AOAM531Dkt8IIVo0AVETYfc2yxuAUB0r4SXMt4YP1kvFxEZ/uoeH8dZp vloP4SjF2nTqJ1jjifNmQuOWaQ7soPHVET61 X-Google-Smtp-Source: ABdhPJy3dh6pbQjSVNfQSD4Ma95VHwr0LUxzFEePpIVEI+XUY0NicFpa1YqbaWV0O1zOaXKVNPZTtg== X-Received: by 2002:a5e:961a:: with SMTP id a26mr201965ioq.90.1628372598857; Sat, 07 Aug 2021 14:43:18 -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 a17sm8062827ios.36.2021.08.07.14.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:18 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 27/49] bsd-user: Add architecture specific signal tramp code Date: Sat, 7 Aug 2021 15:42:20 -0600 Message-Id: <20210807214242.82385-28-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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_arch_sigtramp.h new file mode 100644 index 0000000000..889bff7a54 --- /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 -TARGET_EOPNOTSUPP; +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */ diff --git a/bsd-user/x86_64/target_arch_sigtramp.h b/bsd-user/x86_64/target_arch_sigtramp.h new file mode 100644 index 0000000000..5629263a19 --- /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 -TARGET_EOPNOTSUPP; +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */ From patchwork Sat Aug 7 21:42:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=FRSBwwHu; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx4B5Sfnz9sWX for ; Sun, 8 Aug 2021 07:55:54 +1000 (AEST) Received: from localhost ([::1]:36676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUIK-0004y7-DA for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:55:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6F-0007nu-Cj for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:23 -0400 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]:41711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6D-00053E-0e for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:23 -0400 Received: by mail-io1-xd43.google.com with SMTP id 188so18233501ioa.8 for ; Sat, 07 Aug 2021 14:43:20 -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=+5IjzFVGTxISeGPyTbmAg1tcWXby/Ptf9qXjlia9zaw=; b=FRSBwwHulM+JiEUAeom188nuerfvIiqauP0QzuNEZ9kTa1xK4E+DupnpHWjMtU5Z7G MnpLiURGeC6iRzRWFRIaG7fTLM3dZu3L53oAKRgYWfjeRSarXAQ0JyesCElRP3056qBL UPcPdLqIjnqfDN+NNPuTODMrbIyQKB2DfdHLpChp0IrG2H9OBItQ3BAyVV9v8Ofq6YcS MGerCWXEbwp6TQw8vhuvV/yJu5MYKWsY50GUablpHEX4kaXwhcXoUffrohdLzzb6+bzD 4eisHawuAYrwuusLas3Tjn7N+r6xu6WymNVLQl4y/yqNRnRuozALHCmh/swVhN86FSXk o23g== 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=+5IjzFVGTxISeGPyTbmAg1tcWXby/Ptf9qXjlia9zaw=; b=jSSofKy+zDLYlMSrG6TreJhgFtBTxeHV4dyI/ngvjdUittTx7kF2Vnqmg/5ZQv24L9 /PZzea3KcKl8iY2GZfshhIUwgnR2ZCPprMy4YfL8RhQm81DIf40feRh7BQ/bx+2gBfUT 2x6NONFNq1KINZJ20lWWT/BV7CQ98Hf5gTOSlci7f5Uw6LmoRcTPCLWtU9PX50jrA+rW X7mTxsbkfH3tKPeaWMcnK7WBvyv0MWAkJWPihdJTg6xwH6zgSHh/OxK/RWa1s9IzilsF kYS5CJYWPQaoq9ZLsqrfbzks29uN+g4o/zSZe8+HDwjB0/IDIrZEICLTNNUdbUKNVM6L 0OHw== X-Gm-Message-State: AOAM533jm8tyy1QqmN8C80jKBTy42mlAiVr41Hkmnq8IYCQNE6YX3B4X 5JOK6pwnHyIHe3DQl1zpG8RmZ65UwFZNuX/f X-Google-Smtp-Source: ABdhPJztfujb8j7YSsUBL2xDCt7remhCgJJblenACWQrrKGaE+4TE026JYMrRXJMoMXb0jyUz8qqlg== X-Received: by 2002:a6b:7801:: with SMTP id j1mr153273iom.32.1628372599766; Sat, 07 Aug 2021 14:43:19 -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 a17sm8062827ios.36.2021.08.07.14.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:19 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 28/49] bsd-user: Move stack initializtion into a per-os file. Date: Sat, 7 Aug 2021 15:42:21 -0600 Message-Id: <20210807214242.82385-29-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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_os_stack.h new file mode 100644 index 0000000000..410b2828ca --- /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" + +/* + * 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 = p = target_stkbas + target_stksiz; + + /* Save some space for ps_strings. */ + p -= sizeof(struct target_ps_strings); + +#ifdef TARGET_SZSIGCODE + /* Add machine depedent sigcode. */ + p -= TARGET_SZSIGCODE; + if (setup_sigtramp(p, (unsigned)offsetof(struct target_sigframe, sf_uc), + TARGET_FREEBSD_NR_sigreturn)) { + errno = EFAULT; + return -1; + } +#endif + if (bprm->fullpath) { + execpath_len = strlen(bprm->fullpath) + 1; + p -= roundup(execpath_len, sizeof(abi_ulong)); + if (memcpy_to_target(p, bprm->fullpath, execpath_len)) { + errno = EFAULT; + return -1; + } + } + /* Add canary for SSP. */ + arc4random_buf(canary, sizeof(canary)); + p -= roundup(sizeof(canary), sizeof(abi_ulong)); + if (memcpy_to_target(p, canary, sizeof(canary))) { + errno = EFAULT; + return -1; + } + /* Add page sizes array. */ + p -= sizeof(abi_ulong); + if (put_user_ual(TARGET_PAGE_SIZE, p)) { + errno = 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 = rounddown(p, TARGET_PAGE_SIZE); + + /* Calculate the string space needed */ + stringspace = 0; + for (i = 0; i < bprm->argc; ++i) { + stringspace += strlen(bprm->argv[i]) + 1; + } + for (i = 0; i < bprm->envc; ++i) { + stringspace += strlen(bprm->envp[i]) + 1; + } + if (stringspace > TARGET_ARG_MAX) { + errno = ENOMEM; + return -1; + } + /* Make room for the argv and envp strings */ + destp = rounddown(p - stringspace, sizeof(abi_ulong)); + p = argvp = destp - (bprm->argc + bprm->envc + 2) * sizeof(abi_ulong); + /* Remember the strings pointer */ + if (stringp) + *stringp = 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 = tswapl(argvp); + ps_strs.ps_nargvstr = tswap32(bprm->argc); + for (i = 0; i < bprm->argc; ++i) { + size_t len = strlen(bprm->argv[i]) + 1; + + if (memcpy_to_target(destp, bprm->argv[i], len)) { + errno = EFAULT; + return -1; + } + if (put_user_ual(destp, argvp)) { + errno = EFAULT; + return -1; + } + argvp += sizeof(abi_ulong); + destp += len; + } + if (put_user_ual(0, argvp)) { + errno = EFAULT; + return -1; + } + /* + * Add env strings. Note that the envp[] vectors are added by + * loader_build_argptr(). + */ + envp = argvp + sizeof(abi_ulong); + ps_strs.ps_envstr = tswapl(envp); + ps_strs.ps_nenvstr = tswap32(bprm->envc); + for (i = 0; i < bprm->envc; ++i) { + size_t len = strlen(bprm->envp[i]) + 1; + + if (memcpy_to_target(destp, bprm->envp[i], len)) { + errno = EFAULT; + return -1; + } + if (put_user_ual(destp, envp)) { + errno = EFAULT; + return -1; + } + envp += sizeof(abi_ulong); + destp += len; + } + if (put_user_ual(0, envp)) { + errno = EFAULT; + return -1; + } + if (memcpy_to_target(stack_hi_addr - sizeof(ps_strs), &ps_strs, + sizeof(ps_strs))) { + errno = EFAULT; + return -1; + } + + if (ret_addr) { + *ret_addr = 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..9fdf7d420f --- /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 = (target_stkbas + target_stksiz) - + MAX_ARG_PAGES * TARGET_PAGE_SIZE; + if (p) { + *p = stack_base; + } + if (stringp) { + *stringp = stack_base; + } + + for (i = 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 = EFAULT; + return -1; + } + g_free(bprm->page[i]); + } + stack_base += 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_os_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 = (target_stkbas + target_stksiz) - + MAX_ARG_PAGES * TARGET_PAGE_SIZE; + if (p) { + *p = stack_base; + } + if (stringp) { + *stringp = stack_base; + } + + for (i = 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 = EFAULT; + return -1; + } + g_free(bprm->page[i]); + } + stack_base += TARGET_PAGE_SIZE; + } + + return 0; +} + +#endif /* !_TARGET_OS_STACK_H_ */ From patchwork Sat Aug 7 21:42:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=iky0JXKl; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx8z3Rsjz9sWl for ; Sun, 8 Aug 2021 08:00:03 +1000 (AEST) Received: from localhost ([::1]:53154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUMK-0007sC-LZ for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:00:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6G-0007sh-IH for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:24 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:38705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6D-00054M-TT for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:24 -0400 Received: by mail-io1-xd44.google.com with SMTP id a13so19905220iol.5 for ; Sat, 07 Aug 2021 14:43:21 -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=UrVmQqhWrbZHbGhwPoQlA+bKpudjp4hJimuUq/4iOng=; b=iky0JXKlArxpYqR4TSmIY5hWE8SerrADFkScHs+G43EV+h69F8V8nNhRJYoQNlQyC5 O7OMVmFK4PH5P+fpVHsBM4cEpGS+o2QMu7jQSvg8H1G0qC+ApMNLPvloHZAR/bpq45rv mrrmUk895Fii/PLq5Amd4Ovfkfm2+X+AT0vKZQxjwUsb0fwEW0KRvYXZ4UTzFaVTwKL1 dDQwzfSl+VFNzAX85ilyQJe4lPNGtWTejvm7Da7WXjv066JdXaoEDJrXtty12KlsjAQ3 cerNpbLkNBpY46DoLjSckHUdAqGKfvRZNmRb5WxF++qBErwqW3JEmtLlKwXmFuoWLjjr ZH9A== 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=UrVmQqhWrbZHbGhwPoQlA+bKpudjp4hJimuUq/4iOng=; b=kT3GfBPsAsGkGqIvuInO+Uy+TmU7RSwC/tYojSyfVjRq1IhrmIUNZvH+LEEAukmFjq U+DrKjQIuXc8uMg4LdepDt/MYewjH5sEt66+rs971Zm38fdozILQ9CULpkETJtSQTCqx 1uqiIj3DPYL9DpR37lWGV9POyjrndzdfPOD2oaMyuE+Jfck94Nfyx/2uxm31Tf/MK49J crIiduwpJmFUN82tukPpuM0tZ1K/KHdA3dQ3eHiASdjjeJAkIfvAgIgSdoHh3ux7nhgp Jw8vKIHIlHyini8ogsAnksFqU5VFzkqKxKbaL0nVjCoeVzdJ3ytXMy+aN90MTCz7OMPF ceEw== X-Gm-Message-State: AOAM530qEJz2E4NaxIxDT3S/XO2SwCla9c7SnwSgfisR4yoqDdaaPvwC lzsBoq14LDbuBcittUj2JI36XLPMkZM0Fdmm X-Google-Smtp-Source: ABdhPJxuG77OflwD+jqKALcPRrv2rB4sNOniJ94tgY0X7zpRSOAGjS9bHcdswpFHWHi74g1mywHIkQ== X-Received: by 2002:a5d:8154:: with SMTP id f20mr217386ioo.89.1628372600692; Sat, 07 Aug 2021 14:43:20 -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 a17sm8062827ios.36.2021.08.07.14.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:20 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 29/49] bsd-user: Add system independent stack, data and text limiting Date: Sat, 7 Aug 2021 15:42:22 -0600 Message-Id: <20210807214242.82385-30-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Sponsored by: Netflix Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 2 +- bsd-user/main.c | 51 +++++++++++++++++++++++++++++++++------------- bsd-user/qemu.h | 7 ++++++- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 70a0f81f3d..5ceb60b1c2 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 bsd_binprm *bprm, /* Create enough stack to hold everything. If we don't use * it for args, we'll use it for something else... */ - size = x86_stack_size; + size = target_dflssiz; if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE) size = MAX_ARG_PAGES * TARGET_PAGE_SIZE; error = target_mmap(0, diff --git a/bsd-user/main.c b/bsd-user/main.c index 91e6abb6e4..5ca1173f04 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -18,6 +18,11 @@ * along with this program; if not, see . */ +#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" -#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 */ -/* - * XXX: on x86 MAP_GROWSDOWN only works if ESP <= 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 = 512 * 1024; +unsigned long target_maxtsiz = TARGET_MAXTSIZ; /* max text size */ +unsigned long target_dfldsiz = TARGET_DFLDSIZ; /* initial data size limit */ +unsigned long target_maxdsiz = TARGET_MAXDSIZ; /* max data size */ +unsigned long target_dflssiz = TARGET_DFLSSIZ; /* initial data size limit */ +unsigned long target_maxssiz = TARGET_MAXSSIZ; /* max stack size */ +unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount to grow stack */ 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=]][,events=][,file=]\n" @@ -132,7 +134,7 @@ static void usage(void) , TARGET_NAME, interp_prefix, - x86_stack_size); + target_dflssiz); exit(1); } @@ -161,6 +163,22 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next = NULL; } +static void +adjust_ssize(void) +{ + struct rlimit rl; + + if (getrlimit(RLIMIT_STACK, &rl) != 0) + return; + + target_maxssiz = MIN(target_maxssiz, rl.rlim_max); + target_dflssiz = MIN(MAX(target_dflssiz, rl.rlim_cur), target_maxssiz); + + rl.rlim_max = target_maxssiz; + rl.rlim_cur = target_dflssiz; + setrlimit(RLIMIT_STACK, &rl); +} + static void save_proc_pathname(char *argv0) { int mib[4]; @@ -197,6 +215,8 @@ int main(int argc, char **argv) envlist_t *envlist = NULL; bsd_type = HOST_DEFAULT_BSD_TYPE; + adjust_ssize(); + if (argc <= 1) { usage(); } @@ -257,14 +277,17 @@ int main(int argc, char **argv) } } else if (!strcmp(r, "s")) { r = argv[optind++]; - rv = qemu_strtoul(r, &r, 0, &x86_stack_size); - if (rv < 0 || x86_stack_size <= 0) { + rv = qemu_strtoul(r, &r, 0, &target_dflssiz); + if (rv < 0 || target_dflssiz <= 0) { usage(); } if (*r == 'M') { - x86_stack_size *= MiB; + target_dflssiz *= 1024 * 1024; } else if (*r == 'k' || *r == 'K') { - x86_stack_size *= KiB; + target_dflssiz *= 1024; + } + if (target_dflssiz > target_maxssiz) { + usage(); } } else if (!strcmp(r, "L")) { interp_prefix = argv[optind++]; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index c5414c7b4c..3f741027f4 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -223,7 +223,12 @@ void mmap_fork_end(int child); /* 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; /* user access */ From patchwork Sat Aug 7 21:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=wlPUmLvo; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx7J3yvBz9sWX for ; Sun, 8 Aug 2021 07:58:36 +1000 (AEST) Received: from localhost ([::1]:47760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUKv-0004Gj-JM for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:58:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6I-0007z2-6T for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:26 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:38704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6F-00055i-5t for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:25 -0400 Received: by mail-io1-xd42.google.com with SMTP id a13so19905290iol.5 for ; Sat, 07 Aug 2021 14:43:22 -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=3mhxBhms5SPEYi9WNkLr28Yj+QMrSE4+Bjh827JVMtU=; b=wlPUmLvoZZSfas6NNH7TFy7uY+q8OlVYqsrb7r4dnLUos5EZZoSxbqIYOCN/Gjgasr v3MlrCKO1sfMWqGKSQAlo3XH7tbYwxyXgZRlLc5s5ucP7ePEW4eiC2AqDxm9iosLtQsT eLyCbDB5gUFNScGOCEdhCdn9n2JJsg22Ks1odRkqGubztwcMf/7dINr212aI6mJeoJ5h XoQOgmst7KBQDRnxMskEMLEXAywZY1Pq96+EmLaTa7+HRc0JsqMHgCtGwscl/vCDvxrB 8V73WP6hhcIz9jJ+X2V4c2UYdp9wZbDIJ/wZO/S1RVdHRSWswL+/DQqSJYofSO+Sovgn 2bRw== 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=3mhxBhms5SPEYi9WNkLr28Yj+QMrSE4+Bjh827JVMtU=; b=Ia85zlaJDgrlgB9/S/TcPGkHpRjgYhI2tClsxFI5Z/DK/8oXbGWHSYsblvnL2QhJFO 8X/JEPjLwafAQVTHuwfmve9cStkSQuCUHUpRDP85V5/K4jnxYYztBiNRBSamfGQV9dix ef3/lg8aczSbM41xhXgiq513BPO5o3FbHD+V+ntQA/wwY2hd/hIKotkMC2kZ+j15oxMj 6M9Sw3SzVVD1MT/C1x4+U6KT9l5iu0+ULfbrWcnv0V3K+0HNStYPxmYFlG5+wdGE/QQQ eWj/HTZSn6swAawtMy1VGB3x9jKEgNfKMsK0lVvNrNlTZt45Qe+uxQGud9Dw3pU/P6Z+ tqYA== X-Gm-Message-State: AOAM530yg/TmZbMqY1c4+pTN0quyCzy7uG6Sv5R8HKWUyjfcDsKvzXPw V9P7akBjTenCXaCDb5+PiMyOFTq8vY/V1FaE X-Google-Smtp-Source: ABdhPJzcFi4pQiglRD3W43ZovT7vBQoZaybnsRDKACaiWYsCT62yinYgIByn8yIcHHEX03HwrvfHMQ== X-Received: by 2002:a5e:d719:: with SMTP id v25mr98126iom.124.1628372601727; Sat, 07 Aug 2021 14:43:21 -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 a17sm8062827ios.36.2021.08.07.14.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:21 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 30/49] bsd-user: elf cleanup Date: Sat, 7 Aug 2021 15:42:23 -0600 Message-Id: <20210807214242.82385-31-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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: Stacey Son , Justin Hibbits , Alexander Kabaev , Kyle Evans , Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Sponsored by: Netflix Acked-by: Richard Henderson --- bsd-user/elfload.c | 190 ++++--------------------------- bsd-user/freebsd/target_os_elf.h | 149 ++++++++++++++++++++++++ bsd-user/netbsd/target_os_elf.h | 143 +++++++++++++++++++++++ bsd-user/openbsd/target_os_elf.h | 143 +++++++++++++++++++++++ bsd-user/qemu.h | 1 + 5 files changed, 459 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 5ceb60b1c2..a09f8fb315 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -23,48 +23,17 @@ #include "disas/disas.h" #include "qemu/path.h" -#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_NULL */ -#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" #include "elf.h" -/* 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; 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 **argv, void **page, return p; } -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 *info, + abi_ulong *stackp, abi_ulong *stringp) { - abi_ulong stack_base, size, error; - int i; + abi_ulong stack_base, size; + abi_long addr; /* Create enough stack to hold everything. If we don't use * it for args, we'll use it for something else... */ size = target_dflssiz; - if (size < MAX_ARG_PAGES * TARGET_PAGE_SIZE) - size = MAX_ARG_PAGES * TARGET_PAGE_SIZE; - error = target_mmap(0, + stack_base = TARGET_USRSTACK - size; + addr = target_mmap(stack_base, size + qemu_host_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); - if (error == -1) { + if (addr == -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); - stack_base = error + size - MAX_ARG_PAGES * TARGET_PAGE_SIZE; - p += stack_base; + target_stksiz = size; + target_stkbas = addr; - for (i = 0 ; i < MAX_ARG_PAGES ; i++) { - if (bprm->page[i]) { - info->rss++; - /* FIXME - check return value of memcpy_to_target() for failure */ - memcpy_to_target(stack_base, bprm->page[i], TARGET_PAGE_SIZE); - g_free(bprm->page[i]); - } - stack_base += TARGET_PAGE_SIZE; + if (setup_initial_stack(bprm, stackp, stringp) != 0) { + perror("stk setup"); + exit(-1); } - return p; } 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) } } - -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 = sizeof(elf_addr_t); - - sp = p; - u_platform = 0; - k_platform = ELF_PLATFORM; - if (k_platform) { - size_t len = strlen(k_platform) + 1; - sp -= (len + n - 1) & ~(n - 1); - u_platform = sp; - /* FIXME - check return value of memcpy_to_target() for failure */ - memcpy_to_target(sp, k_platform, len); - } - /* - * Force 16 byte _final_ alignment here for generality. - */ - sp = sp & ~(abi_ulong)15; - size = (DLINFO_ITEMS + 1) * 2; - if (k_platform) - size += 2; -#ifdef DLINFO_ARCH_ITEMS - size += DLINFO_ARCH_ITEMS * 2; -#endif - size += envc + argc + 2; - size += 1; /* argc itself */ - size *= n; - if (size & 15) - sp -= 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 -= n; put_user_ual(val, sp); \ - sp -= 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. PPC). - */ - ARCH_DLINFO; -#endif -#undef NEW_AUX_ENT - - sp = 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 target_pt_regs *regs, info->mmap = 0; elf_entry = (abi_ulong) elf_ex.e_entry; - /* - * 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 = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; - i++, elf_ppnt++) { - if (elf_ppnt->p_type != PT_LOAD) - continue; - if (HOST_PAGE_ALIGN(elf_ppnt->p_vaddr) < mmap_min_addr) { - guest_base = 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 = 0; - bprm->p = setup_arg_pages(bprm->p, bprm, info); + setup_arg_pages(bprm, info, &bprm->p, &bprm->stringp); info->start_stack = bprm->p; /* Now we do a little grungy work by mmaping the ELF image into @@ -965,13 +826,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, #ifdef LOW_ELF_STACK info->start_stack = bprm->p = elf_stack - 4; #endif - bprm->p = create_elf_tables(bprm->p, - bprm->argc, - bprm->envc, - &elf_ex, - load_addr, load_bias, - interp_load_addr, - info); + bprm->p = 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 = reloc_func_desc; info->start_brk = info->brk = elf_brk; info->end_code = 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..5232abf852 --- /dev/null +++ b/bsd-user/freebsd/target_os_elf.h @@ -0,0 +1,149 @@ +/* + * 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 = sizeof(elf_addr_t); + + target_auxents_sz = 0; + sp = p; + /* + * Force 16 byte _final_ alignment here for generality. + */ + sp = sp &~ (abi_ulong)15; + size = (DLINFO_ITEMS + 1) * 2; + size += envc + argc + 2; + size += 1; /* argc itself */ + size *= n; + if (size & 15) + sp -= 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 -= n; put_user_ual(val, sp); \ + sp -= n; put_user_ual(id, sp); \ + target_auxents_sz += 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); + features = ELF_HWCAP; +#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) + { +#ifdef ARM_FEATURE_VFP3 /* XXX FIXME XXX */ + ARMCPU *cpu = ARM_CPU(thread_cpu); + if (arm_feature(&cpu->env, ARM_FEATURE_VFP3)) + features |= ARM_HWCAP_ARM_VFPv3; + if (arm_feature(&cpu->env, ARM_FEATURE_VFP4)) + features |= ARM_HWCAP_ARM_VFPv4; +#endif + } +#endif + NEW_AUX_ENT(FREEBSD_AT_HWCAP, features); +#ifndef TARGET_PPC + 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()); +#endif + target_auxents = sp; /* Note where the aux entries are in the target */ +#ifdef ARCH_DLINFO + /* + * ARCH_DLINFO must come last so platform specific code can enforce + * special alignment requirements on the AUXV if necessary (eg. PPC). + */ + ARCH_DLINFO; +#endif +#undef NEW_AUX_ENT + + sp = 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_elf.h new file mode 100644 index 0000000000..08ff04065a --- /dev/null +++ b/bsd-user/netbsd/target_os_elf.h @@ -0,0 +1,143 @@ +/* + * 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 = sizeof(elf_addr_t); + + sp = p; + u_platform = 0; + k_platform = ELF_PLATFORM; + if (k_platform) { + size_t len = strlen(k_platform) + 1; + sp -= (len + n - 1) & ~(n - 1); + u_platform = sp; + /* FIXME - check return value of memcpy_to_target() for failure */ + memcpy_to_target(sp, k_platform, len); + } + /* + * Force 16 byte _final_ alignment here for generality. + */ + sp = sp &~ (abi_ulong)15; + size = (DLINFO_ITEMS + 1) * 2; + if (k_platform) + size += 2; +#ifdef DLINFO_ARCH_ITEMS + size += DLINFO_ARCH_ITEMS * 2; +#endif + size += envc + argc + 2; + size += 1; /* argc itself */ + size *= n; + if (size & 15) + sp -= 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 -= n; put_user_ual(val, sp); \ + sp -= 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. PPC). + */ + ARCH_DLINFO; +#endif +#undef NEW_AUX_ENT + + sp = 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..c70e1da7b0 --- /dev/null +++ b/bsd-user/openbsd/target_os_elf.h @@ -0,0 +1,143 @@ +/* + * 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 = sizeof(elf_addr_t); + + sp = p; + u_platform = 0; + k_platform = ELF_PLATFORM; + if (k_platform) { + size_t len = strlen(k_platform) + 1; + sp -= (len + n - 1) & ~(n - 1); + u_platform = sp; + /* FIXME - check return value of memcpy_to_target() for failure */ + memcpy_to_target(sp, k_platform, len); + } + /* + * Force 16 byte _final_ alignment here for generality. + */ + sp = sp &~ (abi_ulong)15; + size = (DLINFO_ITEMS + 1) * 2; + if (k_platform) + size += 2; +#ifdef DLINFO_ARCH_ITEMS + size += DLINFO_ARCH_ITEMS * 2; +#endif + size += envc + argc + 2; + size += 1; /* argc itself */ + size *= n; + if (size & 15) + sp -= 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 -= n; put_user_ual(val, sp); \ + sp -= 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. PPC). + */ + ARCH_DLINFO; +#endif +#undef NEW_AUX_ENT + + sp = 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 3f741027f4..b47312b1e2 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -127,6 +127,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; From patchwork Sat Aug 7 21:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=DEnOTeEE; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxCj4PQwz9sWl for ; Sun, 8 Aug 2021 08:02:25 +1000 (AEST) Received: from localhost ([::1]:59778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUOd-0003xU-7s for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:02:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6H-0007wj-Gf for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:25 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]:36826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6G-00057V-0I for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:25 -0400 Received: by mail-io1-xd2d.google.com with SMTP id f11so19876891ioj.3 for ; Sat, 07 Aug 2021 14:43:23 -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=gnr+5rbOJGaDAhEuFudq50cgY0fAjmRcHPUHHvIxNIY=; b=DEnOTeEEKz5jQc+0CQm62acebqc0uV8/bh9h8CKmIXWUZh4QzCVpI7KDhXruKBLYmr cKIP+QUTeNv9pbPmsv073DZZBrR5oB2n3J3Vvg1P/xPzdW1vM9m+UkR2X3ieMK/vIEX1 D7zNQ2VQB87hELcLYO0zJQnb51KrOcB43FvPMd3y4sgqYYDU1r4vyEz6KoHoy5t1zqTg BkQ7CwcWIdqey0cd4yB3InMv3UPtCq9NwAYbTIFDJ/UFyH1MGFuTQhsMvoHY38uJpwsy i50syFD+9qmHvYT6mwsKuromzInTW8qXAn1NimFS8pPgbuUpKpF7wXQWK2Axovqs6GYJ E6vQ== 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=gnr+5rbOJGaDAhEuFudq50cgY0fAjmRcHPUHHvIxNIY=; b=CIxAzvzXclciN7C+jaJIKNZt2+vKqArMBXdL6v409SWqpPOPd+sBpwV0vcLhunJpW0 vwX0c6wz+NlbnroKfyxYjS+e79leROReq+r0U8F3j293ekLbkMsx8IQpQ8tPs596kIV5 XuYAgl1F1BjEe3ok5xOk71V4JTNSgF3HG3lkyOfVwDBqvx6beA1GrS2A5LCz5xdh1Bpa zASd0dH21KBsfWCG2KHWpVhsAX8eNpXH3qxsOxFSTEAZsSCLFXFhJuxX1Mqvu6RwPf+w V+//Ib0ejJfL5LP+M1BrwtF/egUNgH/5NXirQ7h5a3X0ytdTvtAFRqp8lGLT/AypGHDx af9w== X-Gm-Message-State: AOAM530znEdx94HoMJfkHZDwbvd0ynY9lcGDnrniEk0CrIauhfnt1mV/ 1cLfixLBDo4nEfomjV38ckGraUHkLCfE+KjF X-Google-Smtp-Source: ABdhPJzYW95/2fNxH2moJj4qnNJBAYFMBre1IPUW486FANAJQMmV5Qno2Tn/XpFUXFMipBEb2hrJBw== X-Received: by 2002:a6b:7f48:: with SMTP id m8mr412751ioq.5.1628372602781; Sat, 07 Aug 2021 14:43:22 -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 a17sm8062827ios.36.2021.08.07.14.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:22 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 31/49] bsd-user: Remove dead #ifdefs from elfload.c Date: Sat, 7 Aug 2021 15:42:24 -0600 Message-Id: <20210807214242.82385-32-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 a09f8fb315..c0787a4e52 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -558,9 +558,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, abi_ulong elf_entry, interp_load_addr = 0; abi_ulong start_code, end_code, start_data, end_data; abi_ulong reloc_func_desc = 0; -#ifdef LOW_ELF_STACK - abi_ulong elf_stack = ~((abi_ulong)0UL); -#endif load_addr = 0; load_bias = 0; @@ -761,11 +758,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, exit(-1); } -#ifdef LOW_ELF_STACK - if (TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack) - elf_stack = TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr); -#endif - if (!load_addr_set) { load_addr_set = 1; load_addr = elf_ppnt->p_vaddr - elf_ppnt->p_offset; @@ -823,9 +815,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, close(bprm->fd); -#ifdef LOW_ELF_STACK - info->start_stack = bprm->p = elf_stack - 4; -#endif bprm->p = 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 = reloc_func_desc; @@ -842,15 +831,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, padzero(elf_bss, elf_brk); -#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 = elf_entry; return 0; From patchwork Sat Aug 7 21:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514756 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=xCyC1s1a; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxFb1mfTz9sWX for ; Sun, 8 Aug 2021 08:04:03 +1000 (AEST) Received: from localhost ([::1]:38090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUQD-0008K2-07 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:04:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6K-00088j-Q1 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:28 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:42661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6H-00059E-6g for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:28 -0400 Received: by mail-io1-xd44.google.com with SMTP id h1so19882143iol.9 for ; Sat, 07 Aug 2021 14:43:24 -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=KDlcdg5awHQz79CK7uZjKMsm1Syxtxzx6hnXAmY0Fqk=; b=xCyC1s1aZifOXDKwWSbE9WUtEf6F2bKudH7JEn9Ja9VNWLyzC+iEfSCU4DtEGwRP32 pdGN6SUueJ5ASnvD9L3PZzpKOua4qLKGsedZsjhg6LWYZsY/2UTBhIrPBOW4UfFv4RFh 5Ib9IIiXyB3HmRgb9XiUdAyc0Xe1hpFdC/qp6kSg9RuaCZ15uVVkspshaB12y6Xuk/Xs +YJjjMdlekYCLafdkUh8E8emYKOlnJOU9F/4cE/VRPxzBlE0K9FII4VwIZ4BledLFvwP gNxHtZas1aABTkK5jk50Q18x6Ho7IhaHYR/CGpuY6GnzxYVvn1YJAhuShZ0R7OpQB1xZ rI9w== 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=KDlcdg5awHQz79CK7uZjKMsm1Syxtxzx6hnXAmY0Fqk=; b=eBqB9kGsIO2Lk1EWlRPY7TktuMp2MLeZ5ROAz4gvAhoW0ZxZsETpXiXd4e8njuR9Wz iACo1/g6f4NdABM5du63GddCrzesp4JpYjqpGe4xtm/8tPUISiWwRmL0u6atFv6GrjDO EJMpPRxnibQbZfco5OPC/+NnCjUiSq8n5ChjtI9c6klb4lz9Hs0tpp5SmL2S9O6vXpgb WU5dCN03q2JMYkRoaIHKKJsN8L9cF0cVHYxZMf7qNKxaxaDmnnkoS3FdaARki/kdqdd4 350H93lO36mnzu/4B+5U1M+bmjakFKZ6RTnw0gwa2S3aj4Y3SIE4Ynx5j8e2Z2hy+VUc 2/og== X-Gm-Message-State: AOAM5301mltqoRLKYS19aUJmYPcJ2d9YEHKag+22nNYExM2H0mQhjjzu FK8a6c7/yZXMdy+afOQA8kJ3CRyZ6aATRxlA X-Google-Smtp-Source: ABdhPJwfHLwP5grFMUpsge5x4h1IhlszLaBEhUhvKsMy6S1/D/lIFQidoQgp1Hu++8FmRwTJ2GfdfQ== X-Received: by 2002:a92:d60a:: with SMTP id w10mr260156ilm.22.1628372603844; Sat, 07 Aug 2021 14:43:23 -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 a17sm8062827ios.36.2021.08.07.14.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:23 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 32/49] bsd-user: *BSD specific siginfo defintions Date: Sat, 7 Aug 2021 15:42:25 -0600 Message-Id: <20210807214242.82385-33-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 | 70 +++++++++++++ bsd-user/openbsd/target_os_siginfo.h | 82 +++++++++++++++ bsd-user/openbsd/target_os_signal.h | 70 +++++++++++++ bsd-user/qemu.h | 3 +- bsd-user/syscall_defs.h | 10 -- bsd-user/x86_64/target_arch_signal.h | 94 +++++++++++++++++ 10 files changed, 716 insertions(+), 12 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..d12b2e213e --- /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 caught) */ +#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<OSTOP)*/ +#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 delivering */ +#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 stop */ +#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 stack*/ + +#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..e2387b2863 --- /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) */ /* XXX to be added. */ + +/* 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; /* = *sf_uncontext */ + target_siginfo_t sf_si; /* = *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; +} + +/* 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 = 0; + return -TARGET_EOPNOTSUPP; +} + +#endif /* TARGET_ARCH_SIGNAL_H */ diff --git a/bsd-user/netbsd/target_os_siginfo.h b/bsd-user/netbsd/target_os_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 == 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..d39a26f6e6 --- /dev/null +++ b/bsd-user/netbsd/target_os_signal.h @@ -0,0 +1,70 @@ +#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 caught) */ +#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<OSTOP) */ +#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 delivering */ +#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 stop */ +#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 stack */ + +#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 == 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..d39a26f6e6 --- /dev/null +++ b/bsd-user/openbsd/target_os_signal.h @@ -0,0 +1,70 @@ +#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 caught) */ +#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<OSTOP) */ +#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 delivering */ +#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 stop */ +#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 stack */ + +#endif /* !_TARGET_OS_SIGNAL_H_ */ diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index b47312b1e2..a22fc19cd6 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -45,8 +45,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 "hostdep.h" +#include "target_os_signal.h" #include "exec/gdbstub.h" /* 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 */ -#define TARGET_NSIG 32 /* counting 0; could be 33 (mask is 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 */ -/* - * 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 */ 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..1998570e9d --- /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) */ /* XXX to be added */ + +/* 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; /* = *sf_uncontext */ + target_siginfo_t sf_si; /* = *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; +} + +/* 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 = 0; + return -TARGET_EOPNOTSUPP; +} + +#endif /* !TARGET_ARCH_SIGNAL_H_ */ From patchwork Sat Aug 7 21:42:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=qe0Mn8RB; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx9m3ycyz9sWX for ; Sun, 8 Aug 2021 08:00:44 +1000 (AEST) Received: from localhost ([::1]:54970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUN0-0000fH-4a for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:00:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6L-0008A3-5j for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:29 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:41712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6I-0005CQ-3T for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:28 -0400 Received: by mail-io1-xd42.google.com with SMTP id 188so18233787ioa.8 for ; Sat, 07 Aug 2021 14:43:25 -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=maepad3ajf55++2eO61t61QOUXz5nVsSBYBxyAWau+g=; b=qe0Mn8RB/juuyzQkEDkWAp3Exzpt4b/ukoBwYc1DYbQ6LaTUVZeSeLyc6KpOo1X+f0 /F2Eo2qX31k8ltvZfHgz5/Yn2z8hDgT33zLIqsiqIQafqIF6dngUqLhiT/Ve9TKclsL2 5Q8+QMV990x+9q/N3UE2WDk3gTkSi514pxoowr9jtbzt8jx7KMzsdYbCNwRs0XZnBXXu kZqAvIXLQEA1u1AQLUIPzAkjjw8eTmHgyXYKvmAxAE2NiBByVlYMLw30/t/L7eM1jKFe e8PxTrE56jVLFteB51I89WMXdrhAXlBPSYGaBRtNYlud75MDrrQLJ1dG9Aspjb7393tw JJOA== 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=maepad3ajf55++2eO61t61QOUXz5nVsSBYBxyAWau+g=; b=pF4OObw+F1dm71eJwxdG5kUHdDESre5ZkpylfNso2NHc9rmaklgooF0DHS5tc90Oaz x1pCF8JroFodjvORYrn3FKY1JnMjzqEpIiTv4RjguwXq1nCMk3aBg9N+21AQEKS3Fwt6 a72XvZnSeNFZxqnaJXajmLRGrgNYOAJaZRSjlIk/AIBSu9fw34+rMkF4tbO2Xx1P7aeQ VXbIOOpjjz7m0UPQaTQzptg+ez5Hrwk7hmT+x69uCEsLvEvFChviuJ8LUx/9iwS5Sfi4 rLDlfyGOQj5lZ/F3PLKBM13ji3m8O8gzpFY0YhZxipCgE0RzqMhZvtgJS+susAEzdh03 9tKg== X-Gm-Message-State: AOAM5314EWAYq/MxRARSGTNSg7ZWsfxr8wjx1im/RbQnC8ep+qU/oxG8 LifpXhlLV6xvyz5rSfXJIohM4fwbc5Qtnol9 X-Google-Smtp-Source: ABdhPJyXFfU08Q0oC/BrwQsu0oXzUL6gffOXEK9u4tx9Ewt9+OVlTxjgNtcKwCqTIxjrDz/tPNjDfg== X-Received: by 2002:a6b:ea0b:: with SMTP id m11mr48141ioc.186.1628372604754; Sat, 07 Aug 2021 14:43:24 -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 a17sm8062827ios.36.2021.08.07.14.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:24 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 33/49] bsd-user: Rewrite target system call definintion glue Date: Sat, 7 Aug 2021 15:42:26 -0600 Message-Id: <20210807214242.82385-34-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)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 misimplemented MAP_INHERIT */ -#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mman.h 8.2 (Berkeley) 1/9/95 - */ -#define TARGET_NETBSD_MAP_INHERIT 0x0080 /* region is retained after exec */ -#define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mman.h 8.1 (Berkeley) 6/2/93 - */ - -#define TARGET_OPENBSD_MAP_INHERIT 0x0080 /* region is retained after exec */ -#define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change 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 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 @@ #include "qemu.h" #include "qemu-common.h" -#include "bsd-mman.h" -#include "exec/exec-all.h" //#define DEBUG_MMAP diff --git a/bsd-user/syscall_defs.h b/bsd-user/syscall_defs.h index eb7d1da9b0..3b36a6963c 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 PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * 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 caught) */ -#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<OSTOP) */ -#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 signal */ -#define TARGET_SA_NODEFER 0x0010 /* don't mask the signal we're delivering */ -#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 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 */ -#define TARGET_BADSIG SIG_ERR +#ifndef _SYSCALL_DEFS_H_ +#define _SYSCALL_DEFS_H_ -#define TARGET_SS_ONSTACK 0x0001 /* take signals on alternate stack */ -#define TARGET_SS_DISABLE 0x0004 /* disable taking signals on alternate stack */ +#include #include "errno_defs.h" @@ -97,8 +28,154 @@ #include "netbsd/syscall_nr.h" #include "openbsd/syscall_nr.h" +/* + * 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 */ }; +/* + * sys/mman.h + */ +#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080 /* previously misimplemented + MAP_INHERIT */ +#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100 /* previously unimplemented + 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 after + exec */ +#define TARGET_NETBSD_MAP_TRYFIXED 0x0400 /* attempt hint address, even + 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 after + exec */ +#define TARGET_OPENBSD_MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change + 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 == 32 + abi_long _pad; +#endif +} __packed; + +#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 == 32 + abi_long _pad; +#endif +} __packed; + +/* + * 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_ */ From patchwork Sat Aug 7 21:42:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=gk4+7t71; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxDF1mqSz9sWX for ; Sun, 8 Aug 2021 08:02:53 +1000 (AEST) Received: from localhost ([::1]:33520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUP4-0005HP-VD for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:02:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6M-0008DW-2Y for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:30 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]:34514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6J-0005Ds-2c for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:29 -0400 Received: by mail-io1-xd33.google.com with SMTP id i7so13719944iow.1 for ; Sat, 07 Aug 2021 14:43:26 -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=elLmv36Kug9A6y9rvQz6AHSujsYE6H7MjC5Me2JmWos=; b=gk4+7t71HFpVtGYMyJEvGrzzAonn2W+Ihzp5PEWjxlx2ShmUZJqbm95J1rGwrvjU8k 9S4dA9BQHZz0mqeX9llGSCYEQrjAZYHwXJWlrJ5CZBNRBTFyRmTxP12jifMo+ntsGB0f tlsxAyTbFY5tSIHiBh8qvyC30VHKxvubnYWulkk5Y1v5gkKtULhnTwoI+FUuowKQ8un6 fpVw4gg8ySzF1i6wDIRs4B1OBSF0p/3KtlEswy2wFxobo9Q6NA4HQUkQT7VXB7P2aK7V qQrKEpinZ9HZFJA63KW8Ugci+gSxscvGQAuFUftpK19cygfg7m/4gAKNBC4gg1cXhvgM T1AQ== 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=elLmv36Kug9A6y9rvQz6AHSujsYE6H7MjC5Me2JmWos=; b=oH6oZpeVU1v3Q0KZNDudgt1azXWTicWrnmcfKPTVmK9LXPPd3viIR316C+aNcNw3mb KuMK1xeAoB3W7JZ/rJ0kEDW5gcMjSmzAPy+WQlA59hglHGZAuH+/X8QfVBpmvsdQwfm1 vZ6sfscErHIBqUEaAgzYkx+O6D4tlTnv9CW35JothdiFWYCF/JiZCdAJFRjqKtC4YEwg ridrajdWo9VWcyHWSrVvXn2UK1xnRIAOfmZUcC7xJeBfEf6R80fCM97B6AeuTWqB4AdE DZ1tmD0H9GHhWxhrEbk3W3foy5ZSAspuAu8Z3ePK+nylSr25p5/t0zvuaVQhKJCWzJVF RUmg== X-Gm-Message-State: AOAM530oluey06GH+A5BZ4LIMsSBgh4zD05HU54SduIR0EWSYrz68JEf CCuju91RDCBdDDs28YhlESNe3NnJfD4ZgSfX X-Google-Smtp-Source: ABdhPJzcvJNyRavK0c3G6QAhDF3NSerRar/oxNmwiDg7ipk1M/B5GB7OpXNJdHq0dYISa8GM7CnIwA== X-Received: by 2002:a05:6602:2e8a:: with SMTP id m10mr32350iow.45.1628372605768; Sat, 07 Aug 2021 14:43:25 -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 a17sm8062827ios.36.2021.08.07.14.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:25 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 34/49] bsd-user: Fix initializtion of task state Date: Sat, 7 Aug 2021 15:42:27 -0600 Message-Id: <20210807214242.82385-35-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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 , Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Fix a number of mismerges in initializing the task state. Save a copy of bprm in this structure and move it earlier before starting to setup other state. Remove linux specific procfs access to find minimal vm address that likely is here through a misguided merge. Remove duplicate initialization as well. Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Signed-off-by: Stacey Son Reviewed-by: Richard Henderson --- bsd-user/main.c | 42 ++++-------------------------------------- bsd-user/qemu.h | 1 + 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 5ca1173f04..b5527537b4 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -205,7 +205,7 @@ int main(int argc, char **argv) struct target_pt_regs regs1, *regs = ®s1; struct image_info info1, *info = &info1; struct bsd_binprm bprm; - TaskState ts1, *ts = &ts1; + TaskState *ts; CPUArchState *env; CPUState *cpu; int optind, rv; @@ -407,31 +407,7 @@ int main(int argc, char **argv) */ guest_base = HOST_PAGE_ALIGN(guest_base); - /* - * 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 = fopen("/proc/sys/vm/mmap_min_addr", "r"); - if (fp != NULL) { - unsigned long tmp; - if (fscanf(fp, "%lu", &tmp) == 1) { - mmap_min_addr = tmp; - qemu_log_mask(CPU_LOG_PAGE, "host mmap_min_addr=0x%lx\n", - mmap_min_addr); - } - fclose(fp); - } - } - - if (loader_exec(filename, argv+optind, target_environ, regs, info, - &bprm) != 0) { + if (loader_exec(filename, argv+optind, target_environ, regs, info, &bprm)) { printf("Error loading %s\n", filename); _exit(1); } @@ -459,21 +435,11 @@ int main(int argc, char **argv) qemu_log("entry 0x" TARGET_ABI_FMT_lx "\n", info->entry); } - target_set_brk(info->brk); - syscall_init(); - signal_init(); - - /* - * Now that we've loaded the binary, GUEST_BASE is fixed. Delay - * generating the prologue until now so that the prologue can take - * the real value of GUEST_BASE into account. - */ - tcg_prologue_init(tcg_ctx); - /* build Task State */ - memset(ts, 0, sizeof(TaskState)); + ts = g_new0(TaskState, 1); init_task_state(ts); ts->info = info; + ts->bprm = &bprm; cpu->opaque = ts; target_set_brk(info->brk); diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index a22fc19cd6..bfd7b8eaa5 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -90,6 +90,7 @@ typedef struct TaskState { pid_t ts_tid; /* tid (or pid) of this task */ struct TaskState *next; + struct bsd_binprm *bprm; int used; /* non zero if used */ struct image_info *info; From patchwork Sat Aug 7 21:42:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=wANSdzZc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx6S0KW0z9sWl for ; Sun, 8 Aug 2021 07:57:52 +1000 (AEST) Received: from localhost ([::1]:45062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUKD-0002Uv-Q0 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:57:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6N-0008Id-Ah for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:31 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]:34505) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6K-0005GR-3J for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:31 -0400 Received: by mail-io1-xd29.google.com with SMTP id i7so13719978iow.1 for ; Sat, 07 Aug 2021 14:43:27 -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=CXac4zaSVrqLe0EtJN2ruvSY7l2U8k34jVxG92h1/AU=; b=wANSdzZckf7Db+tFxKscYWjd6nVcXilsg6USU4eZCX2ihYscCxci8jgjPutGaetMUJ H+CIjyAr7lu07nNA9tT6FqbKqoFV8fWxos/q9R7uwzFO9nnSIWmHLrDEA0lNd5CKQzti Wch9yATDgjuKkoLmifPLV4duTOtKljs3XN39//WB3FSduBYTVHNaQslbs9GcEJJGnXco Sru9ZaIZAry7d5a2YhUoF54tvehoafirTzvzl16QMYCYFk9wZ6bgroI5QuBwL0FuY9DW 5XTY/u8RqF9ex7TS3NBXF+o4fyI3lr854npkK+b+IGlSAqv3xlUyRiKHDUVX8Y9VeDSn zrKA== 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=CXac4zaSVrqLe0EtJN2ruvSY7l2U8k34jVxG92h1/AU=; b=X5qmTl2/qm9cviZHZKOo3uvdyK/187evi4AEeEoYX84+NOOtLmhR/XYfqiD4jrfXPD fV/7KjrK9Tp3eQuy+aemMMP5hMvP8XM2Hh9B9s+Je8hm7WTv4mrSJwSdiVerH+IQiM60 7IkUuetHGXyJY/99F0ccIOvrelqszBinE5VIsVK9CXJ6SZd89ELZmm3cWkKMay2u4DVG Qx4surudjLBmYh5YaudbMcPDCMS9Qx8/R5xzUXJegaDj2GWxDuiZoRAdqxBnauOX1Cxs ms8YMVKjV3tsMzp5XJIbFW12xulZwBWw5IXcXX6bHQHMkXeswM66f707ezax4cXDkctU Uwrw== X-Gm-Message-State: AOAM5336HXf6SWsPYDDlOTP3QXzY0VoIB6xqJhaYjtGgSOO9sk0SUzW0 RDpIqU85MNuLfiBehoynx/rVbp15qlIXdkbK X-Google-Smtp-Source: ABdhPJxUsOtbcYJaCok3bPuy1sjTBAmLRS0NeISbs3URvdMHKas76GL25/rHSHJddcuLVwVe7tgEgg== X-Received: by 2002:a6b:b306:: with SMTP id c6mr190342iof.24.1628372606606; Sat, 07 Aug 2021 14:43:26 -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 a17sm8062827ios.36.2021.08.07.14.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:26 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 35/49] bsd-user: remove error_init Date: Sat, 7 Aug 2021 15:42:28 -0600 Message-Id: <20210807214242.82385-36-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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: 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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Error reporting isn't used, so gc it until it's used. Signed-off-by: Warner Losh --- bsd-user/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index b5527537b4..7e20430fb7 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -34,7 +34,6 @@ #include "qapi/error.h" #include "qemu.h" #include "qemu/config-file.h" -#include "qemu/error-report.h" #include "qemu/path.h" #include "qemu/help_option.h" #include "qemu/module.h" @@ -223,7 +222,6 @@ int main(int argc, char **argv) save_proc_pathname(argv[0]); - error_init(argv[0]); module_call_init(MODULE_INIT_TRACE); qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); From patchwork Sat Aug 7 21:42:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514757 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=XoTqhoAP; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxGQ51bJz9sWX for ; Sun, 8 Aug 2021 08:04:46 +1000 (AEST) Received: from localhost ([::1]:40074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUQu-0001Dg-89 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:04:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6M-0008EL-9K for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:30 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]:39692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6K-0005Hc-Ka for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:30 -0400 Received: by mail-io1-xd2e.google.com with SMTP id r72so5855988iod.6 for ; Sat, 07 Aug 2021 14:43:28 -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=5A2mszKQ5aOSvpmfaS/1EtSnZ2WQixfIiVZgOA13t6U=; b=XoTqhoAPh76UHBMrvuHqJf+zxOnYQg+rr+AIe9jyFtnc2TnKyBjfwQgoVuuDKs0is3 ZffyoZhGGKsQ1XtFMi15pG6Yu2Bt6PKwFHKQuGTre4zxapT6CmghREr8UtZxKq5kIYVg kW1bMUUu52WIjONiMGCOZma8j3Mb05i8rzZ8THQ9goQKmQYNNNe7Njw6/ugubXyNmhAi YlOlK3/GpY97OOLxtW7zb0YXW7YB/MXFH9X4RMSySAxxNBdoyre946BzLxyfRATYNv4c 1aGKak4SVXRm1W1RRJxqfGeSd8bV9KPq2xBnJEeFoaJqN/lblRK3BtLXHQSUg8ARm02n K+/w== 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=5A2mszKQ5aOSvpmfaS/1EtSnZ2WQixfIiVZgOA13t6U=; b=hqURHhyhpq9sNBaPZTDbCZp1grOqRCDbznDhS3eKr7ROF4/U61/Lpi0kiyhshlgmvS iy0aeY0WkO7g9bRHi1HUEdLoyPwA9VYmVtIjARKQ2dwmaJdfFk2zNnVKh5ocEnmWw1dM dB7zwcouXtf8zGdx1xJflih9LMPjs35un51UskUxHMvk8qcQ9BCqOl+Cni7TKmPq6NqE mCkyWGhQKkFSIaww7cVvJdU2uqxvL+Dzx66N2UdCbAWwhsR7+OxsVkRmHdgunK8DRF0x cJRLcCXXhwQKHyZRf8vUyzJ+nadBmmObCMObczmOwjzQIk88HX2GQrKbNpi+PUciIc9/ H11w== X-Gm-Message-State: AOAM531vPdBgqe8s9FjN4eDbmtSiC49RP2RYConGZOCi3NY3/qzeYj88 dY3DZMth75o0w0t03yiUwjaig0MX2wfisT92 X-Google-Smtp-Source: ABdhPJz0Jt0lVF7k6xKCGzCoIWhcWj4xCGPpbw5CK8N74IMdxsdRAU+wtZOueFt1u35X4MSqYgwVLg== X-Received: by 2002:a05:6638:1356:: with SMTP id u22mr15955690jad.39.1628372607413; Sat, 07 Aug 2021 14:43:27 -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 a17sm8062827ios.36.2021.08.07.14.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:27 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 36/49] bsd-user: Make cpu_model and cpu_type visible to all of main.c Date: Sat, 7 Aug 2021 15:42:29 -0600 Message-Id: <20210807214242.82385-37-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh cpu_model and cpu_type will be used future commits, so move them from main() scoped to file scoped. Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 7e20430fb7..93ef9298b8 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -51,6 +51,8 @@ int singlestep; unsigned long mmap_min_addr; uintptr_t guest_base; +static const char *cpu_model; +static const char *cpu_type; bool have_guest_base; unsigned long reserved_va; @@ -197,8 +199,6 @@ static void save_proc_pathname(char *argv0) int main(int argc, char **argv) { const char *filename; - const char *cpu_model; - const char *cpu_type; const char *log_file = NULL; const char *log_mask = NULL; struct target_pt_regs regs1, *regs = ®s1; From patchwork Sat Aug 7 21:42:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514759 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=AYCCB486; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxJy4b0bz9sWX for ; Sun, 8 Aug 2021 08:06:58 +1000 (AEST) Received: from localhost ([::1]:47838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUT2-0006Ra-CG for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:06:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6O-0008N7-Ec for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:32 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]:46889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6L-0005IC-LP for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:32 -0400 Received: by mail-io1-xd33.google.com with SMTP id x10so9098131iop.13 for ; Sat, 07 Aug 2021 14:43:29 -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=hMZeNvS0Jt1YHQmPhjmHqhTtgGPWiJc8Qou+PKhoA5E=; b=AYCCB486mJ86Ocw/dGGUKbi7YegpYyfXDgsJEvekdhC6Ljx5axD/2/TJoI80m/uQPx y5k7PIIibsMvE0jWGise/ju8hf4W0lBtGe2zTZojS3rM3eKw/e28lQlU5EL6QM4cChrM vOZ9ZUTPIUwYkvgytWGKVHJMtmWn+VzSMLquqHr/WTf99yjmSiJa+sm3NI0SgF4/2DAk QtXBu/y4pCymGoWcE7+pBotOqkZvbtzuPJdQfbTdUrewWHOgdvhzVbYkXMvuRvB9FLUF xsgVZBOWELrwZWX4L3KR1OLS9QppK9lT6zHl6qzJ1J9FUOCAoSmH6xHULSqJ5hLpiQ0F r7cw== 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=hMZeNvS0Jt1YHQmPhjmHqhTtgGPWiJc8Qou+PKhoA5E=; b=R54ieT1vEXo4zoJp/FpMdytAET2eODBj7PXW3hYO/iJX7feo+FDFFNNuMf5yTc0XEX uEXGPK+tE05D8dFCwICR0K1arSFAwfz8tsCDxpGASr8ZcaGisbEsOH9SGNqvIRWAhuFM TQ1Od/JH0c5Fr2XYa1wbuCVYBa03GX8Cg5qGLYh23KpZ07toRvkfNsSvl/j2KCMiQMVK AyAnUhB6pnCbFKuZSQSyCntMCyuKVjXcXgZdMqUyb37V09uIZ6+Io9TAqOPjls7w2aK6 26XYGklVDkH3/xdZRGwi1HbvaZPQEdU0W2D/tlA44TK+mHTpIjtHJLIiiQozTPP3CG5i hqYQ== X-Gm-Message-State: AOAM5331yjMDuD40BzpFDlmLeSydfMVXLmRD6tBesTNugd9UY4/H8fJy egcKUWcIZCcEYHdJfv8wWaQ7ENcG26amJMzB X-Google-Smtp-Source: ABdhPJztSPSEqjcVzeGj/sKHfUU4bro8YQ+64oFgqGxVrEIfI4+au9mgYL9OgHn/GrWYJZKyES01bg== X-Received: by 2002:a5d:9906:: with SMTP id x6mr48148iol.23.1628372608358; Sat, 07 Aug 2021 14:43:28 -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 a17sm8062827ios.36.2021.08.07.14.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:28 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 37/49] bsd-user: update debugging in mmap.c Date: Sat, 7 Aug 2021 15:42:30 -0600 Message-Id: <20210807214242.82385-38-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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 , Sean Bruno , Warner Losh , Warner Losh , =?utf-8?q?Mika?= =?utf-8?q?=C3=ABl_Urankar?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Update the debugging code for new features and different targets. Signed-off-by: MikaĆ«l Urankar Signed-off-by: Sean Bruno Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/mmap.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 03119b1f20..99563d61aa 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 prot) int prot1, ret; #ifdef DEBUG_MMAP - printf("mprotect: start=0x" TARGET_FMT_lx - " len=0x" TARGET_FMT_lx " prot=%c%c%c\n", start, len, + printf("mprotect: start=0x" TARGET_ABI_FMT_lx + "len=0x" TARGET_ABI_FMT_lx " prot=%c%c%c\n", start, len, prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); @@ -250,28 +250,37 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, mmap_lock(); #ifdef DEBUG_MMAP { - printf("mmap: start=0x" TARGET_FMT_lx - " len=0x" TARGET_FMT_lx " prot=%c%c%c flags=", + printf("mmap: start=0x" TARGET_ABI_FMT_lx + " len=0x" TARGET_ABI_FMT_lx " prot=%c%c%c flags=", start, len, prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); + if (flags & MAP_ALIGNMENT_MASK) + printf ("MAP_ALIGNED(%u) ", (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200035 + 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: - printf("MAP_PRIVATE "); - break; - case MAP_SHARED: - printf("MAP_SHARED "); - break; - default: - printf("[MAP_FLAGMASK=0x%x] ", flags & TARGET_BSD_MAP_FLAGMASK); - break; - } - printf("fd=%d offset=" TARGET_FMT_lx "\n", fd, offset); +#ifdef MAP_EXCL + if (flags & MAP_EXCL) + printf("MAP_EXCL "); +#endif + if (flags & MAP_PRIVATE) + printf("MAP_PRIVATE "); + if (flags & MAP_SHARED) + printf("MAP_SHARED "); + if (flags & MAP_NOCORE) + printf("MAP_NOCORE "); +#ifdef MAP_STACK + if (flags & MAP_STACK) + printf("MAP_STACK "); +#endif + printf("fd=%d offset=0x%llx\n", fd, offset); } #endif @@ -399,7 +408,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, page_set_flags(start, start + len, prot | PAGE_VALID); the_end: #ifdef DEBUG_MMAP - printf("ret=0x" TARGET_FMT_lx "\n", start); + printf("ret=0x" TARGET_ABI_FMT_lx "\n", start); page_dump(stdout); printf("\n"); #endif @@ -416,7 +425,9 @@ int target_munmap(abi_ulong start, abi_ulong len) int prot, ret; #ifdef DEBUG_MMAP - printf("munmap: start=0x%lx len=0x%lx\n", start, len); + printf("munmap: start=0x" TARGET_ABI_FMT_lx " len=0x" + TARGET_ABI_FMT_lx "\n", + start, len); #endif if (start & ~TARGET_PAGE_MASK) return -EINVAL; From patchwork Sat Aug 7 21:42:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=0Sx7wN7m; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxJB3rtXz9sWX for ; Sun, 8 Aug 2021 08:06:18 +1000 (AEST) Received: from localhost ([::1]:45604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUSN-0004wt-Qj for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:06:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6P-0008Qn-B5 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:33 -0400 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:37536) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6M-0005Ij-PT for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:33 -0400 Received: by mail-io1-xd42.google.com with SMTP id l20so17749390iom.4 for ; Sat, 07 Aug 2021 14:43:30 -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=tAIPPJm6zxDq+3s8RtiwvzCdGXD+I5V+8YLL7QmlLYE=; b=0Sx7wN7mG8CyP0xccqH1GruTnoPwJzHu4RwW3kTh1f7zzA0ZleQjlZxYeA/RCpk29+ HROFlus4s2stTN5td8JdSCXPjcGn6HFo+pgi6z09gWOi9p/uLEYYrZRGhHi5x1BwCP12 iKTR/Q2VM2WrfsJaDKI4frwokagtPqIY6PD8/aEaB6/+3TaUQWtd6EUWmcELS8rZWh30 Z0FQnzj3jrOpnpmoRDDmFutopj0v68E+vGDU49RTG9nvv2Gkcj+y7J6nUJ2RmAECO10Y NTn0LaU5upcN5J2h6na7OeNsHFBZV65e6s0eAxg5g01XODzF71FlJMCOZKD9SZ90wERY VDZQ== 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=tAIPPJm6zxDq+3s8RtiwvzCdGXD+I5V+8YLL7QmlLYE=; b=LyQgc+7qC6YV/SuXPa/dEHu+dGEfL311sxXiPjjq6OqXzZeHj9/SP1h32k12rvqVhm HRYHlbK9jb45NyQOMnrTEHKj8aKUtzC4gf0TkAsikUjebSAoxm1xE6sGFoue5nz/CNko uKx3d+4WWLYAYVL7BXXoXhpQLVYpGDkJCRtwNzf1ZBf8VrxdEcjQACA7T3U7JD1UT8IE 6vS2eRhCqJylct/3Z3x5pKu7NKgYEaX8k9LFYvCpGO2FxOaLHGzx49jLAmvg+i3eHQyE sM+5JRDF8pqqiVwovLIkJx9hY0bZVo2Nye8tDorxVqevYIcBc99n+D4Ftcz15OkEgGxE RZ3Q== X-Gm-Message-State: AOAM5318Av71GsEGLwfbqVerWNO0PgO1vAYSEQUJj2LnrCO6RFVYr0NO y3oBhABidAnzSRrjI07Jo+6xZ9o1YeRh4Vl4 X-Google-Smtp-Source: ABdhPJw6sZjZWgbd/k24Dwf5KGnIVa6GuFuJ4aF1/Ex6BtNNR5/XiCrH2gdGAHEFjerxJx/smYF7rg== X-Received: by 2002:a02:2506:: with SMTP id g6mr15483263jag.77.1628372609395; Sat, 07 Aug 2021 14:43:29 -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 a17sm8062827ios.36.2021.08.07.14.43.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:29 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 38/49] bsd-user: Update mapping to handle reserved and starting conditions Date: Sat, 7 Aug 2021 15:42:31 -0600 Message-Id: <20210807214242.82385-39-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , =?utf-8?q?Mika=C3=ABl_Urankar?= , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: MikaĆ«l Urankar Signed-off-by: Stacey Son Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/main.c | 23 ++- bsd-user/mmap.c | 372 ++++++++++++++++++++++++++++++++++++++++-------- bsd-user/qemu.h | 5 +- 3 files changed, 335 insertions(+), 65 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 93ef9298b8..36852604f8 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -49,12 +49,29 @@ #include "target_arch_cpu.h" int singlestep; -unsigned long mmap_min_addr; uintptr_t guest_base; static const char *cpu_model; static const char *cpu_type; bool have_guest_base; +#if (TARGET_LONG_BITS == 32) && (HOST_LONG_BITS == 64) +/* + * 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 stack + * or anything else that QEMU maps. + */ +# ifdef TARGET_MIPS +/* MIPS only supports 31 bits of virtual address space for user space */ +unsigned long reserved_va = 0x77000000; +# elif defined(TARGET_PPC64) +unsigned long reserved_va = 0xfffff000; +# else +unsigned long reserved_va = 0xf7000000; +# endif +#else unsigned long reserved_va; +#endif static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; @@ -399,6 +416,10 @@ int main(int argc, char **argv) target_environ = envlist_to_environ(envlist, NULL); envlist_free(envlist); + if (reserved_va) { + mmap_next_start = reserved_va; + } + /* * Now that page sizes are configured we can do * proper page alignment for guest_base. diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 99563d61aa..07e985b0c5 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -188,64 +188,191 @@ static int mmap_frag(abi_ulong real_start, return 0; } -static abi_ulong mmap_next_start = 0x40000000; +#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 +# define TASK_UNMAPPED_BASE (1ul << 38) +#else +# define TASK_UNMAPPED_BASE 0x40000000 +#endif +abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; unsigned long last_brk; -/* find a free memory area of size 'size'. The search starts at - 'start'. If 'start' == 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; - - new_brk = (unsigned long)sbrk(0); - if (last_brk && last_brk < new_brk && last_brk == (target_ulong)last_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); + int looped = 0; + + if (size > reserved_va) { + return (abi_ulong)-1; + } + + size = HOST_PAGE_ALIGN(size) + alignment; + end_addr = start + size; + if (end_addr > reserved_va) { + end_addr = reserved_va; + } + addr = end_addr - qemu_host_page_size; + + while (1) { + if (addr > end_addr) { + if (looped) { + return (abi_ulong)-1; + } + end_addr = reserved_va; + addr = end_addr - qemu_host_page_size; + looped = 1; + continue; + } + prot = page_get_flags(addr); + if (prot) { + end_addr = addr; + } + if (end_addr - addr >= size) { + break; + } + addr -= qemu_host_page_size; + } + + if (start == mmap_next_start) { + mmap_next_start = addr; + } + /* addr is sufficiently low to align it up */ + if (alignment != 0) + addr = (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' == 0, then a default start address is used. */ + if (start == 0) { + start = mmap_next_start; + } else { + start &= qemu_host_page_mask; } - last_brk = new_brk; size = HOST_PAGE_ALIGN(size); - start = start & qemu_host_page_mask; + + if (reserved_va) { + return mmap_find_vma_reserved(start, size, + (alignment != 0 ? 1 << alignment : 0)); + } + addr = start; - if (addr == 0) - addr = mmap_next_start; - addr_start = addr; - for (;;) { - prot = 0; - for (addr1 = addr; addr1 < (addr + size); addr1 += TARGET_PAGE_SIZE) { - prot |= page_get_flags(addr1); + wrapped = repeat = 0; + prev = 0; + flags = MAP_ANONYMOUS|MAP_PRIVATE; +#ifdef MAP_ALIGNED + if (alignment != 0) + flags |= MAP_ALIGNED(alignment); +#else + /* XXX TODO */ +#endif + + for (;; prev = 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 = mmap(g2h_untagged(addr), size, PROT_NONE, + flags, -1, 0); + + /* ENOMEM, if host address space has no memory */ + if (ptr == MAP_FAILED) { + return (abi_ulong)-1; } - if (prot == 0) - break; - addr += qemu_host_page_size; - /* we found nothing */ - if (addr == addr_start) + + /* Count the number of sequential returns of the same address. + This is used to modify the search algorithm below. */ + repeat = (ptr == prev ? repeat + 1 : 0); + + if (h2g_valid(ptr + size - 1)) { + addr = h2g(ptr); + + if ((addr & ~TARGET_PAGE_MASK) == 0) { + /* Success. */ + if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) { + mmap_next_start = 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 = TARGET_PAGE_ALIGN(addr); + break; + case 1: + /* Sometimes the kernel decides to perform the allocation + at the top end of memory instead. */ + addr &= TARGET_PAGE_MASK; + break; + case 2: + /* Start over at low memory. */ + addr = 0; + break; + default: + /* Fail. This unaligned block must the last. */ + addr = -1; + break; + } + } else { + /* Since the result the kernel gave didn't fit, start + again at low memory. If any repetition, fail. */ + addr = (repeat ? -1 : 0); + } + + /* Unmap and try again. */ + munmap(ptr, size); + + /* ENOMEM if we checked the whole of the target address space. */ + if (addr == (abi_ulong)-1) { + return (abi_ulong)-1; + } else if (addr == 0) { + if (wrapped) { + return (abi_ulong)-1; + } + wrapped = 1; + /* Don't actually use 0 when wrapping, instead indicate + that we'd truly like an allocation in low memory. */ + addr = TARGET_PAGE_SIZE; + } else if (wrapped && addr >= start) { return (abi_ulong)-1; + } } - if (start == 0) - mmap_next_start = addr + size; - return addr; +} + +abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) +{ + return mmap_find_vma_aligned(start, size, 0); } /* 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_len; - unsigned long host_start; mmap_lock(); #ifdef DEBUG_MMAP @@ -284,43 +411,112 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, } #endif + if ((flags & MAP_ANONYMOUS) && fd != -1) { + errno = EINVAL; + goto fail; + } +#ifdef MAP_STACK + if (flags & MAP_STACK) { + if ((fd != -1) || ((prot & (PROT_READ | PROT_WRITE)) != + (PROT_READ | PROT_WRITE))) { + errno = EINVAL; + goto fail; + } + } +#endif /* MAP_STACK */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200035 + if ((flags & MAP_GUARD) && (prot != PROT_NONE || fd != -1 || + offset != 0 || (flags & (MAP_SHARED | MAP_PRIVATE | /* MAP_PREFAULT | */ /* MAP_PREFAULT not in mman.h */ + MAP_PREFAULT_READ | MAP_ANON | MAP_STACK)) != 0)) { + errno = EINVAL; + goto fail; + } +#endif + if (offset & ~TARGET_PAGE_MASK) { errno = EINVAL; goto fail; } len = TARGET_PAGE_ALIGN(len); - if (len == 0) - goto the_end; + if (len == 0) { + errno = EINVAL; + goto fail; + } real_start = start & qemu_host_page_mask; + host_offset = offset & qemu_host_page_mask; + /* 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 = offset & qemu_host_page_mask; host_len = len + offset - host_offset; host_len = HOST_PAGE_ALIGN(host_len); - mmap_start = mmap_find_vma(real_start, host_len); - if (mmap_start == (abi_ulong)-1) { + if ((flags & MAP_ALIGNMENT_MASK) != 0) + start = mmap_find_vma_aligned(real_start, host_len, + (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); + else + start = mmap_find_vma(real_start, host_len); + if (start == (abi_ulong)-1) { errno = ENOMEM; goto fail; } + } + + /* 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 != -1) { + struct stat sb; + + if (fstat(fd, &sb) == -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 = REAL_HOST_PAGE_ALIGN(sb.st_size - offset); + } + } + + if (!(flags & MAP_FIXED)) { + unsigned long host_start; + void *p; + + host_len = len + offset - host_offset; + host_len = 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 = mmap(g2h_untagged(mmap_start), - host_len, prot, flags | MAP_FIXED, fd, host_offset); + p = mmap(g2h_untagged(start), host_len, prot, + flags | MAP_FIXED | ((fd != -1) ? MAP_ANONYMOUS : 0), -1, 0); if (p == MAP_FAILED) goto fail; /* update start so that it points to the file position at 'offset' */ host_start = (unsigned long)p; - if (!(flags & MAP_ANON)) + if (fd != -1) { + p = mmap(g2h_untagged(start), len, prot, + flags | MAP_FIXED, fd, host_offset); + if (p == MAP_FAILED) { + munmap(g2h_untagged(start), host_len); + goto fail; + } host_start += offset - host_offset; + } start = h2g(host_start); } else { - int flg; - target_ulong addr; - if (start & ~TARGET_PAGE_MASK) { errno = EINVAL; goto fail; @@ -328,13 +524,17 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, end = start + len; real_end = HOST_PAGE_ALIGN(end); - for (addr = real_start; addr < real_end; addr += TARGET_PAGE_SIZE) { - flg = page_get_flags(addr); - if (flg & PAGE_RESERVED) { - errno = 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 correctly. + */ +#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 + if ((unsigned long)start + len - 1 > (abi_ulong) -1) { + errno = EINVAL; + goto fail; } +#endif /* worst case: we cannot map the file because the offset is not aligned, so we read it */ @@ -382,7 +582,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, /* handle the end of the mapping */ if (end < real_end) { ret = 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 - start); if (ret == -1) @@ -412,6 +612,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, page_dump(stdout); printf("\n"); #endif + tb_invalidate_phys_range(start, start + len); mmap_unlock(); return start; fail: @@ -419,6 +620,47 @@ fail: return -1; } +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 = start & qemu_host_page_mask; + real_end = HOST_PAGE_ALIGN(start + size); + end = start + size; + if (start > real_start) { + /* handle host page containing start */ + prot = 0; + for (addr = real_start; addr < start; addr += TARGET_PAGE_SIZE) { + prot |= page_get_flags(addr); + } + if (real_end == real_start + qemu_host_page_size) { + for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { + prot |= page_get_flags(addr); + } + end = real_end; + } + if (prot != 0) + real_start += qemu_host_page_size; + } + if (end < real_end) { + prot = 0; + for (addr = end; addr < real_end; addr += TARGET_PAGE_SIZE) { + prot |= page_get_flags(addr); + } + if (prot != 0) + real_end -= qemu_host_page_size; + } + if (real_start != 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; @@ -466,11 +708,17 @@ int target_munmap(abi_ulong start, abi_ulong len) ret = 0; /* unmap what we can */ if (real_start < real_end) { - ret = munmap(g2h_untagged(real_start), real_end - real_start); + if (reserved_va) { + mmap_reserve(real_start, real_end - real_start); + } else { + ret = munmap(g2h_untagged(real_start), real_end - real_start); + } } - if (ret == 0) + if (ret == 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 bfd7b8eaa5..a85abb8fe1 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -104,7 +104,6 @@ typedef struct TaskState { void init_task_state(TaskState *ts); extern const char *qemu_uname_release; -extern unsigned long mmap_min_addr; /* * TARGET_ARG_MAX defines the number of bytes allocated for arguments @@ -212,13 +211,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); From patchwork Sat Aug 7 21:42:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=LMrS5v4p; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxMR1jPvz9sWX for ; Sun, 8 Aug 2021 08:09:07 +1000 (AEST) Received: from localhost ([::1]:54392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUV6-0002NO-Vl for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:09:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6O-0008PO-Us for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:32 -0400 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]:46046) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6N-0005KP-Ij for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:32 -0400 Received: by mail-io1-xd31.google.com with SMTP id e186so17979404iof.12 for ; Sat, 07 Aug 2021 14:43:31 -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=va1ltaQnDQahwRJKm8S9pyEvLkuFSkPE295Tlhm8C0M=; b=LMrS5v4pHu5RN4wG7VAaJlSOPwUhvKhfB4BNUNOw7KCi3RISyKKV/0SMWLEXZB4b9k PQUPt6ba8JyIrHFQPDzm+xyPqUtxxyOP1n4KSeb1R+J+n8Dj/YGR6e3gWrUduuzxRnZy 7rUE0zlo7ylY+Z3EtZd6qEO5cIywFFXnNxaXBmkhRhQg+e73p0/JkMtgy1kj1zAPswUA gTG4pydl73GwHxQ6bMcEhtmNvfb4hqSj21XVbq2N6yKM3eOdM/10r0yiUzGn1Hj0g4Og 9K1h1cFAeGnYwmdK1FDCGIFEQCnDnNL7TKnKE8eP9ioIzQdMNqVrkHEH9uNIbnCPEQjK L77Q== 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=va1ltaQnDQahwRJKm8S9pyEvLkuFSkPE295Tlhm8C0M=; b=m2lB4YL3G+WkFSw7R2AxELDoxiKCW+tedCNRMqaUAHMfsTtH5p4NJSSr7WYjlTBkv/ 8jGFNsND0rrju8U97e5QtZmeIEl5EpushTPWIxREx5ElnAvQmk8RNV/FPQI/c9DEMFwY +n4gcwi9kzLcn8RpKnyQLncjQ6RxfPfzlLcbN4jgRE3RYUoSa2qDpCC0szUBJnLcy23J L+jF1FetDShyV3HHwHDo+cnntC48bSUcC/F0M9CDvu8PATZWt67jMkguwBN3unvCRELf SM2MHwkzKm6BgEfzMcntj6s8P4AhHPvBD8Gm96ife1co3imHeXCw0ji256BNLPtrCZMD FgGg== X-Gm-Message-State: AOAM532t3Jq6npeqPoCrEdWapCDJ+PLxO3aCm9O9OCQLoimnh/pYyd9y 09b3rGx4xVf8Owjmv+FmdREq8bmnTfOZniA4 X-Google-Smtp-Source: ABdhPJzJc6hsnsdrwxgxQsOWplVofzyxW0Dx0VYswh1VtjMtd7VtdJMkJXvTCJVv52rOiZlkY85OfQ== X-Received: by 2002:a05:6638:303:: with SMTP id w3mr8492566jap.79.1628372610265; Sat, 07 Aug 2021 14:43:30 -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 a17sm8062827ios.36.2021.08.07.14.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:29 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 39/49] bsd-user: Need to reset CPU after creation. Date: Sat, 7 Aug 2021 15:42:32 -0600 Message-Id: <20210807214242.82385-40-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 36852604f8..08f88d9668 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -405,8 +405,10 @@ int main(int argc, char **argv) accel_init_interfaces(ac); ac->init_machine(NULL); } + cpu = cpu_create(cpu_type); env = cpu->env_ptr; + cpu_reset(cpu); thread_cpu = cpu; if (getenv("QEMU_STRACE")) { From patchwork Sat Aug 7 21:42:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=gdwMSVCM; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghwzc6Q52z9sWX for ; Sun, 8 Aug 2021 07:51:56 +1000 (AEST) Received: from localhost ([::1]:45494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUEU-00088s-Jn for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:51:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6R-00006t-Cj for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:35 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]:33433) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6O-0005N3-GN for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:35 -0400 Received: by mail-io1-xd44.google.com with SMTP id n19so20056589ioz.0 for ; Sat, 07 Aug 2021 14:43:32 -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=+TkPtqaplXXdM8u31B/ooyNVIvnQ5JDMIlJ4xfG4jD8=; b=gdwMSVCMYhf1tDl8G7y3CZxFsk5KQARuoaUw0mTFNFiz3rEwJMF2XnOtMa/DB3EXpI GhoQv49XkdtkAI9jz2wpCItEzNBPrDOhbhEveKQywNWTNrrWRAaIfo5bu5oX9DsGvtFT TBlReRZi4aQaKD90eMrd6RIO8KTWoTVsBcr4myFOe41fuEbsFodXENL7vkb3CGPSakGz PbkfOCMCAvxzh4FA1fuCuNUW1MYWB27XfX258cdHpFco2oExv3AXz394hlJpFkYFLdge bPwhxvHmWoT8LcKPQfEyo2Dg6PpvgwbpU2iWW2UUXvs4aVeQQW6c2ngxOHvQ4Dzy3pRQ JBtQ== 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=+TkPtqaplXXdM8u31B/ooyNVIvnQ5JDMIlJ4xfG4jD8=; b=UOpUlPy9rGsW1QVHPjkIVfQrjt+8t2nok6MrJNSIPpUF0eVr/UfO4mVl6xE6QPTxls JYJKtyNIQC8dWZgeoWqVrYfBFwaX4U7jBFOQZz0Zc8J4bmX//nk8/UguIf+uYcCvdjAV Qp+iQ7ETcPrfCp8e6OcTG+IJrRF3I0+aqO56nCquxF0bzsSs9iAqPjgR3+jqABQAgA4w GsYOc6MV6hYWrr+GOmC6rXFhj8p2uypWjEFAQZUakSTaxTqtdxkrOchdMK0Nh6k5be/w wlW+VPipN0MF4xnmXyi2UUApkN8DM82LvTQToa2zPRSQLmADhLCPhPNmPgpHY6GTIea/ amKg== X-Gm-Message-State: AOAM533sYxzy3TiS5ME7fvGhSX6LchmottImvMmFZ46QhRiIAyDK1SFy HiznRU+Nom7ixfMW0NmZEr50JpXdcyBcHpG8 X-Google-Smtp-Source: ABdhPJyArIm9QHSy+KDIkAcrmVxiWolz/p4/SlF+8YhiV6MIFxzhL3Ce9c8F3RQ5IVS6gaEpiyMo4Q== X-Received: by 2002:a05:6638:306:: with SMTP id w6mr15615233jap.132.1628372611262; Sat, 07 Aug 2021 14:43:31 -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 a17sm8062827ios.36.2021.08.07.14.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:30 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 40/49] bsd-user: Add target_arch_reg to describe a target's register set Date: Sat, 7 Aug 2021 15:42:33 -0600 Message-Id: <20210807214242.82385-41-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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_reg.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 = env->segs[R_FS].selector & 0xffff; + regs->r_es = env->segs[R_ES].selector & 0xffff; + regs->r_ds = env->segs[R_DS].selector & 0xffff; + + regs->r_edi = env->regs[R_EDI]; + regs->r_esi = env->regs[R_ESI]; + regs->r_ebp = env->regs[R_EBP]; + /* regs->r_isp = env->regs[R_ISP]; XXX */ + regs->r_ebx = env->regs[R_EBX]; + regs->r_edx = env->regs[R_EDX]; + regs->r_ecx = env->regs[R_ECX]; + regs->r_eax = env->regs[R_EAX]; + /* regs->r_trapno = env->regs[R_TRAPNO]; XXX */ + regs->r_err = env->error_code; /* XXX ? */ + regs->r_eip = env->eip; + + regs->r_cs = env->segs[R_CS].selector & 0xffff; + + regs->r_eflags = env->eflags; + regs->r_esp = env->regs[R_ESP]; + + regs->r_ss = env->segs[R_SS].selector & 0xffff; + regs->r_gs = 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_arch_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 = env->regs[15]; + regs->r_r14 = env->regs[14]; + regs->r_r13 = env->regs[13]; + regs->r_r12 = env->regs[12]; + regs->r_r11 = env->regs[11]; + regs->r_r10 = env->regs[10]; + regs->r_r9 = env->regs[9]; + regs->r_r8 = env->regs[8]; + regs->r_rdi = env->regs[R_EDI]; + regs->r_rsi = env->regs[R_ESI]; + regs->r_rbp = env->regs[R_EBP]; + regs->r_rbx = env->regs[R_EBX]; + regs->r_rdx = env->regs[R_EDX]; + regs->r_rcx = env->regs[R_ECX]; + regs->r_rax = env->regs[R_EAX]; + /* regs->r_trapno = env->regs[R_TRAPNO]; XXX */ + regs->r_fs = env->segs[R_FS].selector & 0xffff; + regs->r_gs = env->segs[R_GS].selector & 0xffff; + regs->r_err = env->error_code; /* XXX ? */ + regs->r_es = env->segs[R_ES].selector & 0xffff; + regs->r_ds = env->segs[R_DS].selector & 0xffff; + regs->r_rip = env->eip; + regs->r_cs = env->segs[R_CS].selector & 0xffff; + regs->r_rflags = env->eflags; + regs->r_rsp = env->regs[R_ESP]; + regs->r_ss = env->segs[R_SS].selector & 0xffff; +} + +#endif /* !_TARGET_ARCH_REG_H_ */ From patchwork Sat Aug 7 21:42:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=sYguo8Af; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxM91fKKz9sWX for ; Sun, 8 Aug 2021 08:08:53 +1000 (AEST) Received: from localhost ([::1]:53110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUUs-0001Y9-TP for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:08:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6S-00008E-5n for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:36 -0400 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]:45765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6P-0005PY-MT for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:35 -0400 Received: by mail-io1-xd41.google.com with SMTP id e186so17979529iof.12 for ; Sat, 07 Aug 2021 14:43:33 -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=WLQPaOs/DOZufIV5gvyQZTRg7t28xl8QQf/KMW1vycg=; b=sYguo8Afds5j21pyACTUnWnemT0WftKMJ0m7tcHKXF6eitAU7zoe7XL66IAuUd3v2Y yHDTN+vXJDtJMnKfUf/ZyIVVnjVw1Ekh95JQLVEILPjS/jGXhH7QtbUFLIZDyILBRF2z VIMM0zC6SqMR/DlG3lmBxrqMsNlXwoj/d1CocrYGlEKOFIs98TuIKkFpV6JLVSO0dNv7 vDVUXPMNQbvOCd+GnsP/aQA7xYnt545IdH/zBQn8Ehgi7Q9XOr98qZgJoY/kgczxfzR9 IN0hSIZ499vDWORx9kwoP6XkV892Of6xg3VfGKGJT+P7a28bhsUnr0Gwxi62ILhENaPz UbOQ== 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=WLQPaOs/DOZufIV5gvyQZTRg7t28xl8QQf/KMW1vycg=; b=R1wiT8uKb+7R9tbBEyQr+vBcs7JwoQOZMjBv0O7vBuy/F1bbihULjzJvPyG+Z5tekW Mf/Gkw25tRzYai8QE+z4seHgNtRnMNQv/jHgBrkCgUIOJ0lETxiSIqr+wPvbszKikrf8 HkpfdsppOjkVQDjtfnXh6mq+1uSKEhBrGvAxtjpwRUQ+UQL40yxbTGiDzOGz5su5uaiy 3B+3GdAdmOwKU1IBpHMF3m/MlDrRIXwXgjIJRPC8XqRKAoabyzYaI3WjGKcFn2PWpwKU oVs4tRgM45yVfhpOdJ8lYHXX689CKD0XB1+GVKi6MdhPRD49U9oehGWBAUyBk+DMNFHN aFkw== X-Gm-Message-State: AOAM530QVw4MPu9Jomn2Gug9lCPawTGBTYnfYNu9K4X951rZQ0zxpw1k S3JvpJJBVEvqzl9yY4L/s4Y0EA8+fza83+mX X-Google-Smtp-Source: ABdhPJyjTAhn6WkzeTzrVLNl19kf0bTNslZ9xq7iP1Ge9n0tePV+2kTmoC9Y+N4uGLxnVlNlo08uAw== X-Received: by 2002:a02:c98b:: with SMTP id b11mr15876764jap.58.1628372612372; Sat, 07 Aug 2021 14:43:32 -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 a17sm8062827ios.36.2021.08.07.14.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:31 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 41/49] bsd-user: Add target_os_user.h to capture the user/kernel structures Date: Sat, 7 Aug 2021 15:42:34 -0600 Message-Id: <20210807214242.82385-42-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Michal Meloun , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- bsd-user/freebsd/target_os_user.h | 429 ++++++++++++++++++++++++++++++ 1 file changed, 429 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..a265e02439 --- /dev/null +++ b/bsd-user/freebsd/target_os_user.h @@ -0,0 +1,429 @@ +/* + * 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 >= 1200031 +#define TARGET_KI_NSPARE_INT 2 +#elif defined(__FreeBSD_version) && __FreeBSD_version >= 1100000 +#define TARGET_KI_NSPARE_INT 4 +#elif defined(__FreeBSD_version) && __FreeBSD_version >= 1000000 +#define TARGET_KI_NSPARE_INT 7 +#else +#define TARGET_KI_NSPARE_INT 9 +#endif /* ! __FreeBSD_version >= 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 >= 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 + children */ + + 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 >= 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 >= 1100000 */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000 + char ki_tdname[TARGET_TDNAMLEN+1]; /* thread name */ +#else + char ki_ocomm[TARGET_TDNAMLEN+1]; /* thread name */ +#endif /* ! __FreeBSD_version >= 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 >= 900000 + char ki_loginclass[TARGET_LOGINCLASSLEN+1]; /* login class */ +#endif /* ! __FreeBSD_version >= 900000 */ + +#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000 + char ki_sparestrings[50]; /* spare string space */ +#else + char ki_sparestrings[68]; /* spare string space */ +#endif /* ! __FreeBSD_version >= 900000 */ + int32_t ki_spareints[TARGET_KI_NSPARE_INT]; /* spare room for growth */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1200031 + uint64_t ki_tdev; /* controlling tty dev */ +#endif +#if defined(__FreeBSD_version) && __FreeBSD_version >= 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 >= 1100000 */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000 + int32_t ki_flag2; /* P2_* flags */ + int32_t ki_fibnum; /* Default FIB number */ +#endif /* ! __FreeBSD_version >= 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 + processes */ + + + 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 growth */ + abi_long ki_sparelongs[TARGET_KI_NSPARE_LONG];/* spare room for growth */ + 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 >= 900000 + union { + struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >= 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 >= 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 >= 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 >= 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 >= 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 >= 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 >= 1000000 + target_cap_rights_t kf_cap_rights; /* Capability rights. */ + uint64_t _kf_cap_spare; /* Space for future cap_rights_t. */ +#else /* ! __FreeBSD_version >= 1000000 */ + uint64_t kf_cap_rights; + int _kf_ispare[4]; +#endif /* ! __FreeBSD_version >= 1000000 */ + +#else /* ! __FreeBSD_version >= 900000 */ + int _kf_ispare[16]; +#endif /* ! __FreeBSD_version >= 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 >= 900000 + uint64_t kve_vn_fileid; /* inode number if vnode */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 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 >= 900000 */ + uint64_t kve_fileid; /* inode number if vnode */ + uint32_t kve_fsid; /* dev_t of vnode location */ +#endif /* ! __FreeBSD_version >= 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 >= 900000 + int32_t kve_vn_type; /* Vnode type. */ + uint64_t kve_vn_size; /* File size. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >= 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 >= 1200031 +#if (__FreeBSD_version >= 1300501 && __FreeBSD_version < 1400000) || \ + __FreeBSD_version >= 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 >= 900000 */ + int _kve_pad0; + int32_t _kve_ispare[16]; /* Space for more stuff. */ +#endif /* ! __FreeBSD_version >= 900000 */ + /* Truncated before copyout in sysctl */ + char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ +}; + +#endif /* ! _TARGET_OS_USER_H_ */ From patchwork Sat Aug 7 21:42:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=Jxsv0AT+; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx8r1CGTz9sWX for ; Sun, 8 Aug 2021 07:59:54 +1000 (AEST) Received: from localhost ([::1]:52416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUMB-0007P6-3A for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:59:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6R-00008D-T6 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:36 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:37720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6Q-0005Pp-Ci for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:35 -0400 Received: by mail-io1-xd36.google.com with SMTP id l20so17749618iom.4 for ; Sat, 07 Aug 2021 14:43:34 -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=BZUIjC8fUpD63sq4WTQh3jNXrXunBjaoQkdXkjk1BIE=; b=Jxsv0AT+/8KJIxmrnfs8ZZQXcOqOvox/jkk3v+n21zqFQebnSuFPa50BWMnb+JlFc8 +R4vG1bIoazryICo/ItkPBnlUq3D0KN2/nw4ZBadOQXh1HkMfh/7moLkInZBQqCmQR7d yXW+XLxu/h30pF/vYB5+NsNSvxJLtqxkfFub3b/Xjr0FLC3C6ErN6y5tDpz/03ul9H/J A9mXUISEklUC0w7pVD6cpNVWUGUNUJjxBThSTOmMLM2vUAbbt9ZpZIfMzMHRws/OhbeR kL6VHsNzMlCiYLb7zOdCT1UvIuR/xgjXyhUZ8weXLz68bMep6X+EPJvlniyYR8fMBUGv LfPw== 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=BZUIjC8fUpD63sq4WTQh3jNXrXunBjaoQkdXkjk1BIE=; b=oxqADOWa7ncmXu7ZZNibcslPrIvYy14EaYVaDWNp+j42KvgsMb1yv+Cv+Q2PBuq86a 7ECX17q2Jmx0+nrfd/w/1412VlEPVdigHsc25pKvMIYn6h2FdkjsTUw8QJQiidHaWtJn 97Q7ndHJltCfdmXNtunqkECrcGTGzTvuWNFqhQU2bYRbaL7PX0rmvxk9gfCrM29oGKlz vmflXnmNr/KDTu2rNbch5XTPyfSJnXdRWlw3XETQsOrxF+uXL16TYfZRTpmmyq8BYB/c DtrIPVxVeMpPeOmeZE7MLt2gizkUNUrIipwAGme7juFDIqt72IfkjdwKiffFckmMgg+C e2eQ== X-Gm-Message-State: AOAM532+SpwwjYc3AA/tXdPgVQm7geiV2T+zPqNEx6RyxzjWSskWPFeJ oSUMUHQlXe9dmjH/q15syqgUwX9JCzEslcGG X-Google-Smtp-Source: ABdhPJwxFbjWS8F/+b/5HBmg6qCeQiIw9UPrb+CNF6RLu3hY8/fXxIuozx+uf4EblCDvQ44k5CamTw== X-Received: by 2002:a02:6c8d:: with SMTP id w135mr15517994jab.70.1628372613287; Sat, 07 Aug 2021 14:43:33 -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 a17sm8062827ios.36.2021.08.07.14.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:32 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 42/49] bsd-user: add stubbed out core dump support Date: Sat, 7 Aug 2021 15:42:35 -0600 Message-Id: <20210807214242.82385-43-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Sponsored by: Netflix Reviewed-by: Richard Henderson --- bsd-user/elfcore.c | 10 ++++++++++ bsd-user/elfload.c | 24 ++++++++++++++++++++++-- bsd-user/qemu.h | 6 ++++++ 3 files changed, 38 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..e3c161942d --- /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; + + bswap_note(&en); + + return 0; +} diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index c0787a4e52..4390a88b07 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -26,15 +26,19 @@ static abi_ulong target_auxents; /* Where the AUX entries are in target */ static size_t target_auxents_sz; /* Size of AUX entries including AT_NULL */ +#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" abi_ulong target_stksiz; abi_ulong target_stkbas; +static int elf_core_dump(int signr, CPUArchState *env); +static int load_elf_sections(const struct elfhdr *hdr, struct elf_phdr *phdr, + int fd, abi_ulong rbase, abi_ulong *baddrp); + static inline void memcpy_fromfs(void *to, const void *from, unsigned long n) { memcpy(to, from, n); @@ -100,15 +104,25 @@ static void bswap_sym(struct elf_sym *sym) bswap16s(&sym->st_shndx); } +static void bswap_note(struct elf_note *en) +{ + bswap32s(&en->n_namesz); + bswap32s(&en->n_descsz); + bswap32s(&en->n_type); +} + #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) { } +static void bswap_note(struct elf_note *en) { } #endif /* ! BSWAP_NEEDED */ +#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 @@ -833,6 +847,12 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, info->entry = elf_entry; +#ifdef USE_ELF_CORE_DUMP + bprm->core_dump = &elf_core_dump; +#else + bprm->core_dump = NULL; +#endif + return 0; } diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index a85abb8fe1..b2b7c3b29a 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -54,6 +54,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; @@ -68,6 +69,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; }; #define MAX_SIGQUEUE_SIZE 1024 @@ -134,6 +138,7 @@ struct bsd_binprm { char **envp; char *filename; /* (Given) Name of binary */ char *fullpath; /* Full path of binary */ + int (*core_dump)(int, CPUArchState *); }; void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); @@ -147,6 +152,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_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); abi_long memcpy_to_target(abi_ulong dest, const void *src, unsigned long len); From patchwork Sat Aug 7 21:42:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=G3vTb1ZA; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx1k49fbz9sWX for ; Sun, 8 Aug 2021 07:53:46 +1000 (AEST) Received: from localhost ([::1]:54188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUGG-0005w6-6h for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:53:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6T-0000DP-Rw for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:38 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:34519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6R-0005Qz-KJ for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:37 -0400 Received: by mail-io1-xd36.google.com with SMTP id i7so13720374iow.1 for ; Sat, 07 Aug 2021 14:43:35 -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=/Ug3NZMWJI2xxYo8zzVx/7Pjb6S3ws5w5seZva8xT8k=; b=G3vTb1ZALW8sI9+fyJW8q4gFt5aIteo80CGPyaLLRH+0kRyIIXPgjuZ935WpypBGki AI4f94edkTZORO28NVFMT7qfN8raA4+Sqy/z/qZvkYyXMkRTjlMr5M4PzrV4u71ccQBX 2tAKG4wXypenpTpzMOoVPXVb+0F3DjAJztBWxfr94hS/Hjq5uhlniOgs0TgpNkDJEF89 hZwOs3Ckm2rLd2CawO7AlqmuukZMXP7IpnyCzP3ynbp4wD3KtdZ3q4Mt0YxgFBxgFiBY ma1q0gfGi5FohSbyAOeq16sW48eEJymk63zDYxAhdGW5YXY6Mjpo+ttxuyaJjkifb1Th /QVg== 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=/Ug3NZMWJI2xxYo8zzVx/7Pjb6S3ws5w5seZva8xT8k=; b=R8DHMLPsmRCNPpLhZdNnPOIDcB5P6ZRt9KHnRPlnfIjeerw+C6l3Qt2abkiDmxTksK THCBYw+JbY3zJgYaIKGVBzIRqKDtrRoHaJ/FJh5By9Mg++aJSetUsu3wm+j3TITMuaC6 tyvO1Y3QQ9rGNKZ+y8Tj4VT5AunSex1eZ3FCqIyncprfc0SmWXLkxDqFHzxbmw4SgXJz IlPrdpxWFUj7+vaSi+BhMSaGxtqufQfAvD0Qw6mnPxkYUw+0aBKuiyvhI+GXV56euTIn PjAg+n4/FZ7mWASSnedB0nhVXFtstk5Zie7e+pF1mdXifZ8kwLsfbhk+f0Gxk6uYpmi+ 7etA== X-Gm-Message-State: AOAM531q27T+u/y/p2OI0QOCb99Goi6OhyUan4OR7QY4QZfzMpgaZ7ig 9EoN1Vk2DUTQdhy/ZQtxwkNnbHqro76JHrg8 X-Google-Smtp-Source: ABdhPJwYbltIOo7lmp7iezD1Cjg2lSN4zl07nAC1iCGKu/yxWyChlpsr8bJifzGCDoeWUzrglB7sbQ== X-Received: by 2002:a05:6638:1513:: with SMTP id b19mr16159016jat.109.1628372614350; Sat, 07 Aug 2021 14:43:34 -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 a17sm8062827ios.36.2021.08.07.14.43.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:33 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 43/49] bsd-user: elfload.c style catch up patch Date: Sat, 7 Aug 2021 15:42:36 -0600 Message-Id: <20210807214242.82385-44-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Various style fixes to elfload.c that were too painful to make earlier in this series. Signed-off-by: Warner Losh Sponsored by: Netflix Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 212 ++++++++++++++++++++++----------------------- 1 file changed, 105 insertions(+), 107 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 4390a88b07..bdf18f3dce 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -36,8 +36,6 @@ abi_ulong target_stksiz; abi_ulong target_stkbas; static int elf_core_dump(int signr, CPUArchState *env); -static int load_elf_sections(const struct elfhdr *hdr, struct elf_phdr *phdr, - int fd, abi_ulong rbase, abi_ulong *baddrp); static inline void memcpy_fromfs(void *to, const void *from, unsigned long n) { @@ -145,10 +143,12 @@ static abi_ulong copy_elf_strings(int argc, char **argv, void **page, exit(-1); } tmp1 = tmp; - while (*tmp++); + while (*tmp++) { + continue; + } len = tmp - tmp1; if (p < len) { /* this shouldn't happen - 128kB */ - return 0; + return 0; } while (len) { --p; --tmp; --len; @@ -158,14 +158,14 @@ static abi_ulong copy_elf_strings(int argc, char **argv, void **page, if (!pag) { pag = g_try_malloc0(TARGET_PAGE_SIZE); page[p / TARGET_PAGE_SIZE] = pag; - if (!pag) + if (!pag) { return 0; + } } } if (len == 0 || offset == 0) { *(pag + offset) = *tmp; - } - else { + } else { int bytes_to_copy = (len > offset) ? offset : len; tmp -= bytes_to_copy; p -= bytes_to_copy; @@ -184,16 +184,14 @@ static void setup_arg_pages(struct bsd_binprm *bprm, struct image_info *info, abi_ulong stack_base, size; abi_long addr; - /* 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 args, + * we'll use it for something else... */ size = target_dflssiz; stack_base = TARGET_USRSTACK - size; - addr = target_mmap(stack_base, - size + qemu_host_page_size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANON, - -1, 0); + addr = target_mmap(stack_base , size + qemu_host_page_size, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (addr == -1) { perror("stk mmap"); exit(-1); @@ -212,55 +210,60 @@ static void setup_arg_pages(struct bsd_binprm *bprm, struct image_info *info, static void set_brk(abi_ulong start, abi_ulong end) { - /* page-align the start and end addresses... */ - start = HOST_PAGE_ALIGN(start); - end = HOST_PAGE_ALIGN(end); - if (end <= start) - return; - if (target_mmap(start, end - start, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) { - perror("cannot mmap brk"); - exit(-1); - } + /* page-align the start and end addresses... */ + start = HOST_PAGE_ALIGN(start); + end = HOST_PAGE_ALIGN(end); + if (end <= start) { + return; + } + if (target_mmap(start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) { + perror("cannot mmap brk"); + exit(-1); + } } -/* 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; - if (elf_bss >= last_bss) - return; + if (elf_bss >= last_bss) { + return; + } - /* 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 = REAL_HOST_PAGE_ALIGN(elf_bss); - end_addr = 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 = REAL_HOST_PAGE_ALIGN(elf_bss); + end_addr = 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); } + } - nbyte = elf_bss & (qemu_host_page_size - 1); - if (nbyte) { - nbyte = 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 = elf_bss & (qemu_host_page_size - 1); + if (nbyte) { + nbyte = qemu_host_page_size - nbyte; + do { + /* FIXME - what to do if put_user() fails? */ + put_user_u8(0, elf_bss); + elf_bss++; + } while (--nbyte); + } } static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, @@ -282,23 +285,23 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, bswap_ehdr(interp_elf_ex); /* First of all, some simple consistency checks */ - if ((interp_elf_ex->e_type != ET_EXEC && - interp_elf_ex->e_type != ET_DYN) || - !elf_check_arch(interp_elf_ex->e_machine)) { + if ((interp_elf_ex->e_type != ET_EXEC && interp_elf_ex->e_type != ET_DYN) || + !elf_check_arch(interp_elf_ex->e_machine)) { return ~((abi_ulong)0UL); } /* Now read in all of the header information */ - - if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE) + if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE) { return ~(abi_ulong)0UL; + } - elf_phdata = (struct elf_phdr *) - malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); + elf_phdata = (struct elf_phdr *) malloc(sizeof(struct elf_phdr) * + interp_elf_ex->e_phnum); - if (!elf_phdata) + if (!elf_phdata) { return ~((abi_ulong)0UL); + } /* * If the size of this structure has changed, then punt, since @@ -311,9 +314,8 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, retval = lseek(interpreter_fd, interp_elf_ex->e_phoff, SEEK_SET); if (retval >= 0) { - retval = read(interpreter_fd, - (char *) elf_phdata, - sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); + retval = read(interpreter_fd, (char *) elf_phdata, + sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); } if (retval < 0) { perror("load_elf_interp"); @@ -324,11 +326,12 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, bswap_phdr(elf_phdata, interp_elf_ex->e_phnum); if (interp_elf_ex->e_type == ET_DYN) { - /* in order to avoid hardcoding the interpreter load - address in qemu, we allocate a big enough memory zone */ - error = 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 = target_mmap(0, INTERP_MAP_SIZE, PROT_NONE, + MAP_PRIVATE | MAP_ANON, -1, 0); if (error == -1) { perror("mmap"); exit(-1); @@ -432,7 +435,7 @@ static const char *lookup_symbolxx(struct syminfo *s, target_ulong orig_addr) struct elf_sym *syms = s->disas_symtab.elf64; #endif - // binary search + /* binary search */ struct elf_sym *sym; sym = bsearch(&orig_addr, syms, s->disas_num_syms, sizeof(*syms), symfind); @@ -448,9 +451,8 @@ static int symcmp(const void *s0, const void *s1) { struct elf_sym *sym0 = (struct elf_sym *)s0; struct elf_sym *sym1 = (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); } /* Best attempt to load symbols from this ELF object. */ @@ -464,23 +466,24 @@ static void load_symbols(struct elfhdr *hdr, int fd) lseek(fd, hdr->e_shoff, SEEK_SET); for (i = 0; i < hdr->e_shnum; i++) { - if (read(fd, &sechdr, sizeof(sechdr)) != sizeof(sechdr)) + if (read(fd, &sechdr, sizeof(sechdr)) != sizeof(sechdr)) { return; + } bswap_shdr(&sechdr, 1); if (sechdr.sh_type == SHT_SYMTAB) { symtab = sechdr; - lseek(fd, hdr->e_shoff - + sizeof(sechdr) * sechdr.sh_link, SEEK_SET); - if (read(fd, &strtab, sizeof(strtab)) - != sizeof(strtab)) + lseek(fd, hdr->e_shoff + sizeof(sechdr) * sechdr.sh_link, + SEEK_SET); + if (read(fd, &strtab, sizeof(strtab)) != sizeof(strtab)) { return; + } bswap_shdr(&strtab, 1); goto found; } } return; /* Shouldn't happen... */ - found: +found: /* Now know where the strtab and symtab are. Snarf them. */ s = malloc(sizeof(*s)); syms = malloc(symtab.sh_size); @@ -508,7 +511,7 @@ static void load_symbols(struct elfhdr *hdr, int fd) i = 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 == SHN_UNDEF || syms[i].st_shndx >= SHN_LORESERVE || ELF_ST_TYPE(syms[i].st_info) != STT_FUNC) { @@ -521,10 +524,12 @@ static void load_symbols(struct elfhdr *hdr, int fd) i++; } - /* 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 = realloc(syms, nsyms * sizeof(*syms)); if (new_syms == NULL) { free(s); @@ -580,19 +585,19 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, /* First of all, some simple consistency checks */ if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) || - (!elf_check_arch(elf_ex.e_machine))) { + (!elf_check_arch(elf_ex.e_machine))) { return -ENOEXEC; } bprm->p = copy_elf_strings(1, &bprm->filename, bprm->page, bprm->p); - bprm->p = copy_elf_strings(bprm->envc, bprm->envp, bprm->page,bprm->p); - bprm->p = copy_elf_strings(bprm->argc, bprm->argv, bprm->page,bprm->p); + bprm->p = copy_elf_strings(bprm->envc, bprm->envp, bprm->page, bprm->p); + bprm->p = copy_elf_strings(bprm->argc, bprm->argv, bprm->page, bprm->p); if (!bprm->p) { retval = -E2BIG; } /* Now read in all of the header information */ - elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize*elf_ex.e_phnum); + elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize * elf_ex.e_phnum); if (elf_phdata == NULL) { return -ENOMEM; } @@ -611,7 +616,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, } bswap_phdr(elf_phdata, elf_ex.e_phnum); - elf_ppnt = elf_phdata; elf_bss = 0; @@ -624,23 +628,16 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, start_data = 0; end_data = 0; - for (i = 0;i < elf_ex.e_phnum; i++) { + for (i = 0; i < elf_ex.e_phnum; i++) { if (elf_ppnt->p_type == PT_INTERP) { - if (elf_interpreter != NULL) - { + if (elf_interpreter != NULL) { free(elf_phdata); free(elf_interpreter); close(bprm->fd); return -EINVAL; } - /* This is the program interpreter used for - * shared libraries - for now assume that this - * is an a.out format binary - */ - elf_interpreter = (char *)malloc(elf_ppnt->p_filesz); - if (elf_interpreter == NULL) { free(elf_phdata); close(bprm->fd); @@ -660,8 +657,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, retval = open(path(elf_interpreter), O_RDONLY); if (retval >= 0) { interpreter_fd = retval; - } - else { + } else { perror(elf_interpreter); exit(-1); /* retval = -errno; */ @@ -675,7 +671,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, } } if (retval >= 0) { - interp_elf_ex = *((struct elfhdr *) bprm->buf); /* elf exec-header */ + interp_elf_ex = *((struct elfhdr *) bprm->buf); } if (retval < 0) { perror("load_elf_binary3"); @@ -692,7 +688,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, /* Some simple consistency checks for the interpreter */ if (elf_interpreter) { if (interp_elf_ex.e_ident[0] != 0x7f || - strncmp((char *)&interp_elf_ex.e_ident[1], "ELF",3) != 0) { + strncmp((char *)&interp_elf_ex.e_ident[1], "ELF", 3) != 0) { free(elf_interpreter); free(elf_phdata); close(bprm->fd); @@ -700,9 +696,10 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, } } - /* 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); @@ -824,8 +821,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, free(elf_phdata); - if (qemu_log_enabled()) + if (qemu_log_enabled()) { load_symbols(&elf_ex, bprm->fd); + } close(bprm->fd); From patchwork Sat Aug 7 21:42:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=wkbeS9TX; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxFM3RxZz9sWX for ; Sun, 8 Aug 2021 08:03:51 +1000 (AEST) Received: from localhost ([::1]:37268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUQ1-0007mZ-7m for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:03:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6V-0000FP-3T for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:39 -0400 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]:42835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6S-0005RL-R8 for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:38 -0400 Received: by mail-io1-xd32.google.com with SMTP id h1so19882771iol.9 for ; Sat, 07 Aug 2021 14:43:36 -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=uV3DXKMiMilvUYIlhME781+iz+qiR6o//M5DU+AgnMw=; b=wkbeS9TXG1xyDZq+qsow/IIRnVvdWGIxVuGgku8dzpdhxO1istStOvkTt5pDdAufzr e4oqd8UIg6XPfWTIty7tBp6LvH6zkRvT8tXZ+9dfA5Gf8lsVEqpB32W8f8Wb+j6alXNY Jtmzdd9ShoMhW491edGvew2oNH/pOZGCITBSKCtqYvMCpfm2XE67TqV9rhIeWuVyrmPi aM7gBPBzjw5miKcn+rGZ23d2mGDJEZsH2n94XVnCiX/tSTtqopNi9U71Z5zOxvIYT3fN KSVzQWJXaWOEuJZxqfM3EAPqNwAO3uBnLmOg2C5tXBejApmM2RupwG9dPOqmfrinQfIM 1zew== 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=uV3DXKMiMilvUYIlhME781+iz+qiR6o//M5DU+AgnMw=; b=YrvKemF7TQY9IZaJXoe2bCalQ/Se0YdKLxweNjgrHvOThOW0fJCXfYyUx8fIsE1SLT qfrLahht53XpL+iVYJgFvJ4+2+f9LTKTyrDagJSl2BSLfefrS8evOIgjN4T3t8HGjrcG 97GpENEb8Gaxpfiqn9vQPOzviL8a0a5e3g+qQKJOhDYpxi0WXlGl3xzch+61KsQnnvgg QmYmdW42gkpFAjNxCvZ0ZQhL92ReJdO4/dG08ez7hpWE3B7tdchMAXUsm/CSUZj2u+e6 ntuXJeP/K6IxM0IKeGgiLs+CrMJoJZUCMrUxEBu/idc8GhHrZndF9BpFk7wQsxlFua+6 6s6Q== X-Gm-Message-State: AOAM530K8A4Xvs5SFMrXYXKKnef0C7aFPzrYvbfhAyuK+1pYwMPG+BfZ Mg2k0GnNkidex6QlyPISyFJOGlCK6upOKPga X-Google-Smtp-Source: ABdhPJzriXe8Z1VMtIjKTOpBZRLnBfumBdb+cJ+D3MmiTxvmOyf9V2ShLdkIDNnZZ2xid2PLrA6ATg== X-Received: by 2002:a05:6638:449:: with SMTP id r9mr15549647jap.137.1628372615503; Sat, 07 Aug 2021 14:43:35 -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 a17sm8062827ios.36.2021.08.07.14.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:35 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 44/49] bsd-user: Refactor load_elf_sections and is_target_elf_binary Date: Sat, 7 Aug 2021 15:42:37 -0600 Message-Id: <20210807214242.82385-45-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d32; envelope-from=imp@bsdimp.com; helo=mail-io1-xd32.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, Warner Losh , Warner Losh , =?utf-8?q?Mika=C3=ABl_Urankar?= , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Factor out load_elf_sections and is_target_elf_binary out of load_elf_interp. Signed-off-by: MikaĆ«l Urankar Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/elfload.c | 350 +++++++++++++++++++++------------------------ 1 file changed, 164 insertions(+), 186 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index bdf18f3dce..aed28f2f73 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -36,6 +36,8 @@ abi_ulong target_stksiz; abi_ulong target_stkbas; static int elf_core_dump(int signr, CPUArchState *env); +static int load_elf_sections(const struct elfhdr *hdr, struct elf_phdr *phdr, + int fd, abi_ulong rbase, abi_ulong *baddrp); 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 *interp_elf_ex, abi_ulong *interp_load_addr) { struct elf_phdr *elf_phdata = NULL; - struct elf_phdr *eppnt; - abi_ulong load_addr = 0; - int load_addr_set = 0; + abi_ulong rbase; int retval; - abi_ulong last_bss, elf_bss; - abi_ulong error; - int i; + abi_ulong baddr, error; - elf_bss = 0; - last_bss = 0; error = 0; bswap_ehdr(interp_elf_ex); @@ -325,6 +321,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, } bswap_phdr(elf_phdata, interp_elf_ex->e_phnum); + rbase = 0; if (interp_elf_ex->e_type == ET_DYN) { /* * In order to avoid hardcoding the interpreter load @@ -332,86 +329,25 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, */ error = target_mmap(0, INTERP_MAP_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0); - if (error == -1) { + if (rbase == -1) { perror("mmap"); exit(-1); } - load_addr = error; - load_addr_set = 1; - } - - eppnt = elf_phdata; - for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) - if (eppnt->p_type == PT_LOAD) { - int elf_type = MAP_PRIVATE | MAP_DENYWRITE; - int elf_prot = 0; - abi_ulong vaddr = 0; - abi_ulong k; - - if (eppnt->p_flags & PF_R) elf_prot = PROT_READ; - if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE; - if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC; - if (interp_elf_ex->e_type == ET_EXEC || load_addr_set) { - elf_type |= MAP_FIXED; - vaddr = eppnt->p_vaddr; - } - error = target_mmap(load_addr + TARGET_ELF_PAGESTART(vaddr), - eppnt->p_filesz + TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr), - elf_prot, - elf_type, - interpreter_fd, - eppnt->p_offset - TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr)); - - if (error == -1) { - /* Real error */ - close(interpreter_fd); - free(elf_phdata); - return ~((abi_ulong)0UL); - } - - if (!load_addr_set && interp_elf_ex->e_type == ET_DYN) { - load_addr = error; - load_addr_set = 1; - } - - /* - * Find the end of the file mapping for this phdr, and keep - * track of the largest address we see for this. - */ - k = load_addr + eppnt->p_vaddr + eppnt->p_filesz; - if (k > elf_bss) elf_bss = k; + } - /* - * Do the same thing for the memory mapping - between - * elf_bss and last_bss is the bss section. - */ - k = load_addr + eppnt->p_memsz + eppnt->p_vaddr; - if (k > last_bss) last_bss = k; - } + error = load_elf_sections(interp_elf_ex, elf_phdata, interpreter_fd, rbase, + &baddr); + if (error != 0) { + perror("load_elf_sections"); + exit(-1); + } /* 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 = 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); - *interp_load_addr = load_addr; - return ((abi_ulong) interp_elf_ex->e_entry) + load_addr; + *interp_load_addr = baddr; + return ((abi_ulong) interp_elf_ex->e_entry) + rbase; } 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 &= ~(target_ulong)1; +#endif i++; } @@ -560,26 +500,119 @@ found: syminfos = s; } +/* 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 = *((struct elfhdr *)buf); + bswap_ehdr(&elf_ex); + + if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != 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 = true; + for (i = 0, elf_ppnt = phdr; i < hdr->e_phnum; i++, elf_ppnt++) { + int elf_prot = 0; + abi_ulong error; + + /* XXX Skip memsz == 0. */ + if (elf_ppnt->p_type != PT_LOAD) { + continue; + } + + if (elf_ppnt->p_flags & PF_R) { + elf_prot |= PROT_READ; + } + if (elf_ppnt->p_flags & PF_W) { + elf_prot |= PROT_WRITE; + } + if (elf_ppnt->p_flags & PF_X) { + elf_prot |= PROT_EXEC; + } + + error = target_mmap(TARGET_ELF_PAGESTART(rbase + elf_ppnt->p_vaddr), + (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 == -1) { + perror("mmap"); + exit(-1); + } else if (elf_ppnt->p_memsz != elf_ppnt->p_filesz) { + abi_ulong start_bss, end_bss; + + start_bss = rbase + elf_ppnt->p_vaddr + elf_ppnt->p_filesz; + end_bss = rbase + elf_ppnt->p_vaddr + elf_ppnt->p_memsz; + + /* + * Calling set_brk effectively mmaps the pages that we need for the + * bss and break sections. + */ + set_brk(start_bss, end_bss); + padzero(start_bss, end_bss); + } + + if (first) { + baddr = TARGET_ELF_PAGESTART(rbase + elf_ppnt->p_vaddr); + first = false; + } + } + + if (baddrp != NULL) { + *baddrp = 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 = -1; /* avoid warning */ - abi_ulong load_addr, load_bias; - int load_addr_set = 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 = 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 = 0; abi_ulong reloc_func_desc = 0; load_addr = 0; - load_bias = 0; elf_ex = *((struct elfhdr *) bprm->buf); /* exec-header */ bswap_ehdr(&elf_ex); @@ -618,16 +651,10 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, bswap_phdr(elf_phdata, elf_ex.e_phnum); elf_ppnt = elf_phdata; - elf_bss = 0; elf_brk = 0; elf_interpreter = NULL; - start_code = ~((abi_ulong)0UL); - end_code = 0; - start_data = 0; - end_data = 0; - for (i = 0; i < elf_ex.e_phnum; i++) { if (elf_ppnt->p_type == PT_INTERP) { if (elf_interpreter != NULL) { @@ -714,94 +741,45 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, info->mmap = 0; elf_entry = (abi_ulong) elf_ex.e_entry; - /* 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 = 0; + for (i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) { + if (elf_ppnt->p_type != PT_LOAD) { + continue; + } + baddr = elf_ppnt->p_vaddr; + break; + } + + et_dyn_addr = 0; + if (elf_ex.e_type == ET_DYN && baddr == 0) { + et_dyn_addr = 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 = 0; setup_arg_pages(bprm, info, &bprm->p, &bprm->stringp); info->start_stack = bprm->p; - /* 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 = elf_ex.e_flags; + error = load_elf_sections(&elf_ex, elf_phdata, bprm->fd, et_dyn_addr, + &load_addr); for (i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) { - int elf_prot = 0; - int elf_flags = 0; - abi_ulong error; - - if (elf_ppnt->p_type != PT_LOAD) + if (elf_ppnt->p_type != PT_LOAD) { continue; - - if (elf_ppnt->p_flags & PF_R) elf_prot |= PROT_READ; - if (elf_ppnt->p_flags & PF_W) elf_prot |= PROT_WRITE; - if (elf_ppnt->p_flags & PF_X) elf_prot |= PROT_EXEC; - elf_flags = MAP_PRIVATE | MAP_DENYWRITE; - if (elf_ex.e_type == ET_EXEC || load_addr_set) { - elf_flags |= MAP_FIXED; - } else if (elf_ex.e_type == 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 movable. */ - /* NOTE: for qemu, we do a big mmap to get enough space - without hardcoding any address */ - error = target_mmap(0, ET_DYN_MAP_SIZE, - PROT_NONE, MAP_PRIVATE | MAP_ANON, - -1, 0); - if (error == -1) { - perror("mmap"); - exit(-1); - } - load_bias = TARGET_ELF_PAGESTART(error - elf_ppnt->p_vaddr); } - - error = 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 == -1) { - perror("mmap"); - exit(-1); - } - - if (!load_addr_set) { - load_addr_set = 1; - load_addr = elf_ppnt->p_vaddr - elf_ppnt->p_offset; - if (elf_ex.e_type == ET_DYN) { - load_bias += error - - TARGET_ELF_PAGESTART(load_bias + elf_ppnt->p_vaddr); - load_addr += load_bias; - reloc_func_desc = load_bias; - } - } - k = elf_ppnt->p_vaddr; - if (k < start_code) - start_code = k; - if (start_data < k) - start_data = k; - k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz; - if (k > elf_bss) - elf_bss = k; - if ((elf_ppnt->p_flags & PF_X) && end_code < k) - end_code = k; - if (end_data < k) - end_data = k; - k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; - if (k > elf_brk) elf_brk = k; - } - - elf_entry += load_bias; - elf_bss += load_bias; - elf_brk += load_bias; - start_code += load_bias; - end_code += load_bias; - start_data += load_bias; - end_data += load_bias; + if (elf_ppnt->p_memsz > elf_ppnt->p_filesz) + elf_brk = MAX(elf_brk, et_dyn_addr + elf_ppnt->p_vaddr + + elf_ppnt->p_memsz); + } + if (error != 0) { + perror("load_elf_sections"); + exit(-1); + } if (elf_interpreter) { elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd, @@ -817,6 +795,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, exit(-1); return 0; } + } else { + interp_load_addr = et_dyn_addr; + elf_entry += interp_load_addr; } free(elf_phdata); @@ -827,21 +808,18 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, close(bprm->fd); - bprm->p = target_create_elf_tables(bprm->p, bprm->argc, bprm->envc, bprm->stringp, - &elf_ex, load_addr, load_bias, interp_load_addr, info); + bprm->p = target_create_elf_tables(bprm->p, + bprm->argc, + bprm->envc, + bprm->stringp, + &elf_ex, + load_addr, et_dyn_addr, + interp_load_addr, + info); info->load_addr = reloc_func_desc; info->start_brk = info->brk = elf_brk; - info->end_code = end_code; - info->start_code = start_code; - info->start_data = start_data; - info->end_data = end_data; info->start_stack = bprm->p; - - /* Calling set_brk effectively mmaps the pages that we need for the bss and break - sections */ - set_brk(elf_bss, elf_brk); - - padzero(elf_bss, elf_brk); + info->load_bias = 0; info->entry = elf_entry; From patchwork Sat Aug 7 21:42:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=1G0T10du; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxCP4sKnz9sWX for ; Sun, 8 Aug 2021 08:02:09 +1000 (AEST) Received: from localhost ([::1]:58904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUON-0003O6-B5 for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:02:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6U-0000EO-SU for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:39 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]:36826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6T-0005S1-Gi for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:38 -0400 Received: by mail-io1-xd2b.google.com with SMTP id f11so19877567ioj.3 for ; Sat, 07 Aug 2021 14:43:37 -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=G3nLLdhEF/Vlqw5++2FHKdCGPSKrUbgdgJXcPdhW92g=; b=1G0T10du/yj9eilbkg2SThlMESF+kIjMCqEBnFNEHcGnJQ9IVJD9WhCyraS/W+jKHw Xyja13XKgiiOTbiGFPypinaNuKJGhHBajiBTTQ9ZMe2q5/ALJxz+5sihaojk49HDtnPJ 4Jj07WP4HKAFqBZlwv2JeOTFLQ59fkp30qqAhi0+w5TeThfAFslat5wKEwZHctuwuGzT 82aREfk09toR7/unfw0W6KOAg5Dk2aoCdmyf6p9vsdThQX2E0+OjvK/A3FfY+6gh58FI rRW48v0din5AVPRlYmbdnpyV4ycWSLfNZDvUXepAGCeHsnlDT3dxxfEG4WIwQfs+rSHm j4iw== 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=G3nLLdhEF/Vlqw5++2FHKdCGPSKrUbgdgJXcPdhW92g=; b=el8nILTwdNDmTMLaTvaLwylIgnJ+XH+2zTBc1ScmYnKKgUkOWGEBfFmCUBKfbqkt+R i6zu8Gg0cpqWHHQ9rbofm7/imSZWhFYMtyvy0dJVAfOm6sldlGYHb7dRA5uyqhHzWsYl 3LwclCD2kkP0/zCRm9n52uAi5Bk9hVGaIE4Y5XNIDOt333qaC8NNSI6YxmIZjz1tML1i gHphNr+r2lT1TYt7aOZR9QHYN5pVWHp1+k0UNlcEZAxGF803B8KBj+/dudJ9ja7+Otsx ETgLbNRIlvRDxrQSZPlJbtddocAuV5b4eA+oNM7RCGF2F+fRu+hc8Sl/Wa3xZcmBnSFB Pexg== X-Gm-Message-State: AOAM530tGw9wUCLwRQhwGldgodydwLc5mlNw+4ZmiNiljygyj3wR4CWg x+yasC/igeFFKuSxaaxglV7GCSI9tiRluXgF X-Google-Smtp-Source: ABdhPJwYXEvFdOPWQEef7DnvY3fjFTy7Ok1JcBFsNc8IxF2BUHcKDZY112n+6cCqwD/+EtaV0ueGZQ== X-Received: by 2002:a02:2307:: with SMTP id u7mr15852354jau.28.1628372616326; Sat, 07 Aug 2021 14:43:36 -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 a17sm8062827ios.36.2021.08.07.14.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:35 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 45/49] bsd-user: Make guest_base an unsigned long Date: Sat, 7 Aug 2021 15:42:38 -0600 Message-Id: <20210807214242.82385-46-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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: kevans@freebsd.org, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Make the guest_base a plan, uneigned long rather than a uintptr_t. It isn't really a pointer. Signed-off-by: Stacey Son Signed-off-by: Warner Losh --- bsd-user/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 08f88d9668..c8fafa78d0 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -49,9 +49,9 @@ #include "target_arch_cpu.h" int singlestep; -uintptr_t guest_base; static const char *cpu_model; static const char *cpu_type; +unsigned long guest_base; bool have_guest_base; #if (TARGET_LONG_BITS == 32) && (HOST_LONG_BITS == 64) /* @@ -440,7 +440,7 @@ int main(int argc, char **argv) g_free(target_environ); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { - qemu_log("guest_base %p\n", (void *)guest_base); + qemu_log("guest_base 0x%lx\n", guest_base); log_page_dump("binary load"); qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); From patchwork Sat Aug 7 21:42:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=wamNaG7J; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxNy1NQYz9sWX for ; Sun, 8 Aug 2021 08:10:25 +1000 (AEST) Received: from localhost ([::1]:58700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUWM-0005Ku-9t for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:10:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6V-0000GF-Vz for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:40 -0400 Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]:37715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6U-0005T1-Eq for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:39 -0400 Received: by mail-io1-xd30.google.com with SMTP id l20so17749798iom.4 for ; Sat, 07 Aug 2021 14:43: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=6TEa87wBqKTP6vhIgK0R3rG57nCLcrb9WVGGCmCQqkk=; b=wamNaG7JqoqbEMD6BMAczlsarHECN2J4sFVwAkC0eDtKSCT5Nm4CrClEWyDRavO9+A pUvD+UdkvEBBUz9C4HFuyV8BbhDDcXn9RWKKO9jPZ0xLJ2GtUJYhmigdk2j3T2QGX9VB RFbDgcAoe8RjlV/f0CW6LnaNI8O8GuV2nt16m8MQoYrTTyVWTFQapXEIMOb54l/ptrva VyhS2XwXbGILSmtR58c0u45XNH72UUBx0pNuZyEFiCT2xVbUlph+BCc+ppRee8YcrEWf jOYAY/7nruGzlEjI+pCnn24hmuWNGx7xEEm6gkAzCv/aGBpXo+hH2JOZxlYPVKid64ui 9CeA== 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=6TEa87wBqKTP6vhIgK0R3rG57nCLcrb9WVGGCmCQqkk=; b=jFLq4vezxKL+NbDacFtP0TUEbU0v97YQTcjz0BniQqMkeYpw0PW67jXnT8WqF04LMi Iove7LXIzdKhfUjlYHDI/LTnEBF7bnyDBx1V4s09SSPZvQvZdRNSCFVskC0Io5kKOBNY y21rp4+JDq2Go+CNNbxWoEGmVyE3kKMxvyZzqG6nfQKbPqLu/WZwaOCmXCTpTZxJqVaO PzxuWlPXW4qJVj/2cocRE6sW7l82gxzSJZmj3//U2zugW499ndomX18pa8chIs0sg0I2 2bjv8/IjE4RKfEmw2FW5I8UfYWVYzne6KFN7KEmHmDi/b46ychdPytQWfXI40ZJh4IUh mF6Q== X-Gm-Message-State: AOAM531FvRCvyt9IOH7CSdWMX6rHxEuUc2JKZQwp4LB16QsqJwgf73nC SGbTpnA5FK44lbIWWUG5IRiFcgKjwc/pM8cm X-Google-Smtp-Source: ABdhPJzQ1RUB+FC0KfJ/YQfWqnbBwjTv8rtpgj1qUf7wi1L6y72ksEODO8JZNB+7zG2HdlVvNCWO0Q== X-Received: by 2002:a05:6638:1928:: with SMTP id p40mr16003859jal.93.1628372617194; Sat, 07 Aug 2021 14:43:37 -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 a17sm8062827ios.36.2021.08.07.14.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:36 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 46/49] bsd-user: move qemu_log to later in the file Date: Sat, 7 Aug 2021 15:42:39 -0600 Message-Id: <20210807214242.82385-47-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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, Warner Losh , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh Signed-off-by: Warner Losh Acked-by: Richard Henderson --- 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 c8fafa78d0..7ba616a995 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -85,14 +85,6 @@ unsigned long target_dflssiz = TARGET_DFLSSIZ; /* initial data size limit */ unsigned long target_maxssiz = TARGET_MAXSSIZ; /* max stack size */ unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount to grow stack */ -void gemu_log(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); -} void fork_start(void) { @@ -181,6 +173,15 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next = NULL; } +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) { From patchwork Sat Aug 7 21:42:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=pt7nvL/Z; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Ghx3m6YClz9sWX for ; Sun, 8 Aug 2021 07:55:32 +1000 (AEST) Received: from localhost ([::1]:34580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUHy-0003bk-Lt for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 17:55:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6W-0000Hm-Nt for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:41 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:35617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6V-0005TW-8l for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:40 -0400 Received: by mail-io1-xd36.google.com with SMTP id s184so20004188ios.2 for ; Sat, 07 Aug 2021 14:43: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=vOkvP8eW9FaZE+oQEicIqxiTibF7uC5PjljIsjV9a8M=; b=pt7nvL/ZCuALCKXK9QCWkULpi8bP2R1yY6mbnJ86xJcIp+TM8DWJqnKHE9Wxeg6+RB LzoCw9IcbROaNTgXtFmFixG4OZObypc9USuDOsIqQZL4yctxGlCyN/98IrWaOp5+sHg/ mQ6RNKwC4iKOItVfpSAJtkJKHfhkGbn2Nye6+IRKConI0RiLcdPa7cE3s3EicwU9BsOr v4dmzx2roU69snDlSowdGTVXnqPiorHnHbdqb9hIuUTThcYlMHb68UCR1FiV0CQmd+08 cGfKOyHmC5tqCGv5CfkvY2F6P/hPhvNOVaPD4/GKQNXqJFqM2CnUMV1M5XhFrPVkDwTi hcKQ== 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=vOkvP8eW9FaZE+oQEicIqxiTibF7uC5PjljIsjV9a8M=; b=XMeBV6qX63VEj+a+i7mrJGj7s2tRUaSd48XxNGeWk2gG8PadhkPMhwfqZ9EDexagYk Cq++SaQQ4s7ShzIzdrI7Pb6iHd6aSPcigx4bn9EBvVSPjC0ogdZEFzhj+sunLK7CynFq 5eexiovxF165x8qGDBQp3qSUSEwhVQNNI5JamtA853o6XFA7aeVjV1NivX9cypqxCPpa +9O6uF0VWPLctviLcB+W2qBqj88FOUm7wlSTjqdbESyoumlPPqVF1/PjbhqEYnQ7SQK3 1Bw3TuL1ptODHzd8COrQOLILXrn+feHPelbE+Imfdx2sANdN38PiEHUgGwE10DEcJK2k jfVA== X-Gm-Message-State: AOAM532YfPTXlXEio79a9gqId54gig7lNpKipRoRRhI11pPn8oYVZR0t +3Qe3F9LV5Py01y6V/0u+87Eb3/oD1Z/BXQG X-Google-Smtp-Source: ABdhPJyLS0HAPdm3PRC9VMokH1qbPaBdW2FiNXAg7BPjmkQsz6NcnN3w4QGLhJTjuqCaJL0Zp63Guw== X-Received: by 2002:a05:6e02:1aa3:: with SMTP id l3mr23292ilv.299.1628372618046; Sat, 07 Aug 2021 14:43:38 -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 a17sm8062827ios.36.2021.08.07.14.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:37 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 47/49] bsd-user: Implement interlock for atomic operations Date: Sat, 7 Aug 2021 15:42:40 -0600 Message-Id: <20210807214242.82385-48-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.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, Warner Losh , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 7ba616a995..2b0716d245 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -85,15 +85,38 @@ unsigned long target_dflssiz = TARGET_DFLSSIZ; /* initial data size limit */ unsigned long target_maxssiz = TARGET_MAXSSIZ; /* max stack size */ unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount to grow stack */ +/* Helper routines for implementing atomic operations. */ void fork_start(void) { + start_exclusive(); + cpu_list_lock(); + mmap_fork_start(); } void fork_end(int child) { if (child) { + CPUState *cpu, *next_cpu; + /* + * Child processes created by fork() only have a single thread. + * Discard information about the parent threads. + */ + CPU_FOREACH_SAFE(cpu, next_cpu) { + if (cpu != 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(); } } From patchwork Sat Aug 7 21:42:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514762 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=bAo7jySb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxNh65ZYz9sWX for ; Sun, 8 Aug 2021 08:10:12 +1000 (AEST) Received: from localhost ([::1]:57938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUWA-0004nT-BO for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:10:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6X-0000Jg-OW for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:42 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]:46049) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6W-0005Uq-9M for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:41 -0400 Received: by mail-io1-xd33.google.com with SMTP id e186so17979869iof.12 for ; Sat, 07 Aug 2021 14:43: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=rfVpKk3K/d551DVmXRmKm6XBuSrm0xhas2vhvUMjkyQ=; b=bAo7jySbQTl8v/QAkuQVEWlDLujUZg2yjniRljOyWDd2izsMFyV+cDe0Txd9busFPP ZtotqlM12EvrMrtcedIr2TnTJmsrKGlTFdEZR50Hq35B/duxJezTyqUsYUNOSn4Xj9Xk gdBmFmpkvNVJcXRNBY22vbw8GXRsHX7QgPzpDCmpeWAalh+GVcxc8yLmbbN5enFmS2+z QZhYLooXJW1hYnhOU4ttfgoHnA3bNV+PxxIYm/0MqKDvDrO8Q+BwWNf/QpYufd8Q9vLH gRCFdtcviDWlKUow25/c2vp7S29R4MJFiF9YeeCOpRPZtYU5bQy+5NRQmOETxuUYieGu KHWQ== 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=rfVpKk3K/d551DVmXRmKm6XBuSrm0xhas2vhvUMjkyQ=; b=bESv46Oxdb8tzpdvGknFAdVbozXm/HwHpBzJtd0tQOAA+SeYUuPWNANX4wrXzKu5Gr LDKsGP5be9K1VbuUlvX484jR+APjt0/U0+hW1ctc1crfBFrT2mM5VQKrlhAhW3U5avCv ztMtgmikY765dTUikztB4KSvHVc9UzPRTT62Z8x4gScGEec0Zh7V5cePQbQnA5vuzfYB K9j+6AB/flCTkcvIjT7u+/4rRH0Rl79x+yn7oLrGSu86J2/J2WawoH2chHomAI7RMtgT 3WPdS6xAGxYFceRncHQIlM3HsZg0VI/yCBdjMADrjG8ws1gCbolBxJbURnhAIN0MXq8U yWdA== X-Gm-Message-State: AOAM530JcgU2zVc3Nq+rOJQfyMtQR/LLyEM/pq/+VdAMLbA2udLKG0Q7 V81ozEj4PisWGbalTpgEyK7sERWeopssDLFs X-Google-Smtp-Source: ABdhPJxx5St20//8fsIDfTjQf/PZ65vNOgoDV25nxo+VfQa4yhEzcxiacC6tXpRenPYuJFboYJFMBg== X-Received: by 2002:a05:6e02:550:: with SMTP id i16mr19385ils.207.1628372619045; Sat, 07 Aug 2021 14:43:39 -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 a17sm8062827ios.36.2021.08.07.14.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:38 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 48/49] bsd-user: Implement cpu_copy() helper routine Date: Sat, 7 Aug 2021 15:42:41 -0600 Message-Id: <20210807214242.82385-49-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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: kevans@freebsd.org, Warner Losh , Justin Hibbits , Warner Losh , Stacey Son Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Warner Losh cpu_copy shouldbe called when processes are creating new threads. It copies the current state of the CPU to a new cpu state needed for the new thread. Signed-off-by: Stacey Son Signed-off-by: Warner Losh Signed-off-by: Justin Hibbits Reviewed-by: Richard Henderson --- bsd-user/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 2b0716d245..1de5dc189b 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -196,6 +196,36 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next = NULL; } +CPUArchState *cpu_copy(CPUArchState *env) +{ + CPUState *cpu = env_cpu(env); + CPUState *new_cpu = cpu_create(cpu_type); + CPUArchState *new_env = new_cpu->env_ptr; + CPUBreakpoint *bp; + CPUWatchpoint *wp; + + /* Reset non arch specific state */ + cpu_reset(new_cpu); + + memcpy(new_env, env, sizeof(CPUArchState)); + + /* + * Clone all break/watchpoints. + * Note: Once we support ptrace with hw-debug register access, make sure + * BP_CPU break/watchpoints are handled correctly on clone. + */ + QTAILQ_INIT(&cpu->breakpoints); + QTAILQ_INIT(&cpu->watchpoints); + QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { + cpu_breakpoint_insert(new_cpu, bp->pc, bp->flags, NULL); + } + QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { + cpu_watchpoint_insert(new_cpu, wp->vaddr, wp->len, wp->flags, NULL); + } + + return new_env; +} + void gemu_log(const char *fmt, ...) { va_list ap; From patchwork Sat Aug 7 21:42:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 1514764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=DDPtkXkx; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhxRN272zz9sWX for ; Sun, 8 Aug 2021 08:12:32 +1000 (AEST) Received: from localhost ([::1]:36336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCUYP-0000yW-3c for incoming@patchwork.ozlabs.org; Sat, 07 Aug 2021 18:12:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCU6a-0000S8-5R for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:44 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]:42829) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mCU6X-0005WJ-Ck for qemu-devel@nongnu.org; Sat, 07 Aug 2021 17:43:43 -0400 Received: by mail-io1-xd2b.google.com with SMTP id h1so19883018iol.9 for ; Sat, 07 Aug 2021 14:43: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=D+a7UQ8owCmGXtyzDU3U40GIDHEJl71xOx4FAs8OqMA=; b=DDPtkXkx5v6T1EP45z2hwLUjNPOy/2PrkgOs+KAC3uECbFD2rkHv2DSuDKNcGbbt4d Y0MUNFq+0TOPmQq7tveSfj7sXYuf7+WC1ycMNPP0Rx5IdoAX93WjWeq1nS7v3UCX+2bb ciT8n/ysVLNpULS0fMnPQbRzGOhsYo/i41erR0PIiSZt3a8Rg2lTPKRw38ItLzLp1XJT 3YBi5qsYR2gSvWJH7dt/O78+4p0q+DvNYoHSh1QdJCXA1Y0ypK169EyQL7OlQGGfdPz6 SCwM2aeXtdMMgzx1QAdiLCDtu2Tys8qE30TDNz2HqEH90ogr5XTs3j1KRJEzc9k0DJtT pY/Q== 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=D+a7UQ8owCmGXtyzDU3U40GIDHEJl71xOx4FAs8OqMA=; b=aZfxks/bfaHo5WyvzX/Dgkjskj5XvOcI3nqp9bACqcTKYxhzqiSctTeTpJfSbMQlz2 5g/uSoos8Lzelat7+s5R04p3Oe/vZNfoY/bg73tQln/RmnaSEJwLWJj7B0PNskurNuzP Nofd6HNTXC2B9MbW9XAcm+Xpb8hL4pFFkrU5fOQh0ILprinf5sfz43/L/fH0+UEyRblk kKcFXOLkCEhmV4V9AocHp3j8jkqxujB8aqgHCv9lSJiai3hGjwpwTYCJWeMymXSGjgtU 2U/AkL5PwVEMVDFJg+q1kIb0qqZtV8Jc/TwYWnwG6BuML2m6IV2GDqqd2HCmXLyvSkbi USTw== X-Gm-Message-State: AOAM5337k4SRsjwNtSOewKiKbu8EYCAgfWEyDtlgyCYNf2gOHhFKSrfS e4LzAbhQ6ES0CLIv/Yx/zPT/bNJCiD9Yrj2w X-Google-Smtp-Source: ABdhPJzhyQ2vYSVCJaYzjPi7xG9T2z9NNVyYuiJ08PnXKnpEQa2NQTOU5rJOGAbnmDeR1LxfZliLrA== X-Received: by 2002:a05:6e02:2147:: with SMTP id d7mr91494ilv.179.1628372620043; Sat, 07 Aug 2021 14:43: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 a17sm8062827ios.36.2021.08.07.14.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Aug 2021 14:43:39 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH for 6.2 49/49] bsd-user: Add '-0 argv0' option to bsd-user/main.c Date: Sat, 7 Aug 2021 15:42:42 -0600 Message-Id: <20210807214242.82385-50-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210807214242.82385-1-imp@bsdimp.com> References: <20210807214242.82385-1-imp@bsdimp.com> MIME-Version: 1.0 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: kevans@freebsd.org, Colin Percival , Warner Losh Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bsd-user/main.c b/bsd-user/main.c index 1de5dc189b..c3ecdaf824 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -284,6 +284,7 @@ int main(int argc, char **argv) char **target_environ, **wrk; envlist_t *envlist = NULL; bsd_type = HOST_DEFAULT_BSD_TYPE; + char * argv0 = NULL; adjust_ssize(); @@ -405,6 +406,8 @@ int main(int argc, char **argv) do_strace = 1; } else if (!strcmp(r, "trace")) { trace_opt_parse(optarg); + } else if (!strcmp(r, "0")) { + argv0 = argv[optind++]; } else { usage(); } @@ -428,6 +431,8 @@ int main(int argc, char **argv) usage(); } filename = argv[optind]; + if (argv0) + argv[optind] = argv0; if (!trace_init_backends()) { exit(1);