aboutsummaryrefslogtreecommitdiff
path: root/linux-user
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2025-07-29 09:11:12 -1000
committerRichard Henderson <richard.henderson@linaro.org>2025-08-30 07:04:04 +1000
commita56ef5e8454e42c0d263a97a1297ae67f4ce19cd (patch)
treee63579b2fa0772cb9d4bd9a6f2b93d5488de1ceb /linux-user
parent8d4a6f8e4c95e11a3da2e38682da2819d4e2160c (diff)
downloadqemu-a56ef5e8454e42c0d263a97a1297ae67f4ce19cd.zip
qemu-a56ef5e8454e42c0d263a97a1297ae67f4ce19cd.tar.gz
qemu-a56ef5e8454e42c0d263a97a1297ae67f4ce19cd.tar.bz2
linux-user: Move init_guest_commpage to arm/elfload.c
Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'linux-user')
-rw-r--r--linux-user/arm/elfload.c46
-rw-r--r--linux-user/arm/target_elf.h2
-rw-r--r--linux-user/elfload.c48
-rw-r--r--linux-user/loader.h2
4 files changed, 49 insertions, 49 deletions
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index f811c2f..1205687 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -3,6 +3,8 @@
#include "qemu/osdep.h"
#include "qemu.h"
#include "loader.h"
+#include "user-internals.h"
+#include "target_elf.h"
#include "target/arm/cpu-features.h"
#include "target_elf.h"
@@ -201,6 +203,50 @@ const char *get_elf_platform(CPUState *cs)
#undef END
}
+bool init_guest_commpage(void)
+{
+ ARMCPU *cpu = ARM_CPU(thread_cpu);
+ int host_page_size = qemu_real_host_page_size();
+ abi_ptr commpage;
+ void *want;
+ void *addr;
+
+ /*
+ * M-profile allocates maximum of 2GB address space, so can never
+ * allocate the commpage. Skip it.
+ */
+ if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
+ return true;
+ }
+
+ commpage = HI_COMMPAGE & -host_page_size;
+ want = g2h_untagged(commpage);
+ addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE |
+ (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE),
+ -1, 0);
+
+ if (addr == MAP_FAILED) {
+ perror("Allocating guest commpage");
+ exit(EXIT_FAILURE);
+ }
+ if (addr != want) {
+ return false;
+ }
+
+ /* Set kernel helper versions; rest of page is 0. */
+ __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu));
+
+ if (mprotect(addr, host_page_size, PROT_READ)) {
+ perror("Protecting guest commpage");
+ exit(EXIT_FAILURE);
+ }
+
+ page_set_flags(commpage, commpage | (host_page_size - 1),
+ PAGE_READ | PAGE_EXEC | PAGE_VALID);
+ return true;
+}
+
void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env)
{
for (int i = 0; i < 16; ++i) {
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index fa8f8af..5f81a43 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -15,6 +15,8 @@
#define HAVE_ELF_PLATFORM 1
#define HAVE_ELF_CORE_DUMP 1
+#define HI_COMMPAGE ((intptr_t)0xffff0f00u)
+
/*
* See linux kernel: arch/arm/include/asm/elf.h, where
* elf_gregset_t is mapped to struct pt_regs via sizeof.
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0ba75a8..2281853 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -191,54 +191,6 @@ typedef abi_int target_pid_t;
#define ELF_EXEC_PAGESIZE 4096
-/* The commpage only exists for 32 bit kernels */
-
-#define HI_COMMPAGE (intptr_t)0xffff0f00u
-
-static bool init_guest_commpage(void)
-{
- ARMCPU *cpu = ARM_CPU(thread_cpu);
- int host_page_size = qemu_real_host_page_size();
- abi_ptr commpage;
- void *want;
- void *addr;
-
- /*
- * M-profile allocates maximum of 2GB address space, so can never
- * allocate the commpage. Skip it.
- */
- if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
- return true;
- }
-
- commpage = HI_COMMPAGE & -host_page_size;
- want = g2h_untagged(commpage);
- addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE |
- (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE),
- -1, 0);
-
- if (addr == MAP_FAILED) {
- perror("Allocating guest commpage");
- exit(EXIT_FAILURE);
- }
- if (addr != want) {
- return false;
- }
-
- /* Set kernel helper versions; rest of page is 0. */
- __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu));
-
- if (mprotect(addr, host_page_size, PROT_READ)) {
- perror("Protecting guest commpage");
- exit(EXIT_FAILURE);
- }
-
- page_set_flags(commpage, commpage | (host_page_size - 1),
- PAGE_READ | PAGE_EXEC | PAGE_VALID);
- return true;
-}
-
#if TARGET_BIG_ENDIAN
#include "elf.h"
#include "vdso-be8.c.inc"
diff --git a/linux-user/loader.h b/linux-user/loader.h
index 98015fb..0c2cc55 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -105,7 +105,7 @@ const char *elf_hwcap_str(uint32_t bit);
const char *elf_hwcap2_str(uint32_t bit);
const char *get_elf_platform(CPUState *cs);
const char *get_elf_base_platform(CPUState *cs);
-#if defined(TARGET_X86_64)
+#if defined(TARGET_X86_64) || defined(TARGET_ARM)
bool init_guest_commpage(void);
#endif