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__
main()15 int main() { return 0; }
16 #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)
main()17 int main() { return 0; }
18 #elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)
main()19 int main() { return 0; }
20 #elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32)
main()21 int main() { return 0; }
22 #elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
main()23 int main() { return 0; }
24 #elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__)
main()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 using pc_t = LocalAddressSpace::LocalProgramCounter;
41 
main()42 int main() {
43   FrameHeaderCache FHC;
44   struct dl_phdr_info PInfo;
45   memset(&PInfo, 0, sizeof(PInfo));
46   // The cache itself should only care about these two fields--they
47   // tell the cache to invalidate or not; everything else is handled
48   // by AddressSpace.hpp.
49   PInfo.dlpi_adds = 6;
50   PInfo.dlpi_subs = 7;
51 
52   UnwindInfoSections UIS;
53   UIS.dso_base = kBaseAddr;
54   UIS.dwarf_section_length = kDwarfSectionLength;
55   dl_iterate_cb_data CBData;
56   // Unused by the cache.
57   CBData.addressSpace = nullptr;
58   CBData.sects = &UIS;
59   CBData.targetAddr = pc_t((uintptr_t)kBaseAddr + 1);
60 
61   // Nothing present, shouldn't find.
62   if (FHC.find(&PInfo, 0, &CBData))
63     abort();
64   FHC.add(&UIS);
65   // Just added. Should find.
66   if (!FHC.find(&PInfo, 0, &CBData))
67     abort();
68   // Cache is invalid. Shouldn't find.
69   PInfo.dlpi_adds++;
70   if (FHC.find(&PInfo, 0, &CBData))
71     abort();
72 
73   FHC.add(&UIS);
74   CBData.targetAddr = pc_t(kBaseAddr - 1);
75   // Shouldn't find something outside of the addresses.
76   if (FHC.find(&PInfo, 0, &CBData))
77     abort();
78   // Add enough things to the cache that the entry is evicted.
79   for (int i = 0; i < 9; i++) {
80     UIS.dso_base = kBaseAddr + (kDwarfSectionLength * i);
81     FHC.add(&UIS);
82   }
83   CBData.targetAddr = pc_t(kBaseAddr);
84   // Should have been evicted.
85   if (FHC.find(&PInfo, 0, &CBData))
86     abort();
87   return 0;
88 }
89 #else
main()90 int main() { return 0; }
91 #endif
92 #else
main()93 int main() { return 0;}
94 #endif
95