• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
29 namespace OHOS {
30 namespace HiviewDFX {
31 #ifndef is_host
32 AT_SYMBOL_HIDDEN bool TrimAndDupStr(const std::string &source, std::string &str);
33 AT_SYMBOL_HIDDEN uint64_t GetTimeMilliSeconds(void);
34 AT_SYMBOL_HIDDEN uint64_t GetAbsTimeMilliSeconds(void);
35 AT_SYMBOL_DEFAULT std::string GetCurrentTimeStr(uint64_t current = 0);
36 AT_SYMBOL_HIDDEN bool ReadDirFiles(const std::string& path, std::vector<std::string>& files);
37 AT_SYMBOL_HIDDEN void ParseSiValue(siginfo_t& si, uint64_t& endTime, int& tid);
38 AT_SYMBOL_HIDDEN bool IsBetaVersion();
39 AT_SYMBOL_HIDDEN bool IsDeveloperMode();
40 AT_SYMBOL_HIDDEN bool IsOversea();
41 #endif
42 AT_SYMBOL_HIDDEN off_t GetFileSize(int fd);
43 AT_SYMBOL_HIDDEN bool ReadFdToString(int fd, std::string& content);
44 AT_SYMBOL_HIDDEN uintptr_t StripPac(uintptr_t inAddr, uintptr_t pacMask);
45 #if is_ohos && !is_mingw
46 AT_SYMBOL_HIDDEN size_t ReadProcMemByPid(const pid_t pid, const uint64_t addr, void* data, size_t size);
47 #endif
48 } // nameapace HiviewDFX
49 } // nameapace OHOS
50 
51 // this will also used for libunwinder head (out of namespace)
52 #if defined(is_mingw) && is_mingw
53 #ifndef MMAP_FAILED
54 #define MMAP_FAILED reinterpret_cast<void *>(-1)
55 #endif
56 void *mmap(void *addr, size_t length, int prot, int flags, int fd, size_t offset);
57 int munmap(void *addr, size_t);
58 #endif
59 #endif
60