[Mesa-dev] [PATCH 01/75] llvmpipe: Fix overflow for 32 bits available memory computation

Roland Scheidegger sroland at vmware.com
Wed Oct 5 21:02:56 UTC 2016


Am 05.10.2016 um 22:08 schrieb Axel Davy:
> And cap to 2 GB on 32 bits.
> 
> Fixes https://bugs.freedesktop.org/show_bug.cgi?id=94561
> 
> Signed-off-by: Axel Davy <axel.davy at ens.fr>
> Signed-off-by: Patrick Rudolph <siro at das-labor.org>
> ---
>  src/gallium/auxiliary/os/os_misc.c       | 2 +-
>  src/gallium/drivers/llvmpipe/lp_screen.c | 5 +++++
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/src/gallium/auxiliary/os/os_misc.c b/src/gallium/auxiliary/os/os_misc.c
> index 82e4957..4880392 100644
> --- a/src/gallium/auxiliary/os/os_misc.c
> +++ b/src/gallium/auxiliary/os/os_misc.c
> @@ -128,7 +128,7 @@ os_get_total_physical_memory(uint64_t *size)
>     const long phys_pages = sysconf(_SC_PHYS_PAGES);
>     const long page_size = sysconf(_SC_PAGE_SIZE);
>  
> -   *size = phys_pages * page_size;
> +   *size = (int64_t)phys_pages * (int64_t)page_size;
>     return (phys_pages > 0 && page_size > 0);
>  #elif defined(PIPE_OS_APPLE) || defined(PIPE_OS_BSD)
>     size_t len = sizeof(*size);
> diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c
> index 18837a2..fa5b5cf 100644
> --- a/src/gallium/drivers/llvmpipe/lp_screen.c
> +++ b/src/gallium/drivers/llvmpipe/lp_screen.c
> @@ -280,6 +280,11 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
>        if (!os_get_total_physical_memory(&system_memory))
>           return 0;
>  
> +#ifdef PIPE_ARCH_X86
> +      /* cap to 2 GB on 32 bits system */
> +      system_memory = MIN2(system_memory, 2048 << 20);
> +#endif
> +
>        return (int)(system_memory >> 20);
>     }
>     case PIPE_CAP_UMA:
> 

Ideally that would use something which works on all 32bit archs, not
just x86. We don't have a define for that I think, so maybe just use
sizeof(void *) == 4 or something like that (of course, it can't be an
ifdef then, but that shouldn't matter).

Also, this code is identical to the one in softpipe at least, and I'd
like if it stays identical there.

Otherwise, for 1,2 of the series:
Reviewed-by: Roland Scheidegger <sroland at vmware.com>


More information about the mesa-dev mailing list