1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HIVIEW_PLUGINS_CRASH_VALIDATOR_H 17 #define HIVIEW_PLUGINS_CRASH_VALIDATOR_H 18 19 #include <memory> 20 #include <mutex> 21 #include <string> 22 23 #include "event.h" 24 #include "plugin.h" 25 #include "sys_event.h" 26 27 namespace OHOS { 28 namespace HiviewDFX { 29 class CrashValidator : public Plugin { 30 public: 31 CrashValidator(); 32 ~CrashValidator(); 33 void OnLoad() override; 34 void OnUnload() override; 35 bool OnEvent(std::shared_ptr<Event>& event) override; 36 bool IsInterestedPipelineEvent(std::shared_ptr<Event> event) override; 37 private: 38 void InitWorkLoop(); 39 bool MatchEvent(int32_t pid); 40 bool CheckProcessMapEmpty(); 41 void AddEventToMap(int32_t pid, std::shared_ptr<SysEvent> sysEvent); 42 void ReportMatchEvent(std::string eventName, std::shared_ptr<SysEvent> sysEvent); 43 void ReportDisMatchEvent(std::shared_ptr<SysEvent> sysEvent); 44 45 std::shared_ptr<SysEvent> Convert2SysEvent(std::shared_ptr<Event>& event); 46 std::atomic<bool> hasLoaded_; 47 std::mutex mutex_; 48 std::map<int32_t, std::shared_ptr<SysEvent>> processExitEvents_; 49 std::map<int32_t, std::shared_ptr<SysEvent>> cppCrashEvents_; 50 std::map<int32_t, std::shared_ptr<SysEvent>> cppCrashExceptionEvents_; 51 }; 52 } // namespace HiviewDFX 53 } // namespace OHOS 54 55 #endif