[Mesa-dev] [PATCH v3 1/1] clover: Don't crash on NULL global buffer objects.
Francisco Jerez
currojerez at riseup.net
Wed Jan 22 04:44:53 PST 2014
Jan Vesely <jan.vesely at rutgers.edu> writes:
> On Sat, 2014-01-18 at 13:34 +0100, Francisco Jerez wrote:
>> Jan Vesely <jan.vesely at rutgers.edu> writes:
>>
>> > Specs say "If the argument is a buffer object, the arg_value
>> > pointer can be NULL or point to a NULL value in which case a NULL
>> > value will be used as the value for the argument declared as a
>> > pointer to __global or __constant memory in the kernel."
>> >
>> > So don't crash when somebody does that.
>> >
>> > v2: Insert NULL into input buffer instead of buffer handle pair
>> > Fix constant_argument too
>> > Drop r600 driver changes
>> >
>> > v3: Fix inserting NULL pointer
>> >
>> > Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
>>
>> Looks OK to me,
>>
>> Reviewed-by: Francisco Jerez <currojerez at riseup.net>
>
> Thank you, can you push it as well? I don't have commit access.
Done. Thank you.
>
>>
>> Thanks.
>>
>> > ---
>> > src/gallium/state_trackers/clover/core/kernel.cpp | 34 +++++++++++++++--------
>> > 1 file changed, 23 insertions(+), 11 deletions(-)
>> >
>> > diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp
>> > index 58780d6..fb826c1 100644
>> > --- a/src/gallium/state_trackers/clover/core/kernel.cpp
>> > +++ b/src/gallium/state_trackers/clover/core/kernel.cpp
>> > @@ -327,7 +327,7 @@ kernel::global_argument::set(size_t size, const void *value) {
>> > if (size != sizeof(cl_mem))
>> > throw error(CL_INVALID_ARG_SIZE);
>> >
>> > - buf = &obj<buffer>(*(cl_mem *)value);
>> > + buf = pobj<buffer>(value ? *(cl_mem *)value : NULL);
>> > _set = true;
>> > }
>> >
>> > @@ -335,8 +335,14 @@ void
>> > kernel::global_argument::bind(exec_context &ctx,
>> > const module::argument &marg) {
>> > align(ctx.input, marg.target_align);
>> > - ctx.g_handles.push_back(allocate(ctx.input, marg.target_size));
>> > - ctx.g_buffers.push_back(buf->resource(*ctx.q).pipe);
>> > +
>> > + if (buf) {
>> > + ctx.g_handles.push_back(allocate(ctx.input, marg.target_size));
>> > + ctx.g_buffers.push_back(buf->resource(*ctx.q).pipe);
>> > + } else {
>> > + //NULL pointer
>> > + allocate(ctx.input, marg.target_size);
>> > + }
>> > }
>> >
>> > void
>> > @@ -379,22 +385,28 @@ kernel::constant_argument::set(size_t size, const void *value) {
>> > if (size != sizeof(cl_mem))
>> > throw error(CL_INVALID_ARG_SIZE);
>> >
>> > - buf = &obj<buffer>(*(cl_mem *)value);
>> > + buf = pobj<buffer>(value ? *(cl_mem *)value : NULL);
>> > _set = true;
>> > }
>> >
>> > void
>> > kernel::constant_argument::bind(exec_context &ctx,
>> > const module::argument &marg) {
>> > - auto v = bytes(ctx.resources.size() << 24);
>> > -
>> > - extend(v, module::argument::zero_ext, marg.target_size);
>> > - byteswap(v, ctx.q->dev.endianness());
>> > align(ctx.input, marg.target_align);
>> > - insert(ctx.input, v);
>> >
>> > - st = buf->resource(*ctx.q).bind_surface(*ctx.q, false);
>> > - ctx.resources.push_back(st);
>> > + if (buf) {
>> > + auto v = bytes(ctx.resources.size() << 24);
>> > +
>> > + extend(v, module::argument::zero_ext, marg.target_size);
>> > + byteswap(v, ctx.q->dev.endianness());
>> > + insert(ctx.input, v);
>> > +
>> > + st = buf->resource(*ctx.q).bind_surface(*ctx.q, false);
>> > + ctx.resources.push_back(st);
>> > + } else {
>> > + //NULL pointer
>> > + allocate(ctx.input, marg.target_size);
>> > + }
>> > }
>> >
>> > void
>> > --
>> > 1.8.4.2
>
> --
> Jan Vesely <jan.vesely at rutgers.edu>
>
> --
> Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 229 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140122/9768e8a0/attachment.pgp>
More information about the mesa-dev
mailing list