- Fix LP64-bugs and misaligned accesses. [1]

- Fix build on sparc64.

Approved by:	marcus
Obtained from:	NetBSD [1]
This commit is contained in:
Marius Strobl 2009-04-04 12:59:28 +00:00
parent 53b300928d
commit e49fa2648d
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=231581
6 changed files with 309 additions and 5 deletions

View file

@ -73,10 +73,6 @@ MOZ_OPTIONS+= --disable-dbus
LIB_DEPENDS+= dbus-glib-1.2:${PORTSDIR}/devel/dbus-glib
.endif
.if ${ARCH} == "sparc64"
BROKEN= Does not compile on sparc64
.endif
post-extract::
@${SED} -e 's|@FIREFOX_ICON@|${FIREFOX_ICON}|' -e 's|@MOZILLA@|${MOZILLA}|' \
-e 's|@MOZILLA_NAME@|${MOZILLA_NAME}|' \
@ -97,7 +93,7 @@ post-patch:
@(cd ${WRKSRC}/xpcom/reflect/xptcall/src/md/unix && \
${LN} -s xptcstubs_asm_sparc64_openbsd.s xptcstubs_asm_sparc64_freebsd.s && \
${LN} -s xptcstubs_sparc64_openbsd.cpp xptcstubs_sparc64_freebsd.cpp && \
${LN} -s xptcinvoke_sparc64_openbsd.cpp xptcinvoke_sparc64_freebsd.cpp) && \
${LN} -s xptcinvoke_sparc64_openbsd.cpp xptcinvoke_sparc64_freebsd.cpp && \
${LN} -s xptcinvoke_asm_sparc64_openbsd.s xptcinvoke_asm_sparc64_freebsd.s)
.endif

View file

@ -0,0 +1,215 @@
# Ensure correct alignment for nsCSSValue objects inside nsCSSValue::Array.
# (Bug 476345)
--- layout/style/nsCSSValue.h.orig 2008-07-02 00:51:43.000000000 +0200
+++ layout/style/nsCSSValue.h 2009-02-01 21:43:29.000000000 +0100
@@ -286,104 +286,7 @@
// failure.
static nsStringBuffer* BufferFromString(const nsString& aValue);
- struct Array {
-
- // return |Array| with reference count of zero
- static Array* Create(PRUint16 aItemCount) {
- return new (aItemCount) Array(aItemCount);
- }
-
- nsCSSValue& operator[](PRUint16 aIndex) {
- NS_ASSERTION(aIndex < mCount, "out of range");
- return *(First() + aIndex);
- }
-
- const nsCSSValue& operator[](PRUint16 aIndex) const {
- NS_ASSERTION(aIndex < mCount, "out of range");
- return *(First() + aIndex);
- }
-
- nsCSSValue& Item(PRUint16 aIndex) { return (*this)[aIndex]; }
- const nsCSSValue& Item(PRUint16 aIndex) const { return (*this)[aIndex]; }
-
- PRUint16 Count() const { return mCount; }
-
- PRBool operator==(const Array& aOther) const
- {
- if (mCount != aOther.mCount)
- return PR_FALSE;
- for (PRUint16 i = 0; i < mCount; ++i)
- if ((*this)[i] != aOther[i])
- return PR_FALSE;
- return PR_TRUE;
- }
-
- void AddRef() {
- if (mRefCnt == PR_UINT16_MAX) {
- NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
- return;
- }
- ++mRefCnt;
- NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Array", sizeof(*this));
- }
- void Release() {
- if (mRefCnt == PR_UINT16_MAX) {
- NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
- return;
- }
- --mRefCnt;
- NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Array");
- if (mRefCnt == 0)
- delete this;
- }
-
- private:
-
- PRUint16 mRefCnt;
- PRUint16 mCount;
-
- void* operator new(size_t aSelfSize, PRUint16 aItemCount) CPP_THROW_NEW {
- return ::operator new(aSelfSize + sizeof(nsCSSValue)*aItemCount);
- }
-
- void operator delete(void* aPtr) { ::operator delete(aPtr); }
-
- nsCSSValue* First() {
- return (nsCSSValue*) (((char*)this) + sizeof(*this));
- }
-
- const nsCSSValue* First() const {
- return (const nsCSSValue*) (((const char*)this) + sizeof(*this));
- }
-
-#define CSSVALUE_LIST_FOR_VALUES(var) \
- for (nsCSSValue *var = First(), *var##_end = var + mCount; \
- var != var##_end; ++var)
-
- Array(PRUint16 aItemCount)
- : mRefCnt(0)
- , mCount(aItemCount)
- {
- MOZ_COUNT_CTOR(nsCSSValue::Array);
- CSSVALUE_LIST_FOR_VALUES(val) {
- new (val) nsCSSValue();
- }
- }
-
- ~Array()
- {
- MOZ_COUNT_DTOR(nsCSSValue::Array);
- CSSVALUE_LIST_FOR_VALUES(val) {
- val->~nsCSSValue();
- }
- }
-
-#undef CSSVALUE_LIST_FOR_VALUES
-
- private:
- Array(const Array& aOther); // not to be implemented
- };
-
+ struct Array;
struct URL {
// Methods are not inline because using an nsIPrincipal means requiring
// caps, which leads to REQUIRES hell, since this header is included all
@@ -454,5 +357,102 @@
} mValue;
};
-#endif /* nsCSSValue_h___ */
+struct nsCSSValue::Array {
+
+ // return |Array| with reference count of zero
+ static Array* Create(PRUint16 aItemCount) {
+ return new (aItemCount) Array(aItemCount);
+ }
+
+ nsCSSValue& operator[](PRUint16 aIndex) {
+ NS_ASSERTION(aIndex < mCount, "out of range");
+ return mArray[aIndex];
+ }
+
+ const nsCSSValue& operator[](PRUint16 aIndex) const {
+ NS_ASSERTION(aIndex < mCount, "out of range");
+ return mArray[aIndex];
+ }
+
+ nsCSSValue& Item(PRUint16 aIndex) { return (*this)[aIndex]; }
+ const nsCSSValue& Item(PRUint16 aIndex) const { return (*this)[aIndex]; }
+
+ PRUint16 Count() const { return mCount; }
+
+ PRBool operator==(const Array& aOther) const
+ {
+ if (mCount != aOther.mCount)
+ return PR_FALSE;
+ for (PRUint16 i = 0; i < mCount; ++i)
+ if ((*this)[i] != aOther[i])
+ return PR_FALSE;
+ return PR_TRUE;
+ }
+
+ void AddRef() {
+ if (mRefCnt == PR_UINT16_MAX) {
+ NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
+ return;
+ }
+ ++mRefCnt;
+ NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Array", sizeof(*this));
+ }
+ void Release() {
+ if (mRefCnt == PR_UINT16_MAX) {
+ NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
+ return;
+ }
+ --mRefCnt;
+ NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Array");
+ if (mRefCnt == 0)
+ delete this;
+ }
+
+private:
+
+ PRUint16 mRefCnt;
+ const PRUint16 mCount;
+ // This must be the last sub-object, since we extend this array to
+ // be of size mCount; it needs to be a sub-object so it gets proper
+ // alignment.
+ nsCSSValue mArray[1];
+ void* operator new(size_t aSelfSize, PRUint16 aItemCount) CPP_THROW_NEW {
+ return ::operator new(aSelfSize + sizeof(nsCSSValue) * (aItemCount - 1));
+ }
+
+ void operator delete(void* aPtr) { ::operator delete(aPtr); }
+
+ nsCSSValue* First() { return mArray; }
+
+ const nsCSSValue* First() const { return mArray; }
+
+#define CSSVALUE_LIST_FOR_EXTRA_VALUES(var) \
+for (nsCSSValue *var = First() + 1, *var##_end = First() + mCount; \
+ var != var##_end; ++var)
+
+ Array(PRUint16 aItemCount)
+ : mRefCnt(0)
+ , mCount(aItemCount)
+ {
+ MOZ_COUNT_CTOR(nsCSSValue::Array);
+ CSSVALUE_LIST_FOR_EXTRA_VALUES(val) {
+ new (val) nsCSSValue();
+ }
+ }
+
+ ~Array()
+ {
+ MOZ_COUNT_DTOR(nsCSSValue::Array);
+ CSSVALUE_LIST_FOR_EXTRA_VALUES(val) {
+ val->~nsCSSValue();
+ }
+ }
+
+#undef CSSVALUE_LIST_FOR_VALUES
+
+private:
+ Array(const Array& aOther); // not to be implemented
+};
+
+#endif /* nsCSSValue_h___ */

View file

@ -0,0 +1,24 @@
--- toolkit/components/history/src/nsGlobalHistory.cpp.orig 2006-02-02 20:55:17.000000000 +0100
+++ toolkit/components/history/src/nsGlobalHistory.cpp
@@ -322,7 +322,9 @@ matchAgeInDaysCallback(nsIMdbRow *row, v
if (err != 0) return PR_FALSE;
PRTime rowDate;
- PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", &rowDate);
+ long long ld;
+ PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", &ld);
+ rowDate = ld;
PRInt32 days = GetAgeInDays(matchSearchTerm->now, rowDate);
@@ -1067,7 +1069,9 @@ nsGlobalHistory::GetRowValue(nsIMdbRow *
if (!yarn.mYarn_Fill || !yarn.mYarn_Buf)
return NS_OK;
- PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", aResult);
+ long long ld;
+ PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", &ld);
+ *aResult = ld;
return NS_OK;
}

View file

@ -0,0 +1,17 @@
--- toolkit/components/places/src/nsMorkHistoryImporter.cpp.orig 2008-03-19 20:30:49.000000000 +0100
+++ toolkit/components/places/src/nsMorkHistoryImporter.cpp 2008-12-17 09:38:05.000000000 +0100
@@ -148,9 +148,12 @@ AddToHistoryCB(const nsCSubstring &aRowI
}
PRTime date;
- if (PR_sscanf(values[kLastVisitColumn].get(), "%lld", &date) != 1) {
+ long long ld;
+ if (PR_sscanf(values[kLastVisitColumn].get(), "%lld", &ld) != 1) {
date = -1;
- }
+ } else {
+ date = ld;
+ }
PRBool isTyped = values[kTypedColumn].EqualsLiteral("1");
PRInt32 transition = isTyped ?

View file

@ -0,0 +1,28 @@
# reported upstream as: https://bugzilla.mozilla.org/show_bug.cgi?id=469276
--- toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp.orig 2008-08-25 22:59:14.000000000 +0200
+++ toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp 2008-12-12 16:31:11.000000000 +0100
@@ -2023,8 +2023,9 @@
return NS_ERROR_FAILURE;
}
const nsCSubstring& str = Substring(chunk, start, 4);
- const PRUint32 *p = reinterpret_cast<const PRUint32*>(str.BeginReading());
- entry->mAddChunkId = PR_ntohl(*p);
+ PRUint32 p;
+ memcpy(&p, str.BeginReading(), 4);
+ entry->mAddChunkId = PR_ntohl(p);
if (entry->mAddChunkId == 0) {
NS_WARNING("Received invalid chunk number.");
return NS_ERROR_FAILURE;
@@ -2052,8 +2053,9 @@
if (chunkType == CHUNK_SUB) {
const nsCSubstring& str = Substring(chunk, start, 4);
- const PRUint32 *p = reinterpret_cast<const PRUint32*>(str.BeginReading());
- entry->mAddChunkId = PR_ntohl(*p);
+ PRUint32 p;
+ memcpy(&p, str.BeginReading(), 4);
+ entry->mAddChunkId = PR_ntohl(p);
if (entry->mAddChunkId == 0) {
NS_WARNING("Received invalid chunk number.");
return NS_ERROR_FAILURE;

View file

@ -0,0 +1,24 @@
--- xpfe/components/history/src/nsGlobalHistory.cpp.orig 2007-12-03 05:25:14.000000000 +0100
+++ xpfe/components/history/src/nsGlobalHistory.cpp
@@ -304,7 +304,9 @@ matchAgeInDaysCallback(nsIMdbRow *row, v
if (err != 0) return PR_FALSE;
PRTime rowDate;
- PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", &rowDate);
+ long long ld;
+ PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", &ld);
+ rowDate = ld;
PRInt32 days = matchSearchTerm->globalHist->GetAgeInDays(rowDate);
@@ -1000,7 +1002,9 @@ nsGlobalHistory::GetRowValue(nsIMdbRow *
if (!yarn.mYarn_Fill || !yarn.mYarn_Buf)
return NS_OK;
- PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", aResult);
+ long long ld;
+ PR_sscanf((const char*)yarn.mYarn_Buf, "%lld", &ld);
+ *aResult = ld;
return NS_OK;
}