diff --git a/etc/samgr_standard.cfg b/etc/samgr_standard.cfg index a3ce2cd8893ee7a5e182b9844dc3ea45bd01416e..3b7f03bf794b57f6b6c80c7137af49aea3bb5274 100644 --- a/etc/samgr_standard.cfg +++ b/etc/samgr_standard.cfg @@ -12,6 +12,7 @@ "critical" : [1, 1, 60], "uid" : "samgr", "gid" : ["samgr", "system", "readproc", "data_reserve"], + "writepid" : ["/dev/memcg/perf_sensitive/cgroup.procs"], "file" : ["/dev/kmsg rd 0660 root system"], "bootevents":"bootevent.samgr.ready", "permission": [ diff --git a/interfaces/innerkits/common/BUILD.gn b/interfaces/innerkits/common/BUILD.gn index 837fb697d014faa475dbb0677fb7152b05b674e3..639f675d70fcb3bf724b31ea9f8e363aea69bbc0 100644 --- a/interfaces/innerkits/common/BUILD.gn +++ b/interfaces/innerkits/common/BUILD.gn @@ -79,7 +79,7 @@ ohos_shared_library("samgr_common") { external_deps += [ "hicollie:libhicollie" ] defines += [ "HICOLLIE_ENABLE" ] } - public_external_deps = [ "json:nlohmann_json_static" ] + external_deps += [ "json:nlohmann_json_static" ] part_name = "samgr" } diff --git a/interfaces/innerkits/dynamic_cache/BUILD.gn b/interfaces/innerkits/dynamic_cache/BUILD.gn index 38d8adf893a8a8775e6b1a6cc5aed200d17191e3..4c5fc7d3efcf2db5feb7fb3d49ac44af8832e151 100644 --- a/interfaces/innerkits/dynamic_cache/BUILD.gn +++ b/interfaces/innerkits/dynamic_cache/BUILD.gn @@ -20,7 +20,7 @@ config("dynamic_cache_config") { include_dirs = [ "include" ] } -ohos_shared_library("dynamic_cache") { +ohos_static_library("dynamic_cache") { sanitize = { cfi = true cfi_cross_dso = true @@ -29,7 +29,8 @@ ohos_shared_library("dynamic_cache") { blocklist = "../../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" - + sources = [ "./src/dynamic_cache.cpp" ] + configs = [ "../samgr_proxy:samgr_proxy_config" ] all_dependent_configs = [ ":dynamic_cache_config" ] public_configs = [ ":dynamic_cache_config" ] if (is_standard_system) { @@ -37,11 +38,9 @@ ohos_shared_library("dynamic_cache") { "c_utils:utils", "hilog:libhilog", "init:libbegetutil", + "ipc:ipc_core", ] } - - install_images = [ system_base_dir ] - relative_install_dir = "chipset-pub-sdk" part_name = "samgr" subsystem_name = "systemabilitymgr" } diff --git a/interfaces/innerkits/dynamic_cache/include/dynamic_cache.h b/interfaces/innerkits/dynamic_cache/include/dynamic_cache.h index 513a88bad18f8221f81de9becc2bf0f4ef207071..55a00f315f03da3dd044c659df3cc2e24846add1 100644 --- a/interfaces/innerkits/dynamic_cache/include/dynamic_cache.h +++ b/interfaces/innerkits/dynamic_cache/include/dynamic_cache.h @@ -18,99 +18,33 @@ #include #include -#include - -#include "datetime_ex.h" #include "iremote_object.h" -#include "parameter.h" -#include "refbase.h" -#include "sam_log.h" -#include "sysparam_errno.h" namespace OHOS { using namespace std; class DynamicCache : public IRemoteObject::DeathRecipient { public: + void OnRemoteDied(const wptr& remote) override { - HILOGD("DynamicCache OnRemoteDied called"); ClearCache(); } - sptr QueryResult(int32_t querySaId, int32_t code) - { - int32_t waterLineLength = 128; - char waterLine[128] = {0}; - string defaultValue = "default"; - GetParameter(key_.c_str(), defaultValue.c_str(), waterLine, waterLineLength); - { - std::lock_guard autoLock(queryCacheLock_); - if (CanUseCache(querySaId, waterLine, defaultValue)) { - HILOGD("DynamicCache QueryResult Return Cache %{public}d", querySaId); - return lastQuerySaProxy_; - } - } - HILOGD("DynamicCache QueryResult Recompute"); - sptr res = Recompute(querySaId, code); - if (res == nullptr) { - return nullptr; - } - { - std::lock_guard autoLock(queryCacheLock_); - localPara_[key_] = waterLine; - if (lastQuerySaProxy_ != nullptr) { - HILOGD("DynamicCache RemoveDeathRecipient"); - lastQuerySaProxy_->RemoveDeathRecipient(this); - } - lastQuerySaId_ = querySaId; - lastQuerySaProxy_ = res; - res->AddDeathRecipient(this); - } - return res; - } - bool CanUseCache(int32_t querySaId, char* waterLine, string defaultValue) - { - return localPara_.count(key_) != 0 && lastQuerySaId_ == querySaId && - defaultValue != string(waterLine) && string(waterLine) == localPara_[key_] && - lastQuerySaProxy_ != nullptr && !lastQuerySaProxy_->IsObjectDead(); - } + sptr QueryResult(int32_t querySaId, int32_t code); + bool CanUseCache(int32_t querySaId, char* waterLine, std::string defaultValue); - __attribute__((no_sanitize("cfi"))) - void ClearCache() + void __attribute__((no_sanitize("cfi"))) ClearCache() { std::lock_guard autoLock(queryCacheLock_); if (lastQuerySaProxy_ != nullptr) { - HILOGD("DynamicCache RemoveDeathRecipient"); lastQuerySaProxy_->RemoveDeathRecipient(this); } lastQuerySaId_ = -1; lastQuerySaProxy_ = nullptr; } - - bool InvalidateCache() - { - HILOGD("DynamicCache InvalidateCache Begin"); - string tickCount = to_string(GetTickCount()); - int32_t ret = SetParameter(key_.c_str(), tickCount.c_str()); - if (ret != EC_SUCCESS) { - HILOGE("DynamicCache InvalidateCache SetParameter error:%{public}d!", ret); - return false; - } - HILOGD("DynamicCache InvalidateCache End"); - return true; - } - - bool SetKey(const string& key) - { - int32_t maxLength = 256; - if (key.size() == 0 || (int32_t)key.size() > maxLength) { - HILOGE("DynamicCache SetKey size error:%{public}zu!", key.size()); - return false; - } - key_ = key; - return true; - } - + + bool InvalidateCache(); + bool SetKey(const std::string& key); virtual sptr Recompute(int32_t querySaId, int32_t code) { std::lock_guard autoLock(queryCacheLock_); @@ -119,12 +53,13 @@ public: } return lastQuerySaProxy_; } + private: std::mutex queryCacheLock_; - map localPara_; - string key_; + std::map localPara_; + std::string key_; int32_t lastQuerySaId_; sptr lastQuerySaProxy_; }; -} +} // namespace OHOS #endif /* DYNAMIC_CACHE_H */ \ No newline at end of file diff --git a/interfaces/innerkits/dynamic_cache/src/dynamic_cache.cpp b/interfaces/innerkits/dynamic_cache/src/dynamic_cache.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0deff3baa6cc06e953cb9b158da18f1957ff76c --- /dev/null +++ b/interfaces/innerkits/dynamic_cache/src/dynamic_cache.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "dynamic_cache.h" + +#include "datetime_ex.h" +#include "parameter.h" +#include "refbase.h" +#include "sam_log.h" +#include "sysparam_errno.h" + +using namespace std; +namespace OHOS { + +sptr DynamicCache::QueryResult(int32_t querySaId, int32_t code) +{ + int32_t waterLineLength = 128; + char waterLine[128] = {0}; + string defaultValue = "default"; + GetParameter(key_.c_str(), defaultValue.c_str(), waterLine, waterLineLength); + { + std::lock_guard autoLock(queryCacheLock_); + if (CanUseCache(querySaId, waterLine, defaultValue)) { + HILOGD("DynamicCache QueryResult Return Cache %{public}d", querySaId); + return lastQuerySaProxy_; + } + } + HILOGD("DynamicCache QueryResult Recompute"); + sptr res = Recompute(querySaId, code); + if (res == nullptr) { + return nullptr; + } + { + std::lock_guard autoLock(queryCacheLock_); + localPara_[key_] = waterLine; + if (lastQuerySaProxy_ != nullptr) { + HILOGD("DynamicCache RemoveDeathRecipient"); + lastQuerySaProxy_->RemoveDeathRecipient(this); + } + lastQuerySaId_ = querySaId; + lastQuerySaProxy_ = res; + res->AddDeathRecipient(this); + } + return res; +} + +bool DynamicCache::CanUseCache(int32_t querySaId, char* waterLine, string defaultValue) +{ + return localPara_.count(key_) != 0 && lastQuerySaId_ == querySaId && + defaultValue != string(waterLine) && string(waterLine) == localPara_[key_] && + lastQuerySaProxy_ != nullptr && !lastQuerySaProxy_->IsObjectDead(); +} + +bool DynamicCache::InvalidateCache() +{ + HILOGD("DynamicCache InvalidateCache Begin"); + string tickCount = to_string(GetTickCount()); + int32_t ret = SetParameter(key_.c_str(), tickCount.c_str()); + if (ret != EC_SUCCESS) { + HILOGE("DynamicCache InvalidateCache SetParameter error:%{public}d!", ret); + return false; + } + HILOGD("DynamicCache InvalidateCache End"); + return true; +} + +bool DynamicCache::SetKey(const string& key) +{ + int32_t maxLength = 256; + if (key.size() == 0 || (int32_t)key.size() > maxLength) { + HILOGE("DynamicCache SetKey size error:%{public}zu!", key.size()); + return false; + } + key_ = key; + return true; +} +} // namespace OHOS diff --git a/interfaces/innerkits/rust/src/definition.rs b/interfaces/innerkits/rust/src/definition.rs index fd1bd0e2873e39d60ceacfed8536bc4855ea623a..a766ac3b6c35bbdea7f151a7b2f01b078312f5fe 100644 --- a/interfaces/innerkits/rust/src/definition.rs +++ b/interfaces/innerkits/rust/src/definition.rs @@ -82,6 +82,7 @@ pub const WIFI_SCAN_SYS_ABILITY_ID: i32 = 1124; pub const BLUETOOTH_HOST_SYS_ABILITY_ID: i32 = 1130; pub const NFC_MANAGER_SYS_ABILITY_ID: i32 = 1140; pub const SE_MANAGER_SYS_ABILITY_ID: i32 = 1141; +pub const NFC_TAG_SYS_ABILITY_ID: i32 = 1148; pub const DISCOVER_SYS_ABILITY_ID: i32 = 1160; pub const DNET_SYS_ABILITY_ID: i32 = 1170; pub const NET_MANAGER_SYS_ABILITY_ID: i32 = 1150; @@ -306,6 +307,8 @@ pub const ECOLOGICAL_RULE_MANAGER_SA_ID: i32 = 6105; pub const SUBSYS_ACE_SYS_ABILITY_ID_BEGIN: i32 = 7001; pub const ARKUI_UI_APPEARANCE_SERVICE_ID: i32 = 7002; pub const CA_DAEMON_ID: i32 = 8001; +pub const TRUSTED_SERVICE_ID: i32 = 8002; +pub const ANTI_FRAUD_SERVICE_ID: i32 = 8003; pub const COMM_WEARABLE_DISTRIBUTED_NET_ABILITY_ID: i32 = 8400; // reserved for vendor diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h b/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h index 354fb74ad360d7bbbff17568d8878919b099b3ca..259067447a70749f3510a8d5248bc8ed79ceb539 100644 --- a/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_definition.h @@ -88,6 +88,7 @@ enum { BLUETOOTH_HOST_SYS_ABILITY_ID = 1130, NFC_MANAGER_SYS_ABILITY_ID = 1140, SE_MANAGER_SYS_ABILITY_ID = 1141, + NFC_TAG_SYS_ABILITY_ID = 1148, DISCOVER_SYS_ABILITY_ID = 1160, DNET_SYS_ABILITY_ID = 1170, NET_MANAGER_SYS_ABILITY_ID = 1150, @@ -320,6 +321,7 @@ enum { ARKUI_UI_APPEARANCE_SERVICE_ID = 7002, CA_DAEMON_ID = 8001, TRUSTED_SERVICE_ID = 8002, + ANTI_FRAUD_SERVICE_ID = 8003, ASSET_SERVICE_ID = 8100, EL5_FILEKEY_MANAGER_SERVICE_ID = 8250, COMM_FIREWALL_MANAGER_SYS_ABILITY_ID = 8300, diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn index e9acf73f4ccf8dac4aad142e907246e7748184da..34cccf3648d6bd7a6b280ec6b42459cb64cbb89e 100644 --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -105,6 +105,7 @@ ohos_executable("samgr") { "init:libbegetutil", "ipc:ipc_core", "ipc:libdbinder", + "json:nlohmann_json_static", "safwk:system_ability_ondemand_reason", ] diff --git a/services/samgr/native/include/system_ability_manager.h b/services/samgr/native/include/system_ability_manager.h index f4c672d4c3e0c5eb235f93643380f882a602399b..833f3eacac0a162bbabf62fe411ba8355e8ccb50 100644 --- a/services/samgr/native/include/system_ability_manager.h +++ b/services/samgr/native/include/system_ability_manager.h @@ -283,7 +283,7 @@ private: void DoInsertSaData(const std::u16string& name, const sptr& ability, const SAExtraProp& extraProp); int32_t StartOnDemandAbility(int32_t systemAbilityId, bool& isExist) { - lock_guard onDemandAbilityLock(onDemandLock_); + std::lock_guard onDemandAbilityLock(onDemandLock_); return StartOnDemandAbilityLocked(systemAbilityId, isExist); } int32_t StartOnDemandAbilityLocked(int32_t systemAbilityId, bool& isExist); @@ -296,7 +296,7 @@ private: void InitSaProfile(); bool GetSaProfile(int32_t saId, CommonSaProfile& saProfile) { - lock_guard autoLock(saProfileMapLock_); + std::lock_guard autoLock(saProfileMapLock_); auto iter = saProfileMap_.find(saId); if (iter == saProfileMap_.end()) { return false; @@ -324,7 +324,7 @@ private: const OnDemandEvent& event); void StartOnDemandAbility(const std::u16string& name, int32_t systemAbilityId) { - lock_guard autoLock(onDemandLock_); + std::lock_guard autoLock(onDemandLock_); StartOnDemandAbilityLocked(name, systemAbilityId); } void StartOnDemandAbilityLocked(const std::u16string& name, int32_t systemAbilityId); @@ -333,7 +333,7 @@ private: int32_t StartDynamicSystemProcess(const std::u16string& name, int32_t systemAbilityId, const OnDemandEvent& event); bool StopOnDemandAbility(const std::u16string& name, int32_t systemAbilityId, const OnDemandEvent& event) { - lock_guard autoLock(onDemandLock_); + std::lock_guard autoLock(onDemandLock_); return StopOnDemandAbilityInner(name, systemAbilityId, event); } bool StopOnDemandAbilityInner(const std::u16string& name, int32_t systemAbilityId, const OnDemandEvent& event); diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index df9693de131159fb852cb5d3e8dec30b2dd218f7..f1349b1282acde1e0ba98b64b7289e828b58c190 100644 --- a/services/samgr/native/source/collect/common_event_collect.cpp +++ b/services/samgr/native/source/collect/common_event_collect.cpp @@ -17,6 +17,7 @@ #include "common_event_collect.h" +#include "datetime_ex.h" #include "ability_death_recipient.h" #include "system_ability_manager_util.h" #include "common_event_manager.h" diff --git a/services/samgr/native/source/collect/device_status_collect_manager.cpp b/services/samgr/native/source/collect/device_status_collect_manager.cpp index 0ab4559e8f5f5906abd952ddf962364a07f68062..66118b7dda2659a374351317115e7558f9bc2082 100644 --- a/services/samgr/native/source/collect/device_status_collect_manager.cpp +++ b/services/samgr/native/source/collect/device_status_collect_manager.cpp @@ -552,7 +552,7 @@ void DeviceStatusCollectManager::StringToTypeAndSaid(const std::string& eventStr HILOGW("StringToTypeAndSaid failed"); return; } - if (pos == string::npos) { + if (pos == std::string::npos) { HILOGW("StringToSaid failed"); return; } diff --git a/services/samgr/native/source/collect/ref_count_collect.cpp b/services/samgr/native/source/collect/ref_count_collect.cpp index 66b62b1cb49df3a615d1f30fccbd445fd70b9e82..bafb0e616813a597dda56600e0249b3f6b7ee7b1 100644 --- a/services/samgr/native/source/collect/ref_count_collect.cpp +++ b/services/samgr/native/source/collect/ref_count_collect.cpp @@ -17,7 +17,7 @@ namespace OHOS { namespace { -constexpr int32_t REF_RESIDENT_TIMER_INTERVAL = 1000 * 60 * 10; +constexpr int32_t REF_RESIDENT_TIMER_INTERVAL = 1000 * 60 * 60; constexpr int32_t REF_ONDEMAND_TIMER_INTERVAL = 1000 * 60 * 1; } diff --git a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp index 1c20f943d38bf4d379e4d5f8c47fea5b1a87e9d5..ab45a062b5fbc1ba9194cf5a36134ea907e9a1e6 100644 --- a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp +++ b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp @@ -1325,7 +1325,7 @@ int32_t SystemAbilityStateScheduler::CheckStartEnableOnce(const OnDemandEvent& e { int32_t result = ERR_INVALID_VALUE; if (saControl.enableOnce) { - lock_guard autoLock(startEnableOnceLock_); + std::lock_guard autoLock(startEnableOnceLock_); auto iter = startEnableOnceMap_.find(saControl.saId); if (iter != startEnableOnceMap_.end() && SamgrUtil::IsSameEvent(event, startEnableOnceMap_[saControl.saId])) { HILOGI("ondemand canceled for enable-once, ondemandId:%{public}d, SA:%{public}d", @@ -1340,7 +1340,7 @@ int32_t SystemAbilityStateScheduler::CheckStartEnableOnce(const OnDemandEvent& e LoadRequestInfo loadRequestInfo = {LOCAL_DEVICE, callback, saControl.saId, callingPid, event}; result = HandleLoadAbilityEvent(loadRequestInfo); if (saControl.enableOnce && result != ERR_OK) { - lock_guard autoLock(startEnableOnceLock_); + std::lock_guard autoLock(startEnableOnceLock_); auto& events = startEnableOnceMap_[saControl.saId]; events.remove(event); if (events.empty()) { @@ -1361,7 +1361,7 @@ int32_t SystemAbilityStateScheduler::CheckStopEnableOnce(const OnDemandEvent& ev { int32_t result = ERR_INVALID_VALUE; if (saControl.enableOnce) { - lock_guard autoLock(stopEnableOnceLock_); + std::lock_guard autoLock(stopEnableOnceLock_); auto iter = stopEnableOnceMap_.find(saControl.saId); if (iter != stopEnableOnceMap_.end() && SamgrUtil::IsSameEvent(event, stopEnableOnceMap_[saControl.saId])) { HILOGI("ondemand canceled for enable-once, ondemandId:%{public}d, SA:%{public}d", @@ -1377,7 +1377,7 @@ int32_t SystemAbilityStateScheduler::CheckStopEnableOnce(const OnDemandEvent& ev std::make_shared(event, saControl.saId, callingPid); result = HandleUnloadAbilityEvent(unloadRequestInfo); if (saControl.enableOnce && result != ERR_OK) { - lock_guard autoLock(stopEnableOnceLock_); + std::lock_guard autoLock(stopEnableOnceLock_); auto& events = stopEnableOnceMap_[saControl.saId]; events.remove(event); if (events.empty()) { diff --git a/services/samgr/native/source/system_ability_manager_dumper.cpp b/services/samgr/native/source/system_ability_manager_dumper.cpp index 7ee5db868effd170428153e5770ea6c6e67d2e37..aee4cd3471ef3f05cb2a56261ac8341b3ee907d4 100644 --- a/services/samgr/native/source/system_ability_manager_dumper.cpp +++ b/services/samgr/native/source/system_ability_manager_dumper.cpp @@ -403,7 +403,7 @@ void SystemAbilityManagerDumper::FfrtStatisticsParser(std::string& result) uint64_t minTime = std::numeric_limits::max(); uint64_t sumTime = 0; uint64_t avgTime = 0; - int count = 0; + uint64_t count = 0; while ((char*)currentStat < lastStat && std::strcmp(currentStat->taskName, "") != 0) { if (currentStat->startTime > currentStat->endTime) { currentStat = (ffrt_stat*)((char*)currentStat + FFRT_STAT_SIZE); diff --git a/services/samgr/native/test/unittest/BUILD.gn b/services/samgr/native/test/unittest/BUILD.gn index 1093230ac49c32258816667ce4e2c884f006f2ed..94c96b0c6263af57525dd87ec61467fe82bc951c 100644 --- a/services/samgr/native/test/unittest/BUILD.gn +++ b/services/samgr/native/test/unittest/BUILD.gn @@ -156,6 +156,13 @@ ohos_unittest("SystemAbilityMgrTest") { } ohos_unittest("SystemAbilityMgrCollectTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } module_out_path = module_output_path sources = [ @@ -282,6 +289,13 @@ ohos_unittest("SystemAbilityMgrCollectTest") { } ohos_unittest("SystemAbilityMgrDeviceNetworkingTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } module_out_path = module_output_path sources = [ @@ -375,6 +389,13 @@ ohos_unittest("SystemAbilityMgrDeviceNetworkingTest") { } ohos_unittest("SystemAbilityMgrStubTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } module_out_path = module_output_path sources = [ @@ -466,6 +487,13 @@ ohos_unittest("SystemAbilityMgrStubTest") { } ohos_unittest("SystemAbilityMgrProxyTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } module_out_path = module_output_path sources = [ @@ -507,6 +535,7 @@ ohos_unittest("SystemAbilityMgrProxyTest") { "c_utils:utils", "googletest:gtest_main", "hilog:libhilog", + "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_single", "json:nlohmann_json_static", @@ -548,12 +577,20 @@ ohos_unittest("LocalAbilityManagerProxyTest") { "c_utils:utils", "googletest:gtest_main", "hilog:libhilog", + "hisysevent:libhisysevent", "ipc:ipc_single", "json:nlohmann_json_static", ] } ohos_unittest("SystemAbilityStateSchedulerTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } module_out_path = module_output_path sources = [ @@ -635,6 +672,13 @@ ohos_unittest("SystemAbilityStateSchedulerTest") { } ohos_unittest("SystemAbilityMgrDumperTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } module_out_path = module_output_path sources = [ @@ -687,6 +731,7 @@ ohos_unittest("SystemAbilityMgrDumperTest") { "ipc:libdbinder", "json:nlohmann_json_static", "safwk:system_ability_fwk", + "samgr:dynamic_cache", ] defines = [] if (samgr_support_access_token) { @@ -699,6 +744,13 @@ ohos_unittest("SystemAbilityMgrDumperTest") { } ohos_unittest("MockSystemAbilityManagerTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } module_out_path = module_output_path sources = [ @@ -733,6 +785,7 @@ ohos_unittest("MockSystemAbilityManagerTest") { "ipc:libdbinder", "json:nlohmann_json_static", "safwk:system_ability_fwk", + "samgr:dynamic_cache", ] defines = [] if (samgr_support_access_token) { @@ -745,6 +798,13 @@ ohos_unittest("MockSystemAbilityManagerTest") { } ohos_executable("manual_ondemand") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } testonly = true sources = [ "${samgr_services_dir}/test/unittest/src/mock_permission.cpp", @@ -786,6 +846,13 @@ ohos_executable("manual_ondemand") { } ohos_executable("ondemand") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } testonly = true sources = [ "${samgr_services_dir}/test/unittest/src/mock_permission.cpp", @@ -827,6 +894,13 @@ ohos_executable("ondemand") { } ohos_executable("TestTool") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } testonly = true #module_out_path = module_output_path @@ -917,12 +991,20 @@ ohos_executable("TestTool") { "ipc:libdbinder", "json:nlohmann_json_static", "safwk:system_ability_fwk", + "samgr:dynamic_cache", ] part_name = "samgr" subsystem_name = "systemabilitymgr" } ohos_static_library("samgr_proxy_tdd") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + cfi_no_nvcall = true + blocklist = "../../../../../cfi_blocklist.txt" + } defines = [ "SAMGR_PROXY" ] sources = [ "//foundation/systemabilitymgr/samgr/frameworks/native/source/system_ability_load_callback_stub.cpp", diff --git a/test/fuzztest/samgr_fuzzer/BUILD.gn b/test/fuzztest/samgr_fuzzer/BUILD.gn index a9aac270357db8a06287f2b0d8d0cad82bbd9b2b..b86f6e95528cf3b27d62b8e598715775cca710e5 100644 --- a/test/fuzztest/samgr_fuzzer/BUILD.gn +++ b/test/fuzztest/samgr_fuzzer/BUILD.gn @@ -167,7 +167,7 @@ foreach(item, samgr_fuzztests) { "src/fuzztest_utils.cpp", item.source, ] - deps = [] + deps = [ "//foundation/systemabilitymgr/samgr/interfaces/innerkits/dynamic_cache:dynamic_cache" ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -181,7 +181,9 @@ foreach(item, samgr_fuzztests) { "init:libbegetutil", "ipc:ipc_core", "ipc:libdbinder", + "json:nlohmann_json_static", "safwk:system_ability_fwk", + "samgr:dynamic_cache", "samgr:samgr_common", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/samgr_fuzzer/src/fuzztest_utils.cpp b/test/fuzztest/samgr_fuzzer/src/fuzztest_utils.cpp index 5733e4a92de8b639e54fde62ecf273c84d69c6f0..325fc4f481dadb5766d915139268f6622586dace 100644 --- a/test/fuzztest/samgr_fuzzer/src/fuzztest_utils.cpp +++ b/test/fuzztest/samgr_fuzzer/src/fuzztest_utils.cpp @@ -15,6 +15,7 @@ #include "fuzztest_utils.h" +#include "datetime_ex.h" #include "if_system_ability_manager.h" #include "sam_mock_permission.h" #include "system_ability_manager.h" diff --git a/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn b/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn index f082e2c6d5b405d4e35390a3827d4c7b65414683..39065272a7f0d2d61511dadd2a778fdd6d8c0b06 100644 --- a/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn +++ b/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn @@ -70,7 +70,7 @@ ohos_fuzztest("SamgrCoverageFuzzTest") { "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", "samgrcoverage_fuzzer.cpp", ] - deps = [] + deps = [ "//foundation/systemabilitymgr/samgr/interfaces/innerkits/dynamic_cache:dynamic_cache" ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -84,7 +84,9 @@ ohos_fuzztest("SamgrCoverageFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "ipc:libdbinder", + "json:nlohmann_json_static", "safwk:system_ability_fwk", + "samgr:dynamic_cache", "samgr:samgr_common", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/samgrcoverage_fuzzer/samgrcoverage_fuzzer.cpp b/test/fuzztest/samgrcoverage_fuzzer/samgrcoverage_fuzzer.cpp index 5f9d24d6658bfe88c370f5814b75e3245f64a026..3463ff5c6bbfd8a79a8f5f13d8825ba23a27b85e 100644 --- a/test/fuzztest/samgrcoverage_fuzzer/samgrcoverage_fuzzer.cpp +++ b/test/fuzztest/samgrcoverage_fuzzer/samgrcoverage_fuzzer.cpp @@ -106,12 +106,12 @@ void FuzzRemoveSystemProcess(const uint8_t* data, size_t size) ++count; saMgr->UnSubscribeSystemAbility(callback->AsObject()); - u16string name = u"test"; - string srcDeviceId = "srcDeviceId"; + std::u16string name = u"test"; + std::string srcDeviceId = "srcDeviceId"; saMgr->startingProcessMap_.clear(); sptr callbackOne = new SystemAbilityLoadCallbackMock(); SystemAbilityManager::AbilityItem abilityItem; - abilityItem.callbackMap[srcDeviceId].push_back(make_pair(callbackOne, SAID)); + abilityItem.callbackMap[srcDeviceId].push_back(std::make_pair(callbackOne, SAID)); saMgr->startingAbilityMap_[SAID] = abilityItem; saMgr->CleanCallbackForLoadFailed(SAID, name, srcDeviceId, callbackOne); } @@ -125,7 +125,7 @@ void FuzzNotifySystemAbilityLoaded(const uint8_t* data, size_t size) sptr callback = new SystemAbilityLoadCallbackMock(); sptr remoteObject = new TestTransactionService(); saMgr->NotifySystemAbilityLoaded(SAID, remoteObject, callback); - string srcDeviceId = "srcDeviceId"; + std::string srcDeviceId = "srcDeviceId"; FuzzedDataProvider fdp(data, size); int32_t systemAbilityId = fdp.ConsumeIntegral(); saMgr->LoadSystemAbilityFromRpc(srcDeviceId, systemAbilityId, callback); @@ -150,7 +150,7 @@ void FuzzNotifySystemAbilityLoaded(const uint8_t* data, size_t size) saMgr->OnRemoteCallbackDied(mockLoadCallback2->AsObject()); sptr callback2 = new SystemAbilityLoadCallbackMock(); - list> callbacks; + std::list> callbacks; callbacks.push_back(callback2); saMgr->remoteCallbackDeath_ = sptr(new RemoteCallbackDeathRecipient()); saMgr->RemoveRemoteCallbackLocked(callbacks, callback2); diff --git a/test/fuzztest/samgrdumper_fuzzer/BUILD.gn b/test/fuzztest/samgrdumper_fuzzer/BUILD.gn index 7ed1b8bc5076be7b22579eaf959cb7f356219173..7d446182a72924fcc81cdc132c5fce2cef4221f6 100644 --- a/test/fuzztest/samgrdumper_fuzzer/BUILD.gn +++ b/test/fuzztest/samgrdumper_fuzzer/BUILD.gn @@ -69,7 +69,7 @@ ohos_fuzztest("SamgrDumperFuzzTest") { "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", "samgrdumper_fuzzer.cpp", ] - deps = [] + deps = [ "//foundation/systemabilitymgr/samgr/interfaces/innerkits/dynamic_cache:dynamic_cache" ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -83,7 +83,9 @@ ohos_fuzztest("SamgrDumperFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "ipc:libdbinder", + "json:nlohmann_json_static", "safwk:system_ability_fwk", + "samgr:dynamic_cache", "samgr:samgr_common", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/samgrdumper_fuzzer/samgrdumper_fuzzer.cpp b/test/fuzztest/samgrdumper_fuzzer/samgrdumper_fuzzer.cpp index c81daef52609c6e69597f3d0b1cf68467b6400c8..aa01728bfacf071ce5c9d09bf84ee7a6ee2dfc9a 100644 --- a/test/fuzztest/samgrdumper_fuzzer/samgrdumper_fuzzer.cpp +++ b/test/fuzztest/samgrdumper_fuzzer/samgrdumper_fuzzer.cpp @@ -67,6 +67,13 @@ std::string BuildStringFromData(const uint8_t* data, size_t size) return strVal; } +void InitData(const uint8_t* data, size_t size) +{ + g_baseFuzzData = data; + g_baseFuzzSize = size; + g_baseFuzzPos = 0; +} + void SamgrDumperFuzzTest(const uint8_t* data, size_t size) { SamMockPermission::MockProcess(HIDUMPER_PROCESS_NAME); @@ -103,12 +110,9 @@ void SamgrDumperFuzzTest(const uint8_t* data, size_t size) manager->IpcDumpSingleProcess(fd, cmd, processName); } -void FuzzListenerDumpProc(const uint8_t* data, size_t size) +void FuzzListenerDumpProc() { SamMockPermission::MockProcess(HIDUMPER_PROCESS_NAME); - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; int32_t pid1 = GetData(); int32_t pid2 = GetData(); std::map> dumpListeners; @@ -149,11 +153,8 @@ void FuzzListenerDumpProc(const uint8_t* data, size_t size) args.clear(); } -void FuzzFfrtLoadMetrics(const uint8_t* data, size_t size) +void FuzzFfrtLoadMetrics() { - g_baseFuzzData = data; - g_baseFuzzSize = size; - g_baseFuzzPos = 0; int32_t pid = GetData(); std::shared_ptr scheduler = std::make_shared(); int32_t fd = -1; @@ -182,9 +183,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } + OHOS::Samgr::InitData(data, size); OHOS::Samgr::SamgrDumperFuzzTest(data, size); - OHOS::Samgr::FuzzListenerDumpProc(data, size); - OHOS::Samgr::FuzzFfrtLoadMetrics(data, size); + OHOS::Samgr::FuzzListenerDumpProc(); + OHOS::Samgr::FuzzFfrtLoadMetrics(); return 0; } diff --git a/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn b/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn index e18e9483fc62a054b39df0d07d51f68a65e5b9ca..9e0cf86a6e5627857a3f370b9d82d2dd2f2ad8af 100644 --- a/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn +++ b/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn @@ -69,7 +69,7 @@ ohos_fuzztest("SystemAbilityManagerFuzzTest") { "//foundation/systemabilitymgr/samgr/services/samgr/native/test/unittest/src/mock_permission.cpp", "systemabilitymanager_fuzzer.cpp", ] - deps = [] + deps = [ "//foundation/systemabilitymgr/samgr/interfaces/innerkits/dynamic_cache:dynamic_cache" ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -83,7 +83,9 @@ ohos_fuzztest("SystemAbilityManagerFuzzTest") { "init:libbegetutil", "ipc:ipc_core", "ipc:libdbinder", + "json:nlohmann_json_static", "safwk:system_ability_fwk", + "samgr:dynamic_cache", "samgr:samgr_common", "samgr:samgr_proxy", ] diff --git a/test/fuzztest/systemabilitymanager_fuzzer/systemabilitymanager_fuzzer.cpp b/test/fuzztest/systemabilitymanager_fuzzer/systemabilitymanager_fuzzer.cpp index c5dbcab0dd3aaa84cb9330a6afc7391747dd9770..0e84d4ebfbfff9adc5b642fd65e07b9697c9a524 100644 --- a/test/fuzztest/systemabilitymanager_fuzzer/systemabilitymanager_fuzzer.cpp +++ b/test/fuzztest/systemabilitymanager_fuzzer/systemabilitymanager_fuzzer.cpp @@ -15,6 +15,7 @@ #include "systemabilitymanager_fuzzer.h" +#include "datetime_ex.h" #include "if_system_ability_manager.h" #include "sam_mock_permission.h" #include "system_ability_manager.h"