first submission
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
static_library("exchook") {
|
||||
sources = [
|
||||
"los_exc_info.c",
|
||||
"los_exchook.c",
|
||||
]
|
||||
include_dirs = [
|
||||
"../../kernel/arch/include",
|
||||
"../../kernel/include",
|
||||
"../../utils",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_exc_info.h"
|
||||
#include "securec.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_exchook.h"
|
||||
#include "los_membox.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
#define EXC_MSG_ARRAY_INIT_VALUE 0xff
|
||||
#define EXC_INT_STATUS_LEN (OS_NVIC_INT_ENABLE_SIZE + OS_NVIC_INT_PEND_SIZE + \
|
||||
OS_NVIC_INT_ACT_SIZE + OS_NVIC_INT_PRI_SIZE + \
|
||||
OS_NVIC_EXCPRI_SIZE + OS_NVIC_SHCSR_SIZE + \
|
||||
OS_NVIC_INT_CTRL_SIZE)
|
||||
|
||||
UINT32 g_excQueueMaxNum;
|
||||
UINT32 g_excMemMaxNum;
|
||||
VOID *g_excContent = NULL;
|
||||
UINT32 g_excArraySize = MAX_EXC_MEM_SIZE;
|
||||
UINT8 g_excMsgArray[MAX_EXC_MEM_SIZE];
|
||||
STATIC ExcInfoArray g_excArray[OS_EXC_TYPE_MAX];
|
||||
|
||||
STATIC UINT32 OsExcSaveIntStatus(UINT32 type, VOID *arg)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINTPTR excContentEnd = (UINTPTR)MAX_INT_INFO_SIZE + (UINTPTR)g_excContent;
|
||||
|
||||
(VOID)arg;
|
||||
|
||||
*((UINT32 *)g_excContent) = type;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
*((UINT32 *)g_excContent) = EXC_INT_STATUS_LEN;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
/* save IRQ ENABLE reg group */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_SETENA_BASE, OS_NVIC_INT_ENABLE_SIZE);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_ENABLE_SIZE;
|
||||
|
||||
/* save IRQ PEND reg group */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_SETPEND_BASE, OS_NVIC_INT_PEND_SIZE);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PEND_SIZE;
|
||||
|
||||
/* save IRQ ACTIVE reg group */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_INT_ACT_BASE, OS_NVIC_INT_ACT_SIZE);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_ACT_SIZE;
|
||||
|
||||
/* save IRQ Priority reg group */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_PRI_BASE, OS_NVIC_INT_PRI_SIZE);
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_PRI_SIZE;
|
||||
|
||||
/* save Exception Priority reg group */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_EXCPRI_BASE, OS_NVIC_EXCPRI_SIZE);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_EXCPRI_SIZE;
|
||||
|
||||
/* save IRQ Handler & SHCSR */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_SHCSR, OS_NVIC_SHCSR_SIZE);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_SHCSR_SIZE;
|
||||
|
||||
/* save IRQ Control & ICSR */
|
||||
ret = memcpy_s(g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(const VOID *)OS_NVIC_INT_CTRL, OS_NVIC_INT_CTRL_SIZE);
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + OS_NVIC_INT_CTRL_SIZE;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsExcMemMsgGet(UINT32 type, VOID *arg)
|
||||
{
|
||||
UINT32 count;
|
||||
UINT32 memNum = *(UINT32 *)arg;
|
||||
UINTPTR memMsgEnd = (UINTPTR)g_excContent + MAX_MEM_INFO_SIZE;
|
||||
|
||||
*((UINT32 *)g_excContent) = type;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
*((UINT32 *)g_excContent) = sizeof(MemInfoCB) * memNum;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
count = OsMemboxExcInfoGet(memNum, g_excContent);
|
||||
if (count < memNum) {
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(MemInfoCB) * count;
|
||||
(VOID)OsMemExcInfoGet(memNum - count, g_excContent);
|
||||
}
|
||||
g_excContent = (VOID *)memMsgEnd;
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsExcContentGet(UINT32 type, VOID *arg)
|
||||
{
|
||||
UINTPTR excContentEnd = MAX_EXC_MEM_SIZE + (UINTPTR)g_excMsgArray;
|
||||
errno_t ret;
|
||||
|
||||
(VOID)arg;
|
||||
|
||||
/* save exception info */
|
||||
*((UINT32 *)g_excContent) = type;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
*((UINT32 *)g_excContent) = sizeof(ExcInfo) + sizeof(EXC_CONTEXT_S);
|
||||
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
ret = memcpy_s((VOID *)g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
(VOID *)&g_excInfo, sizeof(ExcInfo));
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(ExcInfo);
|
||||
|
||||
ret = memcpy_s((VOID *)g_excContent, excContentEnd - (UINTPTR)g_excContent,
|
||||
g_excInfo.context, sizeof(EXC_CONTEXT_S));
|
||||
if (ret != EOK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(EXC_CONTEXT_S);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsExcHookFunc(UINT32 type, UINT32 index, UINT32 loop, UINT32 len, EXC_INFO_SAVE_CALLBACK func)
|
||||
{
|
||||
UINT32 i;
|
||||
|
||||
*((UINT32 *)g_excContent) = (UINT32)type;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
*((UINT32 *)g_excContent) = len * loop;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
for (i = index; i < loop; i++) {
|
||||
(VOID)func(i, g_excContent);
|
||||
g_excContent = (UINT8 *)g_excContent + len;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == 1)
|
||||
STATIC UINT32 OsExcQueueMsgGet(UINT32 type, VOID *arg)
|
||||
{
|
||||
UINT32 len = sizeof(QUEUE_INFO_S);
|
||||
UINT32 loop = *(UINT32 *)arg;
|
||||
|
||||
return OsExcHookFunc(type, 1, loop, len, (EXC_INFO_SAVE_CALLBACK)LOS_QueueInfoGet);
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC UINT32 OsExcTaskMsgGet(UINT32 type, VOID *arg)
|
||||
{
|
||||
UINT32 len = sizeof(TSK_INFO_S);
|
||||
UINT32 loop = *(UINT32 *)arg;
|
||||
|
||||
return OsExcHookFunc(type, 0, loop, len, (EXC_INFO_SAVE_CALLBACK)LOS_TaskInfoGet);
|
||||
}
|
||||
|
||||
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == 1)
|
||||
STATIC UINT32 OsExcTskSwitchMsgGet(UINT32 type, VOID *arg)
|
||||
{
|
||||
UINT32 len;
|
||||
UINT32 loop;
|
||||
UINT32 taskSwitchCount;
|
||||
TaskSwitchInfo *taskSwitchInfo = NULL;
|
||||
UINT32 i;
|
||||
|
||||
/* not necessary, just for macro int library */
|
||||
taskSwitchInfo = (TaskSwitchInfo *)arg;
|
||||
taskSwitchCount = taskSwitchInfo->cntInfo.maxCnt;
|
||||
len = sizeof(UINT32) + (sizeof(CHAR) * LOS_TASK_NAMELEN);
|
||||
if (taskSwitchInfo->cntInfo.isFull) {
|
||||
i = taskSwitchInfo->idx;
|
||||
loop = i + taskSwitchCount;
|
||||
} else {
|
||||
i = 0;
|
||||
loop = taskSwitchInfo->idx;
|
||||
}
|
||||
|
||||
return OsExcHookFunc(type, i, loop, len, (EXC_INFO_SAVE_CALLBACK)LOS_TaskSwitchInfoGet);
|
||||
}
|
||||
#endif
|
||||
|
||||
VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
|
||||
{
|
||||
ExcInfoArray *excInfo = NULL;
|
||||
if ((type >= OS_EXC_TYPE_MAX) || (func == NULL)) {
|
||||
PRINT_ERR("HalExcRegister ERROR!\n");
|
||||
return;
|
||||
}
|
||||
excInfo = &(g_excArray[type]);
|
||||
if (excInfo->valid == TRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
excInfo->type = type;
|
||||
excInfo->fnExcInfoCb = func;
|
||||
excInfo->arg = arg;
|
||||
excInfo->valid = TRUE;
|
||||
}
|
||||
|
||||
STATIC VOID OsExcMsgDump(VOID)
|
||||
{
|
||||
UINT32 index;
|
||||
|
||||
/* Ignore the return code when matching CSEC rule 6.6(4). */
|
||||
(VOID)memset_s(g_excMsgArray, g_excArraySize, EXC_MSG_ARRAY_INIT_VALUE, g_excArraySize);
|
||||
|
||||
*((UINT32 *)g_excContent) = MAX_EXC_MEM_SIZE; /* The total length of exception information. */
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
|
||||
for (index = 0; index < OS_EXC_TYPE_MAX; index++) {
|
||||
if (!g_excArray[index].valid) {
|
||||
continue;
|
||||
}
|
||||
g_excArray[index].fnExcInfoCb(g_excArray[index].type, g_excArray[index].arg);
|
||||
}
|
||||
|
||||
*((UINT32 *)g_excContent) = OS_EXC_TYPE_MAX;
|
||||
g_excContent = (UINT8 *)g_excContent + sizeof(UINT32);
|
||||
return;
|
||||
}
|
||||
|
||||
VOID OsExcMsgDumpInit(VOID)
|
||||
{
|
||||
g_excQueueMaxNum = LOSCFG_BASE_IPC_QUEUE_LIMIT;
|
||||
g_excMemMaxNum = OS_SYS_MEM_NUM;
|
||||
g_excContent = (VOID *)g_excMsgArray;
|
||||
|
||||
OsExcRegister(OS_EXC_TYPE_CONTEXT, OsExcContentGet, NULL);
|
||||
OsExcRegister(OS_EXC_TYPE_TSK, OsExcTaskMsgGet, &g_taskMaxNum);
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == 1)
|
||||
OsExcRegister(OS_EXC_TYPE_QUE, OsExcQueueMsgGet, &g_excQueueMaxNum);
|
||||
#endif
|
||||
OsExcRegister(OS_EXC_TYPE_NVIC, OsExcSaveIntStatus, NULL);
|
||||
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == 1)
|
||||
OsExcRegister(OS_EXC_TYPE_TSK_SWITCH, OsExcTskSwitchMsgGet, &g_taskSwitchInfo);
|
||||
#endif
|
||||
OsExcRegister(OS_EXC_TYPE_MEM, OsExcMemMsgGet, &g_excMemMaxNum);
|
||||
|
||||
(VOID)LOS_RegExcHook(EXC_INTERRUPT, (ExcHookFn)OsExcMsgDump);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_task.h"
|
||||
#include "los_queue.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
#define INFO_TYPE_AND_SIZE 8
|
||||
|
||||
#define MAX_SCENE_INFO_SIZE (INFO_TYPE_AND_SIZE + sizeof(ExcInfo) + sizeof(EXC_CONTEXT_S))
|
||||
#define MAX_TSK_INFO_SIZE (INFO_TYPE_AND_SIZE + sizeof(TSK_INFO_S) * (LOSCFG_BASE_CORE_TSK_LIMIT + 1))
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == 1)
|
||||
#define MAX_QUEUE_INFO_SIZE (INFO_TYPE_AND_SIZE + sizeof(QUEUE_INFO_S) * LOSCFG_BASE_IPC_QUEUE_LIMIT)
|
||||
#else
|
||||
#define MAX_QUEUE_INFO_SIZE (0)
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == 1)
|
||||
#define MAX_SWITCH_INFO_SIZE (INFO_TYPE_AND_SIZE + (sizeof(UINT32) + sizeof(CHAR) * LOS_TASK_NAMELEN) * OS_TASK_SWITCH_INFO_COUNT)
|
||||
#else
|
||||
#define MAX_SWITCH_INFO_SIZE (0)
|
||||
#endif
|
||||
|
||||
#define MAX_MEM_INFO_SIZE (INFO_TYPE_AND_SIZE + sizeof(MemInfoCB) * OS_SYS_MEM_NUM)
|
||||
#define MAX_EXC_MEM_SIZE (INFO_TYPE_AND_SIZE + MAX_SCENE_INFO_SIZE + MAX_TSK_INFO_SIZE + MAX_QUEUE_INFO_SIZE + MAX_INT_INFO_SIZE + MAX_SWITCH_INFO_SIZE + MAX_MEM_INFO_SIZE)
|
||||
|
||||
typedef enum {
|
||||
OS_EXC_TYPE_CONTEXT = 0,
|
||||
OS_EXC_TYPE_TSK = 1,
|
||||
OS_EXC_TYPE_QUE = 2,
|
||||
OS_EXC_TYPE_NVIC = 3,
|
||||
OS_EXC_TYPE_TSK_SWITCH = 4,
|
||||
OS_EXC_TYPE_MEM = 5,
|
||||
OS_EXC_TYPE_MAX = 6
|
||||
} ExcInfoType;
|
||||
|
||||
typedef struct {
|
||||
ExcInfoType flag;
|
||||
UINT32 length;
|
||||
ExcInfo info;
|
||||
EXC_CONTEXT_S context;
|
||||
} ExcContextInfoArray;
|
||||
|
||||
typedef struct {
|
||||
ExcInfoType flag;
|
||||
UINT32 length;
|
||||
TSK_INFO_S taskInfo[LOSCFG_BASE_CORE_TSK_LIMIT + 1];
|
||||
} ExcTaskInfoArray;
|
||||
|
||||
typedef struct {
|
||||
ExcInfoType flag;
|
||||
UINT32 length;
|
||||
QUEUE_INFO_S queueInfo[LOSCFG_BASE_CORE_TSK_LIMIT];
|
||||
} ExcQueueInfoArray;
|
||||
|
||||
typedef struct {
|
||||
UINT32 totalLen;
|
||||
ExcContextInfoArray excInfo;
|
||||
ExcTaskInfoArray taskInfo;
|
||||
ExcQueueInfoArray queueInfo;
|
||||
} ExcMsgArray;
|
||||
|
||||
typedef UINT32 (*EXC_INFO_SAVE_CALLBACK)(UINT32, VOID *);
|
||||
|
||||
typedef struct {
|
||||
ExcInfoType type;
|
||||
UINT32 valid;
|
||||
EXC_INFO_SAVE_CALLBACK fnExcInfoCb;
|
||||
VOID *arg;
|
||||
} ExcInfoArray;
|
||||
|
||||
VOID OsExcMsgDumpInit(VOID);
|
||||
extern UINT8 g_excMsgArray[MAX_EXC_MEM_SIZE];
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_exchook.h"
|
||||
#include "los_context.h"
|
||||
|
||||
#ifndef LOSCFG_BASE_EXC_HOOK_LIMIT
|
||||
#define LOSCFG_BASE_EXC_HOOK_LIMIT 16
|
||||
#endif
|
||||
|
||||
struct Node {
|
||||
ExcHookFn excHookFn;
|
||||
struct Node *next;
|
||||
};
|
||||
|
||||
STATIC struct Node g_excNodes[LOSCFG_BASE_EXC_HOOK_LIMIT];
|
||||
STATIC struct Node *g_excHeads[EXC_TYPE_END + 1]; /* EXC_TYPE_END is used for the free list. */
|
||||
|
||||
STATIC VOID DoExcHookInRegOrder(EXC_TYPE excType, struct Node *node)
|
||||
{
|
||||
if (node != NULL) {
|
||||
DoExcHookInRegOrder(excType, node->next);
|
||||
node->excHookFn(excType);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID DoExcHook(EXC_TYPE excType)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (excType >= EXC_TYPE_END) {
|
||||
return;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
DoExcHookInRegOrder(excType, g_excHeads[excType]);
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
STATIC struct Node *GetFreeNode(VOID)
|
||||
{
|
||||
struct Node *node = NULL;
|
||||
int i;
|
||||
if (g_excHeads[EXC_TYPE_END] == NULL) {
|
||||
if (g_excNodes[0].excHookFn != NULL) {
|
||||
/* no free node now */
|
||||
return NULL;
|
||||
} else {
|
||||
/* Initialize the free list */
|
||||
for (i = 0; i < LOSCFG_BASE_EXC_HOOK_LIMIT; ++i) {
|
||||
g_excNodes[i].next = g_excHeads[EXC_TYPE_END];
|
||||
g_excHeads[EXC_TYPE_END] = &g_excNodes[i];
|
||||
}
|
||||
OsExcHookRegister(DoExcHook);
|
||||
}
|
||||
}
|
||||
|
||||
node = g_excHeads[EXC_TYPE_END];
|
||||
g_excHeads[EXC_TYPE_END] = node->next;
|
||||
return node;
|
||||
}
|
||||
|
||||
UINT32 LOS_RegExcHook(EXC_TYPE excType, ExcHookFn excHookFn)
|
||||
{
|
||||
UINT32 intSave;
|
||||
struct Node *node = NULL;
|
||||
if (excType >= EXC_TYPE_END || excHookFn == NULL) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
node = GetFreeNode();
|
||||
if (node == NULL) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_SYS_HOOK_IS_FULL;
|
||||
}
|
||||
|
||||
node->excHookFn = excHookFn;
|
||||
node->next = g_excHeads[excType];
|
||||
g_excHeads[excType] = node;
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 LOS_UnRegExcHook(EXC_TYPE excType, ExcHookFn excHookFn)
|
||||
{
|
||||
UINT32 intSave;
|
||||
struct Node *node = NULL;
|
||||
struct Node *preNode = NULL;
|
||||
if (excType >= EXC_TYPE_END || excHookFn == NULL) {
|
||||
return LOS_ERRNO_SYS_PTR_NULL;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
for (node = g_excHeads[excType]; node != NULL; node = node->next) {
|
||||
if (node->excHookFn == excHookFn) {
|
||||
if (preNode) {
|
||||
preNode->next = node->next;
|
||||
} else {
|
||||
g_excHeads[excType] = node->next;
|
||||
}
|
||||
node->excHookFn = NULL;
|
||||
node->next = g_excHeads[EXC_TYPE_END];
|
||||
g_excHeads[EXC_TYPE_END] = node;
|
||||
}
|
||||
preNode = node;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_exchook Exception hooks
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EXCHOOK_H
|
||||
#define _LOS_EXCHOOK_H
|
||||
|
||||
#include "los_tick.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_exchook
|
||||
* @brief: System exception hooks register function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to register exception hooks.
|
||||
* Hooks will be invoked in reverse order.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>This function should not be call in excHookFn.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: LOS_OK success.
|
||||
* LOS_ERRNO_SYS_HOOK_IS_FULL too many hooks registered. @see LOSCFG_BASE_EXC_HOOK_LIMIT
|
||||
* LOS_ERRNO_SYS_PTR_NULL excHookFn is null or invalid excType.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_exchook.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*
|
||||
* */
|
||||
extern UINT32 LOS_RegExcHook(EXC_TYPE excType, ExcHookFn excHookFn);
|
||||
|
||||
/**
|
||||
* @ingroup los_exchook
|
||||
* @brief: System exception hooks unregister function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to unregister exception hooks.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>This function should not be call in excHookFn.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: LOS_OK success.
|
||||
* LOS_ERRNO_SYS_PTR_NULL excHookFn is null or invalid excType.
|
||||
*
|
||||
* @par Dependency:
|
||||
* <ul><li>los_exchook.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*
|
||||
* */
|
||||
extern UINT32 LOS_UnRegExcHook(EXC_TYPE excType, ExcHookFn excHookFn);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_EXCHOOK_H */
|
||||
Reference in New Issue
Block a user