From cc0dc02ebd31346c37e976194597c1c5d8562025 Mon Sep 17 00:00:00 2001 From: Luo Xionghu Date: Thu, 11 Sep 2014 08:43:54 +0800 Subject: fix piglit cl-api-set-kernel-arg fail. the memory object should be checked whether valid in context buffers before being set as kernel arguments. v2: rename the function from mem_in_buffers to is_valid_mem, move the magic header check into it. Signed-off-by: Luo Xionghu Reviewed-by: Zhigang Gong --- src/cl_kernel.c | 3 ++- src/cl_mem.c | 15 +++++++++++++++ src/cl_mem.h | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/cl_kernel.c b/src/cl_kernel.c index 5ab9c558..d7c2f7c1 100644 --- a/src/cl_kernel.c +++ b/src/cl_kernel.c @@ -99,6 +99,7 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value) enum gbe_arg_type arg_type; /* kind of argument */ size_t arg_sz; /* size of the argument */ cl_mem mem = NULL; /* for __global, __constant and image arguments */ + cl_context ctx = k->program->ctx; if (UNLIKELY(index >= k->arg_n)) return CL_INVALID_ARG_INDEX; @@ -136,7 +137,7 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value) if(value != NULL) mem = *(cl_mem*)value; if(value != NULL && mem) { - if (UNLIKELY(mem->magic != CL_MAGIC_MEM_HEADER)) + if( CL_SUCCESS != is_valid_mem(mem, ctx->buffers)) return CL_INVALID_MEM_OBJECT; if (UNLIKELY((arg_type == GBE_ARG_IMAGE && !IS_IMAGE(mem)) diff --git a/src/cl_mem.c b/src/cl_mem.c index 70bc3eb1..81c4d642 100644 --- a/src/cl_mem.c +++ b/src/cl_mem.c @@ -289,6 +289,21 @@ error: } +LOCAL cl_int +is_valid_mem(cl_mem mem, cl_mem buffers) +{ + cl_mem tmp = buffers; + while(tmp){ + if(mem == tmp){ + if (UNLIKELY(mem->magic != CL_MAGIC_MEM_HEADER)) + return CL_INVALID_MEM_OBJECT; + return CL_SUCCESS; + } + tmp = tmp->next; + } + return CL_INVALID_MEM_OBJECT; +} + LOCAL cl_mem cl_mem_new_buffer(cl_context ctx, cl_mem_flags flags, diff --git a/src/cl_mem.h b/src/cl_mem.h index 44772400..3174c5cd 100644 --- a/src/cl_mem.h +++ b/src/cl_mem.h @@ -176,6 +176,9 @@ extern cl_int cl_get_mem_object_info(cl_mem, cl_mem_info, size_t, void *, size_t /* Query information about an image */ extern cl_int cl_get_image_info(cl_mem, cl_image_info, size_t, void *, size_t *); +/* Query whether mem is in buffers */ +extern cl_int is_valid_mem(cl_mem mem, cl_mem buffers); + /* Create a new memory object and initialize it with possible user data */ extern cl_mem cl_mem_new_buffer(cl_context, cl_mem_flags, size_t, void*, cl_int*); -- cgit v1.2.1