From nobody Sat May 4 19:12:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554790454764868.3582293426338; Mon, 8 Apr 2019 23:14:14 -0700 (PDT) Received: from localhost ([127.0.0.1]:36027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDk1B-0001ya-PF for importer@patchew.org; Tue, 09 Apr 2019 02:14:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDk0H-0001cG-J3 for qemu-devel@nongnu.org; Tue, 09 Apr 2019 02:13:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDk0G-0005Mz-M9 for qemu-devel@nongnu.org; Tue, 09 Apr 2019 02:13:05 -0400 Received: from mail.weilnetz.de ([37.120.169.71]:43718 helo=v2201612906741603.powersrv.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDk0G-0005Ml-DG; Tue, 09 Apr 2019 02:13:04 -0400 Received: from localhost (localhost [127.0.0.1]) by v2201612906741603.powersrv.de (Postfix) with ESMTP id B1AD4DB6050; Tue, 9 Apr 2019 08:04:39 +0200 (CEST) Received: from v2201612906741603.powersrv.de ([127.0.0.1]) by localhost (v2201612906741603.powersrv.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0hL-XRLQcPSb; Tue, 9 Apr 2019 08:04:38 +0200 (CEST) Received: from qemu.weilnetz.de (qemu.weilnetz.de [188.68.58.204]) by v2201612906741603.powersrv.de (Postfix) with ESMTP id E83CFDB604C; Tue, 9 Apr 2019 08:04:38 +0200 (CEST) Received: by qemu.weilnetz.de (Postfix, from userid 1000) id DD47A46000F; Tue, 9 Apr 2019 08:04:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at v2201612906741603.powersrv.de From: Stefan Weil To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Date: Tue, 9 Apr 2019 08:04:35 +0200 Message-Id: <20190409060435.22801-1-sw@weilnetz.de> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 37.120.169.71 Subject: [Qemu-devel] [PATCH] tci: Fix some unaligned memory accesses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Weil , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Stefan Weil --- tcg/tci.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tcg/tci.c b/tcg/tci.c index 33edca1903..20b0715b6e 100644 --- a/tcg/tci.c +++ b/tcg/tci.c @@ -1,7 +1,7 @@ /* * Tiny Code Interpreter for QEMU * - * Copyright (c) 2009, 2011, 2016 Stefan Weil + * Copyright (c) 2009, 2011, 2016, 2019 Stefan Weil * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -159,7 +159,8 @@ static uint64_t tci_uint64(uint32_t high, uint32_t low) /* Read constant (native size) from bytecode. */ static tcg_target_ulong tci_read_i(uint8_t **tb_ptr) { - tcg_target_ulong value =3D *(tcg_target_ulong *)(*tb_ptr); + tcg_target_ulong value; + memcpy(&value, *tb_ptr, sizeof(value)); *tb_ptr +=3D sizeof(value); return value; } @@ -167,7 +168,8 @@ static tcg_target_ulong tci_read_i(uint8_t **tb_ptr) /* Read unsigned constant (32 bit) from bytecode. */ static uint32_t tci_read_i32(uint8_t **tb_ptr) { - uint32_t value =3D *(uint32_t *)(*tb_ptr); + uint32_t value; + memcpy(&value, *tb_ptr, sizeof(value)); *tb_ptr +=3D sizeof(value); return value; } @@ -175,7 +177,8 @@ static uint32_t tci_read_i32(uint8_t **tb_ptr) /* Read signed constant (32 bit) from bytecode. */ static int32_t tci_read_s32(uint8_t **tb_ptr) { - int32_t value =3D *(int32_t *)(*tb_ptr); + int32_t value; + memcpy(&value, *tb_ptr, sizeof(value)); *tb_ptr +=3D sizeof(value); return value; } @@ -184,7 +187,8 @@ static int32_t tci_read_s32(uint8_t **tb_ptr) /* Read constant (64 bit) from bytecode. */ static uint64_t tci_read_i64(uint8_t **tb_ptr) { - uint64_t value =3D *(uint64_t *)(*tb_ptr); + uint64_t value; + memcpy(&value, *tb_ptr, sizeof(value)); *tb_ptr +=3D sizeof(value); return value; } @@ -474,7 +478,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *= tb_ptr) tcg_target_ulong regs[TCG_TARGET_NB_REGS]; long tcg_temps[CPU_TEMP_BUF_NLONGS]; uintptr_t sp_value =3D (uintptr_t)(tcg_temps + CPU_TEMP_BUF_NLONGS); - uintptr_t ret =3D 0; + uint64_t ret =3D 0; =20 regs[TCG_AREG0] =3D (tcg_target_ulong)env; regs[TCG_REG_CALL_STACK] =3D sp_value; @@ -1094,7 +1098,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t= *tb_ptr) /* QEMU specific operations. */ =20 case INDEX_op_exit_tb: - ret =3D *(uint64_t *)tb_ptr; + memcpy(&ret, tb_ptr, sizeof(uint64_t)); goto exit; break; case INDEX_op_goto_tb: --=20 2.11.0