From 54ce2697466befdd5015d2eb4d72de4fdf176342 Mon Sep 17 00:00:00 2001 From: liqiao49 Date: Sat, 15 Jul 2023 11:04:25 +0800 Subject: [PATCH 1/3] fix safuzz test crash Signed-off-by: liqiao49 --- interfaces/ipc/include/distributed_input_source_stub.h | 3 +++ interfaces/ipc/src/distributed_input_source_stub.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 2690ce8..75484f0 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -19,6 +19,7 @@ #include "i_distributed_source_input.h" #include +#include #include "iremote_stub.h" @@ -57,6 +58,8 @@ private: int32_t HandleRegisterSimulationEventListener(MessageParcel &data, MessageParcel &reply); int32_t HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply); DISALLOW_COPY_AND_MOVE(DistributedInputSourceStub); +private: + std::atomic sourceInitFlag_ {false}; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 6475bca..7a830ef 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -31,11 +31,16 @@ DistributedInputSourceStub::~DistributedInputSourceStub() int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel &reply) { + if (sourceInitFlag_.load()) { + DHLOGE("DistributedInputSourceStub already init."); + return DH_SUCCESS; + } int32_t ret = Init(); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSourceStub Init write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } + sourceInitFlag_.store(true); return DH_SUCCESS; } -- Gitee From 6e267f90e8e22fe21a4144662354fff46ad42a91 Mon Sep 17 00:00:00 2001 From: liqiao49 Date: Sat, 15 Jul 2023 11:17:52 +0800 Subject: [PATCH 2/3] add source manager release mutex Signed-off-by: liqiao49 --- interfaces/ipc/include/distributed_input_source_stub.h | 6 ++++-- interfaces/ipc/src/distributed_input_source_stub.cpp | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 75484f0..5df3b2c 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -18,8 +18,9 @@ #include "i_distributed_source_input.h" -#include #include +#include +#include #include "iremote_stub.h" @@ -59,7 +60,8 @@ private: int32_t HandleUnregisterSimulationEventListener(MessageParcel &data, MessageParcel &reply); DISALLOW_COPY_AND_MOVE(DistributedInputSourceStub); private: - std::atomic sourceInitFlag_ {false}; + std::atomic sourceManagerInitFlag_ {false}; + std::mutex sourceManagerReleaseMutex_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 7a830ef..16d1984 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -31,7 +31,7 @@ DistributedInputSourceStub::~DistributedInputSourceStub() int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel &reply) { - if (sourceInitFlag_.load()) { + if (sourceManagerInitFlag_.load()) { DHLOGE("DistributedInputSourceStub already init."); return DH_SUCCESS; } @@ -40,12 +40,13 @@ int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel DHLOGE("DistributedInputSourceStub Init write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } - sourceInitFlag_.store(true); + sourceManagerInitFlag_.store(true); return DH_SUCCESS; } int32_t DistributedInputSourceStub::HandleReleaseDistributedHardware(MessageParcel &reply) { + std::unique_lock lock(sourceManagerReleaseMutex_); int32_t ret = Release(); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSourceStub release write ret failed"); -- Gitee From 082590745c16c536ca96c1eba6e8cd6bf814865d Mon Sep 17 00:00:00 2001 From: liqiao49 Date: Mon, 17 Jul 2023 12:04:06 +0800 Subject: [PATCH 3/3] fix dinput crash Signed-off-by: liqiao49 --- interfaces/ipc/include/distributed_input_source_stub.h | 2 +- interfaces/ipc/src/distributed_input_source_stub.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 5df3b2c..8f40adb 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -61,7 +61,7 @@ private: DISALLOW_COPY_AND_MOVE(DistributedInputSourceStub); private: std::atomic sourceManagerInitFlag_ {false}; - std::mutex sourceManagerReleaseMutex_; + std::mutex operatorMutex_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 16d1984..5b7a959 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -31,6 +31,7 @@ DistributedInputSourceStub::~DistributedInputSourceStub() int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel &reply) { + std::unique_lock lock(operatorMutex_); if (sourceManagerInitFlag_.load()) { DHLOGE("DistributedInputSourceStub already init."); return DH_SUCCESS; @@ -46,12 +47,17 @@ int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel int32_t DistributedInputSourceStub::HandleReleaseDistributedHardware(MessageParcel &reply) { - std::unique_lock lock(sourceManagerReleaseMutex_); + std::unique_lock lock(operatorMutex_); + if (!sourceManagerInitFlag_.load()) { + DHLOGE("DistributedInputSourceStub already Release."); + return DH_SUCCESS; + } int32_t ret = Release(); if (!reply.WriteInt32(ret)) { DHLOGE("DistributedInputSourceStub release write ret failed"); return ERR_DH_INPUT_IPC_WRITE_TOKEN_VALID_FAIL; } + sourceManagerInitFlag_.store(false); return DH_SUCCESS; } -- Gitee