Louis Dionne | cb96c63 | 2022-04-03 08:55:57 -0400 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 10 | // The other libunwind tests don't test internal interfaces, so the include path |
| 11 | // is a little wonky. |
| 12 | #include "../src/config.h" |
| 13 | |
| 14 | // Only run this test under supported configurations. |
Sterling Augustine | 157d5f8 | 2020-03-12 18:12:52 -0700 | [diff] [blame] | 15 | |
Ryan Prichard | 7629c30 | 2020-08-27 23:46:49 -0700 | [diff] [blame] | 16 | #if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \ |
Ryan Prichard | 7629c30 | 2020-08-27 23:46:49 -0700 | [diff] [blame] | 17 | defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 18 | |
| 19 | #include <link.h> |
| 20 | #include <stdio.h> |
| 21 | |
| 22 | // This file defines several of the data structures needed here, |
| 23 | // and includes FrameHeaderCache.hpp as well. |
| 24 | #include "../src/AddressSpace.hpp" |
| 25 | |
| 26 | #define kBaseAddr 0xFFF000 |
Ryan Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame] | 27 | #define kTextSegmentLength 0xFF |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 28 | |
| 29 | using namespace libunwind; |
| 30 | |
Louis Dionne | cbfe017 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 31 | int main(int, char**) { |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 32 | FrameHeaderCache FHC; |
| 33 | struct dl_phdr_info PInfo; |
| 34 | memset(&PInfo, 0, sizeof(PInfo)); |
| 35 | // The cache itself should only care about these two fields--they |
| 36 | // tell the cache to invalidate or not; everything else is handled |
| 37 | // by AddressSpace.hpp. |
| 38 | PInfo.dlpi_adds = 6; |
| 39 | PInfo.dlpi_subs = 7; |
| 40 | |
| 41 | UnwindInfoSections UIS; |
| 42 | UIS.dso_base = kBaseAddr; |
Ryan Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame] | 43 | UIS.text_segment_length = kTextSegmentLength; |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 44 | dl_iterate_cb_data CBData; |
| 45 | // Unused by the cache. |
| 46 | CBData.addressSpace = nullptr; |
| 47 | CBData.sects = &UIS; |
| 48 | CBData.targetAddr = kBaseAddr + 1; |
| 49 | |
| 50 | // Nothing present, shouldn't find. |
| 51 | if (FHC.find(&PInfo, 0, &CBData)) |
| 52 | abort(); |
| 53 | FHC.add(&UIS); |
| 54 | // Just added. Should find. |
| 55 | if (!FHC.find(&PInfo, 0, &CBData)) |
| 56 | abort(); |
| 57 | // Cache is invalid. Shouldn't find. |
| 58 | PInfo.dlpi_adds++; |
| 59 | if (FHC.find(&PInfo, 0, &CBData)) |
| 60 | abort(); |
| 61 | |
| 62 | FHC.add(&UIS); |
| 63 | CBData.targetAddr = kBaseAddr - 1; |
| 64 | // Shouldn't find something outside of the addresses. |
| 65 | if (FHC.find(&PInfo, 0, &CBData)) |
| 66 | abort(); |
| 67 | // Add enough things to the cache that the entry is evicted. |
| 68 | for (int i = 0; i < 9; i++) { |
Ryan Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame] | 69 | UIS.dso_base = kBaseAddr + (kTextSegmentLength * i); |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 70 | FHC.add(&UIS); |
| 71 | } |
| 72 | CBData.targetAddr = kBaseAddr; |
| 73 | // Should have been evicted. |
| 74 | if (FHC.find(&PInfo, 0, &CBData)) |
| 75 | abort(); |
| 76 | return 0; |
| 77 | } |
Ryan Prichard | 7629c30 | 2020-08-27 23:46:49 -0700 | [diff] [blame] | 78 | |
Sterling Augustine | 157d5f8 | 2020-03-12 18:12:52 -0700 | [diff] [blame] | 79 | #else |
Louis Dionne | cbfe017 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 80 | int main(int, char**) { return 0;} |
Sterling Augustine | 157d5f8 | 2020-03-12 18:12:52 -0700 | [diff] [blame] | 81 | #endif |