From 61fec56c6eda155a0c50cc986f334983587c0a24 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Tue, 21 Jan 2020 22:24:15 +0000 Subject: [PATCH] thermosphere: minor changes --- thermosphere/src/pattern_utils.c | 86 +++++++++++++++++++++++++ thermosphere/src/pattern_utils.h | 1 + thermosphere/src/software_breakpoints.c | 1 + 3 files changed, 88 insertions(+) diff --git a/thermosphere/src/pattern_utils.c b/thermosphere/src/pattern_utils.c index c5931dced..a86d34815 100644 --- a/thermosphere/src/pattern_utils.c +++ b/thermosphere/src/pattern_utils.c @@ -164,6 +164,92 @@ unsigned int xstrtoui(const char *nptr, char **endptr, int base, bool allowPrefi return (acc); } +// Copied from newlib, without the reent stuff + some other stuff +unsigned long int xstrtoul(const char *nptr, char **endptr, int base, bool allowPrefix, bool *ok) +{ + register const unsigned char *s = (const unsigned char *)nptr; + register unsigned long acc; + register int c; + register unsigned long cutoff; + register int neg = 0, any, cutlim; + + if(ok != NULL) + *ok = true; + /* + * See strtol for comments as to the logic used. + */ + do { + c = *s++; + } while ((c >= 9 && c <= 13) || c == ' '); + if (c == '-') { + if(!allowPrefix) { + if(ok != NULL) + *ok = false; + return 0; + } + neg = 1; + c = *s++; + } else if (c == '+'){ + if(!allowPrefix) { + if(ok != NULL) + *ok = false; + return 0; + } + + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + + if(!allowPrefix) { + if(ok != NULL) + *ok = false; + return 0; + } + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) { + if(!allowPrefix) { + if(ok != NULL) + *ok = false; + return 0; + } + + base = c == '0' ? 8 : 10; + } + cutoff = (unsigned long)(-1) / (unsigned long)base; + cutlim = (unsigned long)(-1) % (unsigned long)base; + for (acc = 0, any = 0;; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + c -= c >= 'A' && c <= 'Z' ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = (unsigned long)-1; + if(ok != NULL) + *ok = false; +// rptr->_errno = ERANGE; + } else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = (char *) (any ? (char *)s - 1 : nptr); + return (acc); +} + // Copied from newlib, without the reent stuff + some other stuff unsigned long long int xstrtoull(const char *nptr, char **endptr, int base, bool allowPrefix, bool *ok) { diff --git a/thermosphere/src/pattern_utils.h b/thermosphere/src/pattern_utils.h index c4c439801..8739a3e68 100644 --- a/thermosphere/src/pattern_utils.h +++ b/thermosphere/src/pattern_utils.h @@ -22,4 +22,5 @@ // Not sure if we need this function because we can only map one guest page at a time... u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize); unsigned int xstrtoui(const char *nptr, char **endptr, int base, bool allowPrefix, bool *ok); +unsigned long int xstrtoul(const char *nptr, char **endptr, int base, bool allowPrefix, bool *ok); unsigned long long int xstrtoull(const char *nptr, char **endptr, int base, bool allowPrefix, bool *ok); diff --git a/thermosphere/src/software_breakpoints.c b/thermosphere/src/software_breakpoints.c index 514edef66..87e815e70 100644 --- a/thermosphere/src/software_breakpoints.c +++ b/thermosphere/src/software_breakpoints.c @@ -86,6 +86,7 @@ static bool applySoftwareBreakpoint(size_t id) return true; } + // This is okay for non-stop mode if sync isn't perfect here atomic_store(&g_softwareBreakpointManager.breakpoints[id].triedToApplyOrRevert, false); executeFunctionOnAllCores(applySoftwareBreakpointHandler, &id, true); atomic_signal_fence(memory_order_seq_cst);