qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: [Qemu-devel] [PATCH v2 2/9] tcg: Avoid stores to unaligned addresses
Date: Tue,  1 Apr 2014 13:53:27 -0700	[thread overview]
Message-ID: <1396385614-19267-3-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1396385614-19267-1-git-send-email-rth@twiddle.net>

From: Peter Maydell <peter.maydell@linaro.org>

Avoid stores to unaligned addresses in TCG code generation, by using the
usual memcpy() approach. (Using bswap.h would drag a lot of QEMU baggage
into TCG, so it's simpler just to do direct memcpy() here.)

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 tcg/tcg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index f1e0763..60f06c5 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -125,21 +125,21 @@ static inline void tcg_out8(TCGContext *s, uint8_t v)
 static inline void tcg_out16(TCGContext *s, uint16_t v)
 {
     uint8_t *p = s->code_ptr;
-    *(uint16_t *)p = v;
+    memcpy(p, &v, sizeof(v));
     s->code_ptr = p + 2;
 }
 
 static inline void tcg_out32(TCGContext *s, uint32_t v)
 {
     uint8_t *p = s->code_ptr;
-    *(uint32_t *)p = v;
+    memcpy(p, &v, sizeof(v));
     s->code_ptr = p + 4;
 }
 
 static inline void tcg_out64(TCGContext *s, uint64_t v)
 {
     uint8_t *p = s->code_ptr;
-    *(uint64_t *)p = v;
+    memcpy(p, &v, sizeof(v));
     s->code_ptr = p + 8;
 }
 
-- 
1.9.0

  parent reply	other threads:[~2014-04-01 20:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-01 20:53 [Qemu-devel] [PATCH v2 0/9] tcg: tidy the type of code_ptr Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 1/9] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps Richard Henderson
2014-04-01 20:53 ` Richard Henderson [this message]
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 3/9] tcg: Avoid undefined behaviour patching code at unaligned addresses Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 4/9] tcg: Introduce byte pointer arithmetic helpers Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 5/9] tcg: Define tcg_insn_unit for code pointers Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 6/9] tcg-i386: Define TCG_TARGET_INSN_UNIT_SIZE Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 7/9] tcg-ppc64: " Richard Henderson
2014-04-01 21:12   ` Peter Maydell
2014-04-01 21:31     ` Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 8/9] tcg-ppc: " Richard Henderson
2014-04-01 20:53 ` [Qemu-devel] [PATCH v2 9/9] tcg-sparc: " Richard Henderson
2014-04-01 21:15 ` [Qemu-devel] [PATCH v2 0/9] tcg: tidy the type of code_ptr Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1396385614-19267-3-git-send-email-rth@twiddle.net \
    --to=rth@twiddle.net \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).