qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

linux-user/FLAT: allow targets to override FLAT processing

This brings flatload.c more in line with the current Linux FLAT loader
which allows targets to handle various FLAT aspects in their own way.
For the common behavior, the new functions get stubbed out.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Riku Voipio <riku.voipio@nokia.com>

authored by

Mike Frysinger and committed by
Riku Voipio
c3109ba1 82a39595

+22 -17
+1 -1
Makefile.target
··· 107 107 108 108 $(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)) 109 109 110 - QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) 110 + QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) -I$(SRC_PATH)/linux-user 111 111 obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \ 112 112 elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \ 113 113 qemu-malloc.o $(oslib-obj-y)
+11 -16
linux-user/flatload.c
··· 41 41 42 42 #include "qemu.h" 43 43 #include "flat.h" 44 + #define ntohl(x) be32_to_cpu(x) 45 + #include <target_flat.h> 44 46 45 47 //#define DEBUG 46 48 ··· 48 50 #define DBG_FLT(...) printf(__VA_ARGS__) 49 51 #else 50 52 #define DBG_FLT(...) 51 - #endif 52 - 53 - #define flat_reloc_valid(reloc, size) ((reloc) <= (size)) 54 - #define flat_old_ram_flag(flag) (flag) 55 - #ifdef TARGET_WORDS_BIGENDIAN 56 - #define flat_get_relocate_addr(relval) (relval) 57 - #else 58 - #define flat_get_relocate_addr(relval) bswap32(relval) 59 53 #endif 60 54 61 55 #define RELOC_FAILED 0xff00ff01 /* Relocation incorrect somewhere */ ··· 77 71 #endif 78 72 79 73 struct linux_binprm; 80 - 81 - #define ntohl(x) be32_to_cpu(x) 82 74 83 75 /****************************************************************************/ 84 76 /* ··· 625 617 * __start to address 4 so that is okay). 626 618 */ 627 619 if (rev > OLD_FLAT_VERSION) { 620 + abi_ulong persistent = 0; 628 621 for (i = 0; i < relocs; i++) { 629 622 abi_ulong addr, relval; 630 623 ··· 633 626 relocated first). */ 634 627 if (get_user_ual(relval, reloc + i * sizeof(abi_ulong))) 635 628 return -EFAULT; 629 + relval = ntohl(relval); 630 + if (flat_set_persistent(relval, &persistent)) 631 + continue; 636 632 addr = flat_get_relocate_addr(relval); 637 633 rp = calc_reloc(addr, libinfo, id, 1); 638 634 if (rp == RELOC_FAILED) ··· 641 637 /* Get the pointer's value. */ 642 638 if (get_user_ual(addr, rp)) 643 639 return -EFAULT; 640 + addr = flat_get_addr_from_rp(rp, relval, flags, &persistent); 644 641 if (addr != 0) { 645 642 /* 646 643 * Do the relocation. PIC relocs in the data section are 647 644 * already in target order 648 645 */ 649 - 650 - #ifndef TARGET_WORDS_BIGENDIAN 651 646 if ((flags & FLAT_FLAG_GOTPIC) == 0) 652 - addr = bswap32(addr); 653 - #endif 647 + addr = ntohl(addr); 654 648 addr = calc_reloc(addr, libinfo, id, 0); 655 649 if (addr == RELOC_FAILED) 656 650 return -ENOEXEC; 657 651 658 652 /* Write back the relocated pointer. */ 659 - if (put_user_ual(addr, rp)) 653 + if (flat_put_addr_at_rp(rp, addr, relval)) 660 654 return -EFAULT; 661 655 } 662 656 } ··· 782 776 stack_len *= sizeof(abi_ulong); 783 777 if ((sp + stack_len) & 15) 784 778 sp -= 16 - ((sp + stack_len) & 15); 785 - sp = loader_build_argptr(bprm->envc, bprm->argc, sp, p, 1); 779 + sp = loader_build_argptr(bprm->envc, bprm->argc, sp, p, 780 + flat_argvp_envp_on_stack()); 786 781 787 782 /* Fake some return addresses to ensure the call chain will 788 783 * initialise library in order for us. We are required to call
+10
linux-user/target_flat.h
··· 1 + /* If your arch needs to do custom stuff, create your own target_flat.h 2 + * header file in linux-user/<your arch>/ 3 + */ 4 + #define flat_argvp_envp_on_stack() 1 5 + #define flat_reloc_valid(reloc, size) ((reloc) <= (size)) 6 + #define flat_old_ram_flag(flag) (flag) 7 + #define flat_get_relocate_addr(relval) (relval) 8 + #define flat_get_addr_from_rp(rp, relval, flags, persistent) (rp) 9 + #define flat_set_persistent(relval, persistent) (*persistent) 10 + #define flat_put_addr_at_rp(rp, addr, relval) put_user_ual(addr, rp)