From 58985c36be85c668d059165d8282f8c8e4c7a380 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sat, 6 Mar 2010 21:57:47 +0200 Subject: glapi: functions for extensions table similar to static table --- src/mesa/glapi/glapi_getproc.c | 69 ++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 19 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 46b466920b..0d9358ce41 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -199,6 +199,45 @@ static struct _glapi_function ExtEntryTable[MAX_EXTENSION_FUNCS]; static GLuint NumExtEntryPoints = 0; +static GLint +get_extension_proc_offset(const char *funcName) +{ + GLuint i; + for (i = 0; i < NumExtEntryPoints; i++) { + if (strcmp(ExtEntryTable[i].name, funcName) == 0) { + return ExtEntryTable[i].dispatch_offset; + } + } + return -1; +} + + +static _glapi_proc +get_extension_proc_address(const char *funcName) +{ + GLuint i; + for (i = 0; i < NumExtEntryPoints; i++) { + if (strcmp(ExtEntryTable[i].name, funcName) == 0) { + return ExtEntryTable[i].dispatch_stub; + } + } + return NULL; +} + + +static const char * +get_extension_proc_name(GLuint offset) +{ + GLuint i; + for (i = 0; i < NumExtEntryPoints; i++) { + if (ExtEntryTable[i].dispatch_offset == offset) { + return ExtEntryTable[i].name; + } + } + return NULL; +} + + /** * strdup() is actually not a standard ANSI C or POSIX routine. * Irix will not define it if ANSI mode is in effect. @@ -399,13 +438,13 @@ _glapi_add_dispatch( const char * const * function_names, PUBLIC GLint _glapi_get_proc_offset(const char *funcName) { + GLint offset; + /* search extension functions first */ - GLuint i; - for (i = 0; i < NumExtEntryPoints; i++) { - if (strcmp(ExtEntryTable[i].name, funcName) == 0) { - return ExtEntryTable[i].dispatch_offset; - } - } + offset = get_extension_proc_offset(funcName); + if (offset >= 0) + return offset; + /* search static functions */ return get_static_proc_offset(funcName); } @@ -420,8 +459,8 @@ _glapi_get_proc_offset(const char *funcName) PUBLIC _glapi_proc _glapi_get_proc_address(const char *funcName) { + _glapi_proc func; struct _glapi_function * entry; - GLuint i; #ifdef MANGLE /* skip the prefix on the name */ @@ -433,11 +472,9 @@ _glapi_get_proc_address(const char *funcName) #endif /* search extension functions first */ - for (i = 0; i < NumExtEntryPoints; i++) { - if (strcmp(ExtEntryTable[i].name, funcName) == 0) { - return ExtEntryTable[i].dispatch_stub; - } - } + func = get_extension_proc_address(funcName); + if (func) + return func; #if !defined( XFree86Server ) /* search static functions */ @@ -461,7 +498,6 @@ _glapi_get_proc_address(const char *funcName) const char * _glapi_get_proc_name(GLuint offset) { - GLuint i; const char * n; /* search built-in functions */ @@ -471,12 +507,7 @@ _glapi_get_proc_name(GLuint offset) } /* search added extension functions */ - for (i = 0; i < NumExtEntryPoints; i++) { - if (ExtEntryTable[i].dispatch_offset == offset) { - return ExtEntryTable[i].name; - } - } - return NULL; + return get_extension_proc_name(offset); } -- cgit v1.2.3 From 5b2340c493cdf8d776e717b00acf0a8002858976 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 7 Mar 2010 23:04:52 +0200 Subject: glapi: add function to find extension by name --- src/mesa/glapi/glapi_getproc.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 0d9358ce41..4205435da5 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -199,29 +199,40 @@ static struct _glapi_function ExtEntryTable[MAX_EXTENSION_FUNCS]; static GLuint NumExtEntryPoints = 0; -static GLint -get_extension_proc_offset(const char *funcName) +static struct _glapi_function * +get_extension_proc(const char *funcName) { GLuint i; for (i = 0; i < NumExtEntryPoints; i++) { if (strcmp(ExtEntryTable[i].name, funcName) == 0) { - return ExtEntryTable[i].dispatch_offset; + return & ExtEntryTable[i]; } } - return -1; + return NULL; +} + + +static GLint +get_extension_proc_offset(const char *funcName) +{ + const struct _glapi_function * const f = get_extension_proc( funcName ); + if (f == NULL) { + return -1; + } + + return f->dispatch_offset; } static _glapi_proc get_extension_proc_address(const char *funcName) { - GLuint i; - for (i = 0; i < NumExtEntryPoints; i++) { - if (strcmp(ExtEntryTable[i].name, funcName) == 0) { - return ExtEntryTable[i].dispatch_stub; - } + const struct _glapi_function * const f = get_extension_proc( funcName ); + if (f == NULL) { + return NULL; } - return NULL; + + return f->dispatch_stub; } -- cgit v1.2.3 From f0c18da2cf01bc11dc720caed4590ae7eca128f1 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sat, 6 Mar 2010 21:19:45 +0200 Subject: glapi: cosmetic for functions for static table make similar to functions for extensions table --- src/mesa/glapi/glapi_getproc.c | 59 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 4205435da5..1514b91ffe 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -44,11 +44,14 @@ #include "glapi/glapioffsets.h" +/********************************************************************** + * Static function management. + */ + + #if !defined(DISPATCH_FUNCTION_SIZE) && !defined(XFree86Server) # define NEED_FUNCTION_POINTER #endif - -/* The code in this file is auto-generated with Python */ #include "glapi/glprocs.h" @@ -57,7 +60,7 @@ * and return the corresponding glprocs_table_t entry. */ static const glprocs_table_t * -find_entry( const char * n ) +get_static_proc( const char * n ) { GLuint i; for (i = 0; static_functions[i].Name_offset >= 0; i++) { @@ -83,11 +86,12 @@ find_entry( const char * n ) static GLint get_static_proc_offset(const char *funcName) { - const glprocs_table_t * const f = find_entry( funcName ); - if (f) { - return f->Offset; + const glprocs_table_t * const f = get_static_proc( funcName ); + if (f == NULL) { + return -1; } - return -1; + + return f->Offset; } @@ -100,25 +104,32 @@ get_static_proc_offset(const char *funcName) static _glapi_proc get_static_proc_address(const char *funcName) { - const glprocs_table_t * const f = find_entry( funcName ); - if (f) { + const glprocs_table_t * const f = get_static_proc( funcName ); + if (f == NULL) { + return NULL; + } + #if defined(DISPATCH_FUNCTION_SIZE) && defined(GLX_INDIRECT_RENDERING) - return (f->Address == NULL) - ? get_entrypoint_address(f->Offset) - : f->Address; + return (f->Address == NULL) + ? get_entrypoint_address(f->Offset) + : f->Address; #elif defined(DISPATCH_FUNCTION_SIZE) - return get_entrypoint_address(f->Offset); + return get_entrypoint_address(f->Offset); #else - return f->Address; + return f->Address; #endif - } - else { - return NULL; - } } -#endif /* !defined(XFree86Server) */ +#else + +static _glapi_proc +get_static_proc_address(const char *funcName) +{ + (void) funcName; + return NULL; +} +#endif /* !defined(XFree86Server) */ /** @@ -487,14 +498,10 @@ _glapi_get_proc_address(const char *funcName) if (func) return func; -#if !defined( XFree86Server ) /* search static functions */ - { - const _glapi_proc func = get_static_proc_address(funcName); - if (func) - return func; - } -#endif /* !defined( XFree86Server ) */ + func = get_static_proc_address(funcName); + if (func) + return func; entry = add_function_name(funcName); return (entry == NULL) ? NULL : entry->dispatch_stub; -- cgit v1.2.3 From f9cc6b3ee7c95130992d67c080ff9bc8e8a6d789 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 8 Mar 2010 01:18:31 +0200 Subject: glapi: use get_extension_proc in _glapi_add_dispatch --- src/mesa/glapi/glapi_getproc.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 1514b91ffe..1d0389e057 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -368,7 +368,6 @@ _glapi_add_dispatch( const char * const * function_names, struct _glapi_function * entry[8]; GLboolean is_static[8]; unsigned i; - unsigned j; int offset = ~0; int new_offset; @@ -403,28 +402,25 @@ _glapi_add_dispatch( const char * const * function_names, } - for ( j = 0 ; j < NumExtEntryPoints ; j++ ) { - if (strcmp(ExtEntryTable[j].name, function_names[i]) == 0) { + entry[i] = get_extension_proc(function_names[i]); + + if (entry[i] != NULL) { + /* The offset may be ~0 if the function name was added by * glXGetProcAddress but never filled in by the driver. */ - if (ExtEntryTable[j].dispatch_offset != ~0) { - if (strcmp(real_sig, ExtEntryTable[j].parameter_signature) - != 0) { + if (entry[i]->dispatch_offset != ~0) { + if (strcmp(real_sig, entry[i]->parameter_signature) != 0) { return -1; } - if ( (offset != ~0) && (ExtEntryTable[j].dispatch_offset != offset) ) { + if ( (offset != ~0) && (entry[i]->dispatch_offset != offset) ) { return -1; } - offset = ExtEntryTable[j].dispatch_offset; + offset = entry[i]->dispatch_offset; } - - entry[i] = & ExtEntryTable[j]; - break; - } } } -- cgit v1.2.3 From ddabf0a151c2ef318e5de45238556c6568540681 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 8 Mar 2010 01:26:01 +0200 Subject: glapi: cosmetic for _glapi_add_dispatch - static vs. extension - indent - s/new_offset/static_offset/ - ... --- src/mesa/glapi/glapi_getproc.c | 57 ++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 1d0389e057..a4d2cb907c 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -369,58 +369,65 @@ _glapi_add_dispatch( const char * const * function_names, GLboolean is_static[8]; unsigned i; int offset = ~0; - int new_offset; (void) memset( is_static, 0, sizeof( is_static ) ); (void) memset( entry, 0, sizeof( entry ) ); for ( i = 0 ; function_names[i] != NULL ; i++ ) { - /* Do some trivial validation on the name of the function. - */ + const char * funcName = function_names[i]; + int static_offset; + int extension_offset; - if (!function_names[i] || function_names[i][0] != 'g' || function_names[i][1] != 'l') + if (funcName[0] != 'g' || funcName[1] != 'l') return -1; - + /* Determine if the named function already exists. If the function does * exist, it must have the same parameter signature as the function * being added. */ - new_offset = get_static_proc_offset(function_names[i]); - if (new_offset >= 0) { + /* search built-in functions */ + static_offset = get_static_proc_offset(funcName); + + if (static_offset >= 0) { + + is_static[i] = GL_TRUE; + /* FIXME: Make sure the parameter signatures match! How do we get * FIXME: the parameter signature for static functions? */ - if ( (offset != ~0) && (new_offset != offset) ) { + if ( (offset != ~0) && (static_offset != offset) ) { return -1; } - is_static[i] = GL_TRUE; - offset = new_offset; + offset = static_offset; } - - - entry[i] = get_extension_proc(function_names[i]); + + /* search added extension functions */ + entry[i] = get_extension_proc(funcName); if (entry[i] != NULL) { + extension_offset = entry[i]->dispatch_offset; - /* The offset may be ~0 if the function name was added by - * glXGetProcAddress but never filled in by the driver. - */ + /* The offset may be ~0 if the function name was added by + * glXGetProcAddress but never filled in by the driver. + */ - if (entry[i]->dispatch_offset != ~0) { - if (strcmp(real_sig, entry[i]->parameter_signature) != 0) { - return -1; - } + if (extension_offset == ~0) { + continue; + } - if ( (offset != ~0) && (entry[i]->dispatch_offset != offset) ) { - return -1; - } + if (strcmp(real_sig, entry[i]->parameter_signature) != 0) { + return -1; + } - offset = entry[i]->dispatch_offset; - } + if ( (offset != ~0) && (extension_offset != offset) ) { + return -1; + } + + offset = extension_offset; } } -- cgit v1.2.3 From cae4fdda8d27cac21714571adb0bfada6d96152a Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 8 Mar 2010 01:40:14 +0200 Subject: glapi: parameter checking, failure paths, ... for add_function_name --- src/mesa/glapi/glapi_getproc.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index a4d2cb907c..ea905bb2cb 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -293,20 +293,34 @@ static struct _glapi_function * add_function_name( const char * funcName ) { struct _glapi_function * entry = NULL; - - if (NumExtEntryPoints < MAX_EXTENSION_FUNCS) { - _glapi_proc entrypoint = generate_entrypoint(~0); - if (entrypoint != NULL) { - entry = & ExtEntryTable[NumExtEntryPoints]; - - ExtEntryTable[NumExtEntryPoints].name = str_dup(funcName); - ExtEntryTable[NumExtEntryPoints].parameter_signature = NULL; - ExtEntryTable[NumExtEntryPoints].dispatch_offset = ~0; - ExtEntryTable[NumExtEntryPoints].dispatch_stub = entrypoint; - NumExtEntryPoints++; - } + _glapi_proc entrypoint = NULL; + char * name_dup = NULL; + + if (NumExtEntryPoints >= MAX_EXTENSION_FUNCS) + return NULL; + + if (funcName == NULL) + return NULL; + + name_dup = str_dup(funcName); + if (name_dup == NULL) + return NULL; + + entrypoint = generate_entrypoint(~0); + + if (entrypoint == NULL) { + free(name_dup); + return NULL; } + entry = & ExtEntryTable[NumExtEntryPoints]; + NumExtEntryPoints++; + + entry->name = name_dup; + entry->parameter_signature = NULL; + entry->dispatch_offset = ~0; + entry->dispatch_stub = entrypoint; + return entry; } -- cgit v1.2.3 From 3833a76eef6b45b82c102a49055602632f960a99 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 8 Mar 2010 01:55:10 +0200 Subject: glapi: add function set_entry_info --- src/mesa/glapi/glapi_getproc.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index ea905bb2cb..95974fe3a0 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -325,6 +325,27 @@ add_function_name( const char * funcName ) } +static struct _glapi_function * +set_entry_info( struct _glapi_function * entry, const char * signature, unsigned offset ) +{ + char * sig_dup = NULL; + + if (signature == NULL) + return NULL; + + sig_dup = str_dup(signature); + if (sig_dup == NULL) + return NULL; + + fill_in_entrypoint_offset(entry->dispatch_stub, offset); + + entry->parameter_signature = sig_dup; + entry->dispatch_offset = offset; + + return entry; +} + + /** * Fill-in the dispatch stub for the named function. * @@ -461,9 +482,7 @@ _glapi_add_dispatch( const char * const * function_names, } } - entry[i]->parameter_signature = str_dup(real_sig); - fill_in_entrypoint_offset(entry[i]->dispatch_stub, offset); - entry[i]->dispatch_offset = offset; + set_entry_info( entry[i], real_sig, offset ); } } -- cgit v1.2.3 From c4b630efdb882f824e9099b9cb2e07d8db2e3549 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 8 Mar 2010 01:58:59 +0200 Subject: glapi: minor cosmetic for _glapi_add_dispatch --- src/mesa/glapi/glapi_getproc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 95974fe3a0..1badff81ea 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -472,20 +472,21 @@ _glapi_add_dispatch( const char * const * function_names, } for ( i = 0 ; function_names[i] != NULL ; i++ ) { - if (! is_static[i] ) { + if (is_static[i]) { + continue; + } + + if (entry[i] == NULL) { + entry[i] = add_function_name( function_names[i] ); if (entry[i] == NULL) { - entry[i] = add_function_name( function_names[i] ); - if (entry[i] == NULL) { - /* FIXME: Possible memory leak here. - */ - return -1; - } + /* FIXME: Possible memory leak here. */ + return -1; } - - set_entry_info( entry[i], real_sig, offset ); } + + set_entry_info( entry[i], real_sig, offset ); } - + return offset; } -- cgit v1.2.3 From 0d1dde5b010feba1afe5b51cc6fe66c85371f70b Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 8 Mar 2010 02:53:57 +0200 Subject: glapi: comments for _glapi_add_dispatch --- src/mesa/glapi/glapi_getproc.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 1badff81ea..921df262af 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -409,6 +409,10 @@ _glapi_add_dispatch( const char * const * function_names, (void) memset( is_static, 0, sizeof( is_static ) ); (void) memset( entry, 0, sizeof( entry ) ); + /* Find the _single_ dispatch offset for all function names that already + * exist (and have a dispatch offset). + */ + for ( i = 0 ; function_names[i] != NULL ; i++ ) { const char * funcName = function_names[i]; int static_offset; @@ -417,11 +421,6 @@ _glapi_add_dispatch( const char * const * function_names, if (funcName[0] != 'g' || funcName[1] != 'l') return -1; - /* Determine if the named function already exists. If the function does - * exist, it must have the same parameter signature as the function - * being added. - */ - /* search built-in functions */ static_offset = get_static_proc_offset(funcName); @@ -466,16 +465,25 @@ _glapi_add_dispatch( const char * const * function_names, } } + /* If all function names are either new (or with no dispatch offset), + * allocate a new dispatch offset. + */ + if (offset == ~0) { offset = next_dynamic_offset; next_dynamic_offset++; } + /* Fill in the dispatch offset for the new function names (and those with + * no dispatch offset). + */ + for ( i = 0 ; function_names[i] != NULL ; i++ ) { if (is_static[i]) { continue; } + /* generate entrypoints for new function names */ if (entry[i] == NULL) { entry[i] = add_function_name( function_names[i] ); if (entry[i] == NULL) { @@ -540,8 +548,12 @@ _glapi_get_proc_address(const char *funcName) if (func) return func; + /* generate entrypoint, dispatch offset must be filled in by the driver */ entry = add_function_name(funcName); - return (entry == NULL) ? NULL : entry->dispatch_stub; + if (entry == NULL) + return NULL; + + return entry->dispatch_stub; } -- cgit v1.2.3 From bae31355150f66f7130d76a2ab4d4b735f239c71 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 8 Mar 2010 03:10:30 +0200 Subject: glapi: these two should be ok for add_dispatch ... - a function cannot be both static and extension, right ? - we should be setting the offset only if not already set, right ? --- src/mesa/glapi/glapi_getproc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 921df262af..5a8c6953ac 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -437,6 +437,8 @@ _glapi_add_dispatch( const char * const * function_names, } offset = static_offset; + + continue; } /* search added extension functions */ @@ -492,7 +494,9 @@ _glapi_add_dispatch( const char * const * function_names, } } - set_entry_info( entry[i], real_sig, offset ); + if (entry[i]->dispatch_offset == ~0) { + set_entry_info( entry[i], real_sig, offset ); + } } return offset; -- cgit v1.2.3 From 7cd8f0ef9d905080dc857c4739be9780b24a7fd2 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Wed, 10 Mar 2010 00:43:01 +0200 Subject: glapi: fix bug with tls and relocs add_dispatch (driver) and maybe get_proc_address (client) may be called before set_dispatch is called, which results in generate_entrypoint using an unreloced function template. --- src/mesa/glapi/glapi_getproc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/mesa/glapi') diff --git a/src/mesa/glapi/glapi_getproc.c b/src/mesa/glapi/glapi_getproc.c index 5a8c6953ac..295657875d 100644 --- a/src/mesa/glapi/glapi_getproc.c +++ b/src/mesa/glapi/glapi_getproc.c @@ -405,6 +405,7 @@ _glapi_add_dispatch( const char * const * function_names, unsigned i; int offset = ~0; + init_glapi_relocs_once(); (void) memset( is_static, 0, sizeof( is_static ) ); (void) memset( entry, 0, sizeof( entry ) ); @@ -533,6 +534,8 @@ _glapi_get_proc_address(const char *funcName) _glapi_proc func; struct _glapi_function * entry; + init_glapi_relocs_once(); + #ifdef MANGLE /* skip the prefix on the name */ if (funcName[1] != 'g' || funcName[2] != 'l') -- cgit v1.2.3