From patchwork Sat Jun 19 03:43:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463848 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp532552jao; Fri, 18 Jun 2021 20:43:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQYjrUEKhJLrpZTwWz5ciLvGuji8+AdsgqPsy/KXGZZ/mnfewzILunZHGE9wi+pnj7loF3 X-Received: by 2002:a05:6e02:dc8:: with SMTP id l8mr9326574ilj.286.1624074239349; Fri, 18 Jun 2021 20:43:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074239; cv=none; d=google.com; s=arc-20160816; b=SRV9fqjZupP511Qq7bOSUv7f3id05LJkM5g7jOtErbwQdZhjTnOnOp4RwQaj/Szvd3 pumcM3MwveNKWwjYkqqqBypaKgL0Dce6fGfZM0IUqN/E4aUBXNPW+ZaNKEy7XWS2tYU/ Db79dqWUcoYi8DDMJRbRZYeYPO9lhyHYkLsJ2w3QuMZg5Nlp7TyJERMYpVCpM9W0O1Bw NfZ6ml6IhuRuX2dpNawcxRe9aekWOW+wzD2S8vnKe3J9ZhkJgehyfxeCtLQth77wBcDz toPHy1VAZiJGRdVlvEWwSFmF2Md94WtTQGcJWOqOiXtXn8EILw7/6mK4tb3Ke/tMz3JA K/8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=NFyiLCGJg5Xo3SqM6ckKPEkOJUNRw/fc9LhzEEFhQ7g=; b=OgD46eVmHhfdcqiXilWQ6+kQ8kSn5H1BchT9eLHuuS6csgIlq5Jc6z4kiBg7+M563t EcZq5t24tepIiUMJF8bbzsjUiW1l1FirC8ZRQDJ9X5DqukNV+f8I7ABwNgHIY0Sw4zUR iOSy7Xper7Eze4jfq2R23p401/xgjTxbnDyQ9Lnjy6Tc9bKyJ8QfT0OHjvufP3apOael /f7EnfgSKUa8+r0mf9vG2DXXiwWmiIOWK6DHRzKdp/hJhbxL5Ou3kKJjURYMpItUDJzi Ml14JRF5+TWqG4gWF+JZdm4Xlt+A/WsjJV1Pwpiq4s6uIinpVr2Dv30W4GwZplNNUPB/ ZNdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GnTPI02Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h21si11584489ioe.3.2021.06.18.20.43.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:43:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GnTPI02Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRtm-00008I-MA for patch@linaro.org; Fri, 18 Jun 2021 23:43:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtS-000083-K3 for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:38 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:43770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtN-00080q-D9 for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:38 -0400 Received: by mail-pf1-x432.google.com with SMTP id a127so9195616pfa.10 for ; Fri, 18 Jun 2021 20:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NFyiLCGJg5Xo3SqM6ckKPEkOJUNRw/fc9LhzEEFhQ7g=; b=GnTPI02Ze0kaGpPWSFxBVUpYR5KTg6tCO08UEaNwHuxSxSBd2ORwCixEnFr4RC1fOJ DH+uG9APHkyEOxuP59vG6Z+U+au1XCVfAwu8er0OtrillEW4VvzDYWlt0DTZV8DVO/1h z9wNCdprtuXs8DUZYnj9Z8B8bjVgaQyIEkVKjlx5sj9/93FNtCddjzJ5n3Qfgez4b1u8 KxtDzvlr+zHaz5/kODHC0wSSpSpvM3UXEsJXAjF/XLr40JdP3RULwPKdNQEPdMFyfuT3 VUnopY5PFTzTOlj9gKVueWWfzd1gdnw0PjA7ufTeLgaT59rCEtHgHPI31/tnWqV3Ufog QNNw== 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=NFyiLCGJg5Xo3SqM6ckKPEkOJUNRw/fc9LhzEEFhQ7g=; b=QSQneVyCdcr0kIUjc0Eluia+cx542B2b6DnOmX12mlaMbvxsFQ3oCuuuKBOLe+FsJn fzTCt8oXtYN8zAeMyVKGOLJhfZgUzKrNQkXS6TMMHtdibA9w0zSKB1mNDj37jh7aowZ6 icYKgn4x3jPdYMj65oDz+DeppP9SUh4DBx3RFJIqQtYx4hmv8xh3lC6cd3O+zLPv1y+3 1zVBXgvNYoSQ+/KDJ70/iIHc88HOafojp7Xiy14ljup2+jm1HpdPqA0eXiX6bFGxbmB9 jeRkGnPmdR0oa7Lwns/0UnFCbkKQSL8BZO3NYwO54kY+4RYUdrGoepT63hUgSsoawE9P mrCA== X-Gm-Message-State: AOAM533cCDjG6JLfs4TArQjbCyi8e5okDbhkJA2pUXCbidvjQp/h/1C7 Kl/X2GkErtQI8ypOkHJI9FYcn30kFX006g== X-Received: by 2002:a63:4c5e:: with SMTP id m30mr13000355pgl.153.1624074211389; Fri, 18 Jun 2021 20:43:31 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 01/12] linux-user: Fix style problems in linuxload.c Date: Fri, 18 Jun 2021 20:43:18 -0700 Message-Id: <20210619034329.532318-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- linux-user/linuxload.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index a27e1d0d8b..9d4eb5e94b 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -1,59 +1,57 @@ /* Code for loading Linux executables. Mostly linux kernel code. */ #include "qemu/osdep.h" - #include "qemu.h" #define NGROUPS 32 /* ??? This should really be somewhere else. */ -abi_long memcpy_to_target(abi_ulong dest, const void *src, - unsigned long len) +abi_long memcpy_to_target(abi_ulong dest, const void *src, unsigned long len) { void *host_ptr; host_ptr = lock_user(VERIFY_WRITE, dest, len, 0); - if (!host_ptr) + if (!host_ptr) { return -TARGET_EFAULT; + } memcpy(host_ptr, src, len); unlock_user(host_ptr, dest, 1); return 0; } -static int count(char ** vec) +static int count(char **vec) { - int i; + int i; - for(i = 0; *vec; i++) { + for (i = 0; *vec; i++) { vec++; } - - return(i); + return i; } static int prepare_binprm(struct linux_binprm *bprm) { - struct stat st; + struct stat st; int mode; int retval; - if(fstat(bprm->fd, &st) < 0) { - return(-errno); + if (fstat(bprm->fd, &st) < 0) { + return -errno; } mode = st.st_mode; - if(!S_ISREG(mode)) { /* Must be regular file */ - return(-EACCES); + if (!S_ISREG(mode)) { /* Must be regular file */ + return -EACCES; } - if(!(mode & 0111)) { /* Must have at least one execute bit set */ - return(-EACCES); + if (!(mode & 0111)) { /* Must have at least one execute bit set */ + return -EACCES; } bprm->e_uid = geteuid(); bprm->e_gid = getegid(); /* Set-uid? */ - if(mode & S_ISUID) { + if (mode & S_ISUID) { bprm->e_uid = st.st_uid; } @@ -125,8 +123,8 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, } int loader_exec(int fdexec, const char *filename, char **argv, char **envp, - struct target_pt_regs * regs, struct image_info *infop, - struct linux_binprm *bprm) + struct target_pt_regs *regs, struct image_info *infop, + struct linux_binprm *bprm) { int retval; @@ -139,7 +137,7 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, retval = prepare_binprm(bprm); - if(retval>=0) { + if (retval >= 0) { if (bprm->buf[0] == 0x7f && bprm->buf[1] == 'E' && bprm->buf[2] == 'L' @@ -157,11 +155,11 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, } } - if(retval>=0) { + if (retval >= 0) { /* success. Initialize important registers */ do_init_thread(regs, infop); return retval; } - return(retval); + return retval; } From patchwork Sat Jun 19 03:43:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463855 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp534408jao; Fri, 18 Jun 2021 20:48:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoPpCQvzo21ASsOUitaCVRRvCglE2XM+lBLT7i0zWBiraMxJscy4VLV/jG68/0qQFsPKbM X-Received: by 2002:a5d:83ce:: with SMTP id u14mr10609219ior.45.1624074487044; Fri, 18 Jun 2021 20:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074487; cv=none; d=google.com; s=arc-20160816; b=etut9Q5nMdct23WjUtK0mPw24IDdAiHQ/xqKR74sEOtMLf7IyD0LdoUv2vItXzXQzR PdIH7JTJ8Fx2wRU7P0IpS0Uu8dWfRtmenptGy95Bti5GrRIPRI+jdUVv+t0X4iTkqwhL RUPGVfRALpwqcFaNaGeT+RMe/kNseqKgAsbm85ZRlbtHa61M9BzAzm/j05bWRY7xTLJA XvthKjAJWPhJnGZho/xDpgPsQBN+TGpqMx1hm5190n4jTLeK/K6RWa0WxyAvvYHUA06l G950Ogc/SxNaivoLBc0biLen1esx9ndH1qmx21Jo83Z8OHTs8vL2ZwyAert45loKK6Pb HDAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=+OXX5KjIYz/ZS9gLgWEfQeUt72TgJXhxPXE04khIgeU=; b=LcZyFwDZhS4/flgXZ9L0SjKkW7mmN9SlxZBChALVjWdzy6m1/xejttA6S+7aOSJm+m 0jXYUzq6FIOd+SZdEqs+AD9nXkX1wqSm99o0xcgGcHELBLAykGjNYI5LllFklehuGkhD HvoSW4o5jbd90SeJRWRHPml6CYnf3XyaRMSX0UiADkQzeyiPxL9oYUeLTMxgivQqfSNV 8rK4BVH+ZpbiFE1pmfl5gLKrxlzwWg0qoyrUkKTJ9MXLO2VXrkyN/FCP+92+TNy3O8g3 b0w+oTJraHSbkhmAPlet9+uYkegxvxsqRvA01AjipU5kEavxjQTp5QiVO8QbFnoIRhW5 sCCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="S/GO4BjO"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x20si12921691iov.0.2021.06.18.20.48.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:48:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="S/GO4BjO"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRxm-0001kj-E0 for patch@linaro.org; Fri, 18 Jun 2021 23:48:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtX-00008y-4T for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:44 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:35551) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtN-00081H-FJ for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:42 -0400 Received: by mail-pg1-x536.google.com with SMTP id v7so9460941pgl.2 for ; Fri, 18 Jun 2021 20:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+OXX5KjIYz/ZS9gLgWEfQeUt72TgJXhxPXE04khIgeU=; b=S/GO4BjOsoDKWuxkTN3vkKjQvtSHxdJU+cp65gGSYdH8lpEeAV5c7cnIL1WjBP4wdx 5nsJCXf8LFwN+xhblY2eeqDKUp0awxxIUOL3Nl8QFq0E5kUC7CUbWdbOmx3+r6zTjnmq xE7WG1Meb/uLClwRX5aQElP/TXMLeq3L/KtcyF+aMNcIZmRcGjmkFah5ybjrS5bzKgSn pLzUvvrbF7XszymWpihKOsGvH3tPeTqgrffuvJc8xP+qi5/QqYqicUk+CxRj8QVX8IbD dEG1dng/6O9bp/MSh5ML4bL8mFOoQsuZyojezQdT2PfHdQK2QUVTVTgzQgci0Q3PBfuC k2Sw== 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=+OXX5KjIYz/ZS9gLgWEfQeUt72TgJXhxPXE04khIgeU=; b=rHEJYOJDSM4QN514MkYLlvI49VA5XK6KDVvb7ig8PcQSGN1txmfKM02HigRkbohuUJ FNmPnyh5xqIRZ5JWjNOpvjbI1mMZUWl+INIavBuoxVePfztLr7gpJMFiVYSfVdapTxy3 hMUjc22fg2ZTnmxL/hDydNoUmxCYrNTesesuWN9irGwjiiCAfuEwwRqRwG3cs9FNO3dM FGiipcZph4HfbSNfMsuzHLHVIaJJMjQnob4CacX8iP+jfnsV45NFgjtLbbe3HIjFeO4r iHl+1VbvTTy+fnFb9MbUpzNNFWVtBkCp7d7HiufiMCxOvh6a5sbWz+liHL84wTph+h/Q NR3g== X-Gm-Message-State: AOAM531IJoxFI50f8jJma79HQN0+Rx7XYz3wqTBQZhAXaQVPO+6NEMI/ Tu26PuYSPHQ5L/Wy8m2ee3LrHqXWSuF+6A== X-Received: by 2002:aa7:962f:0:b029:2ed:cf:1f90 with SMTP id r15-20020aa7962f0000b02902ed00cf1f90mr8006496pfg.76.1624074211934; Fri, 18 Jun 2021 20:43:31 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 02/12] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Date: Fri, 18 Jun 2021 20:43:19 -0700 Message-Id: <20210619034329.532318-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Introduced and initialized, but not yet really used. These will tidy the current tests vs BPRM_BUF_SIZE. Signed-off-by: Richard Henderson --- linux-user/qemu.h | 50 ++++++++++++++++++++++++++++++++++-------- linux-user/linuxload.c | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 9 deletions(-) -- 2.25.1 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 9e5e2aa499..f4cdfb16b3 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -168,6 +168,37 @@ extern unsigned long mmap_min_addr; /* ??? See if we can avoid exposing so much of the loader internals. */ +typedef struct { + const void *cache; + unsigned int cache_size; + int fd; +} ImageSource; + +/** + * imgsrc_read: Read from ImageSource + * @dst: destination for read + * @offset: offset within file for read + * @len: size of the read + * @img: ImageSource to read from + * @errp: Error details. + * + * Read into @dst, using the cache when possible. + */ +bool imgsrc_read(void *dst, off_t offset, size_t len, + const ImageSource *img, Error **errp); + +/** + * imgsrc_read_alloc: Read from ImageSource + * @offset: offset within file for read + * @size: size of the read + * @img: ImageSource to read from + * @errp: Error details. + * + * Read into newly allocated memory, using the cache when possible. + */ +void *imgsrc_read_alloc(off_t offset, size_t len, + const ImageSource *img, Error **errp); + /* Read a good amount of data initially, to hopefully get all the program headers loaded. */ #define BPRM_BUF_SIZE 1024 @@ -177,15 +208,16 @@ extern unsigned long mmap_min_addr; * used when loading binaries. */ struct linux_binprm { - char buf[BPRM_BUF_SIZE] __attribute__((aligned)); - abi_ulong p; - int fd; - int e_uid, e_gid; - int argc, envc; - char **argv; - char **envp; - char * filename; /* Name of binary */ - int (*core_dump)(int, const CPUArchState *); /* coredump routine */ + char buf[BPRM_BUF_SIZE] __attribute__((aligned)); + ImageSource src; + abi_ulong p; + int fd; + int e_uid, e_gid; + int argc, envc; + char **argv; + char **envp; + char *filename; /* Name of binary */ + int (*core_dump)(int, const CPUArchState *); /* coredump routine */ }; typedef struct IOCTLEntry IOCTLEntry; diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 9d4eb5e94b..3b0bafc490 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -2,6 +2,7 @@ #include "qemu/osdep.h" #include "qemu.h" +#include "qapi/error.h" #define NGROUPS 32 @@ -74,6 +75,10 @@ static int prepare_binprm(struct linux_binprm *bprm) /* Make sure the rest of the loader won't read garbage. */ memset(bprm->buf + retval, 0, BPRM_BUF_SIZE - retval); } + + bprm->src.cache = bprm->buf; + bprm->src.cache_size = retval; + return retval; } @@ -129,6 +134,7 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, int retval; bprm->fd = fdexec; + bprm->src.fd = fdexec; bprm->filename = (char *)filename; bprm->argc = count(argv); bprm->argv = argv; @@ -163,3 +169,43 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, return retval; } + +bool imgsrc_read(void *dst, off_t offset, size_t len, + const ImageSource *img, Error **errp) +{ + ssize_t ret; + + if (offset + len <= img->cache_size) { + memcpy(dst, img->cache + offset, len); + return true; + } + + if (img->fd < 0) { + error_setg(errp, "read past end of buffer"); + return false; + } + + ret = pread(img->fd, dst, len, offset); + if (ret == len) { + return true; + } + if (ret < 0) { + error_setg_errno(errp, errno, "Error reading file header"); + } else { + error_setg(errp, "Incomplete read of file header"); + } + return false; +} + +void *imgsrc_read_alloc(off_t offset, size_t len, + const ImageSource *img, Error **errp) +{ + void *alloc = g_malloc(len); + bool ok = imgsrc_read(alloc, offset, len, img, errp); + + if (!ok) { + g_free(alloc); + alloc = NULL; + } + return alloc; +} From patchwork Sat Jun 19 03:43:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463853 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp533722jao; Fri, 18 Jun 2021 20:46:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzw1IATOVaaRo53ks6OwEpxTUxKnFdTSn6nqDQex2wIPkjJtm2S4XTJI/UKlooTFqqCDKMw X-Received: by 2002:a05:6e02:dc8:: with SMTP id l8mr9332790ilj.286.1624074404402; Fri, 18 Jun 2021 20:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074404; cv=none; d=google.com; s=arc-20160816; b=K5/AHOwo3PtCnUcegoxqyFY1I6SkgSgwUlzf6Urvtw01UJEcALe7jTFAzGtnqIkfK6 nzrkGWSojc94iSkiA/dNh2MHfEb+jaAHVtFTDo1K/XL8PbB5l3F/9wlpVbfd2Sc9cReJ JQ6T9ZDioPB1Rp2fKrm2IpKVob8admOuD05SixPqrfitCVwk/XuGvZJXfWNOD0YavGuV kWkP7ChTsmNtzg4HlnUkCM+2hlSvnBA5Ql+BH32M9pgv6fY2YCl27/7FfMQY/XrQPmYj Ow+qCVSiMKRMC/qTWMU6Jid81PPDyut1uGE/cc4MKz9VDJ+uy5snPQ2J2kxfd0/KZxtz aIpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=QrbeKgDr0Qimf/fLTiNrPtuYBtEMwhitINuZ4xKKmc01jdr4naWyuQYc14LzwgqkeC 0P39Ulxh7HmbCEhiUFL3oiSGrtGivYvahga23egACdg2hBrqk7yUudeKsrjN+hasIfuc Ltfd7OQ3KT2YZzJBE6kSPVXkLBxAVX66+q1Yv5Si/mcJwAphZPlLXVih08Hfu/KiEAcg sIJ8UhWij+GUAC45Ya8yo5NR4IJbIOVtQbLK3BpMDrR5UXcHtEe36ZHQA5j26zAJM0FR uvzshgof2jfvCu0uzb3MWvgCZx2QJDLUxGRcvDkdzv3I4ccTdE5bjSh46pslHQ9C0XxH Qfcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=B7DgDyNs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g10si10173279iok.45.2021.06.18.20.46.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:46:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=B7DgDyNs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRwR-0005nE-Pp for patch@linaro.org; Fri, 18 Jun 2021 23:46:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtW-00008S-J8 for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:42 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:44608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtN-00081L-QD for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:42 -0400 Received: by mail-pl1-x62c.google.com with SMTP id x22so4133218pll.11 for ; Fri, 18 Jun 2021 20:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=B7DgDyNsPlzK/y/kHNSUjiAzoQ+BvbREj7iI3LOJH8DD5nkMFIa3ehRtPeedKUMFjH Iigd7J7UxHGzekuObvChgosi/3s7KeLKnPYmpP+F1+SlnIbIe+USHiKhGvN2nh4qTnHH 0fa8kNUf5r3Ib3QjcYj8w3FPmLsuL1zRZhwQLXibnXRDkvc8p1DUfZGKiq0xhqTZ7BDV UjlXAlBTF657xmCpupqVrnzuW1Gl/Ai4aM+coDhwuIY0aT60S9eRtbyQ/DcDc/aUIoD5 nBWe0NJ7G5onuyx36v6v57MVme+2dRzbQilWaLHpggWxhRzmJGvvgAB6I+KAP3Wq+02U US1A== 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=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=enxD4EweCsRrlzL4U/nzG/vB63CaBoY0n10C2rT6Rq8unowXNvl3uuW+u9kTCl+bGC Y51YE9BiXnhczCrdfJkfyfdo1AbLMDQOOdABdmdBP9SdVG1NklBvNsi7fXJ26m0EkEAX kelKT7Am4FK1KXIbmR0ANmfsIAv3kOCet8N0OKyb0DO1QB1XueoygMp/Ot4KQjsDKMdp pqlxtvGmNkJn6k8YhqZwuVEODMS5A684Yg1fxAiPX5YHAs5AVaWGx09VIoke8UH8Igvr AXMJAJ8802JFIZzd2sMklEySuKHM3u5AnZIXRTopsPBjYCov3LkxdpXwESgU2jAOqPrZ tvBQ== X-Gm-Message-State: AOAM530pex/2BnZM5w+h44VgW9YMLAjgugzJBmM1R2qv3SH/u8tcmXRt kCNbXu8/EWLSIUyBH+u9HrevpwA8SmhHcA== X-Received: by 2002:a17:90a:31c4:: with SMTP id j4mr25823220pjf.105.1624074212535; Fri, 18 Jun 2021 20:43:32 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 03/12] linux-user: Tidy loader_exec Date: Fri, 18 Jun 2021 20:43:20 -0700 Message-Id: <20210619034329.532318-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Signed-off-by: Richard Henderson --- linux-user/linuxload.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) -- 2.25.1 diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 3b0bafc490..8b93b9704c 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -143,31 +143,31 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **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, infop); -#if defined(TARGET_HAS_BFLT) - } else if (bprm->buf[0] == 'b' - && bprm->buf[1] == 'F' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'T') { - retval = load_flt_binary(bprm, infop); -#endif - } else { - return -ENOEXEC; - } + if (retval < 4) { + return -ENOEXEC; } - - if (retval >= 0) { - /* success. Initialize important registers */ - do_init_thread(regs, infop); + if (bprm->buf[0] == 0x7f + && bprm->buf[1] == 'E' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'F') { + retval = load_elf_binary(bprm, infop); +#if defined(TARGET_HAS_BFLT) + } else if (bprm->buf[0] == 'b' + && bprm->buf[1] == 'F' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'T') { + retval = load_flt_binary(bprm, infop); +#endif + } else { + return -ENOEXEC; + } + if (retval < 0) { return retval; } - return retval; + /* Success. Initialize important registers. */ + do_init_thread(regs, infop); + return 0; } bool imgsrc_read(void *dst, off_t offset, size_t len, From patchwork Sat Jun 19 03:43:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463851 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp532771jao; Fri, 18 Jun 2021 20:44:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVTSfILeNgqCLXFHb0DFgwup33wn1h8y/+heTTANv+QxfpTb6pqfV8678utgr7Fj76tl3b X-Received: by 2002:a05:6e02:5ac:: with SMTP id k12mr9667803ils.29.1624074270572; Fri, 18 Jun 2021 20:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074270; cv=none; d=google.com; s=arc-20160816; b=A/stM7sVUp7iP8LFtP8uXW3nm3ly1Y7c0eBR6zxbV5++Nk+ZeSWICANArBNf5Ju/zY rTluXhnwfBydXTekLitKZjk3ih4A/hEGFe3AvcAewUAEYkcsCKgk80V0bZ/ZQb6MSCdQ a9+TiUsPgXaX5SLPsm5XkPtk8D2XXuEZ3jdy7Y0zvVnsZkKre/oo8AQ6F+dWfLBGcc5B sRn5Uqn9npGADj6bwkrlGSi+jWyPhBbtYYNIJYSX60ICeTqwWoboX/6U7lJ/xM/PL5eo H47okuvl47nZy82hRsafBXsYqZ4DMFCS9G69xNbGJ3vARF3PUKqiVO3VFnSlnCTIpkUK LoYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=dtXXZ8iOGwpaQfUOm6DW075wk6Tcr8F02y3NmtzbotE=; b=DD1N56MS4yTjbTa/FDU+mfWLLkq4ksAFtFn5a0xaidQvYHq2P6B86iw6URXS354G9P +D7AaP5NsrnZknOkKIxl30fMl5dut9w3GmOCoHHJdNJcbXmUyyxFv/47fmaOLLJNyoBg MoAqCGD3jLUnwVVt8ehg2JjziBwfq1dFzqL18vb4H25PsNhHIIGAFhohdORD6wgfmcZN OIEqV46grNAd4qptZ/30rx+fTI6uAe2vhf7x8rX/jlASdJNeyJf1RDR682Q1N8aQekxt N+Uergo3IHXbH25r5VpzOckQy3+vRETFm/FsF/eWa/vTrFRd3E0L09AUqt263UF2SYuL csOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oma6t+J6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m1si3962918ilj.142.2021.06.18.20.44.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:44:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oma6t+J6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRuH-0000Hl-VQ for patch@linaro.org; Fri, 18 Jun 2021 23:44:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtV-00008J-UW for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:42 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:33643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtP-00081j-10 for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:41 -0400 Received: by mail-pl1-x630.google.com with SMTP id f10so3546124plg.0 for ; Fri, 18 Jun 2021 20:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dtXXZ8iOGwpaQfUOm6DW075wk6Tcr8F02y3NmtzbotE=; b=oma6t+J6HZwI1G5DffLzF9PdZihCwD5yizlAwk/JNOeRv87FMG5v7B0Z2dDbC9HE89 Z6xSQ7iqyjumfDXLJXzPcja39w00px12wHyMDdPSBZhDLv4/dHRQoKL8UCsHma1x+PWe fuHGI34Q7+flia9cmetY6Srz5n8cM78tuSECthmNFBgzX84vya9Bwzkwq0UCLsT1XEst WI+q0u32TD4lkOWVkwFQ9RHH55TOl1zpYqQpoNnHjMCHN9gqij31Od2Pi37OlJb/YRk4 40qs51WYJrtDIwHqZjM+ZMPomVzhRJRQnKVUa0dR/JXedD6BYYnFCCVDOq8z8XBEtz6/ ChQw== 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=dtXXZ8iOGwpaQfUOm6DW075wk6Tcr8F02y3NmtzbotE=; b=ZxTnEh6NYxlyajyhfS7vttjsGcSu1MIe0FaNG5K68UwWBs2ONs0Jmr59bSdU5NRinZ SXw3YLZVuKMwvhpOL7q1H8ezKu4WAB6YfdXGsCEBrmImpE201salactNEcD14e9XUydm soj1n9zX3CkjHUGGWWoZSPu41KqcgAH8gQ5Rf5NM9EP3eJwbKFj5SSw6Kzj8yqtIFHdp NeRQqj+OBeiZHHaTa1whNr8BlNggxbw+noSWsWpXviuMrS3bv7fwBfav1hn5JmuzO609 0fSr4elzCqLBrGUPFGkvCt8bhLxaecg2k+H2SZywXL2U52F7pFkTY2+/jUgEV87HFIMU s7Eg== X-Gm-Message-State: AOAM532YThW1H56D94Jm4MytKYld5KDkwyrBH6IAv9hzbBzysmsW48gZ hhUALpvUVT2gSDYXonb+xWNxi1y02iK25A== X-Received: by 2002:a17:90b:393:: with SMTP id ga19mr14289824pjb.182.1624074213153; Fri, 18 Jun 2021 20:43:33 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 04/12] linux-user: Do not clobber bprm_buf swapping ehdr Date: Fri, 18 Jun 2021 20:43:21 -0700 Message-Id: <20210619034329.532318-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rearrange the allocation of storage for ehdr between load_elf_image and load_elf_binary. The same set of copies are done, but we don't modify bprm_buf, which will be important later. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c0236a0b09..1f9a69703a 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2622,16 +2622,17 @@ static bool parse_elf_properties(int image_fd, On return: INFO values will be filled in, as necessary or available. */ static void load_elf_image(const char *image_name, int image_fd, - struct image_info *info, char **pinterp_name, + struct image_info *info, struct elfhdr *ehdr, + char **pinterp_name, char bprm_buf[BPRM_BUF_SIZE]) { - struct elfhdr *ehdr = (struct elfhdr *)bprm_buf; struct elf_phdr *phdr; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; int i, retval, prot_exec; Error *err = NULL; /* First of all, some simple consistency checks */ + memcpy(ehdr, bprm_buf, sizeof(*ehdr)); if (!elf_check_ident(ehdr)) { error_setg(&err, "Invalid ELF image for this architecture"); goto exit_errmsg; @@ -2944,6 +2945,7 @@ static void load_elf_image(const char *image_name, int image_fd, static void load_elf_interp(const char *filename, struct image_info *info, char bprm_buf[BPRM_BUF_SIZE]) { + struct elfhdr ehdr; int fd, retval; Error *err = NULL; @@ -2965,7 +2967,7 @@ static void load_elf_interp(const char *filename, struct image_info *info, memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); } - load_elf_image(filename, fd, info, NULL, bprm_buf); + load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf); } static int symfind(const void *s0, const void *s1) @@ -3157,8 +3159,14 @@ uint32_t get_elf_eflags(int fd) int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) { + /* + * We need a copy of the elf header for passing to create_elf_tables. + * We will have overwritten the original when we re-use bprm->buf + * while loading the interpreter. Allocate the storage for this now + * and let elf_load_image do any swapping that may be required. + */ + struct elfhdr ehdr; struct image_info interp_info; - struct elfhdr elf_ex; char *elf_interpreter = NULL; char *scratch; @@ -3170,12 +3178,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) info->start_mmap = (abi_ulong)ELF_START_MMAP; load_elf_image(bprm->filename, bprm->fd, info, - &elf_interpreter, bprm->buf); - - /* ??? We need a copy of the elf header for passing to create_elf_tables. - If we do nothing, we'll have overwritten this when we re-use bprm->buf - when we load the interpreter. */ - elf_ex = *(struct elfhdr *)bprm->buf; + &ehdr, &elf_interpreter, bprm->buf); /* Do this so that we can load the interpreter, if need be. We will change some of these later */ @@ -3245,7 +3248,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC); } - bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &elf_ex, + bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info, (elf_interpreter ? &interp_info : NULL)); info->start_stack = bprm->p; From patchwork Sat Jun 19 03:43:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463859 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp536860jao; Fri, 18 Jun 2021 20:53:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyh+/CVfRxAOc2ClRnM5VmHzChu8suLjvXi6t++2CK3/JWLu1kJMnrRITn5hcIQ/Oyw0eUK X-Received: by 2002:a92:cb02:: with SMTP id s2mr9858411ilo.256.1624074819332; Fri, 18 Jun 2021 20:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074819; cv=none; d=google.com; s=arc-20160816; b=Ca+jDXshXY1PHbT8bC0sTI0Z5RpyYAazDGbOmyIRt5nQLg6U9oogbyCf5zOwsz+ir0 t1omThM8LAGZBLIp50PMEnYRLbB2ULuJgZLfYRCTHTyh8VQwVwgoRiHQl7+RKsc1qfKl GvMwNy+HepiHBjnYfmM96ofSWwjCMNzOA9rsH/z3NqsiwG1SOUtrtNQCxqde4w5tgk+k Z5YXwTzcuXoq4uIPFrsFkXfBOrFicWguy1uivnrcPFZkx3KdVm/H8PGf69AF8lS63hEZ pkXcuAT5tBq5lRAiRVvC9fowHUM6j3+8f6K0OaN19bO4wvkT/wd8CX/0W50xNCvze860 wOwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=8e5E/z+pH2CRQ8YHwtnQOyFDongtbxSl8xpH1CVFvZE=; b=W8gmnrfcxWAw7RkKLKZJEJvueiE3wBXLh81YuCVHLp2XMeVIMV2SscBMWLHl8XVQ2v fufay42aKqJq6AUuE8qBRc7hnn/gHMV//kRlhpRVFinVat2JlSBpXEIHa/hFIo20g37T tNC5hFuq9LCM0R0lQ0RDj7A23KN8cIaLOIDYQnk8qNd5LRiGss7X9nW0xOkvzPIpFgEi El7omQf0qYUbbCDll9i6IBnij2CFDw3pT4gjdCwjFp6pWgBoKaW91CD1vGkE1tcvetuU xivPnFpyDC4OetLEpzgDfkeRBI/wtHHEkwsBSeLZr/Ha5sgm07c0pic/lObM78PLYWtE vUiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rxgkwup7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q16si11245407jat.124.2021.06.18.20.53.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:53:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rxgkwup7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luS38-00017A-MO for patch@linaro.org; Fri, 18 Jun 2021 23:53:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtd-0000Ft-UO for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:49 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:36744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtP-000828-1M for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:49 -0400 Received: by mail-pg1-x531.google.com with SMTP id e33so9455258pgm.3 for ; Fri, 18 Jun 2021 20:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8e5E/z+pH2CRQ8YHwtnQOyFDongtbxSl8xpH1CVFvZE=; b=rxgkwup73HhdSZG1sioe3h2l9TZqUGcR0WDnA315Q0+IFMjuPiO2vBXdF1Cc+2MLMb sO/aM8SMbPSeLnF5x4GE1ob6RtZY24/nzsJ1LdP9KetmfTPLi0LXBLMaKDFDbYZEuv1e yEK/B25kamA+etydZ5h0M6+12uC1y5/nF5tMT90TzSmnaGtxQ6a3/wTU3kaJwAT8RUuR 6vJbBuV0GtqWQ5K4ZFKIpxIOTPOxznT5FgBwcUtTXKkEOm0GWAe4s45x7svU1KuVgTZ6 qlSGntoAv7rRTI7yVpY0+oa3li9bXvT4NPcoPgd7zXG2HyivJgW7O/9/q0foxMhWN6YR 3u4w== 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=8e5E/z+pH2CRQ8YHwtnQOyFDongtbxSl8xpH1CVFvZE=; b=CdSaGsRmrVIogqZ1Ex25mS7nW4LZpkTHk+Ywg91NXbiB8LzEzzQh64OoLNJ1beI6Y+ znFTL8K8FeF03TAInhwOJ6bbOQWmtcW+sFvHS5Pp0uR2dVbfGm2yuvT4sMcpuxH08fKX xwA7DksjDqm1y3KLSIFxzYl46jBgO8y1v9C34HdvEMyTI2qqVEgFi3+/oF/N0glRZh2A R5H0puokWap7TYlWc/henTgHKzr7R1ga6LzkuOwTSD2zGjFfd4OVml71M9sRAArA/oHN APEfGYFt057Fj7bZOiYM5Q2FghpQr4H4NyS6SAcsRj/NshK/mC1r9dxHmnx3/xm+sM/u UTtQ== X-Gm-Message-State: AOAM533HnNkJbf0selZvohJh2DAi3wnDTc3/JfiVpb+4/O8ivnPrrWYb i9aNa5zp/aj6k1f18rCg9c1I/VrjHBjTiw== X-Received: by 2002:aa7:8c59:0:b029:301:81b0:16ee with SMTP id e25-20020aa78c590000b029030181b016eemr616338pfd.24.1624074213787; Fri, 18 Jun 2021 20:43:33 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 05/12] linux-user: Use ImageSource in load_elf_image Date: Fri, 18 Jun 2021 20:43:22 -0700 Message-Id: <20210619034329.532318-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Change parse_elf_properties as well, as the bprm_buf argument ties the two functions closely. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 124 ++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 77 deletions(-) -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 1f9a69703a..425420f0cc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2525,10 +2525,9 @@ static bool parse_elf_property(const uint32_t *data, int *off, int datasz, } /* Process NT_GNU_PROPERTY_TYPE_0. */ -static bool parse_elf_properties(int image_fd, +static bool parse_elf_properties(const ImageSource *src, struct image_info *info, const struct elf_phdr *phdr, - char bprm_buf[BPRM_BUF_SIZE], Error **errp) { union { @@ -2556,14 +2555,8 @@ static bool parse_elf_properties(int image_fd, return false; } - if (phdr->p_offset + n <= BPRM_BUF_SIZE) { - memcpy(¬e, bprm_buf + phdr->p_offset, n); - } else { - ssize_t len = pread(image_fd, ¬e, n, phdr->p_offset); - if (len != n) { - error_setg_errno(errp, errno, "Error reading file header"); - return false; - } + if (!imgsrc_read(¬e, phdr->p_offset, n, src, errp)) { + return false; } /* @@ -2609,30 +2602,34 @@ static bool parse_elf_properties(int image_fd, } } -/* Load an ELF image into the address space. +/** + * load_elf_image: Load an ELF image into the address space. + * @image_name: the filename of the image, to use in error messages. + * @src: the ImageSource from which to read. + * @info: info collected from the loaded image. + * @ehdr: the ELF header, not yet bswapped. + * @pinterp_name: record any PT_INTERP string found. + * + * On return: @info values will be filled in, as necessary or available. + */ - IMAGE_NAME is the filename of the image, to use in error messages. - IMAGE_FD is the open file descriptor for the image. - - BPRM_BUF is a copy of the beginning of the file; this of course - contains the elf file header at offset 0. It is assumed that this - buffer is sufficiently aligned to present no problems to the host - in accessing data at aligned offsets within the buffer. - - On return: INFO values will be filled in, as necessary or available. */ - -static void load_elf_image(const char *image_name, int image_fd, +static void load_elf_image(const char *image_name, const ImageSource *src, struct image_info *info, struct elfhdr *ehdr, - char **pinterp_name, - char bprm_buf[BPRM_BUF_SIZE]) + char **pinterp_name) { - struct elf_phdr *phdr; + g_autofree struct elf_phdr *phdr = NULL; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; - int i, retval, prot_exec; + int i, prot_exec; Error *err = NULL; - /* First of all, some simple consistency checks */ - memcpy(ehdr, bprm_buf, sizeof(*ehdr)); + /* + * First of all, some simple consistency checks. + * Note that we rely on the bswapped ehdr staying in bprm_buf, + * for later use by load_elf_binary and create_elf_tables. + */ + if (!imgsrc_read(ehdr, 0, sizeof(*ehdr), src, &err)) { + goto exit_errmsg; + } if (!elf_check_ident(ehdr)) { error_setg(&err, "Invalid ELF image for this architecture"); goto exit_errmsg; @@ -2643,15 +2640,11 @@ static void load_elf_image(const char *image_name, int image_fd, goto exit_errmsg; } - i = ehdr->e_phnum * sizeof(struct elf_phdr); - if (ehdr->e_phoff + i <= BPRM_BUF_SIZE) { - phdr = (struct elf_phdr *)(bprm_buf + ehdr->e_phoff); - } else { - phdr = (struct elf_phdr *) alloca(i); - retval = pread(image_fd, phdr, i, ehdr->e_phoff); - if (retval != i) { - goto exit_read; - } + phdr = imgsrc_read_alloc(ehdr->e_phoff, + ehdr->e_phnum * sizeof(struct elf_phdr), + src, &err); + if (phdr == NULL) { + goto exit_errmsg; } bswap_phdr(phdr, ehdr->e_phnum); @@ -2687,17 +2680,10 @@ static void load_elf_image(const char *image_name, int image_fd, goto exit_errmsg; } - interp_name = g_malloc(eppnt->p_filesz); - - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { - memcpy(interp_name, bprm_buf + eppnt->p_offset, - eppnt->p_filesz); - } else { - retval = pread(image_fd, interp_name, eppnt->p_filesz, - eppnt->p_offset); - if (retval != eppnt->p_filesz) { - goto exit_read; - } + interp_name = imgsrc_read_alloc(eppnt->p_offset, eppnt->p_filesz, + src, &err); + if (interp_name == NULL) { + goto exit_errmsg; } if (interp_name[eppnt->p_filesz - 1] != 0) { error_setg(&err, "Invalid PT_INTERP entry"); @@ -2705,7 +2691,7 @@ static void load_elf_image(const char *image_name, int image_fd, } *pinterp_name = g_steal_pointer(&interp_name); } else if (eppnt->p_type == PT_GNU_PROPERTY) { - if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { + if (!parse_elf_properties(src, info, eppnt, &err)) { goto exit_errmsg; } } @@ -2847,7 +2833,7 @@ static void load_elf_image(const char *image_name, int image_fd, vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED, - image_fd, eppnt->p_offset - vaddr_po); + src->fd, eppnt->p_offset - vaddr_po); if (error == -1) { goto exit_mmap; @@ -2893,20 +2879,11 @@ static void load_elf_image(const char *image_name, int image_fd, #ifdef TARGET_MIPS } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; - if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) { - error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry"); + + if (!imgsrc_read(&abiflags, eppnt->p_offset, sizeof(abiflags), + src, &err)) { goto exit_errmsg; } - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { - memcpy(&abiflags, bprm_buf + eppnt->p_offset, - sizeof(Mips_elf_abiflags_v0)); - } else { - retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0), - eppnt->p_offset); - if (retval != sizeof(Mips_elf_abiflags_v0)) { - goto exit_read; - } - } bswap_mips_abiflags(&abiflags); info->fp_abi = abiflags.fp_abi; #endif @@ -2919,21 +2896,14 @@ static void load_elf_image(const char *image_name, int image_fd, } if (qemu_log_enabled()) { - load_symbols(ehdr, image_fd, load_bias); + load_symbols(ehdr, src->fd, load_bias); } mmap_unlock(); - close(image_fd); + close(src->fd); return; - exit_read: - if (retval >= 0) { - error_setg(&err, "Incomplete read of file header"); - } else { - error_setg_errno(&err, errno, "Error reading file header"); - } - goto exit_errmsg; exit_mmap: error_setg_errno(&err, errno, "Error mapping file"); goto exit_errmsg; @@ -2946,6 +2916,7 @@ static void load_elf_interp(const char *filename, struct image_info *info, char bprm_buf[BPRM_BUF_SIZE]) { struct elfhdr ehdr; + ImageSource src; int fd, retval; Error *err = NULL; @@ -2963,11 +2934,11 @@ static void load_elf_interp(const char *filename, struct image_info *info, exit(-1); } - if (retval < BPRM_BUF_SIZE) { - memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); - } + src.fd = fd; + src.cache = bprm_buf; + src.cache_size = retval; - load_elf_image(filename, fd, info, &ehdr, NULL, bprm_buf); + load_elf_image(filename, &src, info, &ehdr, NULL); } static int symfind(const void *s0, const void *s1) @@ -3177,8 +3148,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) info->start_mmap = (abi_ulong)ELF_START_MMAP; - load_elf_image(bprm->filename, bprm->fd, info, - &ehdr, &elf_interpreter, bprm->buf); + load_elf_image(bprm->filename, &bprm->src, info, &ehdr, &elf_interpreter); /* Do this so that we can load the interpreter, if need be. We will change some of these later */ From patchwork Sat Jun 19 03:43:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463857 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp535123jao; Fri, 18 Jun 2021 20:49:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2MSTOu/2CG1/UrqJuij4eRhpo35wXiKWB3sjb4K78r0uWyNyMZjKR4Ps8BPhEJZg/zG5J X-Received: by 2002:a92:d601:: with SMTP id w1mr9598188ilm.1.1624074587853; Fri, 18 Jun 2021 20:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074587; cv=none; d=google.com; s=arc-20160816; b=SzRZg8OYGdk4Z3DrQNgfVdVovAmMG+I1KWUE8O/ybkfG03TzF+eZWSqZKBZ/sWNAPJ MeZfhX2YMBhCslKBUDRQb2RlBg1/4/6ySLNmg8gz7gH9+7oY4xXtil+g7Nw9zl6DqhWS X9jOt/+WX7o3cohwP3Y0mHkWVK7O42CxGUQtn8QzD+4AaagNoyOermd2TgVsByOGu0RU gUsNpXxb2JXNiF87HVI8AfhnEv71EYtpVdISYD+tZGWbZzF1lPI5fQmNWaBdh4+9KOq4 FVuyDCwHVraTbcHQVrRsKO2CJWourkW92Ns6teD79IkUO3eBou3iom7VsIKU1S1n5nmC GCQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=C8iPVs7HJyqae3VBQhrLESrT2Lay4oj3eIp3fHt5b/o=; b=TXpuX4GvVvz9dGdKpGTwv2V7FzwyMnDp8E8izb4NywfD540BpBIhkzWYaiXzqdIbMz pgSSLzAzFME2juOkhJd+81oAvXzQwtRK7Gtznyj6kF606qnlmESjsq+nqKTK+42ivbgK RO1hGTbt5WFki4/GUW249iWxxoWzeHpbIyyuBtXeRO+tccjScXPqZt9mDvZEDBBx0tM/ h/ZKEcwM722B4IK8dla47roOe/vy6Jecc4/q9JcvOwIRUujELJWwbx6MkdpPG1swy2Ds bHyhQgcmJQ8La3LNVpWW5ZwDLNuRxYDikEvcH3QE60NcHLeYY/oY6ezxJyZGRGmKvlw7 5/MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JiaXbgl2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i12si11676717jal.25.2021.06.18.20.49.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JiaXbgl2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRzP-0005wI-B0 for patch@linaro.org; Fri, 18 Jun 2021 23:49:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtZ-00009P-Dn for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:45 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:44000) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtQ-00082H-Ub for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:44 -0400 Received: by mail-pj1-x102f.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso7040285pjp.2 for ; Fri, 18 Jun 2021 20:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C8iPVs7HJyqae3VBQhrLESrT2Lay4oj3eIp3fHt5b/o=; b=JiaXbgl2DWOceQh6kfQsIWz94H9ekP2VWAVw7TZlaEofnW6twKumQxksUu7/kJCHqn NWpDVMu/93kCjkRpvunqxirpLkLQ/sSNGpWTab0o+hQmovPinSX6ehPMNruF8r23uNnd FZeNnQ14wCvGlu0T/YKfvSHJpwQK1JeWsRna1Qn3TEAJvJCLPBNWsTmfQLw4F2Tu7rvp kkqds0qCpjquzWSeXEgxXKqsxwGO9OgRMpCp0ih2dnMYm9agoE/GTIQq1BLblYSRo4G1 B7y8cJ7MiTqcjmHlQxchukS9QrT8NasRlxms+mfHTtHTujQI+4i/4J1d4BWlT/Z3iYa7 Ljew== 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=C8iPVs7HJyqae3VBQhrLESrT2Lay4oj3eIp3fHt5b/o=; b=me9Ok5qWuhCypw0PCaQi1odwH4CbKQ/+UcKuDS8u76j/QVmG5YzHS3hzt2H4uJa4ef AHvpWzTgB5FZvlqz0V2YX+NbqYPv5po8cQza3KAq2SgiatmKHOrZH0xjiQ88rxG6oJPy 9TEyZMw0feMGvjdLZ2+AXE3o3snkTwjgjCVSihlheXO8w9OX6OHjp8BSK6zjzqdoPNgm MxtwJx0FEbnd6uB6tFoZVQ6B42sy1mWwD1MKsd+bFOHNFBAYcNYMw6yK7d7hrh1DqUCR S4a9URqmQ8RkclT44wvztDfI3kVBN325wak5JG83bx1oZF3ZHIVTNe4wYbN+rDnVqyNA ZxKg== X-Gm-Message-State: AOAM530KPENnoB4f00p32gVOg6R5ojwgcKs69NW0YwrOo67M2wXaJ2yw +0WXAwrAVH/maz18OwwLB7gM2ndM6TQnpA== X-Received: by 2002:a17:90a:b795:: with SMTP id m21mr14491730pjr.143.1624074214390; Fri, 18 Jun 2021 20:43:34 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 06/12] linux-user: Use ImageSource in load_symbols Date: Fri, 18 Jun 2021 20:43:23 -0700 Message-Id: <20210619034329.532318-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Aside from the section headers, we're unlikely to hit the ImageSource cache on guest executables. But the interface for imgsrc_read_* is better. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 87 ++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 39 deletions(-) -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 425420f0cc..3c31a5e3b0 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1729,7 +1729,8 @@ static inline void bswap_mips_abiflags(Mips_elf_abiflags_v0 *abiflags) { } #ifdef USE_ELF_CORE_DUMP static int elf_core_dump(int, const CPUArchState *); #endif /* USE_ELF_CORE_DUMP */ -static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias); +static void load_symbols(struct elfhdr *hdr, const ImageSource *src, + abi_ulong load_bias); /* Verify the portions of EHDR within E_IDENT for the target. This can be performed before bswapping the entire header. */ @@ -2896,7 +2897,7 @@ static void load_elf_image(const char *image_name, const ImageSource *src, } if (qemu_log_enabled()) { - load_symbols(ehdr, src->fd, load_bias); + load_symbols(ehdr, src, load_bias); } mmap_unlock(); @@ -2984,19 +2985,20 @@ static int symcmp(const void *s0, const void *s1) } /* Best attempt to load symbols from this ELF object. */ -static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) +static void load_symbols(struct elfhdr *hdr, const ImageSource *src, + abi_ulong load_bias) { int i, shnum, nsyms, sym_idx = 0, str_idx = 0; - uint64_t segsz; - struct elf_shdr *shdr; + g_autofree struct elf_shdr *shdr = NULL; char *strings = NULL; - struct syminfo *s = NULL; - struct elf_sym *new_syms, *syms = NULL; + struct elf_sym *syms = NULL; + struct elf_sym *new_syms; + uint64_t segsz; shnum = hdr->e_shnum; - i = shnum * sizeof(struct elf_shdr); - shdr = (struct elf_shdr *)alloca(i); - if (pread(fd, shdr, i, hdr->e_shoff) != i) { + shdr = imgsrc_read_alloc(hdr->e_shoff, shnum * sizeof(struct elf_shdr), + src, NULL); + if (shdr == NULL) { return; } @@ -3014,31 +3016,33 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) found: /* Now know where the strtab and symtab are. Snarf them. */ - s = g_try_new(struct syminfo, 1); - if (!s) { - goto give_up; - } segsz = shdr[str_idx].sh_size; - s->disas_strtab = strings = g_try_malloc(segsz); - if (!strings || - pread(fd, strings, segsz, shdr[str_idx].sh_offset) != segsz) { + strings = g_try_malloc(segsz); + if (!strings) { + goto give_up; + } + if (!imgsrc_read(strings, shdr[str_idx].sh_offset, segsz, src, NULL)) { goto give_up; } segsz = shdr[sym_idx].sh_size; - syms = g_try_malloc(segsz); - if (!syms || pread(fd, syms, segsz, shdr[sym_idx].sh_offset) != segsz) { - goto give_up; - } - if (segsz / sizeof(struct elf_sym) > INT_MAX) { - /* Implausibly large symbol table: give up rather than ploughing - * on with the number of symbols calculation overflowing + /* + * Implausibly large symbol table: give up rather than ploughing + * on with the number of symbols calculation overflowing. */ goto give_up; } nsyms = segsz / sizeof(struct elf_sym); + syms = g_try_malloc(segsz); + if (!syms) { + goto give_up; + } + if (!imgsrc_read(syms, shdr[sym_idx].sh_offset, segsz, src, NULL)) { + goto give_up; + } + for (i = 0; i < nsyms; ) { bswap_sym(syms + i); /* Throw away entries which we do not need. */ @@ -3063,10 +3067,12 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) goto give_up; } - /* 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 = g_try_renew(struct elf_sym, syms, nsyms); if (new_syms == NULL) { goto give_up; @@ -3075,20 +3081,23 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) qsort(syms, nsyms, sizeof(*syms), symcmp); - s->disas_num_syms = nsyms; -#if ELF_CLASS == ELFCLASS32 - s->disas_symtab.elf32 = syms; -#else - s->disas_symtab.elf64 = syms; -#endif - s->lookup_symbol = lookup_symbolxx; - s->next = syminfos; - syminfos = s; + { + struct syminfo *s = g_new(struct syminfo, 1); + s->disas_strtab = strings; + s->disas_num_syms = nsyms; +#if ELF_CLASS == ELFCLASS32 + s->disas_symtab.elf32 = syms; +#else + s->disas_symtab.elf64 = syms; +#endif + s->lookup_symbol = lookup_symbolxx; + s->next = syminfos; + syminfos = s; + } return; -give_up: - g_free(s); + give_up: g_free(strings); g_free(syms); } From patchwork Sat Jun 19 03:43:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463850 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp532575jao; Fri, 18 Jun 2021 20:44:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDpqv0qfFM7WJ7xobnt4lna4lNPzNBFsd8IKBQikMaOuhD0EEtImG+q27Ueo25mImizICR X-Received: by 2002:a92:200a:: with SMTP id j10mr9472197ile.251.1624074242717; Fri, 18 Jun 2021 20:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074242; cv=none; d=google.com; s=arc-20160816; b=cP8cdOn4LGaPDMsRY9xzbMA6ER3EoFfVUtJV6JWnQI0+6WEuA+3S77sKVNMrrNcLde atNcrDC+RWCYhuAWQApYL9TKvOb8bvEPdrlcwlLPW6BoSD5nQfuHoHAJIjC2DTluXEGq zw5wb9YHSWyHXSWwnYkTrrn+8opLl+TXuqcF8JKakavirKyota6IovJPC9LiGFezUIA6 3lTuUimdy0PYLU0E7Q3Aqb+ZNnyFlzkORC9eC8yTaqKiFdIZDqAxiiFn1LKPZ1Cr8XcL hbZjaVekHKjemKOfzwX+L+Pb4DqqdaeOMNbwpt4H3kH2SdHpYCIejpB65owfPzMN78vo Suhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=YC2foJgnALUaFU8F6U+DDhXWrRa+DNA7R4W0GBliIEU=; b=YM9Kan1UZDBQxzOTE9oh0qnBL3mJbOX1EKivzExKsELz3eSPQvZG/9RCdAbNGcZL1j wQFF1S6/OMEpSXGHTlVhHeTw3kZtUirstkxXHaKQ0fc5j82kEPMRbzcGMjrFb7C9ST0+ 8yJgXuoa7pBU66gy+gBK1STchreUTq3VGWfu+bmtXN7S8NWR/dNSG7fHQTMKQVEaFWXF YV0L3zPmjOtFKwzYiqNb+c/WDGN2QC16J8Bm2PyEhUJyLNJOxlIKluPpYoopvlBwyboX 1arHtHSQYNRC2RutljmdeTYJteclmnAwur800YDacLH5PAZu7uVagFr0t2msdGM3v6Df UkHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AausL1d+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u21si10929541jak.34.2021.06.18.20.44.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AausL1d+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRtq-0000GA-66 for patch@linaro.org; Fri, 18 Jun 2021 23:44:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtZ-00009Q-ER for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:45 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:35474) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtQ-00082N-Ui for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:45 -0400 Received: by mail-pf1-x42b.google.com with SMTP id h12so9240416pfe.2 for ; Fri, 18 Jun 2021 20:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YC2foJgnALUaFU8F6U+DDhXWrRa+DNA7R4W0GBliIEU=; b=AausL1d+dIJbIcyEOLHzxetr1Gqs9u+R7IU/7/O6HOHcDY6VmHkcsTmnLF0ftUhZXr CaVdpZZarNPBlqUYHdfm84aMZzY08JLzSu8wrn90TaGgrE4zyRP32zHXyNDP0a7jvPWu Sq+sGVKlzgyrqnMmcAnfGhl07KJU66O3AOdNdkeCYVsOk42Ay/EQKbkfKM6Kqyyp3Wrd O8YuuLwluwzAzwH6yk8sB6JXXBFr8ibNEpiEz3JwtGv4KhfY/ukvW3OIJjWxkIlrZaCt pUtbLl8PhZyYqcdecCJgA8nTLbRa4b1yqfGJgaecnB/4jyIjBMQ+r68lBxL9jerEK4mH Ak+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=YC2foJgnALUaFU8F6U+DDhXWrRa+DNA7R4W0GBliIEU=; b=RiQFF5vfXoyFo8u5CCIC5vxUELsCDnkwxKbUx10jErAObix2tXmuAYWwulLtRAsfTq OdkbWh9X3Kqz9PmrHhVIqyoYhXpMrMLNXI0S0KMWKLWwN1qxrqmPxz9AXiF/sCvtI3B7 HctvrRVXf/Y4HKvOtY1V0wwBuLD90f5u5MdQKA6XB73z2VLdYDkDeAMP34x3gHf8H90Q jD0SvQHeJMPgAzqEKUr2ZkEqwPEHpmQtO6PTKwHEMHhtr1YlUKlHfrHE00PfqArj0EHG AWu09dJSaroJ02gHC8tD5DLda9ML4aAwh/V8Qh6NjQ4QCBoSnKtY/02/P/NlwQuGoLC3 QDZQ== X-Gm-Message-State: AOAM533az+NhZ8j3mKJ2Q84Op+1PAnPpsgBXwUD5Mv2QQ2bsBuROX0Yr OybmgIfDrlNWE+m3f8xi6LAMchPS1xu3DQ== X-Received: by 2002:a63:6d8d:: with SMTP id i135mr11084192pgc.350.1624074214962; Fri, 18 Jun 2021 20:43:34 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 07/12] linux-user: Replace bprm->fd with bprm->src.fd Date: Fri, 18 Jun 2021 20:43:24 -0700 Message-Id: <20210619034329.532318-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There are only a couple of uses of bprm->fd remaining. Migrate to the other field. Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/flatload.c | 8 ++++---- linux-user/linuxload.c | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/qemu.h b/linux-user/qemu.h index f4cdfb16b3..dafaae6293 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -211,7 +211,6 @@ struct linux_binprm { char buf[BPRM_BUF_SIZE] __attribute__((aligned)); ImageSource src; abi_ulong p; - int fd; int e_uid, e_gid; int argc, envc; char **argv; diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 3e5594cf89..58d0d9352c 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -460,7 +460,7 @@ static int load_flat_file(struct linux_binprm * bprm, DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n"); textpos = target_mmap(0, text_len, PROT_READ|PROT_EXEC, - MAP_PRIVATE, bprm->fd, 0); + MAP_PRIVATE, bprm->src.fd, 0); if (textpos == -1) { fprintf(stderr, "Unable to mmap process text\n"); return -1; @@ -487,7 +487,7 @@ static int load_flat_file(struct linux_binprm * bprm, } else #endif { - result = target_pread(bprm->fd, datapos, + result = target_pread(bprm->src.fd, datapos, data_len + (relocs * sizeof(abi_ulong)), fpos); } @@ -537,10 +537,10 @@ static int load_flat_file(struct linux_binprm * bprm, else #endif { - result = target_pread(bprm->fd, textpos, + result = target_pread(bprm->src.fd, textpos, text_len, 0); if (result >= 0) { - result = target_pread(bprm->fd, datapos, + result = target_pread(bprm->src.fd, datapos, data_len + (relocs * sizeof(abi_ulong)), ntohl(hdr->data_start)); } diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 8b93b9704c..d0d3f2ed0e 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -36,7 +36,7 @@ static int prepare_binprm(struct linux_binprm *bprm) int mode; int retval; - if (fstat(bprm->fd, &st) < 0) { + if (fstat(bprm->src.fd, &st) < 0) { return -errno; } @@ -66,7 +66,7 @@ static int prepare_binprm(struct linux_binprm *bprm) bprm->e_gid = st.st_gid; } - retval = read(bprm->fd, bprm->buf, BPRM_BUF_SIZE); + retval = read(bprm->src.fd, bprm->buf, BPRM_BUF_SIZE); if (retval < 0) { perror("prepare_binprm"); exit(-1); @@ -133,7 +133,6 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, { int retval; - bprm->fd = fdexec; bprm->src.fd = fdexec; bprm->filename = (char *)filename; bprm->argc = count(argv); From patchwork Sat Jun 19 03:43:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463854 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp533729jao; Fri, 18 Jun 2021 20:46:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw19EEtJwm6aI7u3F7qXYpjAIJ8HqgtXaBIhvwERYlf8M8/ZRmShOUgaYQ7XswSBNy2+jii X-Received: by 2002:a92:660f:: with SMTP id a15mr10375669ilc.182.1624074405420; Fri, 18 Jun 2021 20:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074405; cv=none; d=google.com; s=arc-20160816; b=L/55AP/eM3HDpVFM2yPIXFGe0AUPRyccqZwPjSPxwPmSxh0fwo61bcige5z4x/grrw sgAEXBHgZ8shtHSWMfhFf63TDwcdQPGvo4DszFxuHSbKbWl0Xt9gQg1TuNIZsgwWjmBL dpuJOahxVpxxcwnE/xzELREv07NFuew47bvLA7xQhapw1g5Doi7qErPhkXOUSCcyzhEW cAg0tpnnTbkUOXrW6llKMmj3HS4jP4QY7qgLmGEWjL+Jn15Pe2WnT8I4kIJVk5uzDsgV C0W/tb7rPYMCpbnACGYje3nSaELtoX3pPcRuDuHLO4hGZ5xfZLtMopjKHjyBzT1Cn5Qs N7HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=cGX+M1DEqpXLqG7oFtvr0mh7D0289/3sneXY8fkD+4E=; b=S5xgHLD/tD0KdI1oBElfjUuq8H0hvsoAezlrriHiNihdxUWfqM91Kar18jUzIGBNmD QpJlBCoEC8n2kDNtNSWRZPOA15mFuc/XP6f4s/NgZGLn+7RqLJX+GuVlSCSGDMIfO4Jz hdSE/T9zuj+wH9KE8M3O8vZhuuG1nXhkH64pX1x/21nn+hcxALTNqTj/rwOZwLnfnlwX t7kvFprCX3vzQya7qaiqZHE3eQGraJg4B7DcXJYUI3Kjqd6dMfPXIT+qsubRXLG4s9H3 J4LlkPOxdY6CHcEKQjrtN7bz0vJhfSdmxEZlPOv044pNiXolu1MGzvPNbhL7Dzyg5mY8 Inmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XtqvGzx5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x20si12917479iov.0.2021.06.18.20.46.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:46:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XtqvGzx5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRwS-0005tt-Sc for patch@linaro.org; Fri, 18 Jun 2021 23:46:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtf-0000Lt-B0 for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:51 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:36587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtQ-00082z-Uk for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:51 -0400 Received: by mail-pj1-x102b.google.com with SMTP id s17-20020a17090a8811b029016e89654f93so9303329pjn.1 for ; Fri, 18 Jun 2021 20:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cGX+M1DEqpXLqG7oFtvr0mh7D0289/3sneXY8fkD+4E=; b=XtqvGzx59fKnmiS+05znM1izSdDTphG8emkM6gFVmZOrzw2XwNry1NILLklLfIi2Bx 5XUTvYKRW6YT3kgcg4YqHDV2Tv+trZcJG6zBy1ZbqxDJFP4STGTOBOWzXJTB4Keawh6u Uc71w8qX8DpRqLlV9RZ8Zf2cFvcqdfPe8arAQeP9Ci3Bhdkok2mIIg3oyLOPynsO/QQr JFhCqCtRwfrYvA2fBsAXh+98JGKV7tnd83seKQYzJg0W0mklEh06ip0XJArK44ec+m3b kuAeRFm6SXRshvVeXGJ6BaS95ruA38LIzu/Cf2yczsUcKgGTc/mhO6VyKFaQnJAiBzqV CQmw== 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=cGX+M1DEqpXLqG7oFtvr0mh7D0289/3sneXY8fkD+4E=; b=WcDJIJcGBFOssoaZTPBn4gqydZX42Ry1jy1Egrt03/Bl0F/7MKXFyfQvUFDYh2PhIP xH+pZHsPdsnICwAZTBlgmdC9m1vXHH/h+C5pL0kgPl6WIKy7bYDAdnK0leBOoz0+rwZQ 3LEYCLRqC1ntI5MAlSBFgWiRDRCF4zaotROFjRGFBPuEyaglVIGg7eqqh43BsTaaaYt3 brNLBQslhj6DiHPsFFHHfbwH0QT8k+mGxOZha+Idh3WauG2/qyMGCmn7/dEiKfEFnYT9 qCnMC68TtAYcWuMGs1WUGRJP49YPZS1Roh2PgxItvyx4yd3wXvpwhXYdG9i+FtJyueAP Cxeg== X-Gm-Message-State: AOAM533dpAVd3JOtv4mpoQJg842ACqAh0aTrsQ2tZKoUUH6EiZu/gax8 N4fLz3reGoeJuJwcxE60RnkCB8snDkN2PA== X-Received: by 2002:a17:90a:6b42:: with SMTP id x2mr14204400pjl.16.1624074215409; Fri, 18 Jun 2021 20:43:35 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 08/12] linux-user: Introduce imgsrc_mmap Date: Fri, 18 Jun 2021 20:43:25 -0700 Message-Id: <20210619034329.532318-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- linux-user/qemu.h | 11 +++++++++++ linux-user/elfload.c | 4 ++-- linux-user/linuxload.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index dafaae6293..255182e133 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -199,6 +199,17 @@ bool imgsrc_read(void *dst, off_t offset, size_t len, void *imgsrc_read_alloc(off_t offset, size_t len, const ImageSource *img, Error **errp); +/** + * imgsrc_mmap: Map from ImageSource + * + * If @src has a file descriptor, pass on to target_mmap. Otherwise, + * this is "mapping" from a host buffer, which resolves to memcpy. + * Therefore, flags must be MAP_PRIVATE | MAP_FIXED; the argument is + * retained for clarity. + */ +abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot, + int flags, const ImageSource *src, abi_ulong offset); + /* Read a good amount of data initially, to hopefully get all the program headers loaded. */ #define BPRM_BUF_SIZE 1024 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 3c31a5e3b0..8a3a7ae3ac 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2832,9 +2832,9 @@ static void load_elf_image(const char *image_name, const ImageSource *src, */ if (eppnt->p_filesz != 0) { vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, + error = imgsrc_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED, - src->fd, eppnt->p_offset - vaddr_po); + src, eppnt->p_offset - vaddr_po); if (error == -1) { goto exit_mmap; diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index d0d3f2ed0e..a437a22b49 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -208,3 +208,47 @@ void *imgsrc_read_alloc(off_t offset, size_t len, } return alloc; } + +abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot, + int flags, const ImageSource *src, abi_ulong offset) +{ + abi_long ret; + int prot_write; + void *haddr; + + assert(flags == (MAP_PRIVATE | MAP_FIXED)); + + if (src->fd >= 0) { + return target_mmap(start, len, prot, flags, src->fd, offset); + } + + /* + * This case is for the vdso; we don't expect bad images. + * The mmap may extend beyond the end of the image, especially + * to the end of the page. Zero fill. + */ + assert(offset < src->cache_size); + + prot_write = prot | PROT_WRITE; + ret = target_mmap(start, len, prot_write, flags | MAP_ANON, -1, 0); + if (ret == -1) { + return ret; + } + + haddr = lock_user(VERIFY_WRITE, start, len, 0); + assert(haddr != NULL); + if (offset + len < src->cache_size) { + memcpy(haddr, src->cache + offset, len); + } else { + size_t rest = src->cache_size - offset; + memcpy(haddr, src->cache + offset, rest); + memset(haddr + rest, 0, len - rest); + } + unlock_user(haddr, start, len); + + if (prot != prot_write) { + target_mprotect(start, len, prot); + } + + return ret; +} From patchwork Sat Jun 19 03:43:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463852 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp533368jao; Fri, 18 Jun 2021 20:45:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytJR4NIw5pP+xYPemfvN4i6+dHD9+ncjLpm3hdHssNDtnQwzEJNrnmfwfaLy0/MGV7Bx+Z X-Received: by 2002:a05:6e02:1be1:: with SMTP id y1mr10042829ilv.204.1624074354298; Fri, 18 Jun 2021 20:45:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074354; cv=none; d=google.com; s=arc-20160816; b=mq5uP4Q2PFKMjFFV2w0KMC9F/+S2OEnCDSuVm98JPo2LQIyXPUQQdujC9+vxAPuNrf BHXTC6/MEOhVUmhGFHaBbHFJxH+oS90Mmn1vfgZKIT0MGuhYxDcD2GpqQ8Ao5a1pnvCY 468JN2yDrfM6LZlFN96B4CTOaxg/gudDey7MsmZV1pvTTJ8x14YJ6a0fKAxAOP4MSSRl 0fKU4kqOd1KNMqjqwSO4ZbZQBYKctOAHJIHgRK8BN9d6bkWA5uFyuOWITOoA3KS2tP2T 8l0cmAOm9ZKeOcH/fBlQrfl0YyHHzzvgDgpLG8NjYniXWbPQnV3J+ZFyCoO4WTyVCF+e ymSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=30EwpAZh1z9iPoV3TY4t8s4Mj5ydqdR77HqBIYGD76w=; b=dGucW5OmxwPmuQfkgjrF47dhT6bKiQCf+bqKbd7NNAb+2pVbG/rtnmtSkeppwTscW0 euNSvJrzqNXfmnftbNL3IUXR6vlvRG5oXggPQ3pE6ZogUyTQeTQx0O/KLQ3NiWyPk21X dvDgDxvxdrDCtwEEeKOFq2A4brWrW2NnZiUWkN9cuykcqLpKg02SlYgc1dya2F1otFGi CUH2ZgAXnruQ8OISjarBsg5jVTayEFUWn95kTuZtlCFtqpuvikJw1TaPjr4iqoFeWnfo rFg8eZszjcjFS4LPvBEwv4H3ma4rmzkqPJxTGARJAD2eX0BL7JKqctV5SqcsCDQdjocx oLMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Crp2RXyi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e7si4295416ilq.68.2021.06.18.20.45.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:45:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Crp2RXyi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRvd-0005kL-Me for patch@linaro.org; Fri, 18 Jun 2021 23:45:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRta-0000A6-Bb for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:46 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:47051) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtR-000834-8p for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:46 -0400 Received: by mail-pg1-x529.google.com with SMTP id n12so709214pgs.13 for ; Fri, 18 Jun 2021 20:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=30EwpAZh1z9iPoV3TY4t8s4Mj5ydqdR77HqBIYGD76w=; b=Crp2RXyiG0vty9/gKv7xrj8Srv3eulFo6gYjIreOl7z9bF1dkf7CYUs/EX/XKoAPB4 5WQfR8ZUWdhse/0pKapJrFaAduLrKRPoVSVhOWZ2Z17kX2swvRkwSSI4T9ACYLCktVqH PHIGwvLvfLNFE0x4ImtG8OqkMzEJ5qsLSfym94ZLwSw1aou2iuYXDHdKt6TgFbjb9r6N q5nDomF4K8ZFnom7nsWRL6gjxJuBskmCxzVUhieWigXQdROEKklrIpO9FxSCZQb4MX/P UiTKlqv6mQIlJidyl+K2oFAqvSf5QB6MbniD9hytyfNfZDgOUEnItU2ISrjE8Ey/ge2N JDJA== 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=30EwpAZh1z9iPoV3TY4t8s4Mj5ydqdR77HqBIYGD76w=; b=k6F3RwKwyDeGl3jZzXENAQwpSwl4HtyQrT9n1JA7JHQG1q2w2EIGkS8OmP534O+rQg l3alO9CIee0nFswuiUm4ngdrXgR6aW5rXCuRN6H68Fov/q59PZli8J1SuyaKE0yhCx59 364/ot5BJaiKNSVybU5k+5Wwwng8lqWjTHVaQ+x+Z/0yRiknKWM9CFN6tX6eFurEq9yv 3B5+RCo+1T3J7w/bvsZheLrQkrC6bIJHBYUMTfEn9jwacIhaCfGiEb8A6Pz4rLW5RNLS gSTGOoBf88dp6uxP6X8pzRAKD07hoTyOCeAaNEITGCppHOTJ8rY30D6HYGFO6HyRKtyd WD1A== X-Gm-Message-State: AOAM531lU1wyCtx3jgB2kD+Xk3bCv+0gCnS3SFFxmPr2TAb3BP/fA00s lCPeVgBxAMYXUtE/dRGxU51F/SMiUyWuPQ== X-Received: by 2002:a63:d053:: with SMTP id s19mr13150063pgi.326.1624074216063; Fri, 18 Jun 2021 20:43:36 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 09/12] linux-user: Load vdso image if available Date: Fri, 18 Jun 2021 20:43:26 -0700 Message-Id: <20210619034329.532318-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The vdso image will be pre-processed into a C data array, with a simple list of relocations to perform, and identifying the location of signal trampolines. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 75 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 8 deletions(-) -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8a3a7ae3ac..a6ad454617 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1966,7 +1966,8 @@ static abi_ulong loader_build_fdpic_loadmap(struct image_info *info, abi_ulong s static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, struct elfhdr *exec, struct image_info *info, - struct image_info *interp_info) + struct image_info *interp_info, + struct image_info *vdso_info) { abi_ulong sp; abi_ulong u_argc, u_argv, u_envp, u_auxv; @@ -2038,8 +2039,12 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } size = (DLINFO_ITEMS + 1) * 2; - if (k_platform) + if (k_platform) { size += 2; + } + if (vdso_info) { + size += 4; + } #ifdef DLINFO_ARCH_ITEMS size += DLINFO_ARCH_ITEMS * 2; #endif @@ -2116,6 +2121,10 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, if (u_platform) { NEW_AUX_ENT(AT_PLATFORM, u_platform); } + if (vdso_info) { + NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); + NEW_AUX_ENT(AT_SYSINFO_EHDR, vdso_info->load_addr); + } NEW_AUX_ENT (AT_NULL, 0); #undef NEW_AUX_ENT @@ -2942,6 +2951,53 @@ static void load_elf_interp(const char *filename, struct image_info *info, load_elf_image(filename, &src, info, &ehdr, NULL); } +#ifndef HAVE_VDSO +#define HAVE_VDSO 0 +static uint8_t vdso_image[] = { }; +static uint32_t vdso_relocs[] = { }; +#define vdso_sigreturn 0 +#define vdso_rt_sigreturn 0 +#endif + +static void load_elf_vdso(struct image_info *info) +{ + ImageSource src; + struct elfhdr ehdr; + abi_ulong load_bias, load_addr; + + src.fd = -1; + src.cache = vdso_image; + src.cache_size = sizeof(vdso_image); + + load_elf_image("", &src, info, &ehdr, NULL); + load_addr = info->load_addr; + load_bias = info->load_bias; + + /* + * We need to relocate the VDSO image. The one built into the kernel + * is built for a fixed address. The one built for QEMU is not, since + * that requires close control of the guest address space. + * We pre-processed the image to locate all of the addresses that need + * to be updated. + */ + for (size_t i = 0, n = ARRAY_SIZE(vdso_relocs); i < n; i++) { + abi_ulong *addr = g2h_untagged(load_addr + vdso_relocs[i]); + *addr = tswapal(tswapal(*addr) + load_bias); + } + + /* Install signal trampolines, if present. */ + if (vdso_sigreturn) { + default_sigreturn = load_addr + vdso_sigreturn; + } + if (vdso_rt_sigreturn) { + default_rt_sigreturn = load_addr + vdso_rt_sigreturn; + } + + /* Mark the VDSO writable segment read-only. */ + target_mprotect(info->start_data, info->end_data - info->start_data, + PROT_READ); +} + static int symfind(const void *s0, const void *s1) { target_ulong addr = *(target_ulong *)s0; @@ -3146,7 +3202,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) * and let elf_load_image do any swapping that may be required. */ struct elfhdr ehdr; - struct image_info interp_info; + struct image_info interp_info, vdso_info; char *elf_interpreter = NULL; char *scratch; @@ -3216,10 +3272,12 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) } /* - * TODO: load a vdso, which would also contain the signal trampolines. - * Otherwise, allocate a private page to hold them. + * Load a vdso if available, which will amongst other things contain the + * signal trampolines. Otherwise, allocate a separate page for them. */ - if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { + if (HAVE_VDSO) { + load_elf_vdso(&vdso_info); + } else if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { abi_ulong tramp_page = target_mmap(0, TARGET_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); @@ -3227,8 +3285,9 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC); } - bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, - info, (elf_interpreter ? &interp_info : NULL)); + bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info, + elf_interpreter ? &interp_info : NULL, + HAVE_VDSO ? &vdso_info : NULL); info->start_stack = bprm->p; /* If we have an interpreter, set that as the program's entry point. From patchwork Sat Jun 19 03:43:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463856 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp534427jao; Fri, 18 Jun 2021 20:48:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFIxxzfQi7UlSN7R5YnAFFti44jQUnRoNIEThvlnw6kO5dFkGNmGiXBDGqezsHiOarey8E X-Received: by 2002:a02:956a:: with SMTP id y97mr6261789jah.58.1624074489340; Fri, 18 Jun 2021 20:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074489; cv=none; d=google.com; s=arc-20160816; b=J86pLtVw1KMnGD8wjyCdUE7HzM9tpmMueHvhJwa9MIsjr/Rsp0Iz6MoQFRrb8oR8qb qo9aCJX7tj31W236B/jlzSWMgL+4FbdbFtopdQ1jXB/CFXKqB/4+vIR2CSy+4jj83VEg DZDoQU+1Ua8VVl9mCdS7Pis1DBLU+Oi5Mi9tJiifUSVbfCYHeLGyXse7Pce0fThRrU86 xIkdcz2YK/leJevLEDdsIUPnQ3NE31+3S5i4jYURHHNwvN502U6NKkhoUOcFVlsZZtKK hkNX/eddpT8M1Q9DiBU75ZjkNvqeIwV8xWvIHkL7DHIa1EDTqIDwWammEq4W7U1Jt7+W AQKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Xf7gfODhEHLAK19nF0i1E5avDqb1sECHeoNiF4HXyew=; b=vPS+QjkV2IkgTt3eek/JUmmHlcM1OKMNiX2hKVXWk4LQWL51MTVIoDWOmxqvUDXAMR 6AO/ltkJchH+8k2xoAZhDbVmGLI7gVGE907BwcLj6EAAxz7Y3qR4xSQ+NT9dZ6cFuclG /pyUSNSHcTlMjTM8CsZB/uzBah1U1dE/U6tgvq/Tcgl1LD0i8J6zkN87fVZIc9gOyjbC qM4uP23NCpaFg6SGmxb0Ml6lLxr1i4lhWrMeSdt3elLJcKWeJMDftUOMB7zVnQcgVXrk s2IsuZfocppl64PaCHiKH5lpNqlAl0O0nJ0pXEHmE7TKCHsy8U/eP55qK4hO6TKWZsqN az1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="qRFoLw/p"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o8si4836929ilu.115.2021.06.18.20.48.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="qRFoLw/p"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRxo-0001qL-Or for patch@linaro.org; Fri, 18 Jun 2021 23:48:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtg-0000QY-8I for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:52 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:39465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtS-000839-7z for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:52 -0400 Received: by mail-pf1-x42d.google.com with SMTP id g192so1535307pfb.6 for ; Fri, 18 Jun 2021 20:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xf7gfODhEHLAK19nF0i1E5avDqb1sECHeoNiF4HXyew=; b=qRFoLw/pun0mqOgFyNOYnYtQG1wLhEr3uqKtZjDoNW+5aagq/WUv3jH4RI8/nv81Ha /HNoHJdI3ndQu7M9VMM+M8oD7CfwOrwCJFjfKWNl1aN1ftFRNV1RTgew3Obd8Y9UXe+x llBXnNqhsqm+UCKLjmv2D2VrfO2jfWG4YepfWCUzIx9kEBjxoJjoMxjIAOAd/Lqnh6OK 79+zs+IyA4YAvPsHiBszQ93qgAuJZeCWyV4XYfFOW4TMx8WKysLHA7iOPXDr47kb0j/K sF1YMCs/rVlWDon37UHQm44aMT84hC+2CkDu5bqhtyUkIl1HvSUT/a1ut8+u6ddO+TBI abGg== 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=Xf7gfODhEHLAK19nF0i1E5avDqb1sECHeoNiF4HXyew=; b=Ps8FelFrvhwgim9p6yLZjEDXQZGn9xl+/CW9fi6RJKIDlHxksmrDR1SS4033IxJb5o XHr19keou6gxSMctP+An5Kng5L8AWFv//T0DKLveF2l/FXyyEEICigYvI1OGYGc4aYyn q85174OpirlP3WCNE/irynKQay/U/Gwye1dPwPeYJ6LzSRk+Jqci4YzBHQo1zDsIvjF2 OlAEY2/lXgcpepAygcYthvXwbWJ++ljyRi9Maa+Nsqe3HsJnejsRVDHuNp7QQ1RmVJQo imHpxQkPk4ZpsMQdnHjR1hF3ZOowOxyPv6HABS/wa2GYBdFwvcO7wQ5VYZdzGiyI9Smd R31A== X-Gm-Message-State: AOAM53242gmkQSwl1Yb7hSnF+QPxGzCSrEWuRfuPx/GfcOeKLKYglRor pI+3esq/qFi371jJjAS+rMYTDbtHuyBpyw== X-Received: by 2002:a63:5553:: with SMTP id f19mr12828301pgm.419.1624074216535; Fri, 18 Jun 2021 20:43:36 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 10/12] linux-user: Add gen-vdso tool Date: Fri, 18 Jun 2021 20:43:27 -0700 Message-Id: <20210619034329.532318-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This tool will be used for post-processing the linked vdso image, turning it into something that is easy to include into elfload.c. Signed-off-by: Richard Henderson --- linux-user/gen-vdso.c | 168 ++++++++++++++++++ linux-user/gen-vdso-elfn.c.inc | 299 +++++++++++++++++++++++++++++++++ linux-user/meson.build | 6 +- 3 files changed, 472 insertions(+), 1 deletion(-) create mode 100644 linux-user/gen-vdso.c create mode 100644 linux-user/gen-vdso-elfn.c.inc -- 2.25.1 diff --git a/linux-user/gen-vdso.c b/linux-user/gen-vdso.c new file mode 100644 index 0000000000..ccbb6c4725 --- /dev/null +++ b/linux-user/gen-vdso.c @@ -0,0 +1,168 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include +#include +#include "elf.h" + + +#define bswap_(p) _Generic(*(p), \ + uint16_t: __builtin_bswap16, \ + uint32_t: __builtin_bswap32, \ + uint64_t: __builtin_bswap64, \ + int16_t: __builtin_bswap16, \ + int32_t: __builtin_bswap32, \ + int64_t: __builtin_bswap64) +#define bswaps(p) (*(p) = bswap_(p)(*(p))) + +static void output_reloc(FILE *outf, void *buf, void *loc) +{ + fprintf(outf, " 0x%08lx,\n", loc - buf); +} + +#define N 32 +#define elfN(x) elf32_##x +#define ElfN(x) Elf32_##x +#include "gen-vdso-elfn.c.inc" +#undef N +#undef elfN +#undef ElfN + +#define N 64 +#define elfN(x) elf64_##x +#define ElfN(x) Elf64_##x +#include "gen-vdso-elfn.c.inc" +#undef N +#undef elfN +#undef ElfN + + +int main(int ac, char **av) +{ + FILE *inf, *outf; + long total_len; + const char *inf_name; + const char *outf_name; + unsigned char *buf; + bool need_bswap; + + if (ac != 3) { + fprintf(stderr, "usage: input-file output-file\n"); + return EXIT_FAILURE; + } + inf_name = av[1]; + outf_name = av[2]; + + /* + * Open the input and output files. + */ + inf = fopen(inf_name, "rb"); + if (inf == NULL) { + goto perror_inf; + } + outf = fopen(outf_name, "w"); + if (outf == NULL) { + goto perror_outf; + } + + /* + * Read the input file into a buffer. + * We expect the vdso to be small, on the order of one page, + * therefore we do not expect a partial read. + */ + fseek(inf, 0, SEEK_END); + total_len = ftell(inf); + fseek(inf, 0, SEEK_SET); + + buf = malloc(total_len); + if (buf == NULL) { + goto perror_inf; + } + + errno = 0; + if (fread(buf, 1, total_len, inf) != total_len) { + if (errno) { + goto perror_inf; + } + fprintf(stderr, "%s: incomplete read\n", inf_name); + return EXIT_FAILURE; + } + fclose(inf); + + /* + * Write out the vdso image now, before we make local changes. + */ + + fputs("/* Automatically generated from linux-user/gen-vdso.c. */\n" + "\n" + "static const uint8_t vdso_image[] = {", + outf); + for (long i = 0; i < total_len; ++i) { + if (i % 12 == 0) { + fputs("\n ", outf); + } + fprintf(outf, " 0x%02x,", buf[i]); + } + fputs("\n};\n\n", outf); + + /* + * Identify which elf flavor we're processing. + * The first 16 bytes of the file are e_ident. + */ + + if (buf[EI_MAG0] != ELFMAG0 || buf[EI_MAG1] != ELFMAG1 || + buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3) { + fprintf(stderr, "%s: not an elf file\n", inf_name); + return EXIT_FAILURE; + } + switch (buf[EI_DATA]) { + case ELFDATA2LSB: + need_bswap = BYTE_ORDER != LITTLE_ENDIAN; + break; + case ELFDATA2MSB: + need_bswap = BYTE_ORDER != BIG_ENDIAN; + break; + default: + fprintf(stderr, "%s: invalid elf EI_DATA (%u)\n", + inf_name, buf[EI_DATA]); + return EXIT_FAILURE; + } + switch (buf[EI_CLASS]) { + case ELFCLASS32: + elf32_process(outf, buf, total_len, need_bswap); + break; + case ELFCLASS64: + elf64_process(outf, buf, total_len, need_bswap); + break; + default: + fprintf(stderr, "%s: invalid elf EI_CLASS (%u)\n", + inf_name, buf[EI_CLASS]); + return EXIT_FAILURE; + } + + /* + * Everything should have gone well. + */ + if (fclose(outf)) { + goto perror_outf; + } + return EXIT_SUCCESS; + + perror_inf: + perror(inf_name); + return EXIT_FAILURE; + + perror_outf: + perror(outf_name); + return EXIT_FAILURE; +} diff --git a/linux-user/gen-vdso-elfn.c.inc b/linux-user/gen-vdso-elfn.c.inc new file mode 100644 index 0000000000..4e9277aeff --- /dev/null +++ b/linux-user/gen-vdso-elfn.c.inc @@ -0,0 +1,299 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * Elf size specialization. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +static void elfN(bswap_ehdr)(ElfN(Ehdr) *ehdr) +{ + bswaps(&ehdr->e_type); /* Object file type */ + bswaps(&ehdr->e_machine); /* Architecture */ + bswaps(&ehdr->e_version); /* Object file version */ + bswaps(&ehdr->e_entry); /* Entry point virtual address */ + bswaps(&ehdr->e_phoff); /* Program header table file offset */ + bswaps(&ehdr->e_shoff); /* Section header table file offset */ + bswaps(&ehdr->e_flags); /* Processor-specific flags */ + bswaps(&ehdr->e_ehsize); /* ELF header size in bytes */ + bswaps(&ehdr->e_phentsize); /* Program header table entry size */ + bswaps(&ehdr->e_phnum); /* Program header table entry count */ + bswaps(&ehdr->e_shentsize); /* Section header table entry size */ + bswaps(&ehdr->e_shnum); /* Section header table entry count */ + bswaps(&ehdr->e_shstrndx); /* Section header string table index */ +} + +static void elfN(bswap_phdr)(ElfN(Phdr) *phdr) +{ + bswaps(&phdr->p_type); /* Segment type */ + bswaps(&phdr->p_flags); /* Segment flags */ + bswaps(&phdr->p_offset); /* Segment file offset */ + bswaps(&phdr->p_vaddr); /* Segment virtual address */ + bswaps(&phdr->p_paddr); /* Segment physical address */ + bswaps(&phdr->p_filesz); /* Segment size in file */ + bswaps(&phdr->p_memsz); /* Segment size in memory */ + bswaps(&phdr->p_align); /* Segment alignment */ +} + +static void elfN(bswap_shdr)(ElfN(Shdr) *shdr) +{ + bswaps(&shdr->sh_name); + bswaps(&shdr->sh_type); + bswaps(&shdr->sh_flags); + bswaps(&shdr->sh_addr); + bswaps(&shdr->sh_offset); + bswaps(&shdr->sh_size); + bswaps(&shdr->sh_link); + bswaps(&shdr->sh_info); + bswaps(&shdr->sh_addralign); + bswaps(&shdr->sh_entsize); +} + +static void elfN(bswap_sym)(ElfN(Sym) *sym) +{ + bswaps(&sym->st_name); + bswaps(&sym->st_value); + bswaps(&sym->st_size); + bswaps(&sym->st_shndx); +} + +static void elfN(bswap_dyn)(ElfN(Dyn) *dyn) +{ + bswaps(&dyn->d_tag); /* Dynamic type tag */ + bswaps(&dyn->d_un.d_ptr); /* Dynamic ptr or val, in union */ +} + +static void elfN(process)(FILE *outf, void *buf, long total_len, + bool need_bswap) +{ + ElfN(Ehdr) *ehdr = buf; + ElfN(Phdr) *phdr; + ElfN(Shdr) *shdr; + unsigned phnum, shnum; + unsigned dynamic_ofs = 0; + unsigned dynamic_addr = 0; + unsigned dynsym_addr = 0; + unsigned sigreturn_addr = 0; + unsigned rt_sigreturn_addr = 0; + unsigned first_segsz = 0; + int errors = 0; + + if (need_bswap) { + elfN(bswap_ehdr)(ehdr); + } + + phnum = ehdr->e_phnum; + phdr = buf + ehdr->e_phoff; + if (need_bswap) { + for (unsigned i = 0; i < phnum; ++i) { + elfN(bswap_phdr)(phdr + i); + } + } + + shnum = ehdr->e_shnum; + shdr = buf + ehdr->e_shoff; + if (need_bswap) { + for (unsigned i = 0; i < shnum; ++i) { + elfN(bswap_shdr)(shdr + i); + } + } + + /* + * Validate the VDSO is created as we expect: that PT_PHDR, + * PT_DYNAMIC, and PT_NOTE located in a writable data segment. + * PHDR and DYNAMIC require relocation, and NOTE will get the + * linux version number. + */ + for (unsigned i = 0; i < phnum; ++i) { + if (phdr[i].p_type == PT_LOAD && phdr[i].p_vaddr == 0) { + if (first_segsz != 0) { + fprintf(stderr, "Multiple load segments covering EHDR\n"); + errors++; + } + if (phdr[i].p_offset != 0) { + fprintf(stderr, "First vdso segment does not cover EHDR\n"); + errors++; + } + if (phdr[i].p_vaddr != 0) { + fprintf(stderr, "First vdso segment not loaded at address 0\n"); + errors++; + } + if ((phdr[i].p_flags & (PF_R | PF_W)) != (PF_R | PF_W)) { + fprintf(stderr, "First vdso segment is not read-write\n"); + errors++; + } + first_segsz = phdr[i].p_filesz; + if (first_segsz < ehdr->e_phoff + phnum * sizeof(*phdr)) { + fprintf(stderr, "First vdso segment does not cover PHDRs\n"); + errors++; + } + } + } + for (unsigned i = 0; i < phnum; ++i) { + const char *which; + + switch (phdr[i].p_type) { + case PT_PHDR: + which = "PT_PHDR"; + break; + case PT_NOTE: + which = "PT_NOTE"; + break; + case PT_DYNAMIC: + dynamic_ofs = phdr[i].p_offset; + dynamic_addr = phdr[i].p_vaddr; + which = "PT_DYNAMIC"; + break; + default: + continue; + } + if (first_segsz < phdr[i].p_vaddr + phdr[i].p_filesz) { + fprintf(stderr, "First vdso segment does not cover %s\n", which); + errors++; + } + } + if (errors) { + exit(EXIT_FAILURE); + } + + /* + * We need to relocate the VDSO image. The one built into the kernel + * is built for a fixed address. The one we built for QEMU is not, + * since that requires close control of the guest address space. + * + * ??? One might think that we'd need to relocate ehdr->e_entry, + * but for some reason glibc does that one itself, though that + * is also available via the AT_SYSINFO entry. + * + * Output relocation addresses as we go. + */ + fputs("static const unsigned vdso_relocs[] = {\n", outf); + + /* Relocate the program headers. */ + for (unsigned i = 0; i < phnum; ++i) { + output_reloc(outf, buf, &phdr[i].p_vaddr); + output_reloc(outf, buf, &phdr[i].p_paddr); + } + + /* Relocate the DYNAMIC entries. */ + if (dynamic_addr) { + ElfN(Dyn) *dyn = buf + dynamic_ofs; + __typeof(dyn->d_tag) tag; + + do { + + if (need_bswap) { + elfN(bswap_dyn)(dyn); + } + tag = dyn->d_tag; + + switch (tag) { + case DT_SYMTAB: + dynsym_addr = dyn->d_un.d_val; + /* fall through */ + case DT_HASH: + case DT_STRTAB: + case DT_VERDEF: + case DT_VERSYM: + case DT_PLTGOT: + case DT_ADDRRNGLO ... DT_ADDRRNGHI: + /* These entries store an address in the entry. */ + output_reloc(outf, buf, &dyn->d_un.d_val); + break; + + case DT_NULL: + case DT_STRSZ: + case DT_SONAME: + case DT_DEBUG: + case DT_FLAGS: + case DT_FLAGS_1: + case DT_BIND_NOW: + case DT_VERDEFNUM: + case DT_VALRNGLO ... DT_VALRNGHI: + /* These entries store an integer in the entry. */ + break; + + case DT_SYMENT: + if (dyn->d_un.d_val != sizeof(ElfN(Sym))) { + fprintf(stderr, "VDSO has incorrect dynamic symbol size\n"); + errors++; + } + break; + + case DT_REL: + case DT_RELSZ: + case DT_RELENT: + case DT_RELA: + case DT_RELASZ: + case DT_RELAENT: + case DT_TEXTREL: + /* + * These entries indicate that the VDSO was built incorrectly. + * It should not have any real relocations. + */ + fprintf(stderr, "VDSO has dynamic relocations\n"); + errors++; + break; + + case DT_NEEDED: + case DT_VERNEED: + case DT_PLTREL: + case DT_JMPREL: + case DT_RPATH: + case DT_RUNPATH: + fprintf(stderr, "VDSO has external dependencies\n"); + errors++; + break; + + default: + /* This is probably something target specific. */ + fprintf(stderr, "VDSO has unknown DYNAMIC entry (%lx)\n", + (unsigned long)tag); + errors++; + break; + } + dyn++; + } while (tag != DT_NULL); + if (errors) { + exit(EXIT_FAILURE); + } + } + + if (dynsym_addr) { + __typeof(shdr->sh_size) dynsym_n = 0; + ElfN(Sym) *sym = NULL; + const char *str = NULL; + + for (unsigned i = 0; i < shnum; ++i) { + if (shdr[i].sh_addr == dynsym_addr) { + dynsym_n = shdr[i].sh_size / sizeof(*sym); + sym = buf + shdr[i].sh_offset; + str = buf + shdr[shdr[i].sh_link].sh_offset; + break; + } + } + + for (unsigned i = 0; i < dynsym_n; ++i) { + if (need_bswap) { + elfN(bswap_sym)(sym + i); + } + + /* Relocate the dynamic symbol table. */ + output_reloc(outf, buf, &sym[i].st_value); + + /* Locate the signal return symbols. */ + const char *name = str + sym[i].st_name; + if (strcmp("__kernel_sigreturn", name) == 0) { + sigreturn_addr = sym[i].st_value; + } else if (strcmp("__kernel_rt_sigreturn", name) == 0) { + rt_sigreturn_addr = sym[i].st_value; + } + } + } + + fputs("};\n\n", outf); /* end vdso_relocs. */ + + fprintf(outf, "#define vdso_sigreturn 0x%x\n", sigreturn_addr); + fprintf(outf, "#define vdso_rt_sigreturn 0x%x\n", rt_sigreturn_addr); +} diff --git a/linux-user/meson.build b/linux-user/meson.build index 9549f81682..c5e6ab058b 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -18,9 +18,13 @@ linux_user_ss.add(when: 'TARGET_HAS_BFLT', if_true: files('flatload.c')) linux_user_ss.add(when: 'TARGET_I386', if_true: files('vm86.c')) linux_user_ss.add(when: 'CONFIG_ARM_COMPATIBLE_SEMIHOSTING', if_true: files('semihost.c')) - syscall_nr_generators = {} +gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c', + native: true, build_by_default: false) +gen_vdso = generator(gen_vdso_exe, output: '@BASENAME@.c.inc', + arguments: ['@INPUT@', '@OUTPUT@']) + subdir('alpha') subdir('arm') subdir('hppa') From patchwork Sat Jun 19 03:43:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463858 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp535805jao; Fri, 18 Jun 2021 20:51:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwyvebDx3X3oYRrippe8girh69KI/pCRGRcCH4vrC8nB4SNbZITkPwK90bFaJu7Wdld4Wq X-Received: by 2002:a05:6e02:12ac:: with SMTP id f12mr9645430ilr.207.1624074673758; Fri, 18 Jun 2021 20:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074673; cv=none; d=google.com; s=arc-20160816; b=oiOy87/H+xtvj3rYLk9t5SwB+Q9v3dUBAG330vmBWP4FiR7SRD5se8V/WlF6SfHs2D I5g5UUVwZ8c31S3SdcLlgnMNVYazdJVsH8zAkIsmrpQoP6IatK4xlDc7Mhanbv2wpg3O c83JYw62ZmMSxU8xsVLcEZAoq2JEOknRFbxDPlgucnrJ8F0NSa4Jwr5eCY0muk0WnOkR 7RMzocZTP76VnBUAu4WcYRL2Xto6/MJ8CjcvY2ChnfHyOXPph+DoFBaxjVWtkn1pIVN4 696ixUdFHpDReIlWvAPSHRC3F/nuB3gNnkwRlb5Xv9JgyTbstgWyf7g/mrI8mWiRE2b2 xC8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=jUXae3SraHm4OVG+O8NmkBHPeUZIHDauOpN34upW9DU=; b=QNFEnFeqxPr0BrO7GMRNlClQm6qvOqomGmy0ZU/aTjoEfUN3T0HoS73yApwS5pWAt+ QBP4FLCT6mlRgoHi4PBgbw3OhOFOQ3Cu5v1LphzPXULhzPAKzLP6IkbqZYpG56zjCTFa DplEOf8YdyEENa9q3d+ZbYwWLcETNBhcbt0bcrj5Xrghn+OA0h2nX6RKt77vKrxNtY07 041ooA4ysmnum26dCrfbxbO6H772oYlEQ8TKYnMbrXCJm/FTB1A7UCTXr7fuIj3s7P0h zNjLtJK3qHV73eMN3xHT4HYwUDXjQUeczfbdhojNgnR1MpaRccQQPGzEU6vpfe9uo9LR 1hEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Hxp8zVdK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z10si2445171ioq.37.2021.06.18.20.51.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:51:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Hxp8zVdK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luS0n-00085w-6c for patch@linaro.org; Fri, 18 Jun 2021 23:51:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtd-0000E0-1F for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:49 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:36804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtS-00083V-BD for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:48 -0400 Received: by mail-pl1-x634.google.com with SMTP id x10so5680348plg.3 for ; Fri, 18 Jun 2021 20:43:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jUXae3SraHm4OVG+O8NmkBHPeUZIHDauOpN34upW9DU=; b=Hxp8zVdKo0LHgnRJjsiw2rdWR5HgloN8+Hfji0V5HsaPQx92mKxV2mrYvrJbED9MI/ buqXCi6b7VOjaeSIe0ZCtGM/MvsLc6zCpOFtDcxEqzIQ46DsDdO82U8NldodHks1ht2C UD3Xfv/A6r5pWaONEoQRHY4RoXecueAwPRQXdvk4/d018gHAbv5W0yc20XcNi8l2hYGE CAZsF2cRajFQbo9amEPrz+o7rOZVRbYdN1auXErRoPM6jRaBailyAe0Pzv5hgLnXoAqm zyx+jfMmDjh7cf8um/7JKeNEc6GnrK3DuySZ3cCgHgOhK3g5v3wAbsASWRCsmcx10B+V uujg== 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=jUXae3SraHm4OVG+O8NmkBHPeUZIHDauOpN34upW9DU=; b=Wpk+ZdNFJz5PIVDvCu/Juj5gomjmaidy7NeYv1l5I5SmvAT9zOLOVlkv/ILQEBe/GX gr8pkD8fSCImxFC0hIBSGxgVnQwDXDJJ8ddp4WZtwj33Y6W+fc+hxqtqfZQuGzzjfJjo 8++JWoyloDb2SfePLv55KaQODTWKl/hbrzvbJABILJ1HFAtd9C5PuRq1JM1e40pmLSwL TiBsnVXABhdcnVruM2wJJfqqA4QG9Y1AZPSH3Wq6caBpetvVHxKJaHYaV4UUnm4Dj/Ai JCFxVCC5Xnr9ivWLTV2lOAGoF/tjMe6sV2yGAVHMVdJ+raYOSh8u8I9J7bvEaBPJBXFc +RAA== X-Gm-Message-State: AOAM533wY6QBgdJkREqH8rvMGDsiarIlj14eWW/CswnDrMf5sejzRivl 26WW1ne0eFq/KEd8u3OqPpU3zf1Gt5CMPg== X-Received: by 2002:a17:902:d4d0:b029:113:fb3d:3644 with SMTP id o16-20020a170902d4d0b0290113fb3d3644mr7545662plg.58.1624074216979; Fri, 18 Jun 2021 20:43:36 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 11/12] linux-user/x86_64: Add vdso Date: Fri, 18 Jun 2021 20:43:28 -0700 Message-Id: <20210619034329.532318-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in that file for now. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 3 + linux-user/x86_64/Makefile.vdso | 3 + linux-user/x86_64/meson.build | 6 ++ linux-user/x86_64/vdso.S | 122 ++++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.ld | 74 +++++++++++++++++++ linux-user/x86_64/vdso.so | Bin 0 -> 5912 bytes 6 files changed, 208 insertions(+) create mode 100644 linux-user/x86_64/Makefile.vdso create mode 100644 linux-user/x86_64/vdso.S create mode 100644 linux-user/x86_64/vdso.ld create mode 100755 linux-user/x86_64/vdso.so diff --git a/linux-user/x86_64/vdso.so b/linux-user/x86_64/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..0cdb8f1706893abf221e42d3443d9f5d49fef080 GIT binary patch literal 5912 zcmeHL&ud&&6h4#5G>PWNw2COv8bm7;9TF)LD3qy9;>5Ng1_DtiuhYzHCzzShnU^w= zQbCLwDVjwW#YJgxFIg5hDiyK*1ybnF3T~t>3@+61eDlsXyt#d~g5c_%rNM0somwpb*kfKPhUU?gKao$oB`^^tD zV((?&WWo`m*nAMz9Q71#@Igx3FNf2SSj#;e&>c8vfA=^Zj7) ze_G$d<&O2g;6yC${|40ODXhl!o%PzU{2t}U9R3OO&pP}g=I`=bZP;tf zr!VXZV!4fIV+XKH@zz`N{pj}1?5CF(J{d2+e{|!gp^x{zd$D=> z++&{|seZKo+kN}CPx+Ol4_e}RXG@Kmx4c?ge#1NC2f<3kzl*H<4RYpEJ6$TSlZ(da z`0|@;vbs`TYd(+EIsKoIW3zLMOWq5)7j=F;v41+Cma@OAU;Z-mu=XFLNvD6KyFYQGu+a(zHotqOHKHn_uduNbWWN4+aC3O# ztLy6ePnOo-;MCz!zqI~3r+)3`(?T8G&G&Zna5tan=;CgEm&EDWv??X);BNo^j{fiF z2c!U@;8;4M|2PEA0ZrnrSAWK<-JKtLBTnz)H-DUtd{+559Sr?~Jg(k7X#TFgoHgF{ z&sm-^h!-_#nRRU=zpH~^GTzO9Lisp-jPnWbZXWTbUYk37eD;WH#Fyt5z3GBCvvBzM zv{#r~h=@T`pK+qngruuaBT_V0v$nOUdLB`2g0=ah{J6c^*c8TMoN=3M$fy+@IeUM6Q$hT|BDsI7=hX?-k;t z-HA1F=l{BnV@`~}*SVvm>747ZUv}d8Jw-f6M??4is1NSX^ThT+27K)S!FwDvJ~!l| zb0-HpX^weY7|ybW^y2+lSDZib+0|ypuIve$=Q~W;aQAPw(sA*7?Hs##pZLE4>E9DK literal 0 HcmV?d00001 -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index a6ad454617..b70a5c48a2 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -154,6 +154,9 @@ static uint32_t get_elf_hwcap(void) #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_X86_64 +#define HAVE_VDSO 1 +#include "vdso.c.inc" + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { regs->rax = 0; diff --git a/linux-user/x86_64/Makefile.vdso b/linux-user/x86_64/Makefile.vdso new file mode 100644 index 0000000000..6111d6f21c --- /dev/null +++ b/linux-user/x86_64/Makefile.vdso @@ -0,0 +1,3 @@ +vdso.so: vdso.S vdso.ld Makefile.vdso + $(CC) -nostdlib -shared -Wl,-T,vdso.ld -Wl,--build-id=none \ + -Wl,-h,linux-vdso.so.1 -Wl,--hash-style=both vdso.S -o $@ diff --git a/linux-user/x86_64/meson.build b/linux-user/x86_64/meson.build index 203af9a60c..f6a0015953 100644 --- a/linux-user/x86_64/meson.build +++ b/linux-user/x86_64/meson.build @@ -3,3 +3,9 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +gen = [ + gen_vdso.process('vdso.so') +] + +linux_user_ss.add(when: 'TARGET_X86_64', if_true: gen) diff --git a/linux-user/x86_64/vdso.S b/linux-user/x86_64/vdso.S new file mode 100644 index 0000000000..7d0d653526 --- /dev/null +++ b/linux-user/x86_64/vdso.S @@ -0,0 +1,122 @@ +/* + * x86-64 linux replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .globl __vdso_clock_gettime + .type __vdso_clock_gettime, @function + .balign 16 + .cfi_startproc +__vdso_clock_gettime: + mov $__NR_clock_gettime, %eax + syscall + ret + .cfi_endproc + .size __vdso_clock_gettime, . - __vdso_clock_gettime + +clock_gettime = __vdso_clock_gettime + .weak clock_gettime + + .globl __vdso_clock_getres + .type __vdso_clock_getres, @function + .balign 16 + .cfi_startproc +__vdso_clock_getres: + mov $__NR_clock_getres, %eax + syscall + ret + .cfi_endproc + .size __vdso_clock_getres, . - __vdso_clock_getres + +clock_getres = __vdso_clock_getres + .weak clock_getres + + .globl __vdso_gettimeofday + .type __vdso_gettimeofday, @function + .balign 16 + .cfi_startproc +__vdso_gettimeofday: + mov $__NR_gettimeofday, %eax + syscall + ret + .cfi_endproc + .size __vdso_gettimeofday, . - __vdso_gettimeofday + +gettimeofday = __vdso_gettimeofday + .weak gettimeofday + + + .globl __vdso_time + .type __vdso_time, @function + .balign 16 + .cfi_startproc +__vdso_time: + mov $__NR_time, %eax + syscall + ret + .cfi_endproc + .size __vdso_time, . - __vdso_time + +time = __vdso_time + .weak time + + + .globl __vdso_getcpu + .type __vdso_getcpu, @function + .balign 16 + .cfi_startproc +__vdso_getcpu: + /* + * ??? There is no syscall number for this allocated on x64. + * We can handle this several ways: + * + * (1) Invent a syscall number for use within qemu. + * It should be easy enough to pick a number that + * is well out of the way of the kernel numbers. + * + * (2) Force the emulated cpu to support the rdtscp insn, + * and initialize the TSC_AUX value the appropriate value. + * + * (3) Pretend that we're always running on cpu 0. + * + * This last is the one that's implemented here, with the + * tiny bit of extra code to support rdtscp in place. + */ + xor %ecx, %ecx /* rdtscp w/ tsc_aux = 0 */ + + /* if (cpu != NULL) *cpu = (ecx & 0xfff); */ + test %rdi, %rdi + jz 1f + mov %ecx, %eax + and $0xfff, %eax + mov %eax, (%rdi) + + /* if (node != NULL) *node = (ecx >> 12); */ +1: test %rsi, %rsi + jz 2f + shr $12, %ecx + mov %ecx, (%rsi) + +2: xor %eax, %eax + ret + .cfi_endproc + .size __vdso_getcpu, . - __vdso_getcpu + +getcpu = __vdso_getcpu + .weak getcpu + +/* + * ??? Perhaps add elf notes. E.g. + * + * #include + * ELFNOTE_START(Linux, 0, "a") + * .long LINUX_VERSION_CODE + * ELFNOTE_END + * + * but what version number would we set for QEMU? + */ diff --git a/linux-user/x86_64/vdso.ld b/linux-user/x86_64/vdso.ld new file mode 100644 index 0000000000..baf261f045 --- /dev/null +++ b/linux-user/x86_64/vdso.ld @@ -0,0 +1,74 @@ +/* + * Linker script for linux x86-64 replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + clock_gettime; + __vdso_clock_gettime; + gettimeofday; + __vdso_gettimeofday; + getcpu; + __vdso_getcpu; + time; + __vdso_time; + clock_getres; + __vdso_clock_getres; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* ??? We can't really prelink to any address without knowing + something about the virtual memory space of the host, since + that leaks over into the available memory space of the guest. */ + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text =0x90909090 +} From patchwork Sat Jun 19 03:43:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463860 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp537497jao; Fri, 18 Jun 2021 20:55:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQNeXeDnt7FApVyXH0lW2r10cf3T8NuSX5Ua7T9Dc8W2kFWfKO3/AYQovr6NlNQdtDCDp1 X-Received: by 2002:a05:6e02:1002:: with SMTP id n2mr9353475ilj.260.1624074915727; Fri, 18 Jun 2021 20:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074915; cv=none; d=google.com; s=arc-20160816; b=UkVdkmVVvjVHKf1izEbTWBNJ2fJmc+kWU40+qkx6a/LEndJqA+sS9VqcmZ92pmXG2e 9Yh/B6wHA77TeeRGzvg8Lwj2PkbTP27Q/K+v+Bk8IYPKUvzBgsHm+xGJj/zzWKouRJ+4 KCiN4ahmbfdVlTyfuiGXZ4gWr7Hiqh+7ViB/Fu10LqOqYFs9Gh0qscNjlLkPBMtxSjKS gt1NoNlrElKOex+nagZ95SBGBPii4zvGV4tJAartLy/bXFby2uEmay5++r5AGCrKJ3g5 ylygCjdeSlwbp5gJFiortKeTyYhJAuH6miM4D+pH737Rx/bk/P73VcquGIxItvFuVtLc kHcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=kSp7KfgnjyVafFIoY3p7Wtj26SoZF+TYJt49SIfQL/o=; b=la+Jpz/R5X5bCbi2vUZCkwncnID4RERjjRIwAnkxqmGq6JCduoj6XD70f8loiWjpq6 fG4oy1lxgWvTEPh3/u1xbALvXQeDh9/aw8ENV7wKkP4f0oTSho123sHMr7vq6fSIj0bi WwQFZdU7ktAs8XEBZOV3dZTH08kaxlI2rKKTxCs0F+WmmtgljMU3yq11VAPlZKbxRgqk GpQQqfErNm0fP03Vl+VSPWnra/uyrm1YICil6F/XtfJrfd/haUyMB0Rkx6u22Ek1bh9s LP6bokvO4fTtx5OgdlZ5XYAw0BybPNLy1tiQeqZIJgO3L4WvP1NiP2v0aPHQySW1uyry hi7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KVi5qQRh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i10si11093626ioo.56.2021.06.18.20.55.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:55:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KVi5qQRh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luS4h-0002jS-6I for patch@linaro.org; Fri, 18 Jun 2021 23:55:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRte-0000G7-06 for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:50 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:39466) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtT-00083s-0P for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:49 -0400 Received: by mail-pf1-x42e.google.com with SMTP id g192so1535332pfb.6 for ; Fri, 18 Jun 2021 20:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kSp7KfgnjyVafFIoY3p7Wtj26SoZF+TYJt49SIfQL/o=; b=KVi5qQRhrgEDWhuK/xKMiaDbCXyel4gzapVmvNo+0y0YDXjZgXD3EPLhBIuJNsHMSu RPdyTTBKR3m+igs/+VylIlogfvOJq3HU0K9l/T56RRG71m+vTVemYLJgMrk3+DE45MRM Asm03Z7o5IP/ZN+D96MsuBTIy1ejIYeP80XACPwdTgQiPi+7RdbBFXBjQTTG7Y7fRjRy pISt1kb/eYkVJAxYYnr+Tmpxyio/dyYUJ4EO4ghJneVAech894EdlPVEAQZUbuKkhHtO 15UepEzQMA8SUhwaBThLRAM2UUUNDAqak0gdo6AoaqBjcQeaxoif/C+3DGDKrWWG+qv7 NmVQ== 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=kSp7KfgnjyVafFIoY3p7Wtj26SoZF+TYJt49SIfQL/o=; b=ZOC031IRECpqEeqGbqn7pE8qoQo4YW5x/WPON4R4ca+72kXPGnwVcA0ySmlOX/F3Rb Ca0JhyT+8282CePZ5gX1pT/9yB+0dei9IwcfsAOWXzwfvYmuZBuURqy3FrO9axMfrUtj JzK44fdGVkAx2CDSDrKPZa5G001H8nr+neAKbg1wW2foHyNa7El8mspm2sdi4HVoLhld tfg4K9Q0pF/PBNql13NcnE2Qfox9iI6gp1H445vjFYzGeaGQjflDB/G+BhkQOJOyBhOW vzVIB2jpCnQUXKaoBihj7ubjWF3fv7ll+/SAsVwGfQPYUiExdzJfT7T/ztNNrW4a1cTb mrEA== X-Gm-Message-State: AOAM532pYGrIwS9dQalfcmyiQKNbwfg98LEmblSAFGSx++ixfHr4U+UB 4nrImaC+plDDHcJ45BUhwksWtZGDcd9RDA== X-Received: by 2002:a63:ed17:: with SMTP id d23mr12903165pgi.107.1624074217674; Fri, 18 Jun 2021 20:43:37 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 12/12] linux-user/hppa: Add vdso and use it for rt_sigreturn Date: Fri, 18 Jun 2021 20:43:29 -0700 Message-Id: <20210619034329.532318-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Building the vdso itself is not actually wired up to anything, since we require a cross-compiler. Just check in that file for now. Drop the now-unused 9 trampoline words, and describe the frame without the trampoline in __kernel_rt_sigreturn. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 3 + linux-user/hppa/signal.c | 8 +- linux-user/hppa/Makefile.vdso | 4 + linux-user/hppa/meson.build | 6 ++ linux-user/hppa/vdso.S | 149 ++++++++++++++++++++++++++++++++++ linux-user/hppa/vdso.ld | 75 +++++++++++++++++ linux-user/hppa/vdso.so | Bin 0 -> 5192 bytes 7 files changed, 238 insertions(+), 7 deletions(-) create mode 100644 linux-user/hppa/Makefile.vdso create mode 100644 linux-user/hppa/vdso.S create mode 100644 linux-user/hppa/vdso.ld create mode 100755 linux-user/hppa/vdso.so diff --git a/linux-user/hppa/vdso.so b/linux-user/hppa/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..a314dc70f2ae8548bfb1e4137039f983fad094e6 GIT binary patch literal 5192 zcmeHLS#MiK6rOQ1r7WRN6$wxP@lZs8)^rJ_&;oH{J1IDuleA3;+`6?Jnt|BMun=Uf z({)XK>e{Y>LRQ8OLH}(A?}JXZ^(p5f9nW|_wqwtIW!AM>->&BwF7a(SH8lO#?>O>z zubECkC`O{}ndlBTH@P#0;CUiOU|4P@`0@Y&rSLnovdk!!3 z_drZY#FuwQoGj5to06=KX~>|#9zSsM?2*!;pM~RW%esZ^fa7{jG2icIy%Dz{2J(fG z($djPaVUbn<)S0r(#>@tQ&FO#tor5jarlTM&r1CKFNF|Qy;s9xjHJ&YYb(}3CvMnJ z)d@dY{KN#gJ=G~HD|=+^!YjX@*tvM}+FjS}zJAY=y-OdC?7LzAvIENxu6ShSqjitn zcxct(n~to0{N^Wad2-EDYoEULncJSd{ki(*qc1cZZG18IQvBt_v9{ywuXMbcI??%B z*X!MHtbcRE$&GLIyxn{1u6O$0z5Bg;-giFO^kMp=%~M-G&U}*nbn9pRpXa{Fe|hg$ z+rA$7X7F@D)eouYuxhwZHM%NRRB=xwMpVvqFh_8{oKZr>|Tg***_T&KUhxL5SA=J#E@)Z5B zIhTUu6n|lGeg*0Inl@%^ZDTIdalR#h{P`L2^NhWS683y!_ZjuHU)tZT&Z+|=6b#G9Q&D%uiv znqw*9G$q>_qDiMMk?4$fIbG3)WZd!R=eb915h;!hdg;xOp6kn;)iPs+^k9CAh(JLW zWZFxMNPl4@l1mqJzTb0w&uG>y=7$Qi3@0NZ*_^Z0O%G;dcOPl`(#KllG&(UfvNL#NO`pi5R_QXH){sy-o1nd9+ literal 0 HcmV?d00001 -- 2.25.1 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b70a5c48a2..6cea556b70 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1457,6 +1457,9 @@ static inline void init_thread(struct target_pt_regs *regs, #define STACK_GROWS_DOWN 0 #define STACK_ALIGNMENT 64 +#define HAVE_VDSO 1 +#include "vdso.c.inc" + static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) { diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c index 0e266f472d..44e2db6d3e 100644 --- a/linux-user/hppa/signal.c +++ b/linux-user/hppa/signal.c @@ -40,7 +40,6 @@ struct target_ucontext { }; struct target_rt_sigframe { - abi_uint tramp[9]; target_siginfo_t info; struct target_ucontext uc; /* hidden location of upper halves of pa2.0 64-bit gregs */ @@ -138,14 +137,9 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, setup_sigcontext(&frame->uc.tuc_mcontext, env); - __put_user(0x34190000, frame->tramp + 0); /* ldi 0,%r25 */ - __put_user(0x3414015a, frame->tramp + 1); /* ldi __NR_rt_sigreturn,%r20 */ - __put_user(0xe4008200, frame->tramp + 2); /* be,l 0x100(%sr2,%r0) */ - __put_user(0x08000240, frame->tramp + 3); /* nop */ - unlock_user_struct(frame, frame_addr, 1); - env->gr[2] = h2g(frame->tramp); + env->gr[2] = default_rt_sigreturn; env->gr[30] = sp; env->gr[26] = sig; env->gr[25] = h2g(&frame->info); diff --git a/linux-user/hppa/Makefile.vdso b/linux-user/hppa/Makefile.vdso new file mode 100644 index 0000000000..ce92d51a37 --- /dev/null +++ b/linux-user/hppa/Makefile.vdso @@ -0,0 +1,4 @@ +vdso.so: vdso.S vdso.ld Makefile.vdso + hppa-linux-gnu-gcc -nostdlib -shared -Wl,-T,vdso.ld \ + -Wl,-h,linux-vdso.so.1 -Wl,--build-id=none \ + -Wl,--hash-style=both vdso.S -o $@ diff --git a/linux-user/hppa/meson.build b/linux-user/hppa/meson.build index 4709508a09..3febe8523a 100644 --- a/linux-user/hppa/meson.build +++ b/linux-user/hppa/meson.build @@ -3,3 +3,9 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +gen = [ + gen_vdso.process('vdso.so') +] + +linux_user_ss.add(when: 'TARGET_HPPA', if_true: gen) diff --git a/linux-user/hppa/vdso.S b/linux-user/hppa/vdso.S new file mode 100644 index 0000000000..eeae2c999a --- /dev/null +++ b/linux-user/hppa/vdso.S @@ -0,0 +1,149 @@ +/* + * hppa linux kernel vdso replacement. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + + .text + +#define sizeof_rt_sigframe 696 +#define offsetof_sigcontext 152 +#define offsetof_sigcontext_gr offsetof_sigcontext + 4 +#define offsetof_sigcontext_fr offsetof_sigcontext_gr + 32 * 4 +#define offsetof_sigcontext_iasq offsetof_sigcontext_fr + 32 * 8 +#define offsetof_sigcontext_iaoq offsetof_sigcontext_iasq + 8 +#define offsetof_sigcontext_sar offsetof_sigcontext_iaoq + 8 + + /* + * While this frame is marked as a signal frame, that only applies + * to how this return address is handled for the outer frame. + * The return address that arrived here, from the inner frame, is + * not marked as a signal frame and so the unwinder still tries to + * subtract 1 to examine the presumed call insn. Thus we must + * extend the unwind info to a nop before the start. + */ + + .cfi_startproc simple + .cfi_signal_frame + + /* Compare pa32_fallback_frame_state from libgcc. */ + + /* Record the size of the stack frame. */ + .cfi_def_cfa 30, -sizeof_rt_sigframe + + /* Record save offset of general registers. */ + .cfi_offset 1, offsetof_sigcontext_gr + 1 * 4 + .cfi_offset 2, offsetof_sigcontext_gr + 2 * 4 + .cfi_offset 3, offsetof_sigcontext_gr + 3 * 4 + .cfi_offset 4, offsetof_sigcontext_gr + 4 * 4 + .cfi_offset 5, offsetof_sigcontext_gr + 5 * 4 + .cfi_offset 6, offsetof_sigcontext_gr + 6 * 4 + .cfi_offset 7, offsetof_sigcontext_gr + 7 * 4 + .cfi_offset 8, offsetof_sigcontext_gr + 8 * 4 + .cfi_offset 9, offsetof_sigcontext_gr + 9 * 4 + .cfi_offset 10, offsetof_sigcontext_gr + 10 * 4 + .cfi_offset 11, offsetof_sigcontext_gr + 11 * 4 + .cfi_offset 12, offsetof_sigcontext_gr + 12 * 4 + .cfi_offset 13, offsetof_sigcontext_gr + 13 * 4 + .cfi_offset 14, offsetof_sigcontext_gr + 14 * 4 + .cfi_offset 15, offsetof_sigcontext_gr + 15 * 4 + .cfi_offset 16, offsetof_sigcontext_gr + 16 * 4 + .cfi_offset 17, offsetof_sigcontext_gr + 17 * 4 + .cfi_offset 18, offsetof_sigcontext_gr + 18 * 4 + .cfi_offset 19, offsetof_sigcontext_gr + 19 * 4 + .cfi_offset 20, offsetof_sigcontext_gr + 20 * 4 + .cfi_offset 21, offsetof_sigcontext_gr + 21 * 4 + .cfi_offset 22, offsetof_sigcontext_gr + 22 * 4 + .cfi_offset 23, offsetof_sigcontext_gr + 23 * 4 + .cfi_offset 24, offsetof_sigcontext_gr + 24 * 4 + .cfi_offset 25, offsetof_sigcontext_gr + 25 * 4 + .cfi_offset 26, offsetof_sigcontext_gr + 26 * 4 + .cfi_offset 27, offsetof_sigcontext_gr + 27 * 4 + .cfi_offset 28, offsetof_sigcontext_gr + 28 * 4 + .cfi_offset 29, offsetof_sigcontext_gr + 29 * 4 + .cfi_offset 30, offsetof_sigcontext_gr + 30 * 4 + .cfi_offset 31, offsetof_sigcontext_gr + 31 * 4 + + /* Record save offset of fp registers, left and right halves. */ + .cfi_offset 32, offsetof_sigcontext_fr + 4 * 8 + .cfi_offset 33, offsetof_sigcontext_fr + 4 * 8 + 4 + .cfi_offset 34, offsetof_sigcontext_fr + 5 * 8 + .cfi_offset 35, offsetof_sigcontext_fr + 5 * 8 + 4 + .cfi_offset 36, offsetof_sigcontext_fr + 6 * 8 + .cfi_offset 37, offsetof_sigcontext_fr + 6 * 8 + 4 + .cfi_offset 38, offsetof_sigcontext_fr + 7 * 8 + .cfi_offset 39, offsetof_sigcontext_fr + 7 * 8 + 4 + .cfi_offset 40, offsetof_sigcontext_fr + 8 * 8 + .cfi_offset 41, offsetof_sigcontext_fr + 8 * 8 + 4 + .cfi_offset 42, offsetof_sigcontext_fr + 9 * 8 + .cfi_offset 43, offsetof_sigcontext_fr + 9 * 8 + 4 + .cfi_offset 44, offsetof_sigcontext_fr + 10 * 8 + .cfi_offset 45, offsetof_sigcontext_fr + 10 * 8 + 4 + .cfi_offset 46, offsetof_sigcontext_fr + 11 * 8 + .cfi_offset 47, offsetof_sigcontext_fr + 11 * 8 + 4 + .cfi_offset 48, offsetof_sigcontext_fr + 12 * 8 + .cfi_offset 49, offsetof_sigcontext_fr + 12 * 8 + 4 + .cfi_offset 50, offsetof_sigcontext_fr + 13 * 8 + .cfi_offset 51, offsetof_sigcontext_fr + 13 * 8 + 4 + .cfi_offset 52, offsetof_sigcontext_fr + 14 * 8 + .cfi_offset 53, offsetof_sigcontext_fr + 14 * 8 + 4 + .cfi_offset 54, offsetof_sigcontext_fr + 15 * 8 + .cfi_offset 55, offsetof_sigcontext_fr + 15 * 8 + 4 + .cfi_offset 56, offsetof_sigcontext_fr + 16 * 8 + .cfi_offset 57, offsetof_sigcontext_fr + 16 * 8 + 4 + .cfi_offset 58, offsetof_sigcontext_fr + 17 * 8 + .cfi_offset 59, offsetof_sigcontext_fr + 17 * 8 + 4 + .cfi_offset 60, offsetof_sigcontext_fr + 18 * 8 + .cfi_offset 61, offsetof_sigcontext_fr + 18 * 8 + 4 + .cfi_offset 62, offsetof_sigcontext_fr + 19 * 8 + .cfi_offset 63, offsetof_sigcontext_fr + 19 * 8 + 4 + .cfi_offset 64, offsetof_sigcontext_fr + 20 * 8 + .cfi_offset 65, offsetof_sigcontext_fr + 20 * 8 + 4 + .cfi_offset 66, offsetof_sigcontext_fr + 21 * 8 + .cfi_offset 67, offsetof_sigcontext_fr + 21 * 8 + 4 + .cfi_offset 68, offsetof_sigcontext_fr + 22 * 8 + .cfi_offset 69, offsetof_sigcontext_fr + 22 * 8 + 4 + .cfi_offset 70, offsetof_sigcontext_fr + 23 * 8 + .cfi_offset 71, offsetof_sigcontext_fr + 23 * 8 + 4 + .cfi_offset 72, offsetof_sigcontext_fr + 24 * 8 + .cfi_offset 73, offsetof_sigcontext_fr + 24 * 8 + 4 + .cfi_offset 74, offsetof_sigcontext_fr + 25 * 8 + .cfi_offset 75, offsetof_sigcontext_fr + 25 * 8 + 4 + .cfi_offset 76, offsetof_sigcontext_fr + 26 * 8 + .cfi_offset 77, offsetof_sigcontext_fr + 26 * 8 + 4 + .cfi_offset 78, offsetof_sigcontext_fr + 27 * 8 + .cfi_offset 79, offsetof_sigcontext_fr + 27 * 8 + 4 + .cfi_offset 80, offsetof_sigcontext_fr + 28 * 8 + .cfi_offset 81, offsetof_sigcontext_fr + 28 * 8 + 4 + .cfi_offset 82, offsetof_sigcontext_fr + 29 * 8 + .cfi_offset 83, offsetof_sigcontext_fr + 29 * 8 + 4 + .cfi_offset 84, offsetof_sigcontext_fr + 30 * 8 + .cfi_offset 85, offsetof_sigcontext_fr + 30 * 8 + 4 + .cfi_offset 86, offsetof_sigcontext_fr + 31 * 8 + .cfi_offset 87, offsetof_sigcontext_fr + 31 * 8 + 4 + + /* Record save offset of %sar */ + .cfi_offset 88, offsetof_sigcontext_sar + + /* Record save offset of return address, iaoq[0]. */ + .cfi_return_column 89 + .cfi_offset 89, offsetof_sigcontext_iaoq + + nop + +__kernel_rt_sigreturn: + + ldi 0, %r25 + ldi __NR_rt_sigreturn, %r20 + be,l 0x100(%sr2, %r0), %sr0, %r31 + nop + + .cfi_endproc + + .size __kernel_rt_sigreturn, . - __kernel_rt_sigreturn + .type __kernel_rt_sigreturn, @function + .globl __kernel_rt_sigreturn diff --git a/linux-user/hppa/vdso.ld b/linux-user/hppa/vdso.ld new file mode 100644 index 0000000000..fed994c3eb --- /dev/null +++ b/linux-user/hppa/vdso.ld @@ -0,0 +1,75 @@ +/* + * Linker script for linux hppa vdso. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +/* + * Note that the kernel does not implement a vdso for hppa. + * Mirror the symbol that other targets use for this, e.g. i386. + */ + +VERSION { + QEMU { + global: + __kernel_rt_sigreturn; + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + data PT_LOAD FLAGS(6) FILEHDR PHDRS; + text PT_LOAD FLAGS(5); + dynamic PT_DYNAMIC FLAGS(4); + note PT_NOTE FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; +} + +SECTIONS { + . = SIZEOF_HEADERS; + + /* The following, including the FILEHDRS and PHDRS, are modified + when we relocate the binary. We want them to be initially + writable for the relocation; we'll force them read-only after. */ + .note : { *(.note*) } :data :note + .dynamic : { *(.dynamic) } :data :dynamic + .dynsym : { *(.dynsym) } :data + .data : { + /* There ought not be any real read-write data. + But since we manipulated the segment layout, + we have to put these sections somewhere. */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :data :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :data + + . = ALIGN(4096); + .text : { *(.text*) } :text +}