2 * 16-bit and 32-bit mode stack frame layout
4 * Copyright 1995, 1998 Alexandre Julliard
7 #ifndef __WINE_STACKFRAME_H
8 #define __WINE_STACKFRAME_H
16 /* 32-bit stack layout after CallTo16() */
17 typedef struct _STACK32FRAME
19 SEGPTR frame16
; /* 00 16-bit frame from last CallFrom16() */
20 DWORD restore_addr
; /* 04 return address for restoring code selector */
21 DWORD codeselector
; /* 08 code selector to restore */
22 DWORD edi
; /* 0c saved registers */
27 DWORD ebp
; /* 20 saved 32-bit frame pointer */
28 DWORD relay
; /* 24 return address to relay stub */
29 DWORD retaddr
; /* 28 actual return address */
30 DWORD args
[1]; /* 2c arguments to 16-bit function */
33 /* 16-bit stack layout after CallFrom16() */
36 STACK32FRAME
*frame32
; /* 00 32-bit frame from last CallTo16() */
37 DWORD edx
; /* 04 saved registers */
44 DWORD relay
; /* 18 address of argument relay stub */
45 DWORD entry_ip
; /* 1c ip of entry point */
46 DWORD entry_cs
; /* 20 cs of entry point */
47 DWORD entry_point
; /* 24 API entry point to call, reused as mutex count */
48 WORD bp
; /* 28 16-bit stack frame chain */
49 WORD ip
; /* 2a return address */
55 #define THREAD_STACK16(teb) ((STACK16FRAME*)PTR_SEG_TO_LIN((teb)->cur_stack))
56 #define CURRENT_STACK16 (THREAD_STACK16(NtCurrentTeb()))
57 #define CURRENT_DS (CURRENT_STACK16->ds)
59 /* varargs lists on the 16-bit stack */
61 typedef void *VA_LIST16
;
63 #define __VA_ROUNDED16(type) \
64 ((sizeof(type) + sizeof(WORD) - 1) / sizeof(WORD) * sizeof(WORD))
65 #define VA_START16(list) ((list) = (VA_LIST16)(CURRENT_STACK16 + 1))
66 #define VA_ARG16(list,type) \
67 (((list) = (VA_LIST16)((char *)(list) + __VA_ROUNDED16(type))), \
68 *((type *)(void *)((char *)(list) - __VA_ROUNDED16(type))))
69 #define VA_END16(list) ((void)0)
72 /* Push bytes on the 16-bit stack of a thread;
73 * return a segptr to the first pushed byte
75 static inline SEGPTR WINE_UNUSED
stack16_push( int size
)
77 TEB
*teb
= NtCurrentTeb();
78 STACK16FRAME
*frame
= THREAD_STACK16(teb
);
79 memmove( (char*)frame
- size
, frame
, sizeof(*frame
) );
80 teb
->cur_stack
-= size
;
81 return (SEGPTR
)(teb
->cur_stack
+ sizeof(*frame
));
84 /* Pop bytes from the 16-bit stack of a thread */
85 static inline void WINE_UNUSED
stack16_pop( int size
)
87 TEB
*teb
= NtCurrentTeb();
88 STACK16FRAME
*frame
= THREAD_STACK16(teb
);
89 memmove( (char*)frame
+ size
, frame
, sizeof(*frame
) );
90 teb
->cur_stack
+= size
;
94 /* Push a DWORD on the 32-bit stack */
95 static inline void WINE_UNUSED
stack32_push( CONTEXT
*context
, DWORD val
)
97 ESP_reg(context
) -= sizeof(DWORD
);
98 *(DWORD
*)ESP_reg(context
) = val
;
101 /* Pop a DWORD from the 32-bit stack */
102 static inline DWORD WINE_UNUSED
stack32_pop( CONTEXT
*context
)
104 DWORD ret
= *(DWORD
*)ESP_reg(context
);
105 ESP_reg(context
) += sizeof(DWORD
);
108 #endif /* __i386__ */
110 /* Win32 register functions */
111 #define REGS_FUNC(name) __regs_##name
113 #endif /* __WINE_STACKFRAME_H */