diff --git a/.gitignore b/.gitignore
index 73f85073bbd3a165a45c240c6b4db017eab0b0b0..107dfa287dc905175b5d5fdf71d4774b4924a126 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
apidoc
+usr
+lib
+build/linux_header_install_for_*
+build/musl_copy_for_*
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..ebbe3f2d55913bd1f71bf9622d50292b0f4c69d2
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,37 @@
+# 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.
+
+config("sysroot_flags") {
+ cflags = [ "--sysroot="+rebase_path(".") ]
+}
+
+group("sysroot") {
+ deps = [ "build" ]
+ public_configs = [ ":sysroot_flags" ]
+}
diff --git a/README b/README
deleted file mode 100644
index 460468f1c142fb21a683553bdf24b41d697b76eb..0000000000000000000000000000000000000000
--- a/README
+++ /dev/null
@@ -1,21 +0,0 @@
- SYSROOT
-
- DESCRIPTION
- -----------
-
- Sysroot is a directory which is considered to be the root directory for
- the purpose of locating headers and libraries.
-
- Most of the headers in usr path were generated from MUSL by compilation, you can see
- the license information of MUSL in COPYRIGHT file.
-
- The build path contains compilation scripts, you can see the license information
- in LICENSE file.
-
- usr/include/arm-liteos/fb.h was generated from NUTTX headers, to provide
- necessary information from kernel to userspace.
-
- usr/include/arm-liteos/linux, usr/include/arm-liteos/asm,
- usr/include/arm-liteos/asm-generic, ohos/uapi were generated from the Linux kernel
- headers by update_headers.py, to provide necessary information from
- kernel to userspace.
diff --git a/README.md b/README.md
index 3b257a25a4ab3da22ab940728dba8b58ef9f8d6c..3f85e3489eb214f5e885bd32b4996f712daa8146 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,6 @@
```
/prebuilts/lite/sysroot
├── build # Toolchain building (including build scripts)
-├── thirdparty # Temporary third-party header files required for toolchain building
├── usr # C library and header files exposed externally
│ ├── include # Header files exposed externally
│ │ └── arm-liteos # Chip architecture for the toolchain
@@ -30,7 +29,7 @@
## Compilation and Building
-When bugs in the musl library are fixed or the version is updated, you need to compile and build a new libc library by executing **thirdparty\_headers.sh** and **build\_musl\_clang.sh** scripts in the **build** directory, respectively. The new libc library will be stored in the **/prebuilts/lite/sysroot/build/usr** directory. Then, you need to replace the header files and libc library in the **/prebuilts/lite/sysroot/usr** directory.
+When bugs in the musl library are fixed or the version is updated, you need to compile and build a new libc library by executing `make` in the **build** directory, respectively. The new libc library will be stored in the **/prebuilts/lite/sysroot/usr** directory.
## Usage
@@ -38,7 +37,7 @@ When bugs in the musl library are fixed or the version is updated, you need to c
- The following is a sample script for compiling the **helloworld.c** program:
```
-clang -o helloworld helloworld.c -target arm-liteos -L ~/llvm/lib/clang/9.0.0/lib/arm-liteos/a7_softfp_neon-vfpv4 --sysroot=/usr/xxx/OS/prebuilts/lite/sysroot/
+clang -o helloworld helloworld.c -target arm-liteos --sysroot=/my_ohos_root_path/prebuilts/lite/sysroot/
```
The compiler directory is **\~/llvm**.
diff --git a/README_zh.md b/README_zh.md
index 8a34e1e4561608dd2ab72b662791989bd1b567a0..f4d928bc92649da7ab7b2dc311ad5c8244baba91 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -16,7 +16,6 @@ sysroot是一个用作clang编译器查找标准库和头文件的根目录,
```
/prebuilts/lite/sysroot
├── build # 工具链构建目录,包括构建脚本
-├── thirdparty # 临时生成的工具链构建所需的三方头文件
├── usr # 对外C库及头文件
│ ├── include # 对外头文件存放目录
│ │ └── arm-liteos # 工具链对应的芯片架构
@@ -30,7 +29,7 @@ sysroot是一个用作clang编译器查找标准库和头文件的根目录,
## 编译构建
-musl库bug修复或者新版本更新时,需要重新编译构建新的libc库。分别执行build目录下的thirdparty\_headers.sh和build\_musl\_clang.sh脚本即可编译构建出新的libc库,存放于/prebuilts/lite/sysroot/build/usr目录下,然后替换/prebuilts/lite/sysroot/usr目录下对应的头文件及libc库即可。
+musl库bug修复或者新版本更新时,需要重新编译构建新的libc库。在build目录下执行`make`即可编译构建出新的libc库,存放于/prebuilts/lite/sysroot/usr目录下。
## 使用说明
@@ -38,7 +37,7 @@ musl库bug修复或者新版本更新时,需要重新编译构建新的libc库
- 编译用户程序helloworld.c示例如下:
```
-clang -o helloworld helloworld.c -target arm-liteos -L ~/llvm/lib/clang/9.0.0/lib/arm-liteos/a7_softfp_neon-vfpv4 --sysroot=/usr/xxx/OS/prebuilts/lite/sysroot/
+clang -o helloworld helloworld.c -target arm-liteos --sysroot=/my_ohos_root_path/prebuilts/lite/sysroot/
```
其中,编译器目录为\~/llvm。
diff --git a/build/BUILD.gn b/build/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..109f9343dfafd5c988dde5de5b9a9b3f3bb3675e
--- /dev/null
+++ b/build/BUILD.gn
@@ -0,0 +1,37 @@
+# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be used
+# to endorse or promote products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import("//build/lite/config/component/lite_component.gni")
+
+build_ext_component("build") {
+ exec_path = rebase_path(target_out_dir)
+ root_path = rebase_path("//.", exec_path)
+ makefile_path = rebase_path("Makefile", exec_path)
+ command = "make TOPDIR=$root_path -f $makefile_path"
+}
diff --git a/build/Makefile b/build/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..5632851dd2290459dfd959b2f084217de3585616
--- /dev/null
+++ b/build/Makefile
@@ -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.
+
+ARCH = arm
+TARGET = $(ARCH)-liteos
+CROSS_COMPILE = llvm-
+CC = clang --target=$(TARGET) $(ARCH_CFLAGS)
+MULTILIB = $(patsubst $(shell $(CC) -print-file-name=)%/,%,$(dir $(shell $(CC) -print-libgcc-file-name)))
+MUSLBUILDDIR = build_$(ARCH)$(subst $(eval) ,,$(patsubst -%,_%,$(sort $(ARCH_CFLAGS))))
+HIDE = @
+
+TOPDIR = $(shell pwd)/../../../..
+MUSLDIR = $(TOPDIR)/third_party/musl
+LINUXKERNELDIR = $(TOPDIR)/third_party/Linux_Kernel
+OPTRTDIR = $(TOPDIR)/third_party/optimized-routines
+NUTTXDIR = $(TOPDIR)/third_party/NuttX
+SYSROOTDIR = $(TOPDIR)/prebuilts/lite/sysroot
+LINUXDIR = $(TOPDIR)/kernel/linux-4.19
+
+TARGETS = liteos_a_user
+TARGETS += $(if $(wildcard $(LINUXDIR)),linux_user,)
+
+define LINUX_TYPES_H
+/* Auto generated file at $(shell date), do NOT edit! */
+#ifndef _LINUX_TYPES_H
+#define _LINUX_TYPES_H
+#include
+typedef uint32_t __u32, __le32;
+#endif
+endef
+export LINUX_TYPES_H
+
+ifeq ($(ARCH),arm)
+ARCH_CFLAGS = -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4
+else
+$(warning *** warning: ARCH $(ARCH) has not been tested yet, use with cautions!)
+ARCH_CFLAGS =
+endif
+
+CFLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -Wl,--build-id=sha1
+
+.PHONY: $(TARGETS:%=musl_copy_for_%)
+.PHONY: $(TARGETS:%=musl_patch_for_%)
+.PHONY: $(TARGETS:%=musl_install_for_%)
+.PHONY: $(TARGETS:%=linux_header_install_for_%)
+.PHONY: $(TARGETS:%=nuttx_header_install_for_%)
+.PHONY: $(TARGETS:%=optimized_routines_install_for_%)
+.PHONY: all clean distclean
+
+all: $(TARGETS:%=musl_install_for_%) $(if $(filter liteos_a_user,$(TARGETS)),musl_install_for_liteos_a_user_debug,)
+
+$(TARGETS:%=musl_copy_for_%):
+ $(HIDE) mkdir -p $@
+ $(HIDE) cp -rfu $(MUSLDIR)/[^p]* $@
+
+optimized_routines_install_for_liteos_a_user: musl_copy_for_liteos_a_user
+ifneq ($(ARCH),)
+ $(HIDE) cp -rfp $(OPTRTDIR)/string/$(ARCH)/* $ $ $/dev/null && \
+ sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-headers install-libs DESTDIR=$(SYSROOTDIR)
+
+musl_install_for_linux_user: TARGET = $(ARCH)-linux-ohosmusl
+musl_install_for_linux_user: MULTILIB = lib/$(TARGET)
+musl_install_for_linux_user: CC += -fuse-ld=lld --rtlib=compiler-rt
+musl_install_for_linux_user: musl_patch_for_linux_user
+ $(HIDE) cd musl_copy_for_linux_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
+ ../configure --prefix=/usr --target=$(TARGET) --includedir=/usr/include/$(TARGET) --libdir=/usr/$(MULTILIB) \
+ CC="$(CC)" CROSS_COMPILE=$(CROSS_COMPILE) CFLAGS="$(CFLAGS)" >/dev/null && \
+ sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-headers install-libs DESTDIR=$(SYSROOTDIR)
+
+musl_install_for_liteos_a_user_debug: CFLAGS += -funwind-tables -fasynchronous-unwind-tables -rdynamic -I $(shell $(CC) -print-file-name=)include
+musl_install_for_liteos_a_user_debug: musl_install_for_liteos_a_user
+ $(HIDE) mkdir -p musl_copy_for_liteos_a_user_debug && \
+ cp -rfp musl_copy_for_liteos_a_user/* musl_copy_for_liteos_a_user_debug && \
+ cp -rfp $(MUSLDIR)/porting/liteos_a/user_debug/* musl_copy_for_liteos_a_user_debug
+ $(HIDE) cd musl_copy_for_liteos_a_user_debug && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
+ ../configure --prefix=/usr --target=$(TARGET) --includedir=/usr/include/$(TARGET) --libdir=/usr/$(MULTILIB)/debug \
+ LDFLAGS="-L $(dir $(shell $(CC) -print-libgcc-file-name)) -lunwind -L lib -ldl" \
+ CC="$(CC)" CROSS_COMPILE=$(CROSS_COMPILE) CFLAGS="$(CFLAGS)" >/dev/null && \
+ sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-headers install-libs DESTDIR=$(SYSROOTDIR) ALL_INCLUDES=include/debug.h
+
+ifeq ($(ARCH),arm)
+
+ARCH_CFLAGS1 = -mfloat-abi=soft -march=armv7-a
+ARCH_CFLAGS2 = -mfloat-abi=soft -mcpu=cortex-a7
+ARCH_CFLAGS3 = -mfloat-abi=hard -mcpu=cortex-a7 -mfpu=neon-vfpv4
+ARCH_CFLAGS4 = -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4
+
+define multilib_template =
+.PHONY: musl_install_for_liteos_a_user$(1) musl_install_for_liteos_a_user_debug$(1)
+all: $$(if $$(filter liteos_a_user,$$(TARGETS)),musl_install_for_liteos_a_user$(1) musl_install_for_liteos_a_user_debug$(1),)
+musl_install_for_liteos_a_user$(1): ARCH_CFLAGS = $$($(2))
+musl_install_for_liteos_a_user$(1): musl_install_for_liteos_a_user
+ $$(HIDE) cd musl_copy_for_liteos_a_user && mkdir -p $$(MUSLBUILDDIR) && cd $$(MUSLBUILDDIR) && \
+ ../configure --prefix=/usr --target=$$(TARGET) --libdir=/usr/$$(MULTILIB) \
+ CC="$$(CC)" CROSS_COMPILE=$$(CROSS_COMPILE) CFLAGS="$$(CFLAGS)" >/dev/null && \
+ sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-libs DESTDIR=$$(SYSROOTDIR)
+musl_install_for_liteos_a_user_debug$(1): ARCH_CFLAGS = $$($(2))
+musl_install_for_liteos_a_user_debug$(1): CFLAGS += -funwind-tables -fasynchronous-unwind-tables -rdynamic -I $$(shell $$(CC) -print-file-name=)include
+musl_install_for_liteos_a_user_debug$(1): musl_install_for_liteos_a_user_debug
+ $$(HIDE) cd musl_copy_for_liteos_a_user_debug && mkdir -p $$(MUSLBUILDDIR) && cd $$(MUSLBUILDDIR) && \
+ ../configure --prefix=/usr --target=$$(TARGET) --libdir=/usr/$$(MULTILIB)/debug \
+ LDFLAGS="-L $$(dir $$(shell $$(CC) -print-libgcc-file-name)) -lunwind -L lib -ldl" \
+ CC="$$(CC)" CROSS_COMPILE=$$(CROSS_COMPILE) CFLAGS="$$(CFLAGS)" >/dev/null && \
+ sed 's, -m 644 , -m 444 ,g' Makefile | make -f- -sj install-libs DESTDIR=$$(SYSROOTDIR)
+endef
+
+$(foreach flags,1 2 3 4,$(eval $(call multilib_template,$(flags),ARCH_CFLAGS$(flags))))
+
+endif
+
+clean:
+ $(HIDE) rm -rf musl_copy_for_* linux_header_install_for_*
+
+distclean: clean
+ $(HIDE) rm -rf $(SYSROOTDIR)/lib $(SYSROOTDIR)/usr
diff --git a/build/linux/linux_kernel_header_install.sh b/build/linux/linux_kernel_header_install.sh
deleted file mode 100755
index dcf96ce509a1a5b077e23ab2110fc2419e8505ff..0000000000000000000000000000000000000000
--- a/build/linux/linux_kernel_header_install.sh
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/bin/bash
-
-#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
-#Licensed under the Apache License, Version 2.0 (the "License");
-#you may not use this file except in compliance with the License.
-#You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-#Unless required by applicable law or agreed to in writing, software
-#distributed under the License is distributed on an "AS IS" BASIS,
-#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#See the License for the specific language governing permissions and
-#limitations under the License.
-
-# This script is used to prepare header files for musl's libc.so.
-
-set -e
-ARM_TYPE=arm
-PRJ_ROOT="$PWD/../../../../../"
-KERNEL_ROOT="$PRJ_ROOT/kernel/linux-4.19"
-ARM_HDR="$KERNEL_ROOT/hdr_install/${ARM_TYPE}_header"
-OUT_HDR="$PRJ_ROOT/prebuilts/lite/sysroot/thirdparty/linux_headers_install"
-export Z_BUILD_TOP="$PRJ_ROOT"
-
-if [ -d "$ARM_HDR" ];then
-rm -r $ARM_HDR
-fi
-
-if [ -d "$OUT_HDR" ];then
-rm -r $OUT_HDR
-fi
-
-mkdir -p $ARM_HDR
-mkdir -p $OUT_HDR
-
-pushd $KERNEL_ROOT
-make headers_install ARCH=${ARM_TYPE} INSTALL_HDR_PATH=$ARM_HDR
-popd
-
-function copy_if_exists () {
- local check_dir=$1
- local src_dir=$2
- local tgt_dir=$3
- mkdir -p ${tgt_dir}
- for file in $(ls -d ${src_dir}/* 2> /dev/null); do
- if [[ -f "${file}" ]] && [[ "${file}" =~ .h$ ]]; then
- header=$(basename ${file})
- if [[ -f "${check_dir}/${header}" ]]; then
- cp ${file} ${tgt_dir}
- fi
- fi
- done
-}
-
-cp -r ${KERNEL_ROOT}/include/uapi ${OUT_HDR}
-cp -r ${KERNEL_ROOT}/include/generated/uapi ${OUT_HDR}
-cp -r ${ARM_HDR}/include/asm ${OUT_HDR}/uapi
-cp -r ${KERNEL_ROOT}/arch/${ARM_TYPE}/include/uapi ${OUT_HDR}/uapi/asm-${ARM_TYPE}
-cp -r ${KERNEL_ROOT}/arch/${ARM_TYPE}/include/generated/uapi ${OUT_HDR}/uapi/asm-${ARM_TYPE}
-copy_if_exists "${KERNEL_ROOT}/include/uapi/asm-generic" \
- "${KERNEL_ROOT}/arch/${ARM_TYPE}/include/generated/asm" \
- "${OUT_HDR}/uapi/asm-${ARM_TYPE}/asm"
-cp ${KERNEL_ROOT}/include/linux/compiler_types.h ${OUT_HDR}/uapi/linux
diff --git a/build/linux/linux_kernel_thirdparty_headers.sh b/build/linux/linux_kernel_thirdparty_headers.sh
deleted file mode 100755
index 5f5cd7ddfcd12bcb3d598eb12e4fc42ec1b8b919..0000000000000000000000000000000000000000
--- a/build/linux/linux_kernel_thirdparty_headers.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-
-#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
-#Licensed under the Apache License, Version 2.0 (the "License");
-#you may not use this file except in compliance with the License.
-#You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-#Unless required by applicable law or agreed to in writing, software
-#distributed under the License is distributed on an "AS IS" BASIS,
-#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#See the License for the specific language governing permissions and
-#limitations under the License.
-
-# This script is used to prepare header files for musl's libc.so.
-
-set -e
-ARM_TYPE=arm
-PRJ_ROOT="${PWD}/../../../../"
-LINUX_HDR="${PRJ_ROOT}/prebuilts/lite/sysroot/thirdparty/linux_headers_install"
-TMP_DIR_ORI="${PRJ_ROOT}/prebuilts/lite/sysroot/ohos_tmp_ori"
-TMP_DIR="${PRJ_ROOT}/prebuilts/lite/sysroot/ohos_tmp"
-if [ $# -eq 1 ]; then
- MUSL_DIR="$1/include"
-else
- MUSL_DIR="${PWD}/musl/include"
-fi
-export Z_BUILD_TOP="${PRJ_ROOT}"
-
-if [ ! -d "${LINUX_HDR}/uapi/asm-${ARM_TYPE}" ] || [ ! -d "${LINUX_HDR}/uapi/asm-generic" ] || [ ! -d "${LINUX_HDR}/uapi/linux" ];then
- echo "please install headers first!!!"
- echo "see guide at ${SYSROOT}/../../thirdparty/README"
- exit 1
-fi
-
-mkdir -p ${TMP_DIR_ORI}
-mkdir -p ${TMP_DIR}
-
-cp -rf ${LINUX_HDR}/* ${TMP_DIR_ORI}
-echo "#ifndef _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
-echo "#define _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
-echo "#define __user" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
-echo "#endif" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
-
-pushd ${PRJ_ROOT}
- python prebuilts/lite/sysroot/build/update_headers.py 2>/dev/null
-popd
-
-if [ ! -d ${MUSL_DIR} ]; then
- mkdir -p ${MUSL_DIR}
-fi
-
-cp -rf ${TMP_DIR}/uapi/* ${MUSL_DIR}/
-rm -rf ${TMP_DIR_ORI}
-rm -rf ${TMP_DIR}
diff --git a/build/liteos/Makefile b/build/liteos/Makefile
deleted file mode 100755
index 55ffd35b54a8ca1d47d5d090e58be5a5f1d33354..0000000000000000000000000000000000000000
--- a/build/liteos/Makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-include $(musldir)/config.mak
-
-HIDE := @
-
-optdir = ./optimized-routines
-
-MUSL_ALL_OBJS = $(sort $(wildcard $(musldir)/obj/src/*/*.lo) $(wildcard $(musldir)/obj/src/*/$(ARCH)/*.lo) $(wildcard $(musldir)/obj/ldso/*.lo) $(wildcard $(musldir)/obj/compat/time32/*.lo))
-MUSL_LIBC_OBJS = $(filter $(musldir)/obj/src/%,$(MUSL_ALL_OBJS)) $(filter $(musldir)/obj/compat/%,$(MUSL_ALL_OBJS))
-
-REPLACED_FUNC = memchr memcpy memcpy_le strcmp strcpy strlen
-REPLACED_OBJS = $(addprefix $(musldir)/obj/src/string/,$(addsuffix .lo,$(REPLACED_FUNC)))
-REPLACED_OBJS += $(addprefix $(musldir)/obj/src/string/$(ARCH)/,$(addsuffix .lo,$(REPLACED_FUNC)))
-MUSL_LIBC_OBJS := $(filter-out $(REPLACED_OBJS),$(MUSL_LIBC_OBJS))
-MUSL_LDSO_OBJS = $(filter $(musldir)/obj/ldso/%,$(MUSL_ALL_OBJS:%.o=%.lo))
-
-OPT_ALL_OBJS = $(sort $(wildcard $(optdir)/build/string/arm/*.o))
-OPT_AOBJS = $(OPT_ALL_OBJS)
-OPT_OBJS = $(filter $(optdir)/build/string/arm/%,$(OPT_ALL_OBJS:%.o=%.os))
-
-LDFLAGS_ALL = -Wl,--sort-section,alignment -Wl,--sort-common -Wl,--gc-sections -Wl,--hash-style=both -Wl,--no-undefined -Wl,--exclude-libs=ALL -Wl,--dynamic-list=$(musldir)/dynamic.list
-LDFLAGS_ALL += $(LDFLAGS)
-
-ifeq ("$(CROSS_COMPILE)", "llvm-")
- TARGET_LIBC_A = libc_opt_clang.a
- TARGET_LIBC_SO = libc_opt_clang.so
-else
- TARGET_LIBC_A = libc_opt.a
- TARGET_LIBC_SO = libc_opt.so
-endif
-
-ifeq ("$(ARCH)","")
-
-all:
- @echo "Please run linux_header_install.sh thirdparty_headers.sh build_musl(_clang).sh before running make."
- @exit 1
-
-else
-
-ifeq ("$(ARCH)","arm")
-# making a new libc.a libc.so
-all: $(TARGET_LIBC_A) $(TARGET_LIBC_SO)
- @echo "success!"
-
-$(TARGET_LIBC_A):
- $(HIDE) $(AR) rc $@ $(MUSL_LIBC_OBJS) $(OPT_AOBJS)
- $(HIDE) $(RANLIB) $@
-
-$(TARGET_LIBC_SO):
- $(HIDE) $(CC) $(LDFLAGS_ALL) -L ${musldir}/lib/ -ldl -lpthread -nostdlib -shared -Wl,-e,_dlstart -o $@ $(MUSL_LIBC_OBJS) $(OPT_OBJS) $(MUSL_LDSO_OBJS) $(LIBCC)
-
-clean:
-ifeq ($(TARGET_LIBC_A), $(wildcard $(TARGET_LIBC_A)))
- rm $(TARGET_LIBC_A)
-endif
-ifeq ($(TARGET_LIBC_SO), $(wildcard $(TARGET_LIBC_SO)))
- rm $(TARGET_LIBC_SO)
-endif
-endif
-endif
diff --git a/build/liteos/README.md b/build/liteos/README.md
deleted file mode 100755
index 8f81d47af688f8c2c35af3595a25590a60dedfe7..0000000000000000000000000000000000000000
--- a/build/liteos/README.md
+++ /dev/null
@@ -1,14 +0,0 @@
-To build toolchains, we follow the steps.
-
-1.linux headers install
-```
-./linux_header_install.sh
-```
-2.build musl
-```
-./build_musl_clang.sh
-```
-3.copy usr directory
-```
-cp -rf usr/lib usr/include ../../usr/
-```
diff --git a/build/liteos/build_musl_clang.sh b/build/liteos/build_musl_clang.sh
deleted file mode 100755
index eb0e9c186223203668ec93a956f87e39f51a0c1c..0000000000000000000000000000000000000000
--- a/build/liteos/build_musl_clang.sh
+++ /dev/null
@@ -1,239 +0,0 @@
-#!/bin/bash
-
-#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
-#Licensed under the Apache License, Version 2.0 (the "License");
-#you may not use this file except in compliance with the License.
-#You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-#Unless required by applicable law or agreed to in writing, software
-#distributed under the License is distributed on an "AS IS" BASIS,
-#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#See the License for the specific language governing permissions and
-#limitations under the License.
-
-set -e
-readonly PRJ_ROOT="$PWD/../../../../../"
-readonly MUSL_DIR="${PWD}/musl"
-readonly MUSL_CUR_DIR="./musl"
-readonly MUSL_DEBUG_DIR="${PWD}/musl_debug"
-readonly MUSL_DEBUG_CUR_DIR="./musl_debug"
-readonly MUSL_PATCH="${PWD}/musl-debug.patch"
-readonly SYSROOT_DEBUG="${PWD}/usr_debug"
-readonly MUSL_SOURCE="${PRJ_ROOT}/third_party/musl/*"
-readonly OPTIMIZE_DIR="${PWD}/optimized-routines"
-readonly OPTIMIZE_SOURCE="${PRJ_ROOT}/third_party/optimized-routines/*"
-readonly LITEOSTOPDIR="${PRJ_ROOT}/kernel/liteos_a"
-readonly SYSROOT="${PWD}/usr"
-
-BUILD=`gcc -dumpmachine`
-HOST=`gcc -dumpmachine`
-TARGET=arm-liteos
-CROSS_COMPILE=llvm-
-CFLAGS_FOR_TARGET="--target=${TARGET} -mfloat-abi=soft -march=armv7-a -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack"
-CFLAGS_FOR_TARGET1="--target=${TARGET} -mfloat-abi=soft -mcpu=cortex-a7 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack"
-CFLAGS_FOR_TARGET2="--target=${TARGET} -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack"
-CFLAGS_FOR_TARGET3="--target=${TARGET} -mfloat-abi=hard -mcpu=cortex-a7 -mfpu=neon-vfpv4 -Wall -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack"
-
-TARGET_LIBC_A="${PWD}/libc_opt_clang.a"
-TARGET_LIBC_SO="${PWD}/libc_opt_clang.so"
-
-PARALLEL=`grep ^processor /proc/cpuinfo|wc -l`
-LITEOS_COMPILER_PATH=`${LITEOSTOPDIR}/tools/build/mk/get_llvm_compiler_path.sh ${CROSS_COMPILE} ${LITEOSTOPDIR}`
-LDFLAG="-L${LITEOS_COMPILER_PATH}/lib/clang/9.0.0/lib/${TARGET} -L${LITEOS_COMPILER_PATH}/lib/${TARGET}/c++ --rtlib=compiler-rt -lclang_rt.builtins -lunwind -fuse-ld=lld -Wl,--build-id=sha1"
-
-export PATH="${LITEOS_COMPILER_PATH}/bin:${PATH}"
-
-# prepare to build musl
-if [ -d "${MUSL_DIR}" ]; then
- rm -r ${MUSL_DIR}
-fi
-mkdir -p ${MUSL_DIR}
-
-if [ -d "${SYSROOT}" ]; then
- rm -r ${SYSROOT}
-fi
-mkdir -p ${SYSROOT}
-
-cp -r ${MUSL_SOURCE} ${MUSL_DIR}
-
-# prepare to build optimized-routines for improve musl performance
-if [ -d "${OPTIMIZE_DIR}" ]; then
- rm -r ${OPTIMIZE_DIR}
-fi
-mkdir -p ${OPTIMIZE_DIR}
-cp -r ${OPTIMIZE_SOURCE} ${OPTIMIZE_DIR}
-
-# build optimized-routines
-function build_opt()
-{
- pushd ${OPTIMIZE_DIR}
- # generate the config.mk file required for compiling the optimized-routines lib.
- exec 3>&1 1>config.mk
- cat << EOF
-# This version of config.mk was generated by:
-# build_musl.sh
-# The default configuration(CFLAGS) is from optimized-routines.
-# Any changes made here will be lost if build_musl.sh re-run
-
-# Target architecture: aarch64, arm or x86_64
-ARCH = arm
-
-# Subprojects to build
-SUBS = string
-
-# Use for cross compilation with gcc/clang.
-CROSS_COMPILE = ${CROSS_COMPILE}
-
-# Compiler for the target
-CC = ${LITEOS_COMPILER_PATH}/bin/clang
-CFLAGS = -std=c99 -pipe -O3 --target=arm-liteos -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=softfp -nostdinc
-CFLAGS += -I/${SYSROOT}/../../../usr/include/${TARGET}
-CFLAGS += -Wall -Wno-missing-braces
-
-# Enable debug info.
-#HOST_CFLAGS += -g
-#CFLAGS += -g
-
-# Use with clang.
-CFLAGS += -ffp-contract=fast
-LDFLAGS = -L${LITEOS_COMPILER_PATH}/lib/clang/9.0.0/lib/${TARGET}/a7_softfp_neon-vfpv4 -L${SYSROOT}/../../../usr/lib/${TARGET}/a7_softfp_neon-vfpv4 -lclang_rt.builtins -fuse-ld=lld -nostartfiles
-
-EOF
- exec 1>&3 3>&-
- make -j
- popd
-}
-
-# generate the final libc.so file.
-function install_opt_libc()
-{
- if [ -e "${TARGET_LIBC_A}" ]; then
- rm ${TARGET_LIBC_A}
- fi
- if [ -e "${TARGET_LIBC_SO}" ]; then
- rm ${TARGET_LIBC_SO}
- fi
-
- # make libc_opt.a libc_opt.so by makefile
- make musldir=$2 -j
-
- # copy libc_opt.so libc_opt.a to a specified directory to replace the original libc.so libc.a file.
- if [ -e "${TARGET_LIBC_A}" ] && [ -e "${TARGET_LIBC_SO}" ] ; then
- rm $1/lib/libc.a $1/lib/libc.so
- cp ${TARGET_LIBC_A} $1/lib/libc.a
- cp ${TARGET_LIBC_SO} $1/lib/libc.so
- else
- printf "build libc_opt error!"
- exit 1;
- fi
-}
-
-function install_debug_musl()
-{
- mkdir -p ${SYSROOT}/include/${TARGET}/debug
- mkdir -p ${SYSROOT}/lib/${TARGET}/debug
- mkdir -p ${SYSROOT}/lib/${TARGET}/a7_soft/debug
- mkdir -p ${SYSROOT}/lib/${TARGET}/a7_softfp_neon-vfpv4/debug
- mkdir -p ${SYSROOT}/lib/${TARGET}/a7_hard_neon-vfpv4/debug
- cp -f ${SYSROOT_DEBUG}/include/${TARGET}/debug.h ${SYSROOT}/include/${TARGET}/debug
- cp -f ${SYSROOT_DEBUG}/lib/${TARGET}/libc.* ${SYSROOT}/lib/${TARGET}/debug
- cp -f ${SYSROOT_DEBUG}/lib/${TARGET}/a7_soft/libc.* ${SYSROOT}/lib/${TARGET}/a7_soft/debug
- cp -f ${SYSROOT_DEBUG}/lib/${TARGET}/a7_softfp_neon-vfpv4/libc.* ${SYSROOT}/lib/${TARGET}/a7_softfp_neon-vfpv4/debug
- cp -f ${SYSROOT_DEBUG}/lib/${TARGET}/a7_hard_neon-vfpv4/libc.* ${SYSROOT}/lib/${TARGET}/a7_hard_neon-vfpv4/debug
-}
-
-# build musl
-function build_musl()
-{
- pushd $5
- if [ "$5" = "${MUSL_DEBUG_DIR}" ]; then
- patch -p1 < ${MUSL_PATCH}
- fi
-
- HEADERDIR="$6/include/${TARGET}"
- LIBDIR="$6/lib/${TARGET}"
- BINDIR="$6/bin/${TARGET}"
- SYSDIR="$6/sys/${TARGET}"
- mkdir -p ${LIBDIR} ${BINDIR} ${SYSDIR} ${HEADERDIR}
- CC="${LITEOS_COMPILER_PATH}/bin/clang $1" CROSS_COMPILE="${CROSS_COMPILE}" LDFLAGS="${LDFLAG}" ./configure --prefix=$6 --libdir=${LIBDIR} --bindir=${BINDIR} --syslibdir=${SYSDIR} --includedir=$HEADERDIR --build=$BUILD --host=$TARGET
- make -j ${PARALLEL}
- popd
- build_opt
- install_opt_libc "$5" "$7"
- pushd $5
- make install
- make clean
-
- HEADERDIR="$6/include/${TARGET}"
- LIBDIR="$6/lib/${TARGET}/a7_soft"
- BINDIR="$6/bin/${TARGET}/a7_soft"
- SYSDIR="$6/sys/a7_soft"
- mkdir -p ${LIBDIR} ${BINDIR} ${SYSDIR} ${HEADERDIR}
- CC="${LITEOS_COMPILER_PATH}/bin/clang $2" CROSS_COMPILE="${CROSS_COMPILE}" LDFLAGS="${LDFLAG}" ./configure --prefix=$6 --libdir=${LIBDIR} --bindir=${BINDIR} --syslibdir=${SYSDIR} --includedir=${HEADERDIR} --build=${BUILD} --host=${TARGET}
- make -j ${PARALLEL}
- popd
- build_opt
- install_opt_libc "$5" "$7"
- pushd $5
- make install
- make clean
-
- HEADERDIR="$6/include/${TARGET}"
- LIBDIR="$6/lib/${TARGET}/a7_softfp_neon-vfpv4"
- BINDIR="$6/bin/${TARGET}/a7_softfp_neon-vfpv4"
- SYSDIR="$6/sys/${TARGET}/a7_softfp_neon-vfpv4"
- mkdir -p ${LIBDIR} ${BINDIR} ${SYSDIR} ${HEADERDIR}
- CC="${LITEOS_COMPILER_PATH}/bin/clang $3" CROSS_COMPILE="${CROSS_COMPILE}" LDFLAGS="${LDFLAG}" ./configure --prefix=$6 --libdir=${LIBDIR} --bindir=${BINDIR} --syslibdir=${SYSDIR} --includedir=${HEADERDIR} --build=${BUILD} --host=${TARGET}
- make -j ${PARALLEL}
- popd
- build_opt
- install_opt_libc "$5" "$7"
- pushd $5
- make install
- make clean
-
- HEADERDIR="$6/include/${TARGET}"
- LIBDIR="$6/lib/${TARGET}/a7_hard_neon-vfpv4"
- BINDIR="$6/bin/${TARGET}/a7_hard_neon-vfpv4"
- SYSDIR="$6/sys/${TARGET}/a7_hard_neon-vfpv4"
- mkdir -p ${LIBDIR} ${BINDIR} ${SYSDIR} ${HEADERDIR}
- CC="${LITEOS_COMPILER_PATH}/bin/clang $4" CROSS_COMPILE="${CROSS_COMPILE}" LDFLAGS="${LDFLAG}" ./configure --prefix=$6 --libdir=${LIBDIR} --bindir=${BINDIR} --syslibdir=${SYSDIR} --includedir=${HEADERDIR} --build=${BUILD} --host=${TARGET}
- make -j ${PARALLEL}
- popd
- build_opt
- install_opt_libc "$5" "$7"
- pushd $5
- make install
- popd
-}
-
-# prepare linux compat headers for musl
-sh thirdparty_headers.sh ${MUSL_DIR}
-# build musl
-build_musl "${CFLAGS_FOR_TARGET}" "${CFLAGS_FOR_TARGET1}" "${CFLAGS_FOR_TARGET2}" "${CFLAGS_FOR_TARGET3}" "${MUSL_DIR}" "${SYSROOT}" "${MUSL_CUR_DIR}"
-
-# prepare for musl debug
-CFLAGS_DEBUG_FOR_TARGET=${CFLAGS_FOR_TARGET}" -funwind-tables -rdynamic"
-CFLAGS_DEBUG_FOR_TARGET1=${CFLAGS_FOR_TARGET1}" -funwind-tables -rdynamic"
-CFLAGS_DEBUG_FOR_TARGET2=${CFLAGS_FOR_TARGET2}" -funwind-tables -rdynamic"
-CFLAGS_DEBUG_FOR_TARGET3=${CFLAGS_FOR_TARGET3}" -funwind-tables -rdynamic"
-UNWIND_H="${LITEOS_COMPILER_PATH}/lib/clang/9.0.0/include/unwind*"
-if [ -d "${MUSL_DEBUG_DIR}" ]; then
- rm -r ${MUSL_DEBUG_DIR}
-fi
-if [ -d "${SYSROOT_DEBUG}" ]; then
- rm -r ${SYSROOT_DEBUG}
-fi
-mkdir -p ${MUSL_DEBUG_DIR}
-mkdir -p ${SYSROOT_DEBUG}
-cp -r ${MUSL_SOURCE} ${MUSL_DEBUG_DIR}
-cp -f ${UNWIND_H} ${MUSL_DEBUG_DIR}/include
-# prepare linux compat headers for musl debug
-sh thirdparty_headers.sh ${MUSL_DEBUG_DIR}
-# build musl debug
-build_musl "${CFLAGS_DEBUG_FOR_TARGET}" "${CFLAGS_DEBUG_FOR_TARGET1}" "${CFLAGS_DEBUG_FOR_TARGET2}" "${CFLAGS_DEBUG_FOR_TARGET3}" "${MUSL_DEBUG_DIR}" "${SYSROOT_DEBUG}" "${MUSL_DEBUG_CUR_DIR}"
-# generate final musl debug shared library
-install_debug_musl
-
diff --git a/build/liteos/linux_header_install.sh b/build/liteos/linux_header_install.sh
deleted file mode 100755
index 7b319a7c805fb5657ae0206d6bc15df731a4c4db..0000000000000000000000000000000000000000
--- a/build/liteos/linux_header_install.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/bash
-
-#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
-#Licensed under the Apache License, Version 2.0 (the "License");
-#you may not use this file except in compliance with the License.
-#You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-#Unless required by applicable law or agreed to in writing, software
-#distributed under the License is distributed on an "AS IS" BASIS,
-#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#See the License for the specific language governing permissions and
-#limitations under the License.
-
-# This script is used to prepare header files for musl's libc.so.
-
-set -e
-
-PRJ_ROOT="$PWD/../../../../../"
-KERNEL_ROOT="$PRJ_ROOT/third_party/Linux_Kernel"
-ARM_HDR="$PRJ_ROOT/third_party/Linux_Kernel/hdr_install/arm_header"
-OUT_HDR="$PRJ_ROOT/prebuilts/lite/sysroot/thirdparty/linux_headers_install"
-export Z_BUILD_TOP="$PRJ_ROOT"
-
-if [ -d "$ARM_HDR" ];then
-rm -r $ARM_HDR
-fi
-
-if [ -d "$OUT_HDR" ];then
-rm -r $OUT_HDR
-fi
-
-mkdir -p $ARM_HDR
-mkdir -p $OUT_HDR
-
-pushd $KERNEL_ROOT
-make headers_install ARCH=arm INSTALL_HDR_PATH=$ARM_HDR
-popd
-
-cp -r $KERNEL_ROOT/include/uapi/* $OUT_HDR
-cp -r $ARM_HDR/include/asm $OUT_HDR
diff --git a/build/liteos/mem_info_parse b/build/liteos/mem_info_parse
deleted file mode 100755
index 35da158d191b737e9d86f0b2d76519890283c975..0000000000000000000000000000000000000000
--- a/build/liteos/mem_info_parse
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/bin/bash
-
-#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
-#Licensed under the Apache License, Version 2.0 (the "License");
-#you may not use this file except in compliance with the License.
-#You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-#Unless required by applicable law or agreed to in writing, software
-#distributed under the License is distributed on an "AS IS" BASIS,
-#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#See the License for the specific language governing permissions and
-#limitations under the License.
-
-LOAD_BASE="0x2000000"
-LLVM_ADDR2LINE=llvm-addr2line
-GCC_ADDR2LINE=addr2line
-
-get_line()
-{
- SYM_ADDR=$(echo $1 | awk '{print $2}')
- ELF_OFFSET=`echo ${SYM_ADDR} | cut -d '[' -f2 | cut -d ']' -f1`
- FILE_LINE=`${ADDR2LINE} -f -e $2 ${ELF_OFFSET} | awk 'NR==2'`
- if [[ "${FILE_LINE}" == *"?"* ]]; then
- typeset ELF_OFFSET=$((ELF_OFFSET+LOAD_BASE))
- ELF_OFFSET=$(echo "obase=16;${ELF_OFFSET}" | bc)
- FILE_LINE=`${ADDR2LINE} -f -e $2 ${ELF_OFFSET} | awk 'NR==2'`
- fi
- echo ${FILE_LINE}
-}
-
-parse_line()
-{
- FILE_PATH=$(echo $1 | awk '{print $4}')
- ELF_FILE=${FILE_PATH##*/}
- ELF_FILE=${ELF_FILE//[$'\t\r\n']}
- FLAG=false
- for i in $2; do
- if [ "${ELF_FILE}" = "$i" ]; then
- if [ ! -f "$i" ]; then
- echo "Error: no such file: $i"
- exit 1
- fi
- FILE_LINE=`get_line "$1" $i`
- if [[ "${FILE_LINE}" == *"?"* ]] || [ -z "${FILE_LINE}" ]; then
- echo " * Error: you need ensure whether file: "$i" was compiled with -g or not! *"
- exit 1
- fi
- LINE=`echo $1 | tr -d '\r'`
- LINE=$(echo ${LINE} | awk '{print $1,$2}')
- echo " "${LINE}" at "${FILE_LINE}
- FLAG=true
- break
- fi
- done
- if [[ "${FLAG}" == "false" ]]; then
- echo " "$1
- fi
-}
-
-if [ $# -le 1 ]; then
- echo "Usage: ./out2line.sh text.txt elf1 elf2 ..."
- exit 1
-fi
-
-read -n5 -p "Compiler is [gcc/llvm]: " ANSWER
-case ${ANSWER} in
-(gcc | GCC)
- which ${GCC_ADDR2LINE} >/dev/null 2>&1
- if [ $? -eq 0 ]; then
- ADDR2LINE=${GCC_ADDR2LINE}
- else
- echo "${GCC_ADDR2LINE} command not found!"
- exit 1
- fi;;
-(llvm | LLVM)
- which ${LLVM_ADDR2LINE} >/dev/null 2>&1
- if [ $? -eq 0 ]; then
- ADDR2LINE=${LLVM_ADDR2LINE}
- else
- echo "${LLVM_ADDR2LINE} command not found! Trying to use ${GCC_ADDR2LINE}!"
- which ${GCC_ADDR2LINE} >/dev/null 2>&1
- if [ $? -eq 0 ]; then
- ADDR2LINE=${GCC_ADDR2LINE}
- else
- echo "${GCC_ADDR2LINE} command not found!"
- exit 1
- fi
- fi;;
-(*)
- echo "Error choise!"
- exit 1
-esac
-echo -e "Now using ${ADDR2LINE} ...\n"
-
-PARAM_LIST="${*:2}"
-cat $1 | while read line; do
- HEAD_STRING=$(echo ${line} | awk '{print $1}')
- if [[ "${HEAD_STRING}" == *"#"* ]]; then
- parse_line "${line}" "${PARAM_LIST}"
- else
- if [[ "${HEAD_STRING}" == *"["* ]]; then
- echo " "${line}
- else
- echo ${line}
- fi
- fi
-done
-
diff --git a/build/liteos/musl-debug.patch b/build/liteos/musl-debug.patch
deleted file mode 100755
index 45bfab52f55f4299c5a95bd6b1977eda1f707570..0000000000000000000000000000000000000000
--- a/build/liteos/musl-debug.patch
+++ /dev/null
@@ -1,1639 +0,0 @@
-diff --git a/Makefile b/Makefile
-index 9f058ca2..70064d1b 100755
---- a/Makefile
-+++ b/Makefile
-@@ -160,7 +160,7 @@ obj/%.lo: $(srcdir)/%.c $(GENH) $(IMPH)
- $(HIDE)$(CC_CMD)
-
- lib/libc.so: $(LOBJS) $(LDSO_OBJS)
-- $(HIDE)$(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -nostdlib -shared \
-+ $(HIDE)$(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -L lib/ -ldl -lpthread -nostdlib -shared \
- -Wl,-e,_dlstart -o $@ $(LOBJS) $(LDSO_OBJS) $(LIBCC)
-
- lib/libc.a: $(AOBJS)
-diff --git a/configure b/configure
-index a2728969..b45d8e88 100755
---- a/configure
-+++ b/configure
-@@ -467,8 +467,8 @@ fi
- # unstrippable. These options force them back to debug sections (and
- # cause them not to get generated at all if debugging is off).
- #
--tryflag CFLAGS_AUTO -fno-unwind-tables
--tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
-+# tryflag CFLAGS_AUTO -fno-unwind-tables
-+# tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
-
- #
- # Attempt to put each function and each data object in its own
-diff --git a/include/debug.h b/include/debug.h
-new file mode 100644
-index 00000000..674ccaa9
---- /dev/null
-+++ b/include/debug.h
-@@ -0,0 +1,88 @@
-+#ifndef _DEBUG_H
-+#define _DEBUG_H
-+
-+#ifdef __cplusplus
-+extern "C" {
-+#endif
-+
-+/**
-+ * @brief Initialization of the memory debug function, including the output method of memory debug information
-+ * and signal registration. You can use command line parameters, "--mwatch" or "--mrecord ", to
-+ * call mem_check_init(char *) when executing your program.
-+ *
-+ * @param f_path The full path of the file to be created where the memory debug information will be written.
-+ * If the param is NULL or the file creation fails, the memory debug information will be output via serial
-+ * port.
-+ *
-+ * @return void.
-+ */
-+void mem_check_init(char *f_path);
-+
-+/**
-+ * @brief View thread-level heap memory usage information, signal registration index is 35, you can use "kill -35 pid"
-+ * to call watch_mem() when your program is running. The output way of memory debug information is determined by how
-+ * the mem_check_init(char *) interface is called.
-+ *
-+ * @param void.
-+ *
-+ * @return void.
-+ */
-+void watch_mem(void);
-+
-+/**
-+ * @brief Check whether the heap memory leak is exist or not, signal registration index is 36, you can use "kill -36
-+ * pid" to call check_leak() when your program is running. The output way of memory debug information is determined by
-+ * how the mem_check_init(char *) interface is called.
-+ *
-+ * @param void.
-+ *
-+ * @return void.
-+ */
-+void check_leak(void);
-+
-+/**
-+ * @brief Check whether the heap memory is integrited or not, signal registration index is 37, you can use "kill -37
-+ * pid" to call check_heap_integrity() when your program is running. The output way of memory debug information is
-+ * determined by how the mem_check_init(char *) interface is called.
-+ *
-+ * @param void.
-+ *
-+ * @return void.
-+ */
-+void check_heap_integrity(void);
-+
-+/**
-+ * @brief Store the address of the call stack information, the max number is param size.
-+ *
-+ * @param buffer The array to store address of the call stack information.
-+ * @param size The size of buffer.
-+ *
-+ * @return The exact number of the address.
-+ */
-+int backtrace(void **buffer, int size);
-+
-+/**
-+ * @brief Find the symbol information corresponding to the address stored in the buffer for dynamic linking.
-+ *
-+ * @param buffer The array stored address of the exact number.
-+ * @param size The exact number of the address stored in the buffer.
-+ *
-+ * @return The pointer to the memory allocated from heap holds the symbol information corresponding to the address
-+ * stored in the buffer. You should free the memory the pointer points to after calling backtrace_symbols().
-+ */
-+char **backtrace_symbols(void *const *buffer, int size);
-+
-+/**
-+ * @brief Print the call stack information of the function calling print_trace().
-+ *
-+ * @param void.
-+ *
-+ * @return void.
-+ */
-+void print_trace(void);
-+
-+#ifdef __cplusplus
-+}
-+#endif
-+
-+#endif
-diff --git a/ldso/dynlink.c b/ldso/dynlink.c
-index 40e05220..e311c674 100644
---- a/ldso/dynlink.c
-+++ b/ldso/dynlink.c
-@@ -1756,7 +1756,7 @@ void __dls3(size_t *sp, size_t *auxv)
- }
- if (DL_FDPIC) app.loadmap = app_loadmap;
- if (app.tls.size) app.tls.image = laddr(&app, tls_image);
-- if (interp_off) ldso.name = laddr(&app, interp_off);
-+ if (interp_off) ldso.name = "/lib/libc.so";
- #if 0
- if ((aux[0] & (1UL<
- #include
-+#include
-+#include
- #include "libc.h"
-
-+extern bool g_enable_check;
-+extern void mem_check_deinit(void);
-+extern void clean_recycle_list(bool clean_all);
-+
- static void dummy()
- {
- }
-@@ -26,6 +32,12 @@ weak_alias(libc_exit_fini, __libc_exit_fini);
-
- _Noreturn void exit(int code)
- {
-+ if (g_enable_check) {
-+ check_leak();
-+ check_heap_integrity();
-+ mem_check_deinit();
-+ clean_recycle_list(true);
-+ }
- __funcs_on_exit();
- __libc_exit_fini();
- __stdio_exit();
-diff --git a/src/internal/malloc_impl.h b/src/internal/malloc_impl.h
-index 59785a7f..6107f0b6 100644
---- a/src/internal/malloc_impl.h
-+++ b/src/internal/malloc_impl.h
-@@ -2,6 +2,20 @@
- #define MALLOC_IMPL_H
-
- #include
-+#include
-+
-+#define BACKTRACE_DEPTH_MAX 5 /* The max depth of backtrace */
-+#define BACKTRACE_START_OFFSET 0 /* The start offset of backtrace */
-+#define SECONDARY_CALL_OFFSET 2 /* The backtrace offset for secondary call backtrace() */
-+#define BACKTRACE_OFFSET (BACKTRACE_START_OFFSET + SECONDARY_CALL_OFFSET)
-+#define PREFIX_PLACE_HOLDER 10 /* Reserve positions for file name prefix "pid()_" */
-+#define PTHREAD_NUM_MAX 128 /* Same as number of task of kernel */
-+#define NODE_MAGIC 0xFCFCFCFC /* Magic number for node of chunk */
-+#define FREE_MAGIC 0xFE /* Magic number for filling freed heap memory not recycled to heap pool */
-+#define RECYCLE_MAX 128 /* The queue size for free() to recycle */
-+#define RECYCLE_SIZE_MAX 0x300000 /* The max sum size of freed chunk for recycle list */
-+#define ITEM_BUFFER_SIZE 256 /* The buffer max size for one item of memory debug info */
-+#define CHECK_POINT_TRACE_MAX 2 /* The trace max for check point */
-
- hidden void *__expand_heap(size_t *);
-
-@@ -10,21 +24,52 @@ hidden void __malloc_donate(char *, char *);
- hidden void *__memalign(size_t, size_t);
-
- struct chunk {
-+ unsigned int checksum;
- size_t psize, csize;
- struct chunk *next, *prev;
- };
-
- struct bin {
-+ unsigned int checksum;
- volatile int lock[2];
- struct chunk *head;
- struct chunk *tail;
- };
-
--#define SIZE_ALIGN (4*sizeof(size_t))
-+struct heap_block {
-+ struct heap_block *next;
-+ struct heap_block *prev;
-+};
-+
-+struct list {
-+ struct list *prev;
-+ struct list *next;
-+};
-+
-+struct node {
-+ short tid, pid;
-+ void *ptr;
-+ size_t size;
-+ void *lr[BACKTRACE_DEPTH_MAX];
-+ struct list list;
-+};
-+
-+struct stat_bin {
-+ volatile int lock[2];
-+ struct list head;
-+ size_t t_total_size;
-+};
-+
-+#define ROUNDUP(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
-+#define SIZE_ALIGN ROUNDUP(sizeof(struct chunk), 0x10)
- #define SIZE_MASK (-SIZE_ALIGN)
--#define OVERHEAD (2*sizeof(size_t))
--#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN)
--#define DONTCARE 16
-+#define OVERHEAD (sizeof(struct chunk))
-+#define BLOCK_HEAD (sizeof(struct heap_block) + OVERHEAD)
-+#define CHUNK_BLOCK_OFFSET (sizeof(struct heap_block))
-+#define CHUNK_TO_BLOCK(c) (struct heap_block *)((char *)(c) - CHUNK_BLOCK_OFFSET)
-+#define BLOCK_TO_CHUNK(p) (struct chunk *)((char *)(p) + CHUNK_BLOCK_OFFSET)
-+#define MMAP_THRESHOLD (0x1c00*(4*sizeof(size_t)))
-+#define DONTCARE SIZE_ALIGN
- #define RECLAIM 163840
-
- #define CHUNK_SIZE(c) ((c)->csize & -2)
-@@ -33,7 +78,7 @@ struct bin {
- #define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c)))
- #define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD)
- #define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD)
--#define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head))
-+#define BIN_TO_CHUNK(i) (&mal.bins[i].checksum)
-
- #define C_INUSE ((size_t)1)
-
-@@ -43,4 +88,18 @@ hidden void __bin_chunk(struct chunk *);
-
- hidden extern int __malloc_replaced;
-
-+hidden extern bool g_enable_check;
-+hidden extern int g_recycle_num;
-+hidden extern size_t g_recycle_size;
-+hidden extern int g_mem_lock[];
-+hidden extern void insert_node(void *ptr, size_t size);
-+hidden extern int delete_node(void *ptr);
-+hidden extern void insert_block_list(struct chunk *ptr);
-+hidden extern void insert_free_tail(struct chunk *self);
-+hidden extern struct chunk *get_free_head(void);
-+hidden extern void get_free_trace(void *ptr);
-+hidden extern void clean_recycle_list(bool clean_all);
-+hidden extern void check_chunk_integrity(struct chunk *cur);
-+hidden extern void calculate_checksum(struct chunk *cur, struct chunk *next);
-+
- #endif
-diff --git a/src/malloc/backtrace.c b/src/malloc/backtrace.c
-new file mode 100644
-index 00000000..859bbee7
---- /dev/null
-+++ b/src/malloc/backtrace.c
-@@ -0,0 +1,141 @@
-+#define _GNU_SOURCE
-+#include
-+#include
-+#include
-+#include
-+#include
-+#include
-+#include
-+
-+#define TRACE_MAX_DEPTH 16
-+#define STRING_MAX_LEN 256
-+#define TRACE_IGNORE 1
-+
-+struct unwind_state_t {
-+ _Unwind_Word **cur;
-+ _Unwind_Word **end;
-+};
-+
-+static _Unwind_Reason_Code unwind_callback(struct _Unwind_Context *context, void *arg)
-+{
-+ struct unwind_state_t *state = (struct unwind_state_t *)arg;
-+ _Unwind_Word pc = _Unwind_GetIP(context);
-+ if (pc != 0) {
-+ if (state->cur != state->end) {
-+ *state->cur = (_Unwind_Word *)pc;
-+ } else {
-+ return _URC_END_OF_STACK;
-+ }
-+ }
-+ ++state->cur;
-+
-+ return _URC_NO_REASON;
-+}
-+
-+int backtrace(void **buffer, int size)
-+{
-+ struct unwind_state_t state;
-+
-+ if ((buffer == NULL) || (size <= 0)) {
-+ return 0;
-+ }
-+
-+ state.cur = (_Unwind_Word **)buffer;
-+ state.end = (_Unwind_Word **)(buffer + size);
-+ _Unwind_Backtrace(&unwind_callback, &state);
-+
-+ return (void **)state.cur - buffer;
-+}
-+
-+char **backtrace_symbols(void *const *buffer, int size)
-+{
-+ int i;
-+ char **str_location = NULL;
-+ char *str_buffer = NULL;
-+ char *str_base = NULL;
-+ char **string = NULL;
-+ Dl_info info = { 0 };
-+ size_t total_size = 0;
-+
-+ if ((buffer == NULL) || (size <= 0)) {
-+ return NULL;
-+ }
-+ str_location = (char **)malloc(size * sizeof(char *));
-+ if (str_location == NULL) {
-+ return NULL;
-+ }
-+ memset(str_location, 0, size * sizeof(char *));
-+ for (i = 0; i < size; ++i) {
-+ dladdr((void *)buffer[i], &info);
-+ if ((info.dli_fname == NULL) || (info.dli_fname[0] == '\0')) {
-+ break;
-+ }
-+ str_buffer = (char *)malloc(STRING_MAX_LEN * sizeof(char));
-+ if (str_buffer == NULL) {
-+ goto err;
-+ }
-+
-+ snprintf(str_buffer, STRING_MAX_LEN, " #%02d: <%s+%#x>[%#x] -> %s\n", i, info.dli_sname,
-+ (uintptr_t)buffer[i] - (uintptr_t)info.dli_saddr,
-+ (uintptr_t)buffer[i] - (uintptr_t)info.dli_fbase, info.dli_fname);
-+ str_location[i] = str_buffer;
-+ total_size += strlen(str_buffer) + 1;
-+ }
-+ string = (char **)malloc(total_size + (size * sizeof(char *)));
-+ if (string == NULL) {
-+ goto err;
-+ }
-+ memset(string, 0, total_size + (size * sizeof(char *)));
-+ str_base = (char *)(string + size);
-+ for (i = 0; i < size; ++i) {
-+ if (str_location[i] == NULL) {
-+ break;
-+ }
-+ strcpy(str_base, str_location[i]);
-+ string[i] = str_base;
-+ str_base += strlen(string[i]) + 1;
-+ free(str_location[i]);
-+ }
-+ free(str_location);
-+ return string;
-+
-+err:
-+ for (i = 0; i < size; ++i) {
-+ if (str_location[i]) {
-+ free(str_location[i]);
-+ }
-+ }
-+ free(str_location);
-+ return NULL;
-+}
-+
-+static void get_backtrace_addr(void *const *buffer, int nptrs)
-+{
-+ for (int i = 1; i < nptrs; ++i) {
-+ printf(" #%02d: %#x\n", i, buffer[i]);
-+ }
-+}
-+
-+void print_trace()
-+{
-+ int nptrs, i;
-+ void *buffer[TRACE_MAX_DEPTH];
-+ char **strings = NULL;
-+
-+ nptrs = backtrace(buffer, TRACE_MAX_DEPTH);
-+ printf("\nBacktrace() returned %d addresses\n", nptrs - TRACE_IGNORE);
-+ strings = backtrace_symbols(buffer, nptrs);
-+ if (strings == NULL) {
-+ printf("backtrace_symbols() err!\n");
-+ return;
-+ }
-+ for (i = 1; i < nptrs; ++i) {
-+ if ((i == 1) && (strings[i] == NULL)) {
-+ get_backtrace_addr(buffer, nptrs);
-+ break;
-+ }
-+ printf("%s", strings[i]);
-+ }
-+ free(strings);
-+}
-+
-diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
-old mode 100644
-new mode 100755
-index df00631f..ba6900a4
---- a/src/malloc/malloc.c
-+++ b/src/malloc/malloc.c
-@@ -4,6 +4,8 @@
- #include
- #include
- #include
-+#include
-+#include
- #include
- #include "libc.h"
- #include "atomic.h"
-@@ -143,6 +145,7 @@ static struct chunk *expand_heap(size_t n)
- return 0;
- }
-
-+ lock(g_mem_lock);
- /* If not just expanding existing space, we need to make a
- * new sentinel chunk below the allocated space. */
- if (p != end) {
-@@ -151,6 +154,7 @@ static struct chunk *expand_heap(size_t n)
- p = (char *)p + SIZE_ALIGN;
- w = MEM_TO_CHUNK(p);
- w->psize = 0 | C_INUSE;
-+ insert_block_list(w);
- }
-
- /* Record new heap end and fill in footer. */
-@@ -163,7 +167,9 @@ static struct chunk *expand_heap(size_t n)
- * zero-size sentinel header at the old end-of-heap. */
- w = MEM_TO_CHUNK(p);
- w->csize = n | C_INUSE;
-+ calculate_checksum(w, MEM_TO_CHUNK(end));
-
-+ unlock(g_mem_lock);
- unlock(heap_lock);
-
- return w;
-@@ -251,7 +257,7 @@ static int pretrim(struct chunk *self, size_t n, int i, int j)
-
- next = NEXT_CHUNK(self);
- split = (void *)((char *)self + n);
--
-+ lock(g_mem_lock);
- split->prev = self->prev;
- split->next = self->next;
- split->prev->next = split;
-@@ -259,7 +265,10 @@ static int pretrim(struct chunk *self, size_t n, int i, int j)
- split->psize = n | C_INUSE;
- split->csize = n1-n;
- next->psize = n1-n;
-+ calculate_checksum(split, next);
- self->csize = n | C_INUSE;
-+ calculate_checksum(self, NULL);
-+ unlock(g_mem_lock);
- return 1;
- }
-
-@@ -272,11 +281,14 @@ static void trim(struct chunk *self, size_t n)
-
- next = NEXT_CHUNK(self);
- split = (void *)((char *)self + n);
--
-+ lock(g_mem_lock);
- split->psize = n | C_INUSE;
- split->csize = n1-n | C_INUSE;
- next->psize = n1-n | C_INUSE;
-+ calculate_checksum(split, next);
- self->csize = n | C_INUSE;
-+ calculate_checksum(self, NULL);
-+ unlock(g_mem_lock);
-
- __bin_chunk(split);
- }
-@@ -290,12 +302,27 @@ void *malloc(size_t n)
-
- if (n > MMAP_THRESHOLD) {
- size_t len = n + OVERHEAD + PAGE_SIZE - 1 & -PAGE_SIZE;
-+ if (g_enable_check) {
-+ /* Allocate two more pages for protection, loacted at the head and tail of user memory respectively */
-+ len += PAGE_SIZE << 1;
-+ }
- char *base = __mmap(0, len, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- if (base == (void *)-1) return 0;
-+ if (g_enable_check) {
-+ if (mprotect(base, PAGE_SIZE, PROT_NONE) ||
-+ mprotect(base + len - PAGE_SIZE, PAGE_SIZE, PROT_NONE)) {
-+ printf("%s %d, mprotect failed, err: %s!\n", __func__, __LINE__, strerror(errno));
-+ }
-+ base += PAGE_SIZE;
-+ }
- c = (void *)(base + SIZE_ALIGN - OVERHEAD);
- c->csize = len - (SIZE_ALIGN - OVERHEAD);
- c->psize = SIZE_ALIGN - OVERHEAD;
-+ if (g_enable_check) {
-+ c->csize -= PAGE_SIZE << 1;
-+ insert_node(CHUNK_TO_MEM(c), CHUNK_SIZE(c));
-+ }
- return CHUNK_TO_MEM(c);
- }
-
-@@ -306,10 +333,13 @@ void *malloc(size_t n)
- c = expand_heap(n);
- if (!c) return 0;
- if (alloc_rev(c)) {
-+ lock(g_mem_lock);
- struct chunk *x = c;
- c = PREV_CHUNK(c);
- NEXT_CHUNK(x)->psize = c->csize =
- x->csize + CHUNK_SIZE(c);
-+ calculate_checksum(c, NEXT_CHUNK(x));
-+ unlock(g_mem_lock);
- }
- break;
- }
-@@ -326,6 +356,9 @@ void *malloc(size_t n)
-
- /* Now patch up in case we over-allocated */
- trim(c, n);
-+ if (g_enable_check) {
-+ insert_node(CHUNK_TO_MEM(c), CHUNK_SIZE(c));
-+ }
-
- return CHUNK_TO_MEM(c);
- }
-@@ -385,13 +418,23 @@ void *realloc(void *p, size_t n)
- size_t oldlen = n0 + extra;
- size_t newlen = n + extra;
- /* Crash on realloc of freed chunk */
-- if (extra & 1) a_crash();
-+ if (extra & 1) {
-+ if (g_enable_check) {
-+ get_free_trace(CHUNK_TO_MEM(self));
-+ a_crash();
-+ } else {
-+ a_crash();
-+ }
-+ }
- if (newlen < PAGE_SIZE && (new = malloc(n-OVERHEAD))) {
- n0 = n;
- goto copy_free_ret;
- }
- newlen = (newlen + PAGE_SIZE-1) & -PAGE_SIZE;
- if (oldlen == newlen) return p;
-+ if (g_enable_check) {
-+ goto copy_realloc;
-+ }
- base = __mremap(base, oldlen, newlen, MREMAP_MAYMOVE);
- if (base == (void *)-1)
- goto copy_realloc;
-@@ -417,13 +460,25 @@ void *realloc(void *p, size_t n)
- self = PREV_CHUNK(self);
- n1 += CHUNK_SIZE(self);
- }
-+ lock(g_mem_lock);
- self->csize = n1 | C_INUSE;
- next->psize = n1 | C_INUSE;
-+ calculate_checksum(self, next);
-+ unlock(g_mem_lock);
-
- /* If we got enough space, split off the excess and return */
- if (n <= n1) {
- //memmove(CHUNK_TO_MEM(self), p, n0-OVERHEAD);
- trim(self, n);
-+ if (g_enable_check) {
-+ int status = delete_node(p);
-+ if (status != 0) {
-+ get_free_trace(CHUNK_TO_MEM(self));
-+ a_crash();
-+ }
-+ insert_node(CHUNK_TO_MEM(self), CHUNK_SIZE(self));
-+ }
-+
- return CHUNK_TO_MEM(self);
- }
-
-@@ -431,6 +486,7 @@ copy_realloc:
- /* As a last resort, allocate a new chunk and copy to it. */
- new = malloc(n-OVERHEAD);
- if (!new) return 0;
-+ n0 = (n0 > n) ? n : n0;
- copy_free_ret:
- memcpy(new, p, n0-OVERHEAD);
- free(CHUNK_TO_MEM(self));
-@@ -451,8 +507,11 @@ void __bin_chunk(struct chunk *self)
-
- for (;;) {
- if (self->psize & next->csize & C_INUSE) {
-+ lock(g_mem_lock);
- self->csize = final_size | C_INUSE;
- next->psize = final_size | C_INUSE;
-+ calculate_checksum(self, next);
-+ unlock(g_mem_lock);
- i = bin_index(final_size);
- lock_bin(i);
- lock(mal.free_lock);
-@@ -482,8 +541,11 @@ void __bin_chunk(struct chunk *self)
- if (!(mal.binmap & 1ULL<csize = final_size;
- next->psize = final_size;
-+ calculate_checksum(self, next);
-+ unlock(g_mem_lock);
- unlock(mal.free_lock);
-
- self->next = BIN_TO_CHUNK(i);
-@@ -512,7 +574,18 @@ static void unmap_chunk(struct chunk *self)
- char *base = (char *)self - extra;
- size_t len = CHUNK_SIZE(self) + extra;
- /* Crash on double free */
-- if (extra & 1) a_crash();
-+ if (extra & 1) {
-+ if (g_enable_check) {
-+ get_free_trace(CHUNK_TO_MEM(self));
-+ a_crash();
-+ } else {
-+ a_crash();
-+ }
-+ }
-+ if (g_enable_check) {
-+ base -= PAGE_SIZE;
-+ len += PAGE_SIZE << 1;
-+ }
- __munmap(base, len);
- }
-
-@@ -521,28 +594,54 @@ void free(void *p)
- if (!p) return;
-
- struct chunk *self = MEM_TO_CHUNK(p);
-+ if (g_enable_check) {
-+ if (!IS_MMAPPED(self)) {
-+ check_chunk_integrity(self);
-+ }
-+ int status = delete_node(p);
-+ if (status != 0) {
-+ get_free_trace(p);
-+ a_crash();
-+ }
-+ }
-
- if (IS_MMAPPED(self))
- unmap_chunk(self);
-- else
-+ else {
-+ if (g_enable_check) {
-+ insert_free_tail(self);
-+ if (g_recycle_size >= RECYCLE_SIZE_MAX) {
-+ clean_recycle_list(false);
-+ return;
-+ }
-+ if (g_recycle_num < RECYCLE_MAX) {
-+ return;
-+ }
-+ self = get_free_head();
-+ }
- __bin_chunk(self);
-+ }
- }
-
- void __malloc_donate(char *start, char *end)
- {
-- size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD);
-+ size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - BLOCK_HEAD);
- size_t align_end_down = (SIZE_ALIGN-1) & (uintptr_t)end;
-
- /* Getting past this condition ensures that the padding for alignment
- * and header overhead will not overflow and will leave a nonzero
- * multiple of SIZE_ALIGN bytes between start and end. */
-- if (end - start <= OVERHEAD + align_start_up + align_end_down)
-+ if (end - start <= BLOCK_HEAD + align_start_up + align_end_down)
- return;
-- start += align_start_up + OVERHEAD;
-+ start += align_start_up + BLOCK_HEAD;
- end -= align_end_down;
-
-+ lock(g_mem_lock);
- struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end);
- c->psize = n->csize = C_INUSE;
- c->csize = n->psize = C_INUSE | (end-start);
-+ calculate_checksum(c, n);
-+ insert_block_list(c);
-+ unlock(g_mem_lock);
- __bin_chunk(c);
- }
-diff --git a/src/malloc/memalign.c b/src/malloc/memalign.c
-index cf9dfbda..a37c5444 100644
---- a/src/malloc/memalign.c
-+++ b/src/malloc/memalign.c
-@@ -1,8 +1,24 @@
- #include
- #include
- #include
-+#include "libc.h"
-+#include "pthread_impl.h"
- #include "malloc_impl.h"
-
-+static inline void lock(volatile int *lk)
-+{
-+ if (libc.threads_minus_1)
-+ while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
-+}
-+
-+static inline void unlock(volatile int *lk)
-+{
-+ if (lk[0]) {
-+ a_store(lk, 0);
-+ if (lk[1]) __wake(lk, 1, 1);
-+ }
-+}
-+
- void *__memalign(size_t align, size_t len)
- {
- unsigned char *mem, *new;
-@@ -29,11 +45,22 @@ void *__memalign(size_t align, size_t len)
- struct chunk *c = MEM_TO_CHUNK(mem);
- struct chunk *n = MEM_TO_CHUNK(new);
-
-+ if (g_enable_check) {
-+ int status = delete_node(mem);
-+ if (status != 0) {
-+ get_free_trace(mem);
-+ a_crash();
-+ }
-+ }
-+
- if (IS_MMAPPED(c)) {
- /* Apply difference between aligned and original
- * address to the "extra" field of mmapped chunk. */
- n->psize = c->psize + (new-mem);
- n->csize = c->csize - (new-mem);
-+ if (g_enable_check) {
-+ insert_node(CHUNK_TO_MEM(n), CHUNK_SIZE(n));
-+ }
- return new;
- }
-
-@@ -44,8 +71,15 @@ void *__memalign(size_t align, size_t len)
- * difference between the aligned and original addresses, and
- * the resulting size copied to its header. A new header and
- * footer are written for the split-off part to be freed. */
-+ lock(g_mem_lock);
- n->psize = c->csize = C_INUSE | (new-mem);
- n->csize = t->psize -= new-mem;
-+ calculate_checksum(c, n);
-+ calculate_checksum(NULL, t);
-+ unlock(g_mem_lock);
-+ if (g_enable_check) {
-+ insert_node(CHUNK_TO_MEM(n), CHUNK_SIZE(n));
-+ }
-
- __bin_chunk(c);
- return new;
-diff --git a/src/malloc/memory_check.c b/src/malloc/memory_check.c
-new file mode 100644
-index 00000000..6ef7e750
---- /dev/null
-+++ b/src/malloc/memory_check.c
-@@ -0,0 +1,831 @@
-+#define _GNU_SOURCE
-+#include
-+#include
-+#include
-+#include
-+#include
-+#include
-+#include
-+#include "libc.h"
-+#include "atomic.h"
-+#include "pthread_impl.h"
-+#include "malloc_impl.h"
-+
-+#if defined(__GNUC__) && defined(__PIC__)
-+#define inline inline __attribute__((always_inline))
-+#endif
-+
-+bool g_enable_check = false;
-+int g_recycle_num;
-+size_t g_recycle_size;
-+int g_mem_lock[2];
-+static struct chunk recycle_list;
-+static struct heap_block block_list;
-+
-+static struct {
-+ struct stat_bin bins[PTHREAD_NUM_MAX];
-+ struct stat_bin free_list;
-+ size_t p_total_size;
-+ size_t peak_size;
-+ char *f_path;
-+ char f_path_buf[PATH_MAX];
-+ int fd;
-+ bool verbose;
-+} mem_stat;
-+
-+static inline void lock(volatile int *lk)
-+{
-+ if (libc.threads_minus_1)
-+ while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
-+}
-+
-+static inline void unlock(volatile int *lk)
-+{
-+ if (lk[0]) {
-+ a_store(lk, 0);
-+ if (lk[1]) __wake(lk, 1, 1);
-+ }
-+}
-+
-+static inline void lock_stat_bin(int tid)
-+{
-+ lock(mem_stat.bins[tid].lock);
-+ if (!mem_stat.bins[tid].head.next)
-+ mem_stat.bins[tid].head.next = mem_stat.bins[tid].head.prev = &mem_stat.bins[tid].head;
-+}
-+
-+static inline void unlock_stat_bin(int tid)
-+{
-+ unlock(mem_stat.bins[tid].lock);
-+}
-+
-+static void insert_free_list(struct node *node)
-+{
-+ struct list *list = NULL;
-+
-+ list = mem_stat.free_list.head.prev;
-+ node->list.prev = list;
-+ node->list.next = list->next;
-+ list->next = &node->list;
-+ node->list.next->prev = &node->list;
-+}
-+
-+static int try_delete_node(int tid, void *ptr)
-+{
-+ struct list *list = NULL;
-+ struct node *node = NULL;
-+
-+ lock_stat_bin(tid);
-+ for (list = mem_stat.bins[tid].head.next; list != &mem_stat.bins[tid].head; list = list->next) {
-+ node = (struct node *)((uintptr_t)list - (uint32_t)&((struct node *)0)->list);
-+ if (node->ptr != ptr) {
-+ continue;
-+ }
-+ list->prev->next = list->next;
-+ list->next->prev = list->prev;
-+ mem_stat.bins[tid].t_total_size -= node->size;
-+ insert_free_list(node);
-+ mem_stat.p_total_size -= node->size;
-+ unlock_stat_bin(tid);
-+ return 0;
-+ }
-+ unlock_stat_bin(tid);
-+ return -1;
-+}
-+
-+int delete_node(void *ptr)
-+{
-+ int tid = ((struct pthread *)pthread_self())->tid;
-+ int status, i;
-+
-+ lock(g_mem_lock);
-+ status = try_delete_node(tid, ptr);
-+ if (status == 0) {
-+ unlock(g_mem_lock);
-+ return 0;
-+ }
-+
-+ for (i = 0; i < PTHREAD_NUM_MAX; ++i) {
-+ if (i == tid) {
-+ continue;
-+ }
-+ status = try_delete_node(i, ptr);
-+ if (status == 0) {
-+ unlock(g_mem_lock);
-+ return 0;
-+ }
-+ }
-+ unlock(g_mem_lock);
-+ return -1;
-+}
-+
-+static struct node *expand_mem(void)
-+{
-+ struct node *ptr = NULL;
-+ struct node *node = NULL;
-+ size_t node_len = sizeof(struct node);
-+ int n_node = PAGE_SIZE / node_len;
-+ int i;
-+
-+ ptr = __mmap(0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-+ if (ptr == MAP_FAILED) {
-+ printf("%s %d, map failed, err: %s\n", __func__, __LINE__, strerror(errno));
-+ return NULL;
-+ }
-+
-+ for (i = 1; i < n_node; ++i) {
-+ node = (struct node *)((uintptr_t)ptr + i * node_len);
-+ insert_free_list(node);
-+ }
-+
-+ return ptr;
-+}
-+
-+static struct node *alloc_node(void)
-+{
-+ struct list *list = NULL;
-+ struct node *node = NULL;
-+ int ret;
-+
-+ if (!mem_stat.free_list.head.next) {
-+ mem_stat.free_list.head.next = mem_stat.free_list.head.prev = &mem_stat.free_list.head;
-+ }
-+
-+ for (list = mem_stat.free_list.head.next; list != &mem_stat.free_list.head; list = list->next) {
-+ node = (struct node *)((uintptr_t)list - (uint32_t)&((struct node *)0)->list);
-+ list->prev->next = list->next;
-+ list->next->prev = list->prev;
-+ return node;
-+ }
-+
-+ return expand_mem();
-+}
-+
-+static struct node *create_node(int tid, void *ptr, size_t size)
-+{
-+ pid_t pid = getpid();
-+ struct node *node = NULL;
-+ void *lr[BACKTRACE_DEPTH_MAX + BACKTRACE_OFFSET + 1] = { 0 };
-+ int nptr;
-+
-+ node = alloc_node();
-+ if (node == NULL) {
-+ return NULL;
-+ }
-+ mem_stat.p_total_size += size;
-+ mem_stat.peak_size = (mem_stat.peak_size < mem_stat.p_total_size) ? mem_stat.p_total_size : mem_stat.peak_size;
-+ node->tid = tid;
-+ node->pid = pid;
-+ node->ptr = ptr;
-+ node->size = size;
-+ nptr = backtrace(lr, BACKTRACE_DEPTH_MAX + BACKTRACE_OFFSET + 1);
-+ memcpy(node->lr, lr + BACKTRACE_OFFSET + 1, BACKTRACE_DEPTH_MAX * sizeof(void *));
-+ return node;
-+}
-+
-+void insert_node(void *ptr, size_t size)
-+{
-+ int tid = ((struct pthread *)pthread_self())->tid;
-+ struct list *list = NULL;
-+ struct node *node = NULL;
-+
-+ lock(g_mem_lock);
-+ node = create_node(tid, ptr, size);
-+ if (node == NULL) {
-+ unlock(g_mem_lock);
-+ return;
-+ }
-+
-+ lock_stat_bin(tid);
-+ mem_stat.bins[tid].t_total_size += size;
-+ list = mem_stat.bins[tid].head.prev;
-+ node->list.prev = list;
-+ node->list.next = list->next;
-+ list->next = &node->list;
-+ node->list.next->prev = &node->list;
-+ unlock_stat_bin(tid);
-+ unlock(g_mem_lock);
-+}
-+
-+static void file_path_init(void)
-+{
-+ char *pos = NULL;
-+ int len;
-+
-+ if (!mem_stat.f_path) {
-+ return;
-+ }
-+
-+ pos = strrchr(mem_stat.f_path, '/');
-+ if (pos) {
-+ len = pos - mem_stat.f_path + 1;
-+ strncpy(mem_stat.f_path_buf, mem_stat.f_path, PATH_MAX - 1);
-+ snprintf(mem_stat.f_path_buf + len, PATH_MAX - len, "pid(%d)_%s", getpid(), pos + 1);
-+ } else {
-+ snprintf(mem_stat.f_path_buf, PATH_MAX, "pid(%d)_%s", getpid(), mem_stat.f_path);
-+ }
-+}
-+
-+static bool get_file(void)
-+{
-+ if (!g_enable_check) {
-+ printf("You should call mem_check_init(char *) or use command line parameters, "
-+ "--mwatch or --mrecord , to call mem_check_init(char *) "
-+ "when executing your program.\n");
-+ return false;
-+ }
-+
-+ if (mem_stat.verbose) {
-+ return true;
-+ }
-+
-+ file_path_init();
-+ if (!access(mem_stat.f_path_buf, 0)) {
-+ return true;
-+ }
-+ mem_stat.fd = open(mem_stat.f_path_buf, O_RDWR | O_CREAT);
-+ if (mem_stat.fd < 0) {
-+ printf("err: %s create failed, memory info will output from serial port!\n", mem_stat.f_path_buf);
-+ mem_stat.verbose = true;
-+ }
-+ return true;
-+}
-+
-+static int get_backtrace_info(void **buffer, int nptr, int fd, bool verbose, bool checkpoint)
-+{
-+ int i, ret;
-+ char str_buf[ITEM_BUFFER_SIZE];
-+ Dl_info info = { 0 };
-+ bool checkpoint_head = false;
-+ int checkpoint_trace_num = 0;
-+ bool symbol_found;
-+
-+ for (i = 0; i < nptr; ++i) {
-+ symbol_found = true;
-+ dladdr((void *)buffer[i], &info);
-+ if ((info.dli_fname == NULL) || (info.dli_fname[0] == '\0')) {
-+ symbol_found = false;
-+ }
-+
-+ if (checkpoint && !checkpoint_head) {
-+ checkpoint_head = true;
-+ if (verbose) {
-+ printf(" [Check point]:\n");
-+ } else {
-+ snprintf(str_buf, ITEM_BUFFER_SIZE, " [Check point]:\n");
-+ ret = write(fd, str_buf, strlen(str_buf));
-+ if (ret != strlen(str_buf)) {
-+ goto err;
-+ }
-+ }
-+ }
-+ if (verbose) {
-+ symbol_found ?
-+ printf("\t#%02d: <%s+%#x>[%#x] -> %s\n", i, info.dli_sname, (uintptr_t)buffer[i] -
-+ (uintptr_t)info.dli_saddr, (uintptr_t)buffer[i] - (uintptr_t)info.dli_fbase, info.dli_fname) :
-+ printf("\t#%02d: %#x\n", i, buffer[i]);
-+ } else {
-+ symbol_found ?
-+ snprintf(str_buf, ITEM_BUFFER_SIZE, "\t#%02d: <%s+%#x>[%#x] -> %s\n", i, info.dli_sname,
-+ (uintptr_t)buffer[i] - (uintptr_t)info.dli_saddr, (uintptr_t)buffer[i] - (uintptr_t)info.dli_fbase,
-+ info.dli_fname) :
-+ snprintf(str_buf, ITEM_BUFFER_SIZE, "\t#%02d: %#x\n", i, buffer[i]);
-+ ret = write(fd, str_buf, strlen(str_buf));
-+ if (ret != strlen(str_buf)) {
-+ goto err;
-+ }
-+ }
-+ if (checkpoint) {
-+ checkpoint_trace_num++;
-+ if (checkpoint_trace_num == CHECK_POINT_TRACE_MAX) {
-+ break;
-+ }
-+ }
-+ }
-+ return 0;
-+err:
-+ printf("Write failed, err: %s\n", strerror(errno));
-+ return ret;
-+}
-+
-+static int print_integrity_info(struct node *node)
-+{
-+ int ret;
-+ char buffer[ITEM_BUFFER_SIZE];
-+ char *str = "The possible attacker was allocated from:";
-+
-+ if (mem_stat.verbose) {
-+ printf("\n==PID:%d== Memory integrity information:\n", getpid());
-+ printf(" [TID:%d PID:%d allocated addr: %#x, size: %#x] %s\n", node->tid, node->pid, node->ptr, node->size,
-+ str);
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\n==PID:%d== Memory integrity information:\n", getpid());
-+ ret = write(mem_stat.fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err;
-+ }
-+ snprintf(buffer, ITEM_BUFFER_SIZE, " [TID:%d PID:%d allocated addr: %#x, size: %#x] %s\n", node->tid, node->pid,
-+ node->ptr, node->size, str);
-+ ret = write(mem_stat.fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err;
-+ }
-+ }
-+ return 0;
-+err:
-+ printf("Write failed, err: %s\n", strerror(errno));
-+ return ret;
-+}
-+
-+static int check_mem_integrity(int tid, void *ptr)
-+{
-+ struct list *list = NULL;
-+ struct node *node = NULL;
-+ int nptr = 0;
-+
-+ lock_stat_bin(tid);
-+ for (list = mem_stat.bins[tid].head.next; list != &mem_stat.bins[tid].head; list = list->next) {
-+ node = (struct node *)((uintptr_t)list - (uint32_t)&((struct node *)0)->list);
-+ if (node->ptr != ptr) {
-+ continue;
-+ }
-+ if (print_integrity_info(node) != 0) {
-+ unlock_stat_bin(tid);
-+ printf("Memory integrity check failed!\n");
-+ return -1;
-+ }
-+ while (node->lr[nptr] != NULL) {
-+ ++nptr;
-+ if (nptr == BACKTRACE_DEPTH_MAX) {
-+ break;
-+ }
-+ }
-+ if ((nptr == 0) || (get_backtrace_info(node->lr, nptr, mem_stat.fd, mem_stat.verbose, false) != 0)) {
-+ unlock_stat_bin(tid);
-+ printf("get backtrace failed!\n");
-+ return -1;
-+ }
-+ if (!mem_stat.verbose) {
-+ printf("Memory integrity information saved in %s\n", mem_stat.f_path_buf);
-+ }
-+ unlock_stat_bin(tid);
-+ return 0;
-+ }
-+ unlock_stat_bin(tid);
-+ return 1;
-+}
-+
-+static void get_integrity_info(void *ptr)
-+{
-+ int i, status;
-+ int tid = ((struct pthread *)pthread_self())->tid;
-+
-+ status = check_mem_integrity(tid, ptr);
-+ if (status != 1) {
-+ return;
-+ }
-+
-+ for (i = 0; i < PTHREAD_NUM_MAX; ++i) {
-+ if (i == tid) {
-+ continue;
-+ }
-+ status = check_mem_integrity(i, ptr);
-+ if (status != 1) {
-+ return;
-+ }
-+ }
-+}
-+
-+bool is_invalid(struct chunk *self)
-+{
-+ uint32_t checksum;
-+ checksum = CHUNK_SIZE(self) ^ CHUNK_PSIZE(self) ^ NODE_MAGIC;
-+ if (checksum != self->checksum) {
-+ return true;
-+ } else {
-+ return false;
-+ }
-+}
-+
-+void calculate_checksum(struct chunk *cur, struct chunk *next)
-+{
-+ if (cur) {
-+ cur->checksum = CHUNK_SIZE(cur) ^ CHUNK_PSIZE(cur) ^ NODE_MAGIC;
-+ }
-+
-+ if (next) {
-+ next->checksum = CHUNK_SIZE(next) ^ CHUNK_PSIZE(next) ^ NODE_MAGIC;
-+ }
-+}
-+
-+void check_heap_integrity(void)
-+{
-+ struct chunk *cur = NULL;
-+ struct chunk *next = NULL;
-+ struct heap_block *block = NULL;
-+
-+ if (!block_list.next) {
-+ return;
-+ }
-+
-+ lock(g_mem_lock);
-+ if (!get_file()) {
-+ unlock(g_mem_lock);
-+ return;
-+ }
-+ block = block_list.next;
-+ while (block != &block_list) {
-+ cur = BLOCK_TO_CHUNK(block);
-+ do {
-+ next = NEXT_CHUNK(cur);
-+ if (is_invalid(next)) {
-+ get_integrity_info(CHUNK_TO_MEM(cur));
-+ unlock(g_mem_lock);
-+ a_crash();
-+ }
-+ cur = next;
-+ } while (CHUNK_SIZE(next));
-+ block = block->next;
-+ }
-+ unlock(g_mem_lock);
-+ printf("\nCheck heap integrity ok!\n");
-+}
-+
-+void check_chunk_integrity(struct chunk *cur)
-+{
-+ struct chunk *next = NULL;
-+
-+ if (is_invalid(cur)) {
-+ check_heap_integrity();
-+ }
-+
-+ lock(g_mem_lock);
-+ next = NEXT_CHUNK(cur);
-+ if ((CHUNK_SIZE(next)) && is_invalid(next)) {
-+ get_integrity_info(CHUNK_TO_MEM(cur));
-+ unlock(g_mem_lock);
-+ a_crash();
-+ }
-+ unlock(g_mem_lock);
-+}
-+
-+void insert_block_list(struct chunk *self)
-+{
-+ struct heap_block *block = CHUNK_TO_BLOCK(self);
-+ struct heap_block *cur = NULL;
-+
-+ if (!block_list.next) {
-+ block_list.next = block_list.prev = &block_list;
-+ }
-+
-+ cur = block_list.prev;
-+ block->next = cur->next;
-+ block->prev = cur;
-+ cur->next = block;
-+ block_list.prev = block;
-+}
-+
-+void get_free_trace(void *ptr)
-+{
-+ void *lr[BACKTRACE_DEPTH_MAX + BACKTRACE_OFFSET] = { 0 };
-+ int tid = ((struct pthread *)pthread_self())->tid;
-+ char buffer[ITEM_BUFFER_SIZE];
-+ int nptr, ret;
-+
-+ lock(g_mem_lock);
-+ if (!get_file()) {
-+ unlock(g_mem_lock);
-+ return;
-+ }
-+ if (mem_stat.verbose) {
-+ printf("\n==PID:%d== double free\n", getpid());
-+ printf(" [TID:%d freed addr: %#x]:\n", tid, ptr);
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\n==PID:%d== double free\n", getpid());
-+ ret = write(mem_stat.fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err;
-+ }
-+ snprintf(buffer, ITEM_BUFFER_SIZE, " [TID:%d freed addr: %#x]:\n", tid, ptr);
-+ ret = write(mem_stat.fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err;
-+ }
-+ }
-+
-+ nptr = backtrace(lr, BACKTRACE_DEPTH_MAX + BACKTRACE_OFFSET);
-+ if (get_backtrace_info(lr + BACKTRACE_OFFSET, nptr - BACKTRACE_OFFSET, mem_stat.fd, mem_stat.verbose, false) != 0) {
-+ printf("Trace failed\n");
-+ }
-+
-+ unlock(g_mem_lock);
-+ return;
-+err:
-+ printf("Write failed, err: %s\n", strerror(errno));
-+ unlock(g_mem_lock);
-+ return;
-+}
-+
-+void watch_mem(void)
-+{
-+ int tid, ret;
-+ char buffer[ITEM_BUFFER_SIZE];
-+ void *lr[BACKTRACE_DEPTH_MAX + BACKTRACE_OFFSET] = { 0 };
-+ pid_t pid = getpid();
-+ int nptr;
-+
-+ lock(g_mem_lock);
-+ if (!get_file()) {
-+ unlock(g_mem_lock);
-+ return;
-+ }
-+ if (mem_stat.verbose) {
-+ printf("\n==PID:%d== Heap memory statistics(bytes):\n", pid);
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\n==PID:%d== Heap memory statistics(bytes):\n", pid);
-+ ret = write(mem_stat.fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err2;
-+ }
-+ }
-+ nptr = backtrace(lr, BACKTRACE_DEPTH_MAX + BACKTRACE_OFFSET);
-+ if (get_backtrace_info(lr + BACKTRACE_OFFSET, nptr - BACKTRACE_OFFSET, mem_stat.fd, mem_stat.verbose, true) != 0) {
-+ printf("Check failed\n");
-+ unlock(g_mem_lock);
-+ return;
-+ }
-+ for (tid = 0; tid < PTHREAD_NUM_MAX; ++tid) {
-+ lock_stat_bin(tid);
-+ if (mem_stat.bins[tid].t_total_size == 0) {
-+ unlock_stat_bin(tid);
-+ continue;
-+ }
-+ if (mem_stat.verbose) {
-+ printf("\n [TID: %d, Used: %#x]", tid, mem_stat.bins[tid].t_total_size);
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\n [TID: %d, Used: %#x]", tid, mem_stat.bins[tid].t_total_size);
-+ ret = write(mem_stat.fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err1;
-+ }
-+ }
-+ unlock_stat_bin(tid);
-+ }
-+ if (mem_stat.verbose) {
-+ printf("\n\n==PID:%d== Total heap: %#x byte(s), Peak: %#x byte(s)\n", pid,
-+ mem_stat.p_total_size, mem_stat.peak_size);
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\n\n==PID:%d== Total heap: %#x byte(s), Peak: %#x byte(s)\n", pid,
-+ mem_stat.p_total_size, mem_stat.peak_size);
-+ ret = write(mem_stat.fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err2;
-+ }
-+ }
-+ if (!mem_stat.verbose) {
-+ printf("Memory statistics information saved in %s\n", mem_stat.f_path_buf);
-+ }
-+ unlock(g_mem_lock);
-+ return;
-+err1:
-+ unlock_stat_bin(tid);
-+err2:
-+ printf("Write failed, err: %s\n", strerror(errno));
-+ unlock(g_mem_lock);
-+}
-+
-+static int get_node_info(struct node *node, int fd, bool verbose, bool mem_leak_exist)
-+{
-+ char buffer[ITEM_BUFFER_SIZE];
-+ void *lr[BACKTRACE_DEPTH_MAX + BACKTRACE_OFFSET] = { 0 };
-+ int nptr, ret;
-+
-+ if (!mem_leak_exist) {
-+ if (verbose) {
-+ printf("\n==PID:%d== Detected memory leak(s):\n", getpid());
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\n==PID:%d== Detected memory leak(s):\n", getpid());
-+ ret = write(fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err;
-+ }
-+ }
-+ nptr = backtrace(lr, BACKTRACE_DEPTH_MAX + BACKTRACE_OFFSET);
-+ if (get_backtrace_info(lr + BACKTRACE_OFFSET, nptr - BACKTRACE_OFFSET, mem_stat.fd, mem_stat.verbose, true) != 0) {
-+ printf("Check failed\n");
-+ goto err;
-+ }
-+ }
-+
-+ if (verbose) {
-+ printf("\n [TID:%d Leak:%#x byte(s)] Allocated from:\n", node->tid, node->size);
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\n [TID:%d Leak:%#x byte(s)] Allocated from:\n", node->tid, node->size);
-+ ret = write(fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ goto err;
-+ }
-+ }
-+ return 0;
-+err:
-+ printf("Write failed, err: %s\n", strerror(errno));
-+ return ret;
-+
-+}
-+
-+static void print_summary_info(size_t leak_size, size_t allocs, int fd, bool verbose, bool mem_leak_exist)
-+{
-+ char buffer[ITEM_BUFFER_SIZE];
-+ int ret;
-+
-+ if (!mem_leak_exist) {
-+ if (verbose) {
-+ printf("\nNo memory leak!\n");
-+ return;
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\nNo memory leak!\n");
-+ ret = write(fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ printf("Write failed, err: %s\n", strerror(errno));
-+ }
-+ return;
-+ }
-+ }
-+
-+ if (verbose) {
-+ printf("\n==PID:%d== SUMMARY: %#x byte(s) leaked in %d allocation(s).\n", getpid(), leak_size, allocs);
-+ } else {
-+ snprintf(buffer, ITEM_BUFFER_SIZE, "\n==PID:%d== SUMMARY: %#x byte(s) leaked in %d allocation(s).\n", getpid(),
-+ leak_size, allocs);
-+ ret = write(fd, buffer, strlen(buffer));
-+ if (ret != strlen(buffer)) {
-+ printf("Write failed, err: %s\n", strerror(errno));
-+ }
-+ }
-+}
-+
-+void check_leak(void)
-+{
-+ struct list *list = NULL;
-+ struct node *node = NULL;
-+ int tid, nptr;
-+ size_t leak_size = 0;
-+ size_t allocs = 0;
-+ bool mem_leak_exist = false;
-+ pid_t pid = getpid();
-+
-+ lock(g_mem_lock);
-+ if (!get_file()) {
-+ unlock(g_mem_lock);
-+ return;
-+ }
-+ for (tid = 0; tid < PTHREAD_NUM_MAX; ++tid) {
-+ lock_stat_bin(tid);
-+ for (list = mem_stat.bins[tid].head.next; list != &mem_stat.bins[tid].head; list = list->next) {
-+ node = (struct node *)((uintptr_t)list - (uint32_t)&((struct node *)0)->list);
-+ if (node->pid != pid) {
-+ continue;
-+ }
-+ if (get_node_info(node, mem_stat.fd, mem_stat.verbose, mem_leak_exist) != 0) {
-+ unlock_stat_bin(tid);
-+ unlock(g_mem_lock);
-+ printf("Check failed\n");
-+ return;
-+ }
-+ ++allocs;
-+ leak_size += node->size;
-+ mem_leak_exist = true;
-+ nptr = 0;
-+ while (node->lr[nptr] != NULL) {
-+ ++nptr;
-+ if (nptr == BACKTRACE_DEPTH_MAX) {
-+ break;
-+ }
-+ }
-+ if (nptr == 0) {
-+ continue;
-+ }
-+ if (get_backtrace_info(node->lr, nptr, mem_stat.fd, mem_stat.verbose, false) != 0) {
-+ unlock_stat_bin(tid);
-+ unlock(g_mem_lock);
-+ printf("Check failed\n");
-+ return;
-+ }
-+ }
-+ unlock_stat_bin(tid);
-+ }
-+ print_summary_info(leak_size, allocs, mem_stat.fd, mem_stat.verbose, mem_leak_exist);
-+ if (!mem_stat.verbose) {
-+ printf("Leak check information saved in %s\n", mem_stat.f_path_buf);
-+ }
-+ unlock(g_mem_lock);
-+}
-+
-+void mem_check_init(char *f_path)
-+{
-+ signal(35, watch_mem);
-+ signal(36, check_leak);
-+ signal(37, check_heap_integrity);
-+ g_enable_check = true;
-+ mem_stat.fd = -1;
-+ const char *string = "memory info will print to serial port!";
-+
-+ if (!f_path) {
-+ goto out;
-+ }
-+
-+ if (strlen(f_path) > (PATH_MAX - PREFIX_PLACE_HOLDER - 1)) {
-+ printf("file name: %s is too long, %s\n", f_path, string);
-+ goto out;
-+ }
-+ mem_stat.f_path = f_path;
-+ file_path_init();
-+ mem_stat.fd = open(mem_stat.f_path_buf, O_RDWR | O_CREAT | O_EXCL);
-+ if (mem_stat.fd < 0) {
-+ switch (errno) {
-+ case EEXIST:
-+ printf("file: %s is exist, %s\n", mem_stat.f_path_buf, string);
-+ goto out;
-+ default:
-+ printf("path: %s create failed, %s\n", mem_stat.f_path_buf, string);
-+ goto out;
-+ }
-+ }
-+ mem_stat.verbose = false;
-+ return;
-+
-+out:
-+ mem_stat.verbose = true;
-+}
-+
-+void mem_check_deinit()
-+{
-+ if (mem_stat.fd > 0) {
-+ close(mem_stat.fd);
-+ }
-+}
-+
-+void parse_argv(int argc, char *argv[])
-+{
-+
-+ if (argc <= 1) {
-+ return;
-+ }
-+
-+ if (!strcmp(argv[argc - 1], "--mwatch")) {
-+ mem_check_init(NULL);
-+ } else if ((argc > 2) && (!strcmp(argv[argc - 2], "--mrecord"))) {
-+ mem_check_init(argv[argc - 1]);
-+ } else if (!strcmp(argv[argc - 1], "--mrecord")) {
-+ printf("usage: --mrecord filepath\n");
-+ }
-+}
-+
-+void insert_free_tail(struct chunk *self)
-+{
-+ volatile struct chunk *cur = NULL;
-+ lock(g_mem_lock);
-+ if (!recycle_list.next) {
-+ recycle_list.next = recycle_list.prev = &recycle_list;
-+ }
-+ cur = recycle_list.prev;
-+ self->next = cur->next;
-+ self->prev = cur;
-+ cur->next = self;
-+ recycle_list.prev = self;
-+ memset(CHUNK_TO_MEM(self), FREE_MAGIC, CHUNK_SIZE(self) - OVERHEAD);
-+ ++g_recycle_num;
-+ g_recycle_size += CHUNK_SIZE(self);
-+ unlock(g_mem_lock);
-+}
-+
-+struct chunk *get_free_head(void)
-+{
-+ struct chunk *cur = NULL;
-+ lock(g_mem_lock);
-+ cur = recycle_list.next;
-+ if ((cur == NULL) || (cur == &recycle_list)) {
-+ unlock(g_mem_lock);
-+ return NULL;
-+ }
-+ recycle_list.next = cur->next;
-+ cur->next->prev = cur->prev;
-+ --g_recycle_num;
-+ g_recycle_size -= CHUNK_SIZE(cur);
-+ unlock(g_mem_lock);
-+ return cur;
-+}
-+
-+void clean_recycle_list(bool clean_all)
-+{
-+ struct chunk *self = NULL;
-+ self = get_free_head();
-+ while (self) {
-+ __bin_chunk(self);
-+ if ((!clean_all) && (g_recycle_size < RECYCLE_SIZE_MAX)) {
-+ break;
-+ }
-+ self = get_free_head();
-+ }
-+}
-+
diff --git a/build/liteos/thirdparty_headers.sh b/build/liteos/thirdparty_headers.sh
deleted file mode 100755
index 6c2ee30b454abcba4403ccea3f411b1cdfa9cfe8..0000000000000000000000000000000000000000
--- a/build/liteos/thirdparty_headers.sh
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/bin/bash
-
-#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
-#Licensed under the Apache License, Version 2.0 (the "License");
-#you may not use this file except in compliance with the License.
-#You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-#Unless required by applicable law or agreed to in writing, software
-#distributed under the License is distributed on an "AS IS" BASIS,
-#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#See the License for the specific language governing permissions and
-#limitations under the License.
-
-# This script is used to prepare header files for musl's libc.so.
-
-set -e
-
-PRJ_ROOT="${PWD}/../../../../../"
-LINUX_HDR="${PRJ_ROOT}/prebuilts/lite/sysroot/thirdparty/linux_headers_install"
-TMP_DIR_ORI="${PRJ_ROOT}/prebuilts/lite/sysroot/ohos_tmp_ori"
-TMP_DIR="${PRJ_ROOT}/prebuilts/lite/sysroot/ohos_tmp"
-if [ $# -eq 1 ]; then
- MUSL_DIR="$1/include"
-else
- MUSL_DIR="${PWD}/musl/include"
-fi
-export Z_BUILD_TOP="${PRJ_ROOT}"
-
-if [ ! -d "${LINUX_HDR}/asm" ] || [ ! -d "${LINUX_HDR}/asm-generic" ] || [ ! -d "${LINUX_HDR}/linux" ];then
- echo "please install headers first!!!"
- echo "see guide at ${SYSROOT}/../../thirdparty/README"
- exit 1
-fi
-
-mkdir -p ${TMP_DIR_ORI}
-mkdir -p ${TMP_DIR}
-
-mkdir -p ${TMP_DIR_ORI}/uapi/asm-generic
-mkdir -p ${TMP_DIR_ORI}/uapi/asm
-mkdir -p ${TMP_DIR_ORI}/uapi/linux
-
-cp ${LINUX_HDR}/asm-generic/bitsperlong.h ${TMP_DIR_ORI}/uapi/asm-generic
-cp ${LINUX_HDR}/asm-generic/int-ll64.h ${TMP_DIR_ORI}/uapi/asm-generic
-cp ${LINUX_HDR}/asm-generic/posix_types.h ${TMP_DIR_ORI}/uapi/asm-generic
-cp ${LINUX_HDR}/asm/bitsperlong.h ${TMP_DIR_ORI}/uapi/asm
-cp ${LINUX_HDR}/asm/posix_types.h ${TMP_DIR_ORI}/uapi/asm
-cp ${LINUX_HDR}/asm/types.h ${TMP_DIR_ORI}/uapi/asm
-cp ${LINUX_HDR}/linux/capability.h ${TMP_DIR_ORI}/uapi/linux
-cp ${LINUX_HDR}/linux/posix_types.h ${TMP_DIR_ORI}/uapi/linux
-cp ${LINUX_HDR}/linux/stddef.h ${TMP_DIR_ORI}/uapi/linux
-cp ${LINUX_HDR}/linux/types.h ${TMP_DIR_ORI}/uapi/linux
-
-echo "#ifndef _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
-echo "#define _UAPI_LINUX_COMPILER_H" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
-echo "#define __user" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
-echo "#endif" >> ${TMP_DIR_ORI}/uapi/linux/compiler.h
-
-pushd ${PRJ_ROOT}
-python prebuilts/lite/sysroot/build/liteos/update_headers.py 2>/dev/null
-popd
-
-cp -rf ${TMP_DIR}/uapi/* ${MUSL_DIR}/
-rm -rf ${TMP_DIR_ORI}
-rm -rf ${TMP_DIR}
diff --git a/build/liteos/update_headers.py b/build/liteos/update_headers.py
deleted file mode 100755
index 343a1edf6c6ae7ddcb530af102b4c2859ea59419..0000000000000000000000000000000000000000
--- a/build/liteos/update_headers.py
+++ /dev/null
@@ -1,229 +0,0 @@
-#!/usr/bin/env python
-#-*-coding:utf-8-*-
-
-#Copyright (c) 2020-2021 Huawei Device Co., Ltd.
-#Licensed under the Apache License, Version 2.0 (the "License");
-#you may not use this file except in compliance with the License.
-#You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-#Unless required by applicable law or agreed to in writing, software
-#distributed under the License is distributed on an "AS IS" BASIS,
-#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#See the License for the specific language governing permissions and
-#limitations under the License.
-
-# Perform for Z kernel headers
-
-import sys
-import os
-import getopt
-import subprocess
-import time
-import string
-import re
-import glob
-
-# /*..*/ //...
-Rule1 = "(\/\*(\s|.)*?\*\/)|(\/\/.*)"
-c1=re.compile(Rule1)
-
-#use list for order
-key_list = [
-# grep key, gerp dir, sed key, sed replace
- ["CONFIG_64BIT", ".", "CONFIG_64BIT", "__LP64__"],
- ["__unused;", ".", "__unused;", "__linux_unused;"],
- ["__unused\[", ".", "__unused\[", "__linux_unused["],
- [" private;", ".", " private;", " __linux_private;"],
- ["\*virtual;", ".", "\*virtual;", "\* __linux_virtual;"],
- ["struct msqid_ds", ".", "struct msqid_ds", "struct __kernel_legacy_msqid_ds"],
- ["struct semid_ds", ".", "struct semid_ds", "struct __kernel_legacy_semid_ds"],
- ["struct shmid_ds", ".", "struct shmid_ds", "struct __kernel_legacy_shmid_ds"],
- ["struct ipc_perm", ".", "struct ipc_perm", "struct __kernel_legacy_ipc_perm"],
- ["union semun", ".", "union semun", "union __kernel_legacy_semun"],
- ["_NSIG", ".", "_NSIG", "_KERNEL__NSIG"],
- ["_KERNEL__NSIG_", ".", "_KERNEL__NSIG_", "_NSIG_"],
- ["#define NSIG\s", ".", "#define NSIG", "#define _KERNEL_NSIG"],
- ["SIGRTMIN", ".", "SIGRTMIN", "__SIGRTMIN"],
- ["SIGRTMAX", ".", "SIGRTMAX", "__SIGRTMAX"],
- ["struct udphdr", ".", "struct udphdr", "struct __kernel_udphdr"],
- ["struct __kernel_sockaddr_storage", ".", "struct __kernel_sockaddr_storage", "struct sockaddr_storage"],
- ["off_t", "asm-mips/asm/stat.h", "off_t", "__kernel_off_t"],
- ["#ifndef __EXPORTED_HEADERS__", ".", "#ifndef __EXPORTED_HEADERS__", "#if 0 \/*__EXPORTED_HEADERS__*\/"],
- ["#ifndef __KERNEL_STRICT_NAMES", ".", "#ifndef __KERNEL_STRICT_NAMES", "#if 0 \/*__KERNEL_STRICT_NAMES*\/"],
- ["#ifdef __CHECKER__", ".", "#ifdef __CHECKER__", "#if 0 \/*__CHECKER__*\/"],
- ["#ifdef __HAVE_BUILTIN_BSWAP16__", ".", "#ifdef __HAVE_BUILTIN_BSWAP16__", "#if 1 \/*__HAVE_BUILTIN_BSWAP16__*\/"],
- ["#ifdef __HAVE_BUILTIN_BSWAP32__", ".", "#ifdef __HAVE_BUILTIN_BSWAP32__", "#if 1 \/*__HAVE_BUILTIN_BSWAP32__*\/"],
- ["#ifdef __HAVE_BUILTIN_BSWAP64__", ".", "#ifdef __HAVE_BUILTIN_BSWAP64__", "#if 1 \/*__HAVE_BUILTIN_BSWAP64__*\/"],
- ["#if defined(__ARMEB__)", "asm-arm", "#if defined(__ARMEB__)", "#if 0 \/*__ARMEB__*\/"],
- ["#ifdef __ARMEB__", "asm-arm", "#ifdef __ARMEB__", "#if 0 \/*__ARMEB__*\/"],
- ["defined(__ARM_EABI__)", "asm-arm", "defined(__ARM_EABI__)", "1 \/*defined(__ARM_EABI__)*\/"],
- ["#ifdef __MIPSEB__", "asm-mips", "#ifdef __MIPSEB__", "#if 0 \/*__MIPSEB__*\/"],
- ["#elif defined (__MIPSEB__)", "asm-mips", "#elif defined (__MIPSEB__)", "#elif 0 \/*__MIPSEB__*\/"],
- ["#if defined(__MIPSEB__)", "asm-mips", "#if defined(__MIPSEB__)", "#if 0 \/*__MIPSEB__*\/"],
- ["#elif defined(__MIPSEL__)", "asm-mips", "#elif defined(__MIPSEL__)", "#elif 1 \/*__MIPSEL__*\/"],
- ["#elif defined (__MIPSEL__)", "asm-mips", "#elif defined (__MIPSEL__)", "#elif 1 \/*__MIPSEL__*\/"],
- ["\!defined(__SANE_USERSPACE_TYPES__)", "asm-mips", "\!defined(__SANE_USERSPACE_TYPES__)", "0 \/*__SANE_USERSPACE_TYPES__*\/"],
- ["\/\*.*\*\/", ".", "\/\*.*\*\/", ""],
- ]
-
-def deal_file(src):
- # file exist or not
- if not os.path.exists(src):
- print('Error: file - %s doesn\'t exist.'% src)
- return False
- if os.path.islink(src):
- print('Error: file - %s is a link.'% src)
- return False
- filetype = (os.path.splitext(src))[1]
- if not filetype in ['.c','.h','.cpp','.hh','.cc']:
- return False
- try:
- if not os.access(src, os.W_OK):
- os.chmod(src, 0o664)
- except:
- print('Error: you can not chang %s\'s mode.'% src)
-
- # del all comments
- inputf = open(src, 'r')
- outputfilename = (os.path.splitext(src))[0] + '_no_comment'+filetype
- outputf = open(outputfilename, 'w')
-
- lines=inputf.read()
- inputf.close()
- lines=re.sub(Rule1,"",lines)
- outputf.write(lines)
- outputf.close()
-
- #del right space & blank line
- os.remove(src)
- inputf = open(outputfilename, 'r')
- outputf = open(src, 'w')
- #write head info
- outputf.write("/*\n")
- outputf.write(" * This header was generated from the Linux kernel headers by update_headers.py,\n")
- outputf.write(" * to provide necessary information from kernel to userspace, such as constants,\n")
- outputf.write(" * structures, and macros, and thus, contains no copyrightable information.\n")
- outputf.write(" */\n")
- line = inputf.readline()
- while line:
- if line == '\n':
- line = line.strip("\n")
- else:
- line = line.rstrip() + '\n'
- outputf.write(line)
- line = inputf.readline()
- inputf.close()
- outputf.close()
- os.remove(outputfilename)
-
- return True
-
-
-def deal_dir(src):
- # dir exist or not
- if not os.path.exists(src):
- print('Error: dir - %s is not exist.'% src)
- return False
- filelists = os.listdir(src)
- for eachfile in filelists:
- eachfile = src + '/' +eachfile
- if os.path.isdir(eachfile):
- deal_dir(eachfile)
- elif os.path.isfile(eachfile):
- deal_file(eachfile)
- return True
-
-
-def copy_kernel_headers(build_top, original_dir, target_dir):
- headers_dir = build_top + '/' + target_dir
- external_dir = build_top + original_dir
-
- headers_rm_cmd = "rm " + headers_dir + "/uapi -rf"
- headers_cp_cmd = "cp " + external_dir + " " + headers_dir + " -r"
-
- try:
- status = subprocess.call(headers_rm_cmd, shell=True)
- except:
- printf("[Error] rm error!!!")
-
- try:
- status = subprocess.call(headers_cp_cmd, shell=True)
- except:
- printf("[Error] cp error!!!")
-
- return 1
-
-def replace_key_words_ext(keys):
- replace_key_words(keys[0], keys[1], keys[2], keys[3])
- return 1
-
-def replace_key_words(original_key, target_dir, replace_key, replace_str):
- replace_cmd = "grep \""+ original_key + "\" -rl " + target_dir + " | xargs sed -i \"s/" + replace_key + "/" + replace_str + "/g\""
- try:
- status = subprocess.call(replace_cmd, shell=True)
- except:
- printf("[Error] replace CONFIG_64BIT error!!!")
-
- return 1
-
-
-
-def usage():
- print(" Usage: run the script at the root of project.\n For example:\n\
- python ./foundation/ccruntime/libc/kernel/tools/update_Z_header.py")
- return 0
-
-
-def main():
-
- if len(sys.argv) > 1:
- usage()
- return -1
-
- kernel_dir = "prebuilts/lite/sysroot/ohos_tmp"
- external_dir = '/prebuilts/lite/sysroot/ohos_tmp_ori/uapi'
- status = -1
-
- try:
- build_top = os.environ["Z_BUILD_TOP"]
- except KeyError as e:
- print("[Warning] no env : %s, use current work dir." %(str(e)))
- build_top = subprocess.check_output("pwd", shell=True)
-
- status = copy_kernel_headers(build_top.strip(), external_dir, kernel_dir)
- if status != 1:
- print("[Error] copy files fail!!!")
- sys.exti(1)
-
- try:
- os.chdir(kernel_dir + "/uapi")
- except:
- print("[Error] no uapi dir1!!!")
- sys.exit(1)
-
- current_dir = os.getcwd()
-
- if "uapi" not in current_dir:
- print("[Error] not uapi dir!!!")
- sys.exit(1)
-
- for val in key_list:
- replace_key_words_ext(val)
-
- try:
- os.chdir("../")
- except:
- print("[Error] no uapi dir2!!!")
- sys.exit(1)
- deal_dir("uapi")
-
- return 1
-
-if __name__ == "__main__":
- starttime=time.time()
- main()
- endtime=time.time()
- print(endtime-starttime)
-
diff --git a/thirdparty/README b/thirdparty/README
deleted file mode 100755
index 931315caa382894b65a699726b297a64c450b393..0000000000000000000000000000000000000000
--- a/thirdparty/README
+++ /dev/null
@@ -1,14 +0,0 @@
-To build toolchains, we need some thirdparty headers.
-
-1.linux headers
-use following commands to install.
-KERNEL_DIR project root directory for linux kernel.
-kernel source version should be 4.4
-...
-cp -r $KERNEL_DIR/include/uapi/* ./linux_headers_install
-...
-pushd $KERNEL_DIR
-make headers_install ARCH=arm INSTALL_HDR_PATH=./tmp_dir
-popd
-...
-cp -r $KERNEL_DIR/tmp_dir/asm ./linux_headers_install
\ No newline at end of file
diff --git a/thirdparty/linux_headers_install/.gitkeep b/thirdparty/linux_headers_install/.gitkeep
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000