[Webkit-unassigned] [Bug 29415] New: [Qt] byte alignment issue on MIPS

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Sep 18 07:36:34 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=29415

           Summary: [Qt] byte alignment issue on MIPS
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: Other
        OS/Version: Mac OS X 10.5
            Status: NEW
          Keywords: Qt
          Severity: Normal
          Priority: P2
         Component: New Bugs
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: vestbo at webkit.org


This bug report originated from issue QTBUG-3991
<http://bugreports.qt.nokia.com/browse/QTBUG-3991>

--- Description ---

We have found an issue in the following function: static inline bool
equal(StringImpl* string, const UChar* characters, unsigned length) in
AtomicString.cpp.
The issue is that the variables 'stringCharacters' and
'bufferCharacters' are uint32 pointers but in fact point to UChar*
variables. This means that the starting
addresses might be not aligned to 4 bytes. On MIPS an unaligned
exception is raised and in our case is handled by the kernel, but,
depending on the kernel, it can
also lead to the kernel sending SIGBUS to the application. The kernel
exception handling is very costly and below is a solution to this
problem; basically we
define a structure with the 'packed' attribute which will make the
compiler to generate code capable of handling unaligned accesses (on
MIPS this means
replacing 'lw' with a pair: 'lwl' and 'lwr'). I saw that Q_PACKED is
defined only for the GCC and Intel compiler which should make our change
safe for all cases.
Another solution is to simply add  || PLATFORM(MIPS) where the check for
ARM is made.

Patch:

--- a/src/3rdparty/webkit/WebCore/platform/text/AtomicString.cpp
+++ b/src/3rdparty/webkit/WebCore/platform/text/AtomicString.cpp
@@ -96,6 +96,10 @@ struct UCharBuffer {
     unsigned length;
 };

+struct unaligned_struct {
+    uint32_t i;
+} Q_PACKED;
+
 static inline bool equal(StringImpl* string, const UChar* characters, unsigned
length)
 {
     if (string->length() != length)
@@ -111,17 +115,21 @@ static inline bool equal(StringImpl* string, const UChar*
characters, unsigned l
 #else
     /* Do it 4-bytes-at-a-time on architectures where it's safe */

-    const uint32_t* stringCharacters = reinterpret_cast<const
uint32_t*>(string->characters());
-    const uint32_t* bufferCharacters = reinterpret_cast<const
uint32_t*>(characters);
+    const struct unaligned_struct *stringCharacters =
+        reinterpret_cast<const struct
unaligned_struct*>(string->characters());
+    const struct unaligned_struct *bufferCharacters =
+        reinterpret_cast<const struct unaligned_struct*>(characters);

     unsigned halfLength = length >> 1;
-    for (unsigned i = 0; i != halfLength; ++i) {
-        if (*stringCharacters++ != *bufferCharacters++)
+    for (unsigned i = 0; i != halfLength; ++i, stringCharacters++,
bufferCharacters++) {
+        if (stringCharacters->i != bufferCharacters->i)
             return false;
     }

-    if (length & 1 &&  *reinterpret_cast<const uint16_t*>(stringCharacters) !=
*reinterpret_cast<const uint16_t*>(bufferCharacters))
+    if (length & 1 &&
+        *reinterpret_cast<const uint16_t*>(stringCharacters) !=
*reinterpret_cast<const uint16_t*>(bufferCharacters)) {
         return false;
+    }

     return true;
 #endif

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list