diff --git a/common/include/concurrent_task_utils.h b/common/include/concurrent_task_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..96ead4af860310b19aac67dee508d86cdc2bee63 --- /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 0000000000000000000000000000000000000000..82df7b7e26679c64e635f96926352c6c0a981747 --- /dev/null +++ b/common/src/concurrent_task_utils.cpp @@ -0,0 +1,28 @@ +/* + * 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 8372df94d44e21143b4a26057dc2b1f7c8ad9685..2e298823cb1286c75c551ff1d3683bd725f35de4 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 8c231099d710bb7329e33f515536968eed3ef9b8..5cb3d245f37b03c95e75ed3db23b0c58d113d9ff 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 ebabca7480befd3205e18464dc32a26693aba356..4caa8824998784f27c7e2e5a74e32c6ef62f8ffa 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(static_cast(&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(static_cast(&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(static_cast(&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(static_cast(&fd))); return ret; } @@ -105,6 +108,7 @@ int QosLeave(void) if (fd < 0) { return fd; } + fdsan_exchange_owner_tag(fd, 0, GetAddrTag(static_cast(&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(static_cast(&fd))); return ret; } @@ -124,6 +128,7 @@ int QosLeaveForOther(int tid) if (fd < 0) { return fd; } + fdsan_exchange_owner_tag(fd, 0, GetAddrTag(static_cast(&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(static_cast(&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(static_cast(&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(static_cast(&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(static_cast(&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(static_cast(&fd))); return ret; } \ No newline at end of file