diff --git a/bundle.json b/bundle.json index 12db5673bd..8b5dd30e24 100644 --- a/bundle.json +++ b/bundle.json @@ -45,7 +45,6 @@ "icu", "access_token", "eventhandler", - "hisysevent", "ipc", "safwk", "samgr", diff --git a/compiler_service/include/aot_compiler_error_utils.h b/compiler_service/include/aot_compiler_error_utils.h index 119490855c..e9a4d8cf45 100644 --- a/compiler_service/include/aot_compiler_error_utils.h +++ b/compiler_service/include/aot_compiler_error_utils.h @@ -31,6 +31,8 @@ enum { ERR_AOT_COMPILER_SIGNATURE_DISABLE = 10005, ERR_AOT_COMPILER_CALL_FAILED = 10006, ERR_AOT_COMPILER_STOP_FAILED = 10007, + ERR_AOT_COMPILER_CALL_CRASH = 10008, + ERR_AOT_COMPILER_CALL_CANCELLED = 10009, INVALID_ERR_CODE = 99999, }; diff --git a/compiler_service/src/aot_compiler_impl.cpp b/compiler_service/src/aot_compiler_impl.cpp index bae98f5d53..1c1548349a 100644 --- a/compiler_service/src/aot_compiler_impl.cpp +++ b/compiler_service/src/aot_compiler_impl.cpp @@ -113,14 +113,14 @@ void AotCompilerImpl::DropCapabilities() const int32_t bundleUid = 0; int32_t bundleGid = 0; GetBundleId(bundleUid, bundleGid); - if (setuid(bundleUid)) { - LOG_SA(ERROR) << "dropCapabilities setuid failed : " << strerror(errno); - exit(-1); - } if (setgid(bundleGid)) { LOG_SA(ERROR) << "dropCapabilities setgid failed : " << strerror(errno); exit(-1); } + if (setuid(bundleUid)) { + LOG_SA(ERROR) << "dropCapabilities setuid failed : " << strerror(errno); + exit(-1); + } struct __user_cap_header_struct capHeader; if (memset_s(&capHeader, sizeof(capHeader), 0, sizeof(capHeader)) != EOK) { LOG_SA(ERROR) << "memset_s capHeader failed : " << strerror(errno); @@ -203,7 +203,7 @@ void AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret) } else if (WIFSIGNALED(status)) { int signalNumber = WTERMSIG(status); LOG_SA(WARN) << "child process terminated by signal: " << signalNumber; - ret = ERR_AOT_COMPILER_CALL_FAILED; + ret = signalNumber == SIGKILL ? ERR_AOT_COMPILER_CALL_CANCELLED : ERR_AOT_COMPILER_CALL_CRASH; } else if (WIFSTOPPED(status)) { int signalNumber = WSTOPSIG(status); LOG_SA(WARN) << "child process was stopped by signal: " << signalNumber; @@ -248,7 +248,7 @@ int32_t AotCompilerImpl::EcmascriptAotCompiler(const std::unordered_map &argsMap, + std::vector &sigData) + { + #ifdef CODE_SIGN_ENABLE + if (!allowAotCompiler_) { + return ERR_AOT_COMPILER_CONNECT_FAILED; + } + if (argsMap.empty() || (PrepareArgs(argsMap) != ERR_OK)) { + return ERR_AOT_COMPILER_PARAM_FAILED; + } + int32_t ret = ERR_OK; + pid_t pid = fork(); + if (pid == -1) { + return ERR_AOT_COMPILER_CALL_FAILED; + } else if (pid == 0) { + DropCapabilities(); + sleep(2); // 2: mock ark aot compiler run time with 2s + ExecuteInChildProcess(); + } else { + mockChildPid_ = pid; + ExecuteInParentProcess(pid, ret); + } + if (ret == ERR_OK_NO_AOT_FILE) { + return ERR_OK; + } + return ret != ERR_OK ? ret : AOTLocalCodeSign(sigData); + #else + return ERR_AOT_COMPILER_SIGNATURE_DISABLE; + #endif + } + int32_t AOTLocalCodeSignMock(std::vector &sigData) const { return AOTLocalCodeSign(sigData); @@ -130,6 +161,14 @@ public: { AllowAotCompiler(); } + + pid_t GetChildPidMock() + { + return mockChildPid_; + } + +private: + pid_t mockChildPid_ = -1; }; class AotCompilerImplTest : public testing::Test { @@ -615,4 +654,61 @@ HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_027, TestSize.Level0) aotImplMock.HandleThermalLevelChanged(aotImplMock.AOT_COMPILE_STOP_LEVEL - 1); EXPECT_TRUE(viewData); } + +/** + * @tc.name: AotCompilerImplTest_028 + * @tc.desc: AotCompilerImpl::ExecuteInParentProcess(const pid_t childPid, int32_t &ret) + * child process terminate with signal SIGKILL; + * parent process receive SIGKILL signal; + * @tc.type: Func +*/ +AotCompilerImplMock g_aotImplMock; +int32_t g_aotRet = INVALID_ERR_CODE; + +void RunAotCompilerTask(void) +{ + std::unordered_map argsMap(argsMapForTest); + std::vector sigData; + { + std::lock_guard lock(aotCompilerMutex_); + int32_t aotRet = g_aotImplMock.EcmascriptAotCompilerMock(argsMap, sigData); + if (aotRet == ERR_AOT_COMPILER_CALL_CRASH || + aotRet == ERR_AOT_COMPILER_CALL_CANCELLED || + aotRet == ERR_AOT_COMPILER_SIGNATURE_DISABLE) { + g_aotRet = aotRet; + } + } +} + +void CancelAotCompilerTask(void) +{ + sleep(1); // 1: delay 1s + pid_t childPid = g_aotImplMock.GetChildPidMock(); + if (childPid > 0) { + g_aotImplMock.InitStateMock(childPid); + (void)g_aotImplMock.StopAotCompiler(); + } +} + +void TestCancelAotCompilerTask() +{ + std::thread([]() { + RunAotCompilerTask(); + }).detach(); + std::thread([]() { + CancelAotCompilerTask(); + }).detach(); + sleep(3); // 3: delay 3s +} + +HWTEST_F(AotCompilerImplTest, AotCompilerImplTest_028, TestSize.Level0) +{ + g_aotRet = INVALID_ERR_CODE; + TestCancelAotCompilerTask(); +#ifdef CODE_SIGN_ENABLE + EXPECT_EQ(g_aotRet, ERR_AOT_COMPILER_CALL_CANCELLED); +#else + EXPECT_EQ(g_aotRet, ERR_AOT_COMPILER_SIGNATURE_DISABLE); +#endif +} } // namespace OHOS::ArkCompiler \ No newline at end of file diff --git a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn index f0f8fd8340..e9a83c4a99 100644 --- a/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerproxy_unit/BUILD.gn @@ -29,6 +29,7 @@ ohos_unittest("AotCompilerProxyUnitTest") { "//third_party/googletest:gtest_main", ] external_deps = [ + "ability_base:want", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "c_utils:utils", diff --git a/compiler_service/test/unittest/aotcompilerproxy_unit/aotcompilerproxy_unit.cpp b/compiler_service/test/unittest/aotcompilerproxy_unit/aotcompilerproxy_unit.cpp index f137405314..2ffe13b298 100644 --- a/compiler_service/test/unittest/aotcompilerproxy_unit/aotcompilerproxy_unit.cpp +++ b/compiler_service/test/unittest/aotcompilerproxy_unit/aotcompilerproxy_unit.cpp @@ -331,7 +331,7 @@ HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_014, TestSize.Level0) { std::string sigData; std::string testData = "test"; - auto func = [&](MessageParcel &reply) -> int32_t { + auto func = [testData](MessageParcel &reply) -> int32_t { reply.WriteInt32(ERR_OK); reply.WriteString16(Str8ToStr16(testData)); return ERR_OK; @@ -389,7 +389,7 @@ HWTEST_F(AotCompilerProxyTest, AotCompilerProxyTest_017, TestSize.Level0) std::string args; bool sigData = false; bool testData = true; - auto func = [=](MessageParcel &data, MessageParcel &reply) -> int32_t { + auto func = [testData](MessageParcel &data, MessageParcel &reply) -> int32_t { reply.WriteInt32(ERR_OK); reply.WriteBool(testData); return ERR_OK; diff --git a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn index 46ee22d203..4a8de30464 100644 --- a/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerservice_unit/BUILD.gn @@ -29,6 +29,7 @@ ohos_unittest("AotCompilerServiceUnitTest") { "//third_party/googletest:gtest_main", ] external_deps = [ + "ability_base:want", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "c_utils:utils", diff --git a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn index d294897744..16ba9aa545 100644 --- a/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn +++ b/compiler_service/test/unittest/aotcompilerstub_unit/BUILD.gn @@ -29,6 +29,7 @@ ohos_unittest("AotCompilerStubUnitTest") { "//third_party/googletest:gtest_main", ] external_deps = [ + "ability_base:want", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", "c_utils:utils", @@ -40,7 +41,6 @@ ohos_unittest("AotCompilerStubUnitTest") { "icu:shared_icui18n", "icu:shared_icuuc", "ipc:ipc_core", - "power_manager:powermgr_client", "runtime_core:libarkfile_static", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/ecmascript/platform/unix/linux/os.cpp b/ecmascript/platform/unix/linux/os.cpp index 7c717199fc..7d116dfaf4 100644 --- a/ecmascript/platform/unix/linux/os.cpp +++ b/ecmascript/platform/unix/linux/os.cpp @@ -83,7 +83,7 @@ void BindMidCpuCore() cpu_set_t cpuset; CPU_ZERO(&cpuset); - for (int i = 0; i < 7; i++) { // 7: 0-3 little core, 4-6 mid core + for (size_t i = 0; i < 7; i++) { // 7: 0-3 little core, 4-6 mid core CPU_SET(i, &cpuset); }