1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _LIBUNWINDSTACK_REGS_ARM64_H
18 #define _LIBUNWINDSTACK_REGS_ARM64_H
19 
20 #include <stdint.h>
21 
22 #include <functional>
23 
24 #include <unwindstack/Elf.h>
25 #include <unwindstack/MachineArm64.h>
26 #include <unwindstack/Regs.h>
27 
28 namespace unwindstack {
29 
30 // Forward declarations.
31 class Memory;
32 
33 class RegsArm64 : public RegsImpl<uint64_t> {
34  public:
35   RegsArm64();
36   virtual ~RegsArm64() = default;
37 
38   ArchEnum Arch() override final;
39 
40   bool SetPcFromReturnAddress(Memory* process_memory) override;
41 
42   bool StepIfSignalHandler(uint64_t elf_offset, Elf* elf, Memory* process_memory) override;
43 
44   void IterateRegisters(std::function<void(const char*, uint64_t)>) override final;
45 
46   uint64_t pc() override;
47   uint64_t sp() override;
48 
49   void set_pc(uint64_t pc) override;
50   void set_sp(uint64_t sp) override;
51 
52   void fallback_pc() override;
53 
54   void ResetPseudoRegisters() override;
55 
56   bool SetPseudoRegister(uint16_t id, uint64_t value) override;
57 
58   bool GetPseudoRegister(uint16_t id, uint64_t* value) override;
59 
60   bool IsRASigned();
61 
62   void SetPACMask(uint64_t mask);
63 
64   Regs* Clone() override final;
65 
66   static Regs* Read(void* data);
67 
68   static Regs* CreateFromUcontext(void* ucontext);
69 
70  protected:
71   uint64_t pseudo_regs_[Arm64Reg::ARM64_PREG_LAST - Arm64Reg::ARM64_PREG_FIRST];
72   uint64_t pac_mask_;
73 };
74 
75 }  // namespace unwindstack
76 
77 #endif  // _LIBUNWINDSTACK_REGS_ARM64_H
78