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>
This commit is contained in:
parent
8d4a6f8e4c
commit
a56ef5e845
4 changed files with 49 additions and 49 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue