From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KojnV-0005vz-Qd for qemu-devel@nongnu.org; Sat, 11 Oct 2008 15:06:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KojnR-0005rH-VN for qemu-devel@nongnu.org; Sat, 11 Oct 2008 15:06:41 -0400 Received: from [199.232.76.173] (port=59372 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KojnR-0005r1-JQ for qemu-devel@nongnu.org; Sat, 11 Oct 2008 15:06:37 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:37669) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KojnQ-0003vC-PK for qemu-devel@nongnu.org; Sat, 11 Oct 2008 15:06:37 -0400 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 7918864E4B for ; Sat, 11 Oct 2008 19:06:30 +0000 (UTC) From: Mike Frysinger Date: Sat, 11 Oct 2008 15:06:29 -0400 Message-Id: <1223751989-10600-1-git-send-email-vapier@gentoo.org> Subject: [Qemu-devel] [PATCH] linux-user/FLAT: allow targets to override FLAT reloc processing Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This brings flatload.c more in line with the current Linux FLAT loader which allows targets to handle FLAT relocations in their own way. For the common behavior, the new functions get stubbed out. Signed-off-by: Mike Frysinger --- Note: i'd like to say these changes didn't break existing FLAT targets, but i'm unable to verify that since all the FLAT targets i tested are already broken (give me "reloc outside program" errors) ... i was able to verify that existing behavior seemed to be unchanged though (same # of relocs were processed with the same result). Makefile.target | 2 +- linux-user/flatload.c | 21 +++++++++------------ linux-user/target_flat.h | 9 +++++++++ 3 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 linux-user/target_flat.h diff --git a/Makefile.target b/Makefile.target index 0f0b7a0..6b9a52f 100644 --- a/Makefile.target +++ b/Makefile.target @@ -321,7 +321,7 @@ ifndef TARGET_ABI_DIR TARGET_ABI_DIR=$(TARGET_ARCH) endif VPATH+=:$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) -CPPFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) +CPPFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) -I$(SRC_PATH)/linux-user ifdef CONFIG_STATIC LDFLAGS+=-static diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 543afeb..e63feb4 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -42,6 +42,8 @@ #include "qemu.h" #include "flat.h" +#define ntohl(x) be32_to_cpu(x) +#include #define DEBUG @@ -51,14 +53,6 @@ #define DBG_FLT(a...) #endif -#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) -#define flat_old_ram_flag(flag) (flag) -#ifdef TARGET_WORDS_BIGENDIAN -#define flat_get_relocate_addr(relval) (relval) -#else -#define flat_get_relocate_addr(relval) bswap32(relval) -#endif - #define RELOC_FAILED 0xff00ff01 /* Relocation incorrect somewhere */ #define UNLOADED_LIB 0x7ff000ff /* Placeholder for unused library */ @@ -79,8 +73,6 @@ static int load_flat_shared_library(int id, struct lib_info *p); struct linux_binprm; -#define ntohl(x) be32_to_cpu(x) - /****************************************************************************/ /* * create_flat_tables() parses the env- and arg-strings in new user @@ -339,7 +331,7 @@ failed: void old_reloc(struct lib_info *libinfo, uint32_t rl) { #ifdef DEBUG - char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; + const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; #endif uint32_t *ptr; uint32_t offset; @@ -625,6 +617,7 @@ static int load_flat_file(struct linux_binprm * bprm, * __start to address 4 so that is okay). */ if (rev > OLD_FLAT_VERSION) { + abi_ulong persistent = 0; for (i = 0; i < relocs; i++) { abi_ulong addr, relval; @@ -633,6 +626,9 @@ static int load_flat_file(struct linux_binprm * bprm, relocated first). */ if (get_user_ual(relval, reloc + i * sizeof(abi_ulong))) return -EFAULT; + relval = ntohl(relval); + if (flat_set_persistent(relval, &persistent)) + continue; addr = flat_get_relocate_addr(relval); rp = calc_reloc(addr, libinfo, id, 1); if (rp == RELOC_FAILED) @@ -641,6 +637,7 @@ static int load_flat_file(struct linux_binprm * bprm, /* Get the pointer's value. */ if (get_user_ual(addr, rp)) return -EFAULT; + addr = flat_get_addr_from_rp(rp, relval, flags, &persistent); if (addr != 0) { /* * Do the relocation. PIC relocs in the data section are @@ -656,7 +653,7 @@ static int load_flat_file(struct linux_binprm * bprm, return -ENOEXEC; /* Write back the relocated pointer. */ - if (put_user_ual(addr, rp)) + if (flat_put_addr_at_rp(rp, addr, relval)) return -EFAULT; } } diff --git a/linux-user/target_flat.h b/linux-user/target_flat.h new file mode 100644 index 0000000..332b6e3 --- /dev/null +++ b/linux-user/target_flat.h @@ -0,0 +1,9 @@ +/* If your arch needs to do custom stuff, create your own target_flat.h + * header file in linux-user// + */ +#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) +#define flat_old_ram_flag(flag) (flag) +#define flat_get_relocate_addr(relval) (relval) +#define flat_get_addr_from_rp(rp, relval, flags, persistent) (rp) +#define flat_set_persistent(relval, persistent) (*persistent) +#define flat_put_addr_at_rp(rp, addr, relval) put_user_ual(addr, rp) -- 1.6.0.2