[Cbe-oss-dev] [PATCH] libspe2 set errno via second argument of perror assist call

D. Herrendoerfer d.herrendoerfer at herrendoerfer.name
Mon Jun 18 17:35:04 EST 2007


Added.

Thank you very much.

D.Herrendoerfer

On Mon, 2007-06-11 at 14:10 -0700, Patrick Mansfield wrote:
> Set errno to the second argument passed to the perror assist call.
> 
> At least with a current SPU newlib, if no argument is passed (as the
> second argument) we end up with the current stack value as the second
> argument, so it might be impossible to ever have the value be less than
> 4096. So, we could check for bad errno values, but perror already prints
> messages for those, and probably has better range checking, so don't
> bother trying to check the errno range.
> 
> errno is always cleared before calling the callback/assist code, so
> without this change, SPU perror always prints "Success". With this
> change and no corresponding SPU newlib change, SPU perror will most
> likely print "Unknown error <number>".
> 
> Using a new opcode would certainly allow us to maintain compatibility with
> the current buggy behaviour.
> 
> Signed-off-by: Patrick Mansfield <patmans at us.ibm.com>
> 
> Index: quilt-libspe2/spebase/default_c99_handler.c
> ===================================================================
> --- quilt-libspe2.orig/spebase/default_c99_handler.c
> +++ quilt-libspe2/spebase/default_c99_handler.c
> @@ -1870,20 +1870,26 @@ int default_c99_handler_ferror(char *ls,
>  /**
>   * default_c99_handler_perror
>   * @ls: base pointer to SPE local-store area.
> - * @opdata: per C99 call opcode & data.
> + * @opdata: per C99 call opcode & data, plus the value of errno on the SPU
> + * must be passed.
>   *
>   * SPE C99 library operation, per: ISO/IEC C Standard 9899:1999,
>   * implementing:
>   *
> - *	void perror(const char *s);
> + *  void perror(const char *s);
>   */
>  int default_c99_handler_perror(char *ls, unsigned long opdata)
>  {
> -    DECL_1_ARGS();
> +    DECL_2_ARGS();
>      char *s;
>  
>      DEBUG_PRINTF("%s\n", __func__);
>      s = GET_LS_PTR_NULL(arg0->slot[0]);
> +    errno = arg1->slot[0];
> +    /*
> +     * Older versions did not pass errno, so using older SPU newlib with
> +     * current libspe will likely give ouput like "Unknown error 262016".
> +     */
>      perror(s);
>      return 0;
>  }
> _______________________________________________
> cbe-oss-dev mailing list
> cbe-oss-dev at ozlabs.org
> https://ozlabs.org/mailman/listinfo/cbe-oss-dev




More information about the cbe-oss-dev mailing list