Jerome Forissier | 1a205ae | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-2-Clause |
| 2 | /* |
| 3 | * Copyright (c) 2020 Huawei Technologies Co., Ltd |
| 4 | */ |
| 5 | |
| 6 | extern "C" { |
| 7 | |
| 8 | #include <dlfcn.h> |
| 9 | #include <os_test_lib.h> |
| 10 | #include <stdint.h> |
| 11 | #include <tee_ta_api.h> |
| 12 | |
| 13 | #include "cxx_tests.h" |
| 14 | #include "os_test.h" |
| 15 | |
| 16 | }; |
| 17 | |
| 18 | class CtorTest { |
| 19 | public: |
| 20 | CtorTest() : val(1) {} |
| 21 | |
| 22 | int val; |
| 23 | }; |
| 24 | |
| 25 | static CtorTest ctor_test; |
| 26 | |
| 27 | TEE_Result ta_entry_cxx_ctor_main(void) |
| 28 | { |
| 29 | if (ctor_test.val != 1) |
| 30 | return TEE_ERROR_GENERIC; |
| 31 | |
| 32 | return TEE_SUCCESS; |
| 33 | } |
| 34 | |
| 35 | TEE_Result ta_entry_cxx_ctor_shlib(void) |
| 36 | { |
| 37 | return os_test_shlib_cxx_ctor(); |
| 38 | } |
| 39 | |
| 40 | TEE_Result ta_entry_cxx_ctor_shlib_dl(void) |
| 41 | { |
| 42 | TEE_Result res = TEE_ERROR_GENERIC; |
| 43 | TEE_Result (*ctor_test_fn)(void); |
| 44 | void *handle = NULL; |
| 45 | |
| 46 | handle = dlopen("b3091a65-9751-4784-abf7-0298a7cc35ba", |
| 47 | RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); |
| 48 | if (!handle) |
| 49 | return TEE_ERROR_GENERIC; |
| 50 | |
| 51 | ctor_test_fn = (TEE_Result (*)(void))dlsym(handle, |
| 52 | "os_test_shlib_dl_cxx_ctor"); |
| 53 | if (ctor_test_fn) |
| 54 | res = ctor_test_fn(); |
| 55 | |
| 56 | dlclose(handle); |
| 57 | return res; |
| 58 | } |
| 59 | |
| 60 | class MyException { |
| 61 | }; |
| 62 | |
| 63 | TEE_Result ta_entry_cxx_exc_main(void) |
| 64 | { |
| 65 | try { |
| 66 | throw MyException(); |
| 67 | } catch (MyException &e) { |
| 68 | return TEE_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | return TEE_ERROR_GENERIC; |
| 72 | } |
| 73 | |
| 74 | class MixedFrameException { |
| 75 | }; |
| 76 | |
| 77 | void throw_mfe(void) |
| 78 | { |
| 79 | throw MixedFrameException(); |
| 80 | } |
| 81 | |
| 82 | class MixedFrameExceptionTest { |
| 83 | public: |
| 84 | MixedFrameExceptionTest() {} |
| 85 | |
| 86 | bool test(); |
| 87 | }; |
| 88 | |
| 89 | bool MixedFrameExceptionTest::test() |
| 90 | { |
| 91 | try { |
| 92 | throwing_c_func(); |
| 93 | } catch (MixedFrameException e) { |
| 94 | return true; |
| 95 | } |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | TEE_Result ta_entry_cxx_exc_mixed(void) |
| 100 | { |
| 101 | MixedFrameExceptionTest test; |
| 102 | |
| 103 | if (test.test()) |
| 104 | return TEE_SUCCESS; |
| 105 | |
| 106 | return TEE_ERROR_GENERIC; |
| 107 | } |