• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_MEMORY_H
17 #define DFX_MEMORY_H
18 
19 #include <atomic>
20 #include <cstdint>
21 #include <memory>
22 #include <string>
23 #include <cinttypes>
24 #include <unistd.h>
25 
26 namespace OHOS {
27 namespace HiviewDFX {
28 #define ALIGN_BYTES(align) ((align) - 1)
29 #define ALIGN_MASK(align) (~(static_cast<uint64_t>((align) - 1)))
30 #define ALIGN_VALUE(val, align) (((val) + ALIGN_BYTES(align)) & ALIGN_MASK(align))
31 
32 class DfxMemory {
33 public:
34     DfxMemory() = default;
35     virtual ~DfxMemory() = default;
36 
37     static size_t MemoryCopy(void *dst, uint8_t *data, size_t copySize, size_t offset, size_t dataSize);
38 
IsLocal()39     virtual bool IsLocal() const { return false; }
40 
41     bool ReadFully(uint64_t addr, void* dst, size_t size);
42     virtual size_t Read(uint64_t addr, void* dst, size_t size) = 0;
43     virtual bool ReadString(uint64_t addr, std::string* dst, size_t maxRead);
44     inline bool Read32(uint64_t addr, uint32_t* dst);
45     inline bool Read64(uint64_t addr, uint64_t* dst);
46 
Clear()47     virtual void Clear() {}
48 };
49 } // namespace HiviewDFX
50 } // namespace OHOS
51 #endif
52