diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 19:32:50 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 19:32:50 +0000 |
commit | abd3ee31ea51b47264986e4f5a3109582fbef97d (patch) | |
tree | 6780c5aad3a11d7e4472dba9373c7d40d756f075 /gpu | |
parent | 826fa729e3763314e75a8391af8b7ca50f3aa573 (diff) | |
download | chromium_src-abd3ee31ea51b47264986e4f5a3109582fbef97d.zip chromium_src-abd3ee31ea51b47264986e4f5a3109582fbef97d.tar.gz chromium_src-abd3ee31ea51b47264986e4f5a3109582fbef97d.tar.bz2 |
Initialize destinations variables before calling GL functions
because if the context is lost those variables will
be uninitialized.
TEST=ran chrome, conformance tests, unit tests and hand edited gles2_demo to test
BUG=none
Review URL: http://codereview.chromium.org/5305005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67293 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rwxr-xr-x | gpu/command_buffer/build_gles2_cmd_buffer.py | 37 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_c_lib.cc | 28 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_c_lib_autogen.h | 22 | ||||
-rw-r--r-- | gpu/command_buffer/client/gles2_demo_cc.cc | 4 | ||||
-rw-r--r-- | gpu/command_buffer/service/common_decoder.cc | 11 | ||||
-rw-r--r-- | gpu/command_buffer/service/common_decoder.h | 2 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 10 |
7 files changed, 103 insertions, 11 deletions
diff --git a/gpu/command_buffer/build_gles2_cmd_buffer.py b/gpu/command_buffer/build_gles2_cmd_buffer.py index 331159c..d610e5b 100755 --- a/gpu/command_buffer/build_gles2_cmd_buffer.py +++ b/gpu/command_buffer/build_gles2_cmd_buffer.py @@ -2125,6 +2125,11 @@ TEST_F(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { else: self.WriteGLES2ImplementationDeclaration(func, file) + def WriteDestinationInitalizationValidation(self, func, file): + """Writes the client side destintion initialization validation.""" + for arg in func.GetOriginalArgs(): + arg.WriteDestinationInitalizationValidation(file, func) + def WriteImmediateCmdComputeSize(self, func, file): """Writes the size computation code for the immediate version of a cmd.""" file.Write(" static uint32 ComputeSize(uint32 size_in_bytes) {\n") @@ -3980,6 +3985,7 @@ class Argument(object): 'GLfloat': 'float', 'GLclampf': 'float', } + need_validation_ = ['GLsizei*', 'GLboolean*', 'GLenum*', 'GLint*'] def __init__(self, name, type): self.name = name @@ -4029,6 +4035,20 @@ class Argument(object): """Writes the validation code for an argument.""" pass + def WriteDestinationInitalizationValidation(self, file, func): + """Writes the client side destintion initialization validation.""" + pass + + def WriteDestinationInitalizationValidatationIfNeeded(self, file, func): + """Writes the client side destintion initialization validation if needed.""" + parts = self.type.split(" ") + if len(parts) > 1: + return + if parts[0] in self.need_validation_: + file.Write(" GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(%s, %s);\n" % + (self.type[:-1], self.name)) + + def WriteGetAddress(self, file): """Writes the code to get the address this argument refers to.""" pass @@ -4213,6 +4233,10 @@ class ImmediatePointerArgument(Argument): """Overridden from Argument.""" return None + def WriteDestinationInitalizationValidation(self, file, func): + """Overridden from Argument.""" + self.WriteDestinationInitalizationValidatationIfNeeded(file, func) + class BucketPointerArgument(Argument): """A class that represents an bucket argument to a function.""" @@ -4238,6 +4262,10 @@ class BucketPointerArgument(Argument): """Overridden from Argument.""" return None + def WriteDestinationInitalizationValidation(self, file, func): + """Overridden from Argument.""" + self.WriteDestinationInitalizationValidatationIfNeeded(file, func) + class PointerArgument(Argument): """A class that represents a pointer argument to a function.""" @@ -4308,6 +4336,10 @@ class PointerArgument(Argument): return InputStringBucketArgument(self.name, self.type) return BucketPointerArgument(self.name, self.type) + def WriteDestinationInitalizationValidation(self, file, func): + """Overridden from Argument.""" + self.WriteDestinationInitalizationValidatationIfNeeded(file, func) + class InputStringBucketArgument(Argument): """An string input argument where the string is passed in a bucket.""" @@ -4629,6 +4661,10 @@ class Function(object): """Writes the GLES2 Implemention declaration.""" self.type_handler.WriteGLES2ImplementationHeader(self, file) + def WriteDestinationInitalizationValidation(self, file): + """Writes the client side destintion initialization validation.""" + self.type_handler.WriteDestinationInitalizationValidation(self, file) + def WriteFormatTest(self, file): """Writes the cmd's format test.""" self.type_handler.WriteFormatTest(self, file) @@ -5113,6 +5149,7 @@ class GLGenerator(object): file.Write("%s GLES2%s(%s) {\n" % (func.return_type, func.name, func.MakeTypedOriginalArgString(""))) + func.WriteDestinationInitalizationValidation(file) comma = "" if len(func.GetOriginalArgs()): comma = " << " diff --git a/gpu/command_buffer/client/gles2_c_lib.cc b/gpu/command_buffer/client/gles2_c_lib.cc index 74cc431..f53067e 100644 --- a/gpu/command_buffer/client/gles2_c_lib.cc +++ b/gpu/command_buffer/client/gles2_c_lib.cc @@ -4,8 +4,36 @@ // These functions emluate GLES2 over command buffers for C. +#include <assert.h> #include "../client/gles2_lib.h" +// Check that destination pointers point to initialized memory. +// When the context is lost, calling GL function has no effect so if destination +// pointers point to initialized memory it can often lead to crash bugs. eg. +// +// GLsizei len; +// glGetShaderSource(shader, max_size, &len, buffer); +// std::string src(buffer, buffer + len); // len can be uninitialized here!!! +// +// Because this check is not official GL this check happens only on Chrome code, +// not Pepper. +// +// If it was up to us we'd just always write to the destination but the OpenGL +// spec defines the behavior of OpenGL function, not us. :-( +#if defined(__native_client__) + #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) +#elif defined(GPU_DCHECK) + #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) GPU_DCHECK(v) +#elif defined(DCHECK) + #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v) +#else + #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v) +#endif + +#define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(type, ptr) \ + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(ptr && \ + (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1))); + extern "C" { // Include the auto-generated part of this file. We split this because it means // we can easily edit the non-auto generated parts right here in this file diff --git a/gpu/command_buffer/client/gles2_c_lib_autogen.h b/gpu/command_buffer/client/gles2_c_lib_autogen.h index ab54997..420b0e5 100644 --- a/gpu/command_buffer/client/gles2_c_lib_autogen.h +++ b/gpu/command_buffer/client/gles2_c_lib_autogen.h @@ -279,6 +279,9 @@ void GLES2GenTextures(GLsizei n, GLuint* textures) { void GLES2GetActiveAttrib( GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, size); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLenum, type); GPU_CLIENT_LOG( "GetActiveAttrib" << "(" << program << ", " << index << ", " << bufsize << ", " << length << ", " << size << ", " << type << ", " << name << ")"); // NOLINT gles2::GetGLContext()->GetActiveAttrib( @@ -287,6 +290,9 @@ void GLES2GetActiveAttrib( void GLES2GetActiveUniform( GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, size); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLenum, type); GPU_CLIENT_LOG( "GetActiveUniform" << "(" << program << ", " << index << ", " << bufsize << ", " << length << ", " << size << ", " << type << ", " << name << ")"); // NOLINT gles2::GetGLContext()->GetActiveUniform( @@ -294,6 +300,7 @@ void GLES2GetActiveUniform( } void GLES2GetAttachedShaders( GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, count); GPU_CLIENT_LOG( "GetAttachedShaders" << "(" << program << ", " << maxcount << ", " << count << ", " << shaders << ")"); // NOLINT gles2::GetGLContext()->GetAttachedShaders(program, maxcount, count, shaders); @@ -305,10 +312,12 @@ GLint GLES2GetAttribLocation(GLuint program, const char* name) { return result; } void GLES2GetBooleanv(GLenum pname, GLboolean* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLboolean, params); GPU_CLIENT_LOG("GetBooleanv" << "(" << pname << ", " << params << ")"); gles2::GetGLContext()->GetBooleanv(pname, params); } void GLES2GetBufferParameteriv(GLenum target, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetBufferParameteriv" << "(" << target << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetBufferParameteriv(target, pname, params); @@ -325,45 +334,54 @@ void GLES2GetFloatv(GLenum pname, GLfloat* params) { } void GLES2GetFramebufferAttachmentParameteriv( GLenum target, GLenum attachment, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetFramebufferAttachmentParameteriv" << "(" << target << ", " << attachment << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetFramebufferAttachmentParameteriv( target, attachment, pname, params); } void GLES2GetIntegerv(GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG("GetIntegerv" << "(" << pname << ", " << params << ")"); gles2::GetGLContext()->GetIntegerv(pname, params); } void GLES2GetProgramiv(GLuint program, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetProgramiv" << "(" << program << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetProgramiv(program, pname, params); } void GLES2GetProgramInfoLog( GLuint program, GLsizei bufsize, GLsizei* length, char* infolog) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); GPU_CLIENT_LOG( "GetProgramInfoLog" << "(" << program << ", " << bufsize << ", " << length << ", " << infolog << ")"); // NOLINT gles2::GetGLContext()->GetProgramInfoLog(program, bufsize, length, infolog); } void GLES2GetRenderbufferParameteriv( GLenum target, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetRenderbufferParameteriv" << "(" << target << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetRenderbufferParameteriv(target, pname, params); } void GLES2GetShaderiv(GLuint shader, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetShaderiv" << "(" << shader << ", " << pname << ", " << params << ")"); gles2::GetGLContext()->GetShaderiv(shader, pname, params); } void GLES2GetShaderInfoLog( GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); GPU_CLIENT_LOG( "GetShaderInfoLog" << "(" << shader << ", " << bufsize << ", " << length << ", " << infolog << ")"); // NOLINT gles2::GetGLContext()->GetShaderInfoLog(shader, bufsize, length, infolog); } void GLES2GetShaderPrecisionFormat( GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, range); + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, precision); GPU_CLIENT_LOG( "GetShaderPrecisionFormat" << "(" << shadertype << ", " << precisiontype << ", " << range << ", " << precision << ")"); // NOLINT gles2::GetGLContext()->GetShaderPrecisionFormat( @@ -371,6 +389,7 @@ void GLES2GetShaderPrecisionFormat( } void GLES2GetShaderSource( GLuint shader, GLsizei bufsize, GLsizei* length, char* source) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLsizei, length); GPU_CLIENT_LOG( "GetShaderSource" << "(" << shader << ", " << bufsize << ", " << length << ", " << source << ")"); // NOLINT gles2::GetGLContext()->GetShaderSource(shader, bufsize, length, source); @@ -387,6 +406,7 @@ void GLES2GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params) { gles2::GetGLContext()->GetTexParameterfv(target, pname, params); } void GLES2GetTexParameteriv(GLenum target, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetTexParameteriv" << "(" << target << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetTexParameteriv(target, pname, params); @@ -397,6 +417,7 @@ void GLES2GetUniformfv(GLuint program, GLint location, GLfloat* params) { gles2::GetGLContext()->GetUniformfv(program, location, params); } void GLES2GetUniformiv(GLuint program, GLint location, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetUniformiv" << "(" << program << ", " << location << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetUniformiv(program, location, params); @@ -414,6 +435,7 @@ void GLES2GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) { gles2::GetGLContext()->GetVertexAttribfv(index, pname, params); } void GLES2GetVertexAttribiv(GLuint index, GLenum pname, GLint* params) { + GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); GPU_CLIENT_LOG( "GetVertexAttribiv" << "(" << index << ", " << pname << ", " << params << ")"); // NOLINT gles2::GetGLContext()->GetVertexAttribiv(index, pname, params); diff --git a/gpu/command_buffer/client/gles2_demo_cc.cc b/gpu/command_buffer/client/gles2_demo_cc.cc index cb33f8c..a0ddaff 100644 --- a/gpu/command_buffer/client/gles2_demo_cc.cc +++ b/gpu/command_buffer/client/gles2_demo_cc.cc @@ -47,7 +47,7 @@ GLuint LoadShader(GLenum type, const char* shaderSrc) { // Compile the shader glCompileShader(shader); // Check the compile status - GLint value; + GLint value = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &value); if (value == 0) { char buffer[1024]; @@ -100,7 +100,7 @@ void InitShaders() { // Link the program glLinkProgram(programObject); // Check the link status - GLint linked; + GLint linked = 0; glGetProgramiv(programObject, GL_LINK_STATUS, &linked); if (linked == 0) { char buffer[1024]; diff --git a/gpu/command_buffer/service/common_decoder.cc b/gpu/command_buffer/service/common_decoder.cc index ce45422..a116d04 100644 --- a/gpu/command_buffer/service/common_decoder.cc +++ b/gpu/command_buffer/service/common_decoder.cc @@ -35,11 +35,16 @@ bool CommonDecoder::Bucket::SetData( return false; } -void CommonDecoder::Bucket::SetFromString(const std::string& str) { +void CommonDecoder::Bucket::SetFromString(const char* str) { // Strings are passed NULL terminated to distinguish between empty string // and no string. - SetSize(str.size() + 1); - SetData(str.c_str(), 0, str.size() + 1); + if (!str) { + SetSize(0); + } else { + size_t size = strlen(str) + 1; + SetSize(size); + SetData(str, 0, size); + } } bool CommonDecoder::Bucket::GetAsString(std::string* str) { diff --git a/gpu/command_buffer/service/common_decoder.h b/gpu/command_buffer/service/common_decoder.h index 7abc016..ea4e520 100644 --- a/gpu/command_buffer/service/common_decoder.h +++ b/gpu/command_buffer/service/common_decoder.h @@ -73,7 +73,7 @@ class CommonDecoder : public AsyncAPIInterface { // Sets the bucket data from a string. Strings are passed NULL terminated to // distinguish between empty string and no string. - void SetFromString(const std::string& str); + void SetFromString(const char* str); // Gets the bucket data as a string. Strings are passed NULL terminated to // distrinquish between empty string and no string. Returns False if there diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index fbb6ca4..17d1f09 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -4313,7 +4313,7 @@ error::Error GLES2DecoderImpl::HandleGetShaderSource( bucket->SetSize(0); return error::kNoError; } - bucket->SetFromString(info->source()); + bucket->SetFromString(info->source().c_str()); return error::kNoError; } @@ -4327,7 +4327,7 @@ error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( if (!info) { return error::kNoError; } - bucket->SetFromString(info->log_info()); + bucket->SetFromString(info->log_info().c_str()); return error::kNoError; } @@ -4342,7 +4342,7 @@ error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( bucket->SetSize(0); return error::kNoError; } - bucket->SetFromString(info->log_info()); + bucket->SetFromString(info->log_info().c_str()); return error::kNoError; } @@ -5739,7 +5739,7 @@ error::Error GLES2DecoderImpl::HandleGetActiveUniform( result->size = uniform_info->size; result->type = uniform_info->type; Bucket* bucket = CreateBucket(name_bucket_id); - bucket->SetFromString(uniform_info->name); + bucket->SetFromString(uniform_info->name.c_str()); return error::kNoError; } @@ -5773,7 +5773,7 @@ error::Error GLES2DecoderImpl::HandleGetActiveAttrib( result->size = attrib_info->size; result->type = attrib_info->type; Bucket* bucket = CreateBucket(name_bucket_id); - bucket->SetFromString(attrib_info->name); + bucket->SetFromString(attrib_info->name.c_str()); return error::kNoError; } |