[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [PATCH 1/1] tci: eliminate UB due to unaligned reads

From: Anatoly Trosinenko
Subject: Re: [Qemu-trivial] [PATCH 1/1] tci: eliminate UB due to unaligned reads
Date: Sat, 3 Mar 2018 19:01:42 +0300

2018-03-03 18:41 GMT+03:00 Stefan Weil <address@hidden>:
Am 03.03.2018 um 15:07 schrieb Anatoly Trosinenko:
> Can rewriting TCI in such a way that every operation is aligned at 4- or
> even 8-byte boundary fix the situation or are there some more serious
> problems?

That's my preferred solution. Are there cases which would require 8-byte

And what if create some function like

uint8_t *align_and_increment(uint8_t **ptr, int pow2) {
  size_t size = 1 << pow2;
  uint8_t *result = (uint8_t*)((((uintptr)*ptr) + size - 1) & ~(size - 1));
  *ptr = result + size;
  return result;

and rewrite get / put functions like this:

static uint32_t tci_read_i32(uint8_t **tb_ptr)
    uint32_t value = *(uint32_t *)align_and_increment(tb_ptr, 2);
    return value;

On one hand, it involves some slightly obscure pointer calculations
(just in one place), on the other hand, no modifications will probably
be required for TCI TCG backend or interpreter loop code (they can
still be useful for **optimizations** of bytecode size, but it should
just work as is).

Best regards,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]