1 //===-- ABIWindows_x86_64.h ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_ABI_X86_ABIWINDOWS_X86_64_H
10 #define LLDB_SOURCE_PLUGINS_ABI_X86_ABIWINDOWS_X86_64_H
11 
12 #include "Plugins/ABI/X86/ABIX86_64.h"
13 
14 class ABIWindows_x86_64 : public ABIX86_64 {
15 public:
16   ~ABIWindows_x86_64() override = default;
17 
18   size_t GetRedZoneSize() const override;
19 
20   bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
21                           lldb::addr_t functionAddress,
22                           lldb::addr_t returnAddress,
23                           llvm::ArrayRef<lldb::addr_t> args) const override;
24 
25   bool GetArgumentValues(lldb_private::Thread &thread,
26                          lldb_private::ValueList &values) const override;
27 
28   lldb_private::Status
29   SetReturnValueObject(lldb::StackFrameSP &frame_sp,
30                        lldb::ValueObjectSP &new_value) override;
31 
32   lldb::ValueObjectSP
33   GetReturnValueObjectImpl(lldb_private::Thread &thread,
34                            lldb_private::CompilerType &type) const override;
35 
36   bool
37   CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
38 
39   bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;
40 
41   bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;
42 
43   // In Windows_x86_64 ABI requires that the stack will be maintained 16-byte
44   // aligned.
45   // When ntdll invokes callbacks such as KiUserExceptionDispatcher or
46   // KiUserCallbackDispatcher, those functions won't have a properly 16-byte
47   // aligned stack - but tolerate unwinding through them by relaxing the
48   // requirement to 8 bytes.
CallFrameAddressIsValid(lldb::addr_t cfa)49   bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
50     if (cfa & (8ull - 1ull))
51       return false; // Not 8 byte aligned
52     if (cfa == 0)
53       return false; // Zero is not a valid stack address
54     return true;
55   }
56 
CodeAddressIsValid(lldb::addr_t pc)57   bool CodeAddressIsValid(lldb::addr_t pc) override {
58     // We have a 64 bit address space, so anything is valid as opcodes
59     // aren't fixed width...
60     return true;
61   }
62 
63   bool GetPointerReturnRegister(const char *&name) override;
64 
65   //------------------------------------------------------------------
66   // Static Functions
67   //------------------------------------------------------------------
68 
69   static void Initialize();
70 
71   static void Terminate();
72 
73   static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch);
74 
GetPluginNameStatic()75   static llvm::StringRef GetPluginNameStatic() { return "windows-x86_64"; }
76 
77   //------------------------------------------------------------------
78   // PluginInterface protocol
79   //------------------------------------------------------------------
80 
GetPluginName()81   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
82 
83 protected:
84   void CreateRegisterMapIfNeeded();
85 
86   lldb::ValueObjectSP
87   GetReturnValueObjectSimple(lldb_private::Thread &thread,
88                              lldb_private::CompilerType &ast_type) const;
89 
90   bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);
91   uint32_t GetGenericNum(llvm::StringRef reg) override;
92 
93 private:
94   using ABIX86_64::ABIX86_64; // Call CreateInstance instead.
95 };
96 
97 #endif // LLDB_SOURCE_PLUGINS_ABI_X86_ABIWINDOWS_X86_64_H
98