From patchwork Tue Jun 15 16:58:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 460551 Delivered-To: patch@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp4479244jae; Tue, 15 Jun 2021 09:59:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5CFCqHr143Swn9dHl33ylzwsW2QAhlthlU2tqfB09EYTsCx4Lb53o0lg1yNPp8sDQen+4 X-Received: by 2002:a67:fad0:: with SMTP id g16mr5986643vsq.37.1623776364653; Tue, 15 Jun 2021 09:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623776364; cv=none; d=google.com; s=arc-20160816; b=sKDU3siqsgFoSNKvKCt5sl1mpLfUBTI2r049bPuzFbgUqFYm1gXIBWX4JXd/GUeZYy O6V/bvvJR+6d1q3PtWYHczfgpW2iSaFxjK7rk8+c9Q/0BhnVOyJ5M2Rdn6mQn+z1krKA zHuVjRJHTPsgZohoAhKqjJuPzjLou8yel116Dw7rSFXTqn9U9+JPzTvzeCtqXmygXkKt TGdwR9Id5x1O3Ou5wpViJNrEwypOSHqU4NBn1n9/t6ly9CLI9qpHYZ+kQ6t0wKeEPWv2 q/l3S/Cnumfyf9qy4mjQgfodJolfWsOX0+T29MUzub1QygtfVAJSmYfnCT/7cAIdGBTg 2KRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=sGa6vECs+n4MFunaX33qznn0819BFDMLBnsgyGX5SyY=; b=CPTYr+v7hSVboOqO5KSzB1kOwrwvmU8zow4TpBjcDHkAaqBA+rYgnJ3kQjTm0hLvmf o7o4/itvUJ01eDgM304u5HDcXuj+uUyQoJcoNx+PCqhaNNs15FOyRY9BftHRzMJhTVaQ OW+2aSy7f6zQaofxoFUxGjgBrkrosvbTXAGP4nEHlO88hsOpDO+o+awfIM0khVXmhDah HP/dmue7ijGXj0jWhTaZJl8Ys9DU2WIOgeihm+j74z7TT3YFMl729Uy4gtfhf6F5u7L9 emfMctnSvCZGGhJAWZ94+ZNuZk/rI7X5DImNrVg+cf8rAfNkzYSW9Tr1Z8QrTZjaTfzP J0Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AHmIuI75; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t27si3018425vkm.43.2021.06.15.09.59.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Jun 2021 09:59:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AHmIuI75; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltCPM-0001wr-1v for patch@linaro.org; Tue, 15 Jun 2021 12:59:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltCOA-00012N-JK for qemu-devel@nongnu.org; Tue, 15 Jun 2021 12:58:10 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:42900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltCO8-000169-Gl for qemu-devel@nongnu.org; Tue, 15 Jun 2021 12:58:10 -0400 Received: by mail-wm1-x331.google.com with SMTP id l7-20020a05600c1d07b02901b0e2ebd6deso24447wms.1 for ; Tue, 15 Jun 2021 09:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sGa6vECs+n4MFunaX33qznn0819BFDMLBnsgyGX5SyY=; b=AHmIuI75QUeVwk45SFwdkpk3d7NH8BoUB55fl1Nm4msNfu8nBuNKEiQMNRMH7yL5p0 3awMfV3VCidU2IqrLScyGlWVr5neYAxdSSYZIKLI/WuKNl5vlSpgCK7MC3II0snmotAF D7mjSfvdid/mfEc45Q9a6mwcT9OmDzAI50CAX67U7sXri2GCpysD59Ia9784ExTb71LY 6sVxGX9tQmxJFKET2BBG53RHzXy3H65mstnMshmadkOKEBg/+bCmzMZy32MWlkLSTaTq VXq0v+Ckr9peSPwOpPz2R9+vD5hgeNx20SFr50Nku7QlxBCJJ/sglcYJNmubgd1aDvRQ yBUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sGa6vECs+n4MFunaX33qznn0819BFDMLBnsgyGX5SyY=; b=tUfddypk+qTMtLgoUvWN9upzo7bU3qekEaesTVl5JZxERnkpeWAxT1dxOrkbgW1313 iia1j8UHeyqTIii6MY2z4IJ46Wyh6yBD5jt5gqBtzZiJzRTWWEG4pXkGLwBGaYeJfmko 3KW/JIfIXfOXHVb7ENCQo0lXe/cCtoW2ZTAXWkr9/U0H72dJE0UzrSrRBsHj4awIlgQs 8YcUfaC17QHA2rD+5gwHthklaLU1xYBW7EndyidWcn6wAkhqucJpxHYiKMa71I22YQgx Xwa6J3FhaAAegPYJmhgQ9uB/z9oKf2MA/+BPQzRtc4qAfGzK6p+DUzSVWcjtLmTvgjDX 5+vQ== X-Gm-Message-State: AOAM532GMMJjMH1GqeCuVZSBUUIlQCLh3QnnMZCZ2l2suDFIjHwnwzCV 3LHfRt8CkG45NZ9BGt+0DUItx0r8yL893Q== X-Received: by 2002:a1c:e907:: with SMTP id q7mr6449591wmc.1.1623776283946; Tue, 15 Jun 2021 09:58:03 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q5sm20162320wrm.15.2021.06.15.09.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 09:58:02 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BB38B1FF8C; Tue, 15 Jun 2021 17:58:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v3 2/2] tests/tcg: port SYS_HEAPINFO to a system test Date: Tue, 15 Jun 2021 17:58:00 +0100 Message-Id: <20210615165800.23265-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210615165800.23265-1-alex.bennee@linaro.org> References: <20210615165800.23265-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This allows us to check our new SYS_HEAPINFO implementation generates sane values. Signed-off-by: Alex Bennée --- tests/tcg/aarch64/system/semiheap.c | 74 +++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/tcg/aarch64/system/semiheap.c -- 2.20.1 diff --git a/tests/tcg/aarch64/system/semiheap.c b/tests/tcg/aarch64/system/semiheap.c new file mode 100644 index 0000000000..d5613dca59 --- /dev/null +++ b/tests/tcg/aarch64/system/semiheap.c @@ -0,0 +1,74 @@ +/* + * Semihosting System HEAPINFO Test + * + * Copyright (c) 2021 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include + +#define SYS_HEAPINFO 0x16 + +uintptr_t __semi_call(uintptr_t type, uintptr_t arg0) +{ + register uintptr_t t asm("x0") = type; + register uintptr_t a0 asm("x1") = arg0; + asm("hlt 0xf000" + : "=r" (t) + : "r" (t), "r" (a0)); + + return t; +} + +int main(int argc, char *argv[argc]) +{ + struct { + void *heap_base; + void *heap_limit; + void *stack_base; + void *stack_limit; + } info; + void *ptr_to_info = (void *) &info; + + ml_printf("Semihosting Heap Info Test\n"); + + /* memset(&info, 0, sizeof(info)); */ + __semi_call(SYS_HEAPINFO, (uintptr_t) &ptr_to_info); + + if (info.heap_base == NULL || info.heap_limit == NULL) { + ml_printf("null heap: %p -> %p\n", info.heap_base, info.heap_limit); + return -1; + } + + /* Error if heap base is above limit */ + if ((uintptr_t) info.heap_base >= (uintptr_t) info.heap_limit) { + ml_printf("heap base %p >= heap_limit %p\n", + info.heap_base, info.heap_limit); + return -2; + } + + if (info.stack_base == NULL) { + ml_printf("null stack: %p -> %p\n", info.stack_base, info.stack_limit); + return -3; + } + + /* + * We don't check our local variables are inside the reported + * stack because the runtime may select a different stack area (as + * our boot.S code does). However we can check we don't clash with + * the heap. + */ + if (ptr_to_info > info.heap_base && ptr_to_info < info.heap_limit) { + ml_printf("info appears to be inside the heap: %p in %p:%p\n", + ptr_to_info, info.heap_base, info.heap_limit); + return -4; + } + + ml_printf("heap: %p -> %p\n", info.heap_base, info.heap_limit); + ml_printf("stack: %p <- %p\n", info.stack_limit, info.stack_base); + ml_printf("Passed HeapInfo checks\n"); + return 0; +}