[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v5 08/20] linux-user: Load vdso image if available
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH v5 08/20] linux-user: Load vdso image if available |
Date: |
Wed, 30 Aug 2023 16:22:02 +0200 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 |
Hi Richard,
On 30/8/23 00:02, Richard Henderson wrote:
The vdso image will be pre-processed into a C data array, with
a simple list of relocations to perform, and identifying the
location of signal trampolines.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/elfload.c | 87 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 78 insertions(+), 9 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f34fb64c0c..2a6adebb4a 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -33,6 +33,19 @@
#undef ELF_ARCH
#endif
+#ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE
+#define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0
I'd rather #error here so new targets are added with
a clearly defined TARGET_ARCH_HAS_SIGTRAMP_PAGE.
+#endif
+
+typedef struct {
+ const uint8_t *image;
+ const uint32_t *relocs;
+ unsigned image_size;
+ unsigned reloc_count;
+ unsigned sigreturn_ofs;
+ unsigned rt_sigreturn_ofs;
+} VdsoImageInfo;
+
#define ELF_OSABI ELFOSABI_SYSV
+#ifndef vdso_image_info
+#define vdso_image_info() NULL
+#endif
+
+static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso)
+{
+ ImageSource src;
+ struct elfhdr ehdr;
+ abi_ulong load_bias, load_addr;
+
+ src.fd = -1;
+ src.cache = vdso->image;
+ src.cache_size = vdso->image_size;
+
+ load_elf_image("<internal-vdso>", &src, info, &ehdr, NULL);
+ load_addr = info->load_addr;
+ load_bias = info->load_bias;
+
+ /*
+ * We need to relocate the VDSO image. The one built into the kernel
+ * is built for a fixed address. The one built for QEMU is not, since
+ * that requires close control of the guest address space.
+ * We pre-processed the image to locate all of the addresses that need
+ * to be updated.
+ */
+ for (unsigned i = 0, n = vdso->reloc_count; i < n; i++) {
Do we really need 'n'?
+ abi_ulong *addr = g2h_untagged(load_addr + vdso->relocs[i]);
+ *addr = tswapal(tswapal(*addr) + load_bias);
+ }
+
+ /* Install signal trampolines, if present. */
+ if (vdso->sigreturn_ofs) {
+ default_sigreturn = load_addr + vdso->sigreturn_ofs;
+ }
+ if (vdso->rt_sigreturn_ofs) {
+ default_rt_sigreturn = load_addr + vdso->rt_sigreturn_ofs;
+ }
+
+ /* Remove write from VDSO segment. */
+ target_mprotect(info->start_data, info->end_data - info->start_data,
+ PROT_READ | PROT_EXEC);
+}
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
- [PATCH v5 09/20] linux-user: Add gen-vdso tool, (continued)
- [PATCH v5 09/20] linux-user: Add gen-vdso tool, Richard Henderson, 2023/08/29
- [PATCH v5 10/20] linux-user: Add build-vdso.sh tool, Richard Henderson, 2023/08/29
- [PATCH v5 18/20] linux-user/ppc: Add vdso, Richard Henderson, 2023/08/29
- [PATCH v5 19/20] linux-user/s390x: Rename __SIGNAL_FRAMESIZE to STACK_FRAME_OVERHEAD, Richard Henderson, 2023/08/29
- [PATCH v5 20/20] linux-user/s390x: Add vdso, Richard Henderson, 2023/08/29
- [PATCH v5 02/20] linux-user: Introduce imgsrc_read, imgsrc_read_alloc, Richard Henderson, 2023/08/29
- [PATCH v5 05/20] linux-user: Use ImageSource in load_elf_image, Richard Henderson, 2023/08/29
- [PATCH v5 07/20] linux-user: Replace bprm->fd with bprm->src.fd, Richard Henderson, 2023/08/29
- [PATCH v5 08/20] linux-user: Load vdso image if available, Richard Henderson, 2023/08/29
- Re: [PATCH v5 08/20] linux-user: Load vdso image if available,
Philippe Mathieu-Daudé <=
[PATCH v5 12/20] linux-user/x86_64: Add vdso, Richard Henderson, 2023/08/29
[PATCH v5 15/20] linux-user/hppa: Add vdso, Richard Henderson, 2023/08/29
Re: [PATCH v5 00/20] linux-user: Implement VDSOs, Helge Deller, 2023/08/30