Skip to content

Commit

Permalink
linux-user: Define ELF_ET_DYN_BASE in $guest/target_mman.h
Browse files Browse the repository at this point in the history
Copy each guest kernel's default value, then bound it
against reserved_va or the host address space.

Tested-by: Helge Deller <deller@gmx.de>
Reviewed-by: Helge Deller <deller@gmx.de>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Aug 6, 2023
1 parent f229c4a commit cff7f7c
Show file tree
Hide file tree
Showing 23 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions linux-user/aarch64/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
#define TASK_UNMAPPED_BASE (1ull << (48 - 2))

/* arch/arm64/include/asm/elf.h */
#define ELF_ET_DYN_BASE TARGET_PAGE_ALIGN((1ull << 48) / 3 * 2)

#include "../generic/target_mman.h"

#endif
3 changes: 3 additions & 0 deletions linux-user/alpha/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
*/
#define TASK_UNMAPPED_BASE 0x20000000000ull

/* arch/alpha/include/asm/elf.h */
#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)

#include "../generic/target_mman.h"

#endif
3 changes: 3 additions & 0 deletions linux-user/arm/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
*/
#define TASK_UNMAPPED_BASE 0x40000000

/* arch/arm/include/asm/elf.h */
#define ELF_ET_DYN_BASE 0x00400000

#include "../generic/target_mman.h"
3 changes: 3 additions & 0 deletions linux-user/cris/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
*/
#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3)

/* arch/cris/include/uapi/asm/elf.h */
#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2)

#include "../generic/target_mman.h"
3 changes: 3 additions & 0 deletions linux-user/hexagon/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
*/
#define TASK_UNMAPPED_BASE 0x40000000

/* arch/hexagon/include/asm/elf.h */
#define ELF_ET_DYN_BASE 0x08000000

#include "../generic/target_mman.h"
3 changes: 3 additions & 0 deletions linux-user/hppa/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
/* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */
#define TASK_UNMAPPED_BASE 0x40000000

/* arch/parisc/include/asm/elf.h */
#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)

#include "../generic/target_mman.h"

#endif
3 changes: 3 additions & 0 deletions linux-user/i386/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
*/
#define TASK_UNMAPPED_BASE 0x40000000

/* arch/x86/include/asm/elf.h */
#define ELF_ET_DYN_BASE 0x00400000

#include "../generic/target_mman.h"
3 changes: 3 additions & 0 deletions linux-user/loongarch64/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
#define TASK_UNMAPPED_BASE \
TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3)

/* arch/loongarch/include/asm/elf.h */
#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2)

#include "../generic/target_mman.h"
2 changes: 2 additions & 0 deletions linux-user/m68k/target_mman.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* arch/m68k/include/asm/processor.h */
#define TASK_UNMAPPED_BASE 0xC0000000
/* arch/m68k/include/asm/elf.h */
#define ELF_ET_DYN_BASE 0xD0000000

#include "../generic/target_mman.h"
15 changes: 15 additions & 0 deletions linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,21 @@ int main(int argc, char **argv, char **envp)
}
mmap_next_start = task_unmapped_base;

/* Similarly for elf_et_dyn_base. */
if (reserved_va) {
if (ELF_ET_DYN_BASE < reserved_va) {
elf_et_dyn_base = ELF_ET_DYN_BASE;
} else {
/* The most common default formula is TASK_SIZE / 3 * 2. */
elf_et_dyn_base = TARGET_PAGE_ALIGN(reserved_va / 3) * 2;
}
} else if (ELF_ET_DYN_BASE < UINTPTR_MAX) {
elf_et_dyn_base = ELF_ET_DYN_BASE;
} else {
/* 32-bit host: pick something medium size. */
elf_et_dyn_base = 0x18000000;
}

#pragma GCC diagnostic pop

{
Expand Down
3 changes: 3 additions & 0 deletions linux-user/microblaze/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
*/
#define TASK_UNMAPPED_BASE 0x48000000

/* arch/microblaze/include/uapi/asm/elf.h */
#define ELF_ET_DYN_BASE 0x08000000

#include "../generic/target_mman.h"
3 changes: 3 additions & 0 deletions linux-user/mips/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#define TASK_UNMAPPED_BASE \
TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3)

/* arch/mips/include/asm/elf.h */
#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2)

#include "../generic/target_mman.h"

#endif
1 change: 1 addition & 0 deletions linux-user/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last,

abi_ulong task_unmapped_base;
abi_ulong mmap_next_start;
abi_ulong elf_et_dyn_base;

/*
* Subroutine of mmap_find_vma, used when we have pre-allocated
Expand Down
3 changes: 3 additions & 0 deletions linux-user/nios2/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
*/
#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3)

/* arch/nios2/include/asm/elf.h */
#define ELF_ET_DYN_BASE 0xD0000000

#include "../generic/target_mman.h"
3 changes: 3 additions & 0 deletions linux-user/openrisc/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
*/
#define TASK_UNMAPPED_BASE 0x30000000

/* arch/openrisc/include/asm/elf.h */
#define ELF_ET_DYN_BASE 0x08000000

#include "../generic/target_mman.h"
7 changes: 7 additions & 0 deletions linux-user/ppc/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
#define TASK_UNMAPPED_BASE 0x40000000
#endif

/* arch/powerpc/include/asm/elf.h */
#ifdef TARGET_PPC64
#define ELF_ET_DYN_BASE 0x100000000ull
#else
#define ELF_ET_DYN_BASE 0x000400000
#endif

#include "../generic/target_mman.h"

#endif
3 changes: 3 additions & 0 deletions linux-user/riscv/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
#define TASK_UNMAPPED_BASE \
TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3)

/* arch/riscv/include/asm/elf.h */
#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2)

#include "../generic/target_mman.h"
10 changes: 10 additions & 0 deletions linux-user/s390x/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@
*/
#define TASK_UNMAPPED_BASE (1ull << 41)

/*
* arch/s390/include/asm/elf.h:
* ELF_ET_DYN_BASE (STACK_TOP / 3 * 2) & ~((1UL << 32) - 1)
*
* arch/s390/include/asm/processor.h:
* STACK_TOP VDSO_LIMIT - VDSO_SIZE - PAGE_SIZE
* VDSO_LIMIT _REGION2_SIZE
*/
#define ELF_ET_DYN_BASE (((1ull << 42) / 3 * 2) & ~0xffffffffull)

#include "../generic/target_mman.h"
3 changes: 3 additions & 0 deletions linux-user/sh4/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
#define TASK_UNMAPPED_BASE \
TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3)

/* arch/sh/include/asm/elf.h */
#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2)

#include "../generic/target_mman.h"
11 changes: 11 additions & 0 deletions linux-user/sparc/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
#define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2))
#endif

/*
* arch/sparc/include/asm/elf_64.h
* Except that COMPAT_ELF_ET_DYN_BASE exactly matches TASK_UNMAPPED_BASE,
* so move it up a bit.
*/
#ifdef TARGET_ABI32
#define ELF_ET_DYN_BASE 0x78000000
#else
#define ELF_ET_DYN_BASE 0x0000010000000000ull
#endif

#include "../generic/target_mman.h"

#endif
1 change: 1 addition & 0 deletions linux-user/user-mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

extern abi_ulong task_unmapped_base;
extern abi_ulong mmap_next_start;
extern abi_ulong elf_et_dyn_base;

int target_mprotect(abi_ulong start, abi_ulong len, int prot);
abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
Expand Down
3 changes: 3 additions & 0 deletions linux-user/x86_64/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
#define TASK_UNMAPPED_BASE \
TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3)

/* arch/x86/include/asm/elf.h */
#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2)

#include "../generic/target_mman.h"
4 changes: 4 additions & 0 deletions linux-user/xtensa/target_mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*/
#define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1))

/* arch/xtensa/include/asm/elf.h */
#define ELF_ET_DYN_BASE \
TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3)

#include "../generic/target_mman.h"

#endif

0 comments on commit cff7f7c

Please sign in to comment.