Author Topic: padding alignments with int3  (Read 14352 times)

Offline Olsonist

  • Jr. Member
  • *
  • Posts: 26
padding alignments with int3
« 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
« Last Edit: March 20, 2017, 05:24:42 AM by Olsonist »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: padding alignments with int3
« Reply #1 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


Offline Olsonist

  • Jr. Member
  • *
  • Posts: 26
Re: padding alignments with int3
« Reply #2 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.
« Last Edit: March 20, 2017, 11:43:24 PM by Olsonist »

Offline Olsonist

  • Jr. Member
  • *
  • Posts: 26
Re: padding alignments with int3
« Reply #3 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.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: padding alignments with int3
« Reply #4 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


Offline Olsonist

  • Jr. Member
  • *
  • Posts: 26
Re: padding alignments with int3
« Reply #5 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.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: padding alignments with int3
« Reply #6 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