From 3f66b7918373adbdbe7bc3a63318b36229b9b480 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Sun, 27 Aug 2017 19:36:49 -0700 Subject: [PATCH] #406: convert remaining relevant memchr calls to VMX_MEMCHR/VMX_HASCHR --- dom/media/ogg/OggCodecState.cpp | 5 ++++- gfx/ots/src/post.cc | 5 ++++- ipc/chromium/src/third_party/libevent/buffer.c | 16 ++++++++++++---- media/libogg/src/ogg_framing.c | 5 ++++- modules/zlib/src/gzread.c | 5 ++++- netwerk/base/nsURLHelper.cpp | 5 ++++- netwerk/base/nsURLParsers.cpp | 5 ++++- netwerk/protocol/http/nsHttpChunkedDecoder.cpp | 5 ++++- netwerk/protocol/http/nsHttpTransaction.cpp | 5 ++++- .../streamconv/converters/nsMultiMixedConv.cpp | 5 ++++- security/certverifier/NSSCertDBTrustDomain.cpp | 5 ++++- security/nss/lib/zlib/gzread.c | 5 ++++- xpcom/io/nsEscape.cpp | 5 ++++- 13 files changed, 60 insertions(+), 16 deletions(-) diff --git a/dom/media/ogg/OggCodecState.cpp b/dom/media/ogg/OggCodecState.cpp index 8184053ec7..22e605f85d 100644 --- a/dom/media/ogg/OggCodecState.cpp +++ b/dom/media/ogg/OggCodecState.cpp @@ -18,6 +18,9 @@ #include "VideoUtils.h" #include +#include "mozilla-config.h" +#include "plvmx.h" + // On Android JellyBean, the hardware.h header redefines version_major and // version_minor, which breaks our build. See: // https://bugzilla.mozilla.org/show_bug.cgi?id=912702#c6 @@ -115,7 +118,7 @@ bool OggCodecState::AddVorbisComment(MetadataTags* aTags, const char* aComment, uint32_t aLength) { - const char* div = (const char*)memchr(aComment, '=', aLength); + const char* div = (const char*)VMX_MEMCHR(aComment, '=', aLength); if (!div) { LOG(LogLevel::Debug, ("Skipping comment: no separator")); return false; diff --git a/gfx/ots/src/post.cc b/gfx/ots/src/post.cc index e7ed92b4a6..8205c049e7 100644 --- a/gfx/ots/src/post.cc +++ b/gfx/ots/src/post.cc @@ -6,6 +6,9 @@ #include "maxp.h" +#include "mozilla-config.h" +#include "plvmx.h" + // post - PostScript // http://www.microsoft.com/typography/otspec/post.htm @@ -95,7 +98,7 @@ bool ots_post_parse(Font *font, const uint8_t *data, size_t length) { if (strings + 1 + string_length > strings_end) { return OTS_FAILURE_MSG("Bad string length %d", string_length); } - if (std::memchr(strings + 1, '\0', string_length)) { + if (VMX_HASCHR(strings + 1, '\0', string_length)) { return OTS_FAILURE_MSG("Bad string of length %d", string_length); } post->names.push_back( diff --git a/ipc/chromium/src/third_party/libevent/buffer.c b/ipc/chromium/src/third_party/libevent/buffer.c index 146c6bf327..a09f58ef8f 100644 --- a/ipc/chromium/src/third_party/libevent/buffer.c +++ b/ipc/chromium/src/third_party/libevent/buffer.c @@ -91,6 +91,9 @@ #include "evbuffer-internal.h" #include "bufferevent-internal.h" +#include "mozilla-config.h" +#include "plvmx.h" + /* some systems do not have MAP_FAILED */ #ifndef MAP_FAILED #define MAP_FAILED ((void *)-1) @@ -1299,7 +1302,7 @@ evbuffer_strchr(struct evbuffer_ptr *it, const char chr) size_t i = it->_internal.pos_in_chain; while (chain != NULL) { char *buffer = (char *)chain->buffer + chain->misalign; - char *cp = memchr(buffer+i, chr, chain->off-i); + char *cp = VMX_MEMCHR(buffer+i, chr, chain->off-i); if (cp) { it->_internal.chain = chain; it->_internal.pos_in_chain = cp - buffer; @@ -1317,7 +1320,12 @@ evbuffer_strchr(struct evbuffer_ptr *it, const char chr) static inline char * find_eol_char(char *s, size_t len) { +#if TENFOURFOX_VMX +#warning using accelerated VMX libevent +#define CHUNK_SZ 1024 +#else #define CHUNK_SZ 128 +#endif /* Lots of benchmarking found this approach to be faster in practice * than doing two memchrs over the whole buffer, doin a memchr on each * char of the buffer, or trying to emulate memchr by hand. */ @@ -1325,8 +1333,8 @@ find_eol_char(char *s, size_t len) s_end = s+len; while (s < s_end) { size_t chunk = (s + CHUNK_SZ < s_end) ? CHUNK_SZ : (s_end - s); - cr = memchr(s, '\r', chunk); - lf = memchr(s, '\n', chunk); + cr = VMX_MEMCHR(s, '\r', chunk); + lf = VMX_MEMCHR(s, '\n', chunk); if (cr) { if (lf && lf < cr) return lf; @@ -2528,7 +2536,7 @@ evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, con const unsigned char *start_at = chain->buffer + chain->misalign + pos._internal.pos_in_chain; - p = memchr(start_at, first, + p = VMX_MEMCHR(start_at, first, chain->off - pos._internal.pos_in_chain); if (p) { pos.pos += p - start_at; diff --git a/media/libogg/src/ogg_framing.c b/media/libogg/src/ogg_framing.c index 4452cbd580..9a00915c26 100644 --- a/media/libogg/src/ogg_framing.c +++ b/media/libogg/src/ogg_framing.c @@ -24,6 +24,9 @@ #include #include +#include "mozilla-config.h" +#include "plvmx.h" + /* A complete description of Ogg framing exists in docs/framing.html */ int ogg_page_version(const ogg_page *og){ @@ -735,7 +738,7 @@ long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){ oy->bodybytes=0; /* search for possible capture */ - next=memchr(page+1,'O',bytes-1); + next=VMX_MEMCHR(page+1,'O',bytes-1); if(!next) next=oy->data+oy->fill; diff --git a/modules/zlib/src/gzread.c b/modules/zlib/src/gzread.c index bf4538eb27..74aa8b931a 100644 --- a/modules/zlib/src/gzread.c +++ b/modules/zlib/src/gzread.c @@ -5,6 +5,9 @@ #include "gzguts.h" +#include "mozilla-config.h" +#include "plvmx.h" + /* Local functions */ local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); local int gz_avail OF((gz_statep)); @@ -523,7 +526,7 @@ char * ZEXPORT gzgets(file, buf, len) /* look for end-of-line in current output buffer */ n = state->x.have > left ? left : state->x.have; - eol = (unsigned char *)memchr(state->x.next, '\n', n); + eol = (unsigned char *)VMX_MEMCHR(state->x.next, '\n', n); if (eol != NULL) n = (unsigned)(eol - state->x.next) + 1; diff --git a/netwerk/base/nsURLHelper.cpp b/netwerk/base/nsURLHelper.cpp index 69598dbe7d..9b63933168 100644 --- a/netwerk/base/nsURLHelper.cpp +++ b/netwerk/base/nsURLHelper.cpp @@ -15,6 +15,9 @@ #include "mozilla/Preferences.h" #include "prnetdb.h" +#include "mozilla-config.h" +#include "plvmx.h" + using namespace mozilla; //---------------------------------------------------------------------------- @@ -902,7 +905,7 @@ net_ParseMediaType(const nsACString &aMediaTypeStr, // include a comma, so this check makes us a bit more tolerant. if (type != typeEnd && - memchr(type, '/', typeEnd - type) != nullptr && + VMX_HASCHR(type, '/', typeEnd - type) && (aStrict ? (net_FindCharNotInSet(start + consumed, end, HTTP_LWS) == end) : (strncmp(type, "*/*", typeEnd - type) != 0))) { // Common case here is that aContentType is empty diff --git a/netwerk/base/nsURLParsers.cpp b/netwerk/base/nsURLParsers.cpp index a024174f04..58b2096eef 100644 --- a/netwerk/base/nsURLParsers.cpp +++ b/netwerk/base/nsURLParsers.cpp @@ -12,6 +12,9 @@ #include "nsString.h" #include "nsCRT.h" +#include "mozilla-config.h" +#include "plvmx.h" + using namespace mozilla; //---------------------------------------------------------------------------- @@ -524,7 +527,7 @@ nsAuthURLParser::ParseUserInfo(const char *userinfo, int32_t userinfoLen, return NS_OK; } - const char *p = (const char *) memchr(userinfo, ':', userinfoLen); + const char *p = (const char *) VMX_MEMCHR(userinfo, ':', userinfoLen); if (p) { // userinfo = if (p == userinfo) { diff --git a/netwerk/protocol/http/nsHttpChunkedDecoder.cpp b/netwerk/protocol/http/nsHttpChunkedDecoder.cpp index f80aec048a..1a5568f970 100644 --- a/netwerk/protocol/http/nsHttpChunkedDecoder.cpp +++ b/netwerk/protocol/http/nsHttpChunkedDecoder.cpp @@ -9,6 +9,9 @@ #include "nsHttpChunkedDecoder.h" #include +#include "mozilla-config.h" +#include "plvmx.h" + namespace mozilla { namespace net { @@ -92,7 +95,7 @@ nsHttpChunkedDecoder::ParseChunkRemaining(char *buf, *bytesConsumed = 0; - char *p = static_cast(memchr(buf, '\n', count)); + char *p = static_cast(VMX_MEMCHR(buf, '\n', count)); if (p) { *p = 0; count = p - buf; // new length diff --git a/netwerk/protocol/http/nsHttpTransaction.cpp b/netwerk/protocol/http/nsHttpTransaction.cpp index ec5aaaa34e..b6d2845e93 100644 --- a/netwerk/protocol/http/nsHttpTransaction.cpp +++ b/netwerk/protocol/http/nsHttpTransaction.cpp @@ -38,6 +38,9 @@ #include "nsISchedulingContext.h" #include +#include "mozilla-config.h" +#include "plvmx.h" + #ifdef MOZ_WIDGET_GONK #include "NetStatistics.h" #endif @@ -1500,7 +1503,7 @@ nsHttpTransaction::ParseHead(char *buf, // otherwise we can assume that we don't have a HTTP/0.9 response. MOZ_ASSERT (mHttpResponseMatched); - while ((eol = static_cast(memchr(buf, '\n', count - *countRead))) != nullptr) { + while ((eol = static_cast(VMX_MEMCHR(buf, '\n', count - *countRead))) != nullptr) { // found line in range [buf:eol] len = eol - buf + 1; diff --git a/netwerk/streamconv/converters/nsMultiMixedConv.cpp b/netwerk/streamconv/converters/nsMultiMixedConv.cpp index 6729673368..aaf2e7d535 100644 --- a/netwerk/streamconv/converters/nsMultiMixedConv.cpp +++ b/netwerk/streamconv/converters/nsMultiMixedConv.cpp @@ -18,6 +18,9 @@ #include "nsContentSecurityManager.h" #include "nsHttp.h" +#include "mozilla-config.h" +#include "plvmx.h" + // // Helper function for determining the length of data bytes up to // the next multipart token. A token is usually preceded by a LF @@ -1187,7 +1190,7 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr, } mContentLength = UINT64_MAX; // XXX what if we were already called? - while (cursorLen && (newLine = (char *) memchr(cursor, nsCRT::LF, cursorLen))) { + while (cursorLen && (newLine = (char *) VMX_MEMCHR(cursor, nsCRT::LF, cursorLen))) { // adjust for linefeeds if ((newLine > cursor) && (newLine[-1] == nsCRT::CR) ) { // CRLF lineFeedIncrement = 2; diff --git a/security/certverifier/NSSCertDBTrustDomain.cpp b/security/certverifier/NSSCertDBTrustDomain.cpp index 805365799a..bce9dcb40c 100644 --- a/security/certverifier/NSSCertDBTrustDomain.cpp +++ b/security/certverifier/NSSCertDBTrustDomain.cpp @@ -30,6 +30,9 @@ #include "CNNICHashWhitelist.inc" +#include "mozilla-config.h" +#include "plvmx.h" + using namespace mozilla; using namespace mozilla::pkix; @@ -314,7 +317,7 @@ GetOCSPAuthorityInfoAccessLocation(PLArenaPool* arena, const SECItem& location = current->name.other; // (location.len + 1) must be small enough to fit into a uint32_t, // but we limit it to a smaller bound to reduce OOM risk. - if (location.len > 1024 || memchr(location.data, 0, location.len)) { + if (location.len > 1024 || VMX_HASCHR(location.data, 0, location.len)) { // Reject embedded nulls. (NSS doesn't do this) return Result::ERROR_CERT_BAD_ACCESS_LOCATION; } diff --git a/security/nss/lib/zlib/gzread.c b/security/nss/lib/zlib/gzread.c index 548201ab00..bbd4b7a659 100644 --- a/security/nss/lib/zlib/gzread.c +++ b/security/nss/lib/zlib/gzread.c @@ -5,6 +5,9 @@ #include "gzguts.h" +#include "mozilla-config.h" +#include "plvmx.h" + /* Local functions */ local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); local int gz_avail OF((gz_statep)); @@ -581,7 +584,7 @@ char * ZEXPORT gzgets(file, buf, len) /* look for end-of-line in current output buffer */ n = state->have > left ? left : state->have; - eol = memchr(state->next, '\n', n); + eol = VMX_MEMCHR(state->next, '\n', n); if (eol != NULL) n = (unsigned)(eol - state->next) + 1; diff --git a/xpcom/io/nsEscape.cpp b/xpcom/io/nsEscape.cpp index 25d8511755..7936e9868e 100644 --- a/xpcom/io/nsEscape.cpp +++ b/xpcom/io/nsEscape.cpp @@ -12,6 +12,9 @@ #include "nsCRT.h" #include "plstr.h" +#include "mozilla-config.h" +#include "plvmx.h" + static const char hexCharsUpper[] = "0123456789ABCDEF"; static const char hexCharsUpperLower[] = "0123456789ABCDEFabcdef"; @@ -529,7 +532,7 @@ NS_EscapeURL(const nsAFlatString& aStr, const nsTArray& aForbidden, return aStr; } -#define ISHEX(c) memchr(hexCharsUpperLower, c, sizeof(hexCharsUpperLower)-1) +#define ISHEX(c) VMX_HASCHR(hexCharsUpperLower, c, sizeof(hexCharsUpperLower)-1) bool NS_UnescapeURL(const char* aStr, int32_t aLen, uint32_t aFlags,