2016-03-11 21:02:00 +01:00
|
|
|
/****************************************************************************
|
2021-06-10 07:51:27 +02:00
|
|
|
* apps/testing/ostest/tls.c
|
2016-03-11 21:02:00 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-03-11 21:02:00 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-03-11 21:02:00 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-03-11 21:02:00 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <nuttx/tls.h>
|
|
|
|
|
|
|
|
#include "ostest.h"
|
|
|
|
|
2020-05-07 17:56:21 +02:00
|
|
|
#if CONFIG_TLS_NELEM > 0
|
2016-03-11 21:02:00 +01:00
|
|
|
|
2022-05-27 04:06:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Preprocessor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define copy_tls_info(a, b) memcpy(a, b, sizeof(struct tls_info_s))
|
|
|
|
|
2016-03-11 21:02:00 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static struct tls_info_s g_save_info;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void get_tls_info(FAR struct tls_info_s *info)
|
|
|
|
{
|
2022-05-27 04:06:17 +02:00
|
|
|
copy_tls_info(info, tls_get_info());
|
2016-03-11 21:02:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void put_tls_info(FAR const struct tls_info_s *info)
|
|
|
|
{
|
2022-05-27 04:06:17 +02:00
|
|
|
copy_tls_info(tls_get_info(), info);
|
2016-03-11 21:02:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_tls_info(uintptr_t value)
|
|
|
|
{
|
2022-05-27 04:06:17 +02:00
|
|
|
FAR struct tls_info_s *info = tls_get_info();
|
2016-03-11 21:02:00 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_TLS_NELEM; i++)
|
|
|
|
{
|
|
|
|
info->tl_elem[i] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool verify_tls_info(uintptr_t value)
|
|
|
|
{
|
2022-05-27 04:06:17 +02:00
|
|
|
FAR struct tls_info_s *info = tls_get_info();
|
2016-03-11 21:02:00 +01:00
|
|
|
bool fail = false;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_TLS_NELEM; i++)
|
|
|
|
{
|
|
|
|
if (info->tl_elem[i] != value)
|
|
|
|
{
|
|
|
|
printf("tls: ERROR Element %d: Set %lx / read %lx\n",
|
|
|
|
i, (unsigned long)value,
|
|
|
|
(unsigned long)info->tl_elem[i]);
|
2018-08-13 15:47:26 +02:00
|
|
|
fail = true;
|
2016-03-11 21:02:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_tls_test(uintptr_t value)
|
|
|
|
{
|
|
|
|
set_tls_info(value);
|
|
|
|
if (!verify_tls_info(value))
|
|
|
|
{
|
|
|
|
printf("tls: Successfully set %lx\n", (unsigned long)value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void tls_test(void)
|
|
|
|
{
|
|
|
|
get_tls_info(&g_save_info);
|
|
|
|
do_tls_test(0);
|
|
|
|
do_tls_test(0xffffffff);
|
|
|
|
do_tls_test(0x55555555);
|
|
|
|
do_tls_test(0xaaaaaaaa);
|
|
|
|
put_tls_info(&g_save_info);
|
|
|
|
}
|
|
|
|
|
2020-05-07 17:56:21 +02:00
|
|
|
#endif /* CONFIG_TLS_NELEM > 0 */
|