From c2cb388e96ad9111c7b3616d81cf489805a49e35 Mon Sep 17 00:00:00 2001 From: Neil Spruit Date: Wed, 30 Aug 2023 10:17:17 -0700 Subject: [PATCH] Fix intercept layer access to array of handles and return of logs Related-To: VLCLJ-2021 Signed-off-by: Spruit, Neil R --- scripts/templates/ldrddi.cpp.mako | 13 +++++++++++++ source/loader/ze_ldrddi.cpp | 16 ++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/templates/ldrddi.cpp.mako b/scripts/templates/ldrddi.cpp.mako index 9064cc0..f525d71 100644 --- a/scripts/templates/ldrddi.cpp.mako +++ b/scripts/templates/ldrddi.cpp.mako @@ -116,7 +116,11 @@ namespace loader %for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)): %if 0 == i: // extract driver's function pointer table + %if 'range' in item: + auto dditable = reinterpret_cast<${item['obj']}*>( ${item['name']}[ 0 ] )->dditable; + %else: auto dditable = reinterpret_cast<${item['obj']}*>( ${item['name']} )->dditable; + %endif auto ${th.make_pfn_name(n, tags, obj)} = dditable->${n}.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}; if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) return ${X}_RESULT_ERROR_UNINITIALIZED; @@ -181,9 +185,11 @@ namespace loader del add_local%> %for i, item in enumerate(th.get_loader_epilogue(n, tags, obj, meta)): %if 0 == i: + %if not re.match(r"\w+ModuleDynamicLink$", th.make_func_name(n, tags, obj)) and not re.match(r"\w+ModuleCreate$", th.make_func_name(n, tags, obj)): if( ${X}_RESULT_SUCCESS != result ) return result; + %endif %endif %if item['release']: // release loader handle @@ -225,6 +231,13 @@ namespace loader } %endif + %if 0 == i: + %if re.match(r"\w+ModuleDynamicLink$", th.make_func_name(n, tags, obj)) or re.match(r"\w+ModuleCreate$", th.make_func_name(n, tags, obj)): + if( ${X}_RESULT_SUCCESS != result ) + return result; + + %endif + %endif %endfor %endif return result; diff --git a/source/loader/ze_ldrddi.cpp b/source/loader/ze_ldrddi.cpp index 8f5a7bb..bc4e070 100644 --- a/source/loader/ze_ldrddi.cpp +++ b/source/loader/ze_ldrddi.cpp @@ -3071,9 +3071,6 @@ namespace loader // forward to device-driver result = pfnCreate( hContext, hDevice, desc, phModule, phBuildLog ); - if( ZE_RESULT_SUCCESS != result ) - return result; - try { // convert driver handle to loader handle @@ -3085,6 +3082,9 @@ namespace loader result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; } + if( ZE_RESULT_SUCCESS != result ) + return result; + try { // convert driver handle to loader handle @@ -3143,7 +3143,7 @@ namespace loader ze_result_t result = ZE_RESULT_SUCCESS; // extract driver's function pointer table - auto dditable = reinterpret_cast( phModules )->dditable; + auto dditable = reinterpret_cast( phModules[ 0 ] )->dditable; auto pfnDynamicLink = dditable->ze.Module.pfnDynamicLink; if( nullptr == pfnDynamicLink ) return ZE_RESULT_ERROR_UNINITIALIZED; @@ -3157,9 +3157,6 @@ namespace loader result = pfnDynamicLink( numModules, phModulesLocal, phLinkLog ); delete []phModulesLocal; - if( ZE_RESULT_SUCCESS != result ) - return result; - try { // convert driver handle to loader handle @@ -3172,6 +3169,9 @@ namespace loader result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; } + if( ZE_RESULT_SUCCESS != result ) + return result; + return result; } @@ -4818,7 +4818,7 @@ namespace loader ze_result_t result = ZE_RESULT_SUCCESS; // extract driver's function pointer table - auto dditable = reinterpret_cast( phModules )->dditable; + auto dditable = reinterpret_cast( phModules[ 0 ] )->dditable; auto pfnInspectLinkageExt = dditable->ze.Module.pfnInspectLinkageExt; if( nullptr == pfnInspectLinkageExt ) return ZE_RESULT_ERROR_UNINITIALIZED;