@samitouri / QOSamiQemu / commits / db3abd36e4

linux-user/sh4: allow full 32-bit address space

On real SH4 hardware, the address space is split between user mode (U0, 0x00000000-0x7fffffff) and kernel mode (P1-P4, 0x80000000-0xffffffff), so TARGET_VIRT_ADDR_SPACE_BITS was set to 31 for CONFIG_USER_ONLY. However, qemu-user does not emulate the MMU, so this limit is not needed. The only effect is to restrict reserved_va to 2 GB, causing OOM failures for memory-intensive builds (e.g. webkit2gtk on Debian sh4 buildds). Set TARGET_VIRT_ADDR_SPACE_BITS to 32 unconditionally, like most other 32-bit targets. Also fix the TASK_UNMAPPED_BASE macro to use 1ull instead of 1u to avoid undefined behavior when shifting by 32. Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Signed-off-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Helge Deller <deller@gmx.de> Signed-off-by: Helge Deller <deller@gmx.de>

Laurent Vivier committed Jul 27, 2026 at 13:48 UTC db3abd36e4c7c2a72e00e5806cf4c47f5aa5c491
2 files changed +4 -6
linux-user/sh4/target_mman.h
+1 -1
@@ -1,6 +1,6 @@
1 /* arch/sh/include/asm/processor_32.h */
2 #define TASK_UNMAPPED_BASE \
3 - TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3)
3 + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3)
4
5 /* arch/sh/include/asm/elf.h */
6 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2)
target/sh4/cpu-param.h
+3 -5
@@ -9,10 +9,8 @@
9 #define SH4_CPU_PARAM_H
10
11 #define TARGET_PAGE_BITS 12 /* 4k */
12 -#ifdef CONFIG_USER_ONLY
13 -# define TARGET_VIRT_ADDR_SPACE_BITS 31
14 -#else
15 -# define TARGET_VIRT_ADDR_SPACE_BITS 32
16 -#endif
12 +
13 +/* qemu-user does not emulate the MMU, so no need to limit to 31 bits. */
14 +#define TARGET_VIRT_ADDR_SPACE_BITS 32
15
16 #endif