On Sun, Apr 9, 2023 at 2:53 AM Michael Tokarev <[email protected]> wrote:
> Hi! > > In the qemu-user case, we allocate various structures and arrays > for conversion of data between host and guest byte orders and sizes. > But it is actually not necessary to do such allocation when the > *size* is the same, and only byte order is different, because the > conversion can be done in-place. Does it make any sense to avoid' > allocations in such cases? > > There are 2 issues with this though. First is that in some cases, > the data being converted is const, and we may end up writing to a > data resides in a read-only segment, is it ever possible? And > second - it is not entirely clear what to do in case the syscall > returned error. > I don't think you can reliably do it in place. What if another thread in the guest reads the data after you've converted it? It will get the wrong answer. I think you have to copy when endian mismatches, just like when alignment, data size or layout differences are present. You'd need to convert it back after the system call as well, which can cause problems, especially if the system call needs multiple steps to emulate for whatever reason. Warner
