1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. 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 #ifndef GWPASAN_COLLECTOR_H 16 #define GWPASAN_COLLECTOR_H 17 18 #include <algorithm> 19 #include <cstdint> 20 #include <cstdio> 21 #include <map> 22 #include <string> 23 #include <vector> 24 #include <regex> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 void WriteSanitizerLog(char* buf, size_t sz, char* path); 30 #ifdef __cplusplus 31 } 32 #endif 33 34 struct GwpAsanCurrInfo { 35 /** type of sanitizer */ 36 std::string faultType; 37 /** the time of happening fault */ 38 uint64_t happenTime; 39 /** the id of current user when fault happened */ 40 int32_t uid; 41 /** the id of process which fault happened*/ 42 int32_t pid; 43 /** type of fault */ 44 std::string moduleName; 45 /** name of module which fault occurred */ 46 std::string logPath; 47 /** logPath of module which fault occurred */ 48 std::string appVersion; 49 /** the reason why fault occurred */ 50 std::string errType; 51 /** the detail of fault information */ 52 std::string description; 53 /** the summary of fault information */ 54 std::string summary; 55 /** information about faultlog using <key,value> */ 56 std::map<std::string, std::string> sectionMaps; 57 /** hash value used for clustering */ 58 std::string hash; 59 /** top stack */ 60 std::string topStack; 61 /** telemetryId for gwpasan */ 62 std::string telemetryId; 63 }; 64 65 void ReadGwpAsanRecord(const std::string& gwpAsanBuffer, const std::string& faultType, char* logPath); 66 std::string GetNameByPid(int32_t pid); 67 std::string GetErrorTypeFromBuffer(const std::string& buffer, const std::string& faultType); 68 std::string GetTopStackWithoutCommonLib(const std::string& description); 69 void WriteCollectedData(const GwpAsanCurrInfo& currInfo, bool& isSendHisysevent); 70 void WriteToFaultLogger(const GwpAsanCurrInfo& currInfo); 71 bool WriteToSandbox(const GwpAsanCurrInfo& currInfo); 72 void SendSanitizerHisysevent(const GwpAsanCurrInfo& currInfo); 73 #endif // GWPASAN_COLLECTOR_H