blob: 1761843698c5bc44d1f52bba3ced00a7ddec5555 [file] [log] [blame]
Jerome Forissier1a205ae2020-06-17 17:55:00 +02001// SPDX-License-Identifier: BSD-2-Clause
2/*
3 * Copyright (c) 2020 Huawei Technologies Co., Ltd
4 */
5
6extern "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
18class CtorTest {
19public:
20 CtorTest() : val(1) {}
21
22 int val;
23};
24
25static CtorTest ctor_test;
26
27TEE_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
35TEE_Result ta_entry_cxx_ctor_shlib(void)
36{
37 return os_test_shlib_cxx_ctor();
38}
39
40TEE_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
60class MyException {
61};
62
63TEE_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
74class MixedFrameException {
75};
76
77void throw_mfe(void)
78{
79 throw MixedFrameException();
80}
81
82class MixedFrameExceptionTest {
83public:
84 MixedFrameExceptionTest() {}
85
86 bool test();
87};
88
89bool MixedFrameExceptionTest::test()
90{
91 try {
92 throwing_c_func();
93 } catch (MixedFrameException e) {
94 return true;
95 }
96 return false;
97}
98
99TEE_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}