Commit 027288cc by Nicolas Capens

Intialize memory to zero to silence MSan.

The MemorySanitizer tool can't instrument JIT-compiled code, so it's unaware that the vertex processing routine writes the clip flags before they're being read by triangle setup. This false positive can be silenced by zeroing the memory at allocation. For good measure, zero out all intermediate buffers. Bug chromium:737875 Change-Id: Ic37ff5c64cb63bbddb151744af1d7dff0a254c2d Reviewed-on: https://swiftshader-review.googlesource.com/10431Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 96699f1a
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
#undef allocate #undef allocate
#undef deallocate #undef deallocate
#undef allocateZero
#undef deallocateZero
#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined (_M_X64)) && !defined(__x86__) #if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined (_M_X64)) && !defined(__x86__)
#define __x86__ #define __x86__
...@@ -65,10 +63,10 @@ struct Allocation ...@@ -65,10 +63,10 @@ struct Allocation
unsigned char *block; unsigned char *block;
}; };
void *allocate(size_t bytes, size_t alignment) inline void *allocateRaw(size_t bytes, size_t alignment)
{ {
unsigned char *block = new unsigned char[bytes + sizeof(Allocation) + alignment]; unsigned char *block = new unsigned char[bytes + sizeof(Allocation) + alignment];
unsigned char *aligned = 0; unsigned char *aligned = nullptr;
if(block) if(block)
{ {
...@@ -82,9 +80,9 @@ void *allocate(size_t bytes, size_t alignment) ...@@ -82,9 +80,9 @@ void *allocate(size_t bytes, size_t alignment)
return aligned; return aligned;
} }
void *allocateZero(size_t bytes, size_t alignment) void *allocate(size_t bytes, size_t alignment)
{ {
void *memory = allocate(bytes, alignment); void *memory = allocateRaw(bytes, alignment);
if(memory) if(memory)
{ {
......
...@@ -23,14 +23,13 @@ namespace sw ...@@ -23,14 +23,13 @@ namespace sw
size_t memoryPageSize(); size_t memoryPageSize();
void *allocate(size_t bytes, size_t alignment = 16); void *allocate(size_t bytes, size_t alignment = 16);
void *allocateZero(size_t bytes, size_t alignment = 16);
void deallocate(void *memory); void deallocate(void *memory);
void *allocateExecutable(size_t bytes); // Allocates memory that can be made executable using markExecutable() void *allocateExecutable(size_t bytes); // Allocates memory that can be made executable using markExecutable()
void markExecutable(void *memory, size_t bytes); void markExecutable(void *memory, size_t bytes);
void deallocateExecutable(void *memory, size_t bytes); void deallocateExecutable(void *memory, size_t bytes);
void clear(uint16_t *memory, uint16_t element, size_t count); void clear(uint16_t *memory, uint16_t element, size_t count);
void clear(uint32_t *memory, uint32_t element, size_t count); void clear(uint32_t *memory, uint32_t element, size_t count);
} }
......
...@@ -26,7 +26,7 @@ namespace sw ...@@ -26,7 +26,7 @@ namespace sw
count = 0; count = 0;
orphaned = false; orphaned = false;
buffer = allocateZero(bytes); buffer = allocate(bytes);
} }
Resource::~Resource() Resource::~Resource()
......
...@@ -3116,7 +3116,7 @@ namespace sw ...@@ -3116,7 +3116,7 @@ namespace sw
// FIXME: Unpacking byte4 to short4 in the sampler currently involves reading 8 bytes, // FIXME: Unpacking byte4 to short4 in the sampler currently involves reading 8 bytes,
// and stencil operations also read 8 bytes per four 8-bit stencil values, // and stencil operations also read 8 bytes per four 8-bit stencil values,
// so we have to allocate 4 extra bytes to avoid buffer overruns. // so we have to allocate 4 extra bytes to avoid buffer overruns.
return allocateZero(size(width2, height2, depth, format) + 4); return allocate(size(width2, height2, depth, format) + 4);
} }
void Surface::memfill4(void *buffer, int pattern, int bytes) void Surface::memfill4(void *buffer, int pattern, int bytes)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment