Compare commits
127 Commits
OpenHarmon
...
OpenHarmon
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7030357cd | ||
|
|
6b4aa6a4c9 | ||
|
|
650d2b91cd | ||
|
|
7b7d64cc87 | ||
|
|
70c18b4a75 | ||
|
|
14bd753aa8 | ||
|
|
8729f6ee57 | ||
|
|
51a50c95b4 | ||
|
|
9d3e872454 | ||
|
|
80473f0975 | ||
|
|
c40e1464b9 | ||
|
|
700c3415c4 | ||
|
|
0973004870 | ||
|
|
d79fd50693 | ||
|
|
9547133e64 | ||
|
|
d9ed4b4bf6 | ||
|
|
60bf2fc517 | ||
|
|
cb17fa50ed | ||
|
|
a531da901d | ||
|
|
a195aac9fb | ||
|
|
1157c4a289 | ||
|
|
0056b4ade5 | ||
|
|
78a50aff99 | ||
|
|
7240fe3bd4 | ||
|
|
e7c4b1963a | ||
|
|
fd6f91bc9f | ||
|
|
33f5c70e6c | ||
|
|
ec977a1c7e | ||
|
|
390159f58a | ||
|
|
d8be8aad65 | ||
|
|
6d948a42bb | ||
|
|
72d9aa1bcb | ||
|
|
8390738de5 | ||
|
|
cacb4f0103 | ||
|
|
ee54cd8b7e | ||
|
|
f523d7a98c | ||
|
|
d7387508e3 | ||
|
|
e4ff04586f | ||
|
|
8784694686 | ||
|
|
b29d9d88ab | ||
|
|
d8263b1e91 | ||
|
|
9304a683ad | ||
|
|
78906f4a6c | ||
|
|
ee7eb89354 | ||
|
|
55e5e29005 | ||
|
|
ac8c2c6d5b | ||
|
|
feae60c8fe | ||
|
|
425975e481 | ||
|
|
cc731d1e69 | ||
|
|
56a95b9ec9 | ||
|
|
3e7622ca78 | ||
|
|
b1b4ddcc7d | ||
|
|
23fd4e55a3 | ||
|
|
e57dc7762b | ||
|
|
003810284c | ||
|
|
379d602ab6 | ||
|
|
bf7b2c0a3e | ||
|
|
4e4f2d6d7e | ||
|
|
d7672d47f2 | ||
|
|
abbeca1cb2 | ||
|
|
50c8abc521 | ||
|
|
0469e5b849 | ||
|
|
dfea902a08 | ||
|
|
339c467e71 | ||
|
|
455e42e5b9 | ||
|
|
6f6dc4f24c | ||
|
|
9e45086d19 | ||
|
|
9515d53dcc | ||
|
|
e0a27badde | ||
|
|
49856dc1e0 | ||
|
|
43bdf2f1d3 | ||
|
|
eb1900d4db | ||
|
|
7de43bb004 | ||
|
|
1d952a254a | ||
|
|
9db3407589 | ||
|
|
bb6abd8c6b | ||
|
|
3cddcb9f66 | ||
|
|
bfd27e78b2 | ||
|
|
a8384b5db2 | ||
|
|
5db839acef | ||
|
|
f4626985fd | ||
|
|
68da7aefc5 | ||
|
|
f1b4c87bc4 | ||
|
|
1348809807 | ||
|
|
eb72f78cf1 | ||
|
|
12577eade5 | ||
|
|
de6db86df3 | ||
|
|
56b8ecaf17 | ||
|
|
1e345f18b3 | ||
|
|
f793dc1097 | ||
|
|
112cdebe41 | ||
|
|
a28dcc38c9 | ||
|
|
3d1cf683f3 | ||
|
|
a9fc1e0e5d | ||
|
|
2e2b14205f | ||
|
|
b8e18ffdf1 | ||
|
|
21d8ac8752 | ||
|
|
008fa8660d | ||
|
|
6860246cfa | ||
|
|
8a3d188240 | ||
|
|
8f0d25225e | ||
|
|
8fe0cc7770 | ||
|
|
ee4cf83121 | ||
|
|
702d8d9dde | ||
|
|
290a3c6f92 | ||
|
|
600dded31e | ||
|
|
67806596a3 | ||
|
|
88fe4eb3e1 | ||
|
|
ca40c79761 | ||
|
|
231cb6be27 | ||
|
|
7f484dfa09 | ||
|
|
1fa6ba3389 | ||
|
|
b7f2df0350 | ||
|
|
8bb4538de1 | ||
|
|
99d7072332 | ||
|
|
30f5ab89b7 | ||
|
|
fd3f4072b5 | ||
|
|
143efc0fab | ||
|
|
2f3d7efc24 | ||
|
|
e76c0046f7 | ||
|
|
b3120b5498 | ||
|
|
53c6d96c6f | ||
|
|
3f84ed5075 | ||
|
|
e9ad6b71c3 | ||
|
|
fbfd71dfe3 | ||
|
|
e4b6ba56b9 | ||
|
|
6e95771303 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -16,9 +16,9 @@ cscope*
|
||||
tags
|
||||
|
||||
# Menuconfig temp files
|
||||
/include/config
|
||||
/include/generated
|
||||
.config*
|
||||
/config.h
|
||||
.config
|
||||
.config.old
|
||||
|
||||
# Build temp files
|
||||
/platform/board.ld
|
||||
|
||||
11
BUILD.gn
11
BUILD.gn
@@ -73,11 +73,10 @@ lite_subsystem("kernel") {
|
||||
|
||||
build_ext_component("make") {
|
||||
exec_path = rebase_path(".", root_build_dir)
|
||||
tee_enable = "false"
|
||||
if (board_name == "hi3516dv300" && enable_tee_ree) {
|
||||
tee_enable = "tee"
|
||||
}
|
||||
prebuilts = "sh build.sh ${board_name} ${ohos_build_compiler} ${root_build_dir} ${ohos_build_type} ${tee_enable} \"${device_company}\" \"${product_path}\""
|
||||
outdir = rebase_path(get_path_info(".", "out_dir"))
|
||||
command = "make clean OUTDIR=$outdir && make rootfs VERSION=\"${ohos_version}\" -j 16 OUTDIR=$outdir"
|
||||
sysroot_path = rebase_path(ohos_current_sysroot)
|
||||
arch_cflags = string_join(" ", target_arch_cflags)
|
||||
command = "./build.sh ${board_name} ${ohos_build_compiler} ${root_build_dir} ${ohos_build_type} \"${tee_enable}\""
|
||||
command += " \"${device_company}\" \"${product_path}\" $outdir \"${ohos_version}\" ${sysroot_path} \"${arch_cflags}\""
|
||||
command += " \"${device_path}\""
|
||||
}
|
||||
|
||||
56
Kconfig
56
Kconfig
@@ -52,15 +52,19 @@ endmenu
|
||||
menu "Platform"
|
||||
|
||||
######################### config options of bsp #####################
|
||||
source "../../kernel/liteos_a/platform/Kconfig"
|
||||
source "platform/Kconfig"
|
||||
|
||||
######################### config options of cpu arch ################
|
||||
source "../../kernel/liteos_a/arch/Kconfig"
|
||||
source "arch/Kconfig"
|
||||
|
||||
######################### config options of rootfs #####################
|
||||
source "../../kernel/liteos_a/kernel/common/Kconfig"
|
||||
source "kernel/common/Kconfig"
|
||||
######################### config options of patchfs #####################
|
||||
source "../../kernel/liteos_a/kernel/common/patchfs/Kconfig"
|
||||
source "kernel/common/patchfs/Kconfig"
|
||||
######################### config options of blackbox #####################
|
||||
source "kernel/common/blackbox/Kconfig"
|
||||
######################### config options of hidumper #####################
|
||||
source "kernel/common/hidumper/Kconfig"
|
||||
|
||||
config QUICK_START
|
||||
bool "Enable QUICK_START"
|
||||
@@ -71,27 +75,24 @@ config QUICK_START
|
||||
endmenu
|
||||
|
||||
######################### config options of kernel #####################
|
||||
source "../../kernel/liteos_a/kernel/Kconfig"
|
||||
source "kernel/Kconfig"
|
||||
######################### config options of lib ########################
|
||||
source "../../kernel/liteos_a/lib/Kconfig"
|
||||
source "lib/Kconfig"
|
||||
######################### config options of compatibility ##############
|
||||
menu "Compat"
|
||||
source "../../kernel/liteos_a/compat/posix/Kconfig"
|
||||
source "../../kernel/liteos_a/bsd/Kconfig"
|
||||
source "compat/posix/Kconfig"
|
||||
source "bsd/Kconfig"
|
||||
endmenu
|
||||
|
||||
######################### config options of framework ##################
|
||||
#source "../../frameworks/m2mcomm/Kconfig"
|
||||
|
||||
######################## config options of filesystem ##################
|
||||
menu "FileSystem"
|
||||
source "../../kernel/liteos_a/fs/vfs/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/fat/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/ramfs/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/romfs/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/nfs/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/proc/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/jffs2/Kconfig"
|
||||
source "fs/vfs/Kconfig"
|
||||
source "fs/fat/Kconfig"
|
||||
source "fs/ramfs/Kconfig"
|
||||
source "fs/romfs/Kconfig"
|
||||
source "fs/nfs/Kconfig"
|
||||
source "fs/proc/Kconfig"
|
||||
source "fs/jffs2/Kconfig"
|
||||
config ENABLE_READ_BUFFER
|
||||
bool "Enable read buffer Option"
|
||||
default n
|
||||
@@ -117,7 +118,7 @@ config MAX_PATH_CACHE_SIZE
|
||||
endmenu
|
||||
|
||||
######################## config options of net ############################
|
||||
source "../../kernel/liteos_a/net/Kconfig"
|
||||
source "net/Kconfig"
|
||||
|
||||
######################## config options of debug ########################
|
||||
menu "Debug"
|
||||
@@ -219,14 +220,14 @@ config DEBUG_SEMAPHORE
|
||||
help
|
||||
Answer Y to enable debug semaphore.
|
||||
|
||||
source "../../kernel/liteos_a/shell/Kconfig"
|
||||
source "shell/Kconfig"
|
||||
config NET_LWIP_SACK_TFTP
|
||||
bool "Enable Tftp"
|
||||
default y
|
||||
depends on SHELL && NET_LWIP_SACK && DEBUG_VERSION
|
||||
help
|
||||
Answer Y to enable LiteOS support tftp cmd and tftp tool.
|
||||
source "../../kernel/liteos_a/net/telnet/Kconfig"
|
||||
source "net/telnet/Kconfig"
|
||||
config SCHED_DEBUG
|
||||
bool "Enable sched debug Feature"
|
||||
default n
|
||||
@@ -265,7 +266,7 @@ config MEM_LEAKCHECK
|
||||
help
|
||||
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the infomations of mem node.
|
||||
config BASE_MEM_NODE_INTEGRITY_CHECK
|
||||
bool "Enable integrity check or not "
|
||||
bool "Enable integrity check or not"
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
config MEM_WATERLINE
|
||||
@@ -290,20 +291,25 @@ config DRIVERS
|
||||
help
|
||||
Answer Y to enable LiteOS support driver.
|
||||
|
||||
source "../../kernel/liteos_a/bsd/dev/usb/Kconfig"
|
||||
source "bsd/dev/usb/Kconfig"
|
||||
source "../../drivers/adapter/khdf/liteos/Kconfig"
|
||||
|
||||
# Device driver Kconfig import
|
||||
osource "$(DEVICE_PATH)/Kconfig"
|
||||
osource "$(DEVICE_PATH)/config/Kconfig"
|
||||
|
||||
source "drivers/char/mem/Kconfig"
|
||||
source "drivers/char/quickstart/Kconfig"
|
||||
source "drivers/char/random/Kconfig"
|
||||
source "../../drivers/liteos/tzdriver/Kconfig"
|
||||
source "drivers/char/video/Kconfig"
|
||||
|
||||
source "../../drivers/liteos/tzdriver/Kconfig"
|
||||
source "../../drivers/liteos/hievent/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Security"
|
||||
source "../../kernel/liteos_a/security/Kconfig"
|
||||
source "security/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Test"
|
||||
|
||||
61
Makefile
61
Makefile
@@ -47,22 +47,17 @@ ROOTFS = rootfs
|
||||
|
||||
LITEOS_TARGET = liteos
|
||||
LITEOS_LIBS_TARGET = libs_target
|
||||
LITEOS_MENUCONFIG_H = $(LITEOSTOPDIR)/include/generated/autoconf.h
|
||||
LITEOS_PLATFORM_BASE = $(LITEOSTOPDIR)/platform
|
||||
|
||||
export CONFIG_=LOSCFG_
|
||||
MENUCONFIG_PATH = $(LITEOSTOPDIR)/tools/menuconfig
|
||||
KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig
|
||||
|
||||
ifeq ($(OS), Linux)
|
||||
MENUCONFIG_MCONF := $(MENUCONFIG_PATH)/mconf
|
||||
MENUCONFIG_CONF := $(MENUCONFIG_PATH)/conf
|
||||
else
|
||||
MENUCONFIG_MCONF := $(MENUCONFIG_PATH)/kconfig-mconf.exe
|
||||
MENUCONFIG_CONF := $(MENUCONFIG_PATH)/kconfig-conf.exe
|
||||
ifeq ($(PRODUCT_PATH),)
|
||||
export PRODUCT_PATH=$(LITEOSTOPDIR)/../../device/hisilicon/drivers
|
||||
endif
|
||||
|
||||
$(shell env CONFIG_=$(CONFIG_) $(MENUCONFIG_CONF) -s --olddefconfig $(KCONFIG_FILE_PATH))
|
||||
ifeq ($(shell which menuconfig),)
|
||||
$(shell pip install --user kconfiglib >/dev/null)
|
||||
endif
|
||||
$(shell env CONFIG_=$(CONFIG_) PRODUCT_PATH=$(PRODUCT_PATH) olddefconfig >/dev/null)
|
||||
|
||||
-include $(LITEOSTOPDIR)/tools/build/config.mk
|
||||
|
||||
@@ -82,6 +77,9 @@ ROOTFS_DIR = $(OUT)/rootfs
|
||||
ROOTFS_ZIP = $(OUT)/rootfs.zip
|
||||
VERSION =
|
||||
|
||||
SYSROOT_PATH ?= $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot
|
||||
export SYSROOT_PATH
|
||||
|
||||
all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS)
|
||||
lib: $(OUT) $(BUILD) $(LITEOS_LIBS_TARGET)
|
||||
|
||||
@@ -113,6 +111,15 @@ else
|
||||
$(HIDE)$(SCRIPTS_PATH)/mklibversion.sh
|
||||
endif
|
||||
|
||||
##### make sysroot #####
|
||||
sysroot:
|
||||
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
|
||||
ifeq ($(wildcard $(SYSROOT_PATH)/usr/include/$(LLVM_TARGET)/),)
|
||||
$(HIDE)$(MAKE) -C $(SYSROOT_PATH)/build TARGETS=liteos_a_user
|
||||
endif
|
||||
$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH))
|
||||
endif
|
||||
|
||||
##### make dynload #####
|
||||
-include $(LITEOS_MK_PATH)/dynload.mk
|
||||
|
||||
@@ -129,26 +136,21 @@ $(OUT): $(LITEOS_MENUCONFIG_H)
|
||||
$(BUILD):
|
||||
$(HIDE)mkdir -p $(BUILD)
|
||||
|
||||
$(LITEOS_LIBS_TARGET): $(__LIBS)
|
||||
$(LITEOS_LIBS_TARGET): $(__LIBS) sysroot
|
||||
$(HIDE)for dir in $(LIB_SUBDIRS); \
|
||||
do $(MAKE) -C $$dir all || exit 1; \
|
||||
done
|
||||
$(HIDE)echo "=============== make lib done ==============="
|
||||
|
||||
##### make menuconfig #####
|
||||
menuconfig:$(MENUCONFIG_MCONF)
|
||||
$< $(KCONFIG_FILE_PATH)
|
||||
|
||||
genconfig:$(MENUCONFIG_CONF)
|
||||
$(HIDE)mkdir -p include/config include/generated
|
||||
$< --olddefconfig $(KCONFIG_FILE_PATH)
|
||||
$< --silentoldconfig $(KCONFIG_FILE_PATH)
|
||||
menuconfig:
|
||||
$(HIDE)menuconfig
|
||||
##### menuconfig end #######
|
||||
|
||||
$(LITEOS_MENUCONFIG_H): .config
|
||||
$(HIDE)$(MAKE) genconfig
|
||||
$(HIDE)genconfig
|
||||
|
||||
$(LITEOS_TARGET): $(__LIBS)
|
||||
$(LITEOS_TARGET): $(__LIBS) sysroot
|
||||
$(HIDE)touch $(LOSCFG_ENTRY_SRC)
|
||||
|
||||
$(HIDE)for dir in $(LITEOS_SUBDIRS); \
|
||||
@@ -162,14 +164,14 @@ $(LITEOS_TARGET): $(__LIBS)
|
||||
$(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm
|
||||
# $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size
|
||||
|
||||
$(APPS): $(LITEOS_TARGET)
|
||||
$(APPS): $(LITEOS_TARGET) sysroot
|
||||
$(HIDE)$(MAKE) -C apps all
|
||||
|
||||
prepare:
|
||||
$(HIDE)mkdir -p $(OUT)/musl
|
||||
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
|
||||
$(HIDE)cp -f $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/usr/lib/$(LLVM_TARGET)/a7_softfp_neon-vfpv4/libc.so $(OUT)/musl
|
||||
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/lib/$(LLVM_TARGET)/c++/a7_softfp_neon-vfpv4/libc++.so $(OUT)/musl
|
||||
$(HIDE)cp -f $$($(CC) --target=$(LLVM_TARGET) --sysroot=$(SYSROOT_PATH) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl
|
||||
$(HIDE)cp -f $$($(GPP) --target=$(LLVM_TARGET) --sysroot=$(SYSROOT_PATH) $(LITEOS_CXXFLAGS) -print-file-name=libc++.so) $(OUT)/musl
|
||||
else
|
||||
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/target/usr/lib/libc.so $(OUT)/musl
|
||||
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libstdc++.so.6 $(OUT)/musl
|
||||
@@ -179,7 +181,7 @@ endif
|
||||
|
||||
$(ROOTFSDIR): prepare $(APPS)
|
||||
$(HIDE)$(MAKE) clean -C apps
|
||||
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT)/bin $(OUT)/musl $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)
|
||||
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT) $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)
|
||||
ifneq ($(VERSION),)
|
||||
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)
|
||||
endif
|
||||
@@ -211,10 +213,11 @@ update_all_config:
|
||||
$(HIDE)shopt -s globstar && for f in tools/build/config/**/*.config ; \
|
||||
do \
|
||||
echo updating $$f; \
|
||||
test -f $$f && cp $$f .config && $(MENUCONFIG_CONF) -s --olddefconfig $(KCONFIG_FILE_PATH) && $(MENUCONFIG_CONF) --savedefconfig $$f $(KCONFIG_FILE_PATH); \
|
||||
test -f $$f && cp $$f .config && olddefconfig && savedefconfig --out $$f; \
|
||||
done
|
||||
|
||||
%.config:
|
||||
$(HIDE)test -f tools/build/config/$@ && cp tools/build/config/$@ .config && $(MENUCONFIG_MCONF) $(KCONFIG_FILE_PATH) && $(MENUCONFIG_CONF) --savedefconfig tools/build/config/$@ $(KCONFIG_FILE_PATH)
|
||||
update_config:
|
||||
$(HIDE)test -f "$(CONFIG)" && cp "$(CONFIG)" .config && menuconfig && savedefconfig --out "$(CONFIG)"
|
||||
|
||||
.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help update_all_config
|
||||
.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help update_all_config update_config
|
||||
.PHONY: prepare sysroot cleanrootfs $(ROOTFS) $(ROOTFSDIR) $(APPS) menuconfig $(LITEOS_LIBS_TARGET) $(__LIBS) $(OUT)
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
OpenHarmony LiteOS-A內核是基於Huawei LiteOS內核演進發展的新一代內核,Huawei LiteOS是面向IoT領域構建的輕量級物聯網操作系統。在IoT產業高速發展的潮流中,OpenHarmony LiteOS-A內核能夠帶給用戶小體積、低功耗、高性能的體驗以及統一開放的生態系統能力,新增了豐富的內核機制、更加全面的POSIX標準接口以及統一驅動框架**HDF**(OpenHarmony Driver Foundation)等,為設備廠商提供了更統一的接入方式,為OpenHarmony的應用開發者提供了更友好的開發體驗。圖1為OpenHarmony LiteOS-A內核架構圖:
|
||||
|
||||
**圖 1** OpenHarmony LiteOS-A內核架構圖<a name="fig27311582210"></a>
|
||||

|
||||
|
||||

|
||||
|
||||
## 目錄<a name="section161941989596"></a>
|
||||
|
||||
@@ -67,31 +68,31 @@ OpenHarmony LiteOS-A內核是基於Huawei LiteOS內核演進發展的新一代
|
||||
|
||||
## 使用說明<a name="section741617511812"></a>
|
||||
|
||||
OpenHarmony LiteOS-A內核支持Hi3518EV300([介紹](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3518%E5%BC%80%E5% 8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))、Hi3516DV300([介紹](https://gitee.com/openharmony/docs/blob/master/zh- cn/device-dev/quick-start/Hi3516%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))單板,開發者可基於兩種單板開發運行自己的應用程序。
|
||||
OpenHarmony LiteOS-A內核支持Hi3518EV300([介紹](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3518%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))、Hi3516DV300([介紹](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))單板,開發者可基於兩種單板開發運行自己的應用程序。
|
||||
|
||||
### 準備<a name="section1579912573329"></a>
|
||||
|
||||
開發者需要在Linux上搭建編譯環境:
|
||||
|
||||
- Hi3518EV300單板:參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E6%90%AD%E5%BB% BA%E7%8E%AF%E5%A2%83.md);
|
||||
- Hi3516DV300單板:參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E6%90%AD%E5%BB %BA%E7%8E%AF%E5%A2%83.md)。
|
||||
- Hi3518EV300單板:參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md);
|
||||
- Hi3516DV300單板:參考[環境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83.md)。
|
||||
|
||||
### 獲取源碼<a name="section11443189655"></a>
|
||||
|
||||
在Linux服務器上下載並解壓一套源代碼,獲取源碼([下載鏈結](https://repo.huaweicloud.com/harmonyos/os/1.0.1/code-1.0.1.tar.gz))。更多源碼獲取方式,參考[源碼獲取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/%E6%BA%90%E7%A0 %81%E8%8E%B7%E5%8F%96.md)。
|
||||
在Linux服務器上下載並解壓一套源代碼,獲取源碼([下載鏈結](https://repo.huaweicloud.com/harmonyos/os/1.0.1/code-1.0.1.tar.gz))。更多源碼獲取方式,參考[源碼獲取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96.md)。
|
||||
|
||||
### 編譯構建<a name="section2081013992812"></a>
|
||||
|
||||
開發者開發第一個應用程序可參考:
|
||||
|
||||
- [helloworld for Hi3518EV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3518%E7% AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F.md);
|
||||
- [helloworld for Hi3518EV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3518%E7%AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F.md);
|
||||
|
||||
- [helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3516%E7% AC%AC%E4%B8%80%E4%B8%AA%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%A4%BA%E4%BE% 8B.md)。
|
||||
- [helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3516%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%A4%BA%E4%BE%8B.md)。
|
||||
|
||||
## 相關倉<a name="section1371113476307"></a>
|
||||
|
||||
[內核子系統](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3 %BB%E7%BB%9F.md)
|
||||
[內核子系統](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
|
||||
|
||||
[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md)
|
||||
|
||||
**kernel\_liteos\_a**
|
||||
**kernel\_liteos\_a**
|
||||
|
||||
@@ -44,7 +44,7 @@ CFLAGS := -std=c99 -fno-exceptions $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
|
||||
CXXFLAGS := -std=c++11 -fexceptions -fpermissive -frtti $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
|
||||
LDCFLAGS := -lc
|
||||
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
|
||||
LLVM_SYSROOT := --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
|
||||
LLVM_SYSROOT := --sysroot=$(SYSROOT_PATH) $(ARCH_CFLAGS)
|
||||
LDCXXFLGS := -lc++ -lc++abi -lc
|
||||
else
|
||||
BASE_OPTS += -Wl,-z,relro,-z,now
|
||||
|
||||
@@ -34,15 +34,16 @@ LITEOSTOPDIR = $(MKSH_DIR)/../../
|
||||
include $(MKSH_DIR)/../config.mk
|
||||
|
||||
APPS_OUT := $(OUT)/bin
|
||||
ETC_OUT := $(OUT)/etc
|
||||
BUILD_DIR := $(MKSH_DIR)/build
|
||||
BUILD_LOG := $(MKSH_DIR)/build.log
|
||||
TARGET_OS := OpenHarmony
|
||||
|
||||
LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4
|
||||
LOCAL_CFLAGS += --target=arm-liteos --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
|
||||
LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2
|
||||
LOCAL_CFLAGS += --target=$(LLVM_TARGET) $(LLVM_SYSROOT)
|
||||
LOCAL_CFLAGS += -DMKSH_DISABLE_TTY_WARNING -DMKSH_SMALL=1 -DMKSH_ASSUME_UTF8=1 -DMKSH_SMALL_BUT_FAST=0 -DMKSH_S_NOVI=1 -DHAVE_CAN_FSTACKPROTECTORSTRONG=1
|
||||
LOCAL_CFLAGS += -DMKSH_LESS_CMDLINE_EDITING -DMKSH_LESS_BUILDINS -DMKSH_NO_INITCOMS -DADAPT_FOR_LITEOS_A
|
||||
LOCAL_LDFLAGS := -Wl,--gc-sections -flto -O2
|
||||
LOCAL_LDFLAGS := -Wl,--gc-sections -flto -O2 --target=$(LLVM_TARGET) $(LLVM_SYSROOT)
|
||||
|
||||
all:$(MKSH)
|
||||
|
||||
@@ -61,6 +62,8 @@ endif
|
||||
$(HIDE)$(STRIP) $(MKSH)
|
||||
$(HIDE)mkdir -p $(APPS_OUT)
|
||||
$(HIDE)$(CP) $(MKSH) $(APPS_OUT)
|
||||
$(HIDE)mkdir -p $(ETC_OUT)
|
||||
$(HIDE)$(CP) -rf $(BUILD_DIR)/.mkshrc $(ETC_OUT)/
|
||||
|
||||
clean:
|
||||
$(HIDE)$(RM) $(MKSH) $(BUILD_DIR) $(BUILD_LOG)
|
||||
|
||||
@@ -33,6 +33,8 @@ APP_SUBDIRS :=
|
||||
|
||||
ifeq ($(LOSCFG_SHELL), y)
|
||||
APP_SUBDIRS += shell
|
||||
APP_SUBDIRS += mksh
|
||||
APP_SUBDIRS += toybox
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_USER_INIT_DEBUG), y)
|
||||
@@ -42,9 +44,3 @@ endif
|
||||
ifeq ($(LOSCFG_NET_LWIP_SACK_TFTP), y)
|
||||
APP_SUBDIRS += tftp
|
||||
endif
|
||||
|
||||
#only enable for qemu now
|
||||
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
|
||||
APP_SUBDIRS += mksh
|
||||
APP_SUBDIRS += toybox
|
||||
endif
|
||||
|
||||
@@ -46,8 +46,8 @@ else
|
||||
$(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(TOYBOX)/. $(BUILD_DIR)
|
||||
$(HIDE)$(CP) -p $(LITEOSTHIRDPARTY)/$(TOYBOX)/porting/liteos_a/. $(BUILD_DIR)
|
||||
endif
|
||||
$(HIDE)CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong --target=arm-liteos \
|
||||
--sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/" CC="$(CC)" OUTNAME=$(OUTNAME) \
|
||||
$(HIDE)CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong --target=$(LLVM_TARGET) $(LLVM_SYSROOT)" CC="$(CC)" OUTNAME=$(OUTNAME) \
|
||||
LDFLAGS="--target=$(LLVM_TARGET) $(LLVM_SYSROOT)" \
|
||||
make -C $(BUILD_DIR) toybox -j> $(BUILD_LOG) 2>&1
|
||||
$(HIDE)$(CP) $(BUILD_DIR)/$(TOYBOX) .
|
||||
$(HIDE)$(STRIP) $(TOYBOX)
|
||||
|
||||
@@ -65,7 +65,7 @@ LITEOS_FPU_OPTS := -mfpu=$(LOSCFG_ARCH_FPU)
|
||||
LITEOS_GCCLIB := $(subst cortex-,,$(LOSCFG_ARCH_CPU))_softfp_$(LOSCFG_ARCH_FPU)
|
||||
endif
|
||||
|
||||
LITEOS_CORE_COPTS = $(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS)
|
||||
LITEOS_CORE_COPTS = $(or $(ARCH_CFLAGS),$(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS))
|
||||
LITEOS_INTERWORK += $(LITEOS_CORE_COPTS)
|
||||
LITEOS_NODEBUG += $(LITEOS_CORE_COPTS)
|
||||
LITEOS_ASOPTS += $(LITEOS_CPU_OPTS)
|
||||
|
||||
50
arch/arm/arm/include/arm_user_clear.h
Normal file
50
arch/arm/arm/include/arm_user_clear.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 _ARM_USER_CLEAR_H
|
||||
#define _ARM_USER_CLEAR_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
size_t _arm_clear_user(void *addr, size_t bytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _ARM_USER_CLEAR_H */
|
||||
@@ -145,7 +145,7 @@ STATIC INLINE VOID ArchCurrUserTaskSet(UINTPTR val)
|
||||
|
||||
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
return ARM_SYSREG_READ(MPIDR) & MPIDR_CPUID_MASK;
|
||||
#else
|
||||
return 0;
|
||||
|
||||
100
arch/arm/arm/src/clear_user.S
Normal file
100
arch/arm/arm/src/clear_user.S
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "asm.h"
|
||||
|
||||
.syntax unified
|
||||
.arm
|
||||
|
||||
// size_t _arm_clear_user(void *addr, size_t bytes)
|
||||
FUNCTION(_arm_clear_user)
|
||||
push {r0-r6, lr}
|
||||
cmp r1, #0
|
||||
beq .Lclear_user_return
|
||||
tst r0, #7
|
||||
beq .Lclear_user_aligned
|
||||
|
||||
.Lclear_user_byte:
|
||||
mov r2, #0
|
||||
0: strb r2, [r0], #1
|
||||
subs r1, r1, #1
|
||||
beq .Lclear_user_return
|
||||
tst r0, #7
|
||||
bne 0b
|
||||
|
||||
.Lclear_user_aligned:
|
||||
eor r3, r3
|
||||
eor r4, r4
|
||||
bics r2, r1, #15
|
||||
bne .Lclear_user_16bytes
|
||||
bics r2, r1, #7
|
||||
bne .Lclear_user_8bytes
|
||||
b .Lclear_user_remaining
|
||||
|
||||
.Lclear_user_16bytes:
|
||||
eor r5, r5
|
||||
eor r6, r6
|
||||
1: stmia r0!, {r3, r4, r5, r6}
|
||||
subs r2, r2, #16
|
||||
bne 1b
|
||||
ands r1, r1, #15
|
||||
beq .Lclear_user_return
|
||||
bics r2, r1, #7
|
||||
beq .Lclear_user_remaining
|
||||
|
||||
.Lclear_user_8bytes:
|
||||
2: stmia r0!, {r3, r4}
|
||||
ands r1, r1, #7
|
||||
beq .Lclear_user_return
|
||||
|
||||
.Lclear_user_remaining:
|
||||
mov r2, #0
|
||||
3: strb r2, [r0], #1
|
||||
subs r1, r1, #1
|
||||
bne 3b
|
||||
|
||||
.Lclear_user_return:
|
||||
pop {r0-r6, lr}
|
||||
mov r0, #0
|
||||
bx lr
|
||||
|
||||
.Lclear_user_err:
|
||||
pop {r0, r1}
|
||||
sub r0, r2, r0
|
||||
sub r0, r1, r0
|
||||
pop {r2-r6, lr}
|
||||
bx lr
|
||||
|
||||
.pushsection __exc_table, "a"
|
||||
.long 0b, .Lclear_user_err
|
||||
.long 1b, .Lclear_user_err
|
||||
.long 2b, .Lclear_user_err
|
||||
.long 3b, .Lclear_user_err
|
||||
.popsection
|
||||
@@ -51,7 +51,7 @@
|
||||
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
|
||||
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \
|
||||
g_firstPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS];
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
|
||||
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \
|
||||
g_tempPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS];
|
||||
@@ -218,7 +218,7 @@ STATIC UINT32 OsCvtSecCacheFlagsToMMUFlags(UINT32 flags)
|
||||
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
|
||||
case VM_MAP_REGION_FLAG_CACHED:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_SHAREABLE;
|
||||
#endif
|
||||
break;
|
||||
@@ -544,7 +544,7 @@ STATIC UINT32 OsCvtPte2CacheFlagsToMMUFlags(UINT32 flags)
|
||||
|
||||
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
|
||||
case VM_MAP_REGION_FLAG_CACHED:
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_SHAREABLE;
|
||||
#endif
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
|
||||
@@ -871,7 +871,7 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
|
||||
kSpace->archMmu.virtTtb = (PTE_T *)g_firstPageTable;
|
||||
kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb);
|
||||
status = LOS_ArchMmuUnmap(&kSpace->archMmu, virtAddr,
|
||||
(bssEndBoundary - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT);
|
||||
(bssEndBoundary - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT);
|
||||
if (status != ((bssEndBoundary - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
|
||||
VM_ERR("unmap failed, status: %d", status);
|
||||
return;
|
||||
@@ -882,8 +882,8 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
|
||||
flags |= VM_MAP_REGION_FLAG_UNCACHED;
|
||||
}
|
||||
status = LOS_ArchMmuMap(&kSpace->archMmu, virtAddr, SYS_MEM_BASE,
|
||||
(textStart - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
|
||||
flags);
|
||||
(textStart - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
|
||||
flags);
|
||||
if (status != ((textStart - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
|
||||
VM_ERR("mmap failed, status: %d", status);
|
||||
return;
|
||||
@@ -910,9 +910,9 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
|
||||
flags |= VM_MAP_REGION_FLAG_UNCACHED;
|
||||
}
|
||||
status = LOS_ArchMmuMap(&kSpace->archMmu, bssEndBoundary,
|
||||
SYS_MEM_BASE + bssEndBoundary - virtAddr,
|
||||
kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
|
||||
flags);
|
||||
SYS_MEM_BASE + bssEndBoundary - virtAddr,
|
||||
kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
|
||||
flags);
|
||||
if (status != (kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
|
||||
VM_ERR("mmap failed, status: %d", status);
|
||||
return;
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "los_excinfo_pri.h"
|
||||
#endif
|
||||
#include "los_sys_stack_pri.h"
|
||||
#include "los_stackinfo_pri.h"
|
||||
#ifdef LOSCFG_COREDUMP
|
||||
#include "los_coredump.h"
|
||||
#endif
|
||||
@@ -62,6 +61,9 @@
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#include "console.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_BLACKBOX
|
||||
#include "los_blackbox.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define INVALID_CPUID 0xFFFF
|
||||
@@ -75,7 +77,7 @@ VOID OsExcHook(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr);
|
||||
UINT32 g_curNestCount[LOSCFG_KERNEL_CORE_NUM] = { 0 };
|
||||
BOOL g_excFromUserMode[LOSCFG_KERNEL_CORE_NUM];
|
||||
STATIC EXC_PROC_FUNC g_excHook = (EXC_PROC_FUNC)OsExcHook;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
STATIC SPIN_LOCK_INIT(g_excSerializerSpin);
|
||||
STATIC UINT32 g_currHandleExcPID = OS_INVALID_VALUE;
|
||||
STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID;
|
||||
@@ -531,7 +533,7 @@ STATIC VOID OsExcRestore(VOID)
|
||||
g_excFromUserMode[currCpuID] = FALSE;
|
||||
g_intCount[currCpuID] = 0;
|
||||
g_curNestCount[currCpuID] = 0;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
OsPercpuGet()->excFlag = CPU_RUNNING;
|
||||
#endif
|
||||
OsPercpuGet()->taskLockCnt = 0;
|
||||
@@ -548,7 +550,7 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
|
||||
return;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LOS_SpinLock(&g_excSerializerSpin);
|
||||
if (g_nextExcWaitCpu != INVALID_CPUID) {
|
||||
g_currHandleExcCpuID = g_nextExcWaitCpu;
|
||||
@@ -563,12 +565,15 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
|
||||
#endif
|
||||
runProcess->processStatus &= ~OS_PROCESS_FLAG_EXIT;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
OsWakeConsoleSendTask();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_BLACKBOX
|
||||
BBoxNotifyError("USER_CRASH", MODULE_SYSTEM, "Crash in user", 0);
|
||||
#endif
|
||||
SCHEDULER_LOCK(intSave);
|
||||
#ifdef LOSCFG_SAVE_EXCINFO
|
||||
OsProcessExitCodeCoreDumpSet(runProcess);
|
||||
@@ -716,14 +721,14 @@ VOID BackTraceSub(UINTPTR regFP)
|
||||
while (IsValidFP(backFP, stackStart, stackEnd, &kvaddr) == TRUE) {
|
||||
tmpFP = backFP;
|
||||
#ifdef LOSCFG_COMPILER_CLANG_LLVM
|
||||
backFP = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
backFP = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
if (IsValidFP(tmpFP + POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
|
||||
PrintExcInfo("traceback backLR check failed, backLP: 0x%x\n", tmpFP + POINTER_SIZE);
|
||||
return;
|
||||
}
|
||||
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
#else
|
||||
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
backLR = *(UINTPTR *)(UINTPTR)kvaddr;
|
||||
if (IsValidFP(tmpFP - POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
|
||||
PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE);
|
||||
return;
|
||||
@@ -909,7 +914,7 @@ VOID OsDataAbortExcHandleEntry(ExcContext *excBufAddr)
|
||||
#endif /* __LINUX_ARM_ARCH__ */
|
||||
#endif /* LOSCFG_GDB */
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#define EXC_WAIT_INTER 50U
|
||||
#define EXC_WAIT_TIME 2000U
|
||||
|
||||
@@ -1007,7 +1012,7 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
|
||||
OsWaitOtherCoresHandleExcEnd(currCpuID);
|
||||
} else {
|
||||
if (g_excFromUserMode[g_currHandleExcCpuID] == TRUE) {
|
||||
if ((g_currHandleExcCpuID < LOSCFG_KERNEL_CORE_NUM) && (g_excFromUserMode[g_currHandleExcCpuID] == TRUE)) {
|
||||
g_currHandleExcCpuID = currCpuID;
|
||||
LOS_SpinUnlock(&g_excSerializerSpin);
|
||||
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
|
||||
@@ -1027,7 +1032,7 @@ STATIC VOID OsCheckAllCpuStatus(VOID)
|
||||
|
||||
STATIC VOID OsCheckCpuStatus(VOID)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
OsCheckAllCpuStatus();
|
||||
#else
|
||||
g_currHandleExcCpuID = ArchCurrCpuid();
|
||||
@@ -1048,7 +1053,7 @@ LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr)
|
||||
|
||||
OsCheckCpuStatus();
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
/* Wait for the end of the Console task to avoid multicore printing code */
|
||||
OsWaitConsoleSendTaskPend(OsCurrTaskGet()->taskID);
|
||||
@@ -1058,6 +1063,11 @@ LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr)
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far)
|
||||
{
|
||||
#ifdef LOSCFG_BLACKBOX
|
||||
#ifdef LOSCFG_SAVE_EXCINFO
|
||||
SetExcInfoIndex(0);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
/* You are not allowed to add any other print information before this exception information */
|
||||
if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
|
||||
@@ -1113,7 +1123,7 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
|
||||
|
||||
OsPrintExcHead(far);
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
OsAllCpuStatusOutput();
|
||||
#endif
|
||||
|
||||
@@ -1125,7 +1135,9 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
|
||||
if (g_curNestCount[ArchCurrCpuid()] == 1) {
|
||||
#ifdef LOSCFG_SAVE_EXCINFO
|
||||
if (func != NULL) {
|
||||
#ifndef LOSCFG_BLACKBOX
|
||||
SetExcInfoIndex(0);
|
||||
#endif
|
||||
OsSysStateSave(&intCount, &lockCount);
|
||||
OsRecordExcInfoTime();
|
||||
OsSysStateRestore(intCount, lockCount);
|
||||
@@ -1154,6 +1166,9 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_BLACKBOX
|
||||
BBoxNotifyError(EVENT_PANIC, MODULE_SYSTEM, "Crash in kernel", 1);
|
||||
#endif
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -1168,7 +1183,7 @@ __attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...)
|
||||
}
|
||||
|
||||
/* stack protector */
|
||||
UINT32 __stack_chk_guard = 0xd00a0dff;
|
||||
USED UINT32 __stack_chk_guard = 0xd00a0dff;
|
||||
|
||||
VOID __stack_chk_fail(VOID)
|
||||
{
|
||||
@@ -1200,7 +1215,11 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCou
|
||||
framePtr = Get_Fp();
|
||||
while ((framePtr > stackStart) && (framePtr < stackEnd) && IS_ALIGNED(framePtr, sizeof(CHAR *))) {
|
||||
tmpFramePtr = framePtr;
|
||||
#ifdef LOSCFG_COMPILER_CLANG_LLVM
|
||||
linkReg = *(UINTPTR *)(tmpFramePtr + sizeof(UINTPTR));
|
||||
#else
|
||||
linkReg = *(UINTPTR *)framePtr;
|
||||
#endif
|
||||
if (index >= jumpCount) {
|
||||
LR[count++] = linkReg;
|
||||
if (count == recordCount) {
|
||||
@@ -1208,7 +1227,11 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCou
|
||||
}
|
||||
}
|
||||
index++;
|
||||
#ifdef LOSCFG_COMPILER_CLANG_LLVM
|
||||
framePtr = *(UINTPTR *)framePtr;
|
||||
#else
|
||||
framePtr = *(UINTPTR *)(tmpFramePtr - sizeof(UINTPTR));
|
||||
#endif
|
||||
}
|
||||
|
||||
/* if linkReg is not enough,clean up the last of the effective LR as the end. */
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "user_copy.h"
|
||||
#include "arm_user_copy.h"
|
||||
#include "arm_user_clear.h"
|
||||
#include "securec.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_vm_map.h"
|
||||
@@ -96,15 +97,9 @@ INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len)
|
||||
if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, len)) {
|
||||
(VOID)memset_s(buf, len, 0, len);
|
||||
} else {
|
||||
unsigned char *tmp = (unsigned char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, len);
|
||||
if (tmp == NULL) {
|
||||
return -ENOMEM;
|
||||
if (_arm_clear_user(buf, len)) {
|
||||
return -EFAULT;
|
||||
}
|
||||
(VOID)memset_s(tmp, len, 0, len);
|
||||
if (_arm_user_copy(buf, tmp, len) != 0) {
|
||||
ret = -EFAULT;
|
||||
}
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, tmp);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ STATIC_ASSERT(OS_USER_HWI_MAX <= 1020, "hwi max is too large!");
|
||||
|
||||
STATIC UINT32 g_curIrqNum = 0;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/*
|
||||
* filter description
|
||||
* 0b00: forward to the cpu interfaces specified in cpu_mask
|
||||
@@ -144,7 +144,7 @@ VOID HalIrqInit(VOID)
|
||||
/* enable gic distributor control */
|
||||
GIC_REG_32(GICD_CTLR) = 1;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/* register inter-processor interrupt */
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
|
||||
(VOID)LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);
|
||||
|
||||
@@ -48,7 +48,7 @@ STATIC INLINE UINT64 MpidrToAffinity(UINT64 mpidr)
|
||||
(MPIDR_AFF_LEVEL(mpidr, 0)));
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
|
||||
STATIC UINT32 NextCpu(UINT32 cpu, UINT32 cpuMask)
|
||||
{
|
||||
@@ -399,7 +399,7 @@ VOID HalIrqInit(VOID)
|
||||
|
||||
HalIrqInitPercpu();
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/* register inter-processor interrupt */
|
||||
LOS_HwiCreate(LOS_MP_IPI_WAKEUP, 0xa0, 0, OsMpWakeHandler, 0);
|
||||
LOS_HwiCreate(LOS_MP_IPI_SCHEDULE, 0xa0, 0, OsMpScheduleHandler, 0);
|
||||
|
||||
@@ -49,7 +49,7 @@ extern VOID HalIrqClear(UINT32 vector);
|
||||
extern CHAR *HalIrqVersion(VOID);
|
||||
extern UINT32 HalCurIrqGet(VOID);
|
||||
extern UINT32 HalIrqSetPrio(UINT32 vector, UINT8 priority);
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
extern VOID HalIrqSendIpi(UINT32 target, UINT32 ipi);
|
||||
extern VOID HalIrqSetAffinity(UINT32 vector, UINT32 cpuMask);
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,7 @@ config DRIVERS_USB_HOST_DRIVER
|
||||
choice
|
||||
depends on DRIVERS_USB_HOST_DRIVER
|
||||
prompt "USB HCD"
|
||||
default y
|
||||
default DRIVERS_USB_HOST_EHCI
|
||||
help
|
||||
Enable EHCI for USB 2.0.
|
||||
Enable XHCI for USB 3.0
|
||||
|
||||
99
build.sh
99
build.sh
@@ -30,44 +30,65 @@
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
set -e
|
||||
|
||||
echo "sh param:$1,$2,$3,$4,$5,$6,$7"
|
||||
destination=".config"
|
||||
config_file=""
|
||||
tee=""
|
||||
outdir="../..$3/test_info/gen/kernel/test"
|
||||
if [ "$5" = "tee" ]; then
|
||||
tee="_tee"
|
||||
fi
|
||||
product_name="$(basename $7)"
|
||||
source="tools/build/config/${product_name}_release.config"
|
||||
if [ "$2" = "clang" ]; then
|
||||
if [ "$4" = "debug" ]; then
|
||||
config_file="${product_name}_$2$tee.config"
|
||||
source="tools/build/config/debug/$config_file"
|
||||
else
|
||||
config_file="${product_name}_$2_release$tee.config"
|
||||
source="tools/build/config/$config_file"
|
||||
fi
|
||||
elif [ "$2" = "gcc" ]; then
|
||||
if [ "$4" = "debug" ]; then
|
||||
config_file="${product_name}_debug_shell$tee.config"
|
||||
source="tools/build/config/$config_file"
|
||||
else
|
||||
config_file="${product_name}_release$tee.config"
|
||||
source="tools/build/config/$config_file"
|
||||
fi
|
||||
fi
|
||||
if [ -d "./out" ]; then
|
||||
rm -rf ./out
|
||||
fi
|
||||
if [ -f "$destination" ]; then
|
||||
rm -rf $destination
|
||||
fi
|
||||
if [ ! -f "$source" ]; then
|
||||
source="$7/config/sys/$config_file"
|
||||
fi
|
||||
cp $source $destination
|
||||
board_name=${1}
|
||||
ohos_build_compiler=${2}
|
||||
root_build_dir=${3}
|
||||
ohos_build_type=${4}
|
||||
tee_enable=${5}
|
||||
device_company=${6}
|
||||
product_path=${7}
|
||||
outdir=${8}
|
||||
ohos_version=${9}
|
||||
sysroot_path=${10}
|
||||
arch_cflags=${11}
|
||||
device_path=${12}
|
||||
|
||||
mkdir -p $outdir
|
||||
cp kernel_test.sources $outdir
|
||||
echo "${board_name}" "${device_company}"
|
||||
echo "sh param:" "$@"
|
||||
|
||||
function main() {
|
||||
destination=".config"
|
||||
tee=""
|
||||
if [ "${tee_enable}" = "true" ]; then
|
||||
tee="_tee"
|
||||
fi
|
||||
|
||||
config_file="${product_path}/config/${ohos_build_type}${tee}.config"
|
||||
if [ -f "${config_file}" ]; then
|
||||
cp "${config_file}" "${destination}"
|
||||
return
|
||||
fi
|
||||
|
||||
product_name=$(basename "${product_path}")
|
||||
config_file="${product_name}_release.config"
|
||||
if [ "${ohos_build_compiler}" = "clang" ]; then
|
||||
if [ "${ohos_build_type}" = "debug" ]; then
|
||||
config_file="debug/${product_name}_${ohos_build_compiler}${tee}.config"
|
||||
else
|
||||
config_file="${product_name}_${ohos_build_compiler}_release${tee}.config"
|
||||
fi
|
||||
elif [ "${ohos_build_compiler}" = "gcc" ]; then
|
||||
if [ "${ohos_build_type}" = "debug" ]; then
|
||||
config_file="${product_name}_debug_shell${tee}.config"
|
||||
else
|
||||
config_file="${product_name}_release${tee}.config"
|
||||
fi
|
||||
fi
|
||||
cp "tools/build/config/${config_file}" "${destination}"
|
||||
}
|
||||
|
||||
if [ "x" != "x${sysroot_path}" ]; then
|
||||
export SYSROOT_PATH=${sysroot_path}
|
||||
fi
|
||||
|
||||
if [ "x" != "x${arch_cflags}" ]; then
|
||||
export ARCH_CFLAGS="${arch_cflags}"
|
||||
fi
|
||||
|
||||
export OUTDIR="${outdir}"
|
||||
export PRODUCT_PATH="${product_path}"
|
||||
export DEVICE_PATH="${device_path}"
|
||||
|
||||
main && \
|
||||
make clean && \
|
||||
make -j rootfs VERSION="${ohos_version}"
|
||||
|
||||
@@ -204,7 +204,7 @@ STATIC UINT32 InitPthreadData(pthread_t threadID, pthread_attr_t *userAttr,
|
||||
PRINT_ERR("%s: %d, err: %d\n", __FUNCTION__, __LINE__, err);
|
||||
return LOS_NOK;
|
||||
}
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
if (userAttr->cpuset.__bits[0] > 0) {
|
||||
taskCB->cpuAffiMask = (UINT16)userAttr->cpuset.__bits[0];
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ int pthread_attr_init(pthread_attr_t *attr)
|
||||
attr->stacksize_set = 1;
|
||||
attr->stacksize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
attr->cpuset.__bits[0] = 0;
|
||||
#endif
|
||||
|
||||
@@ -239,7 +239,7 @@ int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stackSize)
|
||||
*/
|
||||
int pthread_attr_setaffinity_np(pthread_attr_t* attr, size_t cpusetsize, const cpu_set_t* cpuset)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
if (attr == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
@@ -264,7 +264,7 @@ int pthread_attr_setaffinity_np(pthread_attr_t* attr, size_t cpusetsize, const c
|
||||
*/
|
||||
int pthread_attr_getaffinity_np(const pthread_attr_t* attr, size_t cpusetsize, cpu_set_t* cpuset)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
if ((attr == NULL) || (cpuset == NULL) || (cpusetsize != sizeof(cpu_set_t))) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ int sched_get_priority_max(int policy)
|
||||
*/
|
||||
int sched_setaffinity(pid_t pid, size_t set_size, const cpu_set_t* set)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT32 taskID = (UINT32)pid;
|
||||
UINT32 ret;
|
||||
|
||||
@@ -93,7 +93,7 @@ int sched_setaffinity(pid_t pid, size_t set_size, const cpu_set_t* set)
|
||||
*/
|
||||
int sched_getaffinity(pid_t pid, size_t set_size, cpu_set_t* set)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT32 taskID = (UINT32)pid;
|
||||
UINT16 cpuAffiMask;
|
||||
|
||||
|
||||
@@ -456,7 +456,7 @@ static int PthreadGetCputime(clockid_t clockID, struct timespec *ats)
|
||||
{
|
||||
uint64_t runtime;
|
||||
UINT32 intSave;
|
||||
UINT32 tid = ((UINT32) ~((clockID) >> CPUCLOCK_ID_OFFSET));
|
||||
UINT32 tid = ((UINT32) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
|
||||
|
||||
if (OS_TID_CHECK_INVALID(tid)) {
|
||||
return -EINVAL;
|
||||
@@ -482,7 +482,7 @@ static int ProcessGetCputime(clockid_t clockID, struct timespec *ats)
|
||||
{
|
||||
UINT64 runtime;
|
||||
UINT32 intSave;
|
||||
const pid_t pid = ((pid_t) ~((clockID) >> CPUCLOCK_ID_OFFSET));
|
||||
const pid_t pid = ((pid_t) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
|
||||
LosProcessCB *spcb = NULL;
|
||||
|
||||
if (OsProcessIDUserCheckInvalid(pid) || pid < 0) {
|
||||
@@ -524,7 +524,7 @@ static int GetCputime(clockid_t clockID, struct timespec *tp)
|
||||
static int CheckClock(const clockid_t clockID)
|
||||
{
|
||||
int error = 0;
|
||||
const pid_t pid = ((pid_t) ~((clockID) >> CPUCLOCK_ID_OFFSET));
|
||||
const pid_t pid = ((pid_t) ~((UINT32)(clockID) >> CPUCLOCK_ID_OFFSET));
|
||||
|
||||
if (!((UINT32)clockID & CPUCLOCK_PERTHREAD_MASK)) {
|
||||
LosProcessCB *spcb = NULL;
|
||||
|
||||
@@ -725,6 +725,9 @@ INT32 los_alloc_diskid_byname(const CHAR *diskName);
|
||||
*/
|
||||
INT32 los_get_diskid_byname(const CHAR *diskName);
|
||||
|
||||
|
||||
los_disk *los_get_mmcdisk_bytype(UINT8 type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -187,6 +187,22 @@ INT32 los_get_diskid_byname(const CHAR *diskName)
|
||||
return diskID;
|
||||
}
|
||||
|
||||
los_disk *los_get_mmcdisk_bytype(UINT8 type)
|
||||
{
|
||||
const CHAR *mmcDevHead = "/dev/mmcblk";
|
||||
|
||||
for (INT32 diskId = 0; diskId < SYS_MAX_DISK; diskId++) {
|
||||
los_disk *disk = get_disk(diskId);
|
||||
if (disk == NULL) {
|
||||
continue;
|
||||
} else if ((disk->type == type) && (strncmp(disk->disk_name, mmcDevHead, strlen(mmcDevHead)) == 0)) {
|
||||
return disk;
|
||||
}
|
||||
}
|
||||
PRINT_ERR("Cannot find the mmc disk!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID OsSetUsbStatus(UINT32 diskID)
|
||||
{
|
||||
if (diskID < SYS_MAX_DISK) {
|
||||
@@ -328,11 +344,7 @@ static INT32 DiskAddPart(los_disk *disk, UINT64 sectorStart, UINT64 sectorCount,
|
||||
|
||||
VnodeHold();
|
||||
VnodeLookup(devName, &partDev, 0);
|
||||
if (ret < 0) {
|
||||
VnodeDrop();
|
||||
PRINT_ERR("DiskAddPart : find %s fail!\n", devName);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
part = DiskPartAllocate(partDev, sectorStart, sectorCount);
|
||||
VnodeDrop();
|
||||
if (part == NULL) {
|
||||
|
||||
@@ -65,7 +65,7 @@ static int RandomHwClose(struct file *filep)
|
||||
|
||||
static int RandomHwIoctl(struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
int ret;
|
||||
int ret = -1;
|
||||
|
||||
switch (cmd) {
|
||||
default:
|
||||
@@ -77,7 +77,7 @@ static int RandomHwIoctl(struct file *filep, int cmd, unsigned long arg)
|
||||
|
||||
static ssize_t RandomHwRead(struct file *filep, char *buffer, size_t buflen)
|
||||
{
|
||||
int ret;
|
||||
int ret = -1;
|
||||
|
||||
if (g_randomOp.read != NULL) {
|
||||
ret = g_randomOp.read(buffer, buflen);
|
||||
|
||||
@@ -39,7 +39,7 @@ LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/../../device/hisilicon/drivers/include/mtd/common/include
|
||||
|
||||
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
|
||||
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/arm_virt/config/cfiflash
|
||||
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "los_tables.h"
|
||||
#include "user_copy.h"
|
||||
#include "los_vm_filemap.h"
|
||||
#include "los_hash.h"
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
@@ -53,7 +54,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "los_hash.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
struct VnodeOps fatfs_vops; /* forward define */
|
||||
@@ -190,7 +191,7 @@ static int fatfs_sync(unsigned long mountflags, FATFS *fs)
|
||||
{
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
los_part *part = NULL;
|
||||
if (mountflags != MS_NOSYNC) {
|
||||
if (!(mountflags & (MS_NOSYNC | MS_RDONLY))) {
|
||||
part = get_part((INT)fs->pdrv);
|
||||
if (part == NULL) {
|
||||
return -ENODEV;
|
||||
@@ -238,7 +239,8 @@ static mode_t fatfs_get_mode(BYTE attribute, mode_t fs_mode)
|
||||
return fs_mode;
|
||||
}
|
||||
|
||||
static enum VnodeType fatfstype_2_vnodetype(BYTE type) {
|
||||
static enum VnodeType fatfstype_2_vnodetype(BYTE type)
|
||||
{
|
||||
switch (type) {
|
||||
case AM_ARC:
|
||||
return VNODE_TYPE_REG;
|
||||
@@ -251,11 +253,13 @@ static enum VnodeType fatfstype_2_vnodetype(BYTE type) {
|
||||
}
|
||||
}
|
||||
|
||||
static FRESULT init_cluster(DIR *dp_new, FATFS *fs, int type, const char *target, DWORD *clust)
|
||||
#define DIR_SIZE 32
|
||||
static FRESULT init_cluster(DIR_FILE *pdfp, DIR *dp_new, FATFS *fs, int type, const char *target, DWORD *clust)
|
||||
{
|
||||
FRESULT result;
|
||||
BYTE *dir = NULL;
|
||||
QWORD sect;
|
||||
DWORD pclust;
|
||||
UINT n;
|
||||
|
||||
/* Allocate a new cluster */
|
||||
@@ -284,24 +288,52 @@ static FRESULT init_cluster(DIR *dp_new, FATFS *fs, int type, const char *target
|
||||
mem_set(dir, 0, SS(fs));
|
||||
if (type == AM_LNK && target) {
|
||||
/* Write target to symlink */
|
||||
strcpy_s((char *)dir, SS(fs), target);
|
||||
}
|
||||
for (n = fs->csize; n > 0; n--) {
|
||||
#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION
|
||||
fs->winsect = sect++;
|
||||
fs->wflag = 1;
|
||||
#else
|
||||
PARENTFS(fs)->winsect = sect++;
|
||||
PARENTFS(fs)->wflag = 1;
|
||||
#endif
|
||||
result = sync_window(fs);
|
||||
if (result != FR_OK) {
|
||||
remove_chain(&(dp_new->obj), *clust, 0);
|
||||
return result;
|
||||
(void)strcpy_s((char *)dir, SS(fs), target);
|
||||
} else {
|
||||
/* Write the dir cluster */
|
||||
mem_set(dir, 0, SS(fs));
|
||||
mem_set(dir + DIR_Name, ' ', 11); /* Create "." entry */
|
||||
dir[DIR_Name] = '.';
|
||||
dir[DIR_Attr] = AM_DIR;
|
||||
st_clust(fs, dir, *clust);
|
||||
mem_cpy(dir + DIR_SIZE, dir, DIR_SIZE); /* Create ".." entry */
|
||||
dir[DIR_SIZE + 1] = '.'; /* Add extra "." */
|
||||
pclust = pdfp->fno.sclst;
|
||||
if (fs->fs_type == FS_FAT32 && pclust == fs->dirbase) {
|
||||
pclust = 0;
|
||||
}
|
||||
if (type == AM_LNK) {
|
||||
/* No need to clean the rest sectors of the cluster for symlink */
|
||||
break;
|
||||
st_clust(fs, dir + DIR_SIZE, pclust);
|
||||
}
|
||||
|
||||
#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION
|
||||
fs->winsect = sect++;
|
||||
fs->wflag = 1;
|
||||
#else
|
||||
PARENTFS(fs)->winsect = sect++;
|
||||
PARENTFS(fs)->wflag = 1;
|
||||
#endif
|
||||
result = sync_window(fs);
|
||||
if (result != FR_OK) {
|
||||
remove_chain(&(dp_new->obj), *clust, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Rest of directory cluster should set to be zero */
|
||||
if (type == AM_DIR) {
|
||||
mem_set(dir, 0, SS(fs));
|
||||
for (n = fs->csize - 1; n > 0; n--) {
|
||||
#ifndef LOSCFG_FS_FAT_VIRTUAL_PARTITION
|
||||
fs->winsect = sect++;
|
||||
fs->wflag = 1;
|
||||
#else
|
||||
PARENTFS(fs)->winsect = sect++;
|
||||
PARENTFS(fs)->wflag = 1;
|
||||
#endif
|
||||
result = sync_window(fs);
|
||||
if (result != FR_OK) {
|
||||
remove_chain(&(dp_new->obj), *clust, 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,7 +398,7 @@ static int fatfs_create_obj(struct Vnode *parent, const char *name, int mode, st
|
||||
}
|
||||
|
||||
if (type == AM_DIR || type == AM_LNK) {
|
||||
result = init_cluster(dp_new, fs, type, target, &clust);
|
||||
result = init_cluster(dfp, dp_new, fs, type, target, &clust);
|
||||
if (result != FR_OK) {
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
@@ -576,7 +608,7 @@ int fatfs_open(struct file *filep)
|
||||
ret = lock_fs(fs);
|
||||
if (ret == FALSE) {
|
||||
ret = EBUSY;
|
||||
goto ERROR_EXIT;
|
||||
goto ERROR_FREE;
|
||||
}
|
||||
|
||||
fp->dir_sect = dp->sect;
|
||||
@@ -595,7 +627,7 @@ int fatfs_open(struct file *filep)
|
||||
fp->buf = (BYTE*) ff_memalloc(SS(fs));
|
||||
if (fp->buf == NULL) {
|
||||
ret = ENOMEM;
|
||||
goto ERROR_FREE;
|
||||
goto ERROR_UNLOCK;
|
||||
}
|
||||
LOS_ListAdd(&finfo->fp_list, &fp->fp_entry);
|
||||
unlock_fs(fs, FR_OK);
|
||||
@@ -603,8 +635,9 @@ int fatfs_open(struct file *filep)
|
||||
filep->f_priv = fp;
|
||||
return fatfs_sync(vp->originMount->mountFlags, fs);
|
||||
|
||||
ERROR_FREE:
|
||||
ERROR_UNLOCK:
|
||||
unlock_fs(fs, FR_OK);
|
||||
ERROR_FREE:
|
||||
free(fp);
|
||||
ERROR_EXIT:
|
||||
return -ret;
|
||||
@@ -704,6 +737,7 @@ off64_t fatfs_lseek64(struct file *filep, off64_t offset, int whence)
|
||||
struct Vnode *vp = filep->f_vnode;
|
||||
DIR_FILE *dfp = (DIR_FILE *)vp->data;
|
||||
FILINFO *finfo = &(dfp->fno);
|
||||
struct Mount *mount = vp->originMount;
|
||||
FSIZE_t fpos;
|
||||
FRESULT result;
|
||||
int ret;
|
||||
@@ -741,6 +775,17 @@ off64_t fatfs_lseek64(struct file *filep, off64_t offset, int whence)
|
||||
if (ret == FALSE) {
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
if (fpos > finfo->fsize) {
|
||||
if ((filep->f_oflags & O_ACCMODE) == O_RDONLY) {
|
||||
result = FR_DENIED;
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
if (mount->mountFlags & MS_RDONLY) {
|
||||
result = FR_WRITE_PROTECTED;
|
||||
goto ERROR_EXIT;
|
||||
}
|
||||
}
|
||||
fp->obj.sclust = finfo->sclst;
|
||||
fp->obj.objsize = finfo->fsize;
|
||||
|
||||
@@ -872,11 +917,13 @@ int fatfs_fallocate64(struct file *filep, int mode, off64_t offset, off64_t len)
|
||||
return -EBUSY;
|
||||
}
|
||||
result = f_expand(fp, (FSIZE_t)offset, (FSIZE_t)len, 1);
|
||||
if (result == FR_OK && finfo->sclst == 0) {
|
||||
finfo->sclst = fp->obj.sclust;
|
||||
if (result == FR_OK) {
|
||||
if (finfo->sclst == 0) {
|
||||
finfo->sclst = fp->obj.sclust;
|
||||
}
|
||||
result = f_sync(fp);
|
||||
}
|
||||
result = f_sync(fp);
|
||||
unlock_fs(fs, FR_OK);
|
||||
unlock_fs(fs, result);
|
||||
|
||||
return -fatfs_2_vfs(result);
|
||||
}
|
||||
@@ -1745,6 +1792,45 @@ static int fatfs_set_part_info(los_part *part)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FRESULT fatfs_setlabel(los_part *part)
|
||||
{
|
||||
QWORD start_sector = 0;
|
||||
BYTE fmt = 0;
|
||||
FATFS fs;
|
||||
FRESULT result;
|
||||
|
||||
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
|
||||
fs.vir_flag = FS_PARENT;
|
||||
fs.parent_fs = &fs;
|
||||
fs.vir_amount = DISK_ERROR;
|
||||
fs.vir_avail = FS_VIRDISABLE;
|
||||
#endif
|
||||
if (disk_ioctl(fs.pdrv, GET_SECTOR_SIZE, &(fs.ssize)) != RES_OK) {
|
||||
return -EIO;
|
||||
}
|
||||
fs.win = (BYTE *)ff_memalloc(fs.ssize);
|
||||
if (fs.win == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
result = find_fat_partition(&fs, part, &fmt, &start_sector);
|
||||
if (result != FR_OK) {
|
||||
free(fs.win);
|
||||
return -fatfs_2_vfs(result);
|
||||
}
|
||||
|
||||
result = init_fatobj(&fs, fmt, start_sector);
|
||||
if (result != FR_OK) {
|
||||
free(fs.win);
|
||||
return -fatfs_2_vfs(result);
|
||||
}
|
||||
|
||||
result = set_volumn_label(&fs, FatLabel);
|
||||
free(fs.win);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int fatfs_mkfs (struct Vnode *device, int sectors, int option)
|
||||
{
|
||||
BYTE *work_buff = NULL;
|
||||
@@ -1780,19 +1866,22 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
|
||||
return -fatfs_2_vfs(result);
|
||||
}
|
||||
|
||||
result = fatfs_setlabel(part);
|
||||
if (result == FR_OK) {
|
||||
#ifdef LOSCFG_FS_FAT_CACHE
|
||||
ret = OsSdSync(part->disk_id);
|
||||
if (ret != 0) {
|
||||
return -EIO;
|
||||
}
|
||||
ret = OsSdSync(part->disk_id);
|
||||
if (ret != 0) {
|
||||
return -EIO;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ret = fatfs_set_part_info(part);
|
||||
if (ret != 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -fatfs_2_vfs(result);
|
||||
}
|
||||
|
||||
int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp)
|
||||
|
||||
@@ -113,6 +113,8 @@ extern "C" {
|
||||
#define FMT_ANY 0x07
|
||||
#define FMT_ERASE 0x08
|
||||
|
||||
extern char FatLabel[LABEL_LEN];
|
||||
|
||||
int fatfs_2_vfs(int result);
|
||||
int fatfs_lookup(struct Vnode *parent, const char *name, int len, struct Vnode **vpp);
|
||||
int fatfs_create(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp);
|
||||
|
||||
@@ -473,7 +473,7 @@ off64_t file_seek64(struct file *filep, off64_t offset, int whence);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int files_allocate(struct Vnode *vnode, int oflags, off_t pos,void *priv, int minfd);
|
||||
int files_allocate(struct Vnode *vnode, int oflags, off_t pos, void *priv, int minfd);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: files_close
|
||||
|
||||
@@ -53,6 +53,7 @@ struct Mount {
|
||||
uint32_t hashseed; /* Random seed for vfshash */
|
||||
unsigned long mountFlags; /* Flags for mount */
|
||||
char pathName[PATH_MAX]; /* path name of mount point */
|
||||
char devName[PATH_MAX]; /* path name of dev point */
|
||||
};
|
||||
|
||||
struct MountOps {
|
||||
@@ -61,7 +62,8 @@ struct MountOps {
|
||||
int (*Statfs)(struct Mount *mount, struct statfs *sbp);
|
||||
};
|
||||
|
||||
typedef int (*foreach_mountpoint_t)(const char *mountpoint,
|
||||
typedef int (*foreach_mountpoint_t)(const char *devpoint,
|
||||
const char *mountpoint,
|
||||
struct statfs *statbuf,
|
||||
void *arg);
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ int VfsJffs2Bind(struct Mount *mnt, struct Vnode *blkDriver, const void *data)
|
||||
|
||||
partNo = p->patitionnum;
|
||||
|
||||
ret = jffs2_mount(partNo, &rootNode);
|
||||
ret = jffs2_mount(partNo, &rootNode, mnt->mountFlags);
|
||||
if (ret != 0) {
|
||||
LOS_MuxUnlock(&g_jffs2FsLock);
|
||||
return ret;
|
||||
@@ -323,7 +323,7 @@ ssize_t VfsJffs2Write(struct file *filep, const char *buffer, size_t bufLen)
|
||||
c = JFFS2_SB_INFO(node->i_sb);
|
||||
pos = filep->f_pos;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
struct super_block *sb = node->i_sb;
|
||||
UINT16 gcCpuMask = LOS_TaskCpuAffiGet(sb->s_gc_thread);
|
||||
UINT32 curTaskId = LOS_CurTaskIDGet();
|
||||
@@ -717,14 +717,17 @@ ssize_t VfsJffs2Readlink(struct Vnode *vnode, char *buffer, size_t bufLen)
|
||||
int VfsJffs2Unlink(struct Vnode *parentVnode, struct Vnode *targetVnode, const char *path)
|
||||
{
|
||||
int ret;
|
||||
struct jffs2_inode *parentInode = (struct jffs2_inode *)parentVnode->data;
|
||||
struct jffs2_inode *targetInode = (struct jffs2_inode *)targetVnode->data;
|
||||
struct jffs2_inode *parentInode = NULL;
|
||||
struct jffs2_inode *targetInode = NULL;
|
||||
|
||||
if (!parentVnode || !targetVnode) {
|
||||
PRINTK("%s-%d parentVnode=%x, targetVnode=%x\n", __FUNCTION__, __LINE__, parentVnode, targetVnode);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
parentInode = (struct jffs2_inode *)parentVnode->data;
|
||||
targetInode = (struct jffs2_inode *)targetVnode->data;
|
||||
|
||||
LOS_MuxLock(&g_jffs2FsLock, (uint32_t)JFFS2_WAITING_FOREVER);
|
||||
|
||||
ret = jffs2_unlink(parentInode, targetInode, (const unsigned char *)path);
|
||||
|
||||
@@ -45,6 +45,8 @@ extern "C" {
|
||||
extern spinlock_t procfsLock;
|
||||
extern bool procfsInit;
|
||||
|
||||
void ProcPmInit(void);
|
||||
|
||||
void ProcVmmInit(void);
|
||||
|
||||
void ProcProcessInit(void);
|
||||
@@ -63,6 +65,10 @@ extern void ProcMountsInit(void);
|
||||
|
||||
extern void ProcUptimeInit(void);
|
||||
|
||||
extern void ProcFsCacheInit(void);
|
||||
|
||||
extern void ProcFdInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -89,6 +89,8 @@ struct ProcFileOperations {
|
||||
};
|
||||
|
||||
struct ProcDirEntry {
|
||||
uint uid;
|
||||
uint gid;
|
||||
mode_t mode;
|
||||
int flags;
|
||||
const struct ProcFileOperations *procFileOps;
|
||||
|
||||
142
fs/proc/os_adapt/fd_proc.c
Normal file
142
fs/proc/os_adapt/fd_proc.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "proc_fs.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "fs/file.h"
|
||||
#include "vfs_config.h"
|
||||
#include "internal.h"
|
||||
|
||||
#include "fs/fd_table.h"
|
||||
#include "los_process.h"
|
||||
#include "capability_api.h"
|
||||
#include "capability_type.h"
|
||||
|
||||
|
||||
/*
|
||||
* Template: Pid Fd [SysFd ] Name
|
||||
*/
|
||||
static void FillFdInfo(struct SeqBuf *seqBuf, struct filelist *fileList, unsigned int pid, bool hasPrivilege)
|
||||
{
|
||||
int fd;
|
||||
int sysFd;
|
||||
char *name = NULL;
|
||||
struct file *filp = NULL;
|
||||
|
||||
struct fd_table_s *fdt = LOS_GetFdTable(pid);
|
||||
if ((fdt == NULL) || (fdt->proc_fds == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
(void)sem_wait(&fdt->ft_sem);
|
||||
|
||||
for (fd = MIN_START_FD; fd < fdt->max_fds; fd++) {
|
||||
if (FD_ISSET(fd, fdt->proc_fds)) {
|
||||
sysFd = fdt->ft_fds[fd].sysFd;
|
||||
if (sysFd < CONFIG_NFILE_DESCRIPTORS) {
|
||||
filp = &fileList->fl_files[sysFd];
|
||||
name = filp->f_path;
|
||||
} else if (sysFd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
|
||||
name = "(socks)";
|
||||
} else if (sysFd < (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS)) {
|
||||
name = "(timer)";
|
||||
} else if (sysFd < (MQUEUE_FD_OFFSET + CONFIG_NQUEUE_DESCRIPTORS)) {
|
||||
name = "(mqueue)";
|
||||
} else {
|
||||
name = "(unknown)";
|
||||
}
|
||||
|
||||
if (hasPrivilege) {
|
||||
(void)LosBufPrintf(seqBuf, "%u\t%d\t%d\t%s\n", pid, fd, sysFd, name);
|
||||
} else {
|
||||
(void)LosBufPrintf(seqBuf, "%u\t%d\t%s\n", pid, fd, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(void)sem_post(&fdt->ft_sem);
|
||||
}
|
||||
|
||||
static int FdProcFill(struct SeqBuf *seqBuf, void *v)
|
||||
{
|
||||
int pidNum;
|
||||
bool hasPrivilege;
|
||||
unsigned int pidMaxNum;
|
||||
unsigned int *pidList = NULL;
|
||||
|
||||
/* privilege user */
|
||||
if (IsCapPermit(CAP_DAC_READ_SEARCH)) {
|
||||
pidMaxNum = LOS_GetSystemProcessMaximum();
|
||||
pidList = (unsigned int *)malloc(pidMaxNum * sizeof(unsigned int));
|
||||
if (pidList == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
pidNum = LOS_GetUsedPIDList(pidList, pidMaxNum);
|
||||
hasPrivilege = true;
|
||||
(void)LosBufPrintf(seqBuf, "Pid\tFd\tSysFd\tName\n");
|
||||
} else {
|
||||
pidNum = 1;
|
||||
pidList = (unsigned int *)malloc(pidNum * sizeof(unsigned int));
|
||||
if (pidList == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
pidList[0] = LOS_GetCurrProcessID();
|
||||
hasPrivilege = false;
|
||||
(void)LosBufPrintf(seqBuf, "Pid\tFd\tName\n");
|
||||
}
|
||||
|
||||
struct filelist *fileList = &tg_filelist;
|
||||
(void)sem_wait(&fileList->fl_sem);
|
||||
|
||||
for (int i = 0; i < pidNum; i++) {
|
||||
FillFdInfo(seqBuf, fileList, pidList[i], hasPrivilege);
|
||||
}
|
||||
|
||||
free(pidList);
|
||||
(void)sem_post(&fileList->fl_sem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations FD_PROC_FOPS = {
|
||||
.read = FdProcFill,
|
||||
};
|
||||
|
||||
void ProcFdInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("fd", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("creat /proc/fd error.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pde->procFileOps = &FD_PROC_FOPS;
|
||||
}
|
||||
|
||||
221
fs/proc/os_adapt/fs_cache_proc.c
Normal file
221
fs/proc/os_adapt/fs_cache_proc.c
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "proc_fs.h"
|
||||
#include "vnode.h"
|
||||
#include "path_cache.h"
|
||||
#include "los_vm_filemap.h"
|
||||
|
||||
#ifdef LOSCFG_DEBUG_VERSION
|
||||
|
||||
#define CLEAR_ALL_CACHE "clear all"
|
||||
#define CLEAR_PATH_CACHE "clear pathcache"
|
||||
#define CLEAR_PAGE_CACHE "clear pagecache"
|
||||
|
||||
static char* VnodeTypeToStr(enum VnodeType type) {
|
||||
switch (type) {
|
||||
case VNODE_TYPE_UNKNOWN:
|
||||
return "UKN";
|
||||
case VNODE_TYPE_REG:
|
||||
return "REG";
|
||||
case VNODE_TYPE_DIR:
|
||||
return "DIR";
|
||||
case VNODE_TYPE_BLK:
|
||||
return "BLK";
|
||||
case VNODE_TYPE_CHR:
|
||||
return "CHR";
|
||||
case VNODE_TYPE_BCHR:
|
||||
return "BCH";
|
||||
case VNODE_TYPE_FIFO:
|
||||
return "FIF";
|
||||
case VNODE_TYPE_LNK:
|
||||
return "LNK";
|
||||
default:
|
||||
return "BAD";
|
||||
}
|
||||
}
|
||||
|
||||
static int VnodeListProcess(struct SeqBuf *buf, LIST_HEAD* list)
|
||||
{
|
||||
int count = 0;
|
||||
struct Vnode *item = NULL;
|
||||
struct Vnode *nextItem = NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, list, struct Vnode, actFreeEntry) {
|
||||
LosBufPrintf(buf, "%-10p %-10p %-10p %10p 0x%08x %-3d %-4s %-3d %-3d %o\n",
|
||||
item, item->parent, item->data, item->vop, item->hash, item->useCount,
|
||||
VnodeTypeToStr(item->type), item->gid, item->uid, item->mode);
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int PathCacheListProcess(struct SeqBuf *buf)
|
||||
{
|
||||
int count = 0;
|
||||
LIST_HEAD* bucketList = GetPathCacheList();
|
||||
|
||||
for (int i = 0; i < LOSCFG_MAX_PATH_CACHE_SIZE; i++) {
|
||||
struct PathCache *pc = NULL;
|
||||
LIST_HEAD *list = &bucketList[i];
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(pc, list, struct PathCache, hashEntry) {
|
||||
LosBufPrintf(buf, "%-3d %-10p %-11p %-10p %-9d %s\n", i, pc,
|
||||
pc->parentVnode, pc->childVnode, pc->hit, pc->name);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int PageCacheEntryProcess(struct SeqBuf *buf, struct page_mapping *mapping)
|
||||
{
|
||||
int total = 0;
|
||||
LosFilePage *fpage = NULL;
|
||||
|
||||
if (mapping == NULL) {
|
||||
LosBufPrintf(buf, "null]\n");
|
||||
return total;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(fpage, &mapping->page_list, LosFilePage, node) {
|
||||
LosBufPrintf(buf, "%d,", fpage->pgoff);
|
||||
total++;
|
||||
}
|
||||
LosBufPrintf(buf, "]\n");
|
||||
return total;
|
||||
}
|
||||
|
||||
static int PageCacheMapProcess(struct SeqBuf *buf)
|
||||
{
|
||||
struct file_map *mapList = GetFileMappingList();
|
||||
char *name = NULL;
|
||||
struct file_map *curMap = NULL;
|
||||
int total = 0;
|
||||
|
||||
(VOID)LOS_MuxLock(&mapList->lock, LOS_WAIT_FOREVER);
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(curMap, &mapList->head, struct file_map, head) {
|
||||
name = curMap->rename ? curMap->rename: curMap->owner;
|
||||
LosBufPrintf(buf, "%s:[", name);
|
||||
total += PageCacheEntryProcess(buf, &curMap->mapping);
|
||||
}
|
||||
(VOID)LOS_MuxUnlock(&mapList->lock);
|
||||
return total;
|
||||
}
|
||||
|
||||
static int FsCacheInfoFill(struct SeqBuf *buf, void *arg)
|
||||
{
|
||||
int vnodeFree= 0;
|
||||
int vnodeActive= 0;
|
||||
int vnodeVirtual= 0;
|
||||
int vnodeTotal = 0;
|
||||
|
||||
int pathCacheTotal = 0;
|
||||
int pathCacheTotalTry = 0;
|
||||
int pathCacheTotalHit = 0;
|
||||
|
||||
int pageCacheTotal = 0;
|
||||
int pageCacheTotalTry = 0;
|
||||
int pageCacheTotalHit = 0;
|
||||
|
||||
ResetPathCacheHitInfo(&pathCacheTotalHit, &pathCacheTotalTry);
|
||||
ResetPageCacheHitInfo(&pageCacheTotalTry, &pageCacheTotalHit);
|
||||
|
||||
VnodeHold();
|
||||
LosBufPrintf(buf, "\n=================================================================\n");
|
||||
LosBufPrintf(buf, "VnodeAddr ParentAddr DataAddr VnodeOps Hash Ref Type Gid Uid Mode\n");
|
||||
vnodeVirtual = VnodeListProcess(buf, GetVnodeVirtualList());
|
||||
vnodeFree = VnodeListProcess(buf, GetVnodeFreeList());
|
||||
vnodeActive = VnodeListProcess(buf, GetVnodeActiveList());
|
||||
vnodeTotal = vnodeVirtual + vnodeFree + vnodeActive;
|
||||
|
||||
LosBufPrintf(buf, "\n=================================================================\n");
|
||||
LosBufPrintf(buf, "No. CacheAddr ParentAddr ChildAddr HitCount Name\n");
|
||||
pathCacheTotal = PathCacheListProcess(buf);
|
||||
|
||||
LosBufPrintf(buf, "\n=================================================================\n");
|
||||
pageCacheTotal = PageCacheMapProcess(buf);
|
||||
|
||||
LosBufPrintf(buf, "\n=================================================================\n");
|
||||
LosBufPrintf(buf, "PathCache Total:%d Try:%d Hit:%d\n",
|
||||
pathCacheTotal, pathCacheTotalTry, pathCacheTotalHit);
|
||||
LosBufPrintf(buf, "Vnode Total:%d Free:%d Virtual:%d Active:%d\n",
|
||||
vnodeTotal, vnodeFree, vnodeVirtual, vnodeActive);
|
||||
LosBufPrintf(buf, "PageCache total:%d Try:%d Hit:%d\n", pageCacheTotal, pageCacheTotalTry, pageCacheTotalHit);
|
||||
VnodeDrop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FsCacheClear(struct ProcFile *pf, const char *buffer, size_t buflen, loff_t *ppos)
|
||||
{
|
||||
if (buffer == NULL || buflen < sizeof(CLEAR_ALL_CACHE)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
int vnodeCount = 0;
|
||||
int pageCount = 0;
|
||||
|
||||
if (!strcmp(buffer, CLEAR_ALL_CACHE)) {
|
||||
vnodeCount = VnodeClearCache();
|
||||
pageCount = OsTryShrinkMemory(VM_FILEMAP_MAX_SCAN);
|
||||
} else if (!strcmp(buffer, CLEAR_PAGE_CACHE)) {
|
||||
pageCount = OsTryShrinkMemory(VM_FILEMAP_MAX_SCAN);
|
||||
} else if (!strcmp(buffer, CLEAR_PATH_CACHE)) {
|
||||
vnodeCount = VnodeClearCache();
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
PRINTK("%d vnodes and related pathcaches cleared\n%d pages cleared\n", vnodeCount, pageCount);
|
||||
return buflen;
|
||||
}
|
||||
static const struct ProcFileOperations FS_CACHE_PROC_FOPS = {
|
||||
.read = FsCacheInfoFill,
|
||||
.write = FsCacheClear,
|
||||
};
|
||||
|
||||
void ProcFsCacheInit(void)
|
||||
{
|
||||
struct ProcDirEntry *pde = CreateProcEntry("fs_cache", 0, NULL);
|
||||
if (pde == NULL) {
|
||||
PRINT_ERR("create fs_cache error!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
pde->procFileOps = &FS_CACHE_PROC_FOPS;
|
||||
}
|
||||
#else
|
||||
void ProcFsCacheInit(void)
|
||||
{
|
||||
/* do nothing in release version */
|
||||
}
|
||||
#endif
|
||||
@@ -32,9 +32,9 @@
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/mount.h>
|
||||
#include "proc_fs.h"
|
||||
#include "los_trace.h"
|
||||
|
||||
#ifdef LOSCFG_KERNEL_TRACE
|
||||
#include "los_trace.h"
|
||||
static int KernelTraceProcFill(struct SeqBuf *m, void *v)
|
||||
{
|
||||
(void)v;
|
||||
|
||||
@@ -38,42 +38,39 @@
|
||||
#include "fs/mount.h"
|
||||
#include "internal.h"
|
||||
|
||||
static int ShowType(const char *mountPoint, struct statfs *statBuf, void *arg)
|
||||
static int ShowType(const char *devPoint, const char *mountPoint, struct statfs *statBuf, void *arg)
|
||||
{
|
||||
struct SeqBuf *seqBuf = (struct SeqBuf *)arg;
|
||||
char *type = NULL;
|
||||
char *name = NULL;
|
||||
|
||||
switch (statBuf->f_type) {
|
||||
case PROCFS_MAGIC:
|
||||
type = "proc";
|
||||
name = "proc";
|
||||
break;
|
||||
case JFFS2_SUPER_MAGIC:
|
||||
type = "jffs2";
|
||||
name = "jffs2";
|
||||
break;
|
||||
case NFS_SUPER_MAGIC:
|
||||
type = "nfs";
|
||||
name = "nfs";
|
||||
break;
|
||||
case TMPFS_MAGIC:
|
||||
type = "tmpfs";
|
||||
name = "tmpfs";
|
||||
break;
|
||||
case MSDOS_SUPER_MAGIC:
|
||||
type = "vfat";
|
||||
name = "fat";
|
||||
break;
|
||||
case ZPFS_MAGIC:
|
||||
type = "zpfs";
|
||||
name = "zpfs";
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)LosBufPrintf(seqBuf, "%s %s %s\n", name, mountPoint, type);
|
||||
if (strlen(devPoint) == 0) {
|
||||
(void)LosBufPrintf(seqBuf, "%s %s %s %s %d %d\n", type, mountPoint, type, "()", 0, 0);
|
||||
} else {
|
||||
(void)LosBufPrintf(seqBuf, "%s %s %s %s %d %d\n", devPoint, mountPoint, type, "()", 0, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
178
fs/proc/os_adapt/power_proc.c
Normal file
178
fs/proc/os_adapt/power_proc.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* 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 <sys/statfs.h>
|
||||
#include <sys/mount.h>
|
||||
#include "proc_fs.h"
|
||||
#include "internal.h"
|
||||
#ifdef LOSCFG_KERNEL_PM
|
||||
#include "los_pm.h"
|
||||
|
||||
static int PowerLockWrite(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)pf;
|
||||
(void)count;
|
||||
(void)ppos;
|
||||
return -LOS_PmLockRequest(buf);
|
||||
}
|
||||
|
||||
static int PowerLockRead(struct SeqBuf *m, void *v)
|
||||
{
|
||||
(void)v;
|
||||
|
||||
LOS_PmLockInfoShow(m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations PowerLock = {
|
||||
.write = PowerLockWrite,
|
||||
.read = PowerLockRead,
|
||||
};
|
||||
|
||||
static int PowerUnlockWrite(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)pf;
|
||||
(void)count;
|
||||
(void)ppos;
|
||||
return -LOS_PmLockRelease(buf);
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations PowerUnlock = {
|
||||
.write = PowerUnlockWrite,
|
||||
.read = PowerLockRead,
|
||||
};
|
||||
|
||||
static int PowerModeWrite(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
(void)pf;
|
||||
(void)count;
|
||||
(void)ppos;
|
||||
|
||||
if (buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(buf, "normal") != 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PowerModeRead(struct SeqBuf *m, void *v)
|
||||
{
|
||||
(void)v;
|
||||
|
||||
LosBufPrintf(m, "normal \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations PowerMode = {
|
||||
.write = PowerModeWrite,
|
||||
.read = PowerModeRead,
|
||||
};
|
||||
|
||||
static int PowerCountRead(struct SeqBuf *m, void *v)
|
||||
{
|
||||
(void)v;
|
||||
UINT32 count = LOS_PmLockCountGet();
|
||||
|
||||
LosBufPrintf(m, "%u\n", count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ProcFileOperations PowerCount = {
|
||||
.write = NULL,
|
||||
.read = PowerCountRead,
|
||||
};
|
||||
|
||||
#define POWER_FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
|
||||
#define OS_POWER_PRIVILEGE 7
|
||||
|
||||
void ProcPmInit(void)
|
||||
{
|
||||
struct ProcDirEntry *power = CreateProcEntry("power", S_IFDIR | S_IRWXU | S_IRWXG | S_IROTH, NULL);
|
||||
if (power == NULL) {
|
||||
PRINT_ERR("create /proc/power error!\n");
|
||||
return;
|
||||
}
|
||||
power->uid = OS_POWER_PRIVILEGE;
|
||||
power->gid = OS_POWER_PRIVILEGE;
|
||||
|
||||
struct ProcDirEntry *mode = CreateProcEntry("power/power_mode", POWER_FILE_MODE, NULL);
|
||||
if (mode == NULL) {
|
||||
PRINT_ERR("create /proc/power/power_mode error!\n");
|
||||
goto FREE_POWER;
|
||||
}
|
||||
mode->procFileOps = &PowerMode;
|
||||
mode->uid = OS_POWER_PRIVILEGE;
|
||||
mode->gid = OS_POWER_PRIVILEGE;
|
||||
|
||||
struct ProcDirEntry *lock = CreateProcEntry("power/power_lock", POWER_FILE_MODE, NULL);
|
||||
if (lock == NULL) {
|
||||
PRINT_ERR("create /proc/power/power_lock error!\n");
|
||||
goto FREE_MODE;
|
||||
}
|
||||
lock->procFileOps = &PowerLock;
|
||||
lock->uid = OS_POWER_PRIVILEGE;
|
||||
lock->gid = OS_POWER_PRIVILEGE;
|
||||
|
||||
struct ProcDirEntry *unlock = CreateProcEntry("power/power_unlock", POWER_FILE_MODE, NULL);
|
||||
if (unlock == NULL) {
|
||||
PRINT_ERR("create /proc/power/power_unlock error!\n");
|
||||
goto FREE_LOCK;
|
||||
}
|
||||
unlock->procFileOps = &PowerUnlock;
|
||||
unlock->uid = OS_POWER_PRIVILEGE;
|
||||
unlock->gid = OS_POWER_PRIVILEGE;
|
||||
|
||||
struct ProcDirEntry *count = CreateProcEntry("power/power_count", S_IRUSR | S_IRGRP | S_IROTH, NULL);
|
||||
if (count == NULL) {
|
||||
PRINT_ERR("create /proc/power/power_count error!\n");
|
||||
goto FREE_UNLOCK;
|
||||
}
|
||||
count->procFileOps = &PowerCount;
|
||||
count->uid = OS_POWER_PRIVILEGE;
|
||||
count->gid = OS_POWER_PRIVILEGE;
|
||||
|
||||
return;
|
||||
|
||||
FREE_UNLOCK:
|
||||
ProcFreeEntry(unlock);
|
||||
FREE_LOCK:
|
||||
ProcFreeEntry(lock);
|
||||
FREE_MODE:
|
||||
ProcFreeEntry(mode);
|
||||
FREE_POWER:
|
||||
ProcFreeEntry(power);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -64,6 +64,11 @@ void ProcFsInit(void)
|
||||
ProcProcessInit();
|
||||
ProcUptimeInit();
|
||||
ProcKernelTraceInit();
|
||||
ProcFsCacheInit();
|
||||
ProcFdInit();
|
||||
#ifdef LOSCFG_KERNEL_PM
|
||||
ProcPmInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
LOS_MODULE_INIT(ProcFsInit, LOS_INIT_LEVEL_KMOD_EXTENDED);
|
||||
|
||||
@@ -60,11 +60,9 @@ static struct Vnode *EntryToVnode(struct ProcDirEntry *entry)
|
||||
node->fop = &g_procfsFops;
|
||||
node->data = entry;
|
||||
node->type = entry->type;
|
||||
if (node->type == VNODE_TYPE_DIR) {
|
||||
node->mode = S_IFDIR | PROCFS_DEFAULT_MODE;
|
||||
} else {
|
||||
node->mode = S_IFREG | PROCFS_DEFAULT_MODE;
|
||||
}
|
||||
node->uid = entry->uid;
|
||||
node->gid = entry->gid;
|
||||
node->mode = entry->mode;
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ struct PathCache {
|
||||
LIST_ENTRY childEntry; /* list entry for cache list in the child vnode */
|
||||
LIST_ENTRY hashEntry; /* list entry for buckets in the hash table */
|
||||
uint8_t nameLen; /* length of path component */
|
||||
#ifdef LOSCFG_DEBUG_VERSION
|
||||
int hit; /* cache hit count*/
|
||||
#endif
|
||||
char name[0]; /* path component name */
|
||||
};
|
||||
|
||||
@@ -52,5 +55,9 @@ int PathCacheLookup(struct Vnode *parent, const char *name, int len, struct Vnod
|
||||
void VnodePathCacheFree(struct Vnode *vnode);
|
||||
void PathCacheMemoryDump(void);
|
||||
void PathCacheDump(void);
|
||||
LIST_HEAD* GetPathCacheList(void);
|
||||
#ifdef LOSCFG_DEBUG_VERSION
|
||||
void ResetPathCacheHitInfo(int *hit, int *try);
|
||||
#endif
|
||||
|
||||
#endif /* _PATH_CACHE_H */
|
||||
|
||||
@@ -176,5 +176,9 @@ void VnodeMemoryDump(void);
|
||||
mode_t GetUmask(void);
|
||||
int VfsPermissionCheck(uint fuid, uint fgid, mode_t fileMode, int accMode);
|
||||
int VfsVnodePermissionCheck(const struct Vnode *node, int accMode);
|
||||
LIST_HEAD* GetVnodeFreeList(void);
|
||||
LIST_HEAD* GetVnodeActiveList(void);
|
||||
LIST_HEAD* GetVnodeVirtualList(void);
|
||||
int VnodeClearCache(void);
|
||||
|
||||
#endif /* !_VNODE_H_ */
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
#include "stdlib.h"
|
||||
#include "sys/stat.h"
|
||||
#include "vnode.h"
|
||||
#include "fs/mount.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Static Functions
|
||||
@@ -69,6 +71,11 @@ int chattr(const char *pathname, struct IATTR *attr)
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY)) {
|
||||
ret = -EROFS;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* The way we handle the stat depends on the type of vnode that we
|
||||
* are dealing with.
|
||||
*/
|
||||
|
||||
@@ -406,7 +406,7 @@ int CopyFdToProc(int fd, unsigned int targetPid)
|
||||
return -ESRCH;
|
||||
}
|
||||
|
||||
procFd = AssignProcessFd(fdt, 3);
|
||||
procFd = AssignProcessFd(fdt, 3); // minfd is 3
|
||||
if (procFd < 0) {
|
||||
if (sem_post(&semId) == -1) {
|
||||
PRINT_ERR("sem_post error, errno %d \n", get_errno());
|
||||
|
||||
@@ -293,4 +293,11 @@ out:
|
||||
(void)sem_post(&f_list->fl_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_DEBUG_VERSION
|
||||
struct file_map* GetFileMappingList(void)
|
||||
{
|
||||
return &g_file_mapping;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -35,7 +35,9 @@
|
||||
#include "dirent.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/select.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/stat.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "sys/prctl.h"
|
||||
#include "fs/fd_table.h"
|
||||
#include "fs/file.h"
|
||||
@@ -256,30 +258,70 @@ char *getcwd(char *buf, size_t n)
|
||||
|
||||
int chmod(const char *path, mode_t mode)
|
||||
{
|
||||
int result;
|
||||
struct stat buf;
|
||||
struct IATTR attr = {0};
|
||||
attr.attr_chg_mode = mode;
|
||||
attr.attr_chg_valid = CHG_MODE; /* change mode */
|
||||
int ret;
|
||||
|
||||
result = stat(path, &buf);
|
||||
if (result != ENOERR) {
|
||||
ret = chattr(path, &attr);
|
||||
if (ret < 0) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int chown(const char *pathname, uid_t owner, gid_t group)
|
||||
{
|
||||
struct IATTR attr = {0};
|
||||
attr.attr_chg_valid = 0;
|
||||
int ret;
|
||||
|
||||
if (owner != (uid_t)-1) {
|
||||
attr.attr_chg_uid = owner;
|
||||
attr.attr_chg_valid |= CHG_UID;
|
||||
}
|
||||
if (group != (gid_t)-1) {
|
||||
attr.attr_chg_gid = group;
|
||||
attr.attr_chg_valid |= CHG_GID;
|
||||
}
|
||||
ret = chattr(pathname, &attr);
|
||||
if (ret < 0) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
/* no access/permission control for files now, just return OK if stat is okay*/
|
||||
return OK;
|
||||
}
|
||||
|
||||
int access(const char *path, int amode)
|
||||
{
|
||||
int result;
|
||||
int ret;
|
||||
struct stat buf;
|
||||
struct statfs fsBuf;
|
||||
|
||||
result = stat(path, &buf);
|
||||
ret = statfs(path, &fsBuf);
|
||||
if (ret != 0) {
|
||||
if (get_errno() != ENOSYS) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
/* dev has no statfs ops, need devfs to handle this in feature */
|
||||
}
|
||||
|
||||
if (result != ENOERR) {
|
||||
if ((fsBuf.f_flags & MS_RDONLY) && ((unsigned int)amode & W_OK)) {
|
||||
set_errno(EROFS);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = stat(path, &buf);
|
||||
if (ret != 0) {
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
if (VfsPermissionCheck(buf.st_uid, buf.st_gid, buf.st_mode, amode)) {
|
||||
set_errno(EACCES);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
/* no access/permission control for files now, just return OK if stat is okay*/
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,11 @@
|
||||
#include "vfs_config.h"
|
||||
#include "sys/stat.h"
|
||||
#include "vnode.h"
|
||||
#include "fs/mount.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "utime.h"
|
||||
#include <fcntl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
@@ -79,6 +81,12 @@ int utime(const char *path, const struct utimbuf *ptimes)
|
||||
goto errout_with_path;
|
||||
}
|
||||
|
||||
if ((vnode->originMount) && (vnode->originMount->mountFlags & MS_RDONLY)) {
|
||||
VnodeDrop();
|
||||
ret = -EROFS;
|
||||
goto errout_with_path;
|
||||
}
|
||||
|
||||
if (vnode->vop && vnode->vop->Chattr) {
|
||||
if (ptimes == NULL) {
|
||||
/* get current seconds */
|
||||
|
||||
@@ -37,6 +37,23 @@
|
||||
|
||||
#define PATH_CACHE_HASH_MASK (LOSCFG_MAX_PATH_CACHE_SIZE - 1)
|
||||
LIST_HEAD g_pathCacheHashEntrys[LOSCFG_MAX_PATH_CACHE_SIZE];
|
||||
#ifdef LOSCFG_DEBUG_VERSION
|
||||
static int g_totalPathCacheHit = 0;
|
||||
static int g_totalPathCacheTry = 0;
|
||||
#define TRACE_TRY_CACHE() do { g_totalPathCacheTry++; } while (0)
|
||||
#define TRACE_HIT_CACHE(pc) do { pc->hit++; g_totalPathCacheHit++; } while (0)
|
||||
|
||||
void ResetPathCacheHitInfo(int *hit, int *try)
|
||||
{
|
||||
*hit = g_totalPathCacheHit;
|
||||
*try = g_totalPathCacheTry;
|
||||
g_totalPathCacheHit = 0;
|
||||
g_totalPathCacheTry = 0;
|
||||
}
|
||||
#else
|
||||
#define TRACE_TRY_CACHE()
|
||||
#define TRACE_HIT_CACHE(pc)
|
||||
#endif
|
||||
|
||||
int PathCacheInit(void)
|
||||
{
|
||||
@@ -50,12 +67,12 @@ void PathCacheDump(void)
|
||||
{
|
||||
PRINTK("-------->pathCache dump in\n");
|
||||
for (int i = 0; i < LOSCFG_MAX_PATH_CACHE_SIZE; i++) {
|
||||
struct PathCache *nc = NULL;
|
||||
struct PathCache *pc = NULL;
|
||||
LIST_HEAD *nhead = &g_pathCacheHashEntrys[i];
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(nc, nhead, struct PathCache, hashEntry) {
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(pc, nhead, struct PathCache, hashEntry) {
|
||||
PRINTK(" pathCache dump hash %d item %s %p %p %d\n", i,
|
||||
nc->name, nc->parentVnode, nc->childVnode, nc->nameLen);
|
||||
pc->name, pc->parentVnode, pc->childVnode, pc->nameLen);
|
||||
}
|
||||
}
|
||||
PRINTK("-------->pathCache dump out\n");
|
||||
@@ -94,7 +111,7 @@ static void PathCacheInsert(struct Vnode *parent, struct PathCache *cache, const
|
||||
|
||||
struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, const char *name, uint8_t len)
|
||||
{
|
||||
struct PathCache *nc = NULL;
|
||||
struct PathCache *pc = NULL;
|
||||
size_t pathCacheSize;
|
||||
int ret;
|
||||
|
||||
@@ -103,53 +120,55 @@ struct PathCache *PathCacheAlloc(struct Vnode *parent, struct Vnode *vnode, cons
|
||||
}
|
||||
pathCacheSize = sizeof(struct PathCache) + len + 1;
|
||||
|
||||
nc = (struct PathCache*)zalloc(pathCacheSize);
|
||||
if (nc == NULL) {
|
||||
pc = (struct PathCache*)zalloc(pathCacheSize);
|
||||
if (pc == NULL) {
|
||||
PRINT_ERR("pathCache alloc failed, no memory!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = strncpy_s(nc->name, len + 1, name, len);
|
||||
ret = strncpy_s(pc->name, len + 1, name, len);
|
||||
if (ret != LOS_OK) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nc->parentVnode = parent;
|
||||
nc->nameLen = len;
|
||||
nc->childVnode = vnode;
|
||||
pc->parentVnode = parent;
|
||||
pc->nameLen = len;
|
||||
pc->childVnode = vnode;
|
||||
|
||||
LOS_ListAdd((&(parent->childPathCaches)), (&(nc->childEntry)));
|
||||
LOS_ListAdd((&(vnode->parentPathCaches)), (&(nc->parentEntry)));
|
||||
LOS_ListAdd((&(parent->childPathCaches)), (&(pc->childEntry)));
|
||||
LOS_ListAdd((&(vnode->parentPathCaches)), (&(pc->parentEntry)));
|
||||
|
||||
PathCacheInsert(parent, nc, name, len);
|
||||
PathCacheInsert(parent, pc, name, len);
|
||||
|
||||
return nc;
|
||||
return pc;
|
||||
}
|
||||
|
||||
int PathCacheFree(struct PathCache *nc)
|
||||
int PathCacheFree(struct PathCache *pc)
|
||||
{
|
||||
if (nc == NULL) {
|
||||
if (pc == NULL) {
|
||||
PRINT_ERR("pathCache free: invalid pathCache\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
LOS_ListDelete(&nc->hashEntry);
|
||||
LOS_ListDelete(&nc->parentEntry);
|
||||
LOS_ListDelete(&nc->childEntry);
|
||||
free(nc);
|
||||
LOS_ListDelete(&pc->hashEntry);
|
||||
LOS_ListDelete(&pc->parentEntry);
|
||||
LOS_ListDelete(&pc->childEntry);
|
||||
free(pc);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
int PathCacheLookup(struct Vnode *parent, const char *name, int len, struct Vnode **vnode)
|
||||
{
|
||||
struct PathCache *nc = NULL;
|
||||
struct PathCache *pc = NULL;
|
||||
int hash = NameHash(name, len, parent) & PATH_CACHE_HASH_MASK;
|
||||
LIST_HEAD *dhead = &g_pathCacheHashEntrys[hash];
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(nc, dhead, struct PathCache, hashEntry) {
|
||||
if (nc->parentVnode == parent && nc->nameLen == len && !strncmp(nc->name, name, len)) {
|
||||
*vnode = nc->childVnode;
|
||||
TRACE_TRY_CACHE();
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(pc, dhead, struct PathCache, hashEntry) {
|
||||
if (pc->parentVnode == parent && pc->nameLen == len && !strncmp(pc->name, name, len)) {
|
||||
*vnode = pc->childVnode;
|
||||
TRACE_HIT_CACHE(pc);
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
@@ -184,3 +203,8 @@ void VnodePathCacheFree(struct Vnode *vnode)
|
||||
FreeParentPathCache(vnode);
|
||||
FreeChildPathCache(vnode);
|
||||
}
|
||||
|
||||
LIST_HEAD* GetPathCacheList()
|
||||
{
|
||||
return g_pathCacheHashEntrys;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
LIST_HEAD g_vnodeFreeList; /* free vnodes list */
|
||||
LIST_HEAD g_vnodeVirtualList; /* dev vnodes list */
|
||||
LIST_HEAD g_vnodeCurrList; /* inuse vnodes list */
|
||||
LIST_HEAD g_vnodeActiveList; /* inuse vnodes list */
|
||||
static int g_freeVnodeSize = 0; /* system free vnodes size */
|
||||
static int g_totalVnodeSize = 0; /* total vnode size */
|
||||
|
||||
@@ -57,7 +57,7 @@ int VnodesInit(void)
|
||||
|
||||
LOS_ListInit(&g_vnodeFreeList);
|
||||
LOS_ListInit(&g_vnodeVirtualList);
|
||||
LOS_ListInit(&g_vnodeCurrList);
|
||||
LOS_ListInit(&g_vnodeActiveList);
|
||||
retval = VnodeAlloc(NULL, &g_rootVnode);
|
||||
if (retval != LOS_OK) {
|
||||
PRINT_ERR("VnodeInit failed error %d\n", retval);
|
||||
@@ -94,7 +94,7 @@ struct Vnode *VnodeReclaimLru(void)
|
||||
struct Vnode *nextItem = NULL;
|
||||
int releaseCount = 0;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeCurrList, struct Vnode, actFreeEntry) {
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
|
||||
if ((item->useCount > 0) ||
|
||||
(item->flag & VNODE_FLAG_MOUNT_ORIGIN) ||
|
||||
(item->flag & VNODE_FLAG_MOUNT_NEW)) {
|
||||
@@ -152,7 +152,7 @@ int VnodeAlloc(struct VnodeOps *vop, struct Vnode **newVnode)
|
||||
LOS_ListAdd(&g_vnodeVirtualList, &(vnode->actFreeEntry));
|
||||
vnode->vop = &g_devfsOps;
|
||||
} else {
|
||||
LOS_ListTailInsert(&g_vnodeCurrList, &(vnode->actFreeEntry));
|
||||
LOS_ListTailInsert(&g_vnodeActiveList, &(vnode->actFreeEntry));
|
||||
vnode->vop = vop;
|
||||
}
|
||||
VnodeDrop();
|
||||
@@ -204,7 +204,7 @@ int VnodeFreeAll(const struct Mount *mount)
|
||||
struct Vnode *nextVnode = NULL;
|
||||
int ret;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(vnode, nextVnode, &g_vnodeCurrList, struct Vnode, actFreeEntry) {
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(vnode, nextVnode, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
|
||||
if ((vnode->originMount == mount) && !(vnode->flag & VNODE_FLAG_MOUNT_NEW)) {
|
||||
ret = VnodeFree(vnode);
|
||||
if (ret != LOS_OK) {
|
||||
@@ -220,7 +220,7 @@ BOOL VnodeInUseIter(const struct Mount *mount)
|
||||
{
|
||||
struct Vnode *vnode = NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(vnode, &g_vnodeCurrList, struct Vnode, actFreeEntry) {
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(vnode, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
|
||||
if (vnode->originMount == mount) {
|
||||
if ((vnode->useCount > 0) || (vnode->flag & VNODE_FLAG_MOUNT_ORIGIN)) {
|
||||
return TRUE;
|
||||
@@ -294,7 +294,7 @@ static void RefreshLRU(struct Vnode *vnode)
|
||||
return;
|
||||
}
|
||||
LOS_ListDelete(&(vnode->actFreeEntry));
|
||||
LOS_ListTailInsert(&g_vnodeCurrList, &(vnode->actFreeEntry));
|
||||
LOS_ListTailInsert(&g_vnodeActiveList, &(vnode->actFreeEntry));
|
||||
}
|
||||
|
||||
static int ProcessVirtualVnode(struct Vnode *parent, uint32_t flags, struct Vnode **vnode)
|
||||
@@ -612,7 +612,7 @@ void VnodeMemoryDump(void)
|
||||
struct Vnode *nextItem = NULL;
|
||||
int vnodeCount = 0;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeCurrList, struct Vnode, actFreeEntry) {
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
|
||||
if ((item->useCount > 0) ||
|
||||
(item->flag & VNODE_FLAG_MOUNT_ORIGIN) ||
|
||||
(item->flag & VNODE_FLAG_MOUNT_NEW)) {
|
||||
@@ -625,3 +625,41 @@ void VnodeMemoryDump(void)
|
||||
PRINTK("Vnode number = %d\n", vnodeCount);
|
||||
PRINTK("Vnode memory size = %d(B)\n", vnodeCount * sizeof(struct Vnode));
|
||||
}
|
||||
|
||||
LIST_HEAD* GetVnodeFreeList()
|
||||
{
|
||||
return &g_vnodeFreeList;
|
||||
}
|
||||
|
||||
LIST_HEAD* GetVnodeVirtualList()
|
||||
{
|
||||
return &g_vnodeVirtualList;
|
||||
}
|
||||
|
||||
LIST_HEAD* GetVnodeActiveList()
|
||||
{
|
||||
return &g_vnodeActiveList;
|
||||
}
|
||||
|
||||
int VnodeClearCache()
|
||||
{
|
||||
struct Vnode *item = NULL;
|
||||
struct Vnode *nextItem = NULL;
|
||||
int count = 0;
|
||||
|
||||
VnodeHold();
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_vnodeActiveList, struct Vnode, actFreeEntry) {
|
||||
if ((item->useCount > 0) ||
|
||||
(item->flag & VNODE_FLAG_MOUNT_ORIGIN) ||
|
||||
(item->flag & VNODE_FLAG_MOUNT_NEW)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (VnodeFree(item) == LOS_OK) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
VnodeDrop();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -89,6 +89,13 @@ config KERNEL_DYNLOAD
|
||||
help
|
||||
If you wish to build LiteOS with support for dynamic load.
|
||||
|
||||
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 ASLR
|
||||
bool "Enable Address Space Layout Randomization"
|
||||
default n
|
||||
|
||||
@@ -183,7 +183,7 @@ VOID OsWaitWakeTask(LosTaskCB *taskCB, UINT32 wakePID)
|
||||
{
|
||||
taskCB->waitID = wakePID;
|
||||
OsSchedTaskWake(taskCB);
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LOS_MpSchedule(OS_MP_CPU_ALL);
|
||||
#endif
|
||||
}
|
||||
@@ -312,7 +312,7 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
if (OsProcessIsUserMode(processCB)) {
|
||||
LiteIpcPoolDelete(&(processCB->ipcInfo));
|
||||
(VOID)memset_s(&(processCB->ipcInfo), sizeof(ProcIpcInfo), 0, sizeof(ProcIpcInfo));
|
||||
@@ -685,7 +685,7 @@ STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const C
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
if (OsProcessIsUserMode(processCB)) {
|
||||
ret = LiteIpcPoolInit(&(processCB->ipcInfo));
|
||||
if (ret != LOS_OK) {
|
||||
@@ -1294,7 +1294,7 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
ret = LiteIpcPoolInit(&(processCB->ipcInfo));
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_NOK;
|
||||
@@ -1690,7 +1690,7 @@ STATIC UINT32 OsCopyProcessResources(UINT32 flags, LosProcessCB *child, LosProce
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
if (OsProcessIsUserMode(child)) {
|
||||
ret = LiteIpcPoolReInit(&child->ipcInfo, (const ProcIpcInfo *)(&run->ipcInfo));
|
||||
if (ret != LOS_OK) {
|
||||
@@ -1794,6 +1794,52 @@ LITE_OS_SEC_TEXT VOID LOS_Exit(INT32 status)
|
||||
OsProcessExit(OsCurrTaskGet(), (UINT32)status);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT INT32 LOS_GetUsedPIDList(UINT32 *pidList, INT32 pidMaxNum)
|
||||
{
|
||||
LosProcessCB *pcb = NULL;
|
||||
INT32 num = 0;
|
||||
UINT32 intSave;
|
||||
UINT32 pid = 1;
|
||||
|
||||
if (pidList == NULL) {
|
||||
return 0;
|
||||
}
|
||||
SCHEDULER_LOCK(intSave);
|
||||
while (OsProcessIDUserCheckInvalid(pid) == false) {
|
||||
pcb = OS_PCB_FROM_PID(pid);
|
||||
pid++;
|
||||
if (OsProcessIsUnused(pcb)) {
|
||||
continue;
|
||||
}
|
||||
pidList[num] = pcb->processID;
|
||||
num++;
|
||||
if (num >= pidMaxNum) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
return num;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
LITE_OS_SEC_TEXT struct fd_table_s *LOS_GetFdTable(UINT32 pid)
|
||||
{
|
||||
LosProcessCB *pcb = NULL;
|
||||
struct files_struct *files = NULL;
|
||||
|
||||
if (OS_PID_CHECK_INVALID(pid)) {
|
||||
return NULL;
|
||||
}
|
||||
pcb = OS_PCB_FROM_PID(pid);
|
||||
files = pcb->files;
|
||||
if (files == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return files->fdt;
|
||||
}
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_GetCurrProcessID(VOID)
|
||||
{
|
||||
return OsCurrProcessGet()->processID;
|
||||
|
||||
@@ -127,7 +127,7 @@ STATIC Percpu *OsFindIdleCpu(UINT16 *ildeCpuID)
|
||||
Percpu *idleCpu = OsPercpuGetByID(0);
|
||||
*ildeCpuID = 0;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT16 cpuID = 1;
|
||||
UINT32 nodeNum = idleCpu->taskSortLink.nodeNum + idleCpu->swtmrSortLink.nodeNum;
|
||||
|
||||
@@ -174,7 +174,7 @@ VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, Sort
|
||||
LOS_SpinLockSave(spinLock, &intSave);
|
||||
SET_SORTLIST_VALUE(node, startTime + (UINT64)waitTicks * OS_CYCLE_PER_TICK);
|
||||
OsAddNode2SortLink(sortLinkHeader, node);
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
node->cpuid = idleCpu;
|
||||
if (idleCpu != ArchCurrCpuid()) {
|
||||
LOS_MpSchedule(CPUID_TO_AFFI_MASK(idleCpu));
|
||||
@@ -186,7 +186,7 @@ VOID OsAdd2SortLink(SortLinkList *node, UINT64 startTime, UINT32 waitTicks, Sort
|
||||
VOID OsDeleteSortLink(SortLinkList *node, SortLinkType type)
|
||||
{
|
||||
UINT32 intSave;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
Percpu *cpu = OsPercpuGetByID(node->cpuid);
|
||||
#else
|
||||
Percpu *cpu = OsPercpuGetByID(0);
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "los_task_pri.h"
|
||||
|
||||
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == YES)
|
||||
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
|
||||
#if (LOSCFG_BASE_CORE_SWTMR_LIMIT <= 0)
|
||||
#error "swtmr maxnum cannot be zero"
|
||||
#endif /* LOSCFG_BASE_CORE_SWTMR_LIMIT <= 0 */
|
||||
@@ -84,7 +84,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
|
||||
swtmrTask.pcName = "Swt_Task";
|
||||
swtmrTask.usTaskPrio = 0;
|
||||
swtmrTask.uwResved = LOS_TASK_STATUS_DETACHED;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
swtmrTask.usCpuAffiMask = CPUID_TO_AFFI_MASK(cpuid);
|
||||
#endif
|
||||
ret = LOS_TaskCreate(&swtmrTaskID, &swtmrTask);
|
||||
@@ -533,4 +533,4 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* LOSCFG_BASE_CORE_SWTMR */
|
||||
#endif /* LOSCFG_BASE_CORE_SWTMR_ENABLE */
|
||||
|
||||
@@ -51,10 +51,10 @@
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
#include "los_cpup_pri.h"
|
||||
#endif
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == YES)
|
||||
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
|
||||
#include "los_swtmr_pri.h"
|
||||
#endif
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
#include "hm_liteipc.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_ENABLE_OOM_LOOP_TASK
|
||||
@@ -98,7 +98,7 @@ VOID OsSetMainTask()
|
||||
g_mainTask[i].taskStatus = OS_TASK_STATUS_UNUSED;
|
||||
g_mainTask[i].taskID = LOSCFG_BASE_CORE_TSK_LIMIT;
|
||||
g_mainTask[i].priority = OS_TASK_PRIORITY_LOWEST;
|
||||
#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
|
||||
g_mainTask[i].lockDep.lockDepth = 0;
|
||||
g_mainTask[i].lockDep.waitLock = NULL;
|
||||
#endif
|
||||
@@ -208,7 +208,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
|
||||
LOS_ListTailInsert(&g_losFreeTask, &g_taskCBArray[index].pendList);
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_TRACE == YES)
|
||||
#ifdef LOSCFG_KERNEL_TRACE
|
||||
LOS_TraceReg(LOS_TRACE_TASK, OsTaskTrace, LOS_TRACE_TASK_NAME, LOS_TRACE_ENABLE);
|
||||
#endif
|
||||
|
||||
@@ -240,7 +240,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
|
||||
taskInitParam.pcName = "Idle";
|
||||
taskInitParam.usTaskPrio = OS_TASK_PRIORITY_LOWEST;
|
||||
taskInitParam.processID = OsGetIdleProcessID();
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
taskInitParam.usCpuAffiMask = CPUID_TO_AFFI_MASK(ArchCurrCpuid());
|
||||
#endif
|
||||
ret = LOS_TaskCreateOnly(idleTaskID, &taskInitParam);
|
||||
@@ -381,7 +381,7 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskStackAlloc(VOID **topStack, UINT32 stack
|
||||
|
||||
STATIC INLINE UINT32 OsTaskSyncCreate(LosTaskCB *taskCB)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
|
||||
UINT32 ret = LOS_SemCreate(0, &taskCB->syncSignal);
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_ERRNO_TSK_MP_SYNC_RESOURCE;
|
||||
@@ -394,7 +394,7 @@ STATIC INLINE UINT32 OsTaskSyncCreate(LosTaskCB *taskCB)
|
||||
|
||||
STATIC INLINE VOID OsTaskSyncDestroy(UINT32 syncSignal)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
|
||||
(VOID)LOS_SemDelete(syncSignal);
|
||||
#else
|
||||
(VOID)syncSignal;
|
||||
@@ -403,7 +403,7 @@ STATIC INLINE VOID OsTaskSyncDestroy(UINT32 syncSignal)
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 OsTaskSyncWait(const LosTaskCB *taskCB)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
|
||||
UINT32 ret = LOS_OK;
|
||||
|
||||
LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
|
||||
@@ -428,7 +428,7 @@ LITE_OS_SEC_TEXT UINT32 OsTaskSyncWait(const LosTaskCB *taskCB)
|
||||
|
||||
STATIC INLINE VOID OsTaskSyncWake(const LosTaskCB *taskCB)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
|
||||
(VOID)OsSemPostUnsafe(taskCB->syncSignal, NULL);
|
||||
#else
|
||||
(VOID)taskCB;
|
||||
@@ -485,7 +485,7 @@ LITE_OS_SEC_TEXT VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
|
||||
processCB->processID, taskCB->taskID, mapBase, mapSize, ret);
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
LiteIpcRemoveServiceHandle(taskCB);
|
||||
#endif
|
||||
}
|
||||
@@ -494,7 +494,7 @@ LITE_OS_SEC_TEXT VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
|
||||
topOfStack = taskCB->topOfStack;
|
||||
taskCB->topOfStack = 0;
|
||||
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
|
||||
syncSignal = taskCB->syncSignal;
|
||||
taskCB->syncSignal = LOSCFG_BASE_IPC_SEM_LIMIT;
|
||||
#endif
|
||||
@@ -523,12 +523,12 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
|
||||
taskCB->taskEntry = initParam->pfnTaskEntry;
|
||||
taskCB->signal = SIGNAL_NONE;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
taskCB->currCpu = OS_TASK_INVALID_CPUID;
|
||||
taskCB->cpuAffiMask = (initParam->usCpuAffiMask) ?
|
||||
initParam->usCpuAffiMask : LOSCFG_KERNEL_CPU_MASK;
|
||||
#endif
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
LOS_ListInit(&(taskCB->msgListHead));
|
||||
#endif
|
||||
taskCB->policy = (initParam->policy == LOS_SCHED_FIFO) ? LOS_SCHED_FIFO : LOS_SCHED_RR;
|
||||
@@ -654,7 +654,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S
|
||||
LOS_ERREND_TCB_INIT:
|
||||
(VOID)LOS_MemFree(pool, topStack);
|
||||
LOS_ERREND_REWIND_SYNC:
|
||||
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
|
||||
OsTaskSyncDestroy(taskCB->syncSignal);
|
||||
#endif
|
||||
LOS_ERREND_REWIND_TCB:
|
||||
@@ -769,7 +769,7 @@ LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UIN
|
||||
/* init default out return value */
|
||||
*ret = LOS_OK;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/* ASYNCHRONIZED. No need to do task lock checking */
|
||||
if (taskCB->currCpu != ArchCurrCpuid()) {
|
||||
taskCB->signal = SIGNAL_SUSPEND;
|
||||
@@ -909,7 +909,7 @@ STATIC BOOL OsRunTaskToDeleteCheckOnRun(LosTaskCB *taskCB, UINT32 *ret)
|
||||
/* init default out return value */
|
||||
*ret = LOS_OK;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/* ASYNCHRONIZED. No need to do task lock checking */
|
||||
if (taskCB->currCpu != ArchCurrCpuid()) {
|
||||
/*
|
||||
@@ -994,7 +994,7 @@ LITE_OS_SEC_TEXT UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UIN
|
||||
SCHEDULER_LOCK(intSave);
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 1);
|
||||
#else
|
||||
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 0);
|
||||
@@ -1235,7 +1235,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInf
|
||||
|
||||
LITE_OS_SEC_TEXT BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMask, UINT16 *oldCpuAffiMask)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
|
||||
taskCB->cpuAffiMask = newCpuAffiMask;
|
||||
@@ -1286,7 +1286,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMa
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskID)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#define INVALID_CPU_AFFI_MASK 0
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT16 cpuAffiMask;
|
||||
@@ -1346,7 +1346,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsTaskProcSignal(VOID)
|
||||
|
||||
/* suspend killed task may fail, ignore the result */
|
||||
(VOID)LOS_TaskSuspend(runTask->taskID);
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
} else if (runTask->signal & SIGNAL_AFFI) {
|
||||
runTask->signal &= ~SIGNAL_AFFI;
|
||||
|
||||
@@ -1406,13 +1406,14 @@ STATIC VOID OsExitGroupActiveTaskKilled(LosProcessCB *processCB, LosTaskCB *task
|
||||
INT32 ret;
|
||||
|
||||
taskCB->taskStatus |= OS_TASK_FLAG_EXIT_KILL;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/* The other core that the thread is running on and is currently running in a non-system call */
|
||||
if (!taskCB->sig.sigIntLock && (taskCB->taskStatus & OS_TASK_STATUS_RUNNING)) {
|
||||
taskCB->signal = SIGNAL_KILL;
|
||||
LOS_MpSchedule(taskCB->currCpu);
|
||||
} else
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
{
|
||||
ret = OsTaskKillUnsafe(taskCB->taskID, SIGKILL);
|
||||
if (ret != LOS_OK) {
|
||||
@@ -1420,6 +1421,7 @@ STATIC VOID OsExitGroupActiveTaskKilled(LosProcessCB *processCB, LosTaskCB *task
|
||||
taskCB->processID, OsCurrTaskGet()->taskID, taskCB->taskID, ret);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(taskCB->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN)) {
|
||||
taskCB->taskStatus |= OS_TASK_FLAG_PTHREAD_JOIN;
|
||||
|
||||
@@ -57,7 +57,7 @@ LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
|
||||
OsVdsoTimevalUpdate();
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TICK_HW_TIME == YES)
|
||||
#ifdef LOSCFG_BASE_CORE_TICK_HW_TIME
|
||||
HalClockIrqClear(); /* diff from every platform */
|
||||
#endif
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
typedef enum {
|
||||
CPU_RUNNING = 0, /* cpu is running */
|
||||
CPU_HALT, /* cpu in the halt */
|
||||
@@ -66,7 +66,7 @@ typedef struct {
|
||||
UINT32 swtmrTaskID; /* software timer task id */
|
||||
|
||||
UINT32 schedFlag; /* pending scheduler flag */
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT32 excFlag; /* cpu halt or exc flag */
|
||||
#endif
|
||||
} Percpu;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "los_sem_pri.h"
|
||||
#include "los_process.h"
|
||||
#include "los_vm_map.h"
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
#include "hm_liteipc.h"
|
||||
#endif
|
||||
#ifdef LOSCFG_SECURITY_CAPABILITY
|
||||
@@ -96,12 +96,12 @@ typedef struct ProcessCB {
|
||||
volatile UINT32 threadNumber; /**< Number of threads alive under this process */
|
||||
UINT32 threadCount; /**< Total number of threads created under this process */
|
||||
LOS_DL_LIST waitList; /**< The process holds the waitLits to support wait/waitpid */
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT32 timerCpu; /**< CPU core number of this task is delayed or pended */
|
||||
#endif
|
||||
UINTPTR sigHandler; /**< Signal handler */
|
||||
sigset_t sigShare; /**< Signal share bit */
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
ProcIpcInfo ipcInfo; /**< Memory pool for lite ipc */
|
||||
#endif
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
|
||||
@@ -112,7 +112,7 @@ STATIC INLINE BOOL OsPreemptableInSched(VOID)
|
||||
{
|
||||
BOOL preemptable = FALSE;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/*
|
||||
* For smp systems, schedule must hold the task spinlock, and this counter
|
||||
* will increase by 1 in that case.
|
||||
|
||||
@@ -50,7 +50,7 @@ typedef enum {
|
||||
typedef struct {
|
||||
LOS_DL_LIST sortLinkNode;
|
||||
UINT64 responseTime;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT32 cpuid;
|
||||
#endif
|
||||
} SortLinkList;
|
||||
|
||||
@@ -45,7 +45,9 @@
|
||||
#include "los_cpup_pri.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_TRACE
|
||||
#include "los_trace.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
@@ -344,14 +346,14 @@ typedef struct {
|
||||
INT32 errorNo; /**< Error Num */
|
||||
UINT32 signal; /**< Task signal */
|
||||
sig_cb sig;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT16 currCpu; /**< CPU core number of this task is running on */
|
||||
UINT16 lastCpu; /**< CPU core number of this task is running on last time */
|
||||
UINT16 cpuAffiMask; /**< CPU affinity mask, support up to 16 cores */
|
||||
#if (LOSCFG_KERNEL_SMP_TASK_SYNC == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
|
||||
UINT32 syncSignal; /**< Synchronization for signal handling */
|
||||
#endif
|
||||
#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
|
||||
LockDep lockDep;
|
||||
#endif
|
||||
#endif
|
||||
@@ -368,7 +370,7 @@ typedef struct {
|
||||
UINTPTR waitID; /**< Wait for the PID or GID of the child process */
|
||||
UINT16 waitFlag; /**< The type of child process that is waiting, belonging to a group or parent,
|
||||
a specific child process, or any child process */
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
UINT32 ipcStatus;
|
||||
LOS_DL_LIST msgListHead;
|
||||
BOOL accessMap[LOSCFG_BASE_CORE_TSK_LIMIT];
|
||||
|
||||
@@ -206,6 +206,10 @@ VOID OsMarkPageDirty(LosFilePage *fpage, LosVmMapRegion *region, int off, int le
|
||||
|
||||
typedef struct ProcessCB LosProcessCB;
|
||||
VOID OsVmmFileRegionFree(struct file *filep, LosProcessCB *processCB);
|
||||
#ifdef LOSCFG_DEBUG_VERSION
|
||||
VOID ResetPageCacheHitInfo(int *try, int *hit);
|
||||
struct file_map* GetFileMappingList(void);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "los_mp.h"
|
||||
#include "los_percpu_pri.h"
|
||||
#include "los_sched_pri.h"
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == YES)
|
||||
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
|
||||
#include "los_exc.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "los_sched_pri.h"
|
||||
|
||||
|
||||
#if (LOSCFG_BASE_IPC_MUX == YES)
|
||||
#ifdef LOSCFG_BASE_IPC_MUX
|
||||
#define MUTEXATTR_TYPE_MASK 0x0FU
|
||||
|
||||
LITE_OS_SEC_TEXT UINT32 LOS_MuxAttrInit(LosMuxAttr *attr)
|
||||
@@ -560,5 +560,5 @@ LITE_OS_SEC_TEXT UINT32 LOS_MuxUnlock(LosMux *mutex)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_IPC_MUX == YES) */
|
||||
#endif /* LOSCFG_BASE_IPC_MUX */
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "los_percpu_pri.h"
|
||||
|
||||
|
||||
#if (LOSCFG_BASE_IPC_QUEUE == YES)
|
||||
#ifdef LOSCFG_BASE_IPC_QUEUE
|
||||
#if (LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0)
|
||||
#error "queue maxnum cannot be zero"
|
||||
#endif /* LOSCFG_BASE_IPC_QUEUE_LIMIT <= 0 */
|
||||
@@ -493,5 +493,5 @@ QUEUE_END:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* (LOSCFG_BASE_IPC_QUEUE == YES) */
|
||||
#endif /* LOSCFG_BASE_IPC_QUEUE */
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include "los_percpu_pri.h"
|
||||
|
||||
|
||||
#if (LOSCFG_BASE_IPC_SEM == YES)
|
||||
#ifdef LOSCFG_BASE_IPC_SEM
|
||||
|
||||
#if (LOSCFG_BASE_IPC_SEM_LIMIT <= 0)
|
||||
#error "sem maxnum cannot be zero"
|
||||
@@ -283,5 +283,5 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* (LOSCFG_BASE_IPC_SEM == YES) */
|
||||
#endif /* LOSCFG_BASE_IPC_SEM */
|
||||
|
||||
|
||||
@@ -101,11 +101,13 @@ STATIC UINT32 OsPendingTaskWake(LosTaskCB *taskCB, INT32 signo)
|
||||
case OS_TASK_WAIT_SIGNAL:
|
||||
OsSigWaitTaskWake(taskCB, signo);
|
||||
break;
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
case OS_TASK_WAIT_LITEIPC:
|
||||
taskCB->ipcStatus &= ~IPC_THREAD_STATUS_PEND;
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
OsSchedTaskWake(taskCB);
|
||||
break;
|
||||
#endif
|
||||
case OS_TASK_WAIT_FUTEX:
|
||||
OsFutexNodeDeleteFromFutexHash(&taskCB->futex, TRUE, NULL, NULL);
|
||||
OsTaskWakeClearPendMask(taskCB);
|
||||
@@ -132,7 +134,7 @@ int OsTcbDispatch(LosTaskCB *stcb, siginfo_t *info)
|
||||
if (masked) {
|
||||
/* If signal is in wait list and mask list, need unblock it */
|
||||
if (LOS_ListEmpty(&sigcb->waitList) ||
|
||||
(!LOS_ListEmpty(&sigcb->waitList) && !OsSigIsMember(&sigcb->sigwaitmask, info->si_signo))) {
|
||||
(!LOS_ListEmpty(&sigcb->waitList) && !OsSigIsMember(&sigcb->sigwaitmask, info->si_signo))) {
|
||||
OsSigAddSet(&sigcb->sigPendFlag, info->si_signo);
|
||||
}
|
||||
} else {
|
||||
@@ -308,7 +310,7 @@ int OsSigProcessSend(LosProcessCB *spcb, siginfo_t *sigInfo)
|
||||
.receivedTcb = NULL
|
||||
};
|
||||
|
||||
if (info.sigInfo == NULL){
|
||||
if (info.sigInfo == NULL) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ struct OsMemPoolInfo {
|
||||
VOID *pool;
|
||||
UINT32 totalSize;
|
||||
UINT32 attr;
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
UINT32 waterLine; /* Maximum usage size in a memory pool */
|
||||
UINT32 curUsedSize; /* Current usage size in a memory pool */
|
||||
#endif
|
||||
@@ -230,7 +230,7 @@ STATIC INLINE VOID OsMemNodeSetTaskID(struct OsMemUsedNodeHead *node)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
STATIC INLINE VOID OsMemWaterUsedRecord(struct OsMemPoolHead *pool, UINT32 size)
|
||||
{
|
||||
pool->info.curUsedSize += size;
|
||||
@@ -775,7 +775,7 @@ STATIC UINT32 OsMemPoolInit(VOID *pool, UINT32 size)
|
||||
endNode->ptr.prev = newNode;
|
||||
OS_MEM_NODE_SET_USED_FLAG(endNode->sizeAndFlag);
|
||||
#endif
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
poolHead->info.curUsedSize = sizeof(struct OsMemPoolHead) + OS_MEM_NODE_HEAD_SIZE;
|
||||
poolHead->info.waterLine = poolHead->info.curUsedSize;
|
||||
#endif
|
||||
@@ -1171,7 +1171,7 @@ STATIC INLINE UINT32 OsMemFree(struct OsMemPoolHead *pool, struct OsMemNodeHead
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
pool->info.curUsedSize -= OS_MEM_NODE_GET_SIZE(node->sizeAndFlag);
|
||||
#endif
|
||||
|
||||
@@ -1256,14 +1256,14 @@ UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
|
||||
|
||||
STATIC INLINE VOID OsMemReAllocSmaller(VOID *pool, UINT32 allocSize, struct OsMemNodeHead *node, UINT32 nodeSize)
|
||||
{
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
struct OsMemPoolHead *poolInfo = (struct OsMemPoolHead *)pool;
|
||||
#endif
|
||||
node->sizeAndFlag = nodeSize;
|
||||
if ((allocSize + OS_MEM_NODE_HEAD_SIZE + OS_MEM_MIN_ALLOC_SIZE) <= nodeSize) {
|
||||
OsMemSplitNode(pool, node, allocSize);
|
||||
OS_MEM_NODE_SET_USED_FLAG(node->sizeAndFlag);
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
poolInfo->info.curUsedSize -= nodeSize - allocSize;
|
||||
#endif
|
||||
}
|
||||
@@ -1595,13 +1595,15 @@ STATIC VOID OsMemPoolHeadCheck(const struct OsMemPoolHead *pool)
|
||||
flag = 1;
|
||||
PRINT_ERR("FreeListIndex: %u, node: %#x, bNode: %#x, prev: %#x, next: %#x\n",
|
||||
index, tmpNode, tmpNode->header.ptr.prev, tmpNode->prev, tmpNode->next);
|
||||
goto OUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OUT:
|
||||
if (flag) {
|
||||
PRINTK("mem pool info: poolAddr: %#x, poolSize: 0x%x\n", pool, pool->info.totalSize);
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
PRINTK("mem pool info: poolWaterLine: 0x%x, poolCurUsedSize: 0x%x\n", pool->info.waterLine,
|
||||
pool->info.curUsedSize);
|
||||
#endif
|
||||
@@ -1842,7 +1844,7 @@ UINT32 LOS_MemInfoGet(VOID *pool, LOS_MEM_POOL_STATUS *poolStatus)
|
||||
OsMemInfoGet(poolInfo, tmpNode, poolStatus);
|
||||
}
|
||||
#endif
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
poolStatus->usageWaterLine = poolInfo->info.waterLine;
|
||||
#endif
|
||||
MEM_UNLOCK(poolInfo, intSave);
|
||||
@@ -1859,7 +1861,7 @@ STATIC VOID OsMemInfoPrint(VOID *pool)
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(OS_MEM_WATERLINE) && (OS_MEM_WATERLINE == YES)
|
||||
#ifdef LOSCFG_MEM_WATERLINE
|
||||
PRINTK("pool addr pool size used size free size "
|
||||
"max free node size used node num free node num UsageWaterLine\n");
|
||||
PRINTK("--------------- -------- ------- -------- "
|
||||
|
||||
@@ -119,9 +119,21 @@ UINT32 OsShellCmdSwtmrCntGet(VOID)
|
||||
LITE_OS_SEC_TEXT_MINOR VOID OsShellCmdSystemInfoGet(VOID)
|
||||
{
|
||||
UINT8 isTaskEnable = YES;
|
||||
UINT8 isSemEnable = LOSCFG_BASE_IPC_SEM;
|
||||
UINT8 isQueueEnable = LOSCFG_BASE_IPC_QUEUE;
|
||||
UINT8 isSwtmrEnable = LOSCFG_BASE_CORE_SWTMR;
|
||||
#ifdef LOSCFG_BASE_IPC_SEM
|
||||
UINT8 isSemEnable = YES;
|
||||
#else
|
||||
UINT8 isSemEnable = NO;
|
||||
#endif
|
||||
#ifdef LOSCFG_BASE_IPC_QUEUE
|
||||
UINT8 isQueueEnable = YES;
|
||||
#else
|
||||
UINT8 isQueueEnable = NO;
|
||||
#endif
|
||||
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
|
||||
UINT8 isSwtmrEnable = YES;
|
||||
#else
|
||||
UINT8 isSwtmrEnable = NO;
|
||||
#endif
|
||||
|
||||
PRINTK("\n Module Used Total Enabled\n");
|
||||
PRINTK("--------------------------------------------\n");
|
||||
|
||||
@@ -85,12 +85,18 @@ STATIC UINT32 *taskWaterLine = NULL;
|
||||
#define OS_TASK_ALL_INFO_LEN (g_taskMaxNum * (sizeof(LosTaskCB) + sizeof(UINT32)))
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#if defined(LOSCFG_BLACKBOX) && defined(LOSCFG_SAVE_EXCINFO)
|
||||
#define SaveExcInfo(arg, ...) WriteExcInfoToBuf(arg, ##__VA_ARGS__)
|
||||
#else
|
||||
#define SaveExcInfo(arg, ...)
|
||||
#endif
|
||||
#define PROCESS_INFO_SHOW(seqBuf, arg...) do { \
|
||||
if (seqBuf != NULL) { \
|
||||
(void)LosBufPrintf((struct SeqBuf *)seqBuf, ##arg); \
|
||||
} else { \
|
||||
PRINTK(arg); \
|
||||
} \
|
||||
SaveExcInfo(arg); \
|
||||
} while (0)
|
||||
#else
|
||||
#define PROCESS_INFO_SHOW(seqBuf, arg...) PRINTK(arg)
|
||||
@@ -428,7 +434,7 @@ EXIT:
|
||||
STATIC VOID OsShellCmdTskInfoTitle(VOID *seqBuf, UINT16 flag)
|
||||
{
|
||||
PROCESS_INFO_SHOW(seqBuf, "\r\n TID PID ");
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
PROCESS_INFO_SHOW(seqBuf, "Affi CPU ");
|
||||
#endif
|
||||
PROCESS_INFO_SHOW(seqBuf, " Status StackSize WaterLine ");
|
||||
@@ -456,7 +462,7 @@ STATIC INLINE VOID OsShellTskInfoData(const LosTaskCB *taskCB, VOID *seqBuf, UIN
|
||||
#endif
|
||||
PROCESS_INFO_SHOW(seqBuf, " %4u%5u", taskCB->taskID, taskCB->processID);
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
PROCESS_INFO_SHOW(seqBuf, "%#5x%4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
|
||||
#endif
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "los_exc.h"
|
||||
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP_LOCKDEP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
|
||||
|
||||
#define LOCKDEP_GET_NAME(lockDep, index) (((SPIN_LOCK_S *)((lockDep)->heldLocks[(index)].lockPtr))->name)
|
||||
#define LOCKDEP_GET_ADDR(lockDep, index) ((lockDep)->heldLocks[(index)].lockAddr)
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "los_swtmr.h"
|
||||
#include "los_task_pri.h"
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
|
||||
VOID LOS_MpSchedule(UINT32 target)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
*/
|
||||
|
||||
#include "los_spinlock.h"
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#include "los_sched_pri.h"
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "los_task_pri.h"
|
||||
|
||||
|
||||
#if (LOSCFG_KERNEL_SCHED_STATISTICS == YES)
|
||||
#ifdef LOSCFG_KERNEL_SCHED_STATISTICS
|
||||
#define HIGHTASKPRI 16
|
||||
#define NS_PER_MS 1000000
|
||||
#define DECIMAL_TO_PERCENTAGE 100
|
||||
@@ -212,7 +212,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsShellMpStaticStart(VOID)
|
||||
for (loop = 0; loop < g_taskMaxNum; loop++) {
|
||||
taskCB = (((LosTaskCB *)g_taskCBArray) + loop);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
cpuid = taskCB->currCpu;
|
||||
#endif
|
||||
if ((UINT32)(OS_TASK_INVALID_CPUID) == cpuid) {
|
||||
@@ -293,7 +293,7 @@ LITE_OS_SEC_TEXT_MINOR VOID OsShellMpStaticStop(VOID)
|
||||
for (loop = 0; loop < g_taskMaxNum; loop++) {
|
||||
taskCB = (((LosTaskCB *)g_taskCBArray) + loop);
|
||||
if (taskCB->taskStatus & OS_TASK_STATUS_RUNNING) {
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
cpuid = taskCB->currCpu;
|
||||
#endif
|
||||
if (cpuid == (UINT32)(OS_TASK_INVALID_CPUID)) {
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#endif
|
||||
#include "los_hw_tick_pri.h"
|
||||
#include "los_tick_pri.h"
|
||||
#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
|
||||
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
|
||||
#include "los_stackinfo_pri.h"
|
||||
#endif
|
||||
#include "los_mp.h"
|
||||
@@ -443,7 +443,7 @@ STATIC INLINE VOID OsSchedWakePendTimeTask(UINT64 currTime, LosTaskCB *taskCB, B
|
||||
if (tempStatus & (OS_TASK_STATUS_PENDING | OS_TASK_STATUS_DELAY)) {
|
||||
taskCB->taskStatus &= ~(OS_TASK_STATUS_PENDING | OS_TASK_STATUS_PEND_TIME | OS_TASK_STATUS_DELAY);
|
||||
if (tempStatus & OS_TASK_STATUS_PENDING) {
|
||||
#if (LOSCFG_KERNEL_LITEIPC == YES)
|
||||
#ifdef LOSCFG_KERNEL_LITEIPC
|
||||
taskCB->ipcStatus &= ~IPC_THREAD_STATUS_PEND;
|
||||
#endif
|
||||
taskCB->taskStatus |= OS_TASK_STATUS_TIMEOUT;
|
||||
@@ -819,7 +819,7 @@ STATIC LosTaskCB *OsGetTopTask(VOID)
|
||||
UINT32 bitmap;
|
||||
LosTaskCB *newTask = NULL;
|
||||
UINT32 processBitmap = g_sched->queueBitmap;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
UINT32 cpuid = ArchCurrCpuid();
|
||||
#endif
|
||||
|
||||
@@ -830,11 +830,11 @@ STATIC LosTaskCB *OsGetTopTask(VOID)
|
||||
while (bitmap) {
|
||||
priority = CLZ(bitmap);
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(newTask, &queueList->priQueueList[priority], LosTaskCB, pendList) {
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
if (newTask->cpuAffiMask & (1U << cpuid)) {
|
||||
#endif
|
||||
goto FIND_TASK;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -869,7 +869,7 @@ VOID OsSchedStart(VOID)
|
||||
OsSchedSetStartTime(HalClockGetCycles());
|
||||
newTask->startTime = OsGerCurrSchedTimeCycle();
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/*
|
||||
* attention: current cpu needs to be set, in case first task deletion
|
||||
* may fail because this flag mismatch with the real current cpu.
|
||||
@@ -889,7 +889,7 @@ VOID OsSchedStart(VOID)
|
||||
OsTaskContextLoad(newTask);
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
VOID OsSchedToUserReleaseLock(VOID)
|
||||
{
|
||||
/* The scheduling lock needs to be released before returning to user mode */
|
||||
@@ -900,7 +900,7 @@ VOID OsSchedToUserReleaseLock(VOID)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
|
||||
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
|
||||
STATIC VOID OsTaskStackCheck(LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
{
|
||||
if (!OS_STACK_MAGIC_CHECK(runTask->topOfStack)) {
|
||||
@@ -917,9 +917,9 @@ STATIC VOID OsTaskStackCheck(LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
|
||||
STATIC INLINE VOID OsSchedSwitchCheck(LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
{
|
||||
#if (LOSCFG_BASE_CORE_TSK_MONITOR == YES)
|
||||
#ifdef LOSCFG_BASE_CORE_TSK_MONITOR
|
||||
OsTaskStackCheck(runTask, newTask);
|
||||
#endif /* LOSCFG_BASE_CORE_TSK_MONITOR == YES */
|
||||
#endif /* LOSCFG_BASE_CORE_TSK_MONITOR */
|
||||
|
||||
OsTraceTaskSchedule(newTask, runTask);
|
||||
}
|
||||
@@ -955,7 +955,7 @@ STATIC VOID OsSchedTaskSwicth(LosTaskCB *runTask, LosTaskCB *newTask)
|
||||
runTask->taskStatus &= ~OS_TASK_STATUS_RUNNING;
|
||||
newTask->taskStatus |= OS_TASK_STATUS_RUNNING;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
/* mask new running task's owner processor */
|
||||
runTask->currCpu = OS_TASK_INVALID_CPUID;
|
||||
newTask->currCpu = ArchCurrCpuid();
|
||||
@@ -1043,7 +1043,7 @@ VOID OsSchedIrqEndCheckNeedSched(VOID)
|
||||
VOID OsSchedResched(VOID)
|
||||
{
|
||||
LOS_ASSERT(LOS_SpinHeld(&g_taskSpin));
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 1);
|
||||
#else
|
||||
LOS_ASSERT(OsPercpuGet()->taskLockCnt == 0);
|
||||
|
||||
@@ -41,10 +41,30 @@
|
||||
#include "los_vm_fault.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "los_vm_lock.h"
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#include "vnode.h"
|
||||
#endif
|
||||
|
||||
#ifndef UNUSED
|
||||
#define UNUSED(x) (VOID)x
|
||||
#define UNUSED(x) (VOID)(x)
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_DEBUG_VERSION
|
||||
static int g_totalPageCacheTry = 0;
|
||||
static int g_totalPageCacheHit = 0;
|
||||
#define TRACE_TRY_CACHE() do { g_totalPageCacheTry++; } while (0)
|
||||
#define TRACE_HIT_CACHE() do { g_totalPageCacheHit++; } while (0)
|
||||
|
||||
VOID ResetPageCacheHitInfo(int *try, int *hit)
|
||||
{
|
||||
*try = g_totalPageCacheTry;
|
||||
*hit = g_totalPageCacheHit;
|
||||
g_totalPageCacheHit = 0;
|
||||
g_totalPageCacheTry = 0;
|
||||
}
|
||||
#else
|
||||
#define TRACE_TRY_CACHE()
|
||||
#define TRACE_HIT_CACHE()
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_VM
|
||||
@@ -365,7 +385,9 @@ INT32 OsVmmFileFault(LosVmMapRegion *region, LosVmPgFault *vmf)
|
||||
/* get or create a new cache node */
|
||||
LOS_SpinLockSave(&mapping->list_lock, &intSave);
|
||||
fpage = OsFindGetEntry(mapping, vmf->pgoff);
|
||||
TRACE_TRY_CACHE();
|
||||
if (fpage != NULL) {
|
||||
TRACE_HIT_CACHE();
|
||||
OsPageRefIncLocked(fpage);
|
||||
} else {
|
||||
fpage = OsPageCacheAlloc(mapping, vmf->pgoff);
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include "los_vm_zone.h"
|
||||
#include "los_vm_common.h"
|
||||
#include "los_vm_map.h"
|
||||
#include "los_vm_lock.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
|
||||
|
||||
@@ -1135,7 +1135,7 @@ DONE:
|
||||
|
||||
LosMux *OsGVmSpaceMuxGet(VOID)
|
||||
{
|
||||
return &g_vmSpaceListMux;
|
||||
return &g_vmSpaceListMux;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsMemLargeAlloc(UINT32 size)
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "los_vm_phys.h"
|
||||
#include "los_vm_filemap.h"
|
||||
#include "los_process_pri.h"
|
||||
#if (LOSCFG_BASE_CORE_SWTMR == YES)
|
||||
#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
|
||||
#include "los_swtmr_pri.h"
|
||||
#endif
|
||||
|
||||
@@ -55,12 +55,12 @@ LITE_OS_SEC_TEXT_MINOR STATIC UINT32 OomScoreProcess(LosProcessCB *candidateProc
|
||||
{
|
||||
UINT32 actualPm;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP != YES)
|
||||
#ifndef LOSCFG_KERNEL_SMP
|
||||
(VOID)LOS_MuxAcquire(&candidateProcess->vmSpace->regionMux);
|
||||
#endif
|
||||
/* we only consider actual physical memory here. */
|
||||
OsUProcessPmUsage(candidateProcess->vmSpace, NULL, &actualPm);
|
||||
#if (LOSCFG_KERNEL_SMP != YES)
|
||||
#ifndef LOSCFG_KERNEL_SMP
|
||||
(VOID)LOS_MuxRelease(&candidateProcess->vmSpace->regionMux);
|
||||
#endif
|
||||
return actualPm;
|
||||
|
||||
@@ -31,13 +31,13 @@ include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
MODULE_NAME := rootfs
|
||||
|
||||
LOCAL_SRCS := $(wildcard los_rootfs.c)
|
||||
LOCAL_SRCS := $(wildcard los_rootfs.c los_bootargs.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/kernel/common \
|
||||
|
||||
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
|
||||
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/arm_virt/config/cfiflash
|
||||
LOCAL_INCLUDE += -I $(LITEOSTOPDIR)/../../device/qemu/drivers/cfiflash
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
10
kernel/common/blackbox/Kconfig
Normal file
10
kernel/common/blackbox/Kconfig
Normal file
@@ -0,0 +1,10 @@
|
||||
config BLACKBOX
|
||||
bool "Enable BlackBox"
|
||||
default n
|
||||
help
|
||||
Answer Y to enable LiteOS support blackbox
|
||||
|
||||
config LOG_ROOT_PATH
|
||||
string "unknown"
|
||||
help
|
||||
define the default log path of blackbox
|
||||
14
kernel/common/blackbox/Makefile
Normal file
14
kernel/common/blackbox/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
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
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
include $(MODULE)
|
||||
91
kernel/common/blackbox/los_blackbox.h
Normal file
91
kernel/common/blackbox/los_blackbox.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "stdarg.h"
|
||||
#include "los_typedef.h"
|
||||
|
||||
#define PATH_MAX_LEN 256
|
||||
#define EVENT_MAX_LEN 32
|
||||
#define MODULE_MAX_LEN 32
|
||||
#define ERROR_DESC_MAX_LEN 512
|
||||
#ifndef LOSCFG_LOG_ROOT_PATH
|
||||
#define LOSCFG_LOG_ROOT_PATH "/storage/data/log"
|
||||
#endif
|
||||
#define KERNEL_FAULT_LOG_PATH LOSCFG_LOG_ROOT_PATH "/kernel_fault.log"
|
||||
#define USER_FAULT_LOG_PATH LOSCFG_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
|
||||
127
kernel/common/blackbox/los_blackbox_common.c
Normal file
127
kernel/common/blackbox/los_blackbox_common.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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"
|
||||
#endif
|
||||
#include "securec.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
/* ------------ local macroes ------------ */
|
||||
/* ------------ local prototypes ------------ */
|
||||
/* ------------ local function declarations ------------ */
|
||||
/* ------------ global function declarations ------------ */
|
||||
/* ------------ local variables ------------ */
|
||||
/* ------------ 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_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)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, 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);
|
||||
(void)snprintf_s(buf, ERROR_INFO_MAX_LEN, ERROR_INFO_MAX_LEN - 1,
|
||||
ERROR_INFO_HEADER_FORMAT, info->event, info->module, info->errorDesc);
|
||||
*(buf + ERROR_INFO_MAX_LEN - 1) = '\0';
|
||||
(void)FullWriteFile(filePath, buf, strlen(buf), 0);
|
||||
(void)LOS_MemFree(m_aucSysMem1, buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
bool IsLogPartReady(void)
|
||||
{
|
||||
return access(LOSCFG_LOG_ROOT_PATH, W_OK) == 0;
|
||||
}
|
||||
#else
|
||||
bool IsLogPartReady(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
61
kernel/common/blackbox/los_blackbox_common.h
Normal file
61
kernel/common/blackbox/los_blackbox_common.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "los_blackbox.h"
|
||||
#include "los_printf.h"
|
||||
#include "los_typedef.h"
|
||||
|
||||
#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, struct ErrorInfo *info);
|
||||
bool IsLogPartReady(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
458
kernel/common/blackbox/los_blackbox_core.c
Normal file
458
kernel/common/blackbox/los_blackbox_core.c
Normal file
@@ -0,0 +1,458 @@
|
||||
/*
|
||||
* 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));
|
||||
(void)strncpy_s(info->event, sizeof(info->event), event, Min(strlen(event), sizeof(info->event) - 1));
|
||||
(void)strncpy_s(info->module, sizeof(info->module), module, Min(strlen(module), sizeof(info->module) - 1));
|
||||
(void)strncpy_s(info->errorDesc, sizeof(info->errorDesc), errorDesc,
|
||||
Min(strlen(errorDesc), sizeof(info->errorDesc) - 1));
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
static void WaitForLogPart(void)
|
||||
{
|
||||
BBOX_PRINT_INFO("wait for log part [%s] begin!\n", LOSCFG_LOG_ROOT_PATH);
|
||||
while (!IsLogPartReady()) {
|
||||
LOS_Msleep(LOG_PART_WAIT_TIME);
|
||||
}
|
||||
BBOX_PRINT_INFO("wait for log part [%s] end!\n", LOSCFG_LOG_ROOT_PATH);
|
||||
}
|
||||
#else
|
||||
static void WaitForLogPart(void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
BBOX_PRINT_INFO("wait for log part [%s] begin!\n", LOSCFG_LOG_ROOT_PATH);
|
||||
while (i++ < LOG_WAIT_TIMES) {
|
||||
LOS_Msleep(LOG_PART_WAIT_TIME);
|
||||
}
|
||||
BBOX_PRINT_INFO("wait for log part [%s] end!\n", LOSCFG_LOG_ROOT_PATH);
|
||||
}
|
||||
#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, 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_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;
|
||||
}
|
||||
|
||||
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 (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));
|
||||
(void)memcpy_s(&newOps->ops, sizeof(newOps->ops), ops, sizeof(*ops));
|
||||
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_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);
|
||||
63
kernel/common/blackbox/los_blackbox_detector.c
Normal file
63
kernel/common/blackbox/los_blackbox_detector.c
Normal 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;
|
||||
}
|
||||
51
kernel/common/blackbox/los_blackbox_detector.h
Normal file
51
kernel/common/blackbox/los_blackbox_detector.h
Normal 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
int UploadEventByFile(const char *filePath);
|
||||
int UploadEventByStream(const char *buf, size_t bufSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
265
kernel/common/blackbox/los_blackbox_system_adapter.c
Normal file
265
kernel/common/blackbox/los_blackbox_system_adapter.c
Normal 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_phys.h"
|
||||
#include "los_vm_common.h"
|
||||
#include "securec.h"
|
||||
|
||||
/* ------------ local macroes ------------ */
|
||||
#define MEM_OVERLAP_COUNT 50
|
||||
#define LOG_FLAG "GOODLOG"
|
||||
#define FAULT_LOG_SIZE 0x4000 /* 16KB */
|
||||
|
||||
/* ------------ 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, FAULT_LOG_SIZE - sizeof(struct FaultLogInfo),
|
||||
g_logBuffer + sizeof(struct FaultLogInfo), WriteExcFile);
|
||||
#endif
|
||||
} else {
|
||||
BBOX_PRINT_ERR("Alloc mem failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
static int AllocLogBuffer(void)
|
||||
{
|
||||
int i = 0;
|
||||
size_t nPages = ROUNDUP(FAULT_LOG_SIZE, PAGE_SIZE) >> PAGE_SHIFT;
|
||||
void *tempBuffer[MEM_OVERLAP_COUNT] = { NULL };
|
||||
|
||||
for (i = 0; i < MEM_OVERLAP_COUNT; i++) {
|
||||
tempBuffer[i] = LOS_PhysPagesAllocContiguous(nPages);
|
||||
}
|
||||
for (i = 0; i < (MEM_OVERLAP_COUNT - 1); i++) {
|
||||
LOS_PhysPagesFreeContiguous(tempBuffer[i], nPages);
|
||||
}
|
||||
g_logBuffer = tempBuffer[i];
|
||||
BBOX_PRINT_INFO("g_logBuffer: %p for blackbox!\n", g_logBuffer);
|
||||
|
||||
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 + FAULT_LOG_SIZE));
|
||||
} else {
|
||||
#ifdef LOSCFG_SAVE_EXCINFO
|
||||
SaveFaultLog(USER_FAULT_LOG_PATH, g_logBuffer + sizeof(struct FaultLogInfo),
|
||||
Min(FAULT_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(FAULT_LOG_SIZE - sizeof(*pLogInfo), pLogInfo->len), info);
|
||||
}
|
||||
(void)memset_s(g_logBuffer, FAULT_LOG_SIZE, 0, FAULT_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");
|
||||
LOS_PhysPagesFreeContiguous(g_logBuffer, ROUNDUP(FAULT_LOG_SIZE, PAGE_SIZE) >> PAGE_SHIFT);
|
||||
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);
|
||||
51
kernel/common/blackbox/los_blackbox_system_adapter.h
Normal file
51
kernel/common/blackbox/los_blackbox_system_adapter.h
Normal 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "los_blackbox.h"
|
||||
#include "los_blackbox_common.h"
|
||||
|
||||
int OsBBoxSystemAdapterInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -437,10 +437,10 @@ STATIC VOID StoreReadChar(CONSOLE_CB *consoleCB, char ch, INT32 readcount)
|
||||
|
||||
VOID KillPgrp()
|
||||
{
|
||||
INT32 consoleId = -1;
|
||||
INT32 consoleId;
|
||||
LosProcessCB *process = OsCurrProcessGet();
|
||||
|
||||
if ((process->consoleID > CONSOLE_NUM -1 ) || (process->consoleID < 0)) {
|
||||
if ((process->consoleID > CONSOLE_NUM - 1) || (process->consoleID < 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -872,7 +872,7 @@ STATIC INT32 ConsoleGetTermios(unsigned long arg)
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if(LOS_ArchCopyToUser((VOID *)arg, &consoleCB->consoleTermios, sizeof(struct termios)) != 0) {
|
||||
if (LOS_ArchCopyToUser((VOID *)arg, &consoleCB->consoleTermios, sizeof(struct termios)) != 0) {
|
||||
return -EFAULT;
|
||||
} else {
|
||||
return LOS_OK;
|
||||
@@ -1662,7 +1662,7 @@ STATIC UINT32 ConsoleSendTask(UINTPTR param)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
VOID OsWaitConsoleSendTaskPend(UINT32 taskID)
|
||||
{
|
||||
UINT32 i;
|
||||
|
||||
@@ -120,7 +120,7 @@ extern INT32 FilepWrite(struct file *filep, const struct file_operations_vfs *fo
|
||||
extern INT32 FilepPoll(struct file *filep, const struct file_operations_vfs *fops, poll_table *fds);
|
||||
extern INT32 FilepIoctl(struct file *filep, const struct file_operations_vfs *fops, INT32 cmd, unsigned long arg);
|
||||
extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, const struct file_operations_vfs **fops);
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
extern VOID OsWaitConsoleSendTaskPend(UINT32 taskID);
|
||||
extern VOID OsWakeConsoleSendTask(VOID);
|
||||
#endif
|
||||
|
||||
5
kernel/common/hidumper/Kconfig
Normal file
5
kernel/common/hidumper/Kconfig
Normal file
@@ -0,0 +1,5 @@
|
||||
config HIDUMPER
|
||||
bool "Enable hidumper"
|
||||
default n
|
||||
help
|
||||
Answer Y to enable LiteOS support hidumper
|
||||
13
kernel/common/hidumper/Makefile
Normal file
13
kernel/common/hidumper/Makefile
Normal 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)
|
||||
381
kernel/common/hidumper/los_hidumper.c
Normal file
381
kernel/common/hidumper/los_hidumper.c
Normal 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);
|
||||
88
kernel/common/hidumper/los_hidumper.h
Normal file
88
kernel/common/hidumper/los_hidumper.h
Normal 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
|
||||
245
kernel/common/los_bootargs.c
Normal file
245
kernel/common/los_bootargs.c
Normal file
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* 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_bootargs.h"
|
||||
#include "los_base.h"
|
||||
#include "string.h"
|
||||
|
||||
#if defined(LOSCFG_STORAGE_SPINOR) || defined(LOSCFG_STORAGE_SPINAND) || defined(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7)
|
||||
#include "mtd_list.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
#include "cfiflash.h"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_STORAGE_EMMC
|
||||
#include "disk.h"
|
||||
#endif
|
||||
|
||||
STATIC CHAR *g_cmdLine = NULL;
|
||||
STATIC UINT64 g_alignSize = 0;
|
||||
STATIC struct BootArgs g_bootArgs[MAX_ARGS_NUM] = {0};
|
||||
|
||||
INT32 LOS_GetCmdLine() {
|
||||
int ret = 0;
|
||||
|
||||
g_cmdLine = (CHAR *)malloc(COMMAND_LINE_SIZE);
|
||||
if (g_cmdLine == NULL) {
|
||||
PRINT_ERR("Malloc g_cmdLine space error!\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_STORAGE_EMMC
|
||||
los_disk *emmcDisk = los_get_mmcdisk_bytype(EMMC);
|
||||
if (emmcDisk == NULL) {
|
||||
PRINT_ERR("Get EMMC disk failed!\n");
|
||||
goto ERROUT;
|
||||
}
|
||||
g_alignSize = EMMC_SEC_SIZE;
|
||||
ret = los_disk_read(emmcDisk->disk_id, g_cmdLine, COMMAND_LINE_ADDR / EMMC_SEC_SIZE,
|
||||
COMMAND_LINE_SIZE / EMMC_SEC_SIZE, TRUE);
|
||||
if (ret == 0) {
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_STORAGE_SPINOR
|
||||
struct MtdDev *mtd = GetMtd("spinor");
|
||||
if (mtd == NULL) {
|
||||
PRINT_ERR("Get spinor mtd failed!\n");
|
||||
goto ERROUT;
|
||||
}
|
||||
g_alignSize = mtd->eraseSize;
|
||||
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
|
||||
if (ret == COMMAND_LINE_SIZE) {
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_STORAGE_SPINAND
|
||||
struct MtdDev *mtd = GetMtd("nand");
|
||||
if (mtd == NULL) {
|
||||
PRINT_ERR("Get nand mtd failed!\n");
|
||||
goto ERROUT;
|
||||
}
|
||||
g_alignSize = mtd->eraseSize;
|
||||
ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
|
||||
if (ret == COMMAND_LINE_SIZE) {
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
|
||||
struct MtdDev *mtd = GetCfiMtdDev();
|
||||
if (mtd == NULL) {
|
||||
PRINT_ERR("Get CFI mtd failed!\n");
|
||||
goto ERROUT;
|
||||
}
|
||||
g_alignSize = mtd->eraseSize;
|
||||
ret = mtd->read(mtd, CFIFLASH_BOOTARGS_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
|
||||
if (ret == COMMAND_LINE_SIZE) {
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
PRINT_ERR("Read cmdline error!\n");
|
||||
ERROUT:
|
||||
free(g_cmdLine);
|
||||
g_cmdLine = NULL;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
VOID LOS_FreeCmdLine() {
|
||||
if (g_cmdLine != NULL) {
|
||||
free(g_cmdLine);
|
||||
g_cmdLine = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INT32 GetBootargs(CHAR **args)
|
||||
{
|
||||
#ifdef LOSCFG_BOOTENV_RAM
|
||||
*args = OsGetArgsAddr();
|
||||
return LOS_OK;
|
||||
#else
|
||||
INT32 i;
|
||||
INT32 len = 0;
|
||||
CHAR *tmp = NULL;
|
||||
const CHAR *bootargsName = "bootargs=";
|
||||
|
||||
if (g_cmdLine == NULL) {
|
||||
PRINT_ERR("Should call LOS_GetCmdLine() first!\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
for (i = 0; i < COMMAND_LINE_SIZE; i += len + 1) {
|
||||
len = strlen(g_cmdLine + i);
|
||||
tmp = strstr(g_cmdLine + i, bootargsName);
|
||||
if (tmp != NULL) {
|
||||
*args = tmp + strlen(bootargsName);
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
PRINT_ERR("Cannot find bootargs!\n");
|
||||
return LOS_NOK;
|
||||
#endif
|
||||
}
|
||||
|
||||
INT32 LOS_ParseBootargs() {
|
||||
INT32 idx = 0;
|
||||
INT32 ret;
|
||||
CHAR *args;
|
||||
CHAR *argName;
|
||||
CHAR *argValue;
|
||||
|
||||
ret = GetBootargs(&args);
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
while ((argValue = strsep(&args, " ")) != NULL) {
|
||||
argName = strsep(&argValue, "=");
|
||||
if (argValue == NULL) {
|
||||
/* If the argument is not compliance with the format 'foo=bar' */
|
||||
g_bootArgs[idx].argName = argName;
|
||||
g_bootArgs[idx].argValue = argName;
|
||||
} else {
|
||||
g_bootArgs[idx].argName = argName;
|
||||
g_bootArgs[idx].argValue = argValue;
|
||||
}
|
||||
if (++idx >= MAX_ARGS_NUM) {
|
||||
/* Discard the rest arguments */
|
||||
break;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
INT32 LOS_GetArgValue(CHAR *argName, CHAR **argValue) {
|
||||
INT32 idx = 0;
|
||||
|
||||
while (idx < MAX_ARGS_NUM) {
|
||||
if (g_bootArgs[idx].argName == NULL) {
|
||||
break;
|
||||
}
|
||||
if (strcmp(argName, g_bootArgs[idx].argName) == 0) {
|
||||
*argValue = g_bootArgs[idx].argValue;
|
||||
return LOS_OK;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
UINT64 LOS_GetAlignsize() {
|
||||
return g_alignSize;
|
||||
}
|
||||
|
||||
UINT64 LOS_SizeStrToNum(CHAR *value)
|
||||
{
|
||||
UINT64 num = 0;
|
||||
|
||||
/* If the string is a hexadecimal value */
|
||||
if (sscanf_s(value, "0x%x", &num) > 0) {
|
||||
value += strlen("0x");
|
||||
if (strspn(value, "0123456789abcdefABCDEF") < strlen(value)) {
|
||||
goto ERROUT;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/* If the string is a decimal value in unit *Bytes */
|
||||
INT32 ret = sscanf_s(value, "%d", &num);
|
||||
INT32 decOffset = strspn(value, "0123456789");
|
||||
CHAR *endPos = value + decOffset;
|
||||
if ((ret <= 0) || (decOffset < (strlen(value) - 1))) {
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
if (strlen(endPos) == 0) {
|
||||
return num;
|
||||
} else if (strcasecmp(endPos, "k") == 0) {
|
||||
num = num * BYTES_PER_KBYTE;
|
||||
} else if (strcasecmp(endPos, "m") == 0) {
|
||||
num = num * BYTES_PER_MBYTE;
|
||||
} else if (strcasecmp(endPos, "g") == 0) {
|
||||
num = num * BYTES_PER_GBYTE;
|
||||
} else {
|
||||
goto ERROUT;
|
||||
}
|
||||
|
||||
return num;
|
||||
|
||||
ERROUT:
|
||||
PRINT_ERR("Invalid value string \"%s\"!\n", value);
|
||||
return num;
|
||||
}
|
||||
61
kernel/common/los_bootargs.h
Normal file
61
kernel/common/los_bootargs.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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_BOOTARGS_H
|
||||
#define _LOS_BOOTARGS_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#define BYTES_PER_GBYTE (1 << 30)
|
||||
#define BYTES_PER_MBYTE (1 << 20)
|
||||
#define BYTES_PER_KBYTE (1 << 10)
|
||||
#define COMMAND_LINE_ADDR (LOSCFG_BOOTENV_ADDR * BYTES_PER_KBYTE)
|
||||
#define COMMAND_LINE_SIZE 1024
|
||||
#define MAX_ARGS_NUM 100
|
||||
#ifdef LOSCFG_STORAGE_EMMC
|
||||
#define EMMC_SEC_SIZE 512
|
||||
#endif
|
||||
|
||||
struct BootArgs {
|
||||
CHAR *argName;
|
||||
CHAR *argValue;
|
||||
};
|
||||
|
||||
INT32 LOS_GetCmdLine(VOID);
|
||||
VOID LOS_FreeCmdLine(VOID);
|
||||
INT32 LOS_ParseBootargs(VOID);
|
||||
INT32 LOS_GetArgValue(CHAR *argName, CHAR **argValue);
|
||||
UINT64 LOS_GetAlignsize(VOID);
|
||||
UINT64 LOS_SizeStrToNum(CHAR *value);
|
||||
|
||||
#ifdef LOSCFG_BOOTENV_RAM
|
||||
CHAR *OsGetArgsAddr(VOID);
|
||||
#endif
|
||||
#endif /* _LOS_BOOTARGS_H */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user