[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/10] linux-user: make binfmt flag O require P
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PATCH 03/10] linux-user: make binfmt flag O require P |
Date: |
Tue, 12 Aug 2014 16:42:13 +0300 |
From: Joakim Tjernlund <address@hidden>
QEMU can autodetect if it is started from Linux binfmt loader
when binfmt flag O is on.
Use that and require binfmt flag P as well which will enable QEMU
to pass in correct argv0 to the application.
Signed-off-by: Joakim Tjernlund <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/main.c | 19 +++++++++++++++----
scripts/qemu-binfmt-conf.sh | 36 ++++++++++++++++++------------------
2 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/linux-user/main.c b/linux-user/main.c
index b453a39..c5878f9 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3751,7 +3751,7 @@ static void usage(void)
exit(1);
}
-static int parse_args(int argc, char **argv)
+static int parse_args(int argc, char **argv, int assume_P_flag)
{
const char *r;
int optind;
@@ -3767,7 +3767,18 @@ static int parse_args(int argc, char **argv)
arginfo->handle_opt(r);
}
}
-
+ if (assume_P_flag) {
+ /* Assume started by binmisc and binfmt P flag is set */
+ if (argc < 3) {
+ fprintf(stderr, "%s: Please use me through binfmt with P flag\n",
+ argv[0]);
+ exit(1);
+ }
+ filename = argv[1];
+ exec_path = argv[1];
+ /* Next argv must be argv0 for the app */
+ return 2;
+ }
optind = 1;
for (;;) {
if (optind >= argc) {
@@ -3858,7 +3869,8 @@ int main(int argc, char **argv, char **envp)
cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
#endif
- optind = parse_args(argc, argv);
+ execfd = qemu_getauxval(AT_EXECFD);
+ optind = parse_args(argc, argv, execfd > 0);
/* Zero out regs */
memset(regs, 0, sizeof(struct target_pt_regs));
@@ -4004,7 +4016,6 @@ int main(int argc, char **argv, char **envp)
cpu->opaque = ts;
task_settid(ts);
- execfd = qemu_getauxval(AT_EXECFD);
if (execfd == 0) {
execfd = open(filename, O_RDONLY);
if (execfd < 0) {
diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh
index 289b1a3..36fcb8f 100644
--- a/scripts/qemu-binfmt-conf.sh
+++ b/scripts/qemu-binfmt-conf.sh
@@ -31,42 +31,42 @@ esac
# register the interpreter for each cpu except for the native one
if [ $cpu != "i386" ] ; then
- echo
':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:'
> /proc/sys/fs/binfmt_misc/register
- echo
':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:PO'
> /proc/sys/fs/binfmt_misc/register
+ echo
':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-i386:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "alpha" ] ; then
- echo
':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-alpha:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-alpha:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "arm" ] ; then
- echo
':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:'
> /proc/sys/fs/binfmt_misc/register
- echo
':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-armeb:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:PO'
> /proc/sys/fs/binfmt_misc/register
+ echo
':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-armeb:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "aarch64" ] ; then
- echo
':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-aarch64:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-aarch64:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "sparc" ] ; then
- echo
':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sparc:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sparc:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "ppc" ] ; then
- echo
':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "m68k" ] ; then
echo 'Please check cpu value and header information for m68k!'
- echo
':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-m68k:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-m68k:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "mips" ] ; then
# FIXME: We could use the other endianness on a MIPS host.
- echo
':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips:'
> /proc/sys/fs/binfmt_misc/register
- echo
':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsel:'
> /proc/sys/fs/binfmt_misc/register
- echo
':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mipsn32:'
> /proc/sys/fs/binfmt_misc/register
- echo
':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsn32el:'
> /proc/sys/fs/binfmt_misc/register
- echo
':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips64:'
> /proc/sys/fs/binfmt_misc/register
- echo
':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips:PO'
> /proc/sys/fs/binfmt_misc/register
+ echo
':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsel:PO'
> /proc/sys/fs/binfmt_misc/register
+ echo
':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mipsn32:PO'
> /proc/sys/fs/binfmt_misc/register
+ echo
':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mipsn32el:PO'
> /proc/sys/fs/binfmt_misc/register
+ echo
':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips64:PO'
> /proc/sys/fs/binfmt_misc/register
+ echo
':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "sh" ] ; then
- echo
':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-sh4:'
> /proc/sys/fs/binfmt_misc/register
- echo
':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sh4eb:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-sh4:PO'
> /proc/sys/fs/binfmt_misc/register
+ echo
':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-sh4eb:PO'
> /proc/sys/fs/binfmt_misc/register
fi
if [ $cpu != "s390x" ] ; then
- echo
':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-s390x:'
> /proc/sys/fs/binfmt_misc/register
+ echo
':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-s390x:PO'
> /proc/sys/fs/binfmt_misc/register
fi
--
2.0.1
- [Qemu-devel] [PATCH 00/10] linux-user update, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 01/10] linux-user: /proc/self/maps content, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 06/10] linux-user: fix readlink handling with magic exe symlink, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 09/10] linux-user: support {name_to, open_by}_handle_at syscalls, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 10/10] linux-user: add setns and unshare, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 03/10] linux-user: make binfmt flag O require P,
riku . voipio <=
- [Qemu-devel] [PATCH 05/10] linux-user: Fix conversion of sigevent argument to timer_create, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 08/10] linux-user: support ioprio_{get, set} syscalls, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 07/10] linux-user: support timerfd_{create, gettime, settime} syscalls, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 04/10] linux-user: Fix syscall instruction usermode emulation on X86_64, riku . voipio, 2014/08/12
- [Qemu-devel] [PATCH 02/10] linux-user: redirect openat calls, riku . voipio, 2014/08/12