qemu/include/user
Peter Maydell b16930ecb9 include/user/guest-host.h: Provide g2h etc for both abi_ptr and vaddr
In commit 7804c84a ("include/user: Use vaddr in guest-host.h") we
changed all the functions in guest-host.h that took or returned their
guest address argument in type abi_ptr to instead use vaddr.

This introduced regressions for the case of a 32-bit guest and an
address above 2GB for the common situation where the address is a
syscall argument stored in a variable of type 'abi_long'.  With
abi_ptr (which will be an unsigned 32-bit type for 32-bit guests),
the address is cast to unsigned 32-bit, and then zero-extended to
64-bits in g2h_untagged_vaddr().  With the switch to vaddr (which is
always a 64-bit unsigned type), the guest address will instead be
sign-extended to 64 bits, which gives the wrong answer.

Fix this by providing two versions of the affected functions: the
standard names (g2h(), g2h_untagged(), guest_addr_valid_untagged(),
guest_range_valid_untagged(), cpu_untagged_addr()) return to using
the logically-correct abi_ptr type; new versions with a _vaddr()
prefix use the vaddr type.

accel/tcg/user-exec.c must change to use the _vaddr() versions; this
is the only file that uses guest-host.h that we want to compile once.
All the other uses are in linux-user and bsd-user code that
inherently has to know the sizes of target-ABI types.

Cc: qemu-stable@nongnu.org
Fixes: 7804c84a ("include/user: Use vaddr in guest-host.h")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3333
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20260330143123.1685142-3-peter.maydell@linaro.org
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 8330da591e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2026-05-14 22:28:26 +03:00
..
abitypes.h qemu: Declare all load/store helper in 'qemu/bswap.h' 2025-07-15 02:56:39 -04:00
cpu_loop.h linux-user: Move target_cpu_copy_regs decl to qemu.h 2025-08-28 06:39:25 +10:00
guest-base.h exec: Restrict inclusion of 'user/guest-base.h' 2024-04-26 17:03:05 +02:00
guest-host.h include/user/guest-host.h: Provide g2h etc for both abi_ptr and vaddr 2026-05-14 22:28:26 +03:00
mmap.h user: Extract common MMAP API to 'user/mmap.h' 2025-03-09 14:54:32 +01:00
page-protection.h accel/tcg: Add clear_flags argument to page_set_flags 2025-10-14 07:30:39 -07:00
safe-syscall.h {linux,bsd}-user: Introduce get_task_state() 2024-03-06 12:35:19 +00:00
signal.h user: Introduce host_interrupt_signal 2025-02-10 13:47:59 +00:00
syscall-trace.h user: Move 'abitypes.h' from 'exec/user' to 'user' 2024-05-03 17:21:18 +02:00
thunk.h user: Move 'thunk.h' from 'exec/user' to 'user' 2024-05-03 17:21:20 +02:00
tswap-target.h exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h' 2024-04-26 17:03:05 +02:00