2021-01-12 07:54:04 +01:00
|
|
|
/*
|
|
|
|
* Copyright The Mbed TLS Contributors
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-03-05 06:09:37 +01:00
|
|
|
* \file mps_trace.h
|
2021-01-12 07:54:04 +01:00
|
|
|
*
|
|
|
|
* \brief Tracing module for MPS
|
|
|
|
*/
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#ifndef MBEDTLS_MPS_MBEDTLS_MPS_TRACE_H
|
|
|
|
#define MBEDTLS_MPS_MBEDTLS_MPS_TRACE_H
|
2021-01-12 07:54:04 +01:00
|
|
|
|
|
|
|
#include "common.h"
|
2021-01-28 08:08:08 +01:00
|
|
|
#include "mps_common.h"
|
|
|
|
#include "mps_trace.h"
|
2021-01-12 07:54:04 +01:00
|
|
|
|
2021-01-12 10:46:03 +01:00
|
|
|
#include "mbedtls/platform.h"
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#if defined(MBEDTLS_MPS_ENABLE_TRACE)
|
2021-01-12 07:54:04 +01:00
|
|
|
|
2021-01-12 10:46:03 +01:00
|
|
|
/*
|
|
|
|
* Adapt this to enable/disable tracing output
|
|
|
|
* from the various layers of the MPS.
|
|
|
|
*/
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_ENABLE_LAYER_1
|
|
|
|
#define MBEDTLS_MPS_TRACE_ENABLE_LAYER_2
|
|
|
|
#define MBEDTLS_MPS_TRACE_ENABLE_LAYER_3
|
|
|
|
#define MBEDTLS_MPS_TRACE_ENABLE_LAYER_4
|
|
|
|
#define MBEDTLS_MPS_TRACE_ENABLE_READER
|
|
|
|
#define MBEDTLS_MPS_TRACE_ENABLE_WRITER
|
2021-01-12 10:46:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To use the existing trace module, only change
|
2021-01-28 10:02:18 +01:00
|
|
|
* MBEDTLS_MPS_TRACE_ENABLE_XXX above, but don't modify the
|
2021-01-12 10:46:03 +01:00
|
|
|
* rest of this file.
|
|
|
|
*/
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef enum {
|
2021-04-07 13:44:02 +02:00
|
|
|
MBEDTLS_MPS_TRACE_TYPE_COMMENT,
|
|
|
|
MBEDTLS_MPS_TRACE_TYPE_CALL,
|
|
|
|
MBEDTLS_MPS_TRACE_TYPE_ERROR,
|
|
|
|
MBEDTLS_MPS_TRACE_TYPE_RETURN
|
2021-01-28 10:02:18 +01:00
|
|
|
} mbedtls_mps_trace_type;
|
|
|
|
|
|
|
|
#define MBEDTLS_MPS_TRACE_BIT_LAYER_1 1
|
|
|
|
#define MBEDTLS_MPS_TRACE_BIT_LAYER_2 2
|
|
|
|
#define MBEDTLS_MPS_TRACE_BIT_LAYER_3 3
|
|
|
|
#define MBEDTLS_MPS_TRACE_BIT_LAYER_4 4
|
|
|
|
#define MBEDTLS_MPS_TRACE_BIT_WRITER 5
|
|
|
|
#define MBEDTLS_MPS_TRACE_BIT_READER 6
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_MPS_TRACE_ENABLE_LAYER_1)
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_LAYER_1 (1u << MBEDTLS_MPS_TRACE_BIT_LAYER_1)
|
2021-01-12 10:46:03 +01:00
|
|
|
#else
|
2021-01-28 10:02:18 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_LAYER_1 0
|
2021-01-12 10:46:03 +01:00
|
|
|
#endif
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#if defined(MBEDTLS_MPS_TRACE_ENABLE_LAYER_2)
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_LAYER_2 (1u << MBEDTLS_MPS_TRACE_BIT_LAYER_2)
|
2021-01-12 10:46:03 +01:00
|
|
|
#else
|
2021-01-28 10:02:18 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_LAYER_2 0
|
2021-01-12 10:46:03 +01:00
|
|
|
#endif
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#if defined(MBEDTLS_MPS_TRACE_ENABLE_LAYER_3)
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_LAYER_3 (1u << MBEDTLS_MPS_TRACE_BIT_LAYER_3)
|
2021-01-12 10:46:03 +01:00
|
|
|
#else
|
2021-01-28 10:02:18 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_LAYER_3 0
|
2021-01-12 10:46:03 +01:00
|
|
|
#endif
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#if defined(MBEDTLS_MPS_TRACE_ENABLE_LAYER_4)
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_LAYER_4 (1u << MBEDTLS_MPS_TRACE_BIT_LAYER_4)
|
2021-01-12 10:46:03 +01:00
|
|
|
#else
|
2021-01-28 10:02:18 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_LAYER_4 0
|
2021-01-12 10:46:03 +01:00
|
|
|
#endif
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#if defined(MBEDTLS_MPS_TRACE_ENABLE_READER)
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_READER (1u << MBEDTLS_MPS_TRACE_BIT_READER)
|
2021-01-12 10:46:03 +01:00
|
|
|
#else
|
2021-01-28 10:02:18 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_READER 0
|
2021-01-12 10:46:03 +01:00
|
|
|
#endif
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#if defined(MBEDTLS_MPS_TRACE_ENABLE_WRITER)
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_WRITER (1u << MBEDTLS_MPS_TRACE_BIT_WRITER)
|
2021-01-12 10:46:03 +01:00
|
|
|
#else
|
2021-01-28 10:02:18 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK_WRITER 0
|
2021-01-12 10:46:03 +01:00
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_MASK (MBEDTLS_MPS_TRACE_MASK_LAYER_1 | \
|
|
|
|
MBEDTLS_MPS_TRACE_MASK_LAYER_2 | \
|
|
|
|
MBEDTLS_MPS_TRACE_MASK_LAYER_3 | \
|
|
|
|
MBEDTLS_MPS_TRACE_MASK_LAYER_4 | \
|
|
|
|
MBEDTLS_MPS_TRACE_MASK_READER | \
|
|
|
|
MBEDTLS_MPS_TRACE_MASK_WRITER)
|
2021-01-12 10:46:03 +01:00
|
|
|
|
|
|
|
/* We have to avoid globals because E-ACSL chokes on them...
|
|
|
|
* Wrap everything in stub functions. */
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_mps_trace_get_depth(void);
|
|
|
|
void mbedtls_mps_trace_inc_depth(void);
|
|
|
|
void mbedtls_mps_trace_dec_depth(void);
|
2021-01-28 10:02:18 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_mps_trace_color(int id);
|
|
|
|
void mbedtls_mps_trace_indent(int level, mbedtls_mps_trace_type ty);
|
2021-01-28 10:02:18 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_mps_trace_print_msg(int id, int line, const char *format, ...);
|
2021-01-28 10:02:18 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE(type, ...) \
|
2021-01-28 10:02:18 +01:00
|
|
|
do { \
|
2023-01-11 14:50:10 +01:00
|
|
|
if (!(MBEDTLS_MPS_TRACE_MASK & (1u << mbedtls_mps_trace_id))) \
|
|
|
|
break; \
|
|
|
|
mbedtls_mps_trace_indent(mbedtls_mps_trace_get_depth(), type); \
|
|
|
|
mbedtls_mps_trace_color(mbedtls_mps_trace_id); \
|
|
|
|
mbedtls_mps_trace_print_msg(mbedtls_mps_trace_id, __LINE__, __VA_ARGS__); \
|
|
|
|
mbedtls_mps_trace_color(0); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define MBEDTLS_MPS_TRACE_INIT(...) \
|
2021-01-28 10:02:18 +01:00
|
|
|
do { \
|
2023-01-11 14:50:10 +01:00
|
|
|
if (!(MBEDTLS_MPS_TRACE_MASK & (1u << mbedtls_mps_trace_id))) \
|
|
|
|
break; \
|
|
|
|
MBEDTLS_MPS_TRACE(MBEDTLS_MPS_TRACE_TYPE_CALL, __VA_ARGS__); \
|
2021-01-28 10:02:18 +01:00
|
|
|
mbedtls_mps_trace_inc_depth(); \
|
2023-01-11 14:50:10 +01:00
|
|
|
} while (0)
|
2021-01-12 10:46:03 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_END(val) \
|
2021-01-28 10:02:18 +01:00
|
|
|
do { \
|
2023-01-11 14:50:10 +01:00
|
|
|
if (!(MBEDTLS_MPS_TRACE_MASK & (1u << mbedtls_mps_trace_id))) \
|
|
|
|
break; \
|
|
|
|
MBEDTLS_MPS_TRACE(MBEDTLS_MPS_TRACE_TYPE_RETURN, "%d (-%#04x)", \
|
|
|
|
(int) (val), -((unsigned) (val))); \
|
2021-01-28 10:02:18 +01:00
|
|
|
mbedtls_mps_trace_dec_depth(); \
|
2023-01-11 14:50:10 +01:00
|
|
|
} while (0)
|
2021-01-12 10:46:03 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_RETURN(val) \
|
2021-01-12 10:46:03 +01:00
|
|
|
do { \
|
|
|
|
/* Breaks tail recursion. */ \
|
|
|
|
int ret__ = val; \
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_MPS_TRACE_END(ret__); \
|
|
|
|
return ret__; \
|
|
|
|
} while (0)
|
2021-01-12 07:54:04 +01:00
|
|
|
|
|
|
|
#else /* MBEDTLS_MPS_TRACE */
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE(type, ...) do { } while (0)
|
|
|
|
#define MBEDTLS_MPS_TRACE_INIT(...) do { } while (0)
|
|
|
|
#define MBEDTLS_MPS_TRACE_END do { } while (0)
|
2021-01-12 07:54:04 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPS_TRACE_RETURN(val) return val;
|
2021-01-12 07:54:04 +01:00
|
|
|
|
|
|
|
#endif /* MBEDTLS_MPS_TRACE */
|
|
|
|
|
2021-01-28 10:02:18 +01:00
|
|
|
#endif /* MBEDTLS_MPS_MBEDTLS_MPS_TRACE_H */
|