***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: 'msvcrt' needs some fixing either WINAPIV or __cdecl specificed in front of its functions.

-----
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   8 Jun 2006 07:06:10 -0000
@@ -1,3 +1,8 @@
+2006-06-08  Nick Burns <adger44@hotmail.com>
+
+       * include/windef.h:
+       If on Mac OSX (x86) use force_align_arg_pointer to fix the stack on entry to Wine.
+
 2006-05-24  Alexandre Julliard <julliard@winehq.org>
 
        * dlls/usp10/tests/usp10.c:
Index: include/windef.h
===================================================================
RCS file: /home/wine/wine/include/windef.h,v
retrieving revision 1.103
diff -u -p -r1.103 windef.h
--- include/windef.h	5 Jun 2006 12:29:21 -0000	1.103
+++ include/windef.h	8 Jun 2006 05:14:30 -0000
@@ -52,7 +52,12 @@ extern "C" {
 #ifndef __stdcall
 # ifdef __i386__
 #  ifdef __GNUC__
-#   define __stdcall __attribute__((__stdcall__))
+#   ifdef __APPLE__
+     /* Mac OSX uses 16-byte aligned stack and not a 4-byte one -- so we must realign on entry */
+#    define __stdcall __attribute__((__stdcall__)) __attribute((force_align_arg_pointer))
+#   else
+#    define __stdcall __attribute__((__stdcall__))
+#   endif
 #  elif defined(_MSC_VER)
     /* Nothing needs to be done. __stdcall already exists */
 #  else
@@ -65,7 +70,12 @@ extern "C" {
 
 #ifndef __cdecl
 # if defined(__i386__) && defined(__GNUC__)
-#  define __cdecl __attribute__((__cdecl__))
+#  ifdef __APPLE__
+    /* Mac OSX uses 16-byte aligned stack and not a 4-byte one -- so we must realign on entry */
+#   define __cdecl __attribute__((__cdecl__)) __attribute((force_align_arg_pointer))
+#  else
+#   define __cdecl __attribute__((__cdecl__))
+#  endif
 # elif !defined(_MSC_VER)
 #  define __cdecl
 # endif
 