We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 602

Summary: SDL based apps crash when run remotely from sparc64 and being dispayed on a i386 system
Product: SDL Reporter: Brad Smith <brad>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: 1.2.13   
Hardware: x86   
OS: OpenBSD   

Description Brad Smith 2008-07-05 18:00:19 UTC
Trying to run SDL based apps on a sparc64 system and having the display output targeted towards a i386 system results in the apps crashing. The handful of apps I have tried all crash in the same function in the SDL library.

#0  0x000000004ab475b4 in SDL_XF86VidModeGetModeLine ()
   from /usr/local/lib/libSDL.so.8.0
#1  0x000000004ab3a630 in save_mode () from /usr/local/lib/libSDL.so.8.0
#2  0x000000004ab3bccc in X11_GetVideoModes () from /usr/local/lib/libSDL.so.8.0
#3  0x000000004ab3dd18 in X11_VideoInit () from /usr/local/lib/libSDL.so.8.0
#4  0x000000004ab2efe4 in SDL_VideoInit () from /usr/local/lib/libSDL.so.8.0
#5  0x000000004ab07890 in SDL_InitSubSystem () from /usr/local/lib/libSDL.so.8.0
#6  0x000000004ab078d4 in SDL_Init () from /usr/local/lib/libSDL.so.8.0
#7  0x0000000000108328 in ?? ()
#8  0x0000000000108328 in ?? ()
Comment 1 Blue Swirl 2008-09-03 09:20:13 UTC
I fixed this with the following patch (sorry, the attachment thing doesn't work):
--- src/video/Xext/Xxf86vm/XF86VMode.c.orig     Mon Dec 31 04:48:09 2007
+++ src/video/Xext/Xxf86vm/XF86VMode.c  Fri Aug 22 18:59:44 2008
@@ -281,7 +281,8 @@
        }
        _XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
     } else {
-       modeline->private = NULL;
+       // Avoid unaligned trap on Sparc64
+       memset(&modeline->private, '\0', sizeof(modeline->private));
     }
     UnlockDisplay(dpy);
     SyncHandle();
Comment 2 Brad Smith 2008-09-03 13:13:27 UTC
> I fixed this with the following patch

As we had talked about in private I tried out your diff and SDL is still crashing. I double checked and rebuilt the library just to make sure and indeed it is still crashing.
Comment 3 Blue Swirl 2008-09-07 05:13:41 UTC
(In reply to comment #2)
> > I fixed this with the following patch
> 
> As we had talked about in private I tried out your diff and SDL is still
> crashing. I double checked and rebuilt the library just to make sure and indeed
> it is still crashing.
> 

Sorry, I had changed the compiler flags from -O2 to -g, and with -O2 level gcc optimizes the memset back to stx which we want to avoid. This version works by calling memset more indirectly.

--- src/video/Xext/Xxf86vm/XF86VMode.c.orig     Mon Dec 31 04:48:09 2007
+++ src/video/Xext/Xxf86vm/XF86VMode.c  Sun Sep  7 11:48:19 2008
@@ -211,6 +211,11 @@
     return True;
 }
 
+static inline void zap_ptr(char *ptr, size_t size)
+{
+    memset(ptr, '\0', size);
+}
+
 Bool
 SDL_NAME(XF86VidModeGetModeLine)(dpy, screen, dotclock, modeline)
     Display* dpy;
@@ -281,7 +286,8 @@
        }
        _XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
     } else {
-       modeline->private = NULL;
+       // Avoid unaligned trap on Sparc64
+       zap_ptr((char *)&modeline->private, sizeof(modeline->private));
     }
     UnlockDisplay(dpy);
     SyncHandle();

Comment 4 Brad Smith 2008-09-07 17:25:25 UTC
Yes, that does the trick.
Comment 5 Ryan C. Gordon 2008-09-08 00:38:30 UTC
Fixed in svn revision #4083 for the 1.2 branch, and #4084 for the 1.3 branch.

Thanks!

--ryan.


Comment 6 Ryan C. Gordon 2008-09-15 13:54:39 UTC
svn revisions #4097 and #4098 have a hopefully-better fix for this.

--ryan.