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 DFX_UTIL_H 17 #define DFX_UTIL_H 18 19 #include <csignal> 20 #include <cstdio> 21 #include <fcntl.h> 22 #include <memory> 23 #include <string> 24 #include <sstream> 25 #include <sys/stat.h> 26 #include <unistd.h> 27 #include <vector> 28 #include "dfx_define.h" 29 30 namespace OHOS { 31 namespace HiviewDFX { 32 #ifndef is_host 33 AT_SYMBOL_HIDDEN bool TrimAndDupStr(const std::string &source, std::string &str); 34 AT_SYMBOL_HIDDEN uint64_t GetTimeMilliSeconds(void); 35 AT_SYMBOL_HIDDEN uint64_t GetAbsTimeMilliSeconds(void); 36 AT_SYMBOL_DEFAULT std::string GetCurrentTimeStr(uint64_t current = 0); 37 AT_SYMBOL_HIDDEN bool ReadDirFiles(const std::string& path, std::vector<std::string>& files); 38 AT_SYMBOL_HIDDEN bool VerifyFilePath(const std::string& filePath, const std::vector<const std::string>& validPaths); 39 AT_SYMBOL_HIDDEN void ParseSiValue(siginfo_t& si, uint64_t& endTime, int& tid); 40 #endif 41 AT_SYMBOL_HIDDEN off_t GetFileSize(const int& fd); 42 AT_SYMBOL_HIDDEN bool ReadFdToString(int fd, std::string& content); 43 } // nameapace HiviewDFX 44 } // nameapace OHOS 45 46 // this will also used for libunwinder head (out of namespace) 47 #if defined(is_mingw) && is_mingw 48 #ifndef MMAP_FAILED 49 #define MMAP_FAILED reinterpret_cast<void *>(-1) 50 #endif 51 void *mmap(void *addr, size_t length, int prot, int flags, int fd, size_t offset); 52 int munmap(void *addr, size_t); 53 #endif 54 #endif 55