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