4141
4242#include "qemu.h"
4343#include "flat.h"
44+ #define ntohl (x ) be32_to_cpu(x)
45+ #include <target_flat.h>
4446
4547//#define DEBUG
4648
5052#define DBG_FLT (...)
5153#endif
5254
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- #endif
60-
6155#define RELOC_FAILED 0xff00ff01 /* Relocation incorrect somewhere */
6256#define UNLOADED_LIB 0x7ff000ff /* Placeholder for unused library */
6357
@@ -78,8 +72,6 @@ static int load_flat_shared_library(int id, struct lib_info *p);
7872
7973struct linux_binprm ;
8074
81- #define ntohl (x ) be32_to_cpu(x)
82-
8375/****************************************************************************/
8476/*
8577 * create_flat_tables() parses the env- and arg-strings in new user
@@ -625,6 +617,7 @@ static int load_flat_file(struct linux_binprm * bprm,
625617 * __start to address 4 so that is okay).
626618 */
627619 if (rev > OLD_FLAT_VERSION ) {
620+ abi_ulong persistent = 0 ;
628621 for (i = 0 ; i < relocs ; i ++ ) {
629622 abi_ulong addr , relval ;
630623
@@ -633,6 +626,9 @@ static int load_flat_file(struct linux_binprm * bprm,
633626 relocated first). */
634627 if (get_user_ual (relval , reloc + i * sizeof (abi_ulong )))
635628 return - EFAULT ;
629+ relval = ntohl (relval );
630+ if (flat_set_persistent (relval , & persistent ))
631+ continue ;
636632 addr = flat_get_relocate_addr (relval );
637633 rp = calc_reloc (addr , libinfo , id , 1 );
638634 if (rp == RELOC_FAILED )
@@ -641,22 +637,20 @@ static int load_flat_file(struct linux_binprm * bprm,
641637 /* Get the pointer's value. */
642638 if (get_user_ual (addr , rp ))
643639 return - EFAULT ;
640+ addr = flat_get_addr_from_rp (rp , relval , flags , & persistent );
644641 if (addr != 0 ) {
645642 /*
646643 * Do the relocation. PIC relocs in the data section are
647644 * already in target order
648645 */
649-
650- #ifndef TARGET_WORDS_BIGENDIAN
651646 if ((flags & FLAT_FLAG_GOTPIC ) == 0 )
652- addr = bswap32 (addr );
653- #endif
647+ addr = ntohl (addr );
654648 addr = calc_reloc (addr , libinfo , id , 0 );
655649 if (addr == RELOC_FAILED )
656650 return - ENOEXEC ;
657651
658652 /* Write back the relocated pointer. */
659- if (put_user_ual ( addr , rp ))
653+ if (flat_put_addr_at_rp ( rp , addr , relval ))
660654 return - EFAULT ;
661655 }
662656 }
@@ -782,7 +776,8 @@ int load_flt_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
782776 stack_len *= sizeof (abi_ulong );
783777 if ((sp + stack_len ) & 15 )
784778 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 ());
786781
787782 /* Fake some return addresses to ensure the call chain will
788783 * initialise library in order for us. We are required to call
0 commit comments