Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Module.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4
6
7 namespace Private_ {
8 // the main executable's read-only image, as address ranges [start, end); fKnown false where Stroika cannot tell
9 struct ReadOnlyImage_ {
10 static constexpr size_t kMaxRanges = 16;
11 bool fKnown{};
12 size_t fCount{};
13 array<pair<uintptr_t, uintptr_t>, kMaxRanges> fRanges{};
14 };
15 const ReadOnlyImage_& GetReadOnlyImage_ (); // examined once, at first use
16 }
17
18 /*
19 ********************************************************************************
20 ****************** Execution::IsAddressReadOnlyAppLifetime *********************
21 ********************************************************************************
22 */
23 inline optional<bool> IsAddressReadOnlyAppLifetime (span<const byte> s)
24 {
25 // inline, with the image kept by reference: String asks this of every string view it is constructed from
26 static const Private_::ReadOnlyImage_& sImage_ = Private_::GetReadOnlyImage_ ();
27 if (not sImage_.fKnown) {
28 return nullopt;
29 }
30 if (s.empty ()) {
31 return false;
32 }
33 uintptr_t start = reinterpret_cast<uintptr_t> (s.data ());
34 for (size_t i = 0; i < sImage_.fCount; ++i) {
35 const auto& [b, e] = sImage_.fRanges[i];
36 if (b <= start and start < e and s.size () <= e - start) {
37 return true;
38 }
39 }
40 return false;
41 }
42
43}
optional< bool > IsAddressReadOnlyAppLifetime(span< const byte > s)
Is all of s in memory that is read-only for as long as the program runs - so a pointer into it may be...
Definition Module.inl:23