***You will need XCode 2.3 or better to use this patch***

****WINE MUST BE CONFIGURED WITH THE FOLLOWING EXPORT****
export CFLAGS='-g -O1'
(the -g is not needed -- but what the hell makes it easier to debug)
(Read the notes below to find out why...)

This patch will fix the stack problems when running windows apps on Mac OSX under wine
Windows uses a  4 byte algined stack
Mac OSX uses a 16 byte algined stack

This leads to windows applications working (luckily) 1/4 of the time (when the stack is aligned)

This patch activates a new gcc extension force_align_arg_pointer/mstackrealign
This extension will realign the stack (to native) when entering specified functions

So a windows application calls a wine function -- 
(Stack possibilities aligned to esp % 16 = {0, 4, 8, 12})
    Before:
        Call Mac OSX function with esp % 16 = {0, 4, 8, 12}
    After:
        Coming into function with esp % 16 = {0, 4, 8, 12}
        Align stack to 16 (this does take a register and extra instructions)
        Call Mac OSX function with esp % 16 = {0}

TODO: The change to 'dlls/msvcrt/Makefile.in' needs to be selective otherwise it may cause problems with older gcc's

-----
NOTE: Mac OSX wine needs this patch to function correctly
      It will not help older gcc's

NOTE: Due to a bug (has some patches out there)
      The realignment has problems with -O2 and above
      .: -O1 is used (when a fix is released to the public this should be checked)

Index: ChangeLog
===================================================================
RCS file: /home/wine/wine/ChangeLog,v
retrieving revision 1.114
diff -u -p -r1.114 ChangeLog
--- ChangeLog   24 May 2006 18:09:06 -0000      1.114
+++ ChangeLog   2 Jun 2006 08:37:32 -0000
@@ -1,3 +1,14 @@
+2006-06-02  Nick Burns <adger44@hotmail.com>
+
+       * dlls/d3d8/d3d8_private.h, dlls/d3d9/d3d9_private.h,
+         dlls/ddraw/gl_private.h, dlls/opengl32/opengl_ext.h,
+         include/windef.h:
+       If on Mac OSX (x86) use force_align_arg_pointer to fix the stack on entry to Wine.
+
+       * dlls/msvcrt/Makefile.in:
+       If on Mac OSX (x86) use mstackrealign.
+       This part of the patch need to me Mac OSX specific
+
 2006-05-24  Alexandre Julliard <julliard@winehq.org>
 
        * dlls/usp10/tests/usp10.c:
Index: dlls/d3d8/d3d8_private.h
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/d3d8_private.h,v
retrieving revision 1.82
diff -u -p -r1.82 d3d8_private.h
--- dlls/d3d8/d3d8_private.h	23 May 2006 12:47:44 -0000	1.82
+++ dlls/d3d8/d3d8_private.h	29 May 2006 21:06:32 -0000
@@ -36,6 +36,13 @@
 #define WINAPI      __stdcall
 #define APIENTRY    WINAPI
 
+#ifdef __APPLE__
+#undef WINAPI
+#define WINAPI __stdcall __attribute((force_align_arg_pointer))
+//why is it #define'ng WINAPI before including windef.h???
+//that will cause redefs...
+#endif
+
 #include <stdarg.h>
 
 #define NONAMELESSUNION
Index: dlls/d3d9/d3d9_private.h
===================================================================
RCS file: /home/wine/wine/dlls/d3d9/d3d9_private.h,v
retrieving revision 1.31
diff -u -p -r1.31 d3d9_private.h
--- dlls/d3d9/d3d9_private.h	23 May 2006 12:47:45 -0000	1.31
+++ dlls/d3d9/d3d9_private.h	29 May 2006 21:06:34 -0000
@@ -47,6 +47,11 @@
 #define WINAPI      __stdcall
 #define APIENTRY    WINAPI
 
+#ifdef __APPLE__
+#undef WINAPI
+#define WINAPI __stdcall __attribute((force_align_arg_pointer))
+#endif
+
 #include "gdi.h"
 #include "d3d9.h"
 #include "ddraw.h"
Index: dlls/ddraw/gl_private.h
===================================================================
RCS file: /home/wine/wine/dlls/ddraw/gl_private.h,v
retrieving revision 1.10
diff -u -p -r1.10 gl_private.h
--- dlls/ddraw/gl_private.h	23 May 2006 12:47:48 -0000	1.10
+++ dlls/ddraw/gl_private.h	29 May 2006 21:06:51 -0000
@@ -45,6 +45,11 @@
 #define WINAPI      __stdcall
 #define APIENTRY    WINAPI
 
+#ifdef __APPLE__
+#undef WINAPI
+#define WINAPI __stdcall __attribute((force_align_arg_pointer))
+#endif
+
 #define GL_API_FUNCTION(f) extern typeof(f) * p##f;
 #include "gl_api.h"
 #undef GL_API_FUNCTION
Index: dlls/msvcrt/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/Makefile.in,v
retrieving revision 1.19
diff -u -p -r1.19 Makefile.in
--- dlls/msvcrt/Makefile.in	3 Nov 2005 12:05:05 -0000	1.19
+++ dlls/msvcrt/Makefile.in	29 May 2006 21:06:57 -0000
@@ -8,6 +8,7 @@ IMPORTLIB = libmsvcrt.$(IMPLIBEXT)
 IMPORTS   = kernel32 ntdll
 DELAYIMPORTS = user32
 EXTRALIBS = $(LIBUNICODE)
+MODCFLAGS = -mstackrealign
 
 C_SRCS = \
 	console.c \
Index: dlls/opengl32/opengl_ext.h
===================================================================
RCS file: /home/wine/wine/dlls/opengl32/opengl_ext.h,v
retrieving revision 1.12
diff -u -p -r1.12 opengl_ext.h
--- dlls/opengl32/opengl_ext.h	23 May 2006 12:48:27 -0000	1.12
+++ dlls/opengl32/opengl_ext.h	29 May 2006 21:07:05 -0000
@@ -41,6 +41,11 @@
 #define WINAPI      __stdcall
 #define APIENTRY    WINAPI
 
+#ifdef __APPLE__
+#undef WINAPI
+#define WINAPI __stdcall __attribute((force_align_arg_pointer))
+#endif
+
 /* For compatibility with old Mesa headers */
 #ifndef GLX_SAMPLE_BUFFERS_ARB
 # define GLX_SAMPLE_BUFFERS_ARB             100000
Index: include/windef.h
===================================================================
RCS file: /home/wine/wine/include/windef.h,v
retrieving revision 1.102
diff -u -p -r1.102 windef.h
--- include/windef.h	23 May 2006 12:49:05 -0000	1.102
+++ include/windef.h	29 May 2006 21:07:59 -0000
@@ -144,6 +144,13 @@ extern "C" {
 #define APIENTRY    WINAPI
 #define CONST       const
 
+#ifdef __APPLE__
+#undef WINAPI
+#define WINAPI      __stdcall __attribute((force_align_arg_pointer))
+#undef WINAPIV
+#define WINAPIV     __cdecl __attribute((force_align_arg_pointer))
+#endif
+
 /* Misc. constants. */
 
 #undef NULL
