NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: Olsonist on March 20, 2017, 05:06:53 AM

Title: padding alignments with int3
Post by: Olsonist on March 20, 2017, 05:06:53 AM
I would like to pad alignments with int3 rather than nop. Something like:
    ALIGNMODE   int3,–1
int3 is commonly used by Microsoft as a padding. It has the nice property of failure. It also tells the decoders not to speculate the instruction following an indirect branch as the likely branch target.

Anyways, is this possible? These attempts don't seem to work:
   align   32,db 0xcc
   align   32,int3
Title: Re: padding alignments with int3
Post by: Frank Kotler on March 20, 2017, 06:09:22 AM
Code: [Select]
align 32, db 0xCC
align 32, int3
both seem to work for me. What's the problem you're having exactly?

Best,
Frank

Title: Re: padding alignments with int3
Post by: Olsonist on March 20, 2017, 05:38:35 PM
I stripped my code down to a minimal test case and int3 worked.
This means two things: I have a problem with my macros and it was kinda late last night.

Coffee ingested. Macro problem solved.

Thanks.
Title: Re: padding alignments with int3
Post by: Olsonist on March 20, 2017, 11:43:35 PM
BTW, aligning with UB2 and INT3 would be nice. UB2 is mentioned by Intel as preventing speculation but it is 2 bytes. Combining UB2 and INT3 could handle both even and odd cases.
Title: Re: padding alignments with int3
Post by: Frank Kotler on March 21, 2017, 01:51:01 AM
Well... I don't use "align" much. I expected "0xCC" to work, I was a little surprised that "int3" worked. Nasm knows "ud2" as an undefined instruction (0xF, 0xB). Is this the same as "UB2"? This seems to work, too, although Nasm seems confused about the meaning of "32" in this case. It's not clear to me how (or why) you'd use an "odd" alignment. "align" itself is apparently an internal macro which uses "times" to do the deed. Maybe you can do something with that?

Best,
Frank

Title: Re: padding alignments with int3
Post by: Olsonist on March 21, 2017, 06:33:18 AM
Doh. ud2.

I can do this 'manually' by putting a ud2 after jump reg and then an align 32,int3.
Title: Re: padding alignments with int3
Post by: Frank Kotler on March 21, 2017, 04:22:18 PM
Okay. As long as you can figure out how to do what you need to do!

Best,
Frank