On Thu, 19 Sept 2024 at 14:11, Alex Bennée <alex.ben...@linaro.org> wrote:
>
> Peter Maydell <peter.mayd...@linaro.org> writes:
> > While I'm looking at the code, this caught my eye:
> >
> >     case QEMU_PLUGIN_MEM_VALUE_U64:
> >     {
> >         uint64_t *p = (uint64_t *) &ri->data[offset];
> >         uint64_t val = be ? htobe64(value.data.u64) : 
> > htole64(value.data.u64);
> >         if (is_store) {
> >             *p = val;
> >         } else if (*p != val) {
> >             unseen_data = true;
> >         }
> >         break;
> >     }
> >
> > Casting a random byte pointer to uint64_t* like that
> > and dereferencing it isn't valid -- it can fault if
> > it's not aligned correctly.
>
> Hmm in the normal case of x86 hosts we will never hit this.

Not necessarily -- some x86 SIMD insns enforce alignment.

> I guess we
> could do a memcpy step and then the byteswap?

That's what bswap.h does, yes.

> Could it be included directly without bringing in the rest of QEMU's
> include deps?

It's technically quite close to standalone I think,
but I think it would be a bad idea to directly include
it because once you put QEMU's include/ on the plugin
compile include path then that's a slippery slope to
the plugins not actually being standalone code any more.

-- PMM

Reply via email to