[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] linux-user: Add an argument QEMU_MMAP_BASE to set custom mma
From: |
Lirong Yuan |
Subject: |
Re: [PATCH] linux-user: Add an argument QEMU_MMAP_BASE to set custom mmap base address in qemu user mode |
Date: |
Fri, 28 Feb 2020 16:43:24 -0800 |
On Fri, Feb 21, 2020 at 5:09 PM Lirong Yuan <address@hidden> wrote:
>
> This change allows us to set custom base address for guest programs. It is
> needed to allow qemu to work with Thread Sanitizer (TSan), which has specific
> boundary definitions for memory mappings on different platforms:
> https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/tsan_platform.h
>
> Signed-off-by: Lirong Yuan <address@hidden>
> ---
> linux-user/main.c | 12 ++++++++++++
> linux-user/mmap.c | 3 ++-
> linux-user/qemu.h | 5 +++++
> 3 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/linux-user/main.c b/linux-user/main.c
> index fba833aac9..c01af6bfee 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -336,6 +336,16 @@ static void handle_arg_guest_base(const char *arg)
> have_guest_base = 1;
> }
>
> +static void handle_arg_mmap_base(const char *arg)
> +{
> + int err = qemu_strtoul(arg, NULL, 0, &mmap_base);
> + if (err) {
> + fprintf(stderr, "Invalid mmap_base: %s, err: %d\n", arg, err);
> + exit(EXIT_FAILURE);
> + }
> + mmap_next_start = mmap_base;
> +}
> +
> static void handle_arg_reserved_va(const char *arg)
> {
> char *p;
> @@ -440,6 +450,8 @@ static const struct qemu_argument arg_table[] = {
> "uname", "set qemu uname release string to 'uname'"},
> {"B", "QEMU_GUEST_BASE", true, handle_arg_guest_base,
> "address", "set guest_base address to 'address'"},
> + {"mmap_base", "QEMU_MMAP_BASE", true, handle_arg_mmap_base,
> + "", "begin allocating guest pages at this host address"},
> {"R", "QEMU_RESERVED_VA", true, handle_arg_reserved_va,
> "size", "reserve 'size' bytes for guest virtual address space"},
> {"d", "QEMU_LOG", true, handle_arg_log,
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index 8685f02e7e..3f35543acf 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -189,6 +189,7 @@ static int mmap_frag(abi_ulong real_start,
> # define TASK_UNMAPPED_BASE 0x40000000
> #endif
> abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
> +abi_ulong mmap_base = TASK_UNMAPPED_BASE;
>
> unsigned long last_brk;
>
> @@ -299,7 +300,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size,
> abi_ulong align)
>
> if ((addr & (align - 1)) == 0) {
> /* Success. */
> - if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) {
> + if (start == mmap_next_start && addr >= mmap_base) {
> mmap_next_start = addr + size;
> }
> return addr;
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index 560a68090e..83c00cfea2 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -161,6 +161,11 @@ void task_settid(TaskState *);
> void stop_all_tasks(void);
> extern const char *qemu_uname_release;
> extern unsigned long mmap_min_addr;
> +/*
> + * mmap_base is minimum address to use when allocating guest pages. All guest
> + * pages will be allocated at this (guest) address or higher addresses.
> + */
> +extern abi_ulong mmap_base;
>
> /* ??? See if we can avoid exposing so much of the loader internals. */
>
> --
> 2.25.0.265.gbab2e86ba0-goog
>
Friendly ping~
Link to the page for the patch on patchwork:
http://patchwork.ozlabs.org/patch/1242370/