Skip to contentSkip to conversation

Enforce aligned pc

PATCH In review Marius Groeger 3 participants 3 messages Apr 26, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enforce aligned pc

Hi,

this patch makes qemu throw an exception when the PC is not aligned to a word boundary.

Signature · 1 line
Marius
translate.c +6 -0
@@ -1320,6 +1707,12 @@
     uint16_t op, op1;
     int16_t imm;
 
+	/* make sure instructions are on a word boundary */
+	if (ctx->pc & 0x3) {
+		generate_exception(ctx, EXCP_AdEL);
+		return;
+	}
+
     if ((ctx->hflags & MIPS_HFLAG_BMASK) == MIPS_HFLAG_BL) {
         /* Handle blikely not taken case */
         MIPS_DEBUG("blikely condition (%08x)", ctx->pc + 4);
#1 lore raw

Is it possible that the pc gets unaligned ?

Fabrice.

Quoted 3 lines · Marius Groeger

Hi,

this patch makes qemu throw an exception when the PC is not aligned to a word boundary.

#2 lore raw
Quoted 1 line · Fabrice Bellard

Is it possible that the pc gets unaligned ?

Yes, e.g. due to stack corruption which overwrites the return address.

Thiemo