[Cbe-oss-dev] [PATCH] make arguments 64 big unconditionally

D. Herrendoerfer d.herrendoerfer at herrendoerfer.name
Mon Aug 13 16:50:43 EST 2007


Ok, added.

Thank you very much.

D.Herrendoerfer

On Sun, 2007-08-12 at 19:31 -0500, Joel Schopp wrote:
> After some discussion it was decided that the arguments to malloc_ea(), calloc_ea(), 
> realloc_ea(), and free_ea() should all be 64 bit unconditionally.  The attached patch 
> implements this change.  If there are no objections please check into libspe2 cvs.
> 
> Signed-off-by: Joel Schopp<jschopp at austin.ibm.com>
> plain text document attachment (64bit.patch)
> Index: libspe2/spebase/default_libea_handler.c
> ===================================================================
> --- libspe2.orig/spebase/default_libea_handler.c
> +++ libspe2/spebase/default_libea_handler.c
> @@ -15,7 +15,12 @@ typedef union {
>      unsigned int by32[2];
>  } addr64;
>  
> -
> +static inline size_t arg64_to_size_t(struct spe_reg128* arg0){
> +  addr64 argument0;
> +  argument0.by32[0] = arg0->slot[0];
> +  argument0.by32[1] = arg0->slot[1];
> +  return (size_t)argument0.all64;
> +}
>  /**
>   * default_libea_handler_calloc
>   * @ls: base pointer to local store area.
> @@ -36,13 +41,20 @@ static int default_libea_handler_calloc(
>    DECL_RET();
>    size_t nmemb;
>    size_t size;
> -  void* calloc_addr;
> +  void* calloc_addr = NULL;
>    addr64 ret2;
>  
> -  nmemb = (size_t) arg0->slot[0];
> -  size = (size_t) arg1->slot[0];
> +  nmemb = arg64_to_size_t(arg0);
> +  size = arg64_to_size_t(arg1);
> +
>  
> -  calloc_addr = calloc(nmemb, size);
> +  /* OK, now if we are 32 bit and we were passed 64 bit that really was
> +   * bigger than 32 bit we need to bail.
> +   */
> +  if((arg0->slot[0]== 0 && arg1->slot[0] == 0) || sizeof(nmemb) == 8)
> +    calloc_addr = calloc(nmemb, size);
> +  else
> +    errno = ENOMEM;
>  
>    ret2.all64 = (unsigned long long) (unsigned long) calloc_addr;
>  
> @@ -98,12 +110,15 @@ static int default_libea_handler_malloc(
>    DECL_1_ARGS();
>    DECL_RET();
>    size_t size;
> -  void* malloc_addr;
> +  void* malloc_addr = NULL;
>    addr64 ret2;
>  
> -  size = (size_t) arg0->slot[0];
> +  size = arg64_to_size_t(arg0);
>  
> -  malloc_addr = malloc(size);
> +  if(arg0->slot[0] == 0 || sizeof(size) == 8)
> +    malloc_addr = malloc(size);
> +  else
> +    errno = ENOMEM;
>  
>    ret2.all64 = (unsigned long long) (unsigned long) malloc_addr;
>  
> @@ -138,9 +153,12 @@ static int default_libea_handler_realloc
>    ptr.by32[0] = arg0->slot[0];
>    ptr.by32[0] = arg0->slot[1];
>  
> -  size = (size_t) arg1->slot[0];
> +  size = arg64_to_size_t(arg1);
>  
> -  realloc_addr = realloc((void *) ((unsigned long)ptr.all64), size);
> +  if(arg1->slot[0] == 0 || sizeof(size) == 8)
> +    realloc_addr = realloc((void *) ((unsigned long)ptr.all64), size);
> +  else
> +    errno = ENOMEM;
>  
>    ret2.all64 = (unsigned long long) (unsigned long) realloc_addr;
>  
> _______________________________________________
> 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