Alignment question

From: Aslan Kral (spamtrap_at_crayne.org)
Date: 02/25/05


Date: Fri, 25 Feb 2005 19:16:00 +0000 (UTC)

The following C++ class is used to jump to the first pointer in the vtable.
class KWndProc
{
    uint32 jmp_buf[3];
protected:
   virtual LRESULT WndProc(HWND hWnd,UINT nMessage,WPARAM wParam,LPARAM
lParam)=0;

public:
#if 1
   KWndProc()
   {
         jmp_buf[0] = 0xB9909090; // mov ecx,
         jmp_buf[1] = (uint32)this;// this
         jmp_buf[2] = 0x20FF018B; // mov eax, [ecx]
                                 // jmp [eax]
   }
   virtual ~KWndProc()
   {}
   operator WNDPROC ()
   { return (WNDPROC) ((uint8*)jmp_buf+3); }
#else
   KWndProc()
   {
         uint8* p = (uint8*)jmp_buf;
         p[0] = 0xB9; // mov ecx,
         *((uint32*)(p+1)) = this;// this
         *((uint32*)(p+5)) = 0x20FF018B; // mov eax, [ecx]
                                 // jmp [eax]
   }
   virtual ~KWndProc()
   {}
   operator WNDPROC ()
   { return (WNDPROC) jmp_buf; }
#endif
};

Which one is better for alignment? The first pointer in the vtable is a
window procedure so it will be called many times by windows through this
thunk data.