|
| 1 | +<%! |
| 2 | +import re |
| 3 | +from templates import helper as th |
| 4 | +%><% |
| 5 | + n=namespace |
| 6 | + N=n.upper() |
| 7 | +
|
| 8 | + x=tags['$x'] |
| 9 | + X=x.upper() |
| 10 | +
|
| 11 | + handle_create_get_retain_release_funcs=th.get_handle_create_get_retain_release_functions(specs, n, tags) |
| 12 | +%>/* |
| 13 | + * |
| 14 | + * Copyright (C) 2023-2024 Intel Corporation |
| 15 | + * |
| 16 | + * Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. |
| 17 | + * See LICENSE.TXT |
| 18 | + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 19 | + * |
| 20 | + * @file ${name}.cpp |
| 21 | + * |
| 22 | + */ |
| 23 | +#include "${x}_exception_sanitizer_layer.hpp" |
| 24 | + |
| 25 | +namespace ur_exception_sanitizer_layer |
| 26 | +{ |
| 27 | + %for obj in th.get_adapter_functions(specs): |
| 28 | + <% |
| 29 | + func_name=th.make_func_name(n, tags, obj) |
| 30 | +
|
| 31 | + param_checks=th.make_param_checks(n, tags, obj, meta=meta).items() |
| 32 | + first_errors = [X + "_RESULT_ERROR_INVALID_NULL_POINTER", X + "_RESULT_ERROR_INVALID_NULL_HANDLE"] |
| 33 | + sorted_param_checks = sorted(param_checks, key=lambda pair: False if pair[0] in first_errors else True) |
| 34 | +
|
| 35 | + 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'])) |
| 36 | + %> |
| 37 | + /////////////////////////////////////////////////////////////////////////////// |
| 38 | + /// @brief Intercept function for ${th.make_func_name(n, tags, obj)} |
| 39 | + %if 'condition' in obj: |
| 40 | + #if ${th.subt(n, tags, obj['condition'])} |
| 41 | + %endif |
| 42 | + __${x}dlllocal ${x}_result_t ${X}_APICALL |
| 43 | + ${func_name}( |
| 44 | + %for line in th.make_param_lines(n, tags, obj): |
| 45 | + ${line} |
| 46 | + %endfor |
| 47 | + ) |
| 48 | + {${th.get_initial_null_set(obj)} |
| 49 | + 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)}; |
| 50 | + |
| 51 | + if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) { |
| 52 | + return ${X}_RESULT_ERROR_UNINITIALIZED; |
| 53 | + } |
| 54 | + |
| 55 | + ${x}_result_t result = UR_RESULT_SUCCESS; |
| 56 | + try { |
| 57 | + result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} ); |
| 58 | + } catch (...) { |
| 59 | + std::cerr << "Exception caught from adapter layer in " << __func__ << " aborting\n"; |
| 60 | + } |
| 61 | + |
| 62 | + return result; |
| 63 | + } |
| 64 | + %if 'condition' in obj: |
| 65 | + #endif // ${th.subt(n, tags, obj['condition'])} |
| 66 | + %endif |
| 67 | + |
| 68 | + %endfor |
| 69 | + %for tbl in th.get_pfntables(specs, meta, n, tags): |
| 70 | + /////////////////////////////////////////////////////////////////////////////// |
| 71 | + /// @brief Exported function for filling application's ${tbl['name']} table |
| 72 | + /// with current process' addresses |
| 73 | + /// |
| 74 | + /// @returns |
| 75 | + /// - ::${X}_RESULT_SUCCESS |
| 76 | + /// - ::${X}_RESULT_ERROR_INVALID_NULL_POINTER |
| 77 | + /// - ::${X}_RESULT_ERROR_UNSUPPORTED_VERSION |
| 78 | + ${X}_DLLEXPORT ${x}_result_t ${X}_APICALL |
| 79 | + ${tbl['export']['name']}( |
| 80 | + %for line in th.make_param_lines(n, tags, tbl['export']): |
| 81 | + ${line} |
| 82 | + %endfor |
| 83 | + ) |
| 84 | + { |
| 85 | + auto& dditable = ur_exception_sanitizer_layer::getContext()->${n}DdiTable.${tbl['name']}; |
| 86 | + |
| 87 | + if( nullptr == pDdiTable ) |
| 88 | + return ${X}_RESULT_ERROR_INVALID_NULL_POINTER; |
| 89 | + |
| 90 | + if (UR_MAJOR_VERSION(ur_exception_sanitizer_layer::getContext()->version) != UR_MAJOR_VERSION(version) || |
| 91 | + UR_MINOR_VERSION(ur_exception_sanitizer_layer::getContext()->version) > UR_MINOR_VERSION(version)) |
| 92 | + return ${X}_RESULT_ERROR_UNSUPPORTED_VERSION; |
| 93 | + |
| 94 | + ${x}_result_t result = ${X}_RESULT_SUCCESS; |
| 95 | + |
| 96 | + %for obj in tbl['functions']: |
| 97 | + %if 'condition' in obj: |
| 98 | + #if ${th.subt(n, tags, obj['condition'])} |
| 99 | + %endif |
| 100 | + dditable.${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = pDdiTable->${th.make_pfn_name(n, tags, obj)}; |
| 101 | + pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 41)} = ur_exception_sanitizer_layer::${th.make_func_name(n, tags, obj)}; |
| 102 | + %if 'condition' in obj: |
| 103 | + #else |
| 104 | + dditable.${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = nullptr; |
| 105 | + pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 41)} = nullptr; |
| 106 | + #endif |
| 107 | + %endif |
| 108 | + |
| 109 | + %endfor |
| 110 | + return result; |
| 111 | + } |
| 112 | + |
| 113 | + %endfor |
| 114 | + ${x}_result_t |
| 115 | + context_t::init(ur_dditable_t *dditable, |
| 116 | + const std::set<std::string> &enabledLayerNames, |
| 117 | + codeloc_data) { |
| 118 | + ${x}_result_t result = ${X}_RESULT_SUCCESS; |
| 119 | + |
| 120 | + return result; |
| 121 | + } |
| 122 | + |
| 123 | + ${x}_result_t context_t::tearDown() { |
| 124 | + return ${X}_RESULT_SUCCESS; |
| 125 | + } |
| 126 | + |
| 127 | +} // namespace ur_exception_sanitizer_layer |
0 commit comments