diff --git a/common/include/concurrent_task_utils.h b/common/include/concurrent_task_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..c848f27dae6523b50f8b43715076af1e66e3a464 --- /dev/null +++ b/common/include/concurrent_task_utils.h @@ -0,0 +1,30 @@ +/* + * 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 +#include + + +namespace OHOS { +namespace ConcurrentTask { + +uint64_t GetAddrTag(void* addr); +} // namespace ConcurrentTask +} // namespace OHOS + +#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..6fd0bb7230a438cd1117b62e81981f14cb90ce20 --- /dev/null +++ b/common/src/concurrent_task_utils.cpp @@ -0,0 +1,29 @@ +/* + * 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 "concurrent_task_utils.h" + +namespace OHOS { +namespace ConcurrentTask { + +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/services/BUILD.gn b/services/BUILD.gn index 8c231099d710bb7329e33f515536968eed3ef9b8..a43a3df88edb76075209eac8f7d0bc0dc61f59cd 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -53,6 +53,7 @@ ohos_shared_library("concurrentsvc") { ldflags = [ "-Wl,--exclude-libs=ALL" ] sources = [ + "../common/src/comcurrent_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..a746ba3c75edd6965a6790d48b32a49f4f2b5997 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) { @@ -42,7 +43,7 @@ static int TrivalOpenRtgNode(void) static int TrivalOpenQosCtrlNode(void) { char fileName[] = "/proc/thread-self/sched_qos_ctrl"; - int fd = open(fileName, O_RDWR); + int fd = fopen(fileName, O_RDWR); if (fd < 0) { CONCUR_LOGE("[Interface] task %{public}d belong to user %{public}d open qos node failed, errno = %{public}d", getpid(), getuid(), errno); @@ -61,14 +62,13 @@ 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, GetAddr((void*)&fd)); return 0; }; @@ -85,6 +85,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 +96,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, GetAddr((void*)&fd)); return ret; } @@ -105,6 +106,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 +116,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, GetAddr((void*)&fd)); return ret; } @@ -124,6 +126,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 +136,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, GetAddr((void*)&fd)); return ret; } @@ -143,12 +146,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, GetAddr((void*)&fd)); return ret; } @@ -164,6 +168,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 +181,6 @@ int QosGetForOther(int tid, int& level) } level = data.qos; - close(fd); + fdsan_close_with_tag(fd, GetAddr((void*)&fd)); return ret; } \ No newline at end of file