mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[RemoteAddress] Handle comparison of addresses in different spaces
Sometimes it makes sense to compares addresses from different address spaces. rdar://148361743
This commit is contained in:
@@ -55,18 +55,44 @@ public:
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
bool inRange(const RemoteAddress &begin, const RemoteAddress &end) const {
|
||||
assert(begin.AddressSpace != end.AddressSpace &&
|
||||
"Unexpected address spaces");
|
||||
if (AddressSpace != begin.AddressSpace)
|
||||
return false;
|
||||
return begin <= *this && *this < end;
|
||||
}
|
||||
|
||||
bool operator<(const RemoteAddress rhs) const {
|
||||
assert(AddressSpace == rhs.AddressSpace &&
|
||||
"Comparing remote addresses of different address spaces");
|
||||
return Data < rhs.Data;
|
||||
}
|
||||
|
||||
/// Less than operator to be used for ordering purposes. The default less than
|
||||
/// operator asserts if the address spaces are different, this one takes it
|
||||
/// into account to determine the order of the addresses.
|
||||
bool orderedLessThan(const RemoteAddress rhs) const {
|
||||
if (AddressSpace == rhs.AddressSpace)
|
||||
return Data < rhs.Data;
|
||||
return AddressSpace < rhs.AddressSpace;
|
||||
}
|
||||
|
||||
bool operator<=(const RemoteAddress rhs) const {
|
||||
assert(AddressSpace == rhs.AddressSpace &&
|
||||
"Comparing remote addresses of different address spaces");
|
||||
return Data <= rhs.Data;
|
||||
}
|
||||
|
||||
/// Less than or equal operator to be used for ordering purposes. The default
|
||||
/// less than or equal operator asserts if the address spaces are different,
|
||||
/// this one takes it into account to determine the order of the addresses.
|
||||
bool orderedLessThanOrEqual(const RemoteAddress rhs) const {
|
||||
if (AddressSpace == rhs.AddressSpace)
|
||||
return Data <= rhs.Data;
|
||||
return AddressSpace <= rhs.AddressSpace;
|
||||
}
|
||||
|
||||
bool operator>(const RemoteAddress &rhs) const {
|
||||
assert(AddressSpace == rhs.AddressSpace &&
|
||||
"Comparing remote addresses of different address spaces");
|
||||
|
||||
@@ -907,7 +907,7 @@ public:
|
||||
for (auto Range : ranges) {
|
||||
auto Start = std::get<0>(Range);
|
||||
auto End = std::get<1>(Range);
|
||||
if (Start <= Address && Address < End)
|
||||
if (Address.inRange(Start, End))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,10 @@ public:
|
||||
|
||||
bool containsRemoteAddress(remote::RemoteAddress remoteAddr,
|
||||
uint64_t size) const {
|
||||
if (Start.getRemoteAddress().getAddressSpace() !=
|
||||
remoteAddr.getAddressSpace())
|
||||
return false;
|
||||
|
||||
return Start.getRemoteAddress() <= remoteAddr &&
|
||||
remoteAddr + size <= Start.getRemoteAddress() + Size;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ TypeRefBuilder::ReflectionTypeDescriptorFinder::
|
||||
.TypeReference.startAddress()
|
||||
.getRemoteAddress();
|
||||
|
||||
return typeReferenceAStart < typeReferenceBStart;
|
||||
return typeReferenceAStart.orderedLessThan(typeReferenceBStart);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,9 +75,11 @@ TypeRefBuilder::ReflectionTypeDescriptorFinder::
|
||||
ReflectionInfoIndexesSortedByTypeReferenceRange.begin(),
|
||||
ReflectionInfoIndexesSortedByTypeReferenceRange.end(), remoteAddr,
|
||||
[&](uint32_t ReflectionInfoIndex, remote::RemoteAddress remoteAddr) {
|
||||
return ReflectionInfos[ReflectionInfoIndex]
|
||||
.TypeReference.endAddress()
|
||||
.getRemoteAddress() <= remoteAddr;
|
||||
auto reflectionInfoAddress = ReflectionInfos[ReflectionInfoIndex]
|
||||
.TypeReference.endAddress()
|
||||
.getRemoteAddress();
|
||||
|
||||
return reflectionInfoAddress.orderedLessThanOrEqual(remoteAddr);
|
||||
});
|
||||
|
||||
if (possiblyMatchingReflectionInfoIndex ==
|
||||
|
||||
Reference in New Issue
Block a user