From patchwork Fri Jan 8 22:42:55 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: 12007741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27AF7C433E0 for ; Fri, 8 Jan 2021 22:56:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C2973239E5 for ; Fri, 8 Jan 2021 22:56:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2973239E5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ky0fr-0002GN-Qo for qemu-devel@archiver.kernel.org; Fri, 08 Jan 2021 17:56:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ky0cb-00073K-GD for qemu-devel@nongnu.org; Fri, 08 Jan 2021 17:52:41 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:35970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ky0cZ-0008Kz-S5 for qemu-devel@nongnu.org; Fri, 08 Jan 2021 17:52:41 -0500 Received: by mail-wr1-x42c.google.com with SMTP id t16so10434400wra.3 for ; Fri, 08 Jan 2021 14:52:39 -0800 (PST) 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=WgAij1gXMiHcT+yoonkBqiCmQUdZDDELVCGJ0vlVeHQ=; b=XVBF2P4/Fc31VwDOo/a/ljatF4Et8swbW7CGgb3CKD3oS47KKMu6GP8iE9NtObHTTg DexjL2CfR1iO46VEXBHrUfADYe1HNj2thlyaDyJcWzN9IlNp8l/W3+48LX8cA1+9wGft 6LCCa66TM0fatq6uVSyOkEuq4Voo0nv7qYjXeo6QRirGvgfKIQMdyxNNJH81eSIIpyW4 4ogvHEcOgHQcFrbUH7JA6NuLH4yPXZv7pZhSkR/FWDVpWpAAaiaxPX+V9PatnFY/x1NZ 57FcPyFB1Zv2BDSeLXwnY76hjMdk44N7NjWXbYOhaOKm0qGUjjwm8+SUToFrXDVuEtN+ djZA== 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=WgAij1gXMiHcT+yoonkBqiCmQUdZDDELVCGJ0vlVeHQ=; b=trJKcE9Zt7PUrhKMCHxu7y/Y8zEnulJmkiwnRtgleLiOZ/E6cAH/dcggKGf1/Q6Uxm KsaEM0xzgyIVT8iBOGVjWk3oIf5sPhQz2ilEe2e7x+nFsWxpG8COZ4ItO7pPluWj6MlC S2IkIWD6m+1qPC36/UzYyBYEBkqyj43o/WTf5mMvwhieE2AmqKUD5XUHxMX9Y2K4nSxT pQgDdkvUqS3aZktTWj0+za1H86eq3gUqoGLT19W4HcRKwVxWDQMKaKEhx8Fv0Nxid2ZV IPHhD56+LDRO3Y0dnpVsjpyZAGzNZ/Gr/36PgdQmFNzqECivP63lVfb4kI18q1YGbT6t 9BIg== X-Gm-Message-State: AOAM531sKPEB/0enVrTa5acNpZvbJ1o0gWXH5ChpWgLn1FykmgzpGEVQ a1VvXLy3DbBJWdsIb0f87W8iJg== X-Google-Smtp-Source: ABdhPJyVYOjyxWonWiEOKXLmQVgVSp22lIvCvKqnP27gPE2rNFiSbyLOt+6z2EbAKl+RpklSVdIgUg== X-Received: by 2002:a5d:5112:: with SMTP id s18mr5564921wrt.267.1610146358607; Fri, 08 Jan 2021 14:52:38 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u205sm14291687wme.42.2021.01.08.14.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 14:52:33 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E34331FFA6; Fri, 8 Jan 2021 22:42:58 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 19/20] semihosting: Implement SYS_TMPNAM Date: Fri, 8 Jan 2021 22:42:55 +0000 Message-Id: <20210108224256.2321-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210108224256.2321-1-alex.bennee@linaro.org> References: <20210108224256.2321-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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: Keith Packard , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Keith Packard Part of Semihosting for AArch32 and AArch64 Release 2.0 Signed-off-by: Keith Packard Message-Id: <20210107170717.2098982-9-keithp@keithp.com> Signed-off-by: Alex Bennée --- hw/semihosting/common-semi.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/semihosting/common-semi.c b/hw/semihosting/common-semi.c index 3d6604dcdd..a631904fb0 100644 --- a/hw/semihosting/common-semi.c +++ b/hw/semihosting/common-semi.c @@ -835,6 +835,7 @@ target_ulong do_common_semihosting(CPUState *cs) CPUArchState *env = cs->env_ptr; target_ulong args; target_ulong arg0, arg1, arg2, arg3; + target_ulong ul_ret; char * s; int nr; uint32_t ret; @@ -998,8 +999,24 @@ target_ulong do_common_semihosting(CPUState *cs) return guestfd_fns[gf->type].flenfn(cs, gf); case TARGET_SYS_TMPNAM: - qemu_log_mask(LOG_UNIMP, "%s: SYS_TMPNAM not implemented", __func__); - return -1; + GET_ARG(0); + GET_ARG(1); + GET_ARG(2); + if (asprintf(&s, "/tmp/qemu-%x%02x", getpid(), + (int) (arg1 & 0xff)) < 0) { + return -1; + } + ul_ret = (target_ulong) -1; + + /* Make sure there's enough space in the buffer */ + if (strlen(s) < arg2) { + char *output = lock_user(VERIFY_WRITE, arg0, arg2, 0); + strcpy(output, s); + unlock_user(output, arg0, arg2); + ul_ret = 0; + } + free(s); + return ul_ret; case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1);