!605 refactor: 内核目录结构整理

Merge pull request !605 from Zhaotianyu/0902dir_refactor
This commit is contained in:
openharmony_ci
2021-09-09 01:23:33 +00:00
committed by Gitee
97 changed files with 586 additions and 670 deletions

View File

@@ -31,14 +31,16 @@ import("//kernel/liteos_a/liteos.gni")
group("extended") {
deps = [
"blackbox",
"cppsupport",
"cpup",
"dynload",
"hidumper",
"hilog",
"hook",
"liteipc",
"pipes",
"power",
"hook",
"trace",
"vdso",
]
@@ -46,12 +48,14 @@ group("extended") {
config("public") {
configs = [
"blackbox:public",
"cpup:public",
"dynload:public",
"vdso:public",
"hidumper:public",
"hilog:public",
"hook:public",
"liteipc:public",
"pipes:public",
"hilog:public",
"vdso:public",
]
}

98
kernel/extended/Kconfig Normal file
View File

@@ -0,0 +1,98 @@
config KERNEL_EXTKERNEL
bool "Enable Extend Kernel"
default y
help
This option will enable extend Kernel of LiteOS. Extend kernel include
cppsupport, cpup, and dynload. You can select one or some
of them.
config KERNEL_CPPSUPPORT
bool "Enable C++ Support"
default y
depends on KERNEL_EXTKERNEL
help
If you wish to build LiteOS with support for C++.
config KERNEL_CPUP
bool "Enable Cpup"
default y
depends on KERNEL_EXTKERNEL
help
If you wish to build LiteOS with support for cpup.
config CPUP_INCLUDE_IRQ
bool "Enable Cpup include irq"
default y
depends on KERNEL_CPUP
help
If you wish to include irq usage for cpup.
config KERNEL_DYNLOAD
bool "Enable Dynamic Load Feature"
default y
depends on KERNEL_EXTKERNEL && KERNEL_VM && KERNEL_SYSCALL
help
If you wish to build LiteOS with support for dynamic load.
config ASLR
bool "Enable Address Space Layout Randomization"
default n
depends on KERNEL_DYNLOAD && HW_RANDOM_ENABLE
help
If you wish to enable ASLR for user aspace.
config KERNEL_PM
bool "Enable Power Management"
default y
depends on KERNEL_EXTKERNEL
help
If you wish to build LiteOS with support for power management.
config KERNEL_VDSO
bool "Enable VDSO Feature"
default n
depends on KERNEL_EXTKERNEL && KERNEL_VM && KERNEL_SYSCALL
help
If you wish to speed up some system calls.
config KERNEL_SHM
bool "Enable Shared Memory"
default y
depends on KERNEL_EXTKERNEL && KERNEL_VM && KERNEL_SYSCALL
help
Answer Y to enable LiteOS support shared memory.
config KERNEL_LITEIPC
bool "Enable liteipc"
default y
depends on KERNEL_EXTKERNEL && KERNEL_VM
help
Answer Y to enable LiteOS support liteipc.
config KERNEL_PIPE
bool "Enable pipes"
default y
depends on KERNEL_EXTKERNEL
help
Answer Y to enable LiteOS support pipes.
config BASE_CORE_HILOG
bool "Enable Hilog"
default y
depends on KERNEL_EXTKERNEL
help
If you wish to include hilog.
config KERNEL_HOOK
bool "Enable Hook Feature"
default n
depends on KERNEL_EXTKERNEL && DEBUG_VERSION
######################### config options of trace #########################
source "kernel/extended/trace/Kconfig"
######################### config options of blackbox #########################
source "kernel/extended/blackbox/Kconfig"
######################### config options of hidumper #########################
source "kernel/extended/hidumper/Kconfig"

View File

@@ -0,0 +1,47 @@
# 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.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_BLACKBOX)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [
"los_blackbox_common.c",
"los_blackbox_core.c",
"los_blackbox_detector.c",
"los_blackbox_system_adapter.c",
]
include_dirs = [ "$LITEOSTOPDIR/syscall" ]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "." ]
}

View File

@@ -0,0 +1,35 @@
config BLACKBOX
bool "Enable BlackBox"
default n
depends on KERNEL_EXTKERNEL
help
Answer Y to enable LiteOS support blackbox
config BLACKBOX_LOG_PART_MOUNT_POINT
string "unknown"
default "/storage"
depends on BLACKBOX
help
Define the default log part representative of blackbox
config BLACKBOX_LOG_ROOT_PATH
string "unknown"
default "/storage/data/log"
depends on BLACKBOX
help
Define the default log path of blackbox
config BLACKBOX_RESERVE_MEM_ADDR
int "The address of the reserve mem for blackbox in hex"
default 0
depends on BLACKBOX
help
Define the address of the reserve mem for blackbox in hex.
config BLACKBOX_LOG_SIZE
int "The size of log saved by blackbox in hex"
range 1024 1048576
default 65536
depends on BLACKBOX
help
Define the size of log saved by blackbox in decimal.

View File

@@ -0,0 +1,15 @@
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/common \
-I $(LITEOSTOPDIR)/kernel/common/blackbox \
-I $(LITEOSTOPDIR)/syscall \
-I $(LITEOSTOPDIR)/kernel/base/include
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2021-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_BLACKBOX_H
#define LOS_BLACKBOX_H
#include "stdarg.h"
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define PATH_MAX_LEN 256
#define EVENT_MAX_LEN 32
#define MODULE_MAX_LEN 32
#define ERROR_DESC_MAX_LEN 512
#define KERNEL_FAULT_LOG_PATH LOSCFG_BLACKBOX_LOG_ROOT_PATH "/kernel_fault.log"
#define USER_FAULT_LOG_PATH LOSCFG_BLACKBOX_LOG_ROOT_PATH "/user_fault.log"
#define MODULE_SYSTEM "SYSTEM"
#define EVENT_SYSREBOOT "SYSREBOOT"
#define EVENT_LONGPRESS "LONGPRESS"
#define EVENT_COMBINATIONKEY "COMBINATIONKEY"
#define EVENT_SUBSYSREBOOT "SUBSYSREBOOT"
#define EVENT_POWEROFF "POWEROFF"
#define EVENT_PANIC "PANIC"
#define EVENT_SYS_WATCHDOG "SYSWATCHDOG"
#define EVENT_HUNGTASK "HUNGTASK"
#define EVENT_BOOTFAIL "BOOTFAIL"
struct ErrorInfo {
char event[EVENT_MAX_LEN];
char module[MODULE_MAX_LEN];
char errorDesc[ERROR_DESC_MAX_LEN];
};
struct ModuleOps {
char module[MODULE_MAX_LEN];
void (*Dump)(const char *logDir, struct ErrorInfo *info);
void (*Reset)(struct ErrorInfo *info);
int (*GetLastLogInfo)(struct ErrorInfo *info);
int (*SaveLastLog)(const char *logDir, struct ErrorInfo *info);
};
int BBoxRegisterModuleOps(struct ModuleOps *ops);
int BBoxNotifyError(const char event[EVENT_MAX_LEN],
const char module[MODULE_MAX_LEN],
const char errorDesc[ERROR_DESC_MAX_LEN],
int needSysReset);
int OsBBoxDriverInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,219 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_blackbox_common.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
#ifdef LOSCFG_FS_VFS
#include "fs/fs.h"
#include "fs/mount.h"
#endif
#include "securec.h"
#include "los_memory.h"
/* ------------ local macroes ------------ */
#ifdef LOSCFG_FS_VFS
#define BBOX_DIR_MODE 0777
#endif
/* ------------ local prototypes ------------ */
/* ------------ local function declarations ------------ */
/* ------------ global function declarations ------------ */
/* ------------ local variables ------------ */
static bool g_isLogPartReady = FALSE;
/* ------------ function definitions ------------ */
int FullWriteFile(const char *filePath, const char *buf, size_t bufSize, int isAppend)
{
#ifdef LOSCFG_FS_VFS
int fd;
int totalToWrite = (int)bufSize;
int totalWrite = 0;
if (filePath == NULL || buf == NULL || bufSize == 0) {
BBOX_PRINT_ERR("filePath: %p, buf: %p, bufSize: %lu!\n", filePath, buf, bufSize);
return -1;
}
if (!IsLogPartReady()) {
BBOX_PRINT_ERR("log path [%s] isn't ready to be written!\n", LOSCFG_BLACKBOX_LOG_ROOT_PATH);
return -1;
}
fd = open(filePath, O_CREAT | O_RDWR | (isAppend ? O_APPEND : O_TRUNC), 0644);
if (fd < 0) {
BBOX_PRINT_ERR("Create file [%s] failed, fd: %d!\n", filePath, fd);
return -1;
}
while (totalToWrite > 0) {
int writeThisTime = write(fd, buf, totalToWrite);
if (writeThisTime < 0) {
BBOX_PRINT_ERR("Failed to write file [%s]!\n", filePath);
(void)close(fd);
return -1;
}
buf += writeThisTime;
totalToWrite -= writeThisTime;
totalWrite += writeThisTime;
}
(void)fsync(fd);
(void)close(fd);
return (totalWrite == (int)bufSize) ? 0 : -1;
#else
(VOID)filePath;
(VOID)buf;
(VOID)bufSize;
(VOID)isAppend;
return -1;
#endif
}
int SaveBasicErrorInfo(const char *filePath, const struct ErrorInfo *info)
{
char *buf = NULL;
if (filePath == NULL || info == NULL) {
BBOX_PRINT_ERR("filePath: %p, event: %p!\n", filePath, info);
return -1;
}
buf = LOS_MemAlloc(m_aucSysMem1, ERROR_INFO_MAX_LEN);
if (buf == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
return -1;
}
(void)memset_s(buf, ERROR_INFO_MAX_LEN, 0, ERROR_INFO_MAX_LEN);
if (snprintf_s(buf, ERROR_INFO_MAX_LEN, ERROR_INFO_MAX_LEN - 1,
ERROR_INFO_HEADER_FORMAT, info->event, info->module, info->errorDesc) != -1) {
*(buf + ERROR_INFO_MAX_LEN - 1) = '\0';
(void)FullWriteFile(filePath, buf, strlen(buf), 0);
} else {
BBOX_PRINT_ERR("buf is not enough or snprintf_s failed!\n");
}
(void)LOS_MemFree(m_aucSysMem1, buf);
return 0;
}
#ifdef LOSCFG_FS_VFS
static int IsLogPartMounted(const char *devPoint, const char *mountPoint, struct statfs *statBuf, void *arg)
{
(void)devPoint;
(void)statBuf;
(void)arg;
if (mountPoint != NULL && arg != NULL) {
if (strcmp(mountPoint, (char *)arg) == 0) {
g_isLogPartReady = TRUE;
}
}
return 0;
}
bool IsLogPartReady(void)
{
if (!g_isLogPartReady) {
(void)foreach_mountpoint((foreach_mountpoint_t)IsLogPartMounted, LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
}
return g_isLogPartReady;
}
#else
bool IsLogPartReady(void)
{
return TRUE;
}
#endif
#ifdef LOSCFG_FS_VFS
int CreateNewDir(const char *dirPath)
{
int ret;
if (dirPath == NULL) {
BBOX_PRINT_ERR("dirPath is NULL!\n");
return -1;
}
ret = access(dirPath, 0);
if (ret == 0) {
return 0;
}
ret = mkdir(dirPath, BBOX_DIR_MODE);
if (ret != 0) {
BBOX_PRINT_ERR("mkdir [%s] failed!\n", dirPath);
return -1;
}
return 0;
}
int CreateLogDir(const char *dirPath)
{
const char *temp = dirPath;
char curPath[PATH_MAX_LEN];
int idx = 0;
if (dirPath == NULL) {
BBOX_PRINT_ERR("dirPath is NULL!\n");
return -1;
}
if (*dirPath != '/') {
BBOX_PRINT_ERR("Invalid dirPath: %s\n", dirPath);
return -1;
}
(void)memset_s(curPath, sizeof(curPath), 0, sizeof(curPath));
curPath[idx++] = *dirPath++;
while (*dirPath != '\0' && idx < sizeof(curPath)) {
if (*dirPath == '/') {
if (CreateNewDir(curPath) != 0) {
return -1;
}
}
curPath[idx] = *dirPath;
dirPath++;
idx++;
}
if (*dirPath != '\0') {
BBOX_PRINT_ERR("dirPath [%s] is too long!\n", temp);
return -1;
}
return CreateNewDir(curPath);
}
#else
int CreateLogDir(const char *dirPath)
{
(void)dirPath;
return -1;
}
#endif

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2021-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_BLACKBOX_COMMON_H
#define LOS_BLACKBOX_COMMON_H
#include "los_blackbox.h"
#include "los_printf.h"
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define ERROR_INFO_HEADER_FORMAT "#### error info ####\nevent: %s\nmodule: %s\nerrorDesc: %s\n"
#define ERROR_INFO_MAX_LEN 768
#define Min(a, b) (((a) > (b)) ? (b) : (a))
#define BBOX_PRINT_ERR(format, ...) PRINTK("bbox: func: %s, line: %d, Err: " \
format, __func__, __LINE__, ##__VA_ARGS__)
#define BBOX_PRINT_INFO(format, ...) PRINTK("bbox: Info: " format, ##__VA_ARGS__)
int FullWriteFile(const char *filePath, const char *buf, size_t bufSize, int isAppend);
int SaveBasicErrorInfo(const char *filePath, const struct ErrorInfo *info);
int CreateLogDir(const char *dirPath);
bool IsLogPartReady(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,478 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_blackbox.h"
#include "los_blackbox_common.h"
#include "los_blackbox_detector.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
#include "los_base.h"
#include "los_config.h"
#include "los_excinfo_pri.h"
#include "los_hw.h"
#include "los_init.h"
#include "los_memory.h"
#include "los_sem.h"
#include "los_syscall.h"
#include "los_task_pri.h"
#include "securec.h"
#include "sys/reboot.h"
/* ------------ local macroes ------------ */
#define LOG_WAIT_TIMES 10
#define LOG_PART_WAIT_TIME 1000
/* ------------ local prototypes ------------ */
typedef struct BBoxOps {
LOS_DL_LIST opsList;
struct ModuleOps ops;
} BBoxOps;
/* ------------ local function declarations ------------ */
/* ------------ global function declarations ------------ */
/* ------------ local variables ------------ */
static bool g_bboxInitSucc = FALSE;
static UINT32 g_opsListSem = 0;
static UINT32 g_tempErrInfoSem = 0;
static UINT32 g_tempErrLogSaveSem = 0;
static LOS_DL_LIST_HEAD(g_opsList);
struct ErrorInfo *g_tempErrInfo;
/* ------------ function definitions ------------ */
static void FormatErrorInfo(struct ErrorInfo *info,
const char event[EVENT_MAX_LEN],
const char module[MODULE_MAX_LEN],
const char errorDesc[ERROR_DESC_MAX_LEN])
{
if (info == NULL || event == NULL || module == NULL || errorDesc == NULL) {
BBOX_PRINT_ERR("info: %p, event: %p, module: %p, errorDesc: %p!\n", info, event, module, errorDesc);
return;
}
(void)memset_s(info, sizeof(*info), 0, sizeof(*info));
if (strncpy_s(info->event, sizeof(info->event), event, Min(strlen(event), sizeof(info->event) - 1)) != EOK) {
BBOX_PRINT_ERR("info->event is not enough or strncpy_s failed!\n");
}
if (strncpy_s(info->module, sizeof(info->module), module, Min(strlen(module), sizeof(info->module) - 1)) != EOK) {
BBOX_PRINT_ERR("info->module is not enough or strncpy_s failed!\n");
}
if (strncpy_s(info->errorDesc, sizeof(info->errorDesc), errorDesc,
Min(strlen(errorDesc), sizeof(info->errorDesc) - 1)) != EOK) {
BBOX_PRINT_ERR("info->errorDesc is not enough or strncpy_s failed!\n");
}
}
#ifdef LOSCFG_FS_VFS
static void WaitForLogPart(void)
{
BBOX_PRINT_INFO("wait for log part [%s] begin!\n", LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
while (!IsLogPartReady()) {
LOS_Msleep(LOG_PART_WAIT_TIME);
}
BBOX_PRINT_INFO("wait for log part [%s] end!\n", LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
}
#else
static void WaitForLogPart(void)
{
int i = 0;
BBOX_PRINT_INFO("wait for log part [%s] begin!\n", LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
while (i++ < LOG_WAIT_TIMES) {
LOS_Msleep(LOG_PART_WAIT_TIME);
}
BBOX_PRINT_INFO("wait for log part [%s] end!\n", LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
}
#endif
static bool FindModuleOps(struct ErrorInfo *info, BBoxOps **ops)
{
bool found = false;
if (info == NULL || ops == NULL) {
BBOX_PRINT_ERR("info: %p, ops: %p!\n", info, ops);
return found;
}
LOS_DL_LIST_FOR_EACH_ENTRY(*ops, &g_opsList, BBoxOps, opsList) {
if (*ops != NULL && strcmp((*ops)->ops.module, info->module) == 0) {
found = true;
break;
}
}
if (!found) {
BBOX_PRINT_ERR("[%s] hasn't been registered!\n", info->module);
}
return found;
}
static void InvokeModuleOps(struct ErrorInfo *info, const BBoxOps *ops)
{
if (info == NULL || ops == NULL) {
BBOX_PRINT_ERR("info: %p, ops: %p!\n", info, ops);
return;
}
if (ops->ops.Dump != NULL) {
BBOX_PRINT_INFO("[%s] starts dumping log!\n", ops->ops.module);
ops->ops.Dump(LOSCFG_BLACKBOX_LOG_ROOT_PATH, info);
BBOX_PRINT_INFO("[%s] ends dumping log!\n", ops->ops.module);
}
if (ops->ops.Reset != NULL) {
BBOX_PRINT_INFO("[%s] starts resetting!\n", ops->ops.module);
ops->ops.Reset(info);
BBOX_PRINT_INFO("[%s] ends resetting!\n", ops->ops.module);
}
}
static void SaveLastLog(const char *logDir)
{
struct ErrorInfo *info = NULL;
BBoxOps *ops = NULL;
info = LOS_MemAlloc(m_aucSysMem1, sizeof(*info));
if (info == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
return;
}
if (LOS_SemPend(g_opsListSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_opsListSem failed!\n");
(void)LOS_MemFree(m_aucSysMem1, info);
return;
}
if (CreateLogDir(LOSCFG_BLACKBOX_LOG_ROOT_PATH) != 0) {
(void)LOS_SemPost(g_opsListSem);
(void)LOS_MemFree(m_aucSysMem1, info);
BBOX_PRINT_ERR("Create log dir [%s] failed!\n", LOSCFG_BLACKBOX_LOG_ROOT_PATH);
return;
}
LOS_DL_LIST_FOR_EACH_ENTRY(ops, &g_opsList, BBoxOps, opsList) {
if (ops == NULL) {
BBOX_PRINT_ERR("ops: NULL, please check it!\n");
continue;
}
if (ops->ops.GetLastLogInfo != NULL && ops->ops.SaveLastLog != NULL) {
(void)memset_s(info, sizeof(*info), 0, sizeof(*info));
if (ops->ops.GetLastLogInfo(info) != 0) {
BBOX_PRINT_ERR("[%s] failed to get log info!\n", ops->ops.module);
continue;
}
BBOX_PRINT_INFO("[%s] starts saving log!\n", ops->ops.module);
if (ops->ops.SaveLastLog(logDir, info) != 0) {
BBOX_PRINT_ERR("[%s] failed to save log!\n", ops->ops.module);
} else {
BBOX_PRINT_INFO("[%s] ends saving log!\n", ops->ops.module);
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
#ifdef LOSCFG_FS_VFS
(void)UploadEventByFile(KERNEL_FAULT_LOG_PATH);
#else
BBOX_PRINT_INFO("LOSCFG_FS_VFS isn't defined!\n");
#endif
BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
}
} else {
BBOX_PRINT_ERR("module [%s], GetLastLogInfo: %p, SaveLastLog: %p!\n",
ops->ops.module, ops->ops.GetLastLogInfo, ops->ops.SaveLastLog);
}
}
(void)LOS_SemPost(g_opsListSem);
(void)LOS_MemFree(m_aucSysMem1, info);
}
static void SaveLogWithoutReset(struct ErrorInfo *info)
{
BBoxOps *ops = NULL;
if (info == NULL) {
BBOX_PRINT_ERR("info is NULL!\n");
return;
}
if (LOS_SemPend(g_opsListSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_opsListSem failed!\n");
return;
}
if (!FindModuleOps(info, &ops)) {
(void)LOS_SemPost(g_opsListSem);
return;
}
if (CreateLogDir(LOSCFG_BLACKBOX_LOG_ROOT_PATH) != 0) {
(void)LOS_SemPost(g_opsListSem);
BBOX_PRINT_ERR("Create log dir [%s] failed!\n", LOSCFG_BLACKBOX_LOG_ROOT_PATH);
return;
}
if (ops->ops.Dump == NULL && ops->ops.Reset == NULL) {
(void)LOS_SemPost(g_opsListSem);
if (SaveBasicErrorInfo(USER_FAULT_LOG_PATH, info) == 0) {
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
#ifdef LOSCFG_FS_VFS
(void)UploadEventByFile(USER_FAULT_LOG_PATH);
#else
BBOX_PRINT_INFO("LOSCFG_FS_VFS isn't defined!\n");
#endif
BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
}
return;
}
InvokeModuleOps(info, ops);
(void)LOS_SemPost(g_opsListSem);
}
static void SaveTempErrorLog(void)
{
if (LOS_SemPend(g_tempErrInfoSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_tempErrInfoSem failed!\n");
return;
}
if (g_tempErrInfo == NULL) {
BBOX_PRINT_ERR("g_tempErrInfo is NULL!\n");
(void)LOS_SemPost(g_tempErrInfoSem);
return;
}
if (strlen(g_tempErrInfo->event) != 0) {
SaveLogWithoutReset(g_tempErrInfo);
}
(void)LOS_SemPost(g_tempErrInfoSem);
}
static void SaveLogWithReset(struct ErrorInfo *info)
{
int ret;
BBoxOps *ops = NULL;
if (info == NULL) {
BBOX_PRINT_ERR("info is NULL!\n");
return;
}
if (!FindModuleOps(info, &ops)) {
return;
}
InvokeModuleOps(info, ops);
ret = SysReboot(0, 0, RB_AUTOBOOT);
BBOX_PRINT_INFO("SysReboot, ret: %d\n", ret);
}
static void SaveTempErrorInfo(const char event[EVENT_MAX_LEN],
const char module[MODULE_MAX_LEN],
const char errorDesc[ERROR_DESC_MAX_LEN])
{
if (event == NULL || module == NULL || errorDesc == NULL) {
BBOX_PRINT_ERR("event: %p, module: %p, errorDesc: %p!\n", event, module, errorDesc);
return;
}
if (LOS_SemPend(g_tempErrInfoSem, LOS_NO_WAIT) != LOS_OK) {
BBOX_PRINT_ERR("Request g_tempErrInfoSem failed!\n");
return;
}
FormatErrorInfo(g_tempErrInfo, event, module, errorDesc);
(void)LOS_SemPost(g_tempErrInfoSem);
}
static int SaveErrorLog(UINTPTR uwParam1, UINTPTR uwParam2, UINTPTR uwParam3, UINTPTR uwParam4)
{
const char *logDir = (const char *)uwParam1;
(void)uwParam2;
(void)uwParam3;
(void)uwParam4;
#ifdef LOSCFG_FS_VFS
WaitForLogPart();
#endif
SaveLastLog(logDir);
while (1) {
if (LOS_SemPend(g_tempErrLogSaveSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_tempErrLogSaveSem failed!\n");
continue;
}
SaveTempErrorLog();
}
return 0;
}
#ifdef LOSCFG_BLACKBOX_DEBUG
static void PrintModuleOps(void)
{
struct BBoxOps *ops = NULL;
BBOX_PRINT_INFO("The following modules have been registered!\n");
LOS_DL_LIST_FOR_EACH_ENTRY(ops, &g_opsList, BBoxOps, opsList) {
if (ops == NULL) {
continue;
}
BBOX_PRINT_INFO("module: %s, Dump: %p, Reset: %p, GetLastLogInfo: %p, SaveLastLog: %p\n",
ops->ops.module, ops->ops.Dump, ops->ops.Reset, ops->ops.GetLastLogInfo, ops->ops.SaveLastLog);
}
}
#endif
int BBoxRegisterModuleOps(struct ModuleOps *ops)
{
BBoxOps *newOps = NULL;
BBoxOps *temp = NULL;
if (!g_bboxInitSucc) {
BBOX_PRINT_ERR("BlackBox isn't initialized successfully!\n");
return -1;
}
if (ops == NULL) {
BBOX_PRINT_ERR("ops is NULL!\n");
return -1;
}
newOps = LOS_MemAlloc(m_aucSysMem1, sizeof(*newOps));
if (newOps == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
return -1;
}
(void)memset_s(newOps, sizeof(*newOps), 0, sizeof(*newOps));
if (memcpy_s(&newOps->ops, sizeof(newOps->ops), ops, sizeof(*ops)) != EOK) {
BBOX_PRINT_ERR("newOps->ops is not enough or memcpy_s failed!\n");
(void)LOS_MemFree(m_aucSysMem1, newOps);
return -1;
}
if (LOS_SemPend(g_opsListSem, LOS_WAIT_FOREVER) != LOS_OK) {
BBOX_PRINT_ERR("Request g_opsListSem failed!\n");
(void)LOS_MemFree(m_aucSysMem1, newOps);
return -1;
}
if (LOS_ListEmpty(&g_opsList)) {
goto __out;
}
LOS_DL_LIST_FOR_EACH_ENTRY(temp, &g_opsList, BBoxOps, opsList) {
if (temp == NULL) {
continue;
}
if (strcmp(temp->ops.module, ops->module) == 0) {
BBOX_PRINT_ERR("module [%s] has been registered!\n", ops->module);
(void)LOS_SemPost(g_opsListSem);
(void)LOS_MemFree(m_aucSysMem1, newOps);
return -1;
}
}
__out:
LOS_ListTailInsert(&g_opsList, &newOps->opsList);
(void)LOS_SemPost(g_opsListSem);
BBOX_PRINT_INFO("module [%s] is registered successfully!\n", ops->module);
#ifdef LOSCFG_BLACKBOX_DEBUG
PrintModuleOps();
#endif
return 0;
}
int BBoxNotifyError(const char event[EVENT_MAX_LEN],
const char module[MODULE_MAX_LEN],
const char errorDesc[ERROR_DESC_MAX_LEN],
int needSysReset)
{
if (event == NULL || module == NULL || errorDesc == NULL) {
BBOX_PRINT_ERR("event: %p, module: %p, errorDesc: %p!\n", event, module, errorDesc);
return -1;
}
if (!g_bboxInitSucc) {
BBOX_PRINT_ERR("BlackBox isn't initialized successfully!\n");
return -1;
}
if (needSysReset == 0) {
SaveTempErrorInfo(event, module, errorDesc);
(void)LOS_SemPost(g_tempErrLogSaveSem);
} else {
struct ErrorInfo *info = LOS_MemAlloc(m_aucSysMem1, sizeof(struct ErrorInfo));
if (info == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
return -1;
}
FormatErrorInfo(info, event, module, errorDesc);
SaveLogWithReset(info);
(void)LOS_MemFree(m_aucSysMem1, info);
}
return 0;
}
int OsBBoxDriverInit(void)
{
UINT32 taskID;
TSK_INIT_PARAM_S taskParam;
if (LOS_BinarySemCreate(1, &g_opsListSem) != LOS_OK) {
BBOX_PRINT_ERR("Create g_opsListSem failed!\n");
return LOS_NOK;
}
if (LOS_BinarySemCreate(1, &g_tempErrInfoSem) != LOS_OK) {
BBOX_PRINT_ERR("Create g_tempErrInfoSem failed!\n");
goto __err;
}
if (LOS_BinarySemCreate(0, &g_tempErrLogSaveSem) != LOS_OK) {
BBOX_PRINT_ERR("Create g_tempErrLogSaveSem failed!\n");
goto __err;
}
LOS_ListInit(&g_opsList);
g_tempErrInfo = LOS_MemAlloc(m_aucSysMem1, sizeof(*g_tempErrInfo));
if (g_tempErrInfo == NULL) {
BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
goto __err;
}
(void)memset_s(g_tempErrInfo, sizeof(*g_tempErrInfo), 0, sizeof(*g_tempErrInfo));
(void)memset_s(&taskParam, sizeof(taskParam), 0, sizeof(taskParam));
taskParam.auwArgs[0] = (UINTPTR)LOSCFG_BLACKBOX_LOG_ROOT_PATH;
taskParam.pfnTaskEntry = (TSK_ENTRY_FUNC)SaveErrorLog;
taskParam.uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
taskParam.pcName = "SaveErrorLog";
taskParam.usTaskPrio = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO;
taskParam.uwResved = LOS_TASK_STATUS_DETACHED;
#ifdef LOSCFG_KERNEL_SMP
taskParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
#endif
(void)LOS_TaskCreate(&taskID, &taskParam);
g_bboxInitSucc = TRUE;
return LOS_OK;
__err:
if (g_opsListSem != 0) {
(void)LOS_SemDelete(g_opsListSem);
}
if (g_tempErrInfoSem != 0) {
(void)LOS_SemDelete(g_tempErrInfoSem);
}
if (g_tempErrLogSaveSem != 0) {
(void)LOS_SemDelete(g_tempErrLogSaveSem);
}
return LOS_NOK;
}
LOS_MODULE_INIT(OsBBoxDriverInit, LOS_INIT_LEVEL_ARCH);

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_blackbox_detector.h"
#include "los_blackbox_common.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
/* ------------ local macroes ------------ */
/* ------------ local prototypes ------------ */
/* ------------ local function declarations ------------ */
/* ------------ global function declarations ------------ */
/* ------------ local variables ------------ */
/* ------------ function definitions ------------ */
int UploadEventByFile(const char *filePath)
{
if (filePath == NULL) {
BBOX_PRINT_ERR("filePath is NULL\n");
return -1;
}
return 0;
}
int UploadEventByStream(const char *buf, size_t bufSize)
{
if (buf == NULL || bufSize == 0) {
BBOX_PRINT_ERR("buf: %p, bufSize: %u\n", buf, (UINT32)bufSize);
return -1;
}
return 0;
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2021-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_BLACKBOX_DETECTOR_H
#define LOS_BLACKBOX_DETECTOR_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
int UploadEventByFile(const char *filePath);
int UploadEventByStream(const char *buf, size_t bufSize);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,265 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_blackbox_system_adapter.h"
#include "los_blackbox_common.h"
#include "los_blackbox_detector.h"
#ifdef LOSCFG_LIB_LIBC
#include "stdlib.h"
#include "unistd.h"
#endif
#include "los_base.h"
#include "los_config.h"
#ifdef LOSCFG_SAVE_EXCINFO
#include "los_excinfo_pri.h"
#endif
#include "los_hw.h"
#include "los_init.h"
#include "los_memory.h"
#include "los_vm_common.h"
#include "los_vm_phys.h"
#include "los_vm_zone.h"
#include "securec.h"
/* ------------ local macroes ------------ */
#define LOG_FLAG "GOODLOG"
/* ------------ local prototypes ------------ */
struct FaultLogInfo {
char flag[8]; /* 8 is the length of the flag */
int len; /* length of the fault log saved by the module excinfo */
struct ErrorInfo info;
};
/* ------------ local function declarations ------------ */
/* ------------ global function declarations ------------ */
/* ------------ local variables ------------ */
static char *g_logBuffer = NULL;
/* ------------ function definitions ------------ */
static void SaveFaultLog(const char *filePath, const char *dataBuf, size_t bufSize, struct ErrorInfo *info)
{
(void)SaveBasicErrorInfo(filePath, info);
(void)FullWriteFile(filePath, dataBuf, bufSize, 1);
}
#ifdef LOSCFG_SAVE_EXCINFO
static void WriteExcFile(UINT32 startAddr, UINT32 space, UINT32 rwFlag, char *buf)
{
(void)startAddr;
(void)space;
(void)rwFlag;
(void)buf;
}
#endif
static void RegisterExcInfoHook(void)
{
if (g_logBuffer != NULL) {
#ifdef LOSCFG_SAVE_EXCINFO
LOS_ExcInfoRegHook(0, LOSCFG_BLACKBOX_LOG_SIZE - sizeof(struct FaultLogInfo),
g_logBuffer + sizeof(struct FaultLogInfo), WriteExcFile);
#endif
} else {
BBOX_PRINT_ERR("Alloc mem failed!\n");
}
}
static int AllocLogBuffer(void)
{
if (LOSCFG_BLACKBOX_LOG_SIZE < sizeof(struct FaultLogInfo)) {
BBOX_PRINT_ERR("LOSCFG_BLACKBOX_LOG_SIZE [%d] is too short, it must be >= %u\n",
LOSCFG_BLACKBOX_LOG_SIZE, sizeof(struct FaultLogInfo));
return -1;
}
/*
* The physical memory pointed to by LOSCFG_BLACKBOX_RESERVE_MEM_ADDR is
* exclusive to blackbox and cannot be occupied by other modules during
* system running and cannot overlap with the memory area of other systems
* during startup.
*/
g_logBuffer = (char *)MEM_CACHED_ADDR(LOSCFG_BLACKBOX_RESERVE_MEM_ADDR);
BBOX_PRINT_INFO("g_logBuffer: %p, len: 0x%x for blackbox!\n", g_logBuffer, (UINT32)LOSCFG_BLACKBOX_LOG_SIZE);
return (g_logBuffer != NULL) ? 0 : -1;
}
static void Dump(const char *logDir, struct ErrorInfo *info)
{
struct FaultLogInfo *pLogInfo = NULL;
if (logDir == NULL || info == NULL) {
BBOX_PRINT_ERR("logDir: %p, info: %p!\n", logDir, info);
return;
}
if (g_logBuffer == NULL) {
BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
return;
}
if (strcmp(info->event, EVENT_PANIC) == 0) {
pLogInfo = (struct FaultLogInfo *)g_logBuffer;
(void)memset_s(pLogInfo, sizeof(*pLogInfo), 0, sizeof(*pLogInfo));
#ifdef LOSCFG_SAVE_EXCINFO
pLogInfo->len = GetExcInfoIndex();
#else
pLogInfo->len = 0;
#endif
(void)memcpy_s(&pLogInfo->flag, sizeof(pLogInfo->flag), LOG_FLAG, strlen(LOG_FLAG));
(void)memcpy_s(&pLogInfo->info, sizeof(pLogInfo->info), info, sizeof(*info));
DCacheFlushRange((UINTPTR)g_logBuffer, (UINTPTR)(g_logBuffer + LOSCFG_BLACKBOX_LOG_SIZE));
} else {
#ifdef LOSCFG_SAVE_EXCINFO
SaveFaultLog(USER_FAULT_LOG_PATH, g_logBuffer + sizeof(struct FaultLogInfo),
Min(LOSCFG_BLACKBOX_LOG_SIZE - sizeof(struct FaultLogInfo), GetExcInfoIndex()), info);
#else
SaveFaultLog(USER_FAULT_LOG_PATH, g_logBuffer + sizeof(struct FaultLogInfo), 0, info);
#endif
}
}
static void Reset(struct ErrorInfo *info)
{
if (info == NULL) {
BBOX_PRINT_ERR("info is NULL!\n");
return;
}
if (strcmp(info->event, EVENT_PANIC) != 0) {
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
(void)UploadEventByFile(USER_FAULT_LOG_PATH);
BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
}
}
static int GetLastLogInfo(struct ErrorInfo *info)
{
struct FaultLogInfo *pLogInfo = NULL;
if (info == NULL) {
BBOX_PRINT_ERR("info is NULL!\n");
return -1;
}
if (g_logBuffer == NULL) {
BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
return -1;
}
pLogInfo = (struct FaultLogInfo *)g_logBuffer;
if (memcmp(pLogInfo->flag, LOG_FLAG, strlen(LOG_FLAG)) == 0) {
(void)memcpy_s(info, sizeof(*info), &pLogInfo->info, sizeof(pLogInfo->info));
return 0;
}
return -1;
}
static int SaveLastLog(const char *logDir, struct ErrorInfo *info)
{
#ifdef LOSCFG_FS_VFS
struct FaultLogInfo *pLogInfo = NULL;
if (logDir == NULL || info == NULL) {
BBOX_PRINT_ERR("logDir: %p, info: %p!\n", logDir, info);
return -1;
}
if (g_logBuffer == NULL) {
BBOX_PRINT_ERR("g_logBuffer is NULL, alloc physical pages failed!\n");
return -1;
}
pLogInfo = (struct FaultLogInfo *)g_logBuffer;
if (memcmp(pLogInfo->flag, LOG_FLAG, strlen(LOG_FLAG)) == 0) {
SaveFaultLog(KERNEL_FAULT_LOG_PATH, g_logBuffer + sizeof(*pLogInfo),
Min(LOSCFG_BLACKBOX_LOG_SIZE - sizeof(*pLogInfo), pLogInfo->len), info);
}
(void)memset_s(g_logBuffer, LOSCFG_BLACKBOX_LOG_SIZE, 0, LOSCFG_BLACKBOX_LOG_SIZE);
BBOX_PRINT_INFO("[%s] starts uploading event [%s]\n", info->module, info->event);
(void)UploadEventByFile(KERNEL_FAULT_LOG_PATH);
BBOX_PRINT_INFO("[%s] ends uploading event [%s]\n", info->module, info->event);
return 0;
#else
(VOID)logDir;
(VOID)info;
BBOX_PRINT_ERR("LOSCFG_FS_VFS isn't defined!\n");
return -1;
#endif
}
#ifdef LOSCFG_BLACKBOX_TEST
static void BBoxTest(void)
{
struct ModuleOps ops = {
.module = "MODULE_TEST",
.Dump = NULL,
.Reset = NULL,
.GetLastLogInfo = NULL,
.SaveLastLog = NULL,
};
if (BBoxRegisterModuleOps(&ops) != 0) {
BBOX_PRINT_ERR("BBoxRegisterModuleOps failed!\n");
return;
}
BBoxNotifyError("EVENT_TEST1", "MODULE_TEST", "Test BBoxNotifyError111", 0);
}
#endif
int OsBBoxSystemAdapterInit(void)
{
struct ModuleOps ops = {
.module = MODULE_SYSTEM,
.Dump = Dump,
.Reset = Reset,
.GetLastLogInfo = GetLastLogInfo,
.SaveLastLog = SaveLastLog,
};
/* allocate buffer for kmsg */
if (AllocLogBuffer() == 0) {
RegisterExcInfoHook();
if (BBoxRegisterModuleOps(&ops) != 0) {
BBOX_PRINT_ERR("BBoxRegisterModuleOps failed!\n");
g_logBuffer = NULL;
return LOS_NOK;
}
} else {
BBOX_PRINT_ERR("AllocLogBuffer failed!\n");
}
#ifdef LOSCFG_BLACKBOX_TEST
BBoxTest();
#endif
return LOS_OK;
}
LOS_MODULE_INIT(OsBBoxSystemAdapterInit, LOS_INIT_LEVEL_PLATFORM);

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2021-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_BLACKBOX_SYSTEM_ADAPTER_H
#define LOS_BLACKBOX_SYSTEM_ADAPTER_H
#include "los_blackbox.h"
#include "los_blackbox_common.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
int OsBBoxSystemAdapterInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -34,7 +34,7 @@ MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard src/*.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include -I $(LITEOSTOPDIR)/kernel/extended/include \
-I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/fs/include
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK) $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)

View File

@@ -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.
import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_HIDUMPER)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "los_hidumper.c" ]
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [ "." ]
}

View File

@@ -0,0 +1,6 @@
config HIDUMPER
bool "Enable hidumper"
default n
depends on KERNEL_EXTKERNEL
help
Answer Y to enable LiteOS support hidumper

View File

@@ -0,0 +1,13 @@
include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/common \
-I $(LITEOSTOPDIR)/kernel/common/hidumper \
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -0,0 +1,381 @@
/*
* Copyright (c) 2021-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.
*/
/* ------------ includes ------------ */
#include "los_hidumper.h"
#ifdef LOSCFG_BLACKBOX
#include "los_blackbox.h"
#endif
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
#include "los_cpup_pri.h"
#endif
#include "los_hwi_pri.h"
#include "los_init.h"
#include "los_mp.h"
#include "los_mux.h"
#include "los_printf.h"
#include "los_process_pri.h"
#include "los_task_pri.h"
#include "los_vm_dump.h"
#include "los_vm_lock.h"
#include "los_vm_map.h"
#ifdef LOSCFG_FS_VFS
#include "fs/file.h"
#endif
#include "fs/driver.h"
#include "securec.h"
#ifdef LOSCFG_LIB_LIBC
#include "unistd.h"
#endif
#include "user_copy.h"
/* ------------ local macroes ------------ */
#define CPUP_TYPE_COUNT 3
#define HIDUMPER_DEVICE "/dev/hidumper"
#define HIDUMPER_DEVICE_MODE 0666
#define KERNEL_FAULT_ADDR 0x1
#define KERNEL_FAULT_VALUE 0x2
#define READ_BUF_SIZE 128
#define SYS_INFO_HEADER "************ sys info ***********"
#define CPU_USAGE_HEADER "************ cpu usage ***********"
#define MEM_USAGE_HEADER "************ mem usage ***********"
#define PAGE_USAGE_HEADER "************ physical page usage ***********"
#define TASK_INFO_HEADER "************ task info ***********"
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#endif
#define REPLACE_INTERFACE(dst, src, type, func) { \
if (((type *)src)->func != NULL) { \
((type *)dst)->func = ((type *)src)->func; \
} else { \
PRINT_ERR("%s->%s is NULL!\n", #src, #func); \
} \
}
#define INVOKE_INTERFACE(adapter, type, func) { \
if (((type *)adapter)->func != NULL) { \
((type *)adapter)->func(); \
} else { \
PRINT_ERR("%s->%s is NULL!\n", #adapter, #func); \
} \
}
/* ------------ local prototypes ------------ */
/* ------------ local function declarations ------------ */
STATIC INT32 HiDumperOpen(struct file *filep);
STATIC INT32 HiDumperClose(struct file *filep);
STATIC INT32 HiDumperIoctl(struct file *filep, INT32 cmd, unsigned long arg);
/* ------------ global function declarations ------------ */
#ifdef LOSCFG_SHELL
extern VOID OsShellCmdSystemInfoGet(VOID);
extern UINT32 OsShellCmdFree(INT32 argc, const CHAR *argv[]);
extern UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[]);
extern UINT32 OsShellCmdDumpPmm(VOID);
#endif
/* ------------ local variables ------------ */
static struct HiDumperAdapter g_adapter;
STATIC struct file_operations_vfs g_hidumperDevOps = {
HiDumperOpen, /* open */
HiDumperClose, /* close */
NULL, /* read */
NULL, /* write */
NULL, /* seek */
HiDumperIoctl, /* ioctl */
NULL, /* mmap */
#ifndef CONFIG_DISABLE_POLL
NULL, /* poll */
#endif
NULL, /* unlink */
};
/* ------------ function definitions ------------ */
STATIC INT32 HiDumperOpen(struct file *filep)
{
(VOID)filep;
return 0;
}
STATIC INT32 HiDumperClose(struct file *filep)
{
(VOID)filep;
return 0;
}
static void DumpSysInfo(void)
{
PRINTK("\n%s\n", SYS_INFO_HEADER);
#ifdef LOSCFG_SHELL
const char *argv[1] = {"-a"};
(VOID)OsShellCmdUname(ARRAY_SIZE(argv), &argv[0]);
(VOID)OsShellCmdSystemInfoGet();
#else
PRINTK("\nUnsupported!\n");
#endif
}
#ifdef LOSCFG_KERNEL_CPUP
static void DoDumpCpuUsageUnsafe(CPUP_INFO_S *processCpupAll,
CPUP_INFO_S *processCpup10s,
CPUP_INFO_S *processCpup1s)
{
UINT32 pid;
PRINTK("%-32s PID CPUUSE CPUUSE10S CPUUSE1S\n", "PName");
for (pid = 0; pid < g_processMaxNum; pid++) {
LosProcessCB *processCB = g_processCBArray + pid;
if (OsProcessIsUnused(processCB)) {
continue;
}
PRINTK("%-32s %u %5u.%1u%8u.%1u%7u.%-1u\n",
processCB->processName, processCB->processID,
processCpupAll[pid].usage / LOS_CPUP_PRECISION_MULT,
processCpupAll[pid].usage % LOS_CPUP_PRECISION_MULT,
processCpup10s[pid].usage / LOS_CPUP_PRECISION_MULT,
processCpup10s[pid].usage % LOS_CPUP_PRECISION_MULT,
processCpup1s[pid].usage / LOS_CPUP_PRECISION_MULT,
processCpup1s[pid].usage % LOS_CPUP_PRECISION_MULT);
}
}
#endif
static void DumpCpuUsageUnsafe(void)
{
PRINTK("\n%s\n", CPU_USAGE_HEADER);
#ifdef LOSCFG_KERNEL_CPUP
UINT32 size;
CPUP_INFO_S *processCpup = NULL;
CPUP_INFO_S *processCpupAll = NULL;
CPUP_INFO_S *processCpup10s = NULL;
CPUP_INFO_S *processCpup1s = NULL;
size = sizeof(*processCpup) * g_processMaxNum * CPUP_TYPE_COUNT;
processCpup = LOS_MemAlloc(m_aucSysMem1, size);
if (processCpup == NULL) {
PRINT_ERR("func: %s, LOS_MemAlloc failed, Line: %d\n", __func__, __LINE__);
return;
}
processCpupAll = processCpup;
processCpup10s = processCpupAll + g_processMaxNum;
processCpup1s = processCpup10s + g_processMaxNum;
(VOID)memset_s(processCpup, size, 0, size);
LOS_GetAllProcessCpuUsage(CPUP_ALL_TIME, processCpupAll, g_processMaxNum * sizeof(CPUP_INFO_S));
LOS_GetAllProcessCpuUsage(CPUP_LAST_TEN_SECONDS, processCpup10s, g_processMaxNum * sizeof(CPUP_INFO_S));
LOS_GetAllProcessCpuUsage(CPUP_LAST_ONE_SECONDS, processCpup1s, g_processMaxNum * sizeof(CPUP_INFO_S));
DoDumpCpuUsageUnsafe(processCpupAll, processCpup10s, processCpup1s);
(VOID)LOS_MemFree(m_aucSysMem1, processCpup);
#else
PRINTK("\nUnsupported!\n");
#endif
}
static void DumpMemUsage(void)
{
PRINTK("\n%s\n", MEM_USAGE_HEADER);
#ifdef LOSCFG_SHELL
PRINTK("Unit: KB\n");
const char *argv[1] = {"-k"};
(VOID)OsShellCmdFree(ARRAY_SIZE(argv), &argv[0]);
PRINTK("%s\n", PAGE_USAGE_HEADER);
(VOID)OsShellCmdDumpPmm();
#else
PRINTK("\nUnsupported!\n");
#endif
}
static void DumpTaskInfo(void)
{
PRINTK("\n%s\n", TASK_INFO_HEADER);
#ifdef LOSCFG_SHELL
(VOID)OsShellCmdTskInfoGet(OS_ALL_TASK_MASK, NULL, OS_PROCESS_INFO_ALL);
#else
PRINTK("\nUnsupported!\n");
#endif
}
#ifdef LOSCFG_BLACKBOX
static void PrintFileData(INT32 fd)
{
#ifdef LOSCFG_FS_VFS
CHAR buf[READ_BUF_SIZE];
if (fd < 0) {
PRINT_ERR("fd: %d!\n", fd);
return;
}
(void)memset_s(buf, sizeof(buf), 0, sizeof(buf));
while (read(fd, buf, sizeof(buf) - 1) > 0) {
PRINTK("%s", buf);
(void)memset_s(buf, sizeof(buf), 0, sizeof(buf));
}
#else
(VOID)fd;
PRINT_ERR("LOSCFG_FS_VFS isn't defined!\n");
#endif
}
static void PrintFile(const char *filePath, const char *pHeader)
{
#ifdef LOSCFG_FS_VFS
int fd;
if (filePath == NULL || pHeader == NULL) {
PRINT_ERR("filePath: %p, pHeader: %p\n", filePath, pHeader);
return;
}
fd = open(filePath, O_RDONLY);
if (fd >= 0) {
PRINTK("\n%s\n", pHeader);
PrintFileData(fd);
(void)close(fd);
} else {
PRINT_ERR("Open [%s] failed or there's no fault log!\n", filePath);
}
#else
(VOID)filePath;
(VOID)pHeader;
PRINT_ERR("LOSCFG_FS_VFS isn't defined!\n");
#endif
}
#endif
static void DumpFaultLog(void)
{
#ifdef LOSCFG_BLACKBOX
PrintFile(KERNEL_FAULT_LOG_PATH, "************kernel fault info************");
PrintFile(USER_FAULT_LOG_PATH, "************user fault info************");
#endif
}
static void DumpMemData(struct MemDumpParam *param)
{
PRINTK("\nDumpType: %d\n", param->type);
PRINTK("Unsupported now!\n");
}
static void InjectKernelCrash(void)
{
#ifdef LOSCFG_DEBUG_VERSION
*((INT32 *)KERNEL_FAULT_ADDR) = KERNEL_FAULT_VALUE;
#else
PRINTK("\nUnsupported!\n");
#endif
}
static INT32 HiDumperIoctl(struct file *filep, INT32 cmd, unsigned long arg)
{
INT32 ret = 0;
switch (cmd) {
case HIDUMPER_DUMP_ALL:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpSysInfo);
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpCpuUsage);
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpMemUsage);
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpTaskInfo);
break;
case HIDUMPER_CPU_USAGE:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpCpuUsage);
break;
case HIDUMPER_MEM_USAGE:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpMemUsage);
break;
case HIDUMPER_TASK_INFO:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpTaskInfo);
break;
case HIDUMPER_INJECT_KERNEL_CRASH:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, InjectKernelCrash);
break;
case HIDUMPER_DUMP_FAULT_LOG:
INVOKE_INTERFACE(&g_adapter, struct HiDumperAdapter, DumpFaultLog);
break;
case HIDUMPER_MEM_DATA:
if (g_adapter.DumpMemData != NULL) {
g_adapter.DumpMemData((struct MemDumpParam *)arg);
}
break;
default:
ret = EPERM;
PRINTK("Invalid CMD: 0x%x\n", (UINT32)cmd);
break;
}
return ret;
}
static void RegisterCommonAdapter(void)
{
struct HiDumperAdapter adapter;
adapter.DumpSysInfo = DumpSysInfo;
adapter.DumpCpuUsage = DumpCpuUsageUnsafe;
adapter.DumpMemUsage = DumpMemUsage;
adapter.DumpTaskInfo = DumpTaskInfo;
adapter.DumpFaultLog = DumpFaultLog;
adapter.DumpMemData = DumpMemData;
adapter.InjectKernelCrash = InjectKernelCrash;
HiDumperRegisterAdapter(&adapter);
}
int HiDumperRegisterAdapter(struct HiDumperAdapter *pAdapter)
{
if (pAdapter == NULL) {
PRINT_ERR("pAdapter: %p\n", pAdapter);
return -1;
}
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpSysInfo);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpCpuUsage);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpMemUsage);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpTaskInfo);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpFaultLog);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, DumpMemData);
REPLACE_INTERFACE(&g_adapter, pAdapter, struct HiDumperAdapter, InjectKernelCrash);
return 0;
}
int OsHiDumperDriverInit(void)
{
INT32 ret;
#ifdef LOSCFG_DEBUG_VERSION
RegisterCommonAdapter();
ret = register_driver(HIDUMPER_DEVICE, &g_hidumperDevOps, HIDUMPER_DEVICE_MODE, NULL);
if (ret != 0) {
PRINT_ERR("Hidumper register driver failed!\n");
return -1;
}
#endif
return 0;
}
LOS_MODULE_INIT(OsHiDumperDriverInit, LOS_INIT_LEVEL_KMOD_EXTENDED);

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2021-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_HIDUMPER_H
#define LOS_HIDUMPER_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifndef __user
#define __user
#endif
#define PATH_MAX_LEN 256
enum MemDumpType {
DUMP_TO_STDOUT,
DUMP_REGION_TO_STDOUT,
DUMP_TO_FILE,
DUMP_REGION_TO_FILE
};
struct MemDumpParam {
enum MemDumpType type;
unsigned long long start;
unsigned long long size;
char filePath[PATH_MAX_LEN];
};
struct HiDumperAdapter {
void (*DumpSysInfo)(void);
void (*DumpCpuUsage)(void);
void (*DumpMemUsage)(void);
void (*DumpTaskInfo)(void);
void (*DumpFaultLog)(void);
void (*DumpMemData)(struct MemDumpParam *param);
void (*InjectKernelCrash)(void);
};
#define HIDUMPER_IOC_BASE 'd'
#define HIDUMPER_DUMP_ALL _IO(HIDUMPER_IOC_BASE, 1)
#define HIDUMPER_CPU_USAGE _IO(HIDUMPER_IOC_BASE, 2)
#define HIDUMPER_MEM_USAGE _IO(HIDUMPER_IOC_BASE, 3)
#define HIDUMPER_TASK_INFO _IO(HIDUMPER_IOC_BASE, 4)
#define HIDUMPER_INJECT_KERNEL_CRASH _IO(HIDUMPER_IOC_BASE, 5)
#define HIDUMPER_DUMP_FAULT_LOG _IO(HIDUMPER_IOC_BASE, 6)
#define HIDUMPER_MEM_DATA _IOW(HIDUMPER_IOC_BASE, 7, struct MemDumpParam)
int HiDumperRegisterAdapter(struct HiDumperAdapter *pAdapter);
int OsHiDumperDriverInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -32,7 +32,10 @@ import("//kernel/liteos_a/liteos.gni")
module_switch = defined(LOSCFG_BASE_CORE_HILOG)
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = [ "//base/hiviewdfx/hilog_lite/frameworks/featured/hiview_log.c" ]
sources = [
"//base/hiviewdfx/hilog_lite/frameworks/featured/hiview_log.c",
"los_hilog.c",
]
public_configs = [ ":public" ]
}
@@ -41,5 +44,6 @@ config("public") {
include_dirs = [
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog",
".",
]
}

View File

@@ -0,0 +1,40 @@
# 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 $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := $(wildcard *.c)
LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/kernel/base/include
LOCAL_FLAGS := $(LITEOS_CFLAGS_INTERWORK) $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
include $(MODULE)

View File

@@ -0,0 +1,339 @@
/*
* 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_hilog.h"
#include "los_init.h"
#include "los_mp.h"
#include "los_mux.h"
#include "los_process_pri.h"
#include "los_task_pri.h"
#include "fs/file.h"
#include "fs/driver.h"
#include "los_vm_map.h"
#include "los_vm_lock.h"
#include "user_copy.h"
#define HILOG_BUFFER 4096
#define DRIVER_MODE 0666
#define HILOG_DRIVER "/dev/hilog"
struct HiLogEntry {
unsigned int len;
unsigned int hdrSize;
unsigned int pid : 16;
unsigned int taskId : 16;
unsigned int sec;
unsigned int nsec;
unsigned int reserved;
char msg[0];
};
ssize_t HilogRead(struct file *filep, char __user *buf, size_t count);
ssize_t HilogWrite(struct file *filep, const char __user *buf, size_t count);
int HiLogOpen(struct file *filep);
int HiLogClose(struct file *filep);
static ssize_t HiLogWrite(struct file *filep, const char *buffer, size_t bufLen);
static ssize_t HiLogRead(struct file *filep, char *buffer, size_t bufLen);
STATIC struct file_operations_vfs g_hilogFops = {
HiLogOpen, /* open */
HiLogClose, /* close */
HiLogRead, /* read */
HiLogWrite, /* write */
NULL, /* seek */
NULL, /* ioctl */
NULL, /* mmap */
#ifndef CONFIG_DISABLE_POLL
NULL, /* poll */
#endif
NULL, /* unlink */
};
struct HiLogCharDevice {
int flag;
LosMux mtx;
unsigned char *buffer;
wait_queue_head_t wq;
size_t writeOffset;
size_t headOffset;
size_t size;
size_t count;
} g_hiLogDev;
static inline unsigned char *HiLogBufferHead(void)
{
return g_hiLogDev.buffer + g_hiLogDev.headOffset;
}
int HiLogOpen(struct file *filep)
{
(void)filep;
return 0;
}
int HiLogClose(struct file *filep)
{
(void)filep;
return 0;
}
static void HiLogBufferInc(size_t sz)
{
if (g_hiLogDev.size + sz <= HILOG_BUFFER) {
g_hiLogDev.size += sz;
g_hiLogDev.writeOffset += sz;
g_hiLogDev.writeOffset %= HILOG_BUFFER;
g_hiLogDev.count++;
}
}
static void HiLogBufferDec(size_t sz)
{
if (g_hiLogDev.size >= sz) {
g_hiLogDev.size -= sz;
g_hiLogDev.headOffset += sz;
g_hiLogDev.headOffset %= HILOG_BUFFER;
g_hiLogDev.count--;
}
}
static int HiLogBufferCopy(unsigned char *dst, unsigned dstLen, const unsigned char *src, size_t srcLen)
{
int retval = -1;
size_t minLen = (dstLen > srcLen) ? srcLen : dstLen;
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dst, minLen) &&
LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, minLen)) {
return retval;
}
if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dst, minLen)) {
retval = LOS_ArchCopyToUser(dst, src, minLen);
} else if (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, minLen)) {
retval = LOS_ArchCopyFromUser(dst, src, minLen);
} else {
retval = memcpy_s(dst, dstLen, src, srcLen);
}
return retval;
}
static int HiLogReadRingBuffer(unsigned char *buffer, size_t bufLen)
{
size_t retval;
size_t bufLeft = HILOG_BUFFER - g_hiLogDev.headOffset;
if (bufLeft > bufLen) {
retval = HiLogBufferCopy(buffer, bufLen, HiLogBufferHead(), bufLen);
} else {
retval = HiLogBufferCopy(buffer, bufLen, HiLogBufferHead(), bufLeft);
if (retval < 0) {
return retval;
}
retval = HiLogBufferCopy(buffer + bufLeft, bufLen - bufLeft, g_hiLogDev.buffer, bufLen - bufLeft);
}
return retval;
}
static ssize_t HiLogRead(struct file *filep, char *buffer, size_t bufLen)
{
size_t retval;
struct HiLogEntry header;
(void)filep;
wait_event_interruptible(g_hiLogDev.wq, (g_hiLogDev.size > 0));
(VOID)LOS_MuxAcquire(&g_hiLogDev.mtx);
retval = HiLogReadRingBuffer((unsigned char *)&header, sizeof(header));
if (retval < 0) {
retval = -EINVAL;
goto out;
}
if (bufLen < header.len + sizeof(header)) {
dprintf("buffer too small,bufLen=%d, header.len=%d,%d\n", bufLen, header.len, header.hdrSize);
retval = -ENOMEM;
goto out;
}
HiLogBufferDec(sizeof(header));
retval = HiLogBufferCopy((unsigned char *)buffer, bufLen, (unsigned char *)&header, sizeof(header));
if (retval < 0) {
retval = -EINVAL;
goto out;
}
retval = HiLogReadRingBuffer((unsigned char *)(buffer + sizeof(header)), header.len);
if (retval < 0) {
retval = -EINVAL;
goto out;
}
HiLogBufferDec(header.len);
retval = header.len + sizeof(header);
out:
(VOID)LOS_MuxRelease(&g_hiLogDev.mtx);
return retval;
}
static int HiLogWriteRingBuffer(unsigned char *buffer, size_t bufLen)
{
int retval;
size_t bufLeft = HILOG_BUFFER - g_hiLogDev.writeOffset;
if (bufLen > bufLeft) {
retval = HiLogBufferCopy(g_hiLogDev.buffer + g_hiLogDev.writeOffset, bufLeft, buffer, bufLeft);
if (retval) {
return -1;
}
retval = HiLogBufferCopy(g_hiLogDev.buffer, HILOG_BUFFER, buffer + bufLeft, bufLen - bufLeft);
} else {
retval = HiLogBufferCopy(g_hiLogDev.buffer + g_hiLogDev.writeOffset, bufLeft, buffer, bufLen);
}
if (retval < 0) {
return -1;
}
return 0;
}
static void HiLogHeadInit(struct HiLogEntry *header, size_t len)
{
struct timespec now;
int ret;
ret = clock_gettime(CLOCK_REALTIME, &now);
if (ret != 0) {
dprintf("In %s line %d,clock_gettime fail", __FUNCTION__, __LINE__);
return;
}
header->len = len;
header->pid = LOS_GetCurrProcessID();
header->taskId = LOS_CurTaskIDGet();
header->sec = now.tv_sec;
header->nsec = now.tv_nsec;
header->hdrSize = sizeof(struct HiLogEntry);
}
static void HiLogCoverOldLog(size_t bufLen)
{
int retval;
struct HiLogEntry header;
size_t totalSize = bufLen + sizeof(struct HiLogEntry);
while (totalSize + g_hiLogDev.size > HILOG_BUFFER) {
retval = HiLogReadRingBuffer((unsigned char *)&header, sizeof(header));
if (retval < 0) {
break;
}
HiLogBufferDec(sizeof(header));
HiLogBufferDec(header.len);
}
}
int HiLogWriteInternal(const char *buffer, size_t bufLen)
{
struct HiLogEntry header;
int retval;
LosTaskCB *runTask = (LosTaskCB *)OsCurrTaskGet();
if ((g_hiLogDev.buffer == NULL) || (OS_INT_ACTIVE) || (runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK)) {
PRINTK("%s\n", buffer);
return -EAGAIN;
}
(VOID)LOS_MuxAcquire(&g_hiLogDev.mtx);
HiLogCoverOldLog(bufLen);
HiLogHeadInit(&header, bufLen);
retval = HiLogWriteRingBuffer((unsigned char *)&header, sizeof(header));
if (retval) {
retval = -ENODATA;
goto out;
}
HiLogBufferInc(sizeof(header));
retval = HiLogWriteRingBuffer((unsigned char *)(buffer), header.len);
if (retval) {
retval = -ENODATA;
goto out;
}
HiLogBufferInc(header.len);
retval = header.len;
out:
(VOID)LOS_MuxRelease(&g_hiLogDev.mtx);
if (retval > 0) {
wake_up_interruptible(&g_hiLogDev.wq);
}
if (retval < 0) {
dprintf("write fail retval=%d\n", retval);
}
return retval;
}
static ssize_t HiLogWrite(struct file *filep, const char *buffer, size_t bufLen)
{
(void)filep;
if (bufLen + sizeof(struct HiLogEntry) > HILOG_BUFFER) {
dprintf("input too large\n");
return -ENOMEM;
}
return HiLogWriteInternal(buffer, bufLen);
}
static void HiLogDeviceInit(void)
{
g_hiLogDev.buffer = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, HILOG_BUFFER);
if (g_hiLogDev.buffer == NULL) {
dprintf("In %s line %d,LOS_MemAlloc fail", __FUNCTION__, __LINE__);
}
init_waitqueue_head(&g_hiLogDev.wq);
LOS_MuxInit(&g_hiLogDev.mtx, NULL);
g_hiLogDev.writeOffset = 0;
g_hiLogDev.headOffset = 0;
g_hiLogDev.size = 0;
g_hiLogDev.count = 0;
}
int OsHiLogDriverInit(VOID)
{
HiLogDeviceInit();
return register_driver(HILOG_DRIVER, &g_hilogFops, DRIVER_MODE, NULL);
}
LOS_MODULE_INIT(OsHiLogDriverInit, LOS_INIT_LEVEL_KMOD_EXTENDED);

View File

@@ -0,0 +1,53 @@
/*
* 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_HILOG_H
#define LOS_HILOG_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#ifndef __user
#define __user
#endif
extern int OsHiLogDriverInit(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,78 @@
config KERNEL_TRACE
bool "Enable Trace Feature"
default n
depends on KERNEL_HOOK
config TRACE_MSG_EXTEND
bool "Enable Record more extended content"
default n
depends on KERNEL_TRACE
config TRACE_FRAME_CORE_MSG
bool "Record cpuid, hardware interrupt status, task lock status"
default n
depends on TRACE_MSG_EXTEND
config TRACE_FRAME_EVENT_COUNT
bool "Record event count, which indicate the sequence of happend events"
default n
depends on TRACE_MSG_EXTEND
config TRACE_FRAME_MAX_PARAMS
int "Record max params"
default 3
depends on KERNEL_TRACE
help
Make sure the max value is bigger than the number defined by each #MODULE#_#TYPE#_PARMAS in los_trace.h, e.g. TASK_SWITCH_PARAMS
choice
prompt "Trace work mode"
default RECORDER_MODE_OFFLINE
depends on KERNEL_TRACE
config RECORDER_MODE_ONLINE
bool "Online mode"
select TRACE_CLIENT_INTERACT
config RECORDER_MODE_OFFLINE
bool "Offline mode"
endchoice
config TRACE_BUFFER_SIZE
int "Trace record buffer size"
default 10000
depends on RECORDER_MODE_OFFLINE
config TRACE_CLIENT_INTERACT
bool "Enable Trace Client Visualization and Control"
default n
depends on KERNEL_TRACE
choice
prompt "Trace Pipeline for Data Transmission"
depends on TRACE_CLIENT_INTERACT
config TRACE_PIPELINE_SERIAL
bool "Via Serial"
endchoice
choice
prompt "Trace Control"
default TRACE_CONTROL_VIA_SHELL
depends on TRACE_CLIENT_INTERACT
help
If you wish to control Trace's start/stop etc.,dynamically by Trace Client.
config TRACE_CONTROL_VIA_SHELL
bool "Via Shell"
select LOSCFG_SHELL
config TRACE_CONTROL_AGENT
bool "Via Trace Agent Task"
config TRACE_NO_CONTROL
bool "No Control"
endchoice

View File

@@ -35,7 +35,6 @@ shared_library("OHOS-vdso") {
include_dirs = [
"$LITEOSTOPDIR/kernel/extended/vdso/include",
"$LITEOSTOPDIR/kernel/include",
"$LITEOSTOPDIR/platform",
"$LITEOSTOPDIR/bsd/compat/linuxkpi/include",
]