[Mesa-dev] [PATCH v2 4/4] glsl/blob: add valgrind checks that written data is defined
Nicolai Hähnle
nhaehnle at gmail.com
Mon Jul 3 12:34:35 UTC 2017
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
Undefined data will eventually trigger a valgrind error while computing
its CRC32 while writing it into the disk cache, but at that point, it is
basically impossible to track down where the undefined data came from.
With this change, finding the origin of undefined data becomes easy.
v2: remove duplicate VALGRIND_CFLAGS (Emil)
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Reviewed-by: Emil Velikov <emil.velikov at collabora.com>
---
src/compiler/Makefile.am | 1 +
src/compiler/glsl/blob.c | 12 ++++++++++++
2 files changed, 13 insertions(+)
diff --git a/src/compiler/Makefile.am b/src/compiler/Makefile.am
index d52da91..4c83365 100644
--- a/src/compiler/Makefile.am
+++ b/src/compiler/Makefile.am
@@ -29,20 +29,21 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/mapi \
-I$(top_srcdir)/src/mesa/ \
-I$(top_builddir)/src/compiler/glsl\
-I$(top_srcdir)/src/compiler/glsl\
-I$(top_srcdir)/src/compiler/glsl/glcpp\
-I$(top_builddir)/src/compiler/nir \
-I$(top_srcdir)/src/compiler/nir \
-I$(top_srcdir)/src/gallium/include \
-I$(top_srcdir)/src/gallium/auxiliary \
-I$(top_srcdir)/src/gtest/include \
+ $(VALGRIND_CFLAGS) \
$(DEFINES)
AM_CFLAGS = \
$(VISIBILITY_CFLAGS) \
$(MSVC2013_COMPAT_CFLAGS)
AM_CXXFLAGS = \
$(VISIBILITY_CXXFLAGS) \
$(MSVC2013_COMPAT_CXXFLAGS)
diff --git a/src/compiler/glsl/blob.c b/src/compiler/glsl/blob.c
index db36252..3c4aed8 100644
--- a/src/compiler/glsl/blob.c
+++ b/src/compiler/glsl/blob.c
@@ -19,20 +19,28 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <string.h>
#include "main/macros.h"
#include "blob.h"
+#ifdef HAVE_VALGRIND
+#include <valgrind.h>
+#include <memcheck.h>
+#define VG(x) x
+#else
+#define VG(x)
+#endif
+
#define BLOB_INITIAL_SIZE 4096
/* Ensure that \blob will be able to fit an additional object of size
* \additional. The growing (if any) will occur by doubling the existing
* allocation.
*/
static bool
grow_to_fit(struct blob *blob, size_t additional)
{
size_t to_allocate;
@@ -103,31 +111,35 @@ blob_create()
bool
blob_overwrite_bytes(struct blob *blob,
size_t offset,
const void *bytes,
size_t to_write)
{
/* Detect an attempt to overwrite data out of bounds. */
if (blob->size < offset + to_write)
return false;
+ VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
+
memcpy(blob->data + offset, bytes, to_write);
return true;
}
bool
blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write)
{
if (! grow_to_fit(blob, to_write))
return false;
+ VG(VALGRIND_CHECK_MEM_IS_DEFINED(bytes, to_write));
+
memcpy(blob->data + blob->size, bytes, to_write);
blob->size += to_write;
return true;
}
uint8_t *
blob_reserve_bytes(struct blob *blob, size_t to_write)
{
uint8_t *ret;
--
2.9.3
More information about the mesa-dev
mailing list