提交 1c18c48b 编写于 作者: Z zhushengle

feat: 支持proc/self目录

BREAKING CHANGE:
支持proc/self目录对外变更:
1.支持/proc/self挂载目录,用于获取进程信息

Close #I6CZ72
Signed-off-by: Nzhushengle <zhushengle@huawei.com>
Change-Id: I465278785bd9e27ddbf4d34ee7b5457e39f98b5b
上级 bea394a7
......@@ -34,6 +34,7 @@ LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
declare_args() {
tee_enable = false
liteos_name = "OHOS_Image"
liteos_container_enable = false
liteos_skip_make = false
liteos_is_mini = false
}
......@@ -239,6 +240,21 @@ config("misc_config") {
asmflags = cflags
}
config("container_config") {
if (liteos_container_enable) {
cflags = [
"-DLOSCFG_KERNEL_CONTAINER",
"-DLOSCFG_PID_CONTAINER",
"-DLOSCFG_UTS_CONTAINER",
"-DLOSCFG_MNT_CONTAINER",
"-DLOSCFG_CHROOT",
"-DLOSCFG_IPC_CONTAINER",
"-DLOSCFG_TIME_CONTAINER",
"-DLOSCFG_PROC_PROCESS_DIR",
]
}
}
config("los_config") {
configs = [
":arch_config",
......@@ -249,6 +265,7 @@ config("los_config") {
":ssp_config",
":warn_config",
":misc_config",
":container_config",
]
}
......
......@@ -60,6 +60,14 @@ struct ProcessData {
unsigned int type;
};
static LosProcessCB *ProcGetProcessCB(struct ProcessData *data)
{
if (data->process != 0) {
return (LosProcessCB *)data->process;
}
return OsCurrProcessGet();
}
#define PROC_PID_PRIVILEGE 7
#define PROC_PID_DIR_LEN 100
#ifdef LOSCFG_KERNEL_CONTAINER
......@@ -95,7 +103,7 @@ static ssize_t ProcessContainerReadLink(struct ProcDirEntry *entry, char *buffer
if (data == NULL) {
return -EINVAL;
}
LosProcessCB *processCB = (LosProcessCB *)data->process;
LosProcessCB *processCB = ProcGetProcessCB(data);
SCHEDULER_LOCK(intSave);
UINT32 containerID = OsGetContainerID(processCB->container, (ContainerType)data->type);
SCHEDULER_UNLOCK(intSave);
......@@ -139,7 +147,7 @@ static int ProcessMemInfoRead(struct SeqBuf *seqBuf, LosProcessCB *pcb)
(void)LosBufPrintf(seqBuf, "VMSpaceMapSize: %u byte\n", vmSpace->mapSize);
(void)LosBufPrintf(seqBuf, "VM TLB Asid: %u\n", vmSpace->archMmu.asid);
(void)LosBufPrintf(seqBuf, "VMHeapSize: %u byte\n", heap->range.size);
(void)LosBufPrintf(seqBuf, "VMHeapRegionNmae: %s\n", OsGetRegionNameOrFilePath(heap));
(void)LosBufPrintf(seqBuf, "VMHeapRegionName: %s\n", OsGetRegionNameOrFilePath(heap));
(void)LosBufPrintf(seqBuf, "VMHeapRegionType: 0x%x\n", heap->regionType);
(void)LOS_MemFree(m_aucSysMem1, vmSpace);
return 0;
......@@ -192,7 +200,7 @@ static int ProcTimeContainerRead(struct SeqBuf *m, void *v)
struct ProcessData *data = (struct ProcessData *)v;
SCHEDULER_LOCK(intSave);
LosProcessCB *processCB = (LosProcessCB *)data->process;
LosProcessCB *processCB = ProcGetProcessCB(data);
ret = OsGetTimeContainerMonotonic(processCB, &offsets);
SCHEDULER_UNLOCK(intSave);
if (ret != LOS_OK) {
......@@ -265,7 +273,7 @@ static int ProcTimeContainerWrite(struct ProcFile *pf, const char *buf, size_t c
}
buf += strlen(g_monotonic);
ret = ProcSetTimensOffset(buf, (LosProcessCB *)data->process);
ret = ProcSetTimensOffset(buf, ProcGetProcessCB(data));
if (ret < 0) {
(VOID)LOS_MemFree(m_aucSysMem1, kbuf);
return ret;
......@@ -288,10 +296,10 @@ static int ProcProcessRead(struct SeqBuf *m, void *v)
struct ProcessData *data = (struct ProcessData *)v;
switch (data->type) {
case PROC_PID_MEM:
return ProcessMemInfoRead(m, (LosProcessCB *)data->process);
return ProcessMemInfoRead(m, ProcGetProcessCB(data));
#ifdef LOSCFG_KERNEL_CPUP
case PROC_PID_CPUP:
return ProcessCpupRead(m, (LosProcessCB *)data->process);
return ProcessCpupRead(m, ProcGetProcessCB(data));
#endif
default:
break;
......@@ -411,10 +419,18 @@ static struct ProcDirEntry *ProcCreatePorcess(UINT32 pid, struct ProcProcess *po
if (data == NULL) {
return NULL;
}
if (porcess->name != NULL) {
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u/%s", pid, porcess->name);
if (pid != OS_INVALID_VALUE) {
if (porcess->name != NULL) {
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u/%s", pid, porcess->name);
} else {
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u", pid);
}
} else {
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%u", pid);
if (porcess->name != NULL) {
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%s/%s", "self", porcess->name);
} else {
ret = snprintf_s(pidName, PROC_PID_DIR_LEN, PROC_PID_DIR_LEN - 1, "%s", "self");
}
}
if (ret < 0) {
free(data);
......@@ -448,9 +464,12 @@ int ProcCreateProcessDir(UINT32 pid, uintptr_t process)
}
}
SCHEDULER_LOCK(intSave);
((LosProcessCB *)process)->procDir = pidDir;
SCHEDULER_UNLOCK(intSave);
if (process != 0) {
SCHEDULER_LOCK(intSave);
((LosProcessCB *)process)->procDir = pidDir;
SCHEDULER_UNLOCK(intSave);
}
return 0;
CREATE_ERROR:
......@@ -482,7 +501,12 @@ void ProcProcessInit(void)
pde->procFileOps = &PROCESS_PROC_FOPS;
#ifdef LOSCFG_PROC_PROCESS_DIR
int ret = ProcCreateProcessDir(OS_USER_ROOT_PROCESS_ID, (uintptr_t)OsGetUserInitProcess());
int ret = ProcCreateProcessDir(OS_INVALID_VALUE, 0);
if (ret < 0) {
PRINT_ERR("Create proc process self dir failed!\n");
}
ret = ProcCreateProcessDir(OS_USER_ROOT_PROCESS_ID, (uintptr_t)OsGetUserInitProcess());
if (ret < 0) {
PRINT_ERR("Create proc process %d dir failed!\n", OS_USER_ROOT_PROCESS_ID);
}
......
......@@ -37,6 +37,5 @@ group("testsuites") {
deps = []
if (liteos_kernel_unittest) {
deps += [ "unittest" ]
#deps += [ "//kernel/liteos_a/testsuites/fuzz:fuzztest" ]
}
}
......@@ -167,5 +167,10 @@ group("unittest") {
deps += [ "container:liteos_a_container_unittest" ]
}
}
# fuzz test
if (LOSCFG_USER_FUZZ_TEST == true) {
deps += [ "fuzz:liteos_a_fuzztest" ]
}
}
}
......@@ -29,6 +29,10 @@
import("$root_out_dir/config.gni")
TEST_UNITTEST_DIR = rebase_path(".")
declare_args() {
liteos_container_test_enable = false
liteos_fuzz_test_enable = false
}
TEST_LEVEL_LOW = 1
TEST_LEVEL_MIDDLE = 3
......@@ -127,7 +131,7 @@ LOSCFG_USER_TEST_SECURITY_REUGID = true
LOSCFG_USER_TEST_SECURITY_VID = true
LOSCFG_USER_TEST_PROCESS_FS = false
if (defined(LOSCFG_PROC_PROCESS_DIR)) {
if (defined(LOSCFG_PROC_PROCESS_DIR) || liteos_container_test_enable == true) {
LOSCFG_USER_TEST_PROCESS_FS = true
}
......@@ -138,21 +142,27 @@ LOSCFG_USER_TEST_UTS_CONTAINER = false
LOSCFG_USER_TEST_MNT_CONTAINER = false
LOSCFG_USER_TEST_IPC_CONTAINER = false
LOSCFG_USER_TEST_TIME_CONTAINER = false
if (defined(LOSCFG_KERNEL_CONTAINER)) {
if (defined(LOSCFG_KERNEL_CONTAINER) || liteos_container_test_enable == true) {
LOSCFG_USER_TEST_CONTAINER = true
if (defined(LOSCFG_PID_CONTAINER)) {
if (defined(LOSCFG_PID_CONTAINER) || liteos_container_test_enable == true) {
LOSCFG_USER_TEST_PID_CONTAINER = true
}
if (defined(LOSCFG_UTS_CONTAINER)) {
if (defined(LOSCFG_UTS_CONTAINER) || liteos_container_test_enable == true) {
LOSCFG_USER_TEST_UTS_CONTAINER = true
}
if (defined(LOSCFG_MNT_CONTAINER)) {
if (defined(LOSCFG_MNT_CONTAINER) || liteos_container_test_enable == true) {
LOSCFG_USER_TEST_MNT_CONTAINER = true
}
if (defined(LOSCFG_IPC_CONTAINER)) {
if (defined(LOSCFG_IPC_CONTAINER) || liteos_container_test_enable == true) {
LOSCFG_USER_TEST_IPC_CONTAINER = true
}
if (defined(LOSCFG_TIME_CONTAINER)) {
if (defined(LOSCFG_TIME_CONTAINER) || liteos_container_test_enable == true) {
LOSCFG_USER_TEST_TIME_CONTAINER = true
}
}
########## fuzz test ##########
LOSCFG_USER_FUZZ_TEST = false
if (liteos_fuzz_test_enable == true) {
LOSCFG_USER_FUZZ_TEST = true
}
......@@ -36,11 +36,7 @@ common_include_dirs = [
sources_entry = [ "$TEST_UNITTEST_DIR/container/It_container_test.cpp" ]
sources_smoke = [
"$TEST_UNITTEST_DIR/container/smoke/It_container_001.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_container_chroot_001.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_container_chroot_002.cpp",
]
sources_smoke = [ "$TEST_UNITTEST_DIR/container/smoke/It_container_001.cpp" ]
sources_full = []
......@@ -91,6 +87,8 @@ if (defined(LOSCFG_USER_TEST_UTS_CONTAINER)) {
}
if (defined(LOSCFG_USER_TEST_MNT_CONTAINER)) {
sources_smoke += [
"$TEST_UNITTEST_DIR/container/smoke/It_container_chroot_001.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_container_chroot_002.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_mnt_container_001.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_mnt_container_002.cpp",
"$TEST_UNITTEST_DIR/container/smoke/It_mnt_container_003.cpp",
......
......@@ -28,7 +28,7 @@
import("//build/lite/config/test.gni")
fuzztest("FuzzDemoTest") {
fuzztest("liteos_a_user_fuzz_test") {
output_extension = "bin"
sources = [
"adjtime_fuzzer.cpp",
......@@ -83,6 +83,6 @@ fuzztest("FuzzDemoTest") {
include_dirs = []
deps = []
}
group("fuzztest") {
deps = [ ":FuzzDemoTest" ]
group("liteos_a_fuzztest") {
deps = [ ":liteos_a_user_fuzz_test" ]
}
......@@ -81,53 +81,11 @@ extern void TestSethostname(void);
int main()
{
DT_Set_Report_Path("/storage/");
TestPosixSpawnFileActionsAddchdirNp();
TestPosixSpawnFileActionsAddopen();
TestPosixSpawnFileActionsAdddup2();
TestPosixSpawnFileActionsAddfchdirNp();
TestPosixSpawnFileActionsDestroy();
TestPosixSpawnFileActionsInit();
TestPosixSpawnattrDestroy();
TestPosixSpawnattrGetflags();
TestPosixSpawnattrGetpgroup();
TestPosixSpawnattrGetschedparam();
TestPosixSpawnattrGetschedpolicy();
TestPosixSpawnattrGetsigdefault();
TestPosixSpawnattrGetsigmask();
TestPosixSpawnattrInit();
TestPosixSpawnattrSetflags();
TestPosixSpawnattrSetpgroup();
TestPosixSpawnattrSetschedparam();
TestPosixSpawnattrSetschedpolicy();
TestPosixSpawnattrSetsigdefault();
TestPosixSpawnattrSetsigmask();
TestPosixSpawn();
TestPosixSpawnp();
TestSyslog();
TestSystem();
TestMlock();
TestMlockall();
TestAdjtime();
TestFesetenv();
TestGetrlimit();
TestReadlink();
TestReadlinkat();
TestTimes();
TestSethostname();
TestClone();
TestEpollCreate();
TestEpollCtl();
TestEpollWait();
TestPthreadMutexConsistent();
TestPthreadMutexGetprioceiling();
TestPthreadMutexattrSetprotocol();
TestPthreadMutexattrSetrobust();
TestPthreadMutexattrSettype();
TestPthreadSetconcurrency();
TestSetns();
TestSemOpen();
TestUnshare();
TestChroot();
TestSethostname();
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册