feat: 支持native动态加载组件
1.【需求描述】 动态库开发部分: gcc的sample code。 提供生成暴露接口生成机制,并允许产品新增需要暴露的接口。 提供可以判断库允许资源大小的能力,并提供相关工具辅助开发者确定开发的库要求的资源是否可以满足。 动态库运行部分: 提供elf load的api,可以加载指定路径下的库,并完成符号重映射等运行准备。 提供elf 暴露符号调用的api,用于调用库的api。 elf加载&链接异常时,有明确错误记录,返回明确错误类型。 提供elf 卸载的api。 2.【方案描述】 (1) 通过灌段的形式记录需要导出符号的地址信息,用于暴露内核对外的接口,在加载链接器中通过查询 对应的符号信息获取符号地址。 (2) 加载链接时,解析共享库并将共享库中可加载段通过文件系统读入内存中,并对共享库中未定义的、 需要重定位的符号进行重定位。需要调用符号时,根据符号名通过哈希表即可查询共享库提供的对应符号 的地址。 BREAKING CHANGE: 新增4个对外接口,声明在los_dynlink.h文件中,分别为: (1) LOS_DynlinkInit: 动态加载模块初始化。 (2) LOS_SoLoad: 加载指定路径的共享库。 (3) LOS_FindSym: 根据共享库句柄查找指定符号。 (4) LOS_SoUnload: 卸载共享库。 close #I418HJ Signed-off-by: Haryslee <lihao189@huawei.com> Change-Id: I7669b7ef20096294f9d1094c85ac6602fefad354
This commit is contained in:
parent
7fe9cc9aa0
commit
d75383400e
5
BUILD.gn
5
BUILD.gn
|
@ -59,7 +59,7 @@ group("kernel") {
|
|||
if (enable_ohos_kernel_liteos_m_kal == true) {
|
||||
deps += [ "kal:kal" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_shell== true) {
|
||||
if (enable_ohos_kernel_liteos_m_shell == true) {
|
||||
deps += [ "components/shell:shell" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_test == true) {
|
||||
|
@ -68,4 +68,7 @@ group("kernel") {
|
|||
if (enable_ohos_kernel_liteos_m_lwip == true) {
|
||||
deps += [ ohos_kernel_liteos_m_lwip_path ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_dynlink == true) {
|
||||
deps += [ "components/dynlink:dynlink" ]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ The directory structure is listed as below, for the detailed directories, please
|
|||
│ ├── backtrace # Backtrace support
|
||||
│ ├── cppsupport # C++ support
|
||||
│ ├── cpup # CPU possession (CPUP)
|
||||
│ ├── dynlink # Dynamic loader & linker
|
||||
│ ├── exchook # Exception hook
|
||||
│ ├── fs # File system
|
||||
│ └── net # Network support
|
||||
|
|
|
@ -23,6 +23,7 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
|
|||
│ ├── backtrace # 回溯栈支持
|
||||
│ ├── cppsupport # C++支持
|
||||
│ ├── cpup # CPUP功能
|
||||
│ ├── dynlink # 动态加载与链接
|
||||
│ ├── exchook # 异常钩子
|
||||
│ ├── fs # 文件系统
|
||||
│ └── net # Network功能
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
│ ├── backtrace --- Backtrace
|
||||
│ ├── cppsupport --- C++
|
||||
│ ├── cpup --- CPUP
|
||||
│ ├── dynlink --- Dynamic loader & linker
|
||||
│ ├── exchook --- Exception hook
|
||||
│ ├── fs --- File System
|
||||
│ └── net --- Network
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
│ ├── backtrace --- 回溯栈支持
|
||||
│ ├── cppsupport --- C++支持
|
||||
│ ├── cpup --- CPUP功能
|
||||
│ ├── dynlink --- 动态加载与链接
|
||||
│ ├── exchook --- 异常钩子
|
||||
│ ├── fs --- 文件系统
|
||||
│ └── net --- 网络功能
|
||||
|
|
|
@ -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.
|
||||
|
||||
config("dynlink_config") {
|
||||
include_dirs = [
|
||||
"../../kernel/include",
|
||||
"../../kernel/arch/include",
|
||||
"../../utils",
|
||||
".",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
|
||||
if (arch == "arm") {
|
||||
include_dirs += [ "../../kernel/arch/arm/include" ]
|
||||
} else {
|
||||
assert(false,
|
||||
"Dynlink module does not support for other archs except for arm!")
|
||||
}
|
||||
}
|
||||
|
||||
static_library("dynlink") {
|
||||
sources = [ "los_dynlink.c" ]
|
||||
|
||||
public_configs = [ ":dynlink_config" ]
|
||||
deps = [ "//kernel/liteos_m/kal/posix" ]
|
||||
}
|
|
@ -0,0 +1,935 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "unistd.h"
|
||||
#include "fcntl.h"
|
||||
#include "errno.h"
|
||||
#include "limits.h"
|
||||
#include "sys/stat.h"
|
||||
#include "securec.h"
|
||||
#include "arch_elf.h"
|
||||
#include "los_task.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_mux.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_DYNLINK == 1)
|
||||
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM)
|
||||
/**
|
||||
* Place instructions below in .icf linker file:
|
||||
*
|
||||
* keep {section .TABLE.START};
|
||||
* keep {section .sym.*};
|
||||
* keep {section .table.end};
|
||||
* define block SYMBOL_TABLE with fixed order
|
||||
* {
|
||||
* section .TABLE.START,
|
||||
* section .sym.*,
|
||||
* section .table.end
|
||||
* };
|
||||
* place in ROM_region {readonly, block SYMBOL_TABLE};
|
||||
*/
|
||||
const SymInfo symTableStart __attribute__((section(".TABLE.START"))) = {
|
||||
.name = "start",
|
||||
.addr = 0
|
||||
};
|
||||
|
||||
const SymInfo symTableEnd __attribute__((section(".table.end"))) = {
|
||||
.name = "end",
|
||||
.addr = 0
|
||||
};
|
||||
#pragma section=".TABLE.START"
|
||||
#pragma section=".table.end"
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
/**
|
||||
* Place instructions below in rodata segment of .ld linker file:
|
||||
*
|
||||
* __sym_table_start = .;
|
||||
* KEEP(*( SORT (.sym.*)));
|
||||
* __sym_table_end = .;
|
||||
*/
|
||||
extern char __sym_table_start[];
|
||||
extern char __sym_table_end[];
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
STATIC LOS_DL_LIST g_dynSharedObjLink;
|
||||
STATIC UINT32 g_dynlinkMux;
|
||||
|
||||
STATIC DynSharedObj *OsIsPreLoaded(const CHAR *fileName)
|
||||
{
|
||||
DynSharedObj *dso = NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(dso, &g_dynSharedObjLink, DynSharedObj, dsoNode) {
|
||||
if (!strcmp(fileName, dso->fileName)) {
|
||||
++dso->ref;
|
||||
return dso;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC INT32 OsVerifyEhdr(const LD_ELF_EHDR *ehdr, UINT32 fileLen)
|
||||
{
|
||||
if (memcmp(ehdr->e_ident, LD_ELFMAG, LD_SELFMAG) != LOS_OK) {
|
||||
PRINT_ERR("The file is not elf format\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
if (ehdr->e_type != ET_DYN) {
|
||||
PRINT_ERR("The file is not shared library\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
if (!check_arch(ehdr)) {
|
||||
PRINT_ERR("The file can not load in current platform\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
if (ehdr->e_phnum > PHDR_NUM_MAX) {
|
||||
PRINT_ERR("The num of program header is out of limit\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
if (ehdr->e_phoff > fileLen) {
|
||||
PRINT_ERR("The offset of program header is invalid, elf file is bad\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsReadELFInfo(INT32 fd, UINT8 *buffer, size_t readSize, off_t offset)
|
||||
{
|
||||
ssize_t byteNum;
|
||||
off_t returnPos;
|
||||
|
||||
if (readSize > 0) {
|
||||
returnPos = lseek(fd, offset, SEEK_SET);
|
||||
if (returnPos != offset) {
|
||||
PRINT_ERR("Failed to seek the position!, offset: %#x\n", offset);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
byteNum = read(fd, buffer, readSize);
|
||||
if (byteNum <= 0) {
|
||||
PRINT_ERR("Failed to read from offset: %#x!\n", offset);
|
||||
return LOS_NOK;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsGetFileLength(UINT32 *fileLen, const CHAR *fileName)
|
||||
{
|
||||
struct stat buf;
|
||||
INT32 ret;
|
||||
|
||||
ret = stat(fileName, &buf);
|
||||
if (ret < 0) {
|
||||
PRINT_ERR("Failed to stat file: %s, errno: %d\n", fileName, errno);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (buf.st_size > FILE_LENGTH_MAX) {
|
||||
PRINT_ERR("The file: %s length is out of limit!\n", fileName);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
*fileLen = (UINT32)buf.st_size;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsReadEhdr(INT32 fd, UINT32 fileLen, DynLinkInfo *dlInfo)
|
||||
{
|
||||
INT32 ret;
|
||||
|
||||
ret = OsReadELFInfo(fd, (UINT8 *)&dlInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
|
||||
if (ret != LOS_OK) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = OsVerifyEhdr(&dlInfo->elfEhdr, fileLen);
|
||||
if (ret != LOS_OK) {
|
||||
return -ELIBBAD;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsReadPhdrs(INT32 fd, UINT32 fileLen, DynLinkInfo *dlInfo)
|
||||
{
|
||||
INT32 ret;
|
||||
UINT32 size;
|
||||
LD_ELF_EHDR *ehdr = &dlInfo->elfEhdr;
|
||||
|
||||
if ((ehdr->e_phnum == 0) || (ehdr->e_phentsize != sizeof(LD_ELF_PHDR))) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
size = sizeof(LD_ELF_PHDR) * ehdr->e_phnum;
|
||||
if ((ehdr->e_phoff + size) > fileLen) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
dlInfo->elfPhdr = (LD_ELF_PHDR *)LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
|
||||
if (dlInfo->elfPhdr == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = OsReadELFInfo(fd, (UINT8 *)dlInfo->elfPhdr, size, ehdr->e_phoff);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dlInfo->elfPhdr);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
ERR:
|
||||
PRINT_ERR("the file is bad\n");
|
||||
return -ELIBBAD;
|
||||
}
|
||||
|
||||
STATIC DynSharedObj *OsLoadInit(const CHAR *fileName, VOID *pool)
|
||||
{
|
||||
DynSharedObj *dso = NULL;
|
||||
UINT32 allocSize, nameLen;
|
||||
UINT32 fileLen = 0;
|
||||
INT32 ret;
|
||||
|
||||
nameLen = strlen(fileName);
|
||||
if (nameLen > PATH_MAX) {
|
||||
PRINT_ERR("file name length is too long\n");
|
||||
errno = ENAMETOOLONG;
|
||||
return NULL;
|
||||
}
|
||||
allocSize = sizeof(DynSharedObj) + nameLen + 1;
|
||||
|
||||
dso = (DynSharedObj *)LOS_MemAlloc(OS_SYS_MEM_ADDR, allocSize);
|
||||
if (dso == NULL) {
|
||||
PRINT_ERR("failed to alloc for dso\n");
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(dso, allocSize, 0, allocSize);
|
||||
|
||||
dso->dlInfo = (DynLinkInfo *)LOS_MemAlloc(OS_SYS_MEM_ADDR, sizeof(DynLinkInfo));
|
||||
if (dso->dlInfo == NULL) {
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
PRINT_ERR("failed to alloc for loadInfo\n");
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(dso->dlInfo, sizeof(DynLinkInfo), 0, sizeof(DynLinkInfo));
|
||||
|
||||
ret = OsGetFileLength(&fileLen, fileName);
|
||||
if (ret != LOS_OK) {
|
||||
errno = ENOENT;
|
||||
goto ERR1;
|
||||
}
|
||||
|
||||
dso->fd = open(fileName, O_RDONLY);
|
||||
if (dso->fd < 0) {
|
||||
PRINT_ERR("Failed to open ELF file: %s!\n", fileName);
|
||||
goto ERR1;
|
||||
}
|
||||
|
||||
ret = OsReadEhdr(dso->fd, fileLen, dso->dlInfo);
|
||||
if (ret != LOS_OK) {
|
||||
errno = -ret;
|
||||
goto ERR2;
|
||||
}
|
||||
|
||||
ret = OsReadPhdrs(dso->fd, fileLen, dso->dlInfo);
|
||||
if (ret != LOS_OK) {
|
||||
errno = -ret;
|
||||
goto ERR2;
|
||||
}
|
||||
|
||||
strcpy(dso->buf, fileName);
|
||||
dso->fileName = dso->buf;
|
||||
dso->ref = 1;
|
||||
dso->pool = (pool ? pool : OS_SYS_MEM_ADDR);
|
||||
LOS_ListInit(&dso->dsoNode);
|
||||
|
||||
return dso;
|
||||
|
||||
ERR2:
|
||||
close(dso->fd);
|
||||
ERR1:
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC INT32 OsReserveSpace(const DynLinkInfo *dlInfo, UINT32 *boundary)
|
||||
{
|
||||
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
|
||||
INT32 phdrNum = dlInfo->elfEhdr.e_phnum;
|
||||
UINTPTR addrMin = SIZE_MAX;
|
||||
UINTPTR addrMax = 0;
|
||||
UINT32 offStart = 0;
|
||||
UINT64 size;
|
||||
INT32 i;
|
||||
|
||||
for (i = 0; i < phdrNum; ++i, ++elfPhdrTemp) {
|
||||
if (elfPhdrTemp->p_type == PT_TLS) {
|
||||
PRINT_ERR("unsupport tls\n");
|
||||
return 0;
|
||||
}
|
||||
if (elfPhdrTemp->p_type != PT_LOAD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*boundary == 0) {
|
||||
*boundary = elfPhdrTemp->p_align;
|
||||
}
|
||||
|
||||
if (elfPhdrTemp->p_vaddr < addrMin) {
|
||||
addrMin = elfPhdrTemp->p_vaddr;
|
||||
offStart = elfPhdrTemp->p_offset;
|
||||
}
|
||||
if ((elfPhdrTemp->p_vaddr + elfPhdrTemp->p_memsz) > addrMax) {
|
||||
addrMax = elfPhdrTemp->p_vaddr + elfPhdrTemp->p_memsz;
|
||||
}
|
||||
}
|
||||
|
||||
if ((addrMin == addrMax) || (addrMax < addrMin)) {
|
||||
return 0;
|
||||
}
|
||||
size = ELF_ALIGN_UP(addrMax, *boundary) - ELF_ALIGN_DOWN(addrMin, *boundary) + ELF_ALIGN_DOWN(offStart, *boundary);
|
||||
|
||||
return (size > UINT_MAX) ? 0 : (UINT32)size;
|
||||
}
|
||||
|
||||
STATIC UINTPTR OsDoLoadFile(INT32 fd, UINTPTR addr, const LD_ELF_PHDR *elfPhdr, UINT32 boundary)
|
||||
{
|
||||
INT32 ret;
|
||||
UINT32 offset = elfPhdr->p_offset - ELF_ALIGN_OFFSET(elfPhdr->p_vaddr, boundary);
|
||||
UINT32 size = elfPhdr->p_filesz + ELF_ALIGN_OFFSET(elfPhdr->p_vaddr, boundary);
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr = ELF_ALIGN_DOWN(addr, boundary);
|
||||
ret = OsReadELFInfo(fd, (UINT8 *)addr, size, offset);
|
||||
if (ret != LOS_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
STATIC INT32 OsLoadELFFile(DynSharedObj *dso, UINT32 boundary)
|
||||
{
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
|
||||
const LD_ELF_EHDR *elfEhdr = &dlInfo->elfEhdr;
|
||||
UINTPTR loadBase = dso->loadBase;
|
||||
UINTPTR vAddr, loadAddr, bssStart, bssEnd;
|
||||
INT32 i;
|
||||
|
||||
for (i = 0; i < elfEhdr->e_phnum; ++i, ++elfPhdrTemp) {
|
||||
if (elfPhdrTemp->p_type != PT_LOAD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((elfPhdrTemp->p_flags & PF_R) == 0) {
|
||||
return -ENOEXEC;
|
||||
}
|
||||
vAddr = elfPhdrTemp->p_vaddr;
|
||||
|
||||
loadAddr = OsDoLoadFile(dso->fd, (vAddr + loadBase), elfPhdrTemp, boundary);
|
||||
if (loadAddr == 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if ((elfPhdrTemp->p_memsz > elfPhdrTemp->p_filesz) && (elfPhdrTemp->p_flags & PF_W)) {
|
||||
bssStart = loadAddr + ELF_ALIGN_OFFSET(vAddr, boundary) + elfPhdrTemp->p_filesz;
|
||||
bssEnd = loadAddr + ELF_ALIGN_OFFSET(vAddr, boundary) + elfPhdrTemp->p_memsz;
|
||||
(VOID)memset_s((VOID *)bssStart, bssEnd - bssStart, 0, bssEnd - bssStart);
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsLoadLibrary(DynSharedObj *dso)
|
||||
{
|
||||
UINT32 loadSize;
|
||||
UINT32 boundary = 0;
|
||||
INT32 ret;
|
||||
|
||||
loadSize = OsReserveSpace(dso->dlInfo, &boundary);
|
||||
if (loadSize == 0) {
|
||||
PRINT_ERR("failed to reserve space!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dso->loadBase = (UINTPTR)LOS_MemAllocAlign(dso->pool, loadSize, boundary);
|
||||
if (dso->loadBase == 0) {
|
||||
PRINT_ERR("failed to alloc memory for loading shared library\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = OsLoadELFFile(dso, boundary);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
PRINT_ERR("failed to load shared library\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsGetDynBase(DynSharedObj *dso)
|
||||
{
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
|
||||
INT32 phdrNum = dlInfo->elfEhdr.e_phnum;
|
||||
INT32 i;
|
||||
|
||||
for (i = 0; i < phdrNum; ++i, ++elfPhdrTemp) {
|
||||
if (elfPhdrTemp->p_type != PT_DYNAMIC) {
|
||||
continue;
|
||||
}
|
||||
dlInfo->dynBase = dso->loadBase + elfPhdrTemp->p_vaddr;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsParseDynamic(DynSharedObj *dso)
|
||||
{
|
||||
LD_ELF_DYN *dyn = NULL;
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
RelocInfoTab *relInfoTab = &dlInfo->relInfoTab;
|
||||
|
||||
for (dyn = (LD_ELF_DYN *)dlInfo->dynBase; dyn->d_tag != DT_NULL; ++dyn) {
|
||||
switch (dyn->d_tag) {
|
||||
case DT_NEEDED:
|
||||
PRINT_ERR("shared library should not depend on others\n");
|
||||
return -ENOTSUP;
|
||||
case DT_TEXTREL:
|
||||
PRINT_ERR("you should recompile shared library with -fPIC\n");
|
||||
return -EFAULT;
|
||||
case DT_HASH:
|
||||
dlInfo->hashTab = (UINT32 *)(dso->loadBase + dyn->d_un.d_ptr);
|
||||
break;
|
||||
case DT_SYMTAB:
|
||||
dlInfo->symTab = (LD_ELF_SYM *)(dso->loadBase + dyn->d_un.d_ptr);
|
||||
break;
|
||||
case DT_STRTAB:
|
||||
dlInfo->symStrings = (CHAR *)(dso->loadBase + dyn->d_un.d_ptr);
|
||||
break;
|
||||
case DT_REL:
|
||||
relInfoTab->rel.relTab = dso->loadBase + dyn->d_un.d_ptr;
|
||||
relInfoTab->rel.relEntSize = sizeof(LD_ELF_REL);
|
||||
break;
|
||||
case DT_RELSZ:
|
||||
relInfoTab->rel.relTabSize = dyn->d_un.d_val;
|
||||
break;
|
||||
case DT_RELA:
|
||||
relInfoTab->rela.relTab = dso->loadBase + dyn->d_un.d_ptr;
|
||||
relInfoTab->rela.relEntSize = sizeof(LD_ELF_RELA);
|
||||
break;
|
||||
case DT_RELASZ:
|
||||
relInfoTab->rela.relTabSize = dyn->d_un.d_val;
|
||||
break;
|
||||
case DT_JMPREL:
|
||||
relInfoTab->jmpRel.relTab = dso->loadBase + dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_PLTRELSZ:
|
||||
relInfoTab->jmpRel.relTabSize = dyn->d_un.d_val;
|
||||
break;
|
||||
case DT_PLTREL:
|
||||
relInfoTab->jmpRel.relEntSize = (dyn->d_un.d_val == DT_REL) ? sizeof(LD_ELF_REL) : sizeof(LD_ELF_RELA);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsGetHashVal(const CHAR *name)
|
||||
{
|
||||
UINT32 hashVal = 0;
|
||||
UINT32 tmp;
|
||||
const UINT8 *str = (const UINT8 *)name;
|
||||
|
||||
while (*str) {
|
||||
hashVal = (*str) + (hashVal << WORD_SHIFT);
|
||||
tmp = hashVal & HASH_MASK;
|
||||
if (tmp != 0) {
|
||||
hashVal ^= tmp >> HASH_SHIFT;
|
||||
}
|
||||
|
||||
hashVal &= ~tmp;
|
||||
++str;
|
||||
}
|
||||
|
||||
return hashVal;
|
||||
}
|
||||
|
||||
STATIC LD_ELF_SYM *OsFindSymInDso(const DynLinkInfo *dlInfo, const CHAR *name)
|
||||
{
|
||||
LD_ELF_SYM *symTab = dlInfo->symTab;
|
||||
LD_ELF_SYM *sym = NULL;
|
||||
CHAR *symStr = dlInfo->symStrings;
|
||||
UINT32 *hashTab = dlInfo->hashTab;
|
||||
UINT32 bucketNum = hashTab[0];
|
||||
UINT32 *bucket = &hashTab[BUCKET_IDX];
|
||||
UINT32 *chain = &bucket[bucketNum];
|
||||
UINT32 hashVal = OsGetHashVal(name);
|
||||
UINT32 symIdx;
|
||||
|
||||
for (symIdx = bucket[hashVal % bucketNum]; symIdx; symIdx = chain[symIdx]) {
|
||||
if (strcmp(name, symStr + symTab[symIdx].st_name) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sym = symTab + symIdx;
|
||||
if ((sym->st_value == 0) || (sym->st_shndx == 0)) {
|
||||
return NULL;
|
||||
}
|
||||
return symTab + symIdx;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC SymInfo *OsFindSymInTable(const CHAR *name)
|
||||
{
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM)
|
||||
SymInfo *symTab = (SymInfo *)__section_end(".TABLE.START");
|
||||
UINT32 symTableSize = ((UINTPTR)__section_begin(".table.end") -
|
||||
(UINTPTR)__section_end(".TABLE.START")) / sizeof(SymInfo);
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
SymInfo *symTab = (SymInfo *)__sym_table_start;
|
||||
UINT32 symTableSize = (__sym_table_end - __sym_table_start) / sizeof(SymInfo);
|
||||
#endif
|
||||
INT32 startIdx = 0;
|
||||
INT32 endIdx = symTableSize - 1;
|
||||
INT32 ret, midIdx;
|
||||
|
||||
while (startIdx <= endIdx) {
|
||||
midIdx = startIdx + ((UINT32)(endIdx - startIdx) >> 1);
|
||||
ret = strcmp(symTab[midIdx].name, name);
|
||||
if (ret > 0) {
|
||||
endIdx = midIdx - 1;
|
||||
} else if (ret < 0) {
|
||||
startIdx = midIdx + 1;
|
||||
} else {
|
||||
return symTab + midIdx;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC UINTPTR OsFindSym(const DynSharedObj *dso, INT32 symIdx)
|
||||
{
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
CHAR *symStrings = dlInfo->symStrings;
|
||||
CHAR *symStr = NULL;
|
||||
LD_ELF_SYM *symTab = dlInfo->symTab;
|
||||
LD_ELF_SYM *sym = NULL;
|
||||
LD_ELF_SYM *symInDso = NULL;
|
||||
SymInfo *symInTab = NULL;
|
||||
|
||||
sym = symTab + symIdx;
|
||||
symStr = symStrings + sym->st_name;
|
||||
if ((symInDso = OsFindSymInDso(dlInfo, symStr)) != NULL) {
|
||||
return dso->loadBase + symInDso->st_value;
|
||||
} else if ((symInTab = OsFindSymInTable(symStr)) != NULL) {
|
||||
return symInTab->addr;
|
||||
} else {
|
||||
PRINT_ERR("failed to relocate %s, symbol: %s not found\n", dso->fileName, symStr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INT32 OsDoReloc(const DynSharedObj *dso, INT32 type, UINTPTR relocAddr, UINT32 addend, UINTPTR symAddr)
|
||||
{
|
||||
switch (type) {
|
||||
case R_ARCH_NONE:
|
||||
break;
|
||||
case R_ARCH_GLOB_DAT:
|
||||
case R_ARCH_JUMP_SLOT:
|
||||
*(UINTPTR *)relocAddr = symAddr + addend;
|
||||
break;
|
||||
case R_ARCH_ABS32:
|
||||
*(UINTPTR *)relocAddr = symAddr + ((addend != 0) ? addend : *(UINTPTR *)relocAddr);
|
||||
break;
|
||||
case R_ARCH_RELATIVE:
|
||||
*(UINTPTR *)relocAddr = dso->loadBase + ((addend != 0) ? addend : *(UINTPTR *)relocAddr);
|
||||
break;
|
||||
default:
|
||||
PRINT_ERR("failed to relocate %s, unsupported reloc type: %d\n", dso->fileName, type);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsDoRelocSyms(DynSharedObj *dso, RelocInfo *relInfo)
|
||||
{
|
||||
UINT32 relStride = relInfo->relEntSize / sizeof(UINT32);
|
||||
UINT32 *relTab = (UINT32 *)relInfo->relTab;
|
||||
UINT32 addend;
|
||||
UINTPTR relocAddr, symAddr;
|
||||
INT32 i, symIdx, ret, type;
|
||||
|
||||
for (i = 0; i < relInfo->relTabSize; i += relInfo->relEntSize, relTab += relStride) {
|
||||
type = REL_TYPE(relTab[1]);
|
||||
if (type == R_ARCH_NONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
symIdx = REL_SYM(relTab[1]);
|
||||
if (symIdx == 0) {
|
||||
symAddr = 0;
|
||||
} else {
|
||||
symAddr = OsFindSym(dso, symIdx);
|
||||
if (symAddr == 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
relocAddr = dso->loadBase + relTab[0];
|
||||
addend = (relInfo->relEntSize == sizeof(LD_ELF_REL)) ? 0 : relTab[relStride - 1];
|
||||
ret = OsDoReloc(dso, type, relocAddr, addend, symAddr);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsRelocSyms(DynSharedObj *dso)
|
||||
{
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
RelocInfo *relInfo = (RelocInfo *)&dlInfo->relInfoTab;
|
||||
INT32 relTypes = sizeof(RelocInfoTab) / sizeof(RelocInfo);
|
||||
INT32 i, ret;
|
||||
|
||||
for (i = 0; i < relTypes; ++i, ++relInfo) {
|
||||
if (relInfo->relTab == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = OsDoRelocSyms(dso, relInfo);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsDoDynLink(DynSharedObj *dso)
|
||||
{
|
||||
INT32 ret;
|
||||
|
||||
ret = OsGetDynBase(dso);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("there are no dynamic segments in elf file\n");
|
||||
return -ELIBBAD;
|
||||
}
|
||||
|
||||
ret = OsParseDynamic(dso);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsRelocSyms(dso);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID OsDeLoadInit(DynSharedObj *dso)
|
||||
{
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
dso->dlInfo->elfPhdr = NULL;
|
||||
close(dso->fd);
|
||||
}
|
||||
|
||||
STATIC VOID OsGetInitFini(DynSharedObj *dso)
|
||||
{
|
||||
LD_ELF_DYN *dyn = NULL;
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
InitFiniTab *initFiniTab = &dso->initFiniTab;
|
||||
|
||||
for (dyn = (LD_ELF_DYN *)dlInfo->dynBase; dyn->d_tag != DT_NULL; ++dyn) {
|
||||
switch (dyn->d_tag) {
|
||||
case DT_INIT:
|
||||
initFiniTab->init.func = dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_INIT_ARRAY:
|
||||
initFiniTab->init.array = dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_INIT_ARRAYSZ:
|
||||
initFiniTab->init.arraySz = dyn->d_un.d_val;
|
||||
break;
|
||||
case DT_FINI:
|
||||
initFiniTab->fini.func = dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_FINI_ARRAY:
|
||||
initFiniTab->fini.array = dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_FINI_ARRAYSZ:
|
||||
initFiniTab->fini.arraySz = dyn->d_un.d_val;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsDoInit(DynSharedObj *dso)
|
||||
{
|
||||
InitFiniTab *initFiniTab = &dso->initFiniTab;
|
||||
INIT_FINI_FUNC initFunc = NULL;
|
||||
UINTPTR *func = NULL;
|
||||
UINT32 funcNum;
|
||||
|
||||
OsGetInitFini(dso);
|
||||
if (initFiniTab->init.func != 0) {
|
||||
initFunc = (INIT_FINI_FUNC)(dso->loadBase + initFiniTab->init.func);
|
||||
initFunc();
|
||||
}
|
||||
|
||||
if (initFiniTab->init.array == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
funcNum = initFiniTab->init.arraySz / sizeof(UINTPTR);
|
||||
func = (UINTPTR *)(dso->loadBase + initFiniTab->init.array);
|
||||
while (funcNum--) {
|
||||
initFunc = (INIT_FINI_FUNC)(*func);
|
||||
initFunc();
|
||||
++func;
|
||||
}
|
||||
}
|
||||
|
||||
VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool)
|
||||
{
|
||||
INT32 ret;
|
||||
DynSharedObj *dso = NULL;
|
||||
|
||||
if (fileName == NULL) {
|
||||
PRINT_ERR("invalid file name\n");
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
|
||||
dso = OsIsPreLoaded(fileName);
|
||||
if (dso != NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
return dso;
|
||||
}
|
||||
|
||||
dso = OsLoadInit(fileName, pool);
|
||||
if (dso == NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = OsLoadLibrary(dso);
|
||||
if (ret != LOS_OK) {
|
||||
errno = -ret;
|
||||
goto ERR1;
|
||||
}
|
||||
|
||||
ret = OsDoDynLink(dso);
|
||||
if (ret != LOS_OK) {
|
||||
errno = -ret;
|
||||
goto ERR2;
|
||||
}
|
||||
|
||||
OsDoInit(dso);
|
||||
|
||||
LOS_ListAdd(&g_dynSharedObjLink, &dso->dsoNode);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
OsDeLoadInit(dso);
|
||||
|
||||
return dso;
|
||||
|
||||
ERR2:
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
ERR1:
|
||||
close(dso->fd);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC DynSharedObj *OsCheckHandle(VOID *handle)
|
||||
{
|
||||
DynSharedObj *dso = NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(dso, &g_dynSharedObjLink, DynSharedObj, dsoNode) {
|
||||
if (handle == dso) {
|
||||
return dso;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID *LOS_FindSym(VOID *handle, const CHAR *name)
|
||||
{
|
||||
LD_ELF_SYM *sym = NULL;
|
||||
DynSharedObj *dso = NULL;
|
||||
VOID *symAddr = NULL;
|
||||
|
||||
if ((handle == NULL) || (name == NULL)) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
|
||||
dso = OsCheckHandle(handle);
|
||||
if (dso == NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
sym = OsFindSymInDso(dso->dlInfo, name);
|
||||
if (sym == NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
PRINT_ERR("failed to find symbol: %s\n", name);
|
||||
errno = EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
symAddr = (VOID *)(dso->loadBase + sym->st_value);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
return symAddr;
|
||||
|
||||
ERR:
|
||||
PRINT_ERR("invalid input param\n");
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC VOID OsDoFini(DynSharedObj *dso)
|
||||
{
|
||||
InitFiniTab *initFiniTab = &dso->initFiniTab;
|
||||
INIT_FINI_FUNC finiFunc = NULL;
|
||||
UINTPTR *func = NULL;
|
||||
UINT32 funcNum;
|
||||
|
||||
if (initFiniTab->fini.array != 0) {
|
||||
funcNum = initFiniTab->fini.arraySz / sizeof(UINTPTR);
|
||||
func = (UINTPTR *)(dso->loadBase + initFiniTab->fini.array) + funcNum;
|
||||
while (funcNum--) {
|
||||
--func;
|
||||
finiFunc = (INIT_FINI_FUNC)(*func);
|
||||
finiFunc();
|
||||
}
|
||||
}
|
||||
|
||||
if (initFiniTab->fini.func != 0) {
|
||||
finiFunc = (INIT_FINI_FUNC)(dso->loadBase + initFiniTab->fini.func);
|
||||
finiFunc();
|
||||
}
|
||||
}
|
||||
|
||||
INT32 LOS_SoUnload(VOID *handle)
|
||||
{
|
||||
DynSharedObj *dso = NULL;
|
||||
|
||||
if (handle == NULL) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
|
||||
dso = OsCheckHandle(handle);
|
||||
if (dso == NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
if (dso->ref > 1) {
|
||||
--dso->ref;
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
OsDoFini(dso);
|
||||
|
||||
LOS_ListDelete(&dso->dsoNode);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
|
||||
return LOS_OK;
|
||||
ERR:
|
||||
PRINT_ERR("invalid handle\n");
|
||||
errno = EINVAL;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
INT32 LOS_DynlinkInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
LOS_ListInit(&g_dynSharedObjLink);
|
||||
ret = LOS_MuxCreate(&g_dynlinkMux);
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#endif /* LOSCFG_DYNLINK */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
|
@ -0,0 +1,201 @@
|
|||
/*
|
||||
* 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_DYNLINK_H
|
||||
#define _LOS_DYNLINK_H
|
||||
|
||||
#include "elf.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_list.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef LOSCFG_AARCH64
|
||||
typedef Elf64_Ehdr LD_ELF_EHDR;
|
||||
typedef Elf64_Phdr LD_ELF_PHDR;
|
||||
typedef Elf64_Sym LD_ELF_SYM;
|
||||
typedef Elf64_Dyn LD_ELF_DYN;
|
||||
typedef Elf64_Rel LD_ELF_REL;
|
||||
typedef Elf64_Rela LD_ELF_RELA;
|
||||
#define REL_TYPE(x) ELF64_R_TYPE(x)
|
||||
#define REL_SYM(x) ELF64_R_SYM(x)
|
||||
#define REL_INFO ELF64_R_INFO
|
||||
#else
|
||||
typedef Elf32_Ehdr LD_ELF_EHDR;
|
||||
typedef Elf32_Phdr LD_ELF_PHDR;
|
||||
typedef Elf32_Sym LD_ELF_SYM;
|
||||
typedef Elf32_Dyn LD_ELF_DYN;
|
||||
typedef Elf32_Rel LD_ELF_REL;
|
||||
typedef Elf32_Rela LD_ELF_RELA;
|
||||
#define REL_TYPE(x) ELF32_R_TYPE(x)
|
||||
#define REL_SYM(x) ELF32_R_SYM(x)
|
||||
#define REL_INFO ELF32_R_INFO
|
||||
#endif
|
||||
|
||||
#define LD_ELFMAG "\177ELF"
|
||||
#define LD_SELFMAG 4
|
||||
#define PHDR_NUM_MAX 128
|
||||
#define DYNAMIC_CNT 32
|
||||
#define HASH_MASK 0xf0000000
|
||||
#define WORD_SHIFT 4
|
||||
#define HASH_SHIFT 24
|
||||
#define BUCKET_IDX 2
|
||||
|
||||
#define ELF_ALIGN_UP(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
|
||||
#define ELF_ALIGN_DOWN(a, b) ((a) & ~((b) - 1))
|
||||
#define ELF_ALIGN_OFFSET(a, b) ((a) & ((b) - 1))
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
#ifndef FILE_LENGTH_MAX
|
||||
#define FILE_LENGTH_MAX 0x40000
|
||||
#endif
|
||||
typedef VOID (*INIT_FINI_FUNC)(VOID);
|
||||
|
||||
typedef struct {
|
||||
UINTPTR relTab;
|
||||
UINT32 relTabSize;
|
||||
UINT32 relEntSize;
|
||||
} RelocInfo;
|
||||
|
||||
typedef struct {
|
||||
RelocInfo rel;
|
||||
RelocInfo rela;
|
||||
RelocInfo jmpRel;
|
||||
} RelocInfoTab;
|
||||
|
||||
typedef struct {
|
||||
UINTPTR func;
|
||||
UINTPTR array;
|
||||
UINT32 arraySz;
|
||||
} InitFiniInfo;
|
||||
|
||||
typedef struct {
|
||||
InitFiniInfo init;
|
||||
InitFiniInfo fini;
|
||||
} InitFiniTab;
|
||||
|
||||
typedef struct {
|
||||
LD_ELF_EHDR elfEhdr;
|
||||
LD_ELF_PHDR *elfPhdr;
|
||||
UINTPTR dynBase;
|
||||
UINT32 *hashTab;
|
||||
LD_ELF_SYM *symTab;
|
||||
CHAR *symStrings;
|
||||
RelocInfoTab relInfoTab;
|
||||
} DynLinkInfo;
|
||||
|
||||
typedef struct {
|
||||
CHAR *fileName;
|
||||
INT32 fd;
|
||||
DynLinkInfo *dlInfo;
|
||||
UINTPTR loadBase;
|
||||
InitFiniTab initFiniTab;
|
||||
LOS_DL_LIST dsoNode;
|
||||
UINT32 ref;
|
||||
VOID *pool;
|
||||
CHAR buf[];
|
||||
} DynSharedObj;
|
||||
|
||||
typedef struct {
|
||||
CHAR *name;
|
||||
UINTPTR addr;
|
||||
} SymInfo;
|
||||
|
||||
#define SYM_EXPORT(func) \
|
||||
const SymInfo sym_##func __attribute__((section(".sym."#func))) = { \
|
||||
.name = #func, \
|
||||
.addr = (UINTPTR)func \
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief Load the shared library file named by the NULL-terminated string filename and
|
||||
* return a valid handle for the loaded library.
|
||||
*
|
||||
* @param fileName The name pointer of shared library.
|
||||
* @param pool The heap for shared library to load. If the parameter, pool, is NULL, then
|
||||
* the dynamic loader & linker module will use the default heap and the pool is not NULL,
|
||||
* then the shared library will be loaded to the heap by pool.
|
||||
*
|
||||
* @note When the heap, pool, is not NULL, you should call LOS_MemInit() to initialize the
|
||||
* pool before calling LOS_SoLoad(). By the way, the system will comsume a certain amount
|
||||
* of memory to initialize the pool. LOS_SoLoad must not be called in interrupt callback.
|
||||
*
|
||||
* @return Return NULL if error. Return non-NULL if success.
|
||||
*/
|
||||
VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool);
|
||||
|
||||
/*
|
||||
* @brief Get the address of symbol named by the parameter, name, from the parameter, handle.
|
||||
*
|
||||
* @param handle The handle for the loaded shared library.
|
||||
* @param name The name of symbol to search.
|
||||
*
|
||||
* @note LOS_FindSym must not be called in interrupt callback.
|
||||
*
|
||||
* @return Return NULL if error. Return non-NULL if success.
|
||||
*/
|
||||
VOID *LOS_FindSym(VOID *handle, const CHAR *name);
|
||||
|
||||
/*
|
||||
* @brief Decrement the reference count on the loaded shared library refered to by handle.
|
||||
* If the reference count drops to zero, then the library is unloaded.
|
||||
*
|
||||
* This function validates that the handle is valid.
|
||||
*
|
||||
* @param handle The handle for the loaded shared library by LOS_SoLoad() interface.
|
||||
*
|
||||
* @note LOS_SoUnload must not be called in interrupt callback.
|
||||
*
|
||||
* @return Return 1 if error. Return 0 if success.
|
||||
*/
|
||||
INT32 LOS_SoUnload(VOID *handle);
|
||||
|
||||
/*
|
||||
* @brief Initialization for dynamic loader & linker module.
|
||||
*
|
||||
* @param VOID.
|
||||
*
|
||||
* @return Return LOS_NOK if error. Return LOS_OK if success.
|
||||
*/
|
||||
INT32 LOS_DynlinkInit(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_DYNLINK_H */
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 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.
|
||||
|
||||
# Description: The script is used to calculate the memory size that the specified shared library
|
||||
# will occupy when loading to the RAM.
|
||||
|
||||
READELF=readelf
|
||||
RM=rm
|
||||
SIZE=0x0
|
||||
SIZE_ALL=0x0
|
||||
SIZE_MAX=0
|
||||
TMP_FILE=tmp.txt
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: ./so_parse lib.so"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
parse_line()
|
||||
{
|
||||
MEM_SIZE=$(echo $1 | awk '{print $6}')
|
||||
echo ${MEM_SIZE}
|
||||
}
|
||||
|
||||
${READELF} -l $1 | while read line; do
|
||||
HEAD_STRING=$(echo ${line} | awk '{print $1}')
|
||||
if [[ "${HEAD_STRING}" == *"LOAD"* ]]; then
|
||||
SIZE=`parse_line "${line}"`
|
||||
SIZE=`echo ${SIZE}`
|
||||
SIZE_ALL=$((SIZE_ALL+SIZE))
|
||||
fi
|
||||
echo ${SIZE_ALL} >> ${TMP_FILE}
|
||||
done
|
||||
|
||||
NEED_SIZE=`tail -n 1 ${TMP_FILE}`
|
||||
echo "${NEED_SIZE} kb memory to reserve for $1!"
|
||||
${RM} -f ${TMP_FILE}
|
||||
|
|
@ -28,9 +28,7 @@
|
|||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
static_library("fs_operations") {
|
||||
sources = [
|
||||
"./fs.c",
|
||||
]
|
||||
sources = [ "./fs.c" ]
|
||||
|
||||
include_dirs = [
|
||||
"../../../kernel/arch/include",
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
|
||||
static_library("littlefs") {
|
||||
sources = [
|
||||
"lfs_api.c",
|
||||
"//third_party/littlefs/lfs.c",
|
||||
"//third_party/littlefs/lfs_util.c",
|
||||
"lfs_api.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
|
|
|
@ -1,50 +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
|
||||
# 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.
|
||||
|
||||
import("lwip_porting.gni")
|
||||
import("//third_party/lwip/lwip.gni")
|
||||
|
||||
config("lwip_depends") {
|
||||
defines = [ "_BSD_SOURCE = 1" ]
|
||||
}
|
||||
|
||||
static_library("lwip") {
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/kal/posix/include",
|
||||
"//kernel/liteos_m/kernel/arch/include",
|
||||
]
|
||||
|
||||
include_dirs += LWIP_PORTING_INCLUDE_DIRS
|
||||
include_dirs += LWIP_INCLUDE_DIRS
|
||||
|
||||
sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES
|
||||
|
||||
configs += [ ":lwip_depends" ]
|
||||
|
||||
deps = [ "//kernel/liteos_m/kal/posix" ]
|
||||
}
|
||||
|
||||
import("//third_party/lwip/lwip.gni")
|
||||
import("lwip_porting.gni")
|
||||
|
||||
config("lwip_depends") {
|
||||
defines = [ "_BSD_SOURCE = 1" ]
|
||||
}
|
||||
|
||||
static_library("lwip") {
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/kal/posix/include",
|
||||
"//kernel/liteos_m/kernel/arch/include",
|
||||
]
|
||||
|
||||
include_dirs += LWIP_PORTING_INCLUDE_DIRS
|
||||
include_dirs += LWIP_INCLUDE_DIRS
|
||||
|
||||
sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES
|
||||
|
||||
configs += [ ":lwip_depends" ]
|
||||
|
||||
deps = [ "//kernel/liteos_m/kal/posix" ]
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ static_library("shell") {
|
|||
"src/base/shmsg.c",
|
||||
"src/base/show.c",
|
||||
"src/cmds/date_shell.c",
|
||||
"src/cmds/fullpath.c",
|
||||
"src/cmds/mempt_shellcmd.c",
|
||||
"src/cmds/shell_shellcmd.c",
|
||||
"src/cmds/task_shellcmd.c",
|
||||
"src/cmds/vfs_shellcmd.c",
|
||||
"src/cmds/mempt_shellcmd.c",
|
||||
"src/cmds/fullpath.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
|
|
|
@ -28,21 +28,21 @@
|
|||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
static_library("trace") {
|
||||
sources = [
|
||||
"los_trace.c",
|
||||
"trace_offline.c",
|
||||
"trace_online.c",
|
||||
sources = [
|
||||
"cnv/trace_cnv.c",
|
||||
"los_trace.c",
|
||||
"pipeline/serial/trace_pipeline_serial.c",
|
||||
"pipeline/trace_pipeline.c",
|
||||
"pipeline/trace_tlv.c",
|
||||
"pipeline/serial/trace_pipeline_serial.c"
|
||||
"trace_offline.c",
|
||||
"trace_online.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"../../kernel/include",
|
||||
"../../kernel/arch/include",
|
||||
"../../utils",
|
||||
"./",
|
||||
"./",
|
||||
"cnv",
|
||||
"pipeline",
|
||||
"pipeline/serial",
|
||||
|
|
|
@ -39,5 +39,6 @@ declare_args() {
|
|||
enable_ohos_kernel_liteos_m_pm = true
|
||||
enable_ohos_kernel_liteos_m_trace = false
|
||||
enable_ohos_kernel_liteos_m_lwip = false
|
||||
enable_ohos_kernel_liteos_m_dynlink = false
|
||||
ohos_kernel_liteos_m_lwip_path = "components/net/lwip-2.1:lwip"
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ static_library("posix") {
|
|||
public_configs = [ ":include" ]
|
||||
|
||||
public_deps = [
|
||||
"//third_party/musl/porting/liteos_m/kernel",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
"//third_party/musl/porting/liteos_m/kernel",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -33,12 +33,12 @@ static_library("kernel") {
|
|||
"src/los_init.c",
|
||||
"src/los_mux.c",
|
||||
"src/los_queue.c",
|
||||
"src/los_sched.c",
|
||||
"src/los_sem.c",
|
||||
"src/los_sortlink.c",
|
||||
"src/los_swtmr.c",
|
||||
"src/los_task.c",
|
||||
"src/los_tick.c",
|
||||
"src/los_sched.c",
|
||||
"src/los_sortlink.c",
|
||||
"src/mm/los_membox.c",
|
||||
"src/mm/los_memory.c",
|
||||
]
|
||||
|
@ -50,6 +50,7 @@ static_library("kernel") {
|
|||
"../components/exchook",
|
||||
"../components/backtrace",
|
||||
"../components/power",
|
||||
"../components/dynlink",
|
||||
"../utils",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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 _ARCH_ELF_H
|
||||
#define _ARCH_ELF_H
|
||||
|
||||
#include "elf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define check_arch(ehdr) ((ehdr)->e_machine == EM_ARM)
|
||||
|
||||
#define R_ARCH_NONE R_ARM_NONE
|
||||
#define R_ARCH_GLOB_DAT R_ARM_GLOB_DAT
|
||||
#define R_ARCH_JUMP_SLOT R_ARM_JUMP_SLOT
|
||||
#define R_ARCH_ABS32 R_ARM_ABS32
|
||||
#define R_ARCH_RELATIVE R_ARM_RELATIVE
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _ARCH_ELF_H */
|
||||
|
|
@ -62,6 +62,10 @@
|
|||
#include "los_pm.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DYNLINK == 1)
|
||||
#include "los_dynlink.h"
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_Reboot
|
||||
Description : system exception, die in here, wait for watchdog.
|
||||
|
@ -210,6 +214,13 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
|
|||
OsExcMsgDumpInit();
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_DYNLINK == 1)
|
||||
ret = LOS_DynlinkInit();
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//kernel/liteos_m/config.gni")
|
||||
|
||||
declare_args() {
|
||||
enable_ohos_kernel_liteos_m_test_full = false
|
||||
|
@ -70,4 +71,7 @@ lite_component("test") {
|
|||
|
||||
#"sample/kernel/tickless:test_tickless",
|
||||
]
|
||||
if (enable_ohos_kernel_liteos_m_dynlink == true) {
|
||||
features += [ "sample/kernel/dynlink:test_dynlink" ]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,6 +161,7 @@ typedef enum {
|
|||
TEST_TINYXML,
|
||||
#endif
|
||||
TEST_DRIVERBASE,
|
||||
TEST_DYNLINK,
|
||||
} LiteOS_test_module;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -82,6 +82,7 @@ extern "C" {
|
|||
#endif
|
||||
#define LOS_KERNEL_FS_TEST 0
|
||||
#define LOS_KERNEL_MEM_TEST 1
|
||||
#define LOS_KERNEL_DYNLINK_TEST 0
|
||||
#define LOS_KERNEL_TICKLESS_TEST 0
|
||||
|
||||
#define LITEOS_CMSIS_TEST 0
|
||||
|
@ -333,6 +334,7 @@ extern VOID ItSuiteLosSem(void);
|
|||
extern VOID ItSuiteLosSwtmr(void);
|
||||
extern VOID ItSuiteLosHwi(void);
|
||||
extern VOID ItSuiteLosMem(void);
|
||||
extern VOID ItSuiteLosDynlink(void);
|
||||
extern VOID ItSuite_Los_FatFs(void);
|
||||
|
||||
extern VOID ItSuite_Cmsis_Lostask(void);
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
|
||||
|
||||
static_library("test_dynlink") {
|
||||
sources = [
|
||||
"It_los_dynlink.c",
|
||||
"It_los_dynlink_001.c",
|
||||
"It_los_dynlink_002.c",
|
||||
"It_los_dynlink_003.c",
|
||||
"It_los_dynlink_004.c",
|
||||
"It_los_dynlink_005.c",
|
||||
"It_los_dynlink_006.c",
|
||||
"It_los_dynlink_007.c",
|
||||
"It_los_dynlink_008.c",
|
||||
"It_los_dynlink_009.c",
|
||||
"It_los_dynlink_010.c",
|
||||
"It_los_dynlink_011.c",
|
||||
"It_los_dynlink_012.c",
|
||||
"It_los_dynlink_013.c",
|
||||
"It_los_dynlink_014.c",
|
||||
"It_los_dynlink_015.c",
|
||||
"It_los_dynlink_016.c",
|
||||
"It_los_dynlink_017.c",
|
||||
"It_los_dynlink_018.c",
|
||||
"It_los_dynlink_019.c",
|
||||
"It_los_dynlink_020.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"../../../../kernel/include",
|
||||
"../../../../kernel/arch/include",
|
||||
"../../../include",
|
||||
"../../../../utils",
|
||||
"../../../../components/dynlink",
|
||||
".",
|
||||
"../../../../components/cpup",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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 "It_los_dynlink.h"
|
||||
|
||||
VOID ItSuiteLosDynlink(VOID)
|
||||
{
|
||||
ItLosDynlink001();
|
||||
ItLosDynlink002();
|
||||
ItLosDynlink003();
|
||||
ItLosDynlink004();
|
||||
ItLosDynlink005();
|
||||
ItLosDynlink006();
|
||||
ItLosDynlink007();
|
||||
ItLosDynlink008();
|
||||
ItLosDynlink009();
|
||||
ItLosDynlink010();
|
||||
ItLosDynlink011();
|
||||
ItLosDynlink012();
|
||||
ItLosDynlink013();
|
||||
ItLosDynlink014();
|
||||
ItLosDynlink015();
|
||||
ItLosDynlink016();
|
||||
ItLosDynlink017();
|
||||
ItLosDynlink018();
|
||||
ItLosDynlink019();
|
||||
ItLosDynlink020();
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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 IT_LOS_DYNLINK_H
|
||||
#define IT_LOS_DYNLINK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "iCunit.h"
|
||||
|
||||
#define DSO_PATH "/music/"
|
||||
#define DSO_FULL_PATH(p) DSO_PATH p
|
||||
|
||||
VOID ItLosDynlink001(VOID);
|
||||
VOID ItLosDynlink002(VOID);
|
||||
VOID ItLosDynlink003(VOID);
|
||||
VOID ItLosDynlink004(VOID);
|
||||
VOID ItLosDynlink005(VOID);
|
||||
VOID ItLosDynlink006(VOID);
|
||||
VOID ItLosDynlink007(VOID);
|
||||
VOID ItLosDynlink008(VOID);
|
||||
VOID ItLosDynlink009(VOID);
|
||||
VOID ItLosDynlink010(VOID);
|
||||
VOID ItLosDynlink012(VOID);
|
||||
VOID ItLosDynlink013(VOID);
|
||||
VOID ItLosDynlink014(VOID);
|
||||
VOID ItLosDynlink015(VOID);
|
||||
VOID ItLosDynlink016(VOID);
|
||||
VOID ItLosDynlink017(VOID);
|
||||
VOID ItLosDynlink018(VOID);
|
||||
VOID ItLosDynlink019(VOID);
|
||||
VOID ItLosDynlink020(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _IT_LOS_DYNLINK_H */
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test invalid param */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
INT32 ret;
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32 ,INT32) = NULL;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(func, NULL, func);
|
||||
|
||||
ret = LOS_SoUnload(NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink001(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink001", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test invalide params */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
VOID *invalHandle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
CHAR *symbolName = "test_api";
|
||||
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_align4.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, NULL);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(NULL, symbolName);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
invalHandle = handle + 1;
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(invalHandle, symbolName);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
ret = LOS_SoUnload(invalHandle);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ret, 0, ret, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink002(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink002", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
#include "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test dso name of too long length */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
CHAR name[PATH_MAX + 2];
|
||||
|
||||
(VOID)memset_s(name, PATH_MAX + 1, 'a', PATH_MAX + 1);
|
||||
name[PATH_MAX + 1] = '\0';
|
||||
handle = (VOID *)LOS_SoLoad(name, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink003(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink003", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test shell script, shared library with ET_EXE flag, shared library with UNIX flag, or bad phdr */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
CHAR *shellName = DSO_FULL_PATH("shell.sh");
|
||||
CHAR *execName = DSO_FULL_PATH("Align4_dynamic_exec.so");
|
||||
CHAR *x86Name = DSO_FULL_PATH("Align4_dynamic_x86.so");
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(shellName, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(execName, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(x86Name, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink004(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink004", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test shared library with TLS or of align 0x1000 or without dynamic segment */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
CHAR *dsoNeedOthers = DSO_FULL_PATH("Align4_dynamic_need_others.so");
|
||||
CHAR *dsoWithoutPIC = DSO_FULL_PATH("Align4_dynamic_nopic.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoNeedOthers, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoWithoutPIC, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink005(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink005", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test symbol not found for reloc, it's upto shared library */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
CHAR *dsoNameUndVal = DSO_FULL_PATH("dynamic_undval.so");
|
||||
CHAR *dsoNameUndFunc = DSO_FULL_PATH("dynamic_undfunc.so");
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoNameUndVal, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoNameUndFunc, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink006(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink006", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test pie */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
INT32 ret;
|
||||
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_pie.so");
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, "test_api");
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink007(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink007", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test symbol not found */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
CHAR *invalSymName1 = "A_invalid_api";
|
||||
CHAR *invalSymName2 = "N_invalid_api";
|
||||
CHAR *invalSymName3 = "Z_invalid_api";
|
||||
CHAR *invalSymName4 = "a_invalid_api";
|
||||
CHAR *invalSymName5 = "o_invalid_api";
|
||||
CHAR *invalSymName6 = "z_invalid_api";
|
||||
CHAR *invalSymName7 = "LOS_InvalidApi";
|
||||
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_align4.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName1);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName2);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName3);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName4);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName5);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName6);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, invalSymName7);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink008(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink008", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
#include "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test Align4_dynamic_align4.so */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
CHAR *symbolName = "test_api";
|
||||
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_align4.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
ret = func(1, 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 14, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink009(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink009", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test Align4_dynamic_align4.so */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle1 = NULL;
|
||||
VOID *handle2 = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
CHAR *symbolName = "test_api";
|
||||
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_align4.so");
|
||||
INT32 ret;
|
||||
|
||||
handle1 = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle1, NULL, handle1);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle1, symbolName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT1);
|
||||
ret = func(1, 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 14, ret, EXIT1);
|
||||
|
||||
handle2 = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_GOTO_NOT_EQUAL(handle2, NULL, handle2, EXIT1);
|
||||
ICUNIT_GOTO_EQUAL(handle1, handle2, handle2, EXIT2);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle2, symbolName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT2);
|
||||
ret = func(1, 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 14, ret, EXIT2);
|
||||
|
||||
ret = LOS_SoUnload(handle2);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1);
|
||||
|
||||
ret = LOS_SoUnload(handle1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = LOS_SoUnload(handle1);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
EXIT2:
|
||||
ret = LOS_SoUnload(handle2);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
EXIT1:
|
||||
ret = LOS_SoUnload(handle1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink010(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink010", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test that bss segment in dynamic_bss.so */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)() = NULL;
|
||||
INT32 *pValue = NULL;
|
||||
CHAR *symbolName1 = "dyn_bss_func";
|
||||
CHAR *symbolName2 = "test_array";
|
||||
CHAR *dsoName = DSO_FULL_PATH("dynamic_bss.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)())LOS_FindSym(handle, symbolName1);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
ret = func();
|
||||
ICUNIT_GOTO_EQUAL(ret, 2117, ret, EXIT);
|
||||
|
||||
pValue = LOS_FindSym(handle, symbolName2);
|
||||
ICUNIT_GOTO_NOT_EQUAL(pValue, NULL, pValue, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink011(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink011", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test that global symbol int dynamic_static.so */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
CHAR *symbolName = "add_test";
|
||||
CHAR *dsoName = DSO_FULL_PATH("dynamic_static.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
ret = func(2000, 16);
|
||||
ICUNIT_GOTO_EQUAL(ret, 2017, ret, EXIT);
|
||||
|
||||
ret = func(2017, -1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 2017, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink012(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink012", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test that function and value to find int dynamic_xxxxx.so */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)() = NULL;
|
||||
INT32 *pValueAddr = NULL;
|
||||
INT32 **ppValueAddr = NULL;
|
||||
CHAR *symbolName1 = "get_value100";
|
||||
CHAR *symbolName2 = "get_value200";
|
||||
CHAR *symbolName3 = "g_value100";
|
||||
CHAR *symbolName4 = "g_pValue100";
|
||||
CHAR *symbolName5 = "pValue200";
|
||||
CHAR *symbolName6 = "g_pValue200";
|
||||
CHAR *dsoName = DSO_FULL_PATH("dynamic_xxxxx.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)())LOS_FindSym(handle, symbolName1);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
ret = func();
|
||||
ICUNIT_GOTO_EQUAL(ret, 100, ret, EXIT);
|
||||
|
||||
func = (INT32 (*)())LOS_FindSym(handle, symbolName2);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
ret = func();
|
||||
ICUNIT_GOTO_EQUAL(ret, 200, ret, EXIT);
|
||||
|
||||
pValueAddr = LOS_FindSym(handle, symbolName3);
|
||||
ICUNIT_GOTO_NOT_EQUAL(pValueAddr, NULL, pValueAddr, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(*pValueAddr, 100, *pValueAddr, EXIT);
|
||||
|
||||
ppValueAddr = LOS_FindSym(handle, symbolName4);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ppValueAddr, NULL, ppValueAddr, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(**ppValueAddr, 100, **ppValueAddr, EXIT);
|
||||
|
||||
pValueAddr = LOS_FindSym(handle, symbolName5);
|
||||
ICUNIT_GOTO_EQUAL(pValueAddr, NULL, pValueAddr, EXIT);
|
||||
|
||||
ppValueAddr = LOS_FindSym(handle, symbolName6);
|
||||
ICUNIT_GOTO_NOT_EQUAL(ppValueAddr, NULL, ppValueAddr, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(**ppValueAddr, 200, **ppValueAddr, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink013(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink013", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test that global and static symbol to find */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
INT32 *pValueAddr = NULL;
|
||||
INT32 *pStaticValueAddr = NULL;
|
||||
CHAR *symbolName1 = "add_test";
|
||||
CHAR *symbolName2 = "static_sub_test";
|
||||
CHAR *symbolName3 = "g_param";
|
||||
CHAR *symbolName4 = "staticParam";
|
||||
CHAR *dsoName = DSO_FULL_PATH("dynamic_static.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName1);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
ret = func(55, 66);
|
||||
ICUNIT_GOTO_EQUAL(ret, 122, ret, EXIT);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName2);
|
||||
ICUNIT_GOTO_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
pValueAddr = LOS_FindSym(handle, symbolName3);
|
||||
ICUNIT_GOTO_NOT_EQUAL(pValueAddr, NULL, pValueAddr, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(*pValueAddr, 10, *pValueAddr, EXIT);
|
||||
|
||||
pStaticValueAddr = LOS_FindSym(handle, symbolName4);
|
||||
ICUNIT_GOTO_EQUAL(pStaticValueAddr, NULL, pStaticValueAddr, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink014(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink014", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test that interfaces in dynamic_athmtc.so */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
VOID (*func0)(INT32, INT32 *) = NULL;
|
||||
VOID (*func1)(CHAR *, CHAR *) = NULL;
|
||||
CHAR *symbolName1 = "It_dynlink_dowhile";
|
||||
CHAR *symbolName2 = "It_dynlink_while";
|
||||
CHAR *symbolName3 = "It_dynlink_for";
|
||||
CHAR *symbolName4 = "It_dynlink_ifelse";
|
||||
CHAR *symbolName5 = "It_dynlink_continue";
|
||||
CHAR *symbolName6 = "It_dynlink_switch";
|
||||
CHAR *dsoName = DSO_FULL_PATH("dynamic_athmtc.so");
|
||||
INT32 out = 0;
|
||||
CHAR inChar[3];
|
||||
CHAR outChar[3] = { 0 };
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName1);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
|
||||
func0(1, &out);
|
||||
ICUNIT_GOTO_EQUAL(out, 2, out, EXIT);
|
||||
|
||||
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName2);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
|
||||
func0(2, &out);
|
||||
ICUNIT_GOTO_EQUAL(out, 3, out, EXIT);
|
||||
|
||||
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName3);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
|
||||
func0(3, &out);
|
||||
ICUNIT_GOTO_EQUAL(out, 4, out, EXIT);
|
||||
|
||||
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName4);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
|
||||
func0(105, &out);
|
||||
ICUNIT_GOTO_EQUAL(out, 105, out, EXIT);
|
||||
|
||||
func0 = (VOID (*)(INT32, INT32 *))LOS_FindSym(handle, symbolName5);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func0, NULL, func0, EXIT);
|
||||
func0(10, &out);
|
||||
ICUNIT_GOTO_EQUAL(out, 6, out, EXIT);
|
||||
|
||||
func1 = (VOID (*)(CHAR *, CHAR *))LOS_FindSym(handle, symbolName6);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func1, NULL, func1, EXIT);
|
||||
inChar[0] = 'a';
|
||||
inChar[1] = 'c';
|
||||
inChar[2] = 'q';
|
||||
func1(inChar, outChar);
|
||||
ICUNIT_GOTO_EQUAL(outChar[0], 'b', outChar[0], EXIT);
|
||||
ICUNIT_GOTO_EQUAL(outChar[1], 'd', outChar[1], EXIT);
|
||||
ICUNIT_GOTO_EQUAL(outChar[2], 'z', outChar[2], EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink015(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink015", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test that shared library is not exist */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
CHAR *dsoName = DSO_FULL_PATH("dynamic_noexist.so");
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink016(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink016", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
#include "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test init fini segment */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
CHAR *symbolName = "test_api";
|
||||
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_init_fini.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
ret = func(1, 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 104, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink017(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink017", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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 "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test shared library with align 0x10000 */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
CHAR *dsoName = DSO_FULL_PATH("dynamic_align10000.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, "test_api");
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
ret = func(1, 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 14, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink018(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink018", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
#include "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test call global function */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
INT32 (*func)(INT32, INT32) = NULL;
|
||||
CHAR *symbolName = "caller";
|
||||
CHAR *dsoName = DSO_FULL_PATH("dynamic_sym.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(handle, NULL, handle);
|
||||
|
||||
func = (INT32 (*)(INT32, INT32))LOS_FindSym(handle, symbolName);
|
||||
ICUNIT_GOTO_NOT_EQUAL(func, NULL, func, EXIT);
|
||||
|
||||
ret = func(1, 1);
|
||||
ICUNIT_GOTO_EQUAL(ret, 2033, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = LOS_SoUnload(handle);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink019(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink019", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
#include "los_dynlink.h"
|
||||
#include "It_los_dynlink.h"
|
||||
|
||||
/* Test that Align4_dynamic_stdlib.so, libc.a not with fPIC */
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
VOID *handle = NULL;
|
||||
VOID (*func)(INT32, INT32) = NULL;
|
||||
CHAR *dsoName = DSO_FULL_PATH("Align4_dynamic_stdlib.so");
|
||||
INT32 ret;
|
||||
|
||||
handle = (VOID *)LOS_SoLoad(dsoName, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(handle, NULL, handle);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosDynlink020(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosDynlink020", TestCase, TEST_LOS, TEST_DYNLINK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
GCC_PREFIX = arm-none-eabi-
|
||||
|
||||
CROSS_GCC = $(GCC_PREFIX)gcc
|
||||
GCC = gcc
|
||||
RM = -rm -rf
|
||||
HIDE = @
|
||||
|
||||
PREFIX = Align4_
|
||||
TESTCASENAME = dynamic_
|
||||
CASE = $(TESTCASENAME)
|
||||
AGCASE = $(PREFIX)$(TESTCASENAME)
|
||||
|
||||
SRCS = $(wildcard *.c)
|
||||
SO = $(patsubst %.c,%.so,$(SRCS))
|
||||
ALIGN_SO = $(patsubst %.c,$(PREFIX)%.so,$(SRCS))
|
||||
# cpu
|
||||
CPU = -mcpu=cortex-m4
|
||||
# fpu
|
||||
FPU = -mfpu=fpv4-sp-d16
|
||||
# float-abi
|
||||
FLOAT-ABI = -mfloat-abi=hard
|
||||
# mcu
|
||||
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
|
||||
CFLAGS = -nostdlib -nostartfiles
|
||||
ALIGN_CFLAGS = $(CFLAGS) -z max-page-size=4
|
||||
INIT_FINI_CFLAGS = $(ALIGN_CFLAGS) -Wl,-init,init_first -Wl,-fini,fini_end
|
||||
|
||||
all: $(SO) $(ALIGN_SO)
|
||||
$(SO): %.so : %.c
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)athmtc.c -o $(CASE)athmtc.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)bss.c -o $(CASE)bss.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)initfini.c -o $(CASE)align10000.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)static.c -o $(CASE)static.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)sym.c -o $(CASE)sym.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)undfunc.c -o $(CASE)undfunc.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)undval.c -o $(CASE)undval.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CFLAGS) $(CASE)xxxxx.c -o $(CASE)xxxxx.so
|
||||
|
||||
$(ALIGN_SO): $(PREFIX)%.so : %.c
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)align4.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(INIT_FINI_CFLAGS) $(CASE)initfini.c -o $(AGCASE)init_fini.so
|
||||
# shared library not for need
|
||||
$(HIDE)$(GCC) -fPIC -shared $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)x86.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIE -pie $(MCU) $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)pie.so
|
||||
$(HIDE)$(CROSS_GCC) $(MCU) $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)exec.so
|
||||
$(HIDE)$(CROSS_GCC) -shared $(MCU) $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)nopic.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(ALIGN_CFLAGS) $(AGCASE)align4.so $(CASE)initfini.c -o \
|
||||
$(AGCASE)need_others.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(ALIGN_CFLAGS) $(CASE)initfini.c -o $(AGCASE)noThumb.so
|
||||
$(HIDE)$(CROSS_GCC) -fPIC -shared $(MCU) $(CASE)initfini.c -o $(AGCASE)stdlib.so
|
||||
|
||||
clean:
|
||||
$(HIDE)$(RM) *.so
|
||||
|
||||
.PHONY: all clean
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
#define OK 0
|
||||
#define NOK 1
|
||||
|
||||
void It_dynlink_dowhile(int cnt, int *out)
|
||||
{
|
||||
int outParam = 0;
|
||||
cnt += 1;
|
||||
|
||||
do {
|
||||
++outParam;
|
||||
--cnt;
|
||||
} while (cnt);
|
||||
|
||||
*out = outParam;
|
||||
}
|
||||
|
||||
void It_dynlink_while(int cnt, int *out)
|
||||
{
|
||||
int index = 0;
|
||||
int outParam = 0;
|
||||
cnt += 1;
|
||||
|
||||
while ((index++) < cnt) {
|
||||
outParam += 1;
|
||||
}
|
||||
|
||||
*out = outParam;
|
||||
}
|
||||
|
||||
void It_dynlink_for(int cnt, int *out)
|
||||
{
|
||||
int index = 0;
|
||||
int outParam = 0;
|
||||
cnt += 1;
|
||||
|
||||
for (; index < cnt; ++index) {
|
||||
++outParam;
|
||||
}
|
||||
|
||||
*out = outParam;
|
||||
}
|
||||
|
||||
void It_dynlink_ifelse(int inVal, int *outVal)
|
||||
{
|
||||
int outParam;
|
||||
|
||||
if (inVal <= 101) {
|
||||
outParam = 101;
|
||||
} else if (inVal == 102) {
|
||||
outParam = inVal;
|
||||
} else if (inVal == 103) {
|
||||
outParam = inVal;
|
||||
} else if (inVal == 104) {
|
||||
outParam = inVal;
|
||||
} else if (inVal == 105) {
|
||||
outParam = inVal;
|
||||
} else if (inVal == 106) {
|
||||
outParam = inVal;
|
||||
} else if (inVal == 107) {
|
||||
outParam = inVal;
|
||||
} else if (inVal == 108) {
|
||||
outParam = inVal + 1;
|
||||
} else if (inVal == 109) {
|
||||
outParam = 45;
|
||||
} else {
|
||||
outParam = 45;
|
||||
}
|
||||
|
||||
*outVal = outParam;
|
||||
}
|
||||
|
||||
void It_dynlink_continue(int cnt, int *out)
|
||||
{
|
||||
int index = 0;
|
||||
int outParam = 0;
|
||||
cnt += 2;
|
||||
|
||||
for (; index < cnt; ++index) {
|
||||
if (index % 2) {
|
||||
continue;
|
||||
} else {
|
||||
++outParam;
|
||||
}
|
||||
}
|
||||
|
||||
*out = outParam;
|
||||
}
|
||||
|
||||
void It_dynlink_switch(char *inVal, char *outVal)
|
||||
{
|
||||
int i;
|
||||
char outParam;
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
switch (inVal[i]) {
|
||||
case 'A':
|
||||
case 'a':
|
||||
outParam = 'b';
|
||||
break;
|
||||
case 'B':
|
||||
case 'b':
|
||||
outParam = 'c';
|
||||
break;
|
||||
case 'C':
|
||||
case 'c':
|
||||
outParam = 'd';
|
||||
break;
|
||||
case 'D':
|
||||
case 'd':
|
||||
outParam = 'e';
|
||||
break;
|
||||
case 'E':
|
||||
case 'e':
|
||||
outParam = 'f';
|
||||
break;
|
||||
case 'F':
|
||||
case 'f':
|
||||
outParam = 'g';
|
||||
break;
|
||||
case 'G':
|
||||
case 'g':
|
||||
outParam = 'h';
|
||||
break;
|
||||
case 'H':
|
||||
case 'h':
|
||||
outParam = 'i';
|
||||
break;
|
||||
default:
|
||||
outParam = 'z';
|
||||
break;
|
||||
}
|
||||
outVal[i] = outParam;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
int test_array[100];
|
||||
|
||||
int dyn_bss_func(void)
|
||||
{
|
||||
test_array[0] += 100;
|
||||
return 2017 + test_array[0];
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
void init_test(void) __attribute__((constructor));
|
||||
void fini_test(void) __attribute((destructor));
|
||||
int g_param = 10;
|
||||
static int param = 2;
|
||||
|
||||
void init_first(void)
|
||||
{
|
||||
g_param = 100;
|
||||
}
|
||||
|
||||
void init_test(void)
|
||||
{
|
||||
g_param += param;
|
||||
}
|
||||
|
||||
void fini_end(void)
|
||||
{
|
||||
g_param = 0;
|
||||
}
|
||||
|
||||
void fini_test(void)
|
||||
{
|
||||
param = 0;
|
||||
}
|
||||
|
||||
int callee(int a, int b)
|
||||
{
|
||||
return g_param + a + b;
|
||||
}
|
||||
|
||||
int test_api(int a, int b)
|
||||
{
|
||||
int c = callee(a, b);
|
||||
return c;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
static int staticParam = 9;
|
||||
int g_param = 10;
|
||||
|
||||
int add_test(int a, int b)
|
||||
{
|
||||
int c;
|
||||
c = a + b + g_param - staticParam;
|
||||
return c;
|
||||
}
|
||||
|
||||
static int static_sub_test(int a, int b)
|
||||
{
|
||||
int c;
|
||||
c = a - b + g_param - staticParam;
|
||||
return c;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
int g_param = 10;
|
||||
|
||||
int callee(int a, int b)
|
||||
{
|
||||
return a + b + g_param;
|
||||
}
|
||||
|
||||
int caller(int a, int b)
|
||||
{
|
||||
return 2021 + callee(a, b);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
extern int undef_func(int a, int b);
|
||||
|
||||
int caller(int a, int b)
|
||||
{
|
||||
return a + undef_func(a, b);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
extern int g_param;
|
||||
|
||||
int caller(int a, int b)
|
||||
{
|
||||
return a + b + g_param;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
int g_value100 = 100;
|
||||
int *g_pValue100 = &g_value100;
|
||||
static int value200 = 200;
|
||||
int *g_pValue200 = &value200;
|
||||
|
||||
int get_value100(void)
|
||||
{
|
||||
return *g_pValue100;
|
||||
}
|
||||
|
||||
int get_value200(void)
|
||||
{
|
||||
return *g_pValue200;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#!/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_FLAG=false
|
||||
|
|
@ -126,6 +126,9 @@ void TestKernel(void)
|
|||
#if (LOS_KERNEL_MEM_TEST == 1)
|
||||
ItSuiteLosMem();
|
||||
#endif
|
||||
#if (LOS_KERNEL_DYNLINK_TEST == 1)
|
||||
ItSuiteLosDynlink();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue