Store the 16-bit stack pointer in the WOW32Reserved TEB field.
[wine] / include / stackframe.h
1 /*
2  * 16-bit and 32-bit mode stack frame layout
3  *
4  * Copyright 1995, 1998 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #ifndef __WINE_STACKFRAME_H
22 #define __WINE_STACKFRAME_H
23
24 #include <string.h>
25 #include <stdarg.h>
26
27 #include <windef.h>
28 #include <winbase.h>
29 #include <winnt.h>
30 #include <winreg.h>
31 #include <winternl.h>
32 #include <thread.h>
33 #include <wine/winbase16.h>
34
35 #include <pshpack1.h>
36
37   /* 32-bit stack layout after CallTo16() */
38 typedef struct _STACK32FRAME
39 {
40     DWORD   restore_addr;   /* 00 return address for restoring code selector */
41     DWORD   codeselector;   /* 04 code selector to restore */
42     EXCEPTION_REGISTRATION_RECORD frame;  /* 08 Exception frame */
43     SEGPTR  frame16;        /* 10 16-bit frame from last CallFrom16() */
44     DWORD   edi;            /* 14 saved registers */
45     DWORD   esi;            /* 18 */
46     DWORD   ebx;            /* 1c */
47     DWORD   ebp;            /* 20 saved 32-bit frame pointer */
48     DWORD   retaddr;        /* 24 return address */
49     DWORD   target;         /* 28 target address / CONTEXT86 pointer */
50     DWORD   nb_args;        /* 2c number of 16-bit argument bytes */
51 } STACK32FRAME;
52
53   /* 16-bit stack layout after CallFrom16() */
54 typedef struct _STACK16FRAME
55 {
56     STACK32FRAME *frame32;        /* 00 32-bit frame from last CallTo16() */
57     DWORD         edx;            /* 04 saved registers */
58     DWORD         ecx;            /* 08 */
59     DWORD         ebp;            /* 0c */
60     WORD          ds;             /* 10 */
61     WORD          es;             /* 12 */
62     WORD          fs;             /* 14 */
63     WORD          gs;             /* 16 */
64     DWORD         callfrom_ip;    /* 18 callfrom tail IP */
65     DWORD         module_cs;      /* 1c module code segment */
66     DWORD         relay;          /* 20 relay function address */
67     WORD          entry_ip;       /* 22 entry point IP */
68     DWORD         entry_point;    /* 26 API entry point to call, reused as mutex count */
69     WORD          bp;             /* 2a 16-bit stack frame chain */
70     WORD          ip;             /* 2c return address */
71     WORD          cs;             /* 2e */
72 } STACK16FRAME;
73
74 #include <poppack.h>
75
76 #define CURRENT_STACK16      ((STACK16FRAME*)MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved))
77 #define CURRENT_DS           (CURRENT_STACK16->ds)
78
79 /* Push bytes on the 16-bit stack of a thread;
80  * return a segptr to the first pushed byte
81  */
82 static inline SEGPTR stack16_push( int size )
83 {
84     STACK16FRAME *frame = CURRENT_STACK16;
85     memmove( (char*)frame - size, frame, sizeof(*frame) );
86     NtCurrentTeb()->WOW32Reserved = (char *)NtCurrentTeb()->WOW32Reserved - size;
87     return (SEGPTR)((char *)NtCurrentTeb()->WOW32Reserved + sizeof(*frame));
88 }
89
90 /* Pop bytes from the 16-bit stack of a thread */
91 static inline void stack16_pop( int size )
92 {
93     STACK16FRAME *frame = CURRENT_STACK16;
94     memmove( (char*)frame + size, frame, sizeof(*frame) );
95     NtCurrentTeb()->WOW32Reserved = (char *)NtCurrentTeb()->WOW32Reserved + size;
96 }
97
98 #endif /* __WINE_STACKFRAME_H */