Skip to content

Commit

Permalink
MIPS: Make sure callee-saved registers end up on word boundaries
Browse files Browse the repository at this point in the history
In addition to handling parameters and local variables,
mono_arch_allocate_vars reserves space for callee-saved registers.

Even though the current implementation takes care of properly aligning
the variables according to their datatype, it doesn't force alignment
to a word boundary before processing the callee-saved area.  This can
result in misaligned accesses if the last locals are booleans or small
integers.

Worse still: the garbage collector does then not see these non-word-
aligned references, and can end up reclaiming the pointed-to objects
if there are no other references to them--causing strange crashes and
type morphing effects under memory pressure.

Fix that by forcibly aligning the callee-saved area.

Commit contributed under the MIT/X11 license.
  • Loading branch information
ztzg committed Apr 17, 2011
1 parent 0cf62d7 commit 3678c1b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mono/mini/mini-mips.c
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,8 @@ mono_arch_allocate_vars (MonoCompile *cfg)
* args or return vals. Extra stack space avoids this in a lot of cases.
*/
offset += EXTRA_STACK_SPACE;
offset += SIZEOF_REGISTER - 1;
offset &= ~(SIZEOF_REGISTER - 1);

/* Space for saved registers */
cfg->arch.iregs_offset = offset;
Expand Down

0 comments on commit 3678c1b

Please sign in to comment.