Skip to content

Commit c3109ba

Browse files
vapierRiku Voipio
authored and
Riku Voipio
committed
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 <[email protected]> Signed-off-by: Riku Voipio <[email protected]>
1 parent 82a3959 commit c3109ba

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

Makefile.target

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ ifdef CONFIG_LINUX_USER
107107

108108
$(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR))
109109

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
111111
obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
112112
elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \
113113
qemu-malloc.o $(oslib-obj-y)

linux-user/flatload.c

+11-16
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
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

@@ -50,14 +52,6 @@
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

7973
struct 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

linux-user/target_flat.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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)

0 commit comments

Comments
 (0)