-
Notifications
You must be signed in to change notification settings - Fork 124
[UR][layer] Add exception sanitizer layer #2216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eba8ddd
Add exception sanitizer layer
394955e
Add CI testing
d9d67de
Add getNames entrypoint in context
cc8193e
Update autogenerated file
d7813a1
Update cmake and fix typo
e3b9bc8
Add try catch in command_buffer.cpp
dbe486a
Change func def
b490eda
Update CMakeLists.txt
8762181
Update .github/workflows/build-hw-reusable.yml
49cdec0
Remove cmake option
cc4cc64
Only enable layer when configured
fc595ea
Merge branch 'main' into except-san-layer
56287f5
Fix typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| <%! | ||
| import re | ||
| from templates import helper as th | ||
| %><% | ||
| n=namespace | ||
| N=n.upper() | ||
|
|
||
| x=tags['$x'] | ||
| X=x.upper() | ||
|
|
||
| handle_create_get_retain_release_funcs=th.get_handle_create_get_retain_release_functions(specs, n, tags) | ||
| %>/* | ||
| * | ||
| * Copyright (C) 2023-2024 Intel Corporation | ||
| * | ||
| * Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| * See LICENSE.TXT | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| * | ||
| * @file ${name}.cpp | ||
| * | ||
| */ | ||
| #include "${x}_exception_sanitizer_layer.hpp" | ||
|
|
||
| namespace ur_exception_sanitizer_layer | ||
| { | ||
| %for obj in th.get_adapter_functions(specs): | ||
| <% | ||
| func_name=th.make_func_name(n, tags, obj) | ||
|
|
||
| param_checks=th.make_param_checks(n, tags, obj, meta=meta).items() | ||
| first_errors = [X + "_RESULT_ERROR_INVALID_NULL_POINTER", X + "_RESULT_ERROR_INVALID_NULL_HANDLE"] | ||
| sorted_param_checks = sorted(param_checks, key=lambda pair: False if pair[0] in first_errors else True) | ||
|
|
||
| tracked_params = list(filter(lambda p: any(th.subt(n, tags, p['type']) in [hf['handle'], hf['handle'] + "*"] for hf in handle_create_get_retain_release_funcs), obj['params'])) | ||
| %> | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| /// @brief Intercept function for ${th.make_func_name(n, tags, obj)} | ||
| %if 'condition' in obj: | ||
| #if ${th.subt(n, tags, obj['condition'])} | ||
| %endif | ||
| __${x}dlllocal ${x}_result_t ${X}_APICALL | ||
| ${func_name}( | ||
| %for line in th.make_param_lines(n, tags, obj): | ||
| ${line} | ||
| %endfor | ||
| ) | ||
| {${th.get_initial_null_set(obj)} | ||
| auto ${th.make_pfn_name(n, tags, obj)} = getContext()->${n}DdiTable.${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; | ||
| } | ||
|
|
||
| ${x}_result_t result = UR_RESULT_SUCCESS; | ||
| try { | ||
| result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); | ||
| } catch (...) { | ||
| std::cerr << "Exception caught from adapter layer in " << __func__ << " aborting\n"; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| %if 'condition' in obj: | ||
| #endif // ${th.subt(n, tags, obj['condition'])} | ||
| %endif | ||
|
|
||
| %endfor | ||
| %for tbl in th.get_pfntables(specs, meta, n, tags): | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| /// @brief Exported function for filling application's ${tbl['name']} table | ||
| /// with current process' addresses | ||
| /// | ||
| /// @returns | ||
| /// - ::${X}_RESULT_SUCCESS | ||
| /// - ::${X}_RESULT_ERROR_INVALID_NULL_POINTER | ||
| /// - ::${X}_RESULT_ERROR_UNSUPPORTED_VERSION | ||
| ${X}_DLLEXPORT ${x}_result_t ${X}_APICALL | ||
| ${tbl['export']['name']}( | ||
| %for line in th.make_param_lines(n, tags, tbl['export']): | ||
| ${line} | ||
| %endfor | ||
| ) | ||
| { | ||
| auto& dditable = ur_exception_sanitizer_layer::getContext()->${n}DdiTable.${tbl['name']}; | ||
|
|
||
| if( nullptr == pDdiTable ) | ||
| return ${X}_RESULT_ERROR_INVALID_NULL_POINTER; | ||
|
|
||
| if (UR_MAJOR_VERSION(ur_exception_sanitizer_layer::getContext()->version) != UR_MAJOR_VERSION(version) || | ||
| UR_MINOR_VERSION(ur_exception_sanitizer_layer::getContext()->version) > UR_MINOR_VERSION(version)) | ||
| return ${X}_RESULT_ERROR_UNSUPPORTED_VERSION; | ||
|
|
||
| ${x}_result_t result = ${X}_RESULT_SUCCESS; | ||
|
|
||
| %for obj in tbl['functions']: | ||
| %if 'condition' in obj: | ||
| #if ${th.subt(n, tags, obj['condition'])} | ||
| %endif | ||
| dditable.${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = pDdiTable->${th.make_pfn_name(n, tags, obj)}; | ||
| pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 41)} = ur_exception_sanitizer_layer::${th.make_func_name(n, tags, obj)}; | ||
| %if 'condition' in obj: | ||
| #else | ||
| dditable.${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = nullptr; | ||
| pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 41)} = nullptr; | ||
| #endif | ||
| %endif | ||
|
|
||
| %endfor | ||
| return result; | ||
| } | ||
|
|
||
| %endfor | ||
| ${x}_result_t | ||
| context_t::init(ur_dditable_t *dditable, | ||
| const std::set<std::string> & enabledLayerNames, | ||
| codeloc_data) { | ||
| ${x}_result_t result = ${X}_RESULT_SUCCESS; | ||
| if (!enabledLayerNames.count(name)){ | ||
| return result; | ||
| } | ||
|
|
||
| %for tbl in th.get_pfntables(specs, meta, n, tags): | ||
| if( ${X}_RESULT_SUCCESS == result ) | ||
| { | ||
| result = ur_exception_sanitizer_layer::${tbl['export']['name']}( ${X}_API_VERSION_CURRENT, &dditable->${tbl['name']} ); | ||
| } | ||
|
|
||
| %endfor | ||
| return result; | ||
| } | ||
|
|
||
| } // namespace ur_exception_sanitizer_layer | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.