Add regression 1029 (Thread Local Storage)
Adds a test using the __thread attribute, used in the main executable
and in a shared library. The test is single threaded of course (OP-TEE
does not support threads at the moment), but it exercices some
previously unimplemented features:
- New TLS relocations (Aarch32, Aarch64)
- The __tls_get_addr() runtime helper (Aarch32 only)
Signed-off-by: Jerome Forissier <jerome@forissier.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c
index 1cde62c..efe1030 100644
--- a/host/xtest/regression_1000.c
+++ b/host/xtest/regression_1000.c
@@ -2199,3 +2199,30 @@
ADBG_CASE_DEFINE(regression, 1028, xtest_tee_test_1028,
"Session: group login for current user's effective group");
+
+static void xtest_tee_test_1029(ADBG_Case_t *c)
+{
+ TEEC_Session session = { 0 };
+ uint32_t ret_orig = 0;
+
+ if (!ADBG_EXPECT_TEEC_SUCCESS(c,
+ xtest_teec_open_session(&session, &os_test_ta_uuid,
+ NULL, &ret_orig)))
+ return;
+
+ Do_ADBG_BeginSubCase(c, "TLS variables (main program)");
+ ADBG_EXPECT_TEEC_SUCCESS(c,
+ TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TLS_TEST_MAIN, NULL,
+ &ret_orig));
+ Do_ADBG_EndSubCase(c, "TLS variables (main program)");
+
+ Do_ADBG_BeginSubCase(c, "TLS variables (shared library)");
+ ADBG_EXPECT_TEEC_SUCCESS(c,
+ TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TLS_TEST_SHLIB,
+ NULL, &ret_orig));
+ Do_ADBG_EndSubCase(c, "TLS variables (shared library)");
+
+ TEEC_CloseSession(&session);
+}
+ADBG_CASE_DEFINE(regression, 1029, xtest_tee_test_1029,
+ "Test __thread attribute");
diff --git a/ta/os_test/include/os_test.h b/ta/os_test/include/os_test.h
index 01892ad..6f05c0d 100644
--- a/ta/os_test/include/os_test.h
+++ b/ta/os_test/include/os_test.h
@@ -28,5 +28,7 @@
TEE_Result ta_entry_call_lib_dl_panic(uint32_t param_types, TEE_Param params[4]);
TEE_Result ta_entry_get_global_var(uint32_t param_types, TEE_Param params[4]);
TEE_Result ta_entry_client_identity(uint32_t param_types, TEE_Param params[4]);
+TEE_Result ta_entry_tls_test_main(void);
+TEE_Result ta_entry_tls_test_shlib(void);
#endif /*OS_TEST_H */
diff --git a/ta/os_test/include/ta_os_test.h b/ta/os_test/include/ta_os_test.h
index 736751e..2b8639c 100644
--- a/ta/os_test/include/ta_os_test.h
+++ b/ta/os_test/include/ta_os_test.h
@@ -30,5 +30,7 @@
#define TA_OS_TEST_CMD_GET_GLOBAL_VAR 18
#define TA_OS_TEST_CMD_NULL_MEMREF_PARAMS 19
#define TA_OS_TEST_CMD_CLIENT_IDENTITY 20
+#define TA_OS_TEST_CMD_TLS_TEST_MAIN 21
+#define TA_OS_TEST_CMD_TLS_TEST_SHLIB 22
#endif /*TA_OS_TEST_H */
diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c
index 7ec2377..11be6ec 100644
--- a/ta/os_test/os_test.c
+++ b/ta/os_test/os_test.c
@@ -1298,3 +1298,35 @@
return res;
}
+
+__thread int os_test_tls_a;
+__thread int os_test_tls_b = 42;
+
+TEE_Result ta_entry_tls_test_main(void)
+{
+ if (os_test_tls_a != 0) {
+ EMSG("os_test_tls_a=%d, expected 0", os_test_tls_a);
+ return TEE_ERROR_GENERIC;
+ }
+ if (os_test_tls_b != 42) {
+ EMSG("os_test_tls_b=%d, expected 42", os_test_tls_b);
+ return TEE_ERROR_GENERIC;
+ }
+
+ return TEE_SUCCESS;
+}
+
+TEE_Result ta_entry_tls_test_shlib(void)
+{
+ if (os_test_shlib_tls_a != 0) {
+ EMSG("os_test_shlib_tls_a=%d, expected 0", os_test_shlib_tls_a);
+ return TEE_ERROR_GENERIC;
+ }
+ if (os_test_shlib_tls_b != 123) {
+ EMSG("os_test_shlib_tls_b=%d, expected 123",
+ os_test_shlib_tls_b);
+ return TEE_ERROR_GENERIC;
+ }
+
+ return TEE_SUCCESS;
+}
diff --git a/ta/os_test/ta_entry.c b/ta/os_test/ta_entry.c
index d4733c0..0fb7629 100644
--- a/ta/os_test/ta_entry.c
+++ b/ta/os_test/ta_entry.c
@@ -109,6 +109,12 @@
case TA_OS_TEST_CMD_CLIENT_IDENTITY:
return ta_entry_client_identity(nParamTypes, pParams);
+ case TA_OS_TEST_CMD_TLS_TEST_MAIN:
+ return ta_entry_tls_test_main();
+
+ case TA_OS_TEST_CMD_TLS_TEST_SHLIB:
+ return ta_entry_tls_test_shlib();
+
default:
return TEE_ERROR_BAD_PARAMETERS;
}
diff --git a/ta/os_test_lib/os_test_lib.c b/ta/os_test_lib/os_test_lib.c
index f5c8127..17eb9bb 100644
--- a/ta/os_test_lib/os_test_lib.c
+++ b/ta/os_test_lib/os_test_lib.c
@@ -16,6 +16,9 @@
DMSG("os_test_global=%d", os_test_global);
}
+__thread int os_test_shlib_tls_a;
+__thread int os_test_shlib_tls_b = 123;
+
int os_test_shlib_add(int a, int b)
{
return a + b;