From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XH6Xa-00010l-KY for qemu-devel@nongnu.org; Tue, 12 Aug 2014 03:30:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XH6XX-0001CJ-SR for qemu-devel@nongnu.org; Tue, 12 Aug 2014 03:30:42 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=42103 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XH6XX-0001Bf-K9 for qemu-devel@nongnu.org; Tue, 12 Aug 2014 03:30:39 -0400 Date: Tue, 12 Aug 2014 10:30:38 +0300 From: Riku Voipio Message-ID: <20140812073038.GB5555@afflict.kos.to> References: <1405432019-11273-1-git-send-email-Joakim.Tjernlund@transmode.se> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] linux-user: make binfmt flag O require P List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Joakim Tjernlund Cc: Alexander Graf , Riku Voipio , qemu-devel@nongnu.org, Andreas =?utf-8?Q?F=C3=A4rber?= Hi, On Mon, Aug 11, 2014 at 06:54:59PM +0200, Joakim Tjernlund wrote: > I do not see this one in master yet. Is there any problem with the pat= ch? It's included in the next pull request: https://git.linaro.org/people/riku.voipio/qemu.git/shortlog/refs/heads/li= nux-user-for-upstream It will be in master soon. Riku > -----Joakim Tjernlund wrote: ----- >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > To: Riku Voipio , Andreas F=C3=A4rber , Alexander Graf , qemu-devel@nongnu.org > From: Joakim Tjernlund > Date: 15/07/2014 15:47=20 > Cc: Joakim Tjernlund > Subject: [PATCH v2] linux-user: make binfmt flag O require P > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > 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. >=20 > Signed-off-by: Joakim Tjernlund > --- >=20 > v2 - This one actually works and does not abuse argv0 > variable. > linux-user/main.c | 19 +++++++++++++++---- > scripts/qemu-binfmt-conf.sh | 36 ++++++++++++++++++------------------ > 2 files changed, 33 insertions(+), 22 deletions(-) >=20 > diff --git a/linux-user/main.c b/linux-user/main.c > index 71a33c7..3767233 100644 > --- a/linux-user/main.c > +++ b/linux-user/main.c > @@ -3750,7 +3750,7 @@ static void usage(void) > exit(1); > } > =20 > -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; > @@ -3766,7 +3766,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 f= lag\n", > + argv[0]); > + exit(1); > + } > + filename =3D argv[1]; > + exec_path =3D argv[1]; > + /* Next argv must be argv0 for the app */ > + return 2; > + } > optind =3D 1; > for (;;) { > if (optind >=3D argc) { > @@ -3857,7 +3868,8 @@ int main(int argc, char **argv, char **envp) > cpudef_setup(); /* parse cpu definitions in target config file (TB= D) */ > #endif > =20 > - optind =3D parse_args(argc, argv); > + execfd =3D qemu_getauxval(AT_EXECFD); > + optind =3D parse_args(argc, argv, execfd > 0); > =20 > /* Zero out regs */ > memset(regs, 0, sizeof(struct target_pt_regs)); > @@ -4003,7 +4015,6 @@ int main(int argc, char **argv, char **envp) > cpu->opaque =3D ts; > task_settid(ts); > =20 > - execfd =3D qemu_getauxval(AT_EXECFD); > if (execfd =3D=3D 0) { > execfd =3D 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 > =20 > # register the interpreter for each cpu except for the native one > if [ $cpu !=3D "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/bi= nfmt_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/bi= nfmt_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 !=3D "alpha" ] ; then > - echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x0= 0\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xf= f\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\x0= 0\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xf= f\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-alpha:PO' > /proc/sys/f= s/binfmt_misc/register > fi > if [ $cpu !=3D "arm" ] ; then > - echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x0= 0\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xf= f\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:' > /proc/sys/fs/bi= nfmt_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/f= s/binfmt_misc/register > + echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x0= 0\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xf= f\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 !=3D "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/s= ys/fs/binfmt_misc/register > fi > if [ $cpu !=3D "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/f= s/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 !=3D "ppc" ] ; then > - echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x0= 0\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf= f\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:' > /proc/sys/fs/bi= nfmt_misc/register > + echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x0= 0\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf= f\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-ppc:PO' > /proc/sys/fs/= binfmt_misc/register > fi > if [ $cpu !=3D "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\x= 00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\x= ff\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\x= 00\x00\x00\x02\x00\x04:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\x= ff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-m68k:PO' > /proc/sys/f= s/binfmt_misc/register > fi > if [ $cpu !=3D "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\x= 00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\x= ff\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\x0= 0\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xf= f\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mipsn32:' > /proc/s= ys/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:' > /pr= oc/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\x= 00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\x= ff\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\x= 00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\x= ff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-mips:PO' > /proc/sys/f= s/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/s= ys/fs/binfmt_misc/register > + echo ':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x0= 0\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xf= f\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/s= ys/fs/binfmt_misc/register > + echo ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x= 00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\x= ff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-mips64el:PO' > /pr= oc/sys/fs/binfmt_misc/register > fi > if [ $cpu !=3D "sh" ] ; then > - echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x= 00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x= ff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-sh4:' > /proc/sys/fs/b= infmt_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\x= 00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x= ff\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/sy= s/fs/binfmt_misc/register > fi > if [ $cpu !=3D "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/f= s/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 > --=20 > 1.8.5.5 >=20 >=20