first submission

This commit is contained in:
qiyongshuang
2023-02-01 14:19:13 +08:00
parent d534aad004
commit b79c6ac80d
3711 changed files with 745432 additions and 2 deletions
@@ -0,0 +1,43 @@
# 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("utils") {
sources = [
"los_debug.c",
"los_error.c",
"los_hook.c",
]
include_dirs = [
"../kernel/include",
"../kernel/arch/include",
".",
"//third_party/bounds_checking_function/include",
]
}
@@ -0,0 +1,131 @@
/*
* 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.
*/
#ifndef _LOS_HOOK_TYPES_H
#define _LOS_HOOK_TYPES_H
#include "los_compiler.h"
#include "los_config.h"
#include "los_context.h"
#include "los_event.h"
#include "los_mux.h"
#include "los_queue.h"
#include "los_sem.h"
#include "los_task.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_DEBUG_HOOK == 1)
#define LOS_HOOK_ALL_TYPES_DEF \
/* Hook types supported by memory modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_INIT, (VOID *pool, UINT32 size)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_DEINIT, (VOID *pool)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOC, (VOID *pool, UINT32 size)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_FREE, (VOID *pool, VOID *ptr)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_REALLOC, (VOID *pool, VOID *ptr, UINT32 size)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MEM_ALLOCALIGN, (VOID *pool, UINT32 size, UINT32 boundary)) \
/* Hook types supported by event modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_INIT, (PEVENT_CB_S eventCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_READ, (PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_WRITE, (PEVENT_CB_S eventCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_CLEAR, (PEVENT_CB_S eventCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_EVENT_DESTROY, (PEVENT_CB_S eventCB)) \
/* Hook types supported by queue modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_CREATE, (const LosQueueCB *queueCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_READ, (const LosQueueCB *queueCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_WRITE, (const LosQueueCB *queueCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_QUEUE_DELETE, (const LosQueueCB *queueCB)) \
/* Hook types supported by semphore modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_CREATE, (const LosSemCB *semCreated)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_POST, (const LosSemCB *semPosted, const LosTaskCB *resumedTask)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_PEND, (const LosSemCB *semPended, const LosTaskCB *runningTask)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_SEM_DELETE, (const LosSemCB *semDeleted)) \
/* Hook types supported by mutex modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_CREATE, (const LosMuxCB *muxCreated)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_POST, (const LosMuxCB *muxPosted)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_PEND, (const LosMuxCB *muxPended)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MUX_DELETE, (const LosMuxCB *muxDeleted)) \
/* Hook types supported by task modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_CREATE, (const LosTaskCB *taskCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_DELAY, (UINT32 tick)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_PRIMODIFY, (const LosTaskCB *pxTask, UINT32 uxNewPriority)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_DELETE, (const LosTaskCB *taskCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_TASK_SWITCHEDIN, (VOID)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTOREADYSTATE, (const LosTaskCB *pstTaskCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, (const LosTaskCB *pstTaskCB)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_MOVEDTASKTOSUSPENDEDLIST, (const LosTaskCB *pstTaskCB)) \
/* Hook types supported by interrupt modules */ \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_EXITTOSCHEDULER, (VOID)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_ENTER, (UINT32 hwiIndex)) \
LOS_HOOK_TYPE_DEF(LOS_HOOK_TYPE_ISR_EXIT, (UINT32 hwiIndex))
/**
* Defines the types of all hooks.
*/
#define LOS_HOOK_TYPE_DEF(type, paramList) type,
typedef enum {
/* Used to manage hook pools */
LOS_HOOK_TYPE_START = 0,
/* All supported hook types */
LOS_HOOK_ALL_TYPES_DEF
/* Used to manage hook pools */
LOS_HOOK_TYPE_END
} HookType;
#undef LOS_HOOK_TYPE_DEF
/**
* Declare the type and interface of the hook functions.
*/
#define LOS_HOOK_TYPE_DEF(type, paramList) \
typedef VOID (*type##_FN) paramList; \
extern UINT32 type##_RegHook(type##_FN func); \
extern UINT32 type##_UnRegHook(type##_FN func); \
extern VOID type##_CallHook paramList;
LOS_HOOK_ALL_TYPES_DEF
#undef LOS_HOOK_TYPE_DEF
#endif /* LOSCFG_DEBUG_HOOK */
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HOOK_TYPES_H */
@@ -0,0 +1,74 @@
/*
* 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.
*/
#ifndef _LOS_HOOK_TYPES_PARSE_H
#define _LOS_HOOK_TYPES_PARSE_H
#define ADDR(a) (&(a))
#define ARGS(a) (a)
#define ADDRn(...) _CONCAT(ADDR, _NARGS(__VA_ARGS__))(__VA_ARGS__)
#define ARGSn(...) _CONCAT(ARGS, _NARGS(__VA_ARGS__))(__VA_ARGS__)
#define ARGS0()
#define ADDR0()
#define ARGS1(a) ARGS(a)
#define ADDR1(a) ADDR(a)
#define ARG_const _ARG_const(
#define _ARG_const(a) ARG_CP_##a)
#define ARG_CP_LosSemCB ADDR(
#define ARG_CP_LosTaskCB ADDR(
#define ARG_CP_UINT32 ADDR(
#define ARG_CP_LosMuxCB ADDR(
#define ARG_CP_LosQueueCB ADDR(
#define ARG_UINT32 ARGS(
#define ARG_PEVENT_CB_S ARGS(
#define ARG_void ADDRn(
#define ARG(a) ARG_##a)
#define PARAM_TO_ARGS1(a) ARG(a)
#define PARAM_TO_ARGS2(a, b) ARG(a), PARAM_TO_ARGS1(b)
#define PARAM_TO_ARGS3(a, b, c) ARG(a), PARAM_TO_ARGS2(b, c)
#define PARAM_TO_ARGS4(a, b, c, d) ARG(a), PARAM_TO_ARGS3(b, c, d)
#define PARAM_TO_ARGS5(a, b, c, d, e) ARG(a), PARAM_TO_ARGS4(b, c, d, e)
#define PARAM_TO_ARGS6(a, b, c, d, e, f) ARG(a), PARAM_TO_ARGS5(b, c, d, e, f)
#define PARAM_TO_ARGS7(a, b, c, d, e, f, g) ARG(a), PARAM_TO_ARGS6(b, c, d, e, f, g)
#define _ZERO_ARGS 7, 6, 5, 4, 3, 2, 1, 0
#define ___NARGS(a, b, c, d, e, f, g, h, n, ...) n
#define __NARGS(...) ___NARGS(__VA_ARGS__)
#define _NARGS(...) __NARGS(x, __VA_ARGS__##_ZERO_ARGS, 7, 6, 5, 4, 3, 2, 1, 0)
#define _CONCAT(a, b) a##b
#define CONCAT(a, b) _CONCAT(a, b)
#define PARAM_TO_ARGS(...) _CONCAT(PARAM_TO_ARGS, _NARGS(__VA_ARGS__))(__VA_ARGS__)
#define OS_HOOK_PARAM_TO_ARGS(paramList) (PARAM_TO_ARGS paramList)
#endif /* _LOS_HOOK_TYPES_PARSE_H */
@@ -0,0 +1,453 @@
/*
* 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.
*/
#ifndef _LOS_COMPILER_H
#define _LOS_COMPILER_H
/* for IAR Compiler */
#ifdef __ICCARM__
#include"iccarm_builtin.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* for IAR Compiler */
#ifdef __ICCARM__
#ifndef ASM
#define ASM __asm
#endif
#ifndef INLINE
#define INLINE inline
#endif
#ifndef STATIC_INLINE
#define STATIC_INLINE static inline
#endif
#ifndef USED
#define USED __root
#endif
#ifndef WEAK
#define WEAK __weak
#endif
#ifndef CLZ
#define CLZ __iar_builtin_CLZ
#endif
#ifndef NORETURN
#define NORETURN __attribute__ ((__noreturn__))
#endif
#ifndef UNREACHABLE
#define UNREACHABLE while (1)
#endif
/* for ARM Compiler */
#elif defined(__CC_ARM)
#ifndef ASM
#define ASM __asm
#endif
#ifndef INLINE
#define INLINE __inline
#endif
#ifndef STATIC_INLINE
#define STATIC_INLINE static __inline
#endif
#ifndef USED
#define USED __attribute__((used))
#endif
#ifndef WEAK
#define WEAK __attribute__((weak))
#endif
#ifndef CLZ
#define CLZ __clz
#endif
#ifndef NORETURN
#define NORETURN __declspec(noreturn)
#endif
#ifndef UNREACHABLE
#define UNREACHABLE while (1)
#endif
#pragma anon_unions
/* for GNU Compiler */
#elif defined(__GNUC__)
#ifndef ASM
#define ASM __asm
#endif
#ifndef INLINE
#define INLINE inline
#endif
#ifndef STATIC_INLINE
#define STATIC_INLINE static inline
#endif
#ifndef USED
#define USED __attribute__((used))
#endif
#ifndef WEAK
#define WEAK __attribute__((weak))
#endif
#ifndef CLZ
#define CLZ __builtin_clz
#endif
#ifndef NORETURN
#define NORETURN __attribute__ ((__noreturn__))
#endif
#ifndef UNREACHABLE
#define UNREACHABLE __builtin_unreachable()
#endif
#else
#error Unknown compiler.
#endif
#ifndef STATIC
#define STATIC static
#endif
/**
* @ingroup los_builddef
* Define inline keyword
*/
#ifndef INLINE
#define INLINE static inline
#endif
/**
* @ingroup los_builddef
* Little endian
*/
#define OS_LITTLE_ENDIAN 0x1234
/**
* @ingroup los_builddef
* Big endian
*/
#define OS_BIG_ENDIAN 0x4321
/**
* @ingroup los_builddef
* Byte order
*/
#ifndef OS_BYTE_ORDER
#define OS_BYTE_ORDER OS_LITTLE_ENDIAN
#endif
/* Define OS code data sections */
/* The indicator function is inline */
/**
* @ingroup los_builddef
* Allow inline sections
*/
#ifndef LITE_OS_SEC_ALW_INLINE
#define LITE_OS_SEC_ALW_INLINE //__attribute__((always_inline))
#endif
/**
* @ingroup los_builddef
* Vector table section
*/
#ifndef LITE_OS_SEC_VEC
#define LITE_OS_SEC_VEC __attribute__ ((section(".vector")))
#endif
/**
* @ingroup los_builddef
* .Text section (Code section)
*/
#ifndef LITE_OS_SEC_TEXT
#define LITE_OS_SEC_TEXT //__attribute__((section(".sram.text")))
#endif
/**
* @ingroup los_builddef
* .Text.ddr section
*/
#ifndef LITE_OS_SEC_TEXT_MINOR
#define LITE_OS_SEC_TEXT_MINOR // __attribute__((section(".dyn.text")))
#endif
/**
* @ingroup los_builddef
* .Text.init section
*/
#ifndef LITE_OS_SEC_TEXT_INIT
#define LITE_OS_SEC_TEXT_INIT //__attribute__((section(".dyn.text")))
#endif
/**
* @ingroup los_builddef
* .Data section
*/
#ifndef LITE_OS_SEC_DATA
#define LITE_OS_SEC_DATA //__attribute__((section(".dyn.data")))
#endif
/**
* @ingroup los_builddef
* .Data.init section
*/
#ifndef LITE_OS_SEC_DATA_INIT
#define LITE_OS_SEC_DATA_INIT //__attribute__((section(".dyn.data")))
#endif
/**
* @ingroup los_builddef
* Not initialized variable section
*/
#ifndef LITE_OS_SEC_BSS
#define LITE_OS_SEC_BSS //__attribute__((section(".sym.bss")))
#endif
/**
* @ingroup los_builddef
* .bss.ddr section
*/
#ifndef LITE_OS_SEC_BSS_MINOR
#define LITE_OS_SEC_BSS_MINOR
#endif
/**
* @ingroup los_builddef
* .bss.init sections
*/
#ifndef LITE_OS_SEC_BSS_INIT
#define LITE_OS_SEC_BSS_INIT
#endif
#ifndef LITE_OS_SEC_TEXT_DATA
#define LITE_OS_SEC_TEXT_DATA //__attribute__((section(".dyn.data")))
#define LITE_OS_SEC_TEXT_BSS //__attribute__((section(".dyn.bss")))
#define LITE_OS_SEC_TEXT_RODATA //__attribute__((section(".dyn.rodata")))
#endif
#ifndef LITE_OS_SEC_SYMDATA
#define LITE_OS_SEC_SYMDATA //__attribute__((section(".sym.data")))
#endif
#ifndef LITE_OS_SEC_SYMBSS
#define LITE_OS_SEC_SYMBSS //__attribute__((section(".sym.bss")))
#endif
#ifndef LITE_OS_SEC_KEEP_DATA_DDR
#define LITE_OS_SEC_KEEP_DATA_DDR //__attribute__((section(".keep.data.ddr")))
#endif
#ifndef LITE_OS_SEC_KEEP_TEXT_DDR
#define LITE_OS_SEC_KEEP_TEXT_DDR //__attribute__((section(".keep.text.ddr")))
#endif
#ifndef LITE_OS_SEC_KEEP_DATA_SRAM
#define LITE_OS_SEC_KEEP_DATA_SRAM //__attribute__((section(".keep.data.sram")))
#endif
#ifndef LITE_OS_SEC_KEEP_TEXT_SRAM
#define LITE_OS_SEC_KEEP_TEXT_SRAM //__attribute__((section(".keep.text.sram")))
#endif
#ifndef LITE_OS_SEC_BSS_MINOR
#define LITE_OS_SEC_BSS_MINOR
#endif
/* type definitions */
#ifndef UINT8
typedef unsigned char UINT8;
#endif
#ifndef UINT16
typedef unsigned short UINT16;
#endif
#ifndef UINT32
typedef unsigned int UINT32;
#endif
#ifndef INT8
typedef signed char INT8;
#endif
#ifndef INT16
typedef signed short INT16;
#endif
#ifndef INT32
typedef signed int INT32;
#endif
#ifndef FLOAT
typedef float FLOAT;
#endif
#ifndef DOUBLE
typedef double DOUBLE;
#endif
#ifndef CHAR
typedef char CHAR;
#endif
#ifndef BOOL
typedef unsigned int BOOL;
#endif
#ifndef UINT64
typedef unsigned long long UINT64;
#endif
#ifndef INT64
typedef signed long long INT64;
#endif
#ifndef UINTPTR
typedef unsigned int UINTPTR;
#endif
#ifndef INTPTR
typedef signed int INTPTR;
#endif
#ifndef VOID
#define VOID void
#endif
#ifndef FALSE
#define FALSE ((BOOL)0)
#endif
#ifndef TRUE
#define TRUE ((BOOL)1)
#endif
#ifndef NULL
#ifdef __cplusplus
#define NULL 0L
#else
#define NULL ((void*)0)
#endif
#endif
#define OS_NULL_BYTE ((UINT8)0xFF)
#define OS_NULL_SHORT ((UINT16)0xFFFF)
#define OS_NULL_INT ((UINT32)0xFFFFFFFF)
#ifndef LOS_OK
#define LOS_OK 0U
#endif
#ifndef LOS_NOK
#define LOS_NOK 1U
#endif
#define OS_FAIL 1
#define OS_ERROR (UINT32)(-1)
#define OS_INVALID (UINT32)(-1)
#define asm __asm
#ifdef typeof
#undef typeof
#endif
#define typeof __typeof__
#define SIZE(a) (a)
#define LOS_ASSERT_COND(expression)
/**
* @ingroup los_base
* Align the beginning of the object with the base address addr,
* with boundary bytes being the smallest unit of alignment.
*/
#ifndef ALIGN
#define ALIGN(addr, boundary) LOS_Align(addr, boundary)
#endif
/**
* @ingroup los_base
* Align the tail of the object with the base address addr, with size bytes being the smallest unit of alignment.
*/
#define TRUNCATE(addr, size) ((addr) & ~((size)-1))
/**
* @ingroup los_base
* @brief Align the value (addr) by some bytes (boundary) you specify.
*
* @par Description:
* This API is used to align the value (addr) by some bytes (boundary) you specify.
*
* @attention
* <ul>
* <li>the value of boundary usually is 4,8,16,32.</li>
* </ul>
*
* @param addr [IN] The variable what you want to align.
* @param boundary [IN] The align size what you want to align.
*
* @retval #UINT32 The variable what have been aligned.
* @par Dependency:
* <ul><li>los_base.h: the header file that contains the API declaration.</li></ul>
* @see
*/
static inline UINT32 LOS_Align(UINT32 addr, UINT32 boundary)
{
return (addr + (((addr + (boundary - 1)) > addr) ? (boundary - 1) : 0)) & ~(boundary - 1);
}
#define OS_GOTO_ERREND() \
do { \
goto LOS_ERREND; \
} while (0)
#ifndef UNUSED
#define UNUSED(X) (void)X
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_COMPILER_H */
@@ -0,0 +1,106 @@
/*
* 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_debug.h"
#include "stdarg.h"
#include "los_context.h"
#if (LOSCFG_KERNEL_PRINTF == 1)
STATIC const CHAR *g_logString[] = {
"EMG",
"COMMON",
"ERR",
"WARN",
"INFO",
"DEBUG",
};
#endif
STATIC ExcHookFn g_excHook;
STATIC BACK_TRACE_HOOK g_backTraceHook = NULL;
VOID OsBackTraceHookSet(BACK_TRACE_HOOK hook)
{
if (g_backTraceHook == NULL) {
g_backTraceHook = hook;
}
}
VOID OsBackTraceHookCall(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
{
if (g_backTraceHook != NULL) {
g_backTraceHook(LR, LRSize, jumpCount, SP);
} else {
PRINT_ERR("Record LR failed, because of g_backTraceHook is not registered, "
"should call OSBackTraceInit firstly\n");
}
}
VOID OsExcHookRegister(ExcHookFn excHookFn)
{
UINT32 intSave = LOS_IntLock();
if (!g_excHook) {
g_excHook = excHookFn;
}
LOS_IntRestore(intSave);
}
VOID OsDoExcHook(EXC_TYPE excType)
{
UINT32 intSave = LOS_IntLock();
if (g_excHook) {
g_excHook(excType);
}
LOS_IntRestore(intSave);
}
#if (LOSCFG_KERNEL_PRINTF == 1)
INT32 OsLogLevelCheck(INT32 level)
{
if (level > PRINT_LEVEL) {
return LOS_NOK;
}
if ((level != LOG_COMMON_LEVEL) && ((level > LOG_EMG_LEVEL) && (level <= LOG_DEBUG_LEVEL))) {
PRINTK("[%s]", g_logString[level]);
}
return LOS_OK;
}
#endif
#if (LOSCFG_KERNEL_PRINTF > 1)
WEAK VOID HalConsoleOutput(LogModuleType type, INT32 level, const CHAR *fmt, ...)
{
}
#endif
@@ -0,0 +1,372 @@
/*
* 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_debug
* @ingroup kernel
*/
#ifndef _LOS_DEBUG_H
#define _LOS_DEBUG_H
#include "los_config.h"
#include "los_compiler.h"
#include "stdio.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_PLATFORM_EXC == 1)
enum MemMangType {
MEM_MANG_MEMBOX,
MEM_MANG_MEMORY,
MEM_MANG_EMPTY
};
typedef struct {
UINT32 type;
UINT32 startAddr;
UINT32 size;
VOID *blkAddrArray;
} MemInfo;
typedef struct {
enum MemMangType type;
UINT32 startAddr;
UINT32 size;
UINT32 free;
UINT32 blockSize;
UINT32 errorAddr;
UINT32 errorLen;
UINT32 errorOwner;
} MemInfoCB;
#endif
typedef enum {
EXC_REBOOT,
EXC_ASSERT,
EXC_STACKOVERFLOW,
EXC_INTERRUPT,
EXC_TYPE_END
} EXC_TYPE;
typedef VOID (*ExcHookFn)(EXC_TYPE excType);
VOID OsExcHookRegister(ExcHookFn excHookFn);
VOID OsDoExcHook(EXC_TYPE excType);
#define LOG_EMG_LEVEL 0
#define LOG_COMMON_LEVEL (LOG_EMG_LEVEL + 1)
#define LOG_ERR_LEVEL (LOG_COMMON_LEVEL + 1)
#define LOG_WARN_LEVEL (LOG_ERR_LEVEL + 1)
#define LOG_INFO_LEVEL (LOG_WARN_LEVEL + 1)
#define LOG_DEBUG_LEVEL (LOG_INFO_LEVEL + 1)
#ifndef PRINT_LEVEL
#define PRINT_LEVEL LOG_ERR_LEVEL
#endif
typedef enum {
LOG_MODULE_KERNEL,
LOG_MODULE_FS,
LOS_MODULE_OTHERS
} LogModuleType;
/**
* @ingroup los_printf
* @brief Format and print data.
*
* @par Description:
* Print argument(s) according to fmt.
*
* @attention
* <ul>
* <li>None</li>
* </ul>
*
* @param type [IN] Type LogModuleType indicates the log type.
* @param level [IN] Type LogLevel indicates the log level.
* @param fmt [IN] Type char* controls the ouput as in C printf.
*
* @retval None
* @par Dependency:
* <ul><li>los_printf.h: the header file that contains the API declaration.</li></ul>
* @see LOS_Printf
* @since none
*/
#if (LOSCFG_KERNEL_PRINTF == 1)
extern INT32 printf(const CHAR *fmt, ...);
extern INT32 OsLogLevelCheck(INT32 level);
#define LOS_Printf(type, level, fmt, args...) do { \
if (!OsLogLevelCheck(level)) { \
printf(fmt, ##args); \
} \
} while (0)
#elif (LOSCFG_KERNEL_PRINTF == 0)
#define LOS_Printf(type, level, fmt, args...)
#else
extern VOID HalConsoleOutput(LogModuleType type, INT32 level, const CHAR *fmt, ...);
#define LOS_Printf HalConsoleOutput
#endif
#define PRINT_DEBUG(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_DEBUG_LEVEL, fmt, ##args)
#define PRINT_INFO(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_INFO_LEVEL, fmt, ##args)
#define PRINT_WARN(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_WARN_LEVEL, fmt, ##args)
#define PRINT_ERR(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_ERR_LEVEL, fmt, ##args)
#define PRINTK(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_COMMON_LEVEL, fmt, ##args)
#define PRINT_EMG(fmt, args...) LOS_Printf(LOG_MODULE_KERNEL, LOG_EMG_LEVEL, fmt, ##args)
#if PRINT_LEVEL < LOG_ERR_LEVEL
#define LOS_ASSERT(judge)
#else
#define LOS_ASSERT(judge) \
do { \
if ((judge) == 0) { \
OsDoExcHook(EXC_ASSERT); \
(VOID)LOS_IntLock(); \
PRINT_ERR("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, __func__); \
while (1) { } \
} \
} while (0)
#endif
typedef VOID (*BACK_TRACE_HOOK)(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
extern VOID OsBackTraceHookSet(BACK_TRACE_HOOK hook);
extern VOID OsBackTraceHookCall(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
/**
* @ingroup los_trace
* Task error code: Insufficient memory for trace struct.
*
* Value: 0x02001400
*
* Solution: Decrease the maximum number of tasks.
*/
#define LOS_ERRNO_TRACE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x00)
/**
* @ingroup los_trace
* Task error code: User type is invalid when register new trace.
*
* Value: 0x02001401
*
* Solution: Use valid type to register the new trace.
*/
#define LOS_ERRNO_TRACE_TYPE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x01)
/**
* @ingroup los_trace
* Task error code: The callback function is null when register new trace.
*
* Value: 0x02001402
*
* Solution: Use valid callback function to register the new trace.
*/
#define LOS_ERRNO_TRACE_FUNCTION_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x02)
/**
* @ingroup los_trace
* Task error code: The filled size is 0 when register new trace.
*
* Value: 0x02001403
*
* Solution: Use valid filled size to register the new trace.
*/
#define LOS_ERRNO_TRACE_MAX_SIZE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TRACE, 0x03)
/**
* @ingroup los_trace
* It's the total size of trace buffer. It's in the unit of char
*/
#define LOS_TRACE_BUFFER_SIZE 1024
/**
* @ingroup los_trace
* It's the length of tag, filled by los_trace system
*/
#define LOS_TRACE_TAG_LENGTH sizeof(UINT32)
/**
* @ingroup los_trace
* Stands for the trace type can be registered.
*/
typedef enum enTraceType {
LOS_TRACE_SWITCH = 0, /**< trace for task switch, 0 is reserved for taskswitch */
LOS_TRACE_INTERRUPT = 1, /**< trace for Interrupt, 1 is reserved for interrupt */
LOS_TRACE_TYPE_NUM = 10, /**< num for the register type, user can use 2~ LOS_TRACE_TYPE_NUM-1 */
} TRACE_TYPE_E;
/**
* @ingroup los_trace
* struct to store the task switch infomation
*/
typedef struct tagTraceTaskSwitch {
UINT8 ucSrcTaskId; /**< source taskId */
UINT8 ucDestTaskId; /**< destination taskId */
UINT32 uwSwitchTick; /**< Time at which the task switch happens */
} TRACE_TASKSWITCH_S;
/**
* @ingroup los_trace
* struct to store the interrupt infomation
*/
typedef struct tagTraceInterrupt {
UINT8 ucIRQEntryExit; /**< 1 stands for that the trace is happend before interrupt function */
/**< 0 stands for that the trace is after before interrupt function */
UINT16 usIRQNo; /**< IRQ number which trigger the interrupt */
UINT32 uwTick; /**< Time at which the the trace is called */
} TRACE_INTERRUPT_S;
/**
* @ingroup los_trace
* union struct to store the interrupt and task switch infomation
*/
typedef struct tagTrace {
union {
TRACE_TASKSWITCH_S stTraceTask; /**< It used for trace the task */
TRACE_INTERRUPT_S stTraceInterrupt; /**< It used for trace the interrupt */
};
} TRACE_S;
/**
* @ingroup los_trace
* Main struct to store the interrupt and task switch infomation
*/
typedef struct tagTraceBuffer {
UINT16 usTracePos;
UINT16 usTraceWrapPos;
UINT8 ucBuffer[LOS_TRACE_BUFFER_SIZE];
} TRACE_BUFFER_S;
/**
* @ingroup los_trace
* Struct to store the trace information for each trace type
*/
typedef struct tagTraceInfo {
TRACE_TYPE_E eType; /**< trace type, selected from TRACE_TYPE_E */
UINT16 (*pfnHook)(UINT8 *outBuffer, VOID *pInfo); /**< callback function for the specific trace type.
* This function is used to store the infomation
* which want to be traced */
} TRACE_INFO_S;
/**
* @ingroup los_trace
* @brief Initialize the trace when the system startup.
*
* @par Description:
* This API is used to initialize the trace for system level.
* @attention
* <ul>
* <li>This API can be called only after the memory is initialized. Otherwise, the CPU usage fails to be obtained.</li>
* </ul>
*
* @param None.
*
* @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001400: The memory is not enough for initialization.
* @retval #LOS_OK 0x00000000: The initialization is successful.
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceInit
*/
extern UINT32 LOS_TraceInit(VOID);
/**
* @ingroup los_trace
* @brief main trace function is called by user to logger the information.
*
* @par Description:
* This API is used to trace the infomation.
* @attention
* <ul>
* <li>This API can be called only after trace type is intialized. Otherwise, the trace will be failed.</li>
* </ul>
*
* @param traceType [IN] TRACE_TYPE_E. Type of trace information.
* @param traceInfo [IN] VOID*. It's a input buffer to store trace infomation
*
* @retval NONE.
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_Trace
*/
extern VOID LOS_Trace(TRACE_TYPE_E traceType, VOID *traceInfo);
/**
* @ingroup los_trace
* @brief register the hook for specific trace type.
*
* @par Description:
* This API is used to register the hook for specific trace type.
* @attention
* <ul>
* <li>This API can be called only after trace type is called. therwise, the trace will be failed.</li>
* </ul>
*
* @param traceType [IN] TRACE_TYPE_E. Type of trace information.
* @param hook [IN] UINT16 (*)(UINT8*, VOID*). It's an callback function to store the useful trace
* information
* @param size [IN] UINT16. The maximum size the trace will use for the specific trace type.
*
* @retval #LOS_ERRNO_TRACE_NO_MEMORY 0x02001400: The memory is not enough for initialization.
* @retval #LOS_ERRNO_TRACE_TYPE_INVALID 0x02001401: The trace type is invalid. Valid type is from
* LOS_TRACE_TYPE_NUM-1
* @retval #LOS_ERRNO_TRACE_FUNCTION_NULL 0x02001402: The input callback function is NULL
* @retval #LOS_ERRNO_TRACE_MAX_SIZE_INVALID 0x02001403: The information maxmum size is 0 to store.
* @retval #LOS_OK 0x00000000: The register is successful.
*
* @par Dependency:
* <ul><li>los_trace.h: the header file that contains the API declaration.</li></ul>
* @see LOS_TraceUserReg
*/
extern UINT32 LOS_TraceUserReg(TRACE_TYPE_E traceType, UINT16 (*hook)(UINT8 *, VOID *), UINT16 size);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_PRINTF_H */
@@ -0,0 +1,62 @@
/*
* 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_error.h"
LITE_OS_SEC_BSS UserErrFunc g_userErrFunc;
/*****************************************************************************
Function : LOS_ErrHandle
Description : Error handle
Input : fileName -- file name
lineNo -- error line number
errorNo -- user defined error number
paraLen -- length of pPara
para -- user description of error
Output : None
Return : LOS_OK always
Other : None
*****************************************************************************/
LITE_OS_SEC_TEXT_INIT UINT32 LOS_ErrHandle(CHAR *fileName,
UINT32 lineNo,
UINT32 errorNo,
UINT32 paraLen,
VOID *para)
{
if (g_userErrFunc.pfnHook != NULL) {
g_userErrFunc.pfnHook(fileName, lineNo, errorNo, paraLen, para);
}
return LOS_OK;
}
@@ -0,0 +1,300 @@
/*
* 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_errno Error code
* @ingroup kernel
*/
#ifndef _LOS_ERRNO_H
#define _LOS_ERRNO_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_errno
* OS error code flag.
*/
#define LOS_ERRNO_OS_ID ((UINT32)0x00 << 16)
/**
* @ingroup los_errno
* Define the error level as informative.
*/
#define LOS_ERRTYPE_NORMAL ((UINT32)0x00 << 24)
/**
* @ingroup los_errno
* Define the error level as warning.
*/
#define LOS_ERRTYPE_WARN ((UINT32)0x01 << 24)
/**
* @ingroup los_errno
* Define the error level as critical.
*/
#define LOS_ERRTYPE_ERROR ((UINT32)0x02 << 24)
/**
* @ingroup los_errno
* Define the error level as fatal.
*/
#define LOS_ERRTYPE_FATAL ((UINT32)0x03 << 24)
/**
* @ingroup los_errno
* Define fatal OS errors.
*/
#define LOS_ERRNO_OS_FATAL(moduleID, errno) \
(LOS_ERRTYPE_FATAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
/**
* @ingroup los_errno
* Define critical OS errors.
*/
#define LOS_ERRNO_OS_ERROR(moduleID, errno) \
(LOS_ERRTYPE_ERROR | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
/**
* @ingroup los_errno
* Define warning OS errors.
*/
#define LOS_ERRNO_OS_WARN(moduleID, errno) \
(LOS_ERRTYPE_WARN | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
/**
* @ingroup los_errno
* Define informative OS errors.
*/
#define LOS_ERRNO_OS_NORMAL(moduleID, errno) \
(LOS_ERRTYPE_NORMAL | LOS_ERRNO_OS_ID | ((UINT32)(moduleID) << 8) | (errno))
/**
* @ingroup los_err
* @brief Define the pointer to the error handling function.
*
* @par Description:
* This API is used to define the pointer to the error handling function.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param fileName [IN] Log file that stores error information.
* @param lineNo [IN] Line number of the erroneous line.
* @param errorNo [IN] Error code.
* @param paraLen [IN] Length of the input parameter pPara.
* @param para [IN] User label of the error.
*
* @retval None.
* @par Dependency:
* <ul><li>los_err.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
typedef VOID (*LOS_ERRORHANDLE_FUNC)(CHAR *fileName,
UINT32 lineNo, /**< Line number of the erroneous line. */
UINT32 errorNo, /**< Error code. */
UINT32 paraLen, /**< Length of the input parameter pPara. */
VOID *para);
/**
* @ingroup los_err
* @brief Error handling function.
*
* @par Description:
* This API is used to perform different operations according to error types.
* @attention
* <ul>
* <li>None</li>
* </ul>
*
* @param fileName [IN] Log file that stores error information.
* @param lineNo [IN] Line number of the erroneous line which should not be OS_ERR_MAGIC_WORD.
* @param errorNo [IN] Error code.
* @param paraLen [IN] Length of the input parameter pPara.
* @param para [IN] User label of the error.
*
* @retval LOS_OK The error is successfully processed.
* @par Dependency:
* <ul><li>los_err.h: the header file that contains the API declaration.</li></ul>
* @see None
*/
extern UINT32 LOS_ErrHandle(CHAR *fileName, UINT32 lineNo,
UINT32 errorNo, UINT32 paraLen,
VOID *para);
/**
* @ingroup los_err
* Error handling function structure.
*/
typedef struct tagUserErrFunc {
LOS_ERRORHANDLE_FUNC pfnHook; /**< Hook function for error handling. */
} UserErrFunc;
enum LOS_MODULE_ID {
LOS_MOD_SYS = 0x0,
LOS_MOD_MEM = 0x1,
LOS_MOD_TSK = 0x2,
LOS_MOD_SWTMR = 0x3,
LOS_MOD_TICK = 0x4,
LOS_MOD_MSG = 0x5,
LOS_MOD_QUE = 0x6,
LOS_MOD_SEM = 0x7,
LOS_MOD_MBOX = 0x8,
LOS_MOD_HWI = 0x9,
LOS_MOD_HWWDG = 0xa,
LOS_MOD_CACHE = 0xb,
LOS_MOD_HWTMR = 0xc,
LOS_MOD_MMU = 0xd,
LOS_MOD_LOG = 0xe,
LOS_MOD_ERR = 0xf,
LOS_MOD_EXC = 0x10,
LOS_MOD_CSTK = 0x11,
LOS_MOD_MPU = 0x12,
LOS_MOD_NMHWI = 0x13,
LOS_MOD_TRACE = 0x14,
LOS_MOD_KNLSTAT = 0x15,
LOS_MOD_EVTTIME = 0x16,
LOS_MOD_THRDCPUP = 0x17,
LOS_MOD_IPC = 0x18,
LOS_MOD_STKMON = 0x19,
LOS_MOD_TIMER = 0x1a,
LOS_MOD_RESLEAKMON = 0x1b,
LOS_MOD_EVENT = 0x1c,
LOS_MOD_MUX = 0X1d,
LOS_MOD_CPUP = 0x1e,
LOS_MOD_HOOK = 0x1f,
LOS_MOD_PM = 0x20,
LOS_MOD_SHELL = 0x31,
LOS_MOD_BUTT
};
/**
* @ingroup los_err
* Define the error magic word.
*/
#define OS_ERR_MAGIC_WORD 0xa1b2c3f8
/**
* @ingroup los_err
* @brief Error handling macro capable of returning error codes.
*
* @par Description:
* This API is used to call the error handling function by using an error code and return the same error code.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param errNo [IN] Error code.
*
* @retval errNo
* @par Dependency:
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
#define OS_RETURN_ERROR(errNo) \
do { \
(VOID)LOS_ErrHandle("os_unspecific_file", OS_ERR_MAGIC_WORD, errNo, 0, NULL); \
return (errNo); \
} while (0)
/**
* @ingroup los_err
* @brief Error handling macro capable of returning error codes.
*
* @par Description:
* This API is used to call the error handling function by using an error code and the line number of the erroneous line,
and return the same error code.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param errLine [IN] Line number of the erroneous line.
* @param errNo [IN] Error code.
*
* @retval errNo
* @par Dependency:
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
#define OS_RETURN_ERROR_P2(errLine, errNo) \
do { \
(VOID)LOS_ErrHandle("os_unspecific_file", errLine, errNo, 0, NULL); \
return (errNo); \
} while (0)
/**
* @ingroup los_err
* @brief Macro for jumping to error handler.
*
* @par Description:
* This API is used to call the error handling function by using an error code.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param errorNo [IN] Error code.
*
* @retval None.
* @par Dependency:
* <ul><li>los_err_pri.h: the header file that contains the API declaration.</li></ul>
* @see None.
*/
#define OS_GOTO_ERR_HANDLER(errorNo) \
do { \
errNo = (errorNo); \
errLine = OS_ERR_MAGIC_WORD; \
goto ERR_HANDLER; \
} while (0)
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_ERRNO_H */
@@ -0,0 +1,67 @@
/*
* 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_hook.h"
#include "internal/los_hook_types_parse.h"
#if (LOSCFG_DEBUG_HOOK == 1)
#define LOS_HOOK_TYPE_DEF(type, paramList) \
STATIC type##_FN g_fn##type; \
UINT32 type##_RegHook(type##_FN func) { \
if ((func) == NULL) { \
return LOS_ERRNO_HOOK_REG_INVALID; \
} \
if (g_fn##type) { \
return LOS_ERRNO_HOOK_POOL_IS_FULL; \
} \
g_fn##type = (func); \
return LOS_OK; \
} \
UINT32 type##_UnRegHook(type##_FN func) { \
if (((func) == NULL) || (g_fn##type != (func))) { \
return LOS_ERRNO_HOOK_UNREG_INVALID; \
} \
g_fn##type = NULL; \
return LOS_OK; \
} \
VOID type##_CallHook paramList { \
if (g_fn##type) { \
g_fn##type(PARAM_TO_ARGS paramList); \
} \
}
LOS_HOOK_ALL_TYPES_DEF;
#undef LOS_HOOK_TYPE_DEF
#endif /* LOSCFG_DEBUG_HOOK */
@@ -0,0 +1,137 @@
/*
* 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.
*/
#ifndef _LOS_HOOK_H
#define _LOS_HOOK_H
#include "internal/los_hook_types.h"
#include "los_config.h"
#include "los_error.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#if (LOSCFG_DEBUG_HOOK == 1)
/**
* @ingroup los_hook
* Hook error code: The hook pool is insufficient.
*
* Value: 0x02001f00
*
* Solution: Deregister the registered hook.
*/
#define LOS_ERRNO_HOOK_POOL_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x00)
/**
* @ingroup los_hook
* Hook error code: Invalid parameter.
*
* Value: 0x02001f01
*
* Solution: Check the input parameters of LOS_HookReg.
*/
#define LOS_ERRNO_HOOK_REG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x01)
/**
* @ingroup los_hook
* Hook error code: Invalid parameter.
*
* Value: 0x02001f02
*
* Solution: Check the input parameters of LOS_HookUnReg.
*/
#define LOS_ERRNO_HOOK_UNREG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HOOK, 0x02)
/**
* @ingroup los_hook
* @brief Registration of hook function.
*
* @par Description:
* This API is used to register hook function.
*
* @attention
* <ul>
* <li> None.</li>
* </ul>
*
* @param hookType [IN] Register the type of the hook.
* @param hookFn [IN] The function to be registered.
*
* @retval None.
* @par Dependency:
* <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_HookReg(hookType, hookFn) hookType##_RegHook(hookFn)
/**
* @ingroup los_hook
* @brief Deregistration of hook function.
*
* @par Description:
* This API is used to deregister hook function.
*
* @attention
* <ul>
* <li> None.</li>
* </ul>
*
* @param hookType [IN] Deregister the type of the hook.
* @param hookFn [IN] The function to be deregistered.
*
* @retval None.
* @par Dependency:
* <ul><li>los_hook.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_HookUnReg(hookType, hookFn) hookType##_UnRegHook(hookFn)
/**
* Call hook functions.
*/
#define OsHookCall(hookType, ...) hookType##_CallHook(__VA_ARGS__)
#else
#define LOS_HookReg(hookType, hookFn)
#define LOS_HookUnReg(hookType, hookFn)
#define OsHookCall(hookType, ...)
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HOOK_H */
@@ -0,0 +1,431 @@
/*
* 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_list Doubly linked list
* @ingroup kernel
*/
#ifndef _LOS_LIST_H
#define _LOS_LIST_H
#include "los_compiler.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_list
* Structure of a node in a doubly linked list.
*/
typedef struct LOS_DL_LIST {
struct LOS_DL_LIST *pstPrev; /**< Current node's pointer to the previous node */
struct LOS_DL_LIST *pstNext; /**< Current node's pointer to the next node */
} LOS_DL_LIST;
/**
* @ingroup los_list
* @brief Initialize a doubly linked list.
*
* @par Description:
* This API is used to initialize a doubly linked list.
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param list [IN] Node in a doubly linked list.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
{
list->pstNext = list;
list->pstPrev = list;
}
/**
* @ingroup los_list
* @brief Point to the next node pointed to by the current node.
*
* @par Description:
* <ul>
* <li>This API is used to point to the next node pointed to by the current node.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param object [IN] Node in the doubly linked list.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_DL_LIST_FIRST(object) ((object)->pstNext)
/**
* @ingroup los_list
* @brief Insert a new node to a doubly linked list.
*
* @par Description:
* This API is used to insert a new node to a doubly linked list.
* @attention
* <ul>
* <li>The parameters passed in should be ensured to be legal pointers.</li>
* </ul>
*
* @param list [IN] Doubly linked list where the new node is inserted.
* @param node [IN] New node to be inserted.
*
* @retval None
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ListDelete
*/
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_LIST *node)
{
node->pstNext = list->pstNext;
node->pstPrev = list;
list->pstNext->pstPrev = node;
list->pstNext = node;
}
/**
* @ingroup los_list
* @brief Insert a node to the tail of a doubly linked list.
*
* @par Description:
* This API is used to insert a new node to the tail of a doubly linked list.
* @attention
* <ul>
* <li>The parameters passed in should be ensured to be legal pointers.</li>
* </ul>
*
* @param list [IN] Doubly linked list where the new node is inserted.
* @param node [IN] New node to be inserted.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ListAdd | LOS_ListHeadInsert
*/
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
{
LOS_ListAdd(list->pstPrev, node);
}
/**
* @ingroup los_list
* @brief Insert a node to the head of a doubly linked list.
*
* @par Description:
* This API is used to insert a new node to the head of a doubly linked list.
* @attention
* <ul>
* <li>The parameters passed in should be ensured to be legal pointers.</li>
* </ul>
*
* @param list [IN] Doubly linked list where the new node is inserted.
* @param node [IN] New node to be inserted.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ListAdd | LOS_ListTailInsert
*/
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListHeadInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
{
LOS_ListAdd(list, node);
}
/**
* @ingroup los_list
* @brief Delete a specified node from a doubly linked list.
*
* @par Description:
* <ul>
* <li>This API is used to delete a specified node from a doubly linked list.</li>
* </ul>
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param node [IN] Node to be deleted.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see LOS_ListAdd
*/
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
{
node->pstNext->pstPrev = node->pstPrev;
node->pstPrev->pstNext = node->pstNext;
node->pstNext = (LOS_DL_LIST *)NULL;
node->pstPrev = (LOS_DL_LIST *)NULL;
}
/**
* @ingroup los_list
* @brief Identify whether a specified doubly linked list is empty.
*
* @par Description:
* <ul>
* <li>This API is used to return whether a doubly linked list is empty.</li>
* </ul>
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
* </ul>
*
* @param list [IN] Doubly linked node.
*
* @retval TRUE The doubly linked list is empty.
* @retval FALSE The doubly linked list is not empty.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
LITE_OS_SEC_ALW_INLINE STATIC_INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *node)
{
return (BOOL)(node->pstNext == node);
}
/**
* @ingroup los_list
* @brief Obtain the pointer to a doubly linked list in a structure.
*
* @par Description:
* This API is used to obtain the pointer to a doubly linked list in a structure.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param type [IN] Structure name.
* @param member [IN] Member name of the doubly linked list in the structure.
*
* @retval Pointer to the doubly linked list in the structure.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_OFF_SET_OF(type, member) ((UINT32)&(((type *)0)->member)) /*lint -e(413) */
/**
* @ingroup los_list
* @brief Obtain the pointer to a structure that contains a doubly linked list.
*
* @par Description:
* This API is used to obtain the pointer to a structure that contains a doubly linked list.
* <ul>
* <li>None.</li>
* </ul>
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param item [IN] Current node's pointer to the next node.
* @param type [IN] Structure name.
* @param member [IN] Member name of the doubly linked list in the structure.
*
* @retval Pointer to the structure that contains the doubly linked list.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_DL_LIST_ENTRY(item, type, member) \
((type *)(VOID *)((CHAR *)(item) - LOS_OFF_SET_OF(type, member))) \
/**
* @ingroup los_list
* @brief Iterate over a doubly linked list of given type.
*
* @par Description:
* This API is used to iterate over a doubly linked list of given type.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
* @param list [IN] Pointer to the doubly linked list to be traversed.
* @param type [IN] Structure name.
* @param member [IN] Member name of the doubly linked list in the structure.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_DL_LIST_FOR_EACH_ENTRY(item, list, type, member) \
for ((item) = LOS_DL_LIST_ENTRY((list)->pstNext, type, member); \
&(item)->member != (list); \
(item) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
/**
* @ingroup los_list
* @brief iterate over a doubly linked list safe against removal of list entry.
*
* @par Description:
* This API is used to iterate over a doubly linked list safe against removal of list entry.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
* @param next [IN] Save the next node.
* @param list [IN] Pointer to the doubly linked list to be traversed.
* @param type [IN] Structure name.
* @param member [IN] Member name of the doubly linked list in the structure.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, next, list, type, member) \
for ((item) = LOS_DL_LIST_ENTRY((list)->pstNext, type, member), \
(next) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member); \
&((item)->member) != (list); \
(item) = (next), (next) = LOS_DL_LIST_ENTRY((item)->member.pstNext, type, member))
/**
* @ingroup los_list
* @brief Delete initialize a doubly linked list.
*
* @par Description:
* This API is used to delete initialize a doubly linked list.
* @attention
* <ul>
* <li>The parameter passed in should be ensured to be s legal pointer.</li>
* </ul>
*
* @param list [IN] Doubly linked list.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
LITE_OS_SEC_ALW_INLINE STATIC_INLINE VOID LOS_ListDelInit(LOS_DL_LIST *list)
{
list->pstNext->pstPrev = list->pstPrev;
list->pstPrev->pstNext = list->pstNext;
LOS_ListInit(list);
}
/**
* @ingroup los_list
* @brief iterate over a doubly linked list.
*
* @par Description:
* This API is used to iterate over a doubly linked list.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
* @param list [IN] Pointer to the doubly linked list to be traversed.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_DL_LIST_FOR_EACH(item, list) \
for ((item) = (list)->pstNext; (item) != (list); (item) = (item)->pstNext)
/**
* @ingroup los_list
* @brief Iterate over a doubly linked list safe against removal of list entry.
*
* @par Description:
* This API is used to iterate over a doubly linked list safe against removal of list entry.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
* @param next [IN] Save the next node.
* @param list [IN] Pointer to the doubly linked list to be traversed.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_DL_LIST_FOR_EACH_SAFE(item, next, list) \
for ((item) = (list)->pstNext, (next) = (item)->pstNext; (item) != (list); \
(item) = (next), (next) = (item)->pstNext)
/**
* @ingroup los_list
* @brief Initialize a double linked list.
*
* @par Description:
* This API is used to initialize a double linked list.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param list [IN] Pointer to the doubly linked list to be traversed.
*
* @retval None.
* @par Dependency:
* <ul><li>los_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_DL_LIST_HEAD(list) \
LOS_DL_LIST list = { &(list), &(list) }
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_LIST_H */
@@ -0,0 +1,117 @@
/*
* 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 kernel Kernel
* @defgroup los_reg Basic definitions
* @ingroup kernel
*/
#ifndef _LOS_REG_H
#define _LOS_REG_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_base
* Read a UINT8 value from addr and stroed in value.
*/
#define READ_UINT8(value, addr) ((value) = *((volatile UINT8 *)(addr)))
/**
* @ingroup los_base
* Read a UINT16 value from addr and stroed in addr.
*/
#define READ_UINT16(value, addr) ((value) = *((volatile UINT16 *)(addr)))
/**
* @ingroup los_base
* Read a UINT32 value from addr and stroed in value.
*/
#define READ_UINT32(value, addr) ((value) = *((volatile UINT32 *)(addr)))
/**
* @ingroup los_base
* Read a UINT64 value from addr and stroed in value.
*/
#define READ_UINT64(value, addr) ((value) = *((volatile UINT64 *)(addr)))
/**
* @ingroup los_base
* Get a UINT8 value from addr.
*/
#define GET_UINT8(addr) (*((volatile UINT8 *)(addr)))
/**
* @ingroup los_base
* Get a UINT16 value from addr.
*/
#define GET_UINT16(addr) (*((volatile UINT16 *)(addr)))
/**
* @ingroup los_base
* Get a UINT32 value from addr.
*/
#define GET_UINT32(addr) (*((volatile UINT32 *)(addr)))
/**
* @ingroup los_base
* Get a UINT64 value from addr.
*/
#define GET_UINT64(addr) (*((volatile UINT64 *)(addr)))
/**
* @ingroup los_base
* Write a UINT8 value to addr.
*/
#define WRITE_UINT8(value, addr) (*((volatile UINT8 *)(addr)) = (value))
/**
* @ingroup los_base
* Write a UINT16 value to addr.
*/
#define WRITE_UINT16(value, addr) (*((volatile UINT16 *)(addr)) = (value))
/**
* @ingroup los_base
* Write a UINT32 value to addr.
*/
#define WRITE_UINT32(value, addr) (*((volatile UINT32 *)(addr)) = (value))
/**
* @ingroup los_base
* Write a UINT64 addr to addr.
*/
#define WRITE_UINT64(value, addr) (*((volatile UINT64 *)(addr)) = (value))
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_REG_H */