[Mesa-dev] [PATCH 2/2] trace: add context pointer sanity checking

Brian Paul brianp at vmware.com
Fri Feb 15 09:44:24 PST 2013


To help catch mixed up context pointer bugs in the future, add a
trace_context_check() function and some new assertions.
---
 src/gallium/drivers/trace/tr_context.c |   15 +++++++++++++++
 src/gallium/drivers/trace/tr_context.h |    7 +++++++
 src/gallium/drivers/trace/tr_texture.c |    1 +
 3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c
index b88f379..538ff4a 100644
--- a/src/gallium/drivers/trace/tr_context.c
+++ b/src/gallium/drivers/trace/tr_context.c
@@ -852,6 +852,8 @@ trace_context_sampler_view_destroy(struct pipe_context *_pipe,
    struct pipe_context *pipe = tr_ctx->pipe;
    struct pipe_sampler_view *view = tr_view->sampler_view;
 
+   assert(_view->context == _pipe);
+
    trace_dump_call_begin("pipe_context", "sampler_view_destroy");
 
    trace_dump_arg(ptr, pipe);
@@ -1610,3 +1612,16 @@ trace_context_create(struct trace_screen *tr_scr,
 error1:
    return pipe;
 }
+
+
+/**
+ * Sanity checker: check that the given context really is a 
+ * trace context (and not the wrapped driver's context).
+ */
+void
+trace_context_check(const struct pipe_context *pipe)
+{
+   struct trace_context *tr_ctx = (struct trace_context *) pipe;
+   assert(tr_ctx->base.destroy == trace_context_destroy);
+}
+
diff --git a/src/gallium/drivers/trace/tr_context.h b/src/gallium/drivers/trace/tr_context.h
index dadbe56..90883d7 100644
--- a/src/gallium/drivers/trace/tr_context.h
+++ b/src/gallium/drivers/trace/tr_context.h
@@ -50,10 +50,17 @@ struct trace_context
 };
 
 
+void
+trace_context_check(const struct pipe_context *pipe);
+
+
 static INLINE struct trace_context *
 trace_context(struct pipe_context *pipe)
 {
    assert(pipe);
+#ifdef DEBUG
+   trace_context_check(pipe);
+#endif
    return (struct trace_context *)pipe;
 }
 
diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c
index aae1338..f6bc386 100644
--- a/src/gallium/drivers/trace/tr_texture.c
+++ b/src/gallium/drivers/trace/tr_texture.c
@@ -108,6 +108,7 @@ error:
 void
 trace_surf_destroy(struct trace_surface *tr_surf)
 {
+   trace_context_check(tr_surf->base.context);
    pipe_resource_reference(&tr_surf->base.texture, NULL);
    pipe_surface_reference(&tr_surf->surface, NULL);
    FREE(tr_surf);
-- 
1.7.3.4



More information about the mesa-dev mailing list