Skip to contentSkip to conversation

How to trigger a binary to excute in Linux/MIPS?

DISCUSSION kjlin 2 participants 2 messages Jun 15, 2001 MIPS

lore
Share & tools
lore

kjlin

author
#0 lore raw

Hi,

To execute a program, the load_elf_binary() loads it and descdes the value of elf_entry, start_code, start_data....etc.. Then , the start_thread(regs, elf_entry, bprm->p) will trigger it.
But it just sets up the value of regs->cp0_status, regs->cp0_epc, regs->regs[29] and current->thread.current_ds. Why can the start_thread() trigger a program?

Here is my situation :
The kernel boots up and mounts the filesystem, when it tries to execute /sbin/hello i don't see any output.
(Ps: /sbin/hello is a simple testing program to replace the real /sbin/init.
It just outputs some console message.)
I looked at the memory and the code for hello is present at "elf_entry", so why does the start_thread not execute it ??

Any help would be really appreciated.

Thanks,
KJ

#1 lore raw
Quoted 8 lines · you

Hi,

To execute a program, the load_elf_binary() loads it and descdes the value of elf_entry, start_code, start_data....etc.. Then , the start_thread(regs, elf_entry, bprm->p) will trigger it.
But it just sets up the value of regs->cp0_status, regs->cp0_epc, regs->regs[29] and current->thread.current_ds. Why can the start_thread() trigger a program?

It does trigger a program, just not in the way you're thinking.

At that point, you're in kernel space, with kernel privileges, so you can't just jump to the entry point of the elf binary; you have to drop privs first.

What you're probably missing is that, when the kernel returns to userspace, it does so (in mips) via an eret, which returns to the epc. The registers are restored from the regs struct that is being modified by start_thread, so it is effectively modifying the registers for userspace, which is what it should be doing.

In short, you're not going to see the new process, in your case, /sbin/hello, start executing until the syscall returns. Check out arch/mips/kernel/entry.S:ret_from_sys_call to see where this happens. You'll also want to check out include/asm-mips/stackframe.h

Does this make sense?

-Justin