Thanks for your insightful input. I will come back to this thread after I tried all the options.
Cheers, Libo Zhou ------------------ Original ------------------ From: "Peter Maydell";<peter.mayd...@linaro.org>; Send time: Saturday, Sep 21, 2019 0:08 AM To: "Libo Zhou"<zhl...@foxmail.com>; Cc: "qemu-devel"<qemu-devel@nongnu.org>; Subject: Re: Initialize data memory in user space emulation On Fri, 20 Sep 2019 at 16:26, Libo Zhou <zhl...@foxmail.com> wrote: > > I actually thought about hacking it to mmap from file into guest memory > before running ELF. In include/exec/memory.h, the function > memory_region_init_ram_from_file sounds like what I need. But the entire > memory.h source file is wrapped by #ifndef CONFIG_USER_ONLY, I cannot use > that API in user space emulation, right? Correct, you don't want to use that. You want to put some code in linux-user/main.c, probably just after the call to signal_init(), which opens the host file and then calls target_mmap() to mmap it into the host. If you happen to have the source for the guest program, you could also just make it do the open and mmap() itself as the first thing it does in main() -- this is basically equivalent. Or if the guest program is dynamically linked then you can use QEMU's -E option to set the LD_PRELOAD environment variable for the guest to make it load a guest shared library that has a constructor function that does the open/mmap before the guest main() gets control. thanks -- PMM