From patchwork Mon Oct 30 21:17:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739284 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337118wrt; Mon, 30 Oct 2023 14:20:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4KW3E6N7s1dJ25qQgxgLlXt5YcL6CqLja0zUO6OsFN/6naKfsFi1QsP53UUsjmvGwxWC9 X-Received: by 2002:a05:6808:4c:b0:3a8:7c67:7cd with SMTP id v12-20020a056808004c00b003a87c6707cdmr10326634oic.24.1698700815707; Mon, 30 Oct 2023 14:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700815; cv=none; d=google.com; s=arc-20160816; b=foyHZM7kqiZa9rxPAUw8KHrT+G9vyTLJGmWfkowm2Di/Ik92EGVejiIHDdDWrwxJ/l ks7S5aHvqCOFziKf5epTiAbY9IPIUEEUom/9kjYpwllE/aMYXfid6X8JL45rfG9klK2/ gsgbflCclWHgbL3veM7QRJRgJhR3zntHrx0WbXMSozKcFYMfdXnZJQEjybjJ0lLAsvEy DNzfdlKR3Ph+LsPhhPQQO6T51vqiTmBFfRny4RfG/9izo5ef96jJmoKIcxyVw+lt3GTJ NVcUKeW2otSC8q+97XTNiS+/NUmfg8ch1AKtw6sqAQtMKASF5poAlVXCa1umP94MvrvE TPCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=DJYOGFevT1c73O/W4pBjxGvOP2r/M3Vo19QIR1W5oz0=; fh=eu2DY09p+eeddYDiV+DalJS3Vr0kxK5BujclYkgWvDw=; b=kU9dlBpScQCda1cTQxVW2018MtwNUZ1YBmGKxXSU/g7DuCOoHcIJhrlJ64L7e4XuMv bYpZkS6M+Ptc5CNeswWdfxQ5B0tTQwBG1+W1zc3D6q77bfue2if2uxYiZYO+FvFjlt2x WYgYNHSyaePbJWgaMp8xVNB8bFn78yLIrnfoq+S58SYnJH9K+dqg/wODrThMJihZbBv/ ZdfCPIAO7NXx4wXgWHiN0CdQcRXrr4oqCAQhGdqjIlohU/kvIEmPH73OE4Rb/77GCBCd IWNXRXdULNPEyajlq2uY02pfQOzRlwLwNNluhCHeHeAKgtdFICvvL1og5Dg75siFt/NQ JcXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P3sO90mN; 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=pass (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 t20-20020a05620a451400b00779ab3d4204si6472326qkp.648.2023.10.30.14.20.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:20: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=pass header.i=@linaro.org header.s=google header.b=P3sO90mN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZeK-0001Ll-U8; Mon, 30 Oct 2023 17:18:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdf-0000yn-N6 for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:38 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZda-0006TW-KM for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:33 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1cc5fa0e4d5so6033385ad.0 for ; Mon, 30 Oct 2023 14:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700649; x=1699305449; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DJYOGFevT1c73O/W4pBjxGvOP2r/M3Vo19QIR1W5oz0=; b=P3sO90mNgq42Zz67d72qsug/RpH+FJbh4I4Pghaxum+ipOKr801MEEBxGKVlhOe8hO D/Eqt8PiMDbNGg8L5x87/DmlgDN8rYjXoUIEqqhcu58Lew/G7cjVMCq90uBAs57XxT6F QSXIjzJrpgaccqk+8gPNf2VlCHTJYUM5A9jPb/TvLhe0BIWQoveCAzpC/JOixHMIwYMy BzL+IIMdXUpp4CLsm6hb3tfFFWK3J9WLilkE+JAQMV2WNSEkLM/xVIcFo+9tsl8f52Qm ez3FqlPZTcPtpvwgDAeHuoNBi7IJj4PscrZh6yn3hNezIkdX85yyzs1xhyXHPd8LVE8H MMjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700649; x=1699305449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DJYOGFevT1c73O/W4pBjxGvOP2r/M3Vo19QIR1W5oz0=; b=mKSsZWYUshnw9VhqUNEU/IdsSeuwHYqyyBwVpCsXNOydZFNM61LcXdIrfdcTuLPc1N tVFmk469m73iUeJDKTzgEmrGihuKeQVkhbAV6ZHBbCXvwI/ZNs/OlPbx5HS7H9wnKY4z QgR6GqqENEMmPIKVcXblFIQIeKEISqsdsYtYsngrL7OOkCrgtZ7luzcB146FkUwKwjmc 6VpA/CWWLk/Gc8HPXgoY2jjYyyzdk/kIVVoWC2RrLP+MmcH9OBWJFCYAegvVM7hlL0F0 UgI7PNb+9lcYi6621KN699mMk+nVRyJGWHjvN6Hnp5m0lMFeINZDzjO87Wbb4l0EbYGO cMyA== X-Gm-Message-State: AOJu0YyCRgBhjJqalKF18gpcPk0pXz7Jk7b5uG8vAFxnlJwo+KBQhv2O DR85I91U1sp7wx8j+JkLF2ncih6np4E83PSc5SY= X-Received: by 2002:a17:903:228f:b0:1cc:543b:b361 with SMTP id b15-20020a170903228f00b001cc543bb361mr2327939plh.43.1698700649052; Mon, 30 Oct 2023 14:17:29 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 01/21] linux-user: Fix guest signal remapping after adjusting SIGABRT Date: Mon, 30 Oct 2023 14:17:07 -0700 Message-Id: <20231030211727.165090-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The arithmetic within the loop was not adjusted properly after SIGRTMIN was stolen for the guest SIGABRT. The effect was that the guest libc could not send itself __SIGRTMIN to wake sleeping threads. Fixes: 38ee0a7dfb4b ("linux-user: Remap guest SIGABRT") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1967 Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- linux-user/signal.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 3b8efec89f..b35d1e512f 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -536,11 +536,10 @@ static void signal_table_init(void) host_to_target_signal_table[SIGABRT] = 0; host_to_target_signal_table[hsig++] = TARGET_SIGABRT; - for (; hsig <= SIGRTMAX; hsig++) { - tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; - if (tsig <= TARGET_NSIG) { - host_to_target_signal_table[hsig] = tsig; - } + for (tsig = TARGET_SIGRTMIN; + hsig <= SIGRTMAX && tsig <= TARGET_NSIG; + hsig++, tsig++) { + host_to_target_signal_table[hsig] = tsig; } /* Invert the mapping that has already been assigned. */ From patchwork Mon Oct 30 21:17:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739288 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337553wrt; Mon, 30 Oct 2023 14:21:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPwhgeuOakKl/zAknLeCXNwECtcYfAoKHNKtyqgSr8P53hUBSnxptOrhiaPEra1xm4YP9R X-Received: by 2002:a05:6870:1191:b0:1ef:b109:b8ca with SMTP id 17-20020a056870119100b001efb109b8camr6611526oau.34.1698700904222; Mon, 30 Oct 2023 14:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700904; cv=none; d=google.com; s=arc-20160816; b=joGGFQMIzzaSR7mbEeOc+jOJQKZeQwxW8Joxo7lDCbgs6APr9AWjnmTkaaXG5EltUk mJfXlG85KAh/2ePdA/XqR8JMbmpc2A27Na5pTeQL7EjAWyjV+HXfHbCFHu5MIgv5jf9w f/vuP9Ji7RdBtyusLCtgcUhshw1fwLoinfDcVw0GqGA0gSlYmWbwpatrcqFXJ7ZlzCfJ esUJQRc3OH6V6UvrnuNOYluM6Yz3ieqLpoDf/DKYMc0LFx2LYiDEkF6DuOq1jpJ1lYUz P/aWZqBllnXhx4SohctGCmMvbOlFRutqBHkka9BDpWWyNiAB6n3JCVdE7rdLoELu8AEM ZB9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=yzz2vrun9ZHolGGbK5hlMNaXrSfdtOTmji9iHcf/zms=; fh=D6FqPLU6GE0ldmgADbJ5dLNMSeh7MbgWcAv41ubRnOE=; b=H4SOM7mGcANscxPCpAg2rOYhGgytqIsTRyaVzewBMLdqzgscLXg4FBM/8qSEFgY0lH UUOJF8PfRKSgut3l8THDOuAfQ6T94u7vslXVxrJfTztVXPGwzm+ACBRftOhXPyib+hU5 vid+6F1aK6Z8AfzFE2oEoUdAXhsvZjjfbjEDRV523I/wxJMI/093Bun6SS/ovzcgyF4+ 7hqo2lGvHk1zjtBuOfrRvwrSQwP0gFlnRmTS+SoJ9j+OJKgncfK2HQXcYnuhak59QNUp Qx3Rfy0twU/bgHebOpnw/EIJ3ajsgSUZsFuCV4Y1d4AXNmCmYOyFzg/AaaVzxU0jc2dp 5VgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZUyARYYZ; 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=pass (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 w20-20020a05622a135400b0041b78c3bdd3si6292735qtk.184.2023.10.30.14.21.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:21: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=pass header.i=@linaro.org header.s=google header.b=ZUyARYYZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZdx-00010x-FL; Mon, 30 Oct 2023 17:17:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdf-0000yo-Mw for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:37 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdb-0006Te-Ty for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:34 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1cc3bb4c307so11455875ad.0 for ; Mon, 30 Oct 2023 14:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700650; x=1699305450; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yzz2vrun9ZHolGGbK5hlMNaXrSfdtOTmji9iHcf/zms=; b=ZUyARYYZhZIEXBcQtRYoYz7BMknWUpaIeHPmVEXoOHFg6WDxABhQS0KdqbuYTH7reB waKhsYYcA1ZjirgIFaXNVj/hwHu3/20IT74JXgByUi9mFeN2fstATPDNODtiAKGnP+g0 XQlvSJpHiJDGt/RG2pdMCCAwnwzP0oCuvTeQTpTQNRSyYGLnYqUzmw0ve33r2DmZLbd4 8nt54jHe4XNFLTf4Yr7VoPOKe7K4Xy7qEbAHXXAj6ZSkydn3rxX/L+ZlYclkXKfMbWER eaUJgb/DlvqfTs3nUQl2PmFkRE0rWVUbaCGWAAGeQ5BjBtBv6U1huTHbqeO6cI8jzQKB w6Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700650; x=1699305450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yzz2vrun9ZHolGGbK5hlMNaXrSfdtOTmji9iHcf/zms=; b=IWMH3n51roHpgT6Lj4q1XgR1B4SWTEbB84XKTj5fkLGM4NbW8maeDybNmNeHXBhVmm vU5eR+hUz4kxZgW1b/kCDw1ZLdjteU65c+SQ+njyImWvNm+SbE/6feSiomWk3Y10Mmmq L38wysjs5JtsluzcocH7KVTa2KcHNWs2B5B8o013vFOYUj5YfeIvErYQ6uKlx9SwXKcZ gsMA+LxHY+wc2nOBl6ja6pDo4G4gnhqwegB2MMfKwjalIwJZvVIenAWTN8p1gJHQ0Hc6 K04mHFoboMuBt3aSaA8588R6rYtlr3bdc3egYRKgc1qirl/gdy2b0o+YtO+Yy5cOMQTD 1Bqw== X-Gm-Message-State: AOJu0YzXYypPvPaAx4cDQEZ+BiEG1ZM7cuN2Ib28O/WXFlsAp0HsLpwK 0X3p7iDWvpMkWD6/uU5gOjrsBhlckvzEv07kVvQ= X-Received: by 2002:a17:903:32d1:b0:1cc:3bc9:b924 with SMTP id i17-20020a17090332d100b001cc3bc9b924mr4169483plr.25.1698700649894; Mon, 30 Oct 2023 14:17:29 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= Subject: [PULL 02/21] linux-user: Introduce imgsrc_read, imgsrc_read_alloc Date: Mon, 30 Oct 2023 14:17:08 -0700 Message-Id: <20231030211727.165090-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Introduced and initialized, but not yet really used. These will tidy the current tests vs BPRM_BUF_SIZE. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/loader.h | 61 +++++++++++++++++++++++----- linux-user/linuxload.c | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 9 deletions(-) diff --git a/linux-user/loader.h b/linux-user/loader.h index 324e5c872a..da6591fff0 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -18,6 +18,48 @@ #ifndef LINUX_USER_LOADER_H #define LINUX_USER_LOADER_H +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); + +/** + * 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. @@ -29,15 +71,16 @@ * 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 */ }; void do_init_thread(struct target_pt_regs *regs, struct image_info *infop); diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 745cce70ab..3536dd8104 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -3,7 +3,9 @@ #include "qemu/osdep.h" #include "qemu.h" #include "user-internals.h" +#include "user-mmap.h" #include "loader.h" +#include "qapi/error.h" #define NGROUPS 32 @@ -76,6 +78,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; } @@ -139,6 +145,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; @@ -173,3 +180,86 @@ 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; +} + +abi_long imgsrc_mmap(abi_ulong start, abi_ulong len, int prot, + int flags, const ImageSource *src, abi_ulong offset) +{ + const int prot_write = PROT_READ | PROT_WRITE; + abi_long ret; + 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); + + 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 Mon Oct 30 21:17:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739290 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337810wrt; Mon, 30 Oct 2023 14:22:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQLZw5Gqi8gFDnlbc9YONGemGGfGhM/hKcKtidSEyuuz+QeF2PHbmibN62uDfSylGBAxea X-Received: by 2002:a05:6870:938b:b0:1ea:d8bb:411a with SMTP id b11-20020a056870938b00b001ead8bb411amr13311228oal.6.1698700945925; Mon, 30 Oct 2023 14:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700945; cv=none; d=google.com; s=arc-20160816; b=X9FeNNayP2bwCTrSH18jgkMqStnaAxrhj78MybVg6QEx7asLCREZ1/Na/Vd7xYq/CP XPgj7Av7ZMjWkrGefbVlubOPIS6wumjnWHqHKQaOdHUWYIOjqi3K7FJnzdGxNlqkZNfD VQff44ZQkIPKM+Fx+GGVn9iU6J4CFIbvprkpjMLoh8x9UiJUah2LFquHTwPhEh4If1ME NKVo/98kaIO4t9hAOHA5wzy6bFD8fPScprquy6PbwZ3Fectu5cIO1FgmyxVGAxnah3Bg 8HrJq/ifrdEgqXuFrqhEsCkweaiqE0PmCe5KxcDuTRln8nBovs4LIofZEj/x1e/vHKGD mNKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; fh=TJcPpxAJvLhucmTZUfF+2W5jJzSYDTiYy3AR4GGmc9w=; b=yZCAQRKFl3BFDgBdtgd9Aq9XLYW/pAEHoryP2yySx3IGf2ZUsL9qKm62yktqb//w3n OgWc8WADYbOyzEusZR4pRzHth3hR8oUa8086FRjDvCR1c4SfFvwD3XpCiS7IV6jJa3KU iWmC8dzF/pYsUT87CjmEZ8YadIi27CS7jxFtCvt3vFLtjqcWClSh3OCx6anZD2Vt/Nnn Df3JlRp4zmq0eP+wYqNuiADqsLks3KUz5xQl5tVX1eN/SIC6IqdGAJtnl85fVsdz94ru dNrH/nKBlix8c8eZ1ZfTNQ+C7DrP+DuLgAqI6y81rGpaEzvyXBuhtnCTc/6SHRdZLIci di+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=njytOOws; 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=pass (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 c5-20020a05622a024500b00418079720b3si6572316qtx.533.2023.10.30.14.22.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:22:25 -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=pass header.i=@linaro.org header.s=google header.b=njytOOws; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZe5-00015c-0j; Mon, 30 Oct 2023 17:18:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdj-0000z2-MY for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:43 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZde-0006Tn-5L for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:37 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1cc2f17ab26so18676805ad.0 for ; Mon, 30 Oct 2023 14:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700651; x=1699305451; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=njytOOws06NJGKXzL2npjNOWR5Md0KE+QBFC/Mfgegqr1eFWZGMuIxlbLHm0odGWMv N2pKduU39uiWKq1DFu2qKyrkHQRGmEsHbDurW5988U8FaHMubW6ZWxQT1FSPL7AUMo+F Zduqq1mvFzi6O9Lh5QnsWDY2fJ45LcfCDZaLijkSr7sBtt3faI3vhAPwYJbnv07WUa8d FrKQA+XZezTLzcnU2I76bbD9Um2yOAQHxotF0AOgljLL6BbE1HTtB46r/xwrn892YH1T ZvE3j2r3SW5ieuQGyW510GkDudnOng0EPAWwHUMP4xj/ZdZys85oF1Q4Evui/jeJ2kE/ TlkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700651; x=1699305451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=CuLovq88fxdc29adpSTdF+oT7HOF14PVpg7Y2cmdXczrW8aGvkWj22NecogA027rTF DrRD6l3r82i98PxNmjcHaEPyTmodLDvk9jAJLCDJvzSZRh2M7Hd3zXvbN0VlsHGq9opH CU0XgTF5+cpsRmvaGRf3mG9flt2M9hnPSnPnOxLjls6MPZCpLPomL2h4tUJ8qIDqv0S9 yRA1BrcE8oEd8JA2NrVp67ys2fMesuVpbXHm+bj/fHyvMYQHL31m7UAWyernMCBDkAt3 Z93554MmZmmWQjjfI1s9tZpKLk+CPOCiQdNFweIEAv47QBQ1cEO3ij61SQR5xMoRB2Kt 8pRA== X-Gm-Message-State: AOJu0YzG1BcOb/9DKwKRcfFe/IfHsQIQnfiVaeEvBoPMSiO4DXd74Rhj HerhWhiDR1LjZtC4Ilo3jfawNXAb9EsijqZ7sHM= X-Received: by 2002:a17:902:6b0c:b0:1ca:2ec4:7f38 with SMTP id o12-20020a1709026b0c00b001ca2ec47f38mr7698634plk.17.1698700651016; Mon, 30 Oct 2023 14:17:31 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= Subject: [PULL 03/21] linux-user: Tidy loader_exec Date: Mon, 30 Oct 2023 14:17:09 -0700 Message-Id: <20231030211727.165090-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/linuxload.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 3536dd8104..5b7e9ab983 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -154,31 +154,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 Mon Oct 30 21:17:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739273 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1336484wrt; Mon, 30 Oct 2023 14:18:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmCRuPSXxbtwB69+Vv1q5VgEsrlF8+qZeAohPJYRQ8por+k6RgpDAAKY1QhtMLayrBMFrx X-Received: by 2002:a05:620a:1a04:b0:777:3da6:532a with SMTP id bk4-20020a05620a1a0400b007773da6532amr1438392qkb.37.1698700705295; Mon, 30 Oct 2023 14:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700705; cv=none; d=google.com; s=arc-20160816; b=0x57kPQdItrbEuXETetLiqBlPqKrArgoi0I7wlLy/fxVXZ/Zy/sdT1FWGX9JVAoGh1 pbONZF+mzXzDhjIdB+nY7BPUjCLc/9l1RmMdAAnbDXorGcwRZ9E7dGbPIpwTBTnCPw/S rcMLE3wQBZzpaM9prlZhfPSiiCb+B51g9pZ6He12JJGzBMXgjnFF28+yb4HlmPs0GnLu GEfX489eB8hzW2GhDVIy7Eb/RUWiBll7/u7pJ80hKXzzrqbOY0SGt5Y6owSelbvBV+0h GFclXzQ4BJx++uyuFD77XdEcSemCpFN9ydN1q0XU/0KJktnGtFaAbZIMvcYypbbYgV/a vZIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=PZXxxvjyYdMGysXW9TK679xn7phxp04idRu5d5Pr4As=; fh=TJcPpxAJvLhucmTZUfF+2W5jJzSYDTiYy3AR4GGmc9w=; b=TjH2GVKI4qKUqzIwnxLRsK2wGqyORdQTk/WpkGMutWjF8XL1x5Ok8HBZcv+ynJ3msl WBA/+2NsKrAxJuJ9jf3Fu8Gm/BXuGSPMXB9t98hY/YIMhMewcr0PTT0mR8mYsuTkup1k XPApfM7w3xwL4GJn2RfN6XOvxoNjIYpTuOm6p/8IzgpwXvkVXzdMT2LeL+N7hJJHqXUD cfedfk4QkZU4wzyrs5DTrPKckmvgzspZGU9X7W9yVv43vw8+DB2G8tpmRyk2Tm9Fb8+I 5GtqVc4HVs6knX2NPttmf5rK7C2v8HbQi0lhCUyDHS/xf7ychhpj1yaEC02LRTtL0zQO RpcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=t774i0zi; 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=pass (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 z25-20020ae9c119000000b00775cab41eaasi6226673qki.462.2023.10.30.14.18.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:18:25 -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=pass header.i=@linaro.org header.s=google header.b=t774i0zi; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZdy-00011c-BF; Mon, 30 Oct 2023 17:17:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdj-0000z1-MI for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:43 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZde-0006Ts-Gv for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:37 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1cc131e52f1so30847195ad.0 for ; Mon, 30 Oct 2023 14:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700652; x=1699305452; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PZXxxvjyYdMGysXW9TK679xn7phxp04idRu5d5Pr4As=; b=t774i0zitop84ktHMNkDhhXMkK379t75QGfCTM0+RG5i96oQQDXRf5XD1oAB/Kz0/P WYWUOs3kht3AmT2Z9Q/B30gxm8Tgg49p3+fIcNoB0h39a5Y8LcSup8eHOOM7VBhEoGWe i5ynjEHps/VhyhBRhz6CjatuYl/s+CKFX8GsWrf8il6gS7AvAbJRgXwxt4AsWFcjdY2O gc2DwhaYfDkvVo+Lz1GE3cJh76kqWXAymGlltEvvLqd336AbhkESKnasPYswmYvqrxav z0X/9VtGzg4sX9VQOWtYSOXJzK8AUPaKJutvkASIvU+z1gLh97IiEK1o+seEUAc0VSu9 Om7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700652; x=1699305452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PZXxxvjyYdMGysXW9TK679xn7phxp04idRu5d5Pr4As=; b=mEsRgc1zy1mMB6wfRnTbE4lFgZvjH9DV1cuKyOC2TK1ZagtnaJ0fGkZY/mRlzsRSO+ QGqslzrMp4TQels1pcyVSyHy10z+eU/ltykwAL01h/NvM46RSmwVFobf56HfYbAx0DQ2 GnUWnW7JqbMuWQ7YtOx8gNcEzIdHyhizfckNA+Lcw+ITi0nogR0qRIbaMGepbMjKZd9e q+PU5wJaARzCMrDyT5Dlpn6gMvxouq9qq/E6F/U0RpZnj0y1hm8xBWQnbAfEndtE2oT4 Thbp61ueCr4SBWGy7T5TnrSq4BvydBAxlQFIjaunCpKlRKDGmg1k3DVrMeEtCM5zYzBN scEg== X-Gm-Message-State: AOJu0Yz0oT99Q4ODejFHYTPcYofsgV/2pHeZ97QueioLTTRmxcsvlR8K dcmfpiyOeijdKkWEfy6ag0etYHmT/TJHQElt6es= X-Received: by 2002:a17:902:ea0a:b0:1cc:4625:74e2 with SMTP id s10-20020a170902ea0a00b001cc462574e2mr885079plg.24.1698700651962; Mon, 30 Oct 2023 14:17:31 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= Subject: [PULL 04/21] linux-user: Do not clobber bprm_buf swapping ehdr Date: Mon, 30 Oct 2023 14:17:10 -0700 Message-Id: <20231030211727.165090-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 2e3809f03c..d5af354a78 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3199,16 +3199,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; @@ -3523,6 +3524,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; @@ -3544,7 +3546,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) @@ -3737,8 +3739,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; @@ -3748,12 +3756,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) #endif 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 */ @@ -3840,7 +3843,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 Mon Oct 30 21:17:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739286 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337395wrt; Mon, 30 Oct 2023 14:21:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYfuXbE01TNQ3209M8kBc0RVcXb7m6o3A+nad1CKUMybRi8zI2BoUaq0xWZaw6ghx3z7H6 X-Received: by 2002:a05:690c:e:b0:5a1:d352:9fe1 with SMTP id bc14-20020a05690c000e00b005a1d3529fe1mr12909224ywb.42.1698700871090; Mon, 30 Oct 2023 14:21:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700871; cv=none; d=google.com; s=arc-20160816; b=lvZ6ns5pgN6mFTxv9WgFrbjFo9k0xONoHjleItOal9vtx2gBVdfMZMPE/QDBJtZWgc +/UXeX8xUCLi/HooxoaiP/QGcRSAHO2xCCIUkircCtrPAc9hN4XI2nMooV1nOwrLCQ9V qQzxMTsHD4OpbIBOx+Id5emueaVF7pBVKYi4HR5iXAQi+assPXIjviBfhjeGzADRwPSe jLuYfeKfcLJkMv+6ttutzNJYb5/BMJWDDvpHk1OQcGy85cfABypv0FJaES3YcFD8Xnwa HX7xL8qEiiuNtcnr/iQWBiiXMAebIK/P+0k8IfWxPe+tZRZZTxt4ViD7XmjTbA0se1KH 0AQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=yNJnXwqPU+XiPb+hM836A6Y7DrvNcYPhsN4z7hvAs88=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=HebRtZsgKQHgZmdta3FUW3jXNfIRkT9GU84NCG2IXWcgPrbNwO9hc0jvf+A0OyA4PO DJpk1eAObscbJAvY1bGqD6PmFeAe7vjp39ZhXqL7noxFwfMtI5iVREVC10DlS2m1DW4o NVQy0JEg4L417uCUO1O9EsEiVi5m1NgDPa1W8OVngL0LLTVQDbB10ghtT2JpzrgdGgNb ajtrZwdjFYRQNyZQEcGaqcaLERH6QxkQG1uQwY6d3nlAMH7IPLI5NUWH1GrfLozLjd3/ vLztoai3y6zcD0juQZyg/q/FYPODuRgWwAQBJxZMn9l8IgQCkHsCrx+1h+n+VfTzvgnv MwRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wpQnFadT; 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=pass (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 u18-20020a0cea52000000b0065d1380dd16si6461947qvp.336.2023.10.30.14.21.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:21:11 -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=pass header.i=@linaro.org header.s=google header.b=wpQnFadT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZe0-00011r-9u; Mon, 30 Oct 2023 17:17:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdj-0000z4-N8 for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:43 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZde-0006Tx-Ux for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:39 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1cc2575dfc7so22791335ad.1 for ; Mon, 30 Oct 2023 14:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700653; x=1699305453; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yNJnXwqPU+XiPb+hM836A6Y7DrvNcYPhsN4z7hvAs88=; b=wpQnFadTdqXNtE//T6uN1JUe3hLVvL4bqrrpRKNlK0dwRDXAc3XxqgJZM9PrvKuF9/ TnONyJ09WyjaDLNShy+UNikRH9joeyzpFIEJN0hNlDpyfQDcpToIam7UOSIlKVL/njJP zlmo68Jx/cZwu3xkAM/MgtRMyl5T/AltH7RrVZdbotTA/deGoU5vhOsU078WbdvYBYZT /107o2gcXP4/Cz3QXVpl+9Lx1C2XPDzP0cswTewJo9q24GP6MaP8Q9SdNTOXv6vjf6fu s/72TzZiZAtPQX0R/94ko6OQOQm8sxZK1fbTsr9isIVKXUNa51ZOKPJApEFz8tGPrWef J8Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700653; x=1699305453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yNJnXwqPU+XiPb+hM836A6Y7DrvNcYPhsN4z7hvAs88=; b=SQNR9+C9fMNI5+ugeoBZi+0bYREoFxBn6K6vZyHz5GywRhqnXOpKluUOv5jIswa7bH ZLZOMB+X+SnKcbZ9BwdaiqIuNvvkLzw3//HyHlOP0a5TjesjrXEJagkexReQc4vBduQ0 mgsaAoZ3APhtmveMjyA/HqNOb+y8DSk4p1Aq2ooKksume1vCqSzXF7uFtLN9rOYN8fGL uSlpH0AEjegyZCngezN+QTVN0mI0Wz9YPNAqmkW9NmWlros0TNGOchfZbDYjCxYxJCR1 XHEETRugofmxMumTepS5GNUzR6bKndjK/xb4sdP+7BTdNHphznW6kxRCN/ousSxUDLZI IIsw== X-Gm-Message-State: AOJu0YylRf4Xxv3DmmaBBbKhbICxPV0fJSrlF4ZymcmOmWvA2m2ENmce OY2a1oU22ulS46UsFHO/7uixTTbBUdbL2Od2mYA= X-Received: by 2002:a17:902:f54f:b0:1cc:dda:9a1b with SMTP id h15-20020a170902f54f00b001cc0dda9a1bmr10600197plf.34.1698700652862; Mon, 30 Oct 2023 14:17:32 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 05/21] linux-user: Use ImageSource in load_elf_image Date: Mon, 30 Oct 2023 14:17:11 -0700 Message-Id: <20231030211727.165090-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Change parse_elf_properties as well, as the bprm_buf argument ties the two functions closely. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 128 +++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 79 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d5af354a78..d763cb855a 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3102,10 +3102,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 { @@ -3133,14 +3132,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; } /* @@ -3186,30 +3179,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; @@ -3220,15 +3217,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); @@ -3265,17 +3258,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"); @@ -3283,7 +3269,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; } } else if (eppnt->p_type == PT_GNU_STACK) { @@ -3436,9 +3422,9 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + error = imgsrc_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, elf_prot, MAP_PRIVATE | MAP_FIXED, - image_fd, eppnt->p_offset - vaddr_po); + src, eppnt->p_offset - vaddr_po); if (error == -1) { goto exit_mmap; } @@ -3470,20 +3456,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 @@ -3496,23 +3473,16 @@ 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); } - debuginfo_report_elf(image_name, image_fd, load_bias); + debuginfo_report_elf(image_name, 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; @@ -3525,6 +3495,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; @@ -3542,11 +3513,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) @@ -3755,8 +3726,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) interp_info.fp_abi = MIPS_ABI_FP_UNKNOWN; #endif - 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 Mon Oct 30 21:17:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739291 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337835wrt; Mon, 30 Oct 2023 14:22:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnCg7P1ysW47El+/Xv7NwSjLH6nnnCAHxabgY+Gg3uCM9pN3eeIArPGw4fmyJ1+fZm2az8 X-Received: by 2002:a05:620a:458a:b0:775:9f94:16f1 with SMTP id bp10-20020a05620a458a00b007759f9416f1mr1451195qkb.22.1698700948571; Mon, 30 Oct 2023 14:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700948; cv=none; d=google.com; s=arc-20160816; b=uSULmxK1eI2F16JuUp2CS3eraaJcjCRQyvz45jEZUmrJcYv58co444gy5zXS94/a+M zrx//3FpedrfRG/zAEUF7T/bLe8ihsoihNH3w4UhZ72G1l2Nj5/jR2pF1xImnbYobA4a TwLMFOaJY59I2Ya2B7rdjy+Zz8pR2nHHPqFb+gMk/kt6eSLPG+o3hJKUmmD6Kfven+pv zwF+ZM42DsuJjHk7nayzc78rUZVR67BZbih4R9Rxf+G3bDQ0KizpLG/Wd07YEa+arWiV vGo3v/bL+jmHLYwvKbPuAqxEPeWpkDFkT3z+0bE58XdY33/Z/U873xM3r4pnGk49Vmsc MfVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=7kHG9dpDbo2QunqRCqU6AhR+zRVLjJJWJlLUD5rS4Pk=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=Xy/TbbvnxP0Bj7ozmXb02Nuu0VTJRipv17hWNDwGyUvf1hLiM+o8uYh2UquvZV8NXE 4KDOWgwHk96BQiF0x03+17zNI0fBjq7gGObJbpajD09t6OEHGfBwA7MmLqVoYVHuf9DF LO9X4nXW9rKYzI+matjTzQ6eoYtwwRO2UOB3n4SPvmvbWa6kEOWWfQUbFZKOJlFfbLsZ 76kKuXtwWtJqA/1D7LH5eCWIUbWgrmYqESdwsk5N10XnT7YlZ2+R/edBSyP1tMlrt/Ii 0A706GEpLlGU6avpjwnnG0jLBKxeLY/i01TJrg5pM2RTUqZDEFcVt8CtG1KQYpD+FNOS OX0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zeRhZnKV; 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=pass (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 s10-20020a05620a29ca00b007758f5499b0si6617388qkp.426.2023.10.30.14.22.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:22:28 -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=pass header.i=@linaro.org header.s=google header.b=zeRhZnKV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZeL-0001My-1W; Mon, 30 Oct 2023 17:18:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdj-0000z3-Mf for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:43 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdf-0006U8-Hu for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:39 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1cc3388621cso15939795ad.1 for ; Mon, 30 Oct 2023 14:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700654; x=1699305454; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7kHG9dpDbo2QunqRCqU6AhR+zRVLjJJWJlLUD5rS4Pk=; b=zeRhZnKV4nCNE2MbksCCyh/aRl7RSeCZEKzZK0ON0O3ILEqiIhIDF/mRIDfmIBpJHk NdNP1h85RFA67IcYxGQOEYO7Oe2CfhnFstnnPJKCTlq8Oz3vvhijN06Ou9G2Hbv5Va6c MM04RM0M/3vbJaNV+y4BlqURsAUQAd2nHzAeNHXD1FfFJ9r9ZZE9lK3q/jPYKnbN9ywB eMEpQ54V1tRY4UVI/JLC7MIrWCrTi+W4LUgNL5E66K6jkiWKLWT8khyldwAOiY87l04n xcBRdc3lV4R8NRnO0GxSu4N30BQu8t+N37TRCvoF/vJHPsYRvXL3l/7BvYJWKlrvg/j4 jXyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700654; x=1699305454; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7kHG9dpDbo2QunqRCqU6AhR+zRVLjJJWJlLUD5rS4Pk=; b=tFzyAa0VBzmSWIPhJFSiERHxh2/9HDBc4K+TqBc2DGKP53WEZHIYGGdqOXF/ElMGYk RXARROlBDByzICX3uIak7iQ1uSy/ssB4N4cJLiY0D0LFqLmZ1p4oFioonLNM/2KLkQLg hFmjJ3jorxbrly6kqREGX3n3DBOlqkjv6vldNTk7lNhrOXdpfUcHEoY5olJCIPR8+3qS RtzYXyy4mV0BcIPuGkCSRVLT7IxW8k7LhbEbFqLBzPu83ctAcpyOUfml3+y+Sq9aWbxU Z3MIFtQ68VQAT5f2fUggu9RounNbKJQ2M8rAX6+XRqeiYG0elamrVHOyQfL9SN2PNUt7 fqEw== X-Gm-Message-State: AOJu0Yx0M/Jwx23eFuyVlPmLyAM58eehx0b9rNJcDWchh90hdrOi4si/ /npV50U4D20/QgxFzBTK6F8E9iOggX+arUd5axY= X-Received: by 2002:a17:902:e74a:b0:1bc:1e17:6d70 with SMTP id p10-20020a170902e74a00b001bc1e176d70mr931741plf.24.1698700654172; Mon, 30 Oct 2023 14:17:34 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 06/21] linux-user: Use ImageSource in load_symbols Date: Mon, 30 Oct 2023 14:17:12 -0700 Message-Id: <20231030211727.165090-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Aside from the section headers, we're unlikely to hit the ImageSource cache on guest executables. But the interface for imgsrc_read_* is better. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 87 ++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index d763cb855a..88c2b01402 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2201,7 +2201,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. */ @@ -3473,7 +3474,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); } debuginfo_report_elf(image_name, src->fd, load_bias); @@ -3564,19 +3565,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; } @@ -3594,31 +3596,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. */ @@ -3643,10 +3647,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; @@ -3655,20 +3661,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 Mon Oct 30 21:17:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739287 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337536wrt; Mon, 30 Oct 2023 14:21:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpQRlWRrkv85aGb0mfN61XcIyncRpksvHmhXuXz5b8ERKMjyOShOLj0Uw52b5Ip6xW+/0a X-Received: by 2002:a05:622a:208:b0:417:d600:115d with SMTP id b8-20020a05622a020800b00417d600115dmr12584308qtx.66.1698700900859; Mon, 30 Oct 2023 14:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700900; cv=none; d=google.com; s=arc-20160816; b=UOogBryOE8Bir0SAYd65LWVJklmdvGd6J0Gbi3x4wmxJrq8fbTU7aTfK0xaUGpgDkY TE0rauT00XPgDYGRUYkpj1TDUwfXvNS1wUu9sVG1Lp8a4nI4q+RzAQYR1tE1R6XSHH4f DFP+cfjcCK460i44icVxCHed3cbJvGEV5CMsYAztdSOZjrn5XmaK4rqCSzSqMdWR4KlI gackskijTns2EC4oEXjqfwPuAeUGPq1fSUaxzHdtmRfzsxY49oH5wljMRj7vP5jOboT0 IFb4c3p+wknKosciHPjSp4bFcroaEpBWKvQi5YSsOWjG15IxV4KcJzERDRH3rTylP01E wVAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=srg8id7JB5fyMoPg/HaJjfZgMuzaSTlQ1OJOVHenLyc=; fh=7Rmoz3vyDpcEhnJW+jMvKhvM9P5kAiKNo2WiNXDg220=; b=F7iUrtyze1jmkQ0cS/X5IMuBFCmIr1XhOZe0Pdgj54SgG3K5UhHC0zn8w067fMnqjc 9RHIBvsuCQ6VNFUyoDuo698SuFZUOLZNceq7hBnSgrDKko1uW8UWbA6IWXg+WQXgs3Yo fvMANOZodZkhZ9I4FfOFavsg03WkflWNJHQX+Hd5Syc/kQegwixkmrcWGdpSEBPcT7v+ AXdvsHIvzeNSKTfgfzDwhFqYfRI0BxJbWC5UG4CkG7N1On3+TFA6czf6IRDQFBDRd3AS oGyxNN6SLnPAnT/P0UWZjxtEoIqvGuuohTqfz3ereuLEYt1ONlgbmShaYgL/0NSUqLJn QIyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pStFU0Kv; 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=pass (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 c22-20020a05622a025600b00412083895d8si6248989qtx.461.2023.10.30.14.21.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:21:40 -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=pass header.i=@linaro.org header.s=google header.b=pStFU0Kv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZe3-00014G-06; Mon, 30 Oct 2023 17:17:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdp-000101-Od for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:51 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdh-0006UM-T3 for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:40 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c9b95943beso44873145ad.1 for ; Mon, 30 Oct 2023 14:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700655; x=1699305455; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=srg8id7JB5fyMoPg/HaJjfZgMuzaSTlQ1OJOVHenLyc=; b=pStFU0Kv9HPPt97XOGB43gLyVjlEuT7fxIb6g3eOwM11EQQsbBOL0SBLtwoom3oxtu 4s3fAEKQJb+RBKNWknzJJJBK661nkCrcFYVOMxUnCf+4pggXJqEV1oqdJCeNepKDpR4R AyJDiswnG83KVSqvgecUm52mQTTSeGZ8Re4UC2ImewXGIWMzIvudoAItsqItblVKsXnr Pl8y0SbZseSJ/Xg2d5Rt0qd6h/u+aKxI9/FAsLHMs6jdieZ5cyTsIlTE3EiQU++0xTd6 iiA7z9t78QEMFagDGwlVbKz0qTLe+1jJTbIUcaVs4KyWc8tDSUg21Vk3Vct39Je5Hfr3 lszg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700655; x=1699305455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=srg8id7JB5fyMoPg/HaJjfZgMuzaSTlQ1OJOVHenLyc=; b=PGxVIg/iOMfS812iWTrt0rxxpKbXSqk2optgeYtORL4gJPpFfEGboyQlFXfCb2ZgCz lLMQGSa6OpOTuEvK85hFH/JVpqZYQ4+jXNAqCpF0PBXDdV5J+ZgMOuJCf5HtKtT/tJ4e Sigts9Jtm7cITLW44KESPDlQNhAMJ7U8/+cdX4htkRGJt/Wt+87qA5l6O/rpSDMWJoiZ cExL6BuTI6sYD2byj/BrV39mu/8yDAy6jTxVYWP80NI+TJwv98+mEnKLLyayAZd2lcB1 xzvd+6mTiKwm6RAqdVFRJArZqrrdxX8lizoE/LfvtgtluJBfdwMPKVn7vVB875U85jqL n93w== X-Gm-Message-State: AOJu0YysKfITHvn3HoBf5RM7/CdfxwzCFCVAZQ3k5cKLkC2lUbSYIOon ov+IiI0EO8QSujZb6yuExvpziIFzjw/16NQ7vU4= X-Received: by 2002:a17:903:41cd:b0:1cc:4e81:36a4 with SMTP id u13-20020a17090341cd00b001cc4e8136a4mr4348851ple.5.1698700655196; Mon, 30 Oct 2023 14:17:35 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 07/21] linux-user: Replace bprm->fd with bprm->src.fd Date: Mon, 30 Oct 2023 14:17:13 -0700 Message-Id: <20231030211727.165090-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org There are only a couple of uses of bprm->fd remaining. Migrate to the other field. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/loader.h | 1 - linux-user/flatload.c | 8 ++++---- linux-user/linuxload.c | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/linux-user/loader.h b/linux-user/loader.h index da6591fff0..a0834290e7 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -74,7 +74,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 fdcc4610fa..5b62aa0a2b 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -463,7 +463,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; @@ -490,7 +490,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); } @@ -540,10 +540,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 5b7e9ab983..4a794f8cea 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -39,7 +39,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; } @@ -69,7 +69,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); @@ -144,7 +144,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 Mon Oct 30 21:17:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739278 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1336814wrt; Mon, 30 Oct 2023 14:19:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0TJk7HJ5TqvfHK/ikmNlpQ0DBub3QUv01FvVA5WfhSy4EipbdAkGRDRTntCy21HE0DVxY X-Received: by 2002:a05:6214:1c4b:b0:66d:61c3:8ca4 with SMTP id if11-20020a0562141c4b00b0066d61c38ca4mr11947169qvb.15.1698700763518; Mon, 30 Oct 2023 14:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700763; cv=none; d=google.com; s=arc-20160816; b=Pd+lBz24PDKjXXglfv9CNVPSHsNnyeTo71QI3TxSm8MRj3BMMfkTfxyUYc7zRk8NPS FGw9kEyzRx6ym60AzIl3VXR56yxf76ey+d7QKU79s/vvqTIJmMGiMmn5Nz0hKxb+AmS3 q6PKRN3Z2cB6QSH02UWpwbUjI20fXrCoOEjg54N1I6RdH4hxcAe7oKSCxt1L+mtfX8Dc kEyLnv7DU3uJwSteodEdz+OB6+s2c0iRZb64ySfttqeRabfCmqi1tYi9HsgJ77YQyoWo 2UfZNPbkxBResV9zBmoH+WVP8RCNMbV4kJSRX42Yqym5KOTspmdWZSmXpdZ4TI1NOJGl XfHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=EZdZAtqEe85hgekxO5brk1Ss9vuV7TkNPc+GgulDDCM=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=omVeryNNT+QbYclDa8Mek4zLMXpo+iOWf9AjIDYrIXAlDL1U6ZkNmRKKqm8WpPV8UB 6YokYW7RLvdDl7MVwIML7EdTrHsDMWdm6vCqUdeKi4Mk1aqNXuNqIuPaVqBlM0D2rHKQ wCJlZx/n3ajhYNmfVbGImgPC7pbWHp+bG2uPZRbSV0S+f79Jw/H21XWshBVuoWYlT5LN /xYu5urx1rTIGf9U73Y43ennSjDDPXc+f4u6xv3PHbdQeFJpPvCsloaYj/BwbQmiCvu/ e8AOc7pzHt3VhhnYUOgfIIqFKbLdnorizBjv4tTbnlwN6/ksmjZ3RiXgJuMuYNXumNXy 9oWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="vG/3griO"; 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=pass (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 z18-20020a0cfed2000000b0065d067f07d6si6302828qvs.318.2023.10.30.14.19.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:19:23 -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=pass header.i=@linaro.org header.s=google header.b="vG/3griO"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZeW-0001jv-Hm; Mon, 30 Oct 2023 17:18:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdp-0000zz-OH for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:49 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdh-0006UT-TA for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:41 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1cc5fa0e4d5so6034925ad.0 for ; Mon, 30 Oct 2023 14:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700656; x=1699305456; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EZdZAtqEe85hgekxO5brk1Ss9vuV7TkNPc+GgulDDCM=; b=vG/3griO58Epk+7em350kGyIpqqtA4iVTXoo5EErmD4GlUYvqWE8jpd/CBf91sW6CD cq8hj5ltRTkmMX45WdGV2azXjL8VI93ObIaJdwAUB6ID3Hp8Euh0fxxAgZkpP2ztfixU tSEaipGKTX74r/K1mvVSqEeD4gjlIT6i8/CbqHNHNdZ7wDT8dGIJk+VnaGqfQMZI8rjL HXndpDmQ1wATgqGZ447Fi91A/p0ZKZYnqXLf1zXmXWhMrTZ6AC4sZpwQJAYtgmLF5/ds yKs2KBDGJIPTfrK1OMuI94XwDMBEOmdefwT1JhA1YwASqy2PNgBQq9dz6WIDv7E9ck15 toew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700656; x=1699305456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EZdZAtqEe85hgekxO5brk1Ss9vuV7TkNPc+GgulDDCM=; b=PnvJahS6REHkv8RSgqgu7CFmUPD+iRnKuucL0mrFHF46VL2ocmNp2GxlrKfDia0qfv hOwtzPA9GasoGBA7XqcXiGLDX4MoHH3B9kSuF/Msv1v9LRrStS/NjYR8R8i/TTMDwpk4 zf5hy51v/HTZW9dz8UHgnFmBo26Suuu4oLdOH37iCsaXRVLf5T1FR8fKiHDM/Af1Dk/R ZUwaaZgLA14SYZoXA6399FeOkiUpoZhbVSqKh2sN1jjmEgbxf2Y+ORzn8d4zDIidHV/h GfxBM9Uf4VQ8QntDYKbSgvreurgN2LD9Hn8oNZEUIwXCQ2QkKu0Esmi+Nqy17a1NyE88 UdMg== X-Gm-Message-State: AOJu0Yy0WTZdctxfHICdfuSN/8UB0gz2pxk3fsePst65ETOueYE+Uz8b 9n7r3+wRzQLQ7F1nJMC3SnErvS7Jrt52F3KIUWU= X-Received: by 2002:a17:902:efc9:b0:1ca:20a0:7b08 with SMTP id ja9-20020a170902efc900b001ca20a07b08mr10893884plb.50.1698700655933; Mon, 30 Oct 2023 14:17:35 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 08/21] linux-user: Load vdso image if available Date: Mon, 30 Oct 2023 14:17:14 -0700 Message-Id: <20231030211727.165090-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 90 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 88c2b01402..b0723071e2 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -33,6 +33,19 @@ #undef ELF_ARCH #endif +#ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE +#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 +#endif + +typedef struct { + const uint8_t *image; + const uint32_t *relocs; + unsigned image_size; + unsigned reloc_count; + unsigned sigreturn_ofs; + unsigned rt_sigreturn_ofs; +} VdsoImageInfo; + #define ELF_OSABI ELFOSABI_SYSV /* from personality.h */ @@ -2471,7 +2484,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; @@ -2559,10 +2573,15 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } size = (DLINFO_ITEMS + 1) * 2; - if (k_base_platform) + if (k_base_platform) { size += 2; - if (k_platform) + } + if (k_platform) { size += 2; + } + if (vdso_info) { + size += 2; + } #ifdef DLINFO_ARCH_ITEMS size += DLINFO_ARCH_ITEMS * 2; #endif @@ -2644,6 +2663,9 @@ 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_EHDR, vdso_info->load_addr); + } NEW_AUX_ENT (AT_NULL, 0); #undef NEW_AUX_ENT @@ -3521,6 +3543,52 @@ static void load_elf_interp(const char *filename, struct image_info *info, load_elf_image(filename, &src, info, &ehdr, NULL); } +#ifdef VDSO_HEADER +#include VDSO_HEADER +#define vdso_image_info() &vdso_image_info +#else +#define vdso_image_info() NULL +#endif + +static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso) +{ + ImageSource src; + struct elfhdr ehdr; + abi_ulong load_bias, load_addr; + + src.fd = -1; + src.cache = vdso->image; + src.cache_size = vdso->image_size; + + 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 (unsigned i = 0, n = vdso->reloc_count; 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_ofs) { + default_sigreturn = load_addr + vdso->sigreturn_ofs; + } + if (vdso->rt_sigreturn_ofs) { + default_rt_sigreturn = load_addr + vdso->rt_sigreturn_ofs; + } + + /* Remove write from VDSO segment. */ + target_mprotect(info->start_data, info->end_data - info->start_data, + PROT_READ | PROT_EXEC); +} + static int symfind(const void *s0, const void *s1) { struct elf_sym *sym = (struct elf_sym *)s1; @@ -3726,7 +3794,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; @@ -3807,10 +3875,13 @@ 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) { + const VdsoImageInfo *vdso = vdso_image_info(); + if (vdso) { + load_elf_vdso(&vdso_info, vdso); + } else if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) { abi_long tramp_page = target_mmap(0, TARGET_PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); @@ -3822,8 +3893,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, + vdso ? &vdso_info : NULL); info->start_stack = bprm->p; /* If we have an interpreter, set that as the program's entry point. From patchwork Mon Oct 30 21:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739277 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1336724wrt; Mon, 30 Oct 2023 14:19:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7Wu3avYc+BbxV0LVKr9fbuQ9AMleDQfGzRYbmKW16JVQvHgdDQ+lHxRzrGPJVzBrRsTGT X-Received: by 2002:ac8:5a4f:0:b0:419:a2c6:820e with SMTP id o15-20020ac85a4f000000b00419a2c6820emr13869444qta.12.1698700747020; Mon, 30 Oct 2023 14:19:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700747; cv=none; d=google.com; s=arc-20160816; b=mAuSxHbeV7mqt2QdB01nnNWrM7yt9idZ98fbrutGnR6tdwkY/NKG4CBpkwYhSaR3L4 G8/TBIstao8nNhmPZn7pAOubrBTupArdBmBq7FdPPJEUMVg3KItWMsqrsByc++oDSaDK CnzHxJCX0ACDC68JtyC6w2ZWOLHDZp9+U98sYE8MWD7VdmPaF6AZoqlP0t12GjlFK8RK py6aJhoxgDTwvXt0HTB7pVMK5C2NZ522Af7OuLQx5yAdcms7VElZbWXCU5203c7VtEFk oTiY+mUfDU0LENa4l9Qo9BK5KyqJt2dCMwZLyZrx76OatMpCoj5yJRvGTAKbFocdjj3M 2eQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=QUbTkt+bHKCfFZB4ZVLzwdrSKYldCzNwa+BNdD8suqc=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=L/fwlSYFBuKjI+sOZsZjrIcXey6a5VF+T7Y2P2XWU24OZFq4UnN5MWWee8OnWVSWHe xtC5KRzhVtXwcGyo+mE6bK/q/h7L6p7Bo7FurulluWHSfOtnZmMv4a/idwEG23jden7D Appdpr7dsR8MACXtGtMKkOFzbi++upIlnL/iQel16DMMf07eiUFtqf/WKMJR36VWAhkU jSNsTFjm8UayazKk1W7GvV/p16LbOQqscCo7OvhrMSpSoC2ApYO3ZqkP8UpvhS5z4Om8 nUnjenGhOKCZ4FnlQ5gLJJO3qjn5TSoL/cz0hRKMiOB4cvsXAcNH/rRBhhm50N16Zs61 oXNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SddCGK5d; 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=pass (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 g1-20020ac87f41000000b004055a8c7903si6466968qtk.211.2023.10.30.14.19.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:19: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=pass header.i=@linaro.org header.s=google header.b=SddCGK5d; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZeT-0001Xo-Os; Mon, 30 Oct 2023 17:18:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdp-000102-Oi for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:51 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdj-0006Uf-Ea for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:42 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5ab94fc098cso3157490a12.1 for ; Mon, 30 Oct 2023 14:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700657; x=1699305457; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QUbTkt+bHKCfFZB4ZVLzwdrSKYldCzNwa+BNdD8suqc=; b=SddCGK5docu2PHXJXMuFcKlafnQxywt3i0VKE7uYHHQ5QHpVqExSlBInFmhUk7SiDL rfN/C2ezeTdHL5csntPGbAWN0E3DeQBNCQrPxO4Dh9b5UD9g20x1Z3LK8f/HXCaZobRN oA8kQkkL6LURHwrhWPGwMMg8N7gPkA1k+Bkq4ksKwYzbqMdVtTv9F2gWZeyb5RzHdDxf WXAbTi8ST6SjdLZB0vF6PNRPJUyPK1c2FpEYx6veV+7aBtdl0VacyrtjqcAQY28UqJ8U s7Om+znRrUYHACJ7FC+V429r8OOOPT+JEBy2mqV3bT2WGDsNowq6HBGtj/A6gHGsDEwE BTdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700657; x=1699305457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QUbTkt+bHKCfFZB4ZVLzwdrSKYldCzNwa+BNdD8suqc=; b=KLj1soD8B6TED7HG3hw7z8Bqc9/Kx4BayuQKDXbyZA5uh+LPrvvWJYn4AcD+48DJSB cvcyy64zOs4sF9LkWyXvsffr5z9GjfPiE08J7R92IprxRTj6W4ztu42B3mpneziXTqil A9zYKMRz5R4jPR+wA9uggUmgdAK4I7m98tjrXdQoPVM4WbqQhy2oDGfnzIeU0GUZIc0J oBALEiozKWfInzp/3g3HStA6isbYoqIikYjTvqcsZ6rE8jBJPG8qvlsYohwTBaSILCSz 9Z15ivzsECTUPTX0Iypb5zRRPKMexnFPAj1dhk78Bte4L62dcujKWpF9JU9BgjX6HUqo LhLQ== X-Gm-Message-State: AOJu0YwoIxi0FBilVSnXYPZOlgRanNBWc+KhPux2sfvKXjmu2LlhSoWv H+bafhDa3yeSfXxLOA98DrgEmdcRYRuXJEoxEgI= X-Received: by 2002:a17:903:68d:b0:1c9:e0f9:a676 with SMTP id ki13-20020a170903068d00b001c9e0f9a676mr7164836plb.6.1698700656783; Mon, 30 Oct 2023 14:17:36 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 09/21] linux-user: Add gen-vdso tool Date: Mon, 30 Oct 2023 14:17:15 -0700 Message-Id: <20231030211727.165090-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This tool will be used for post-processing the linked vdso image, turning it into something that is easy to include into elfload.c. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/gen-vdso.c | 223 ++++++++++++++++++++++++ linux-user/gen-vdso-elfn.c.inc | 307 +++++++++++++++++++++++++++++++++ linux-user/meson.build | 6 +- 3 files changed, 535 insertions(+), 1 deletion(-) create mode 100644 linux-user/gen-vdso.c create mode 100644 linux-user/gen-vdso-elfn.c.inc diff --git a/linux-user/gen-vdso.c b/linux-user/gen-vdso.c new file mode 100644 index 0000000000..31e333be80 --- /dev/null +++ b/linux-user/gen-vdso.c @@ -0,0 +1,223 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#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%08tx,\n", loc - buf); +} + +static const char *sigreturn_sym; +static const char *rt_sigreturn_sym; + +static unsigned sigreturn_addr; +static unsigned rt_sigreturn_addr; + +#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 argc, char **argv) +{ + FILE *inf, *outf; + long total_len; + const char *prefix = "vdso"; + const char *inf_name; + const char *outf_name = NULL; + unsigned char *buf; + bool need_bswap; + + while (1) { + int opt = getopt(argc, argv, "o:p:r:s:"); + if (opt < 0) { + break; + } + switch (opt) { + case 'o': + outf_name = optarg; + break; + case 'p': + prefix = optarg; + break; + case 'r': + rt_sigreturn_sym = optarg; + break; + case 's': + sigreturn_sym = optarg; + break; + default: + usage: + fprintf(stderr, "usage: [-p prefix] [-r rt-sigreturn-name] " + "[-s sigreturn-name] -o output-file input-file\n"); + return EXIT_FAILURE; + } + } + + if (optind >= argc || outf_name == NULL) { + goto usage; + } + inf_name = argv[optind]; + + /* + * 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. + */ + + fprintf(outf, + "/* Automatically generated from linux-user/gen-vdso.c. */\n" + "\n" + "static const uint8_t %s_image[] = {", + prefix); + for (long i = 0; i < total_len; ++i) { + if (i % 12 == 0) { + fputs("\n ", outf); + } + fprintf(outf, " 0x%02x,", buf[i]); + } + fprintf(outf, "\n};\n\n"); + + /* + * 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; + } + + /* + * 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. + * + * Output relocation addresses as we go. + */ + + fprintf(outf, "static const unsigned %s_relocs[] = {\n", prefix); + + switch (buf[EI_CLASS]) { + case ELFCLASS32: + elf32_process(outf, buf, need_bswap); + break; + case ELFCLASS64: + elf64_process(outf, buf, need_bswap); + break; + default: + fprintf(stderr, "%s: invalid elf EI_CLASS (%u)\n", + inf_name, buf[EI_CLASS]); + return EXIT_FAILURE; + } + + fprintf(outf, "};\n\n"); /* end vdso_relocs. */ + + fprintf(outf, "static const VdsoImageInfo %s_image_info = {\n", prefix); + fprintf(outf, " .image = %s_image,\n", prefix); + fprintf(outf, " .relocs = %s_relocs,\n", prefix); + fprintf(outf, " .image_size = sizeof(%s_image),\n", prefix); + fprintf(outf, " .reloc_count = ARRAY_SIZE(%s_relocs),\n", prefix); + fprintf(outf, " .sigreturn_ofs = 0x%x,\n", sigreturn_addr); + fprintf(outf, " .rt_sigreturn_ofs = 0x%x,\n", rt_sigreturn_addr); + fprintf(outf, "};\n"); + + /* + * 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..7034c36d5e --- /dev/null +++ b/linux-user/gen-vdso-elfn.c.inc @@ -0,0 +1,307 @@ +/* + * Post-process a vdso elf image for inclusion into qemu. + * Elf size specialization. + * + * Copyright 2023 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(search_symtab)(ElfN(Shdr) *shdr, unsigned sym_idx, + void *buf, bool need_bswap) +{ + unsigned str_idx = shdr[sym_idx].sh_link; + ElfN(Sym) *sym = buf + shdr[sym_idx].sh_offset; + unsigned sym_n = shdr[sym_idx].sh_size / sizeof(*sym); + const char *str = buf + shdr[str_idx].sh_offset; + + for (unsigned i = 0; i < sym_n; ++i) { + const char *name; + + if (need_bswap) { + elfN(bswap_sym)(sym + i); + } + name = str + sym[i].st_name; + + if (sigreturn_sym && strcmp(sigreturn_sym, name) == 0) { + sigreturn_addr = sym[i].st_value; + } + if (rt_sigreturn_sym && strcmp(rt_sigreturn_sym, name) == 0) { + rt_sigreturn_addr = sym[i].st_value; + } + } +} + +static void elfN(process)(FILE *outf, void *buf, 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 symtab_idx = 0; + unsigned dynsym_idx = 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); + } + } + for (unsigned i = 0; i < shnum; ++i) { + switch (shdr[i].sh_type) { + case SHT_SYMTAB: + symtab_idx = i; + break; + case SHT_DYNSYM: + dynsym_idx = i; + break; + } + } + + /* + * 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) { + continue; + } + if (first_segsz != 0) { + fprintf(stderr, "Multiple LOAD segments\n"); + errors++; + } + if (phdr[i].p_offset != 0) { + fprintf(stderr, "LOAD segment does not cover EHDR\n"); + errors++; + } + if (phdr[i].p_vaddr != 0) { + fprintf(stderr, "LOAD segment not loaded at address 0\n"); + errors++; + } + first_segsz = phdr[i].p_filesz; + if (first_segsz < ehdr->e_phoff + phnum * sizeof(*phdr)) { + fprintf(stderr, "LOAD segment does not cover PHDRs\n"); + errors++; + } + if ((phdr[i].p_flags & (PF_R | PF_W)) != (PF_R | PF_W)) { + fprintf(stderr, "LOAD segment is not read-write\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, "LOAD segment does not cover %s\n", which); + errors++; + } + } + if (errors) { + exit(EXIT_FAILURE); + } + + /* 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_HASH: + case DT_SYMTAB: + 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_SYMBOLIC: + 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_RELA: + case DT_RELASZ: + /* + * These entries indicate that the VDSO was built incorrectly. + * It should not have any real relocations. + * ??? The RISC-V toolchain will emit these even when there + * are no relocations. Validate zeros. + */ + if (dyn->d_un.d_val != 0) { + fprintf(stderr, "VDSO has dynamic relocations\n"); + errors++; + } + break; + case DT_RELENT: + case DT_RELAENT: + case DT_TEXTREL: + /* These entries store an integer in the entry. */ + /* Should not be required; see above. */ + 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); + } + } + + /* Relocate the dynamic symbol table. */ + if (dynsym_idx) { + ElfN(Sym) *sym = buf + shdr[dynsym_idx].sh_offset; + unsigned sym_n = shdr[dynsym_idx].sh_size / sizeof(*sym); + + for (unsigned i = 0; i < sym_n; ++i) { + output_reloc(outf, buf, &sym[i].st_value); + } + } + + /* Search both dynsym and symtab for the signal return symbols. */ + if (dynsym_idx) { + elfN(search_symtab)(shdr, dynsym_idx, buf, need_bswap); + } + if (symtab_idx) { + elfN(search_symtab)(shdr, symtab_idx, buf, need_bswap); + } +} diff --git a/linux-user/meson.build b/linux-user/meson.build index 7171dc60be..e4cb70ed2d 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -28,9 +28,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: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@']) + subdir('alpha') subdir('arm') subdir('hppa') From patchwork Mon Oct 30 21:17:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739285 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337135wrt; Mon, 30 Oct 2023 14:20:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHO7cs7vozelzvDx78ZgnTAztTsG0I8ug7amtTk+nJVr8F8m7/c0MgSyuHW4Dg9WuKvqsPg X-Received: by 2002:ac8:7f83:0:b0:41c:da69:e917 with SMTP id z3-20020ac87f83000000b0041cda69e917mr15842828qtj.53.1698700819110; Mon, 30 Oct 2023 14:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700819; cv=none; d=google.com; s=arc-20160816; b=yvc2lp9yisAayJGKQ7pUKwshVesWv4WdQO85wLcVJavhN9Jt6LWSZucQy5K43GTSxq xBQkJGhQaxVZCeqNIPiVzCpoYFgQMRqdffGTLi5D0oTh4QhrEqt8hbctUar5E/oRv39c oIkiTeJ/Cl5bKhDzFpJeH7sLhG0oST/90m2NtqSM0Qor2A8QBYL7YMVHxacfqtDk16qd Qe7YbJkwv0j4kZTZzP9jY2Ejr9/ih/TZ6bb8pMEpWVttmwGcSEajkzZ/khlmJ8OMy8Hb OE7SIKXD320vpDA7hui+lNMl09oe5u5jI0vsk5hSd03Iu+KerXN7DyBKn6BC1ABohpIJ RSXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=JfYuDIRqxMfLfLgP1NKQpppnMNn5znqvhpuixH3Tu3U=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=NM+Nw/0rPt9dwTrkAMm5N+Vp1T43gatNk0OP9xX18W6hRHY78L6fvjegIBohUfmHym 8wAyX6yUUllePwpp/NSbV1WoMItbFUxtNELDuxUa1PLFsElZHU55OeiVYclSDMuuNQm0 tMEoImSP5eaatMiLbkDVxTfIgFcWC76NMY/hdxilEVSmmp18jbIbvBODJPi3Y9o9jSod rJp28RbEJNMYQD/8UQtvxGEGd5G0e3BPnYn0GTbL7LNmBYGL8qC0s3Xi10rYDSF/b0o4 wcOwizgZBkyIzpXp8KQl/0waaahmenfg5loWcLmThZvr6wSnx7mnXM6+r9ZYrMa7QOoL aYJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OrzLXtJh; 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=pass (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 y3-20020a05622a004300b0041986d6423fsi6251663qtw.195.2023.10.30.14.20.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:20:19 -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=pass header.i=@linaro.org header.s=google header.b=OrzLXtJh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZe3-00014l-Nw; Mon, 30 Oct 2023 17:17:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdp-000100-OJ for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:49 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdj-0006Ul-Eb for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:41 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c9c5a1b87bso35034345ad.3 for ; Mon, 30 Oct 2023 14:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700657; x=1699305457; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JfYuDIRqxMfLfLgP1NKQpppnMNn5znqvhpuixH3Tu3U=; b=OrzLXtJh0UtT0c0MBGZki8dkYc1E5vQKwy2no8oB31I4rgFct5yTTZb34m2RvwElfr nrFCVLNQ2M8xHmlf21B/bQnN2m6aUncft1PUI7akSKh8h2GCfurRd7zZ9d8A6ZJLh8qF ZlVEuHWfMbS+2VP6pCsU4UHul0YwbKHqEEseLNSV0XJ3ZEH1GJMeAkmu+9eOs9u3ecZA VEX6uzkrNu00ByqoxjHyBDvpLXNk2cncK/sb32S3MF0ta9kkuhAy+EHjMQhUuKEwB22x mmDBugyvJg4v2vPrLMqFcoWGyV8SUahSbxO3TBs6Zyf2ZxePo78heLMWyBR3tw3DaRhE kV8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700657; x=1699305457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JfYuDIRqxMfLfLgP1NKQpppnMNn5znqvhpuixH3Tu3U=; b=ajnuG7huQehmGUlb02mxYdLTyRXhZuRCMBtZdrRMLtbTWIld08irL21tCqQDjUZLzt /lSsXSU4WJ2fBh7fTZsGt/pLTF9+sfig1CZdUKRc4wfH7LVPnc8VZ0GMVXshLCbqs2GX cFTiARGCaSZOX/Yuy0IwxAziceZ3xquDfxgtulRKjwumPxPKBxBk96VkNBhxQC+3uVa9 odNYAvrFWNp4q1SYV7wHdSF3ynrSdYKD6b1Clt59DIJSOML47/eudE5u8whq/axbU1gv BLhbUfhDYwaBfBJ8fj/v3dFhLV7QB6YN92rdNn94vvJnuYXkMZMtcGxcIplfI0uSAGsO 3rfA== X-Gm-Message-State: AOJu0YxbwJ14ySRsZnac3nZ8MznPu4iixnXSWHeEaOd5yhCdhnZYsyny +92kq9ihdsMtBuvYVZw+964jrPt0I5fPnk60Lfk= X-Received: by 2002:a17:902:fb45:b0:1cc:379b:3505 with SMTP id lf5-20020a170902fb4500b001cc379b3505mr3682655plb.49.1698700657585; Mon, 30 Oct 2023 14:17:37 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 10/21] linux-user/i386: Add vdso Date: Mon, 30 Oct 2023 14:17:16 -0700 Message-Id: <20231030211727.165090-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1267 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/i386/vdso-asmoffset.h | 6 ++ linux-user/elfload.c | 19 +++- linux-user/i386/signal.c | 11 +++ linux-user/i386/Makefile.vdso | 11 +++ linux-user/i386/meson.build | 7 ++ linux-user/i386/vdso.S | 143 +++++++++++++++++++++++++++++++ linux-user/i386/vdso.ld | 76 ++++++++++++++++ linux-user/i386/vdso.so | Bin 0 -> 2672 bytes 8 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 linux-user/i386/vdso-asmoffset.h create mode 100644 linux-user/i386/Makefile.vdso create mode 100644 linux-user/i386/vdso.S create mode 100644 linux-user/i386/vdso.ld create mode 100755 linux-user/i386/vdso.so GIT binary patch literal 2672 zcmbtWU1%It6u#5lG_z^4ZB?X_C>9o5sxCF8QBlyONt?nZ)?|y73e)ZGba%;SR(597 zjTXE8QIiHtY6YPbDhO>6s(mPS(FX(Z2Q`g?1xp_^KInr_=|f8&)b;yj=5}w=eGok1 z%XiMX=brmB_ny0ldSlx(O%qZAA|PnR8-(ZpuhYGj4)L&P5F5p65f&@qVw=PV(21ar zS~fT!zaSUUNMnrKqu7p`(Ouv?E|~S#J4vR z?eBj&+ji~rg~eZ!zf~VSJr_pXM}D8DFrl0ORPzVHn5LKmbB!e|qzOC^tO77~@mIB) zzl6kpgPDI3e2U8d6uIY2bq_`x0-wZWxDMLSfe$J6M%crOeHivUY<@1rr@`l7bI!EC z1WQ>fZdBic@iW@_P1t@f_$4LZXEGSfcpH2f?e~Kj&v`Zj+$T!NBlkb|jQhnHeiL+a z&lJblO18$ z-OkRAyW9oSmOj5{et#-4CVgruv?pIJqQxKI&ZY~dQ!H3DSHUrA-dxrymL5+h95ZU? zqfdy~j)7gfjrM5g9c>HN9>C7?j(;zF-_-GQuCsOgock95 z$CvrnLFHO513c5BE36+~5f2BEAVM30`47nj^o(oe;NgZND~~oF)87oe)%5l%caD!C zZUR`#4&CABw}%(BE9KdV>yxiUf|Id`UI}64SIQGVslJnSd`)$H14yd$t+Ysc2OQ(J+srhD+k<&>BHxRjq5)uze70i3T0nE36-;4MD zX|P(C`eCbeVGnF6>~F$Q>&)x0)jBo>TdiYfVXJlMbJ%KKV=Y$enlO4^9_Z@du@yHB zwchCMGqw$O_4gWmJ%e{HQ)lfOF0TyrZnl4$<)z$G>%HU>FE1lXy;xFj>Xa70cGRgB zZe?YqcLID@7{~XU=z-4s6vh$lz%9JdjN|)G?1a8N?pfc* zIKKY`&zcmDP2m_-KOf(Hg0)2EV}IgBfWHx_^Y;P~hc5SkbEE79n459x?;V(~$T$m@ zjElobxDGGOT`N`AK*n(#-do~0bSZKjGMDr(AZ`H$D-74d^xS8@>$IiJAn|o+fMq_` OKQ-regs[R_ESP]); (*regs)[16] = tswapreg(env->segs[R_SS].selector & 0xffff); } -#endif + +/* + * i386 is the only target which supplies AT_SYSINFO for the vdso. + * All others only supply AT_SYSINFO_EHDR. + */ +#define DLINFO_ARCH_ITEMS (vdso_info != NULL) +#define ARCH_DLINFO \ + do { \ + if (vdso_info) { \ + NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); \ + } \ + } while (0) + +#define VDSO_HEADER "vdso.c.inc" + +#endif /* TARGET_X86_64 */ #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 -#endif +#endif /* TARGET_I386 */ #ifdef TARGET_ARM diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 60fa07d6f9..bc5d45302e 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -214,6 +214,17 @@ struct rt_sigframe { }; #define TARGET_RT_SIGFRAME_FXSAVE_OFFSET ( \ offsetof(struct rt_sigframe, fpstate) + TARGET_FPSTATE_FXSAVE_OFFSET) + +/* + * Verify that vdso-asmoffset.h constants match. + */ +#include "i386/vdso-asmoffset.h" + +QEMU_BUILD_BUG_ON(offsetof(struct sigframe, sc.eip) + != SIGFRAME_SIGCONTEXT_eip); +QEMU_BUILD_BUG_ON(offsetof(struct rt_sigframe, uc.tuc_mcontext.eip) + != RT_SIGFRAME_SIGCONTEXT_eip); + #else struct rt_sigframe { diff --git a/linux-user/i386/Makefile.vdso b/linux-user/i386/Makefile.vdso new file mode 100644 index 0000000000..95bc616f6d --- /dev/null +++ b/linux-user/i386/Makefile.vdso @@ -0,0 +1,11 @@ +include $(BUILD_DIR)/tests/tcg/i386-linux-user/config-target.mak + +SUBDIR = $(SRC_PATH)/linux-user/i386 +VPATH += $(SUBDIR) + +all: $(SUBDIR)/vdso.so + +$(SUBDIR)/vdso.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ -m32 -nostdlib -shared -Wl,-h,linux-gate.so.1 \ + -Wl,--build-id=sha1 -Wl,--hash-style=both \ + -Wl,-T,$(SUBDIR)/vdso.ld $< diff --git a/linux-user/i386/meson.build b/linux-user/i386/meson.build index ee523019a5..d42fc6cbc9 100644 --- a/linux-user/i386/meson.build +++ b/linux-user/i386/meson.build @@ -3,3 +3,10 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_inc = gen_vdso.process('vdso.so', extra_args: [ + '-s', '__kernel_sigreturn', + '-r', '__kernel_rt_sigreturn' + ]) + +linux_user_ss.add(when: 'TARGET_I386', if_true: vdso_inc) diff --git a/linux-user/i386/vdso.S b/linux-user/i386/vdso.S new file mode 100644 index 0000000000..e7a1f333a1 --- /dev/null +++ b/linux-user/i386/vdso.S @@ -0,0 +1,143 @@ +/* + * i386 linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include "vdso-asmoffset.h" + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro vdso_syscall1 name, nr +\name: + .cfi_startproc + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov $\nr, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc +endf \name +.endm + +.macro vdso_syscall2 name, nr +\name: + .cfi_startproc + mov %ebx, %edx + .cfi_register %ebx, %edx + mov 4(%esp), %ebx + mov 8(%esp), %ecx + mov $\nr, %eax + int $0x80 + mov %edx, %ebx + ret + .cfi_endproc +endf \name +.endm + +.macro vdso_syscall3 name, nr +\name: + .cfi_startproc + push %ebx + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset %ebx, 0 + mov 8(%esp), %ebx + mov 12(%esp), %ecx + mov 16(%esp), %edx + mov $\nr, %eax + int $0x80 + pop %ebx + .cfi_adjust_cfa_offset -4 + .cfi_restore %ebx + ret + .cfi_endproc +endf \name +.endm + +__kernel_vsyscall: + .cfi_startproc + int $0x80 + ret + .cfi_endproc +endf __kernel_vsyscall + +vdso_syscall2 __vdso_clock_gettime, __NR_clock_gettime +vdso_syscall2 __vdso_clock_gettime64, __NR_clock_gettime64 +vdso_syscall2 __vdso_clock_getres, __NR_clock_getres +vdso_syscall2 __vdso_gettimeofday, __NR_gettimeofday +vdso_syscall1 __vdso_time, __NR_time +vdso_syscall3 __vdso_getcpu, __NR_gettimeofday + +/* + * Signal return handlers. + */ + + .cfi_startproc simple + .cfi_signal_frame + +/* + * For convenience, put the cfa just above eip in sigcontext, and count + * offsets backward from there. Re-compute the cfa in the two contexts + * we have for signal unwinding. This is far simpler than the + * DW_CFA_expression form that the kernel uses, and is equally correct. + */ + + .cfi_def_cfa %esp, SIGFRAME_SIGCONTEXT_eip + 4 + + .cfi_offset %eip, -4 + /* err, -8 */ + /* trapno, -12 */ + .cfi_offset %eax, -16 + .cfi_offset %ecx, -20 + .cfi_offset %edx, -24 + .cfi_offset %ebx, -28 + .cfi_offset %esp, -32 + .cfi_offset %ebp, -36 + .cfi_offset %esi, -40 + .cfi_offset %edi, -44 + +/* + * While this frame is marked as a signal frame, that only applies to how + * the 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. + */ + nop + +__kernel_sigreturn: + popl %eax /* pop sig */ + .cfi_adjust_cfa_offset -4 + movl $__NR_sigreturn, %eax + int $0x80 +endf __kernel_sigreturn + + .cfi_def_cfa_offset RT_SIGFRAME_SIGCONTEXT_eip + 4 + nop + +__kernel_rt_sigreturn: + movl $__NR_rt_sigreturn, %eax + int $0x80 +endf __kernel_rt_sigreturn + + .cfi_endproc + +/* + * TODO: 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/i386/vdso.ld b/linux-user/i386/vdso.ld new file mode 100644 index 0000000000..326b7a8f98 --- /dev/null +++ b/linux-user/i386/vdso.ld @@ -0,0 +1,76 @@ +/* + * Linker script for linux i386 replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +ENTRY(__kernel_vsyscall) + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_time; + __vdso_clock_getres; + __vdso_clock_gettime64; + __vdso_getcpu; + }; + + LINUX_2.5 { + global: + __kernel_vsyscall; + __kernel_sigreturn; + __kernel_rt_sigreturn; + local: *; + }; +} + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS=RWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +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*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + .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) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load =0x90909090 +} diff --git a/linux-user/i386/vdso.so b/linux-user/i386/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..bdece5dfcf8da036d013262d4e37208350283cfa From patchwork Mon Oct 30 21:17:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739289 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337550wrt; Mon, 30 Oct 2023 14:21:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5n7SCL51i5eozzE/Hn2DxwL1eE4grGA1TNa7MOke2SuAfL5GAWuIByN+EHFK+S/7mN8WN X-Received: by 2002:a05:6870:8e16:b0:1eb:e8b:73cb with SMTP id lw22-20020a0568708e1600b001eb0e8b73cbmr13524442oab.58.1698700903872; Mon, 30 Oct 2023 14:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700903; cv=none; d=google.com; s=arc-20160816; b=0k+EKtrOvCKqyw0WGnRuiBQWQlirmWnXhq0ZCabNM15I8jaNi66PzHtdT3SzGFajMM iDZR+WvYWtrDrdBy+Lo3blzqtLor3chOs4zPo+xGBIFeLPldQSAdAKmiDAPcJneSGqhs K0tSpfQ9wpxPEkwPhD3vpluicJwuvY5IR1IXcRhiaOtKm4f9q3Elmg1F3Ik+KX5MCu4e RaGaA2QrLz6sV3/vhBXarrs9y53oQR8xHEUaplRw6cHRF5/Z1IEGxL/kzlYbRioTk9jP rXSYa57t0ZnI1XY8iTimFNiAy3D4fdJDeUzfgzNi2gdAbBBeFRO4mAoXoNzXXq8CbtZX 4HSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=7rKwQXQ2qQHHnqM2GXf0sWy0oFd+5mMN8UFsU+MjJSA=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=rg65XIA1TIB2lTZnrs6oBhI9MvTuEf8UFdMAHO9iZ0IJzDMWcQvfJszdxuqte2tC+R tuYGlizxyyTa1PzVyteUwJQHRzkJIsg17KQwGKFNKy8wQG93fkl3zCn2/PJsLWQ0ZyVz 4M65hxk+3zL4+OMuR8yvjQGc3lgsVRGJZjZ2tyhGsi3HhEjrNAqlQKsBzpu63iIxyltb iSB475+FQ2k6bTPF9iHwl4aJDvVFZz3TItwyIfmfTYrHjAcGEvCN2qwJS5RXidV/xrYa TsFRN2Ss7NGLgJtaMW8eRh1BS4KZLI1ezMiqxv1M6lCr9N0Z+UlBUTgMCiJsaZG/4haD zpNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FNkZxC5m; 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=pass (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 d15-20020a05622a100f00b0041983be87b9si6318999qte.629.2023.10.30.14.21.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:21:43 -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=pass header.i=@linaro.org header.s=google header.b=FNkZxC5m; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZeU-0001hO-OE; Mon, 30 Oct 2023 17:18:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdv-00010O-Sp for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:52 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdm-0006Ut-AI for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:49 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c434c33ec0so37448415ad.3 for ; Mon, 30 Oct 2023 14:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700659; x=1699305459; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7rKwQXQ2qQHHnqM2GXf0sWy0oFd+5mMN8UFsU+MjJSA=; b=FNkZxC5mSfN7ZF8c0XS+WTxUh+B2mmwVPIWhXe7UEgNorQlTBQrcBPsMJ62V4IQp7q TqnAIWBsxM7wE31y78yV0qrmScOivAjV42JUxKotP7Ro7svIG+i+i5TJ/4jwuWIcdYEA Dex7gZbZ2zk3EKJaU1YxBjV6j2iA4SUeXqQGq0AF0bVyLltHhF0n3BUH2m5WC7zesP0v BIm1C3ioI5Mx4+zBe5SBawXa2Z0HnxosSnbPD3sB3yhvO+tpO/heFRAGclI1ptF1M5Yf 0RlRqjgE3DdAqXWktHw8nEGAwenC62to6npEEgDM1h0XlPO1m4Os7utaizim6FBQ6ScA VLvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700659; x=1699305459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7rKwQXQ2qQHHnqM2GXf0sWy0oFd+5mMN8UFsU+MjJSA=; b=PTb3zRJrNCGgd4b8A2tz2JfDOZbBvFdrRVukOMDmiAMy3zSfEheBhiUI/cNMeuw7AK QCWo9TgUdPJz35NHgM6xN+gBr7HQPzcKVN6Y3dIkRizag/YPMoo3lfTcw4Q/vbRUj23e QtRrL+fY4cn8TwYvwqEyf6+GJYdu9Jx6hNLXwLArp3Q3AN27pw9HnI/4FywT+BxGtz8H tY2iYSlTEECl3F7Fp7x9H9t3Mt+7/QcGjMr9133k5Td4Z8oDZWHVFbwkNKxT5JwadRbm kvddox0FZ+kFHMZ1b/k4Zh2CYimI0msInqWifD0OcWB+FrHnbdytabbdH5piETey9h6/ kbJg== X-Gm-Message-State: AOJu0YwPjcTIVGhpsrokpu3Nup5atn2PDYlgTzjGVoCMuAswmsJ4mCY2 eL9993BJeDhdI44ZsKOrT2on+gQbwJN46np2aQo= X-Received: by 2002:a17:902:e845:b0:1cc:3fce:8aa8 with SMTP id t5-20020a170902e84500b001cc3fce8aa8mr4597429plg.6.1698700658602; Mon, 30 Oct 2023 14:17:38 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 11/21] linux-user/x86_64: Add vdso Date: Mon, 30 Oct 2023 14:17:17 -0700 Message-Id: <20231030211727.165090-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 +- linux-user/x86_64/Makefile.vdso | 11 +++++ linux-user/x86_64/meson.build | 4 ++ linux-user/x86_64/vdso.S | 78 ++++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.ld | 73 ++++++++++++++++++++++++++++++ linux-user/x86_64/vdso.so | Bin 0 -> 2968 bytes 6 files changed, 168 insertions(+), 2 deletions(-) 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 GIT binary patch literal 2968 zcmcgtO=w(I6uvKUOl$t7l}J=nY6?Lgol-PVEvcEL6HP)om@-1c>vZO|6VjQnGcRQ# zQlk(xE{v3}x(Eh$E+iYFJ0pdXxDr=E=&lLvMs(4vwBz~aoiCl-j=CuHBzL}hzkANP z=iPhmJs%H_3^h28p){If=E2CAex2B8q6WA=6OrF`(`KF&`Uz?MI&EW@IwS5;Jq_-2rSodh0=h5M8yR&|8~q9xUzjR(|@2weye zz8a;S7@IIXlUIKD#o1b1+rN5odUE>L=z;rh$dv40C`m=ye*;62d-p2^;2j+^>^@b* z{zK-lF(OZeV2X;(id~9-RYHGjYX7&6)!h7{=_DaLK@yv17h==zIwme4kF^2|U3rG4QL%vz2K73uCxOLI|+`aN! z$F-%z;-Tzk@6K$E*Jv}RD{ao_%it)TlnNq<^Unr!fz4Lw$ zOy&HC$f92&rz(YWnba(~S{s>9e=uV%Oyy_Fufeq||4}nCJT{T^4!f^Qd<}K~WJ1Kz zzvUl)Z^gZPP8#nNzOg~(w`aa@FjYY9u^!IW^5APGzK1@7^HK>gD4>;p^R}arI;0o1?04=jpKWw!W)=?0Yt= zynUbER^IkMss3a7y}So_=McZ`$9S>#$BvH<4@j=b`|AzHy`jYM(LpaBOVlKlW^ujb z)P%J2ye6gV=6*G&ja!<{1*x-wK{3QEd-+1(8#gnXPvxf4)sE;I_k4cF&8AA(kO_(* zbIC83rV9C8121D-KkJ<idjF0yGj>9sy zEwzyLtiMFu4~T6avc|lrbF^o@CbB+LUq6S#>RVK)S)cWo$nWI(T!)Byg4)h8>pihg zSHk{7hu^QXIU^m!MEjk0M(-crN9uFmIL=%4U1~>sm5Pe?`en6ee(>HC`S#L{y??u6 vr;^|o8ppUAvD!gdKbRPND1BpVH#|fA;?X5$6$T literal 0 HcmV?d00001 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 46f73a4166..62a33481e1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -318,10 +318,10 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en } \ } while (0) -#define VDSO_HEADER "vdso.c.inc" - #endif /* TARGET_X86_64 */ +#define VDSO_HEADER "vdso.c.inc" + #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 diff --git a/linux-user/x86_64/Makefile.vdso b/linux-user/x86_64/Makefile.vdso new file mode 100644 index 0000000000..26552b66db --- /dev/null +++ b/linux-user/x86_64/Makefile.vdso @@ -0,0 +1,11 @@ +include $(BUILD_DIR)/tests/tcg/x86_64-linux-user/config-target.mak + +SUBDIR = $(SRC_PATH)/linux-user/x86_64 +VPATH += $(SUBDIR) + +all: $(SUBDIR)/vdso.so + +$(SUBDIR)/vdso.so: vdso.S vdso.ld + $(CC) -o $@ -nostdlib -shared -Wl,-h,linux-vdso.so.1 \ + -Wl,--build-id=sha1 -Wl,--hash-style=both \ + -Wl,-T,$(SUBDIR)/vdso.ld $< diff --git a/linux-user/x86_64/meson.build b/linux-user/x86_64/meson.build index 203af9a60c..8c60da7a60 100644 --- a/linux-user/x86_64/meson.build +++ b/linux-user/x86_64/meson.build @@ -3,3 +3,7 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_inc = gen_vdso.process('vdso.so') + +linux_user_ss.add(when: 'TARGET_X86_64', if_true: vdso_inc) diff --git a/linux-user/x86_64/vdso.S b/linux-user/x86_64/vdso.S new file mode 100644 index 0000000000..47d16c00ab --- /dev/null +++ b/linux-user/x86_64/vdso.S @@ -0,0 +1,78 @@ +/* + * x86-64 linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro weakalias name +\name = __vdso_\name + .weak \name +.endm + +.macro vdso_syscall name, nr +__vdso_\name: + mov $\nr, %eax + syscall + ret +endf __vdso_\name +weakalias \name +.endm + + .cfi_startproc + +vdso_syscall clock_gettime, __NR_clock_gettime +vdso_syscall clock_getres, __NR_clock_getres +vdso_syscall gettimeofday, __NR_gettimeofday +vdso_syscall time, __NR_time + +__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 +endf __vdso_getcpu + +weakalias getcpu + + .cfi_endproc + +/* TODO: Add elf note for LINUX_VERSION_CODE */ diff --git a/linux-user/x86_64/vdso.ld b/linux-user/x86_64/vdso.ld new file mode 100644 index 0000000000..ca6001cc3c --- /dev/null +++ b/linux-user/x86_64/vdso.ld @@ -0,0 +1,73 @@ +/* + * Linker script for linux x86-64 replacement vdso. + * + * Copyright 2023 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; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS=RWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +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*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + .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) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load =0x90909090 +} diff --git a/linux-user/x86_64/vdso.so b/linux-user/x86_64/vdso.so new file mode 100755 index 0000000000000000000000000000000000000000..c873d6ea580b393825506d2ffbddcf9827d89e14 From patchwork Mon Oct 30 21:17:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739292 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1337837wrt; Mon, 30 Oct 2023 14:22:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7DUIoXCvbCY6WXKrc8z+anzwqWlScWyMaN1ij3pEBVkIscBjsyv8aUpoHhI14Nkv04uhu X-Received: by 2002:a05:620a:4405:b0:778:930c:1e09 with SMTP id v5-20020a05620a440500b00778930c1e09mr12590536qkp.15.1698700948490; Mon, 30 Oct 2023 14:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700948; cv=none; d=google.com; s=arc-20160816; b=SlGCx2bLlgjB9zLEh5Yy4lsA4rmWCc4gPGbxxSD8BXdXaPVGtTsWJRCBnWlTy5II0+ MqZWH9sAxttNgxSaTIAClIxIetK6zwfWbsiqwOh0Lw1L6G5vgGZyzDORLCYjIeFFFpQo LZt3HIMhsfGjVnL4tLFIktrjT0SI5ZHGYWkjQY1PQU60uAwESIqcqo1jb5nvN4f2zfn6 hQGPUD27lRUjlk4jW0ZvFD7ED65C2qWf2xe0jgSCLEk3q2J/8ED+WUxYOa6pyAc3qoQ9 pau8GQlUPRZUHmnUnDLxncMv0nrjiN6FlE60Swuki3IiXvSiaiMTANuzlJj+VxsDqDlS u3/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=G+bR46JSOqwlNXNPelKKL+3XJAFRZZecNI0O7KRhIOs=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=OHIHAfgaEAIL+NvUs1I8CtnTVPkmXh1x4JNm+ROnoe7CJ7gqB/eSTmtcNZtyiNEMEV 6XNxu1wFkSNYTL89kYxg8Gefy9AE/NjWhRZWI97K8Tc24dARoMa4MnSck0IC+CPgq+rL zpVzLM+OhnQ3BXwgc4EdoGal4Qf7GlnFD/dBCON+yaxV/kkgjRH+hBn7P7Posqi2QzqE uNgrQilLIC2XVWqr1ZVYXlbFtYxagNQlsqRfoSoU10/ltUzrFRy6n/XQ4EL9AbRxrVr6 uS0bM2y5q1AmPQbEQxiwibL/tZD6uu3z+gl3gNq0eD0lEiO/Q04YX15p7VKZbAhUVhRx xW1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=caW6BkjB; 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=pass (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 bk15-20020a05620a1a0f00b00773f4e709efsi6502221qkb.275.2023.10.30.14.22.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:22:28 -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=pass header.i=@linaro.org header.s=google header.b=caW6BkjB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZe5-00016F-2C; Mon, 30 Oct 2023 17:18:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdx-000112-EB for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:53 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdn-0006VE-Ht for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:52 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1cc3542e328so13254865ad.1 for ; Mon, 30 Oct 2023 14:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700659; x=1699305459; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G+bR46JSOqwlNXNPelKKL+3XJAFRZZecNI0O7KRhIOs=; b=caW6BkjBR80YF25qqvs0IMBuYZOL1othElj2fDEVvab1ivud9o3p9mhzcZ512oluzV AhgXp9V/uLqrcBw1KzSaAx9YEoNY38IFAj3M+oXAp0WMce26AP/374xB6GLlvlC4B/cn HYaHtlqYXo/ZPY4c2EA06KH/kIS8R3bhWks4L0moeygg+kcUcxgGpLqB9rjjNvhTs+2p j1+tR/2WW0cgLmgqhRIn5IUsT1OqVE6e/vHPKGE0soKDKDoht3Yc1c4ZbS9c9S/FoHEe aN8rdZ/F58oC+QvfbfccdwjsoudDK6D9Kx4g18qco0FzyaBHhhY55g+8uBk81OclaDmW fnlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700659; x=1699305459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G+bR46JSOqwlNXNPelKKL+3XJAFRZZecNI0O7KRhIOs=; b=mQkdm6/Z/HULpbv9m8evdn6CmXSs7/xqGwR8zetYAfqfaEeKhx/dClyWIH0cWk7tzK XC7Cp6J7aFEVSslNA5A6iU+8IP1Rv0Q2MtIL0BS4OR9Q/mxT0N/n1C76gMDEJkIanRD7 EF8ZGheNIuwhXKwSDikMeJ14W7JK1+qnyjzJNuJKy6BUT736qgGx3asbWxNzo6tT/A/7 VPQJMZ5kteYCFCRqakk8btvTf1Zzxhodz/u80w/43Cz1ROycWvkIUma2hX47xrXci99X EoxDNHDZ9KqGXGt5RBDUyKHrF7sV8ebHgPA3c2wp3Hl6tMHOnEOT818aQne/tPvVV+E7 /Y9Q== X-Gm-Message-State: AOJu0YzuxP1J21H0/dsnYkEPGZCGJrsFcNVI4z9wu2ZqAEwkhK8sAy3/ BEZpp/byVjxjac/GjhLG7RfY9nf4VnHic11pEXU= X-Received: by 2002:a17:902:d484:b0:1cc:361b:7b28 with SMTP id c4-20020a170902d48400b001cc361b7b28mr4701218plg.64.1698700659559; Mon, 30 Oct 2023 14:17:39 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 12/21] linux-user/aarch64: Add vdso Date: Mon, 30 Oct 2023 14:17:18 -0700 Message-Id: <20231030211727.165090-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 6 +++ linux-user/aarch64/Makefile.vdso | 15 +++++++ linux-user/aarch64/meson.build | 11 +++++ linux-user/aarch64/vdso-be.so | Bin 0 -> 3216 bytes linux-user/aarch64/vdso-le.so | Bin 0 -> 3216 bytes linux-user/aarch64/vdso.S | 71 ++++++++++++++++++++++++++++++ linux-user/aarch64/vdso.ld | 72 +++++++++++++++++++++++++++++++ linux-user/meson.build | 1 + 8 files changed, 176 insertions(+) create mode 100644 linux-user/aarch64/Makefile.vdso create mode 100644 linux-user/aarch64/meson.build create mode 100755 linux-user/aarch64/vdso-be.so create mode 100755 linux-user/aarch64/vdso-le.so create mode 100644 linux-user/aarch64/vdso.S create mode 100644 linux-user/aarch64/vdso.ld diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 62a33481e1..0a3a57018b 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -944,6 +944,12 @@ const char *elf_hwcap2_str(uint32_t bit) #undef GET_FEATURE_ID +#if TARGET_BIG_ENDIAN +# define VDSO_HEADER "vdso-be.c.inc" +#else +# define VDSO_HEADER "vdso-le.c.inc" +#endif + #endif /* not TARGET_AARCH64 */ #endif /* TARGET_ARM */ diff --git a/linux-user/aarch64/Makefile.vdso b/linux-user/aarch64/Makefile.vdso new file mode 100644 index 0000000000..599958116b --- /dev/null +++ b/linux-user/aarch64/Makefile.vdso @@ -0,0 +1,15 @@ +include $(BUILD_DIR)/tests/tcg/aarch64-linux-user/config-target.mak + +SUBDIR = $(SRC_PATH)/linux-user/aarch64 +VPATH += $(SUBDIR) + +all: $(SUBDIR)/vdso-be.so $(SUBDIR)/vdso-le.so + +LDFLAGS = -nostdlib -shared -Wl,-h,linux-vdso.so.1 -Wl,--build-id=sha1 \ + -Wl,--hash-style=both -Wl,-T,$(SUBDIR)/vdso.ld + +$(SUBDIR)/vdso-be.so: vdso.S vdso.ld + $(CC) -o $@ $(LDFLAGS) -mbig-endian $< + +$(SUBDIR)/vdso-le.so: vdso.S vdso.ld + $(CC) -o $@ $(LDFLAGS) -mlittle-endian $< diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build new file mode 100644 index 0000000000..248c578d15 --- /dev/null +++ b/linux-user/aarch64/meson.build @@ -0,0 +1,11 @@ +# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it +# is always true as far as source_set.apply() is concerned. Always build +# both header files and include the right one via #if. + +vdso_be_inc = gen_vdso.process('vdso-be.so', + extra_args: ['-r', '__kernel_rt_sigreturn']) + +vdso_le_inc = gen_vdso.process('vdso-le.so', + extra_args: ['-r', '__kernel_rt_sigreturn']) + +linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [vdso_be_inc, vdso_le_inc]) diff --git a/linux-user/aarch64/vdso-be.so b/linux-user/aarch64/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..6084f3d1a701316004894fcdd739c4e1e0463b68 GIT binary patch literal 3216 zcmc&$O>A355T57v+64N8Q&ABq6>X&mRj7RmMS`Gmu!EhX$W24qs-c&yv0q~6$41XD z#X$mc;KBh>)D!9f7jbE&o3KO1&W#3omsDqjgUAn$-Zyr zo0*+`yF2UmUcNA$N_k+#hcB@25ZaP4_Th`HO~N+FKpLJveLJ?m*pV~RgWjm21z{L< z$}wd4LC@ee4`!_DFeDmp#mw&i^z)Y(0;(W3!dXI>qX-{*VL(Jr;fPar2{J(&x^9ec+i^?x(BSN1)Vd z6xX6PwHzf$bv>#tm5ZAlwzO6+t%|J=9Y>808z-t!U5=w- z6pqiGSyV^E7sBUX!r9;i8&^=H^Slq6Ij8hSDe#8W?GM<704wzH#{6Rl z3kP~-l0hxTsW!QgLi`s#bF@9x%T9lbJQ zY!o|4aN}q$C{o`>LtdYI781M2@Zr_SAbWZB{G@i?^Z?>M}yPa6444u6aN z(@-i+W?!6HJsZ|xybR+_P`TIVvL}weg5`%7zsk?5>4ofxyqe7|fSM_soXQr|$?54+ z`P1rjcB+t9-4$r--d6bFQntST=8k}{vALcU-#|=agB9u3>PZA)d9zkruaW$*LZfyK0az`B= zOP9o-=tekTbo-S2gfC;0-yF_wz7ueqd5$=Y$YX0p;sews@%Q~V_LKN6qx+07iF&_y za+`8&63=yF?=kuAAb%2B2kO6y`P9?hbjKdryS z$@`Pr5;mESVJiH5fKy;kWM_r}wHqu6`)kkRea&Hpa463^!_;Pn&K^S8m+ zp?wpfSa~nu80C99^(GSZO}Up1l7AF+`VDc{mR$&j&a-ljQ9$NP`UtiG@xy#y!}}7* HXyg9^8}}&g literal 0 HcmV?d00001 diff --git a/linux-user/aarch64/vdso-le.so b/linux-user/aarch64/vdso-le.so new file mode 100755 index 0000000000000000000000000000000000000000..947d534ec1899740edbd6921da6bc6e70e2ecd09 GIT binary patch literal 3216 zcmcguL2MgU5FKYzk|v=|N~=Z+qD6{Og~_6L z9VDO!E}RJB#LXZsa7BWO3q5c^;)VcKz2t<11S;tPP82h|}KgVe=J;LxHx3r3FKB<#|V;X^n)Fz2- z%cM-;q^lZWOhj#+*XG^Ds~rB${uGqOuBG$Zd_T*Cz*Q~uCH;#!pUtzO6%jc6iOo2- zUEEGBEQ!`_!5rx^Nnd=)Smd95v^A8^_@B?;{q2QA>mys0rC%Ro5$%x&)1`=ocG5ko z6aD^Iry=8;Iu?IIw{$G$Bh;3SV;YGV-B3QNd{X(JooK$aERgAej@6vDbv&c;NbCQ9 zy6kcvjnN%lhwQabmYd)|D~|JcjqwS(-w~ZS$+3$5Eo+{GihpC_aoczwaVXo4J(oVt zLv%HS2r(>}=m;)N?7pOQiiV@`7Cn)F;GMkl%e$@jzP@~EJllTi@Po`JTV%{t&#!wc zrs4%bZPjZmmx~)cw6xMFU4<+G_Pu5g^#jwaReUd4^Xs%ytFN`5T`xBqF8`mS!u-P0 zMRU|W=01Od7sIQ^Pev*IefZVAM%JKvfiC4uzP+=NPvcQDQRF&JRZp-29I1zrXF6AH(sU{_$LFT%Cwyk#+LZ z;ng6&;~EaXMOzkXk;A9cMqe_Vo>WIFiraPM4aMzx@xJ0a>P4w^{aUtsrS3Lpx=hn8 zGTB!bGNW-|qICZ9i-J8#ZsW(zsfpMl-H?`HVJ zQ@N}AZ)ya&&5hNdc!hc3N4$z&y%BiimN)9f)mka+urBjrP$aifUvsO)W;MbCKSI_$ zzgcV4`v#^=u2(h7esR?^)iP^hL~h`<0^Y;_N)i`xuRvNNF2N-Z;)L%5uqU}Abr|7; zxC7_l3JG@?*rRSe%~JWM!awQ*_-14tu2H6fJ-)w38511-QAfZJvn)=q2Y-=;^38#N z)EjWrSput!}27rBsaAE89EDuX@lA>g=oKwq~LLwcEeotS^rIq;}{ z^!&pQ_yx9?I}66Bhu~O0Vg&Dx1uSz%)&%>9-4mgYeZyE{IBt*n3VsBN%5DE|sy*%y zs59VLKc=z$$9+Rb__iuu(-)I_ + +/* ??? These are in include/elf.h, which is not ready for inclusion in asm. */ +#define NT_GNU_PROPERTY_TYPE_0 5 +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1) + +#define GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT \ + (GNU_PROPERTY_AARCH64_FEATURE_1_BTI | GNU_PROPERTY_AARCH64_FEATURE_1_PAC) + + .section .note.gnu.property + .align 3 + .long 2f - 1f + .long 6f - 3f + .long NT_GNU_PROPERTY_TYPE_0 +1: .string "GNU" +2: .align 3 +3: .long GNU_PROPERTY_AARCH64_FEATURE_1_AND + .long 5f - 4f +4: .long GNU_PROPERTY_AARCH64_FEATURE_1_DEFAULT +5: .align 3 +6: + + .text + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +.macro vdso_syscall name, nr +\name: + bti c + mov x8, #\nr + svc #0 + ret +endf \name +.endm + + .cfi_startproc + +vdso_syscall __kernel_gettimeofday, __NR_gettimeofday +vdso_syscall __kernel_clock_gettime, __NR_clock_gettime +vdso_syscall __kernel_clock_getres, __NR_clock_getres + + .cfi_endproc + + +/* + * TODO: The kernel makes a big deal of turning off the .cfi directives, + * because they cause libgcc to crash, but that's because they're wrong. + * + * For now, elide the unwind info for __kernel_rt_sigreturn and rely on + * the libgcc fallback routine as we have always done. This requires + * that the code sequence used be exact. + */ +__kernel_rt_sigreturn: + /* No BTI C insn here -- we arrive via RET. */ + mov x8, #__NR_rt_sigreturn + svc #0 +endf __kernel_rt_sigreturn diff --git a/linux-user/aarch64/vdso.ld b/linux-user/aarch64/vdso.ld new file mode 100644 index 0000000000..4c12f33352 --- /dev/null +++ b/linux-user/aarch64/vdso.ld @@ -0,0 +1,72 @@ +/* + * Linker script for linux aarch64 replacement vdso. + * + * Copyright 2021 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6.39 { + global: + __kernel_rt_sigreturn; + __kernel_gettimeofday; + __kernel_clock_gettime; + __kernel_clock_getres; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + /* + * We can't 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*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + .data : { + *(.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) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load =0xd503201f +} diff --git a/linux-user/meson.build b/linux-user/meson.build index e4cb70ed2d..dd24389052 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -35,6 +35,7 @@ gen_vdso_exe = executable('gen-vdso', 'gen-vdso.c', gen_vdso = generator(gen_vdso_exe, output: '@BASENAME@.c.inc', arguments: ['-o', '@OUTPUT@', '@EXTRA_ARGS@', '@INPUT@']) +subdir('aarch64') subdir('alpha') subdir('arm') subdir('hppa') From patchwork Mon Oct 30 21:17:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739274 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1336520wrt; Mon, 30 Oct 2023 14:18:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHd+YKdICM6hQILpY8wOMl9Kw4yJgybNssMf/8G+zkvCkVJWVTzdQdskk8CrEg0HhszzVDO X-Received: by 2002:a05:620a:3192:b0:775:98ab:e11a with SMTP id bi18-20020a05620a319200b0077598abe11amr1503521qkb.11.1698700711129; Mon, 30 Oct 2023 14:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700711; cv=none; d=google.com; s=arc-20160816; b=K4gBx99BErCWjBlEISXvX04fTOWGwmYZLHDoAiPxnJSllGrFPI8k0Hvfd3m8GJRV7n G1cLCtzllhm2UEIM7QXfr6vtsr/0QZNiFkZmPb2CeRExH1bL791GcEJu3zfMR+vsh73o EWk0KqOHDjQJvZDk3oKo76z/ogHkFStNPgGT0U35PreOEaVjFsY1L97lWSB9LZoMIT+r FpsABDFzDQ/xCQDNSEWs9h8RaDL2lihBBn6gf6XbCrMU/TfUYYY65X8VatD+Ze5Tr/Lz Lc9jAqF63kxfWMxa+MGKEko+yyunLyHDtFK3eKkl6gFPP68Ssx6qtMgYWkqlQykxyit7 3tFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=o8UKlKVkoj09wOTSfnwVa8vuy3oPCOLj92gGCvrYZjE=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=pRJTCnCwwRB+rDEmyuSTCgeZHcYP2p0T6oczcOBaQwhgzoCIXbkbg6I6f+lccd4I84 rO/WSGyU1C6MtOGeMkQnP+nRoBQtB8RENHWmtpEEB6+oooEdm7VfMY6WCZAy2FEVyJGJ yjveyxo75ngpVm1Ft8VhFatPGmqZYDOZI5TKgPmgN7z7e/ctXCbLJtFmAYA8guU9g9mG Ffsutme1WBcYiFf6WpXbQ1g6oYQsjdVPBLX769P4auGI8t1UQL/I7GpbvQadGoWPf5b8 gw3LZZwEI9j8WROj1sNOkGsbJUrLaAHvvPHOnvYWXILT1LNERxdilV3b9HdFIPqg7YlL Xqiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h7BBz2mj; 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=pass (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 s11-20020a05620a254b00b0077a0282bfa1si6792812qko.261.2023.10.30.14.18.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:18:31 -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=pass header.i=@linaro.org header.s=google header.b=h7BBz2mj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZe9-00017A-Nb; Mon, 30 Oct 2023 17:18:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdx-000115-GU for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:53 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdp-0006VM-H5 for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:52 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1cc53d0030fso9722505ad.0 for ; Mon, 30 Oct 2023 14:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700660; x=1699305460; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=o8UKlKVkoj09wOTSfnwVa8vuy3oPCOLj92gGCvrYZjE=; b=h7BBz2mj/SQgaMpiYWwsC+CIWR7lWViiFM/jJjlo7sjUCieu4rfJGr/kSMbVTpnMKo Y6NVdrguCejjXbpu96kYCrBKCDUuMa09/1oLbw7o8G1QjBwm/6c1vL5z+xAx1qSE0Pgl EljRmAJWaZNj2E/idibLQUlcCDtP3pRJVgqHS3XTLl7Pj9DRH9H09d9rVWFo5DMVTB4R Xlwt9RiHi216KsmIPVj+7Y+Y3y4A4T1lM7/aDCMeGNpCth7cGYhyDQSzi9cxs1Daiqd6 YkCo7KhLK+sWCOPJRI+m5l/Ef7p+YRZaxAa9tqS7bP2a3NXgtjZ9XErUDMcadxssuLzm MmWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700660; x=1699305460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o8UKlKVkoj09wOTSfnwVa8vuy3oPCOLj92gGCvrYZjE=; b=t1ndPjq4VPS8UqaaFoKrbFopMh/rbx6qWrDoiWr5Fqt4FDi8jHeb5kZGi78Eoxw5V7 EZn+kW+8WgZgsXSNrjmHJIS7ItfXYX1uYdeURGpRKfsiSsxj1Am606eLwBb1Hgp7hv6P 9e5RMLSQBOw3H6wxhhpb9isAsENounyD7Bb9ehiOOIb6fOs6BAaTX6PBXT8Mz9s+Pdp+ bXzo8aTp3jXYJsB+20eyO52j2toMcR1qrdcDmIg3V5qBLAw+DW39ERCzE6qip9sV9aEE +hZmZVLn9QuEm2kc/7a+NGKrhzDJog4i05KfO86V/miw2J1XHxweGSndJHbp0rneBAyl WAew== X-Gm-Message-State: AOJu0YznUW1fj84q0dSUaBUSbB9dorz2YTMFxmh2Q/3e0cn69wSlZJ8l znojynxgD9flY4WDs5W6VKosNoyr5GjdgfgKgMk= X-Received: by 2002:a17:903:2805:b0:1cc:30bf:d07c with SMTP id kp5-20020a170903280500b001cc30bfd07cmr744293plb.10.1698700660512; Mon, 30 Oct 2023 14:17:40 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 13/21] linux-user/arm: Add vdso Date: Mon, 30 Oct 2023 14:17:19 -0700 Message-Id: <20231030211727.165090-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson --- linux-user/arm/vdso-asmoffset.h | 3 + linux-user/arm/signal.c | 55 ++++++---- linux-user/elfload.c | 3 +- linux-user/arm/Makefile.vdso | 17 ++++ linux-user/arm/meson.build | 12 +++ linux-user/arm/vdso-be.so | Bin 0 -> 2648 bytes linux-user/arm/vdso-le.so | Bin 0 -> 2648 bytes linux-user/arm/vdso.S | 174 ++++++++++++++++++++++++++++++++ linux-user/arm/vdso.ld | 67 ++++++++++++ 9 files changed, 310 insertions(+), 21 deletions(-) create mode 100644 linux-user/arm/vdso-asmoffset.h create mode 100644 linux-user/arm/Makefile.vdso create mode 100755 linux-user/arm/vdso-be.so create mode 100755 linux-user/arm/vdso-le.so create mode 100644 linux-user/arm/vdso.S create mode 100644 linux-user/arm/vdso.ld diff --git a/linux-user/arm/vdso-asmoffset.h b/linux-user/arm/vdso-asmoffset.h new file mode 100644 index 0000000000..252a95c46e --- /dev/null +++ b/linux-user/arm/vdso-asmoffset.h @@ -0,0 +1,3 @@ +/* offsetof(struct sigframe, retcode[3]) */ +#define SIGFRAME_RC3_OFFSET 756 +#define RT_SIGFRAME_RC3_OFFSET 884 diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c index cf99fd7b8a..e19b514f17 100644 --- a/linux-user/arm/signal.c +++ b/linux-user/arm/signal.c @@ -21,6 +21,7 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" +#include "vdso-asmoffset.h" struct target_sigcontext { abi_ulong trap_no; @@ -102,6 +103,11 @@ struct rt_sigframe struct sigframe sig; }; +QEMU_BUILD_BUG_ON(offsetof(struct sigframe, retcode[3]) + != SIGFRAME_RC3_OFFSET); +QEMU_BUILD_BUG_ON(offsetof(struct rt_sigframe, sig.retcode[3]) + != RT_SIGFRAME_RC3_OFFSET); + static abi_ptr sigreturn_fdpic_tramp; /* @@ -160,6 +166,9 @@ get_sigframe(struct target_sigaction *ka, CPUARMState *regs, int framesize) return (sp - framesize) & ~7; } +static void write_arm_sigreturn(uint32_t *rc, int syscall); +static void write_arm_fdpic_sigreturn(uint32_t *rc, int ofs); + static int setup_return(CPUARMState *env, struct target_sigaction *ka, int usig, struct sigframe *frame, abi_ulong sp_addr) @@ -167,9 +176,9 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig, abi_ulong handler = 0; abi_ulong handler_fdpic_GOT = 0; abi_ulong retcode; - int thumb, retcode_idx; - int is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info); - bool copy_retcode; + bool is_fdpic = info_is_fdpic(((TaskState *)thread_cpu->opaque)->info); + bool is_rt = ka->sa_flags & TARGET_SA_SIGINFO; + bool thumb; if (is_fdpic) { /* In FDPIC mode, ka->_sa_handler points to a function @@ -184,9 +193,7 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig, } else { handler = ka->_sa_handler; } - thumb = handler & 1; - retcode_idx = thumb + (ka->sa_flags & TARGET_SA_SIGINFO ? 2 : 0); uint32_t cpsr = cpsr_read(env); @@ -202,24 +209,32 @@ setup_return(CPUARMState *env, struct target_sigaction *ka, int usig, cpsr &= ~CPSR_E; } - if (ka->sa_flags & TARGET_SA_RESTORER) { - if (is_fdpic) { - __put_user((abi_ulong)ka->sa_restorer, &frame->retcode[3]); - retcode = (sigreturn_fdpic_tramp + - retcode_idx * RETCODE_BYTES + thumb); - copy_retcode = true; - } else { - retcode = ka->sa_restorer; - copy_retcode = false; - } + /* Our vdso default_sigreturn label is a table of entry points. */ + retcode = default_sigreturn + (is_fdpic * 2 + is_rt) * 8; + + /* + * Put the sigreturn code on the stack no matter which return + * mechanism we use in order to remain ABI compliant. + * Because this is about ABI, always use the A32 instructions, + * despite the fact that our actual vdso trampoline is T16. + */ + if (is_fdpic) { + write_arm_fdpic_sigreturn(frame->retcode, + is_rt ? RT_SIGFRAME_RC3_OFFSET + : SIGFRAME_RC3_OFFSET); } else { - retcode = default_sigreturn + retcode_idx * RETCODE_BYTES + thumb; - copy_retcode = true; + write_arm_sigreturn(frame->retcode, + is_rt ? TARGET_NR_rt_sigreturn + : TARGET_NR_sigreturn); } - /* Copy the code to the stack slot for ABI compatibility. */ - if (copy_retcode) { - memcpy(frame->retcode, g2h_untagged(retcode & ~1), RETCODE_BYTES); + if (ka->sa_flags & TARGET_SA_RESTORER) { + if (is_fdpic) { + /* Place the function descriptor in slot 3. */ + __put_user((abi_ulong)ka->sa_restorer, &frame->retcode[3]); + } else { + retcode = ka->sa_restorer; + } } env->regs[0] = usig; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 0a3a57018b..7400ed0ca1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -944,13 +944,14 @@ const char *elf_hwcap2_str(uint32_t bit) #undef GET_FEATURE_ID +#endif /* not TARGET_AARCH64 */ + #if TARGET_BIG_ENDIAN # define VDSO_HEADER "vdso-be.c.inc" #else # define VDSO_HEADER "vdso-le.c.inc" #endif -#endif /* not TARGET_AARCH64 */ #endif /* TARGET_ARM */ #ifdef TARGET_SPARC diff --git a/linux-user/arm/Makefile.vdso b/linux-user/arm/Makefile.vdso new file mode 100644 index 0000000000..2d098a5748 --- /dev/null +++ b/linux-user/arm/Makefile.vdso @@ -0,0 +1,17 @@ +include $(BUILD_DIR)/tests/tcg/arm-linux-user/config-target.mak + +SUBDIR = $(SRC_PATH)/linux-user/arm +VPATH += $(SUBDIR) + +all: $(SUBDIR)/vdso-be.so $(SUBDIR)/vdso-le.so + +# Adding -use-blx disables unneeded interworking without actually using blx. +LDFLAGS = -nostdlib -shared -Wl,-use-blx \ + -Wl,-h,linux-vdso.so.1 -Wl,--build-id=sha1 \ + -Wl,--hash-style=both -Wl,-T,$(SUBDIR)/vdso.ld + +$(SUBDIR)/vdso-be.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS) -mbig-endian $< + +$(SUBDIR)/vdso-le.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS) -mlittle-endian $< diff --git a/linux-user/arm/meson.build b/linux-user/arm/meson.build index 5a93c925cf..c4bb9af5b8 100644 --- a/linux-user/arm/meson.build +++ b/linux-user/arm/meson.build @@ -5,3 +5,15 @@ syscall_nr_generators += { arguments: [ meson.current_source_dir() / 'syscallhdr.sh', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it +# is always true as far as source_set.apply() is concerned. Always build +# both header files and include the right one via #if. + +vdso_be_inc = gen_vdso.process('vdso-be.so', + extra_args: ['-s', 'sigreturn_codes']) + +vdso_le_inc = gen_vdso.process('vdso-le.so', + extra_args: ['-s', 'sigreturn_codes']) + +linux_user_ss.add(when: 'TARGET_ARM', if_true: [vdso_be_inc, vdso_le_inc]) diff --git a/linux-user/arm/vdso-be.so b/linux-user/arm/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..69cafbb956e283e2975bac59a10491c0cbafca57 GIT binary patch literal 2648 zcmbtVO>A355T57%q>ketR9ezQ5D`VCwMu1`A`rrf?W8D4OPYuR5-*PZ5?ds8WWR(2 z@#8{h3oY#>2P%XJf@`Y?wNft?xqwg)z@Y~Y{2jstAq3+00GRLFx0^a47sMproBd{H zci-Ec8NZkr$XY&2*2OP(V{8mbk?=~e?h{E$mjvPKkU0Dy0KRoBV@w1z%zRKvVA+F& z^~zXK{%ArSV?xa@xZfTX@xgB(Y4`}`*ZKyuK{v)kv;S6bf8WrkT>1HI=J#C}-v0DM z`Ko86^ZqyN_qyPV0iyusSZkHW-@jr%ep?Va4UKQK=Am1G3a|}`R~n5!;a`RR3)~0& zBh+P#|F5L*D%>Y>i%1lDAGibEs`+;CC!09VIPho_XRMMAY5ar%&)0|_1Kt@mh37=U zx2hZAeHdX3?~e!ucLq!h=LA6obHD6}=FU|f2Mju6;lhx^e0ON;&FanQ51J*e74D=NAY3MoVW#|{6 zanIHg5CLf03mfxAtY?SC_gu{CjJA<-pB(_tzg1GP$SL1Bo+a)3f$z4k_rvzZ7WOgN zJ^><4>mP{+D1V6mJPr-x*-qNEh%uz;lUsF(DljGBI$8)UPyl zNA8oa>(@A1S|7FO(a>)CR!Yzxm1(PEZ z^0nw!=Z+iX1{o6A_<0B9K5Cff`2=TGT(rgQ}v7(FCIR|w_~Q7kFj14 zBZ!Vi+wgjT<<0Me=LBqBI1J9e$GjiLe7}dxdFc2N*p%pg@)YJb_opg2YsvH{IP`qcBbFX4yOh) zc7J+U?7o2`J*ffvNH%*cGh&aVdImCfQ%ledXhQ?p+?1Lc&4xy`MNd-wOA@t(X*V|x z?N&WqG^29GbtF+(DCee2c{M;Rbk5C5VzNA&DCTNK&+b+|%bZiKl`7>8#4bp}DcTd& z+_YmC3y3sK60S4vN+LBpn8>+qwKP8K;%NSp;J#I!GWS^*L^ohW=e*nj1M?ecr}Bk4 zTL*NGBb~hb-UH1%!+NYERZC;wjAO1cj{Wd}=2(yQrE07>zZplc7FcIoZ_R`31?PKE zOxz*-#gf@z*MNm_mp!O@FzdlipFC!M<3U$F z$RXJIz4Y__C=&qJ=6X0gRrAv?=0AXBj6aWAK literal 0 HcmV?d00001 diff --git a/linux-user/arm/vdso-le.so b/linux-user/arm/vdso-le.so new file mode 100755 index 0000000000000000000000000000000000000000..ad05a1251875ac0c76685e1f9190a7307a8444d1 GIT binary patch literal 2648 zcmbtWU1%It6h5<)-6ZYqW>ciL#)n9wmD&!qgeWwKo1aZ8NgB5ajR>7=b|=}zWT)&- zVj@~ojcv8s`j8h9Aw_&tf++N*n7)V<5g#h}py-1lh)4@s`cPfJ@6OyfN%J6hHs74{ zoqO(`JNMpmZeH#k$QXtpT1i52o2xxn z_w4-TgA;d}AB-ETNwkdyeSX4(|NOh=rtr=vd_Bc$r=V{@FGDxb z2kZxU9w^2OS&6)uG+N>b;d^!gTz~GJq>~M2BNq(%4+6geoBjRpeYb^w9KNpro(Vlp zJ8cNwc?>UY;!DRDQ>U9=Nxqs`iodq~%(kbOjXUR6Z#Cm zvm|}VAL(xez5tehI3THH^rb(du~@3Ho_bGROvU_$rfERUMa9H|n3#%TSIXk2wY?3G z$q$QHXf3Z>je#|^mu+hq{d*pq_J@JK@^1XvJDF79_km8|i$QZvZlWYc0%o**L}HOf zPW>*q9(YW(^Zp*tWds@U ze4~nI{qp10j!S2dfTpS@BEvx)kLlnIvCH7X0G0> z?Euj=zyNOnKaKabLPya55w-{O +#include "vdso-asmoffset.h" + +/* + * All supported cpus have T16 instructions: at least arm4t. + * + * We support user-user with m-profile cpus as an extension, because it + * is useful for testing gcc, which requires we avoid A32 instructions. + */ + .thumb + .arch armv4t + .eabi_attribute Tag_FP_arch, 0 + .eabi_attribute Tag_ARM_ISA_use, 0 + + .text + +.macro raw_syscall n + .ifne \n < 0x100 + mov r7, #\n + .elseif \n < 0x1ff + mov r7, #0xff + add r7, #(\n - 0xff) + .else + .err + .endif + swi #0 +.endm + +.macro fdpic_thunk ofs + ldr r3, [sp, #\ofs] + ldmia r2, {r2, r3} + mov r9, r3 + bx r2 +.endm + +.macro endf name + .globl \name + .type \name, %function + .size \name, . - \name +.endm + +/* + * We must save/restore r7 for the EABI syscall number. + * While we're doing that, we might as well save LR to get a free return, + * and a branch that is interworking back to ARMv5. + */ + +.macro SYSCALL name, nr +\name: + .cfi_startproc + push {r7, lr} + .cfi_adjust_cfa_offset 8 + .cfi_offset r7, -8 + .cfi_offset lr, -4 + raw_syscall \nr + pop {r7, pc} + .cfi_endproc +endf \name +.endm + +SYSCALL __vdso_clock_gettime, __NR_clock_gettime +SYSCALL __vdso_clock_gettime64, __NR_clock_gettime64 +SYSCALL __vdso_clock_getres, __NR_clock_getres +SYSCALL __vdso_gettimeofday, __NR_gettimeofday + + +/* + * We, like the real kernel, use a table of sigreturn trampolines. + * Unlike the real kernel, we do not attempt to pack this into as + * few bytes as possible -- simply use 8 bytes per slot. + * + * Within each slot, use the exact same code sequence as the kernel, + * lest we trip up someone doing code inspection. + */ + +.macro slot n + .balign 8 + .org sigreturn_codes + 8 * \n +.endm + +.macro cfi_fdpic_r9 ofs + /* + * fd = *(r13 + ofs) + * r9 = *(fd + 4) + * + * DW_CFA_expression r9, length (7), + * DW_OP_breg13, ofs, DW_OP_deref, + * DW_OP_plus_uconst, 4, DW_OP_deref + */ + .cfi_escape 0x10, 9, 7, 0x7d, (\ofs & 0x7f) + 0x80, (\ofs >> 7), 0x06, 0x23, 4, 0x06 +.endm + +.macro cfi_fdpic_pc ofs + /* + * fd = *(r13 + ofs) + * pc = *fd + * + * DW_CFA_expression lr (14), length (5), + * DW_OP_breg13, ofs, DW_OP_deref, DW_OP_deref + */ + .cfi_escape 0x10, 14, 5, 0x7d, (\ofs & 0x7f) + 0x80, (\ofs >> 7), 0x06, 0x06 +.endm + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + .cfi_startproc simple + .cfi_signal_frame + .cfi_return_column 15 + + .cfi_def_cfa sp, 32 + 64 + .cfi_offset r0, -16 * 4 + .cfi_offset r1, -15 * 4 + .cfi_offset r2, -14 * 4 + .cfi_offset r3, -13 * 4 + .cfi_offset r4, -12 * 4 + .cfi_offset r5, -11 * 4 + .cfi_offset r6, -10 * 4 + .cfi_offset r7, -9 * 4 + .cfi_offset r8, -8 * 4 + .cfi_offset r9, -7 * 4 + .cfi_offset r10, -6 * 4 + .cfi_offset r11, -5 * 4 + .cfi_offset r12, -4 * 4 + .cfi_offset r13, -3 * 4 + .cfi_offset r14, -2 * 4 + .cfi_offset r15, -1 * 4 + + nop + + .balign 16 +sigreturn_codes: + /* [EO]ABI sigreturn */ + slot 0 + raw_syscall __NR_sigreturn + + .cfi_def_cfa_offset 160 + 64 + + /* [EO]ABI rt_sigreturn */ + slot 1 + raw_syscall __NR_rt_sigreturn + + .cfi_endproc + + /* FDPIC sigreturn */ + .cfi_startproc + cfi_fdpic_pc SIGFRAME_RC3_OFFSET + cfi_fdpic_r9 SIGFRAME_RC3_OFFSET + + slot 2 + fdpic_thunk SIGFRAME_RC3_OFFSET + .cfi_endproc + + /* FDPIC rt_sigreturn */ + .cfi_startproc + cfi_fdpic_pc RT_SIGFRAME_RC3_OFFSET + cfi_fdpic_r9 RT_SIGFRAME_RC3_OFFSET + + slot 3 + fdpic_thunk RT_SIGFRAME_RC3_OFFSET + .cfi_endproc + + .balign 16 +endf sigreturn_codes diff --git a/linux-user/arm/vdso.ld b/linux-user/arm/vdso.ld new file mode 100644 index 0000000000..3b00adf27a --- /dev/null +++ b/linux-user/arm/vdso.ld @@ -0,0 +1,67 @@ +/* + * Linker script for linux arm replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_clock_getres; + __vdso_clock_gettime64; + + local: *; + }; +} + + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS=RWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +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*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + .data : { + *(.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) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load +} From patchwork Mon Oct 30 21:17:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 739276 Delivered-To: patch@linaro.org Received: by 2002:a5d:4c47:0:b0:32d:baff:b0ca with SMTP id n7csp1336673wrt; Mon, 30 Oct 2023 14:18:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWPta2s/eBsM3nG5qdwMQc0naWFSqsk+CnCwk0hQn9z1KsQBrLS5jbgaNu1o/BhqrRdP1/ X-Received: by 2002:a05:6214:f6a:b0:65c:fec4:30a1 with SMTP id iy10-20020a0562140f6a00b0065cfec430a1mr15139397qvb.55.1698700733644; Mon, 30 Oct 2023 14:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698700733; cv=none; d=google.com; s=arc-20160816; b=rCemSfvI6qEUi9JxsmE0gGcg2ZlYAekaSFSOJUL53pKatV3pEl/9Nk0VQ5+pweKQM3 P/WhBGmX03s4Hlun5PDEbbAWEVNS9OKm4QOcYY5KySzD98ZvjzHElyOPfsjtRfiSFVyI Dk05pLLV0aCdXhAQV2TXUycpTgpM596w5/gYrxjJc4UlCHcCwTJVB9QYvUbG7S82Fjg9 Fk/G/fExH26rdvqe/4I5t1OcEAtMpVcdrvP66D0hcRYlj559e8/oNgG6gQHYGVYCgTJk +wYHtTl7VJFp7xXcnj1X92QakfRYDBTVtpebjvWMv3rQLmyscB7e+DCCeBdR/v1oBn3A 9QCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=4/MBMw/W/ZdwjTxmKJnaM9kgrEqezUX04ffr+PV0Xg0=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=GWa2ELSC6VkUYWMfp19ubF15O/X1X7xrYtrLnv0DNxfz4l2BJHNoPo2iu7bdfBy3KW PZb2/fuFwunLO9k+83Gsnk+4IQByCxorRex143SY2F0SXVdLRfAazb36EpxwxkfKkcah biaCwXbjUmlGU8CsubbU0Qtp1PPdatjPN3eGbgr1RU/OMuZ21+ftyGQPWPBN+T+DdFwl YQslLehtfGwNvC33Xuy+UUf3vzewaBs1EEN8rR2UEGHmQVkVkc5sRAv7ixlb7xZV5C1F 22GoPCAuC1KxgApkanAej1wSC795rttER9uu0KRaUgHY9WUcnlxwe7R0Esf7Rkg78HYN giyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ts+057Ox; 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=pass (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 m4-20020ad44d44000000b0063f7d73dd87si6273883qvm.584.2023.10.30.14.18.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Oct 2023 14:18:53 -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=pass header.i=@linaro.org header.s=google header.b=Ts+057Ox; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxZe6-000176-4L; Mon, 30 Oct 2023 17:18:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxZdx-00011A-Gk for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:54 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxZdo-0006VS-Lk for qemu-devel@nongnu.org; Mon, 30 Oct 2023 17:17:52 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1cc4f777ab9so11131445ad.0 for ; Mon, 30 Oct 2023 14:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698700661; x=1699305461; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4/MBMw/W/ZdwjTxmKJnaM9kgrEqezUX04ffr+PV0Xg0=; b=Ts+057OxxJAl3KepBWx6keaGteEsmN3ll7qYrr1jvYaq3egn1gAozTGjz21tFdtcnR 1vXT6s4e5AjXH1IE0D/gR+48zUIxeqnRoijJjU3Qg6ExJrSOyTeYK9PLoGd1rfJtElc5 b8iCyCcBNYVNIk7hvbB24BeDUIKy+Jo8zMY4iaeu1QusqVB0AF4tVM1Y43QFUytTUKsS a/kbMWxrrEPfsieih8bmpJaXCWur9WcIq48EBEXMdgP6rIedcnN0wWdVWrSKN6bFCSox tANGxiMlNRTyi33VXsu/NZtdnT5zWn+7xRnuf6gDJjVx7xJcuYnWBNhP8Ze37b1WgUjU /Gcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698700661; x=1699305461; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4/MBMw/W/ZdwjTxmKJnaM9kgrEqezUX04ffr+PV0Xg0=; b=UvKfLucOird3yALP/+uy/s7JzthiTkVT+cR+sy/YXXLauTmV53jtWUPCQ199Xj9McH Ok+GPAUcQc+aEhGUJccox0Tdxa6DutW3ad/iUZWHh2oHMFGOpnj5dYyggOWHMN0ZNzsH c3m4JwTaUt1bOepv44k+k+JzM10fmwQpaBdJAk+h/+iRj4luwVONSSFts0cT8fPx57P/ k0MIdoyFD5H2yAcdv/AFY69YfRZXxuokhndABiPTZllYmbRGkBCNg6699DiRBI7CBgr4 WTXqV7MEypnP+vQ0DcWr1GdxqCyk5F7CEFLPx8GtAohibpLuOGwv+sJGV6u3zfFMHdkn T0yg== X-Gm-Message-State: AOJu0YzBd+uhjLL9w8v7y/D4ZGxwjEfw61cErxuP+X165hNdfc4dfNUD pOLPOerbnLij0/GnGKuSsXJIcDIJ5krz1yaW8XI= X-Received: by 2002:a17:902:dcc5:b0:1cc:b3f:dd81 with SMTP id t5-20020a170902dcc500b001cc0b3fdd81mr7593302pll.67.1698700661319; Mon, 30 Oct 2023 14:17:41 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id jf2-20020a170903268200b001cc32261bdfsm4670350plb.38.2023.10.30.14.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 14:17:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 14/21] linux-user/hppa: Add vdso Date: Mon, 30 Oct 2023 14:17:20 -0700 Message-Id: <20231030211727.165090-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030211727.165090-1-richard.henderson@linaro.org> References: <20231030211727.165090-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/hppa/vdso-asmoffset.h | 12 +++ linux-user/elfload.c | 2 + linux-user/hppa/signal.c | 24 +++-- linux-user/hppa/Makefile.vdso | 11 +++ linux-user/hppa/meson.build | 5 + linux-user/hppa/vdso.S | 165 +++++++++++++++++++++++++++++++ linux-user/hppa/vdso.ld | 77 +++++++++++++++ linux-user/hppa/vdso.so | Bin 0 -> 2104 bytes 8 files changed, 286 insertions(+), 10 deletions(-) create mode 100644 linux-user/hppa/vdso-asmoffset.h 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 GIT binary patch literal 2104 zcmbtVTXR!Y6kaFkhEgcBP%l`hafWdil!Lv1RY03GNz;<1rD7>6(0JUG~~*U)EYXMdFQ(BmGb?r%x-$mIFC+3xTU<+0?(1N%-~JGte| zwo#0&1h`Mkv8G3g7ybaBfv&)R1jiYzaqu#r23QVo^SCSe7yscgz|X_x1OE;7zacM{ z)|dd5Qv4kHJ82ot+=CYbD;A=;?E| z+O@bm6U{_s6$j@&=K!(p?Mg~X zNxxOSx@O|YQQtBD{UyiM14~XUeXw+5*+XR~mp{DXk@8b3A6<32;<3udS3j}l$*QL= zd;0Qcu9&>?*|pDI^?daU>t0;{Qq9X(zY>_*^y+o5UH|&#H|#gJymiCdwbOO))W6&C z-q!cGeQ@K4jUV0g@y(xX|8&P^J3qhW%&lKEeHlC(`l|Ws@Hdf}=(jE3#lCMHW; zONHX9xm|@5D$=2%ovLNGigl^hq-yI{yLwc7k81B#i9XfQuR8at-M6W(+g0)o)qSVx zanzoDsyC(j22_8Vr_*Qt6`W`0eJzTL#S4K_@ijH9MKe`ddw-H+LR}U|=Qy2(>V?rY z1fBH)(sj*o{IovBFBJ9<$eQLCI%^7~`+_?Ao;v%3I{KO9);;u6S9h0zzRc5gxj|&Sy_i8rNTu72w>n-mm4>KjyI4HF5rW`17r(z$)~w!;~p-Ow|1nqfFBMc>aU8q_P9)|;yMpZzCl>C4=|Coz%^Y;{L;DN4)bKq{t{_fJydxBhI~~zzGScmI z2Sf3Qv!HS8{Ndq3>MpVKg`CR=jg%cJWW-J%&ZdTk?$!c)!Bd5l*!#1i_FyVM=-LZ8 z*K#P6%MXoY7bs3z?98AufIVfL!8AOLCUzk+R&dYvKfl%RW1g54)&;QvFy!T2u7QF1 zMOrSt&AewX$GSF{-%SAXhIp(aT}uJz^keQAkM9EVqIJY$eh5<^kS@K|J0P>p7;oBz z?knzt#CSv_-q=6E={Ms-0?_~K7xHZML!Ihc<@;@jdnC0XUJ;yrc(-*8a~%^8c8*D} zdE;G`CSg6AJLMeG0KnLAF#k;p-Us8y>={4wf$jxe@351M-+hqjhn)DwT}TsjLrtFG t#WH69ET#p-{eR>C0pl?r>_u}nn&