1 // The other libunwind tests don't test internal interfaces, so the include path
2 // is a little wonky.
3 #include "../src/config.h"
4 
5 // Only run this test under supported configurations.
6 // The frame header cache should work fine for other architectures,
7 // but the #ifdefs end up being even more complicated than this.
8 
9 #ifdef __x86_64__
10 
11 // This #if chain is ugly, but see the comments in AddressSpace.hpp for
12 // the reasoning.
13 
14 #ifdef __APPLE__
15 int main() { return 0; }
16 #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)
17 int main() { return 0; }
18 #elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)
19 int main() { return 0; }
20 #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32)
21 int main() { return 0; }
22 #elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
23 int main() { return 0; }
24 #elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__)
25 int main() { return 0; }
26 #elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
27 
28 #include <link.h>
29 #include <stdio.h>
30 
31 // This file defines several of the data structures needed here,
32 // and includes FrameHeaderCache.hpp as well.
33 #include "../src/AddressSpace.hpp"
34 
35 #define kBaseAddr 0xFFF000
36 #define kDwarfSectionLength 0xFF
37 
38 using namespace libunwind;
39 
40 int main() {
41   FrameHeaderCache FHC;
42   struct dl_phdr_info PInfo;
43   memset(&PInfo, 0, sizeof(PInfo));
44   // The cache itself should only care about these two fields--they
45   // tell the cache to invalidate or not; everything else is handled
46   // by AddressSpace.hpp.
47   PInfo.dlpi_adds = 6;
48   PInfo.dlpi_subs = 7;
49 
50   UnwindInfoSections UIS;
51   UIS.dso_base = kBaseAddr;
52   UIS.dwarf_section_length = kDwarfSectionLength;
53   dl_iterate_cb_data CBData;
54   // Unused by the cache.
55   CBData.addressSpace = nullptr;
56   CBData.sects = &UIS;
57   CBData.targetAddr = kBaseAddr + 1;
58 
59   // Nothing present, shouldn't find.
60   if (FHC.find(&PInfo, 0, &CBData))
61     abort();
62   FHC.add(&UIS);
63   // Just added. Should find.
64   if (!FHC.find(&PInfo, 0, &CBData))
65     abort();
66   // Cache is invalid. Shouldn't find.
67   PInfo.dlpi_adds++;
68   if (FHC.find(&PInfo, 0, &CBData))
69     abort();
70 
71   FHC.add(&UIS);
72   CBData.targetAddr = kBaseAddr - 1;
73   // Shouldn't find something outside of the addresses.
74   if (FHC.find(&PInfo, 0, &CBData))
75     abort();
76   // Add enough things to the cache that the entry is evicted.
77   for (int i = 0; i < 9; i++) {
78     UIS.dso_base = kBaseAddr + (kDwarfSectionLength * i);
79     FHC.add(&UIS);
80   }
81   CBData.targetAddr = kBaseAddr;
82   // Should have been evicted.
83   if (FHC.find(&PInfo, 0, &CBData))
84     abort();
85   return 0;
86 }
87 #else
88 int main() { return 0; }
89 #endif
90 #else
91 int main() { return 0;}
92 #endif
93