• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 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 #ifndef MEMORYREADER_H
16 #define MEMORYREADER_H
17 
18 #include "smart_fd.h"
19 namespace OHOS {
20 namespace HiviewDFX {
21 class MemoryReader {
22 public:
23     virtual ~MemoryReader() = default;
24     virtual bool ReadMemory(const uint64_t src, void* dst, size_t dataSize) = 0;
25 };
26 
27 class ThreadMemoryReader : public MemoryReader {
28 public:
29     ThreadMemoryReader(uintptr_t stackBegin, uintptr_t stackEnd);
30     ~ThreadMemoryReader() override = default;
31     bool ReadMemory(const uint64_t src, void* dst, size_t dataSize) override;
32 private:
33     uintptr_t stackBegin_{0};
34     uintptr_t stackEnd_{0};
35 };
36 
37 class ProcessMemoryReader : public MemoryReader {
38 public:
39     ProcessMemoryReader();
40     ~ProcessMemoryReader() override = default;
41     bool ReadMemory(const uint64_t src, void* dst, size_t dataSize) override ;
42 private:
43     SmartFd writeFd_;
44     SmartFd readFd_;
45 };
46 }
47 }
48 #endif