All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Andrew Jones <drjones@redhat.com>, kvm@vger.kernel.org
Cc: lvivier@redhat.com, rkrcmar@redhat.com
Subject: Re: [kvm-unit-tests PATCH v2 3/4] arm/arm64: populate argv[0] with prognam
Date: Fri, 22 Apr 2016 19:48:28 +0200	[thread overview]
Message-ID: <571A63EC.6020303@redhat.com> (raw)
In-Reply-To: <1461336889-27472-4-git-send-email-drjones@redhat.com>

On 22.04.2016 16:54, Andrew Jones wrote:
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  arm/Makefile.common |  6 +++++-
>  lib/argv.c          | 25 +++++++++++++++++++++----
>  lib/auxinfo.h       |  7 +++++++
>  scripts/auxinfo.mak |  7 +++++++
>  4 files changed, 40 insertions(+), 5 deletions(-)
>  create mode 100644 lib/auxinfo.h
>  create mode 100755 scripts/auxinfo.mak
> 
> diff --git a/arm/Makefile.common b/arm/Makefile.common
> index 9a2d61fc88a27..6b87a48b0066b 100644
> --- a/arm/Makefile.common
> +++ b/arm/Makefile.common
> @@ -26,6 +26,7 @@ CFLAGS += -I lib -I lib/libfdt
>  
>  asm-offsets = lib/$(ARCH)/asm-offsets.h
>  include scripts/asm-offsets.mak
> +include scripts/auxinfo.mak
>  
>  cflatobjs += lib/util.o
>  cflatobjs += lib/alloc.o
> @@ -49,9 +50,12 @@ start_addr := $(shell printf "%x\n" $$(( $(phys_base) + $(kernel_offset) )))
>  FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
>  %.elf: LDFLAGS = $(CFLAGS) -nostdlib
>  %.elf: %.o $(FLATLIBS) arm/flat.lds
> +	$(call gen-auxinfo,$(@:.elf=.aux.c),$(@:.elf=.flat))
> +	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(@:.elf=.aux.c)
>  	$(CC) $(LDFLAGS) -o $@ \
>  		-Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \
> -		$(filter %.o, $^) $(FLATLIBS)
> +		$(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o)
> +	$(RM) $(@:.elf=.aux).*
>  
>  %.flat: %.elf
>  	$(OBJCOPY) -O binary $^ $@
> diff --git a/lib/argv.c b/lib/argv.c
> index c6ad5fcbc8cf4..66cd43f24d336 100644
> --- a/lib/argv.c
> +++ b/lib/argv.c
> @@ -1,4 +1,7 @@
>  #include "libcflat.h"
> +#include "auxinfo.h"
> +
> +static char *copy_ptr;
>  
>  int __argc;
>  char *__argv[100];
> @@ -21,26 +24,40 @@ void __setup_args(void)
>  {
>      char *args = __args;
>      char **argv = __argv;
> -    char *p = __args_copy;
> +
> +    copy_ptr = __args_copy;
>  
>      while (*(args = skip_blanks(args)) != '\0') {
> -        *argv++ = p;
> +        *argv++ = copy_ptr;
>          while (*args != '\0' && !isblank(*args))
> -            *p++ = *args++;
> -        *p++ = '\0';
> +            *copy_ptr++ = *args++;
> +        *copy_ptr++ = '\0';
>      }
>      __argc = argv - __argv;
>  }
>  
>  void setup_args(char *args)
>  {
> +#if defined(__arm__) || defined(__aarch64__)
> +    const char *p;
> +#endif
> +
>      if (args) {
>          __args = args;
>          __setup_args();
>  
>          for (int i = __argc; i > 0; --i)
>              __argv[i] = __argv[i-1];
> +    } else {
> +        copy_ptr = __args_copy;
>      }
> +#if defined(__arm__) || defined(__aarch64__)
> +    __argv[0] = copy_ptr;
> +    p = auxinfo.prognam;
> +    while ((*copy_ptr++ = *p++) != 0)
> +        ;

Could you also use strcpy() here? Or do you still need the updated
copy_ptr afterwards?

> +#else
>      __argv[0] = NULL; //HACK: just reserve argv[0] for now
> +#endif
>      ++__argc;
>  }
> diff --git a/lib/auxinfo.h b/lib/auxinfo.h
> new file mode 100644
> index 0000000000000..fc2d736aa63b1
> --- /dev/null
> +++ b/lib/auxinfo.h
> @@ -0,0 +1,7 @@
> +#ifndef _AUXINFO_H_
> +#define _AUXINFO_H_
> +struct auxinfo {
> +	const char *prognam;
> +};
> +extern struct auxinfo auxinfo;
> +#endif
> diff --git a/scripts/auxinfo.mak b/scripts/auxinfo.mak
> new file mode 100755
> index 0000000000000..dbb588e89fc6f
> --- /dev/null
> +++ b/scripts/auxinfo.mak
> @@ -0,0 +1,7 @@
> +
> +define gen-auxinfo
> +	(echo "#include <auxinfo.h>";		\
> +	 echo "struct auxinfo auxinfo = {";	\
> +	 echo "    .prognam = \"$(2)\",";	\
> +	 echo "};" ) > $(1)
> +endef

Looks sane. Not sure, whether it really makes sense to provide the name
to the unit test, but hey, why not?

Reviewed-by: Thomas Huth <thuth@redhat.com>


  reply	other threads:[~2016-04-22 17:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-22 14:54 [kvm-unit-tests PATCH v2 0/4] arm/powerpc: make argv[0] the program name Andrew Jones
2016-04-22 14:54 ` [kvm-unit-tests PATCH v2 1/4] arm/arm64: reserve argv[0] for prognam Andrew Jones
2016-04-22 17:23   ` Thomas Huth
2016-04-22 17:36     ` Andrew Jones
2016-04-22 14:54 ` [kvm-unit-tests PATCH v2 2/4] powerpc/ppc64: " Andrew Jones
2016-04-22 17:24   ` Thomas Huth
2016-04-22 14:54 ` [kvm-unit-tests PATCH v2 3/4] arm/arm64: populate argv[0] with prognam Andrew Jones
2016-04-22 17:48   ` Thomas Huth [this message]
2016-04-22 18:05     ` Andrew Jones
2016-04-22 14:54 ` [kvm-unit-tests PATCH v2 4/4] powerpc/ppc64: " Andrew Jones
2016-04-22 17:50   ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=571A63EC.6020303@redhat.com \
    --to=thuth@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.