From b5ef3284b54dca5ebf9ebc1921dc8538dc320487 Mon Sep 17 00:00:00 2001 From: liuyuxiu Date: Tue, 26 Nov 2024 14:39:14 +0800 Subject: [PATCH] =?UTF-8?q?qos=20adapt=20FDSAN=20=EF=BC=88cherry=20picked?= =?UTF-8?q?=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/include/concurrent_task_utils.h | 25 ++++++++++++++++++++++++ common/src/concurrent_task_utils.cpp | 27 ++++++++++++++++++++++++++ qos/BUILD.gn | 2 ++ services/BUILD.gn | 3 ++- services/src/qos_interface.cpp | 19 ++++++++++++------ 5 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 common/include/concurrent_task_utils.h create mode 100644 common/src/concurrent_task_utils.cpp diff --git a/common/include/concurrent_task_utils.h b/common/include/concurrent_task_utils.h new file mode 100644 index 0000000..96ead4a --- /dev/null +++ b/common/include/concurrent_task_utils.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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. + */ + +#ifndef CONCURRENT_TASK_COMMON_INCLUDE_CONCURRENT_TASK_UTILS_H +#define CONCURRENT_TASK_COMMON_INCLUDE_CONCURRENT_TASK_UTILS_H + +#include + + +uint64_t GetAddrTag(void* addr); + + +#endif // CONCURRENT_TASK_COMMON_INCLUDE_CONCURRENT_TASK_UTILS_H \ No newline at end of file diff --git a/common/src/concurrent_task_utils.cpp b/common/src/concurrent_task_utils.cpp new file mode 100644 index 0000000..80eef27 --- /dev/null +++ b/common/src/concurrent_task_utils.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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 +#include +#include "concurrent_task_utils.h" + + +uint64_t GetAddrTag(void* addr) { + uint64_t tag = 0; + if (addr != nullptr) { + tag = fdsan_create_owner_tag(FDSAN_OWNER_TYPE_FILE, (uint64_t)addr); + } + return tag; +} \ No newline at end of file diff --git a/qos/BUILD.gn b/qos/BUILD.gn index 8372df9..2e29882 100644 --- a/qos/BUILD.gn +++ b/qos/BUILD.gn @@ -19,6 +19,7 @@ config("qos_config") { "../include/", "../interfaces/inner_api/", "../services/include/", + "../common/include/", ] } @@ -38,6 +39,7 @@ ohos_shared_library("qos") { ] public_configs = [ ":qos_config" ] sources = [ + "../common/src/concurrent_task_utils.cpp", "../services/src/qos_interface.cpp", "qos.cpp", ] diff --git a/services/BUILD.gn b/services/BUILD.gn index 8c23109..5cb3d24 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -25,7 +25,7 @@ config("concurrent_task_config") { "../include", "../frameworks/concurrent_task_client/include/", "../interfaces/inner_api/", - "../common/include", + "../common/include/", ] } @@ -53,6 +53,7 @@ ohos_shared_library("concurrentsvc") { ldflags = [ "-Wl,--exclude-libs=ALL" ] sources = [ + "../common/src/concurrent_task_utils.cpp", "src/concurrent_task_controller_interface.cpp", "src/concurrent_task_service.cpp", "src/concurrent_task_service_ability.cpp", diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index ebabca7..189d122 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -27,6 +27,7 @@ #include #include "concurrent_task_log.h" +#include "concurrent_task_utils.h" static int TrivalOpenRtgNode(void) { @@ -61,13 +62,14 @@ int EnableRtg(bool flag) if (fd < 0) { return fd; } + fdsan_exchange_owner_tag(fd, 0, GetAddrTag((void*)&fd)); int ret = ioctl(fd, CMD_ID_SET_ENABLE, &enableData); if (ret < 0) { CONCUR_LOGE("set rtg config enable failed."); } - close(fd); + fdsan_close_with_tag(fd, GetAddrTag((void*)&fd)); return 0; }; @@ -85,6 +87,7 @@ int QosApplyForOther(unsigned int level, int tid) if (fd < 0) { return fd; } + fdsan_exchange_owner_tag(fd, 0, GetAddrTag((void*)&fd)); struct QosCtrlData data; data.level = level; @@ -95,7 +98,7 @@ int QosApplyForOther(unsigned int level, int tid) if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d apply qos failed, errno = %{public}d", tid, errno); } - close(fd); + fdsan_close_with_tag(fd, GetAddrTag((void*)&fd)); return ret; } @@ -105,6 +108,7 @@ int QosLeave(void) if (fd < 0) { return fd; } + fdsan_exchange_owner_tag(fd, 0, GetAddrTag((void*)&fd)); struct QosCtrlData data; data.type = static_cast(QosManipulateType::QOS_LEAVE); @@ -114,7 +118,7 @@ int QosLeave(void) if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d leave qos failed, errno = %{public}d", gettid(), errno); } - close(fd); + fdsan_close_with_tag(fd, GetAddrTag((void*)&fd)); return ret; } @@ -124,6 +128,7 @@ int QosLeaveForOther(int tid) if (fd < 0) { return fd; } + fdsan_exchange_owner_tag(fd, 0, GetAddrTag((void*)&fd)); struct QosCtrlData data; data.type = static_cast(QosManipulateType::QOS_LEAVE); @@ -133,7 +138,7 @@ int QosLeaveForOther(int tid) if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d leave qos failed, errno = %{public}d", tid, errno); } - close(fd); + fdsan_close_with_tag(fd, GetAddrTag((void*)&fd)); return ret; } @@ -143,12 +148,13 @@ int QosPolicySet(const struct QosPolicyDatas* policyDatas) if (fd < 0) { return fd; } + fdsan_exchange_owner_tag(fd, 0, GetAddrTag((void*)&fd)); int ret = ioctl(fd, QOS_CTRL_POLICY_OPERATION, policyDatas); if (ret < 0) { CONCUR_LOGE("[Interface] set qos policy failed, errno = %{public}d", errno); } - close(fd); + fdsan_close_with_tag(fd, GetAddrTag((void*)&fd)); return ret; } @@ -164,6 +170,7 @@ int QosGetForOther(int tid, int& level) if (fd < 0) { return fd; } + fdsan_exchange_owner_tag(fd, 0, GetAddrTag((void*)&fd)); struct QosCtrlData data; data.type = static_cast(QosManipulateType::QOS_GET); @@ -176,6 +183,6 @@ int QosGetForOther(int tid, int& level) } level = data.qos; - close(fd); + fdsan_close_with_tag(fd, GetAddrTag((void*)&fd)); return ret; } \ No newline at end of file -- Gitee