[Mesa-dev] [PATCH 08/11] glapi: Harden GLX request size processing

Ian Romanick idr at freedesktop.org
Mon Mar 28 18:10:06 UTC 2016


On 03/24/2016 11:10 AM, Adam Jackson wrote:
> ---
>  src/mapi/glapi/gen/glX_XML.py        |  2 +-
>  src/mapi/glapi/gen/glX_proto_recv.py |  2 --
>  src/mapi/glapi/gen/glX_proto_send.py |  2 --
>  src/mapi/glapi/gen/glX_proto_size.py | 24 +++++++++++-------------
>  src/mapi/glapi/gen/gl_XML.py         |  2 +-
>  5 files changed, 13 insertions(+), 19 deletions(-)
> 
> diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py
> index 166dbc1..3b833ee 100644
> --- a/src/mapi/glapi/gen/glX_XML.py
> +++ b/src/mapi/glapi/gen/glX_XML.py
> @@ -359,7 +359,7 @@ class glx_function(gl_XML.gl_function):
>                  # FIXME adds some extra diffs to the generated
>                  # FIXME code.
>  
> -                size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string(1))
> +                size_string = size_string + " + safe_pad(%s)" % (p.size_string(1))
>  
>          return size_string
>  
> diff --git a/src/mapi/glapi/gen/glX_proto_recv.py b/src/mapi/glapi/gen/glX_proto_recv.py
> index 1cfa8c5..21b187c 100644
> --- a/src/mapi/glapi/gen/glX_proto_recv.py
> +++ b/src/mapi/glapi/gen/glX_proto_recv.py
> @@ -89,8 +89,6 @@ class PrintGlxDispatchFunctions(glX_proto_common.glx_print_proto):
>          print '#include "indirect_util.h"'
>          print '#include "singlesize.h"'
>          print ''
> -        print '#define __GLX_PAD(x)  (((x) + 3) & ~3)'

I was going to suggest just changing the __GLX_PAD macro to use
safe_pad, but of course there are multiple definitions of __GLX_PAD. :(

> -        print ''
>          print 'typedef struct {'
>          print '    __GLX_PIXEL_3D_HDR;'
>          print '} __GLXpixel3DHeader;'
> diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py
> index 8b3d8d7..10abcff 100644
> --- a/src/mapi/glapi/gen/glX_proto_send.py
> +++ b/src/mapi/glapi/gen/glX_proto_send.py
> @@ -177,8 +177,6 @@ class PrintGlxProtoStubs(glX_proto_common.glx_print_proto):
>          print '#include <limits.h>'
>  
>          print ''
> -        print '#define __GLX_PAD(n) (((n) + 3) & ~3)'
> -        print ''
>          self.printFastcall()
>          self.printNoinline()
>          print ''
> diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py
> index 75fc26f..828b726 100644
> --- a/src/mapi/glapi/gen/glX_proto_size.py
> +++ b/src/mapi/glapi/gen/glX_proto_size.py
> @@ -291,7 +291,7 @@ class glx_server_enum_function(glx_enum_function):
>          print ''
>          print '    compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ","))
>          p = f.variable_length_parameter()
> -        print '    return __GLX_PAD(%s);' % (p.size_string())
> +        print '    return safe_pad(%s);' % (p.size_string())
>  
>          print '}'
>          print ''
> @@ -428,7 +428,7 @@ class PrintGlxReqSize_h(PrintGlxReqSize_common):
      def printBody(self, api):
>          for func in api.functionIterateGlx():
>              if not func.ignore and func.has_variable_size_request():
> -                print 'extern PURE _X_HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap);' % (func.name)
> +                print 'extern PURE _X_HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap, int reqlen);' % (func.name)

I don't see where reqlen is used.  Did I miss something?

>  
>  
>  class PrintGlxReqSize_c(PrintGlxReqSize_common):
> @@ -452,20 +452,18 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
>          print '#include "indirect_size.h"'
>          print '#include "indirect_reqsize.h"'
>          print ''
> -        print '#define __GLX_PAD(x)  (((x) + 3) & ~3)'
> -        print ''
>          print '#if defined(__CYGWIN__) || defined(__MINGW32__)'
>          print '#  undef HAVE_ALIAS'
>          print '#endif'
>          print '#ifdef HAVE_ALIAS'
>          print '#  define ALIAS2(from,to) \\'
> -        print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\'
> +        print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap, int reqlen ) \\'

Also, I'm in favor of fixing the spurious whitespace in this code. :)

>          print '        __attribute__ ((alias( # to )));'
>          print '#  define ALIAS(from,to) ALIAS2( from, __glX ## to ## ReqSize )'
>          print '#else'
>          print '#  define ALIAS(from,to) \\'
> -        print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\'
> -        print '    { return __glX ## to ## ReqSize( pc, swap ); }'
> +        print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap, int reqlen ) \\'
> +        print '    { return __glX ## to ## ReqSize( pc, swap, reqlen ); }'
>          print '#endif'
>          print ''
>          print ''
> @@ -547,7 +545,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
>  
>      def common_func_print_just_header(self, f):
>          print 'int'
> -        print '__glX%sReqSize( const GLbyte * pc, Bool swap )' % (f.name)
> +        print '__glX%sReqSize( const GLbyte * pc, Bool swap, int reqlen )' % (f.name)
>          print '{'
>  
>  
> @@ -602,7 +600,6 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
>          offset = 0
>          fixup = []
>          params = []
> -        plus = ''
>          size = ''
>          param_offsets = {}
>  
> @@ -620,9 +617,10 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
>                  if s == 0: s = 1
>  
>                  sig += "(%u,%u)" % (f.offset_of(p.counter), s)
> -                size += '%s%s' % (plus, p.size_string())
> -                plus = ' + '
> -
> +		if size is '':
> +		    size = p.size_string()
> +		else:
> +		    size = "safe_add(%s, %s)" % (size, p.size_string())
>  
>          # If the calculated signature matches a function that has
>          # already be emitted, don't emit this function.  Instead, add
> @@ -645,7 +643,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
>              self.common_emit_fixups(fixup)
>              print ''
>  
> -            print '    return __GLX_PAD(%s);' % (size)
> +            print '    return safe_pad(%s);' % (size)
>              print '}'
>              print ''
>  
> diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
> index e11f6fc..4f35343 100644
> --- a/src/mapi/glapi/gen/gl_XML.py
> +++ b/src/mapi/glapi/gen/gl_XML.py
> @@ -576,7 +576,7 @@ class gl_parameter(object):
>                  list.append( str(s) )
>  
>              if len(list) > 1 and use_parens :
> -                return "(%s)" % (string.join(list, " * "))
> +                return "safe_mul(%s)" % (string.join(list, ", "))
>              else:
>                  return string.join(list, " * ")
>  
> 



More information about the mesa-dev mailing list