[ scummvm-Patches-1657436 ] AGOS: alignment problems
SourceForge.net
noreply at sourceforge.net
Sun Feb 11 19:18:15 CET 2007
Patches item #1657436, was opened at 2007-02-11 20:18
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=418822&aid=1657436&group_id=37116
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 7
Private: No
Submitted By: Kostas Nakos (knakos)
Assigned to: kirben (kirben)
Summary: AGOS: alignment problems
Initial Comment:
(c'nued from our discussion in irc)
Agos engine crashes at several points, whenever a struct is "applied" to a memory buffer.
Problem:
Even though some structures have good sizes (like SubroutineLine which is 8 bytes), by not marking the struct as a packed struct the compiler (gcc) makes the assumption that a struct pointer for these will occur every time at word (32bit) boundary. This assumption is valid if all such structs are statically declared at compile time or malloc'ed at runtime. For performance reasons, these will all yield a pointer at a 4byte boundary. Thus, given this compiler-internal convention and also for performance reasons, the compiler favors word (32bit) accesses when it leads to more efficient code.
But we use (some) of these structs as "masks" onto memory buffers to extract info from, and (some) of these "masks" can be on 2byte boundary (SubroutineLine f.ex). This condition results in unaligned access error, whenever the compiler has optimized code for accessing these structs using 32bit loads/stores.
Solution:
Mark the offending structs as packed structs. In particular, any struct we use as a read/write template onto game data. ScummVM generated data (through malloc, static data) with these structs do not need to be packed.
I have not attached a patch as I got the engine running trivially: In intern.h surround all struct definition with our "pack-*.h" includes (excluding all enum definitions). Kirben might want to optimize this a bit, by leaving outside of the pack directives those structs which are used by the engine internally and are not used to read/write game structs (or not of course).
(this error condition should arise in all gcc-arm targets such as gp2x)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=418822&aid=1657436&group_id=37116
More information about the Scummvm-tracker
mailing list