Added some RPC definitions.
[wine] / include / stackframe.h
1 /*
2  * 16-bit and 32-bit mode stack frame layout
3  *
4  * Copyright 1995, 1998 Alexandre Julliard
5  */
6
7 #ifndef __WINE_STACKFRAME_H
8 #define __WINE_STACKFRAME_H
9
10 #include <string.h>
11
12 #include "thread.h"
13 #include "winnt.h"
14 #include "wine/winbase16.h"
15
16 #include "pshpack1.h"
17
18   /* 32-bit stack layout after CallTo16() */
19 typedef struct _STACK32FRAME
20 {
21     SEGPTR  frame16;        /* 00 16-bit frame from last CallFrom16() */
22     DWORD   restore_addr;   /* 04 return address for restoring code selector */
23     DWORD   codeselector;   /* 08 code selector to restore */
24     DWORD   edi;            /* 0c saved registers */
25     DWORD   esi;            /* 10 */
26     DWORD   edx;            /* 14 */
27     DWORD   ecx;            /* 18 */
28     DWORD   ebx;            /* 1c */
29     DWORD   ebp;            /* 20 saved 32-bit frame pointer */
30     DWORD   retaddr;        /* 24 return address */
31     DWORD   target;         /* 28 target address / CONTEXT86 pointer */
32     DWORD   nb_args;        /* 2c number of 16-bit argument bytes */
33 } STACK32FRAME;
34
35   /* 16-bit stack layout after CallFrom16() */
36 typedef struct _STACK16FRAME
37 {
38     STACK32FRAME *frame32;        /* 00 32-bit frame from last CallTo16() */
39     DWORD         edx;            /* 04 saved registers */
40     DWORD         ecx;            /* 08 */
41     DWORD         ebp;            /* 0c */
42     WORD          ds;             /* 10 */
43     WORD          es;             /* 12 */
44     WORD          fs;             /* 14 */
45     WORD          gs;             /* 16 */
46     DWORD         callfrom_ip;    /* 18 callfrom tail IP */
47     DWORD         module_cs;      /* 1c module code segment */
48     DWORD         relay;          /* 20 relay function address */
49     WORD          entry_ip;       /* 22 entry point IP */
50     DWORD         entry_point;    /* 26 API entry point to call, reused as mutex count */
51     WORD          bp;             /* 2a 16-bit stack frame chain */
52     WORD          ip;             /* 2c return address */
53     WORD          cs;             /* 2e */
54 } STACK16FRAME;
55
56 #include "poppack.h"
57
58 #define THREAD_STACK16(teb)  ((STACK16FRAME*)MapSL((teb)->cur_stack))
59 #define CURRENT_STACK16      (THREAD_STACK16(NtCurrentTeb()))
60 #define CURRENT_DS           (CURRENT_STACK16->ds)
61
62 /* varargs lists on the 16-bit stack */
63
64 typedef void *VA_LIST16;
65
66 #define __VA_ROUNDED16(type) \
67     ((sizeof(type) + sizeof(WORD) - 1) / sizeof(WORD) * sizeof(WORD))
68 #define VA_START16(list) ((list) = (VA_LIST16)(CURRENT_STACK16 + 1))
69 #define VA_ARG16(list,type) \
70     (((list) = (VA_LIST16)((char *)(list) + __VA_ROUNDED16(type))), \
71      *((type *)(void *)((char *)(list) - __VA_ROUNDED16(type))))
72 #define VA_END16(list) ((void)0)
73
74
75 /* Push bytes on the 16-bit stack of a thread;
76  * return a segptr to the first pushed byte
77  */
78 static inline SEGPTR WINE_UNUSED stack16_push( int size )
79 {
80     TEB *teb = NtCurrentTeb();
81     STACK16FRAME *frame = THREAD_STACK16(teb);
82     memmove( (char*)frame - size, frame, sizeof(*frame) );
83     teb->cur_stack -= size;
84     return (SEGPTR)(teb->cur_stack + sizeof(*frame));
85 }
86
87 /* Pop bytes from the 16-bit stack of a thread */
88 static inline void WINE_UNUSED stack16_pop( int size )
89 {
90     TEB *teb = NtCurrentTeb();
91     STACK16FRAME *frame = THREAD_STACK16(teb);
92     memmove( (char*)frame + size, frame, sizeof(*frame) );
93     teb->cur_stack += size;
94 }
95
96 /* Push a DWORD on the 32-bit stack */
97 static inline void WINE_UNUSED stack32_push( CONTEXT86 *context, DWORD val )
98 {
99     context->Esp -= sizeof(DWORD);
100     *(DWORD *)context->Esp = val;
101 }
102
103 /* Pop a DWORD from the 32-bit stack */
104 static inline DWORD WINE_UNUSED stack32_pop( CONTEXT86 *context )
105 {
106     DWORD ret = *(DWORD *)context->Esp;
107     context->Esp += sizeof(DWORD);
108     return ret;
109 }
110
111 #endif /* __WINE_STACKFRAME_H */