1212#ifndef __UNWINDCURSOR_HPP__
1313#define __UNWINDCURSOR_HPP__
1414
15- #include < algorithm>
1615#include < stdint.h>
1716#include < stdio.h>
1817#include < stdlib.h>
@@ -106,7 +105,6 @@ class _LIBUNWIND_HIDDEN DwarfFDECache {
106105 static void dyldUnloadHook (const struct mach_header *mh, intptr_t slide);
107106 static bool _registeredForDyldUnloads;
108107#endif
109- // Can't use std::vector<> here because this code is below libc++.
110108 static entry *_buffer;
111109 static entry *_bufferUsed;
112110 static entry *_bufferEnd;
@@ -1229,7 +1227,6 @@ template<typename A>
12291227struct EHABISectionIterator {
12301228 typedef EHABISectionIterator _Self;
12311229
1232- typedef std::random_access_iterator_tag iterator_category;
12331230 typedef typename A::pint_t value_type;
12341231 typedef typename A::pint_t * pointer;
12351232 typedef typename A::pint_t & reference;
@@ -1283,6 +1280,29 @@ struct EHABISectionIterator {
12831280 const UnwindInfoSections* _sects;
12841281};
12851282
1283+ namespace {
1284+
1285+ template <typename A>
1286+ EHABISectionIterator<A> EHABISectionUpperBound (
1287+ EHABISectionIterator<A> first,
1288+ EHABISectionIterator<A> last,
1289+ typename A::pint_t value) {
1290+ size_t len = last - first;
1291+ while (len > 0 ) {
1292+ size_t l2 = len / 2 ;
1293+ EHABISectionIterator<A> m = first + l2;
1294+ if (value < *m) {
1295+ len = l2;
1296+ } else {
1297+ first = ++m;
1298+ len -= l2 + 1 ;
1299+ }
1300+ }
1301+ return first;
1302+ }
1303+
1304+ }
1305+
12861306template <typename A, typename R>
12871307bool UnwindCursor<A, R>::getInfoFromEHABISection(
12881308 pint_t pc,
@@ -1294,7 +1314,7 @@ bool UnwindCursor<A, R>::getInfoFromEHABISection(
12941314 if (begin == end)
12951315 return false ;
12961316
1297- EHABISectionIterator<A> itNextPC = std::upper_bound (begin, end, pc);
1317+ EHABISectionIterator<A> itNextPC = EHABISectionUpperBound (begin, end, pc);
12981318 if (itNextPC == begin)
12991319 return false ;
13001320 EHABISectionIterator<A> itThisPC = itNextPC - 1 ;
@@ -1304,8 +1324,7 @@ bool UnwindCursor<A, R>::getInfoFromEHABISection(
13041324 // in the table, we don't really know the function extent and have to choose a
13051325 // value for nextPC. Choosing max() will allow the range check during trace to
13061326 // succeed.
1307- pint_t nextPC = (itNextPC == end) ? std::numeric_limits<pint_t >::max ()
1308- : itNextPC.functionAddress ();
1327+ pint_t nextPC = (itNextPC == end) ? UINTPTR_MAX : itNextPC.functionAddress ();
13091328 pint_t indexDataAddr = itThisPC.dataAddress ();
13101329
13111330 if (indexDataAddr == 0 )
0 commit comments