source: trunk/src/kernel32/THUNK.C@ 20

Last change on this file since 20 was 17, checked in by phaller, 26 years ago

Code cleanup #1 for build, mainly addresses linkage problems

File size: 6.0 KB
Line 
1/* $Id: THUNK.C,v 1.2 1999-05-31 22:08:09 phaller Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 */
8/*
9 * Win32 thunking API functions (mostly stubs)
10 *
11 * Copyright 1998 Patrick Haller (stubs + Wine port) (?)
12 *
13 * Original WINE code (win32\kernel32.c)
14 *
15 * KERNEL32 thunks and other undocumented stuff
16 *
17 * Copyright 1997-1998 Marcus Meissner
18 * Copyright 1998 Ulrich Weigand
19 */
20#include <os2win.h>
21#include <string.h>
22#include <builtin.h>
23#include "thunk.h"
24#include "misc.h"
25
26//******************************************************************************
27//******************************************************************************
28DWORD WIN32API MapLS(void *address)
29{
30// _interrupt(3);
31 dprintf(("MapLS %X, not supported\n", address));
32 return((DWORD)address);
33}
34//******************************************************************************
35//******************************************************************************
36DWORD WIN32API ThunkProc(DWORD arg1)
37{
38 dprintf(("ThunkProc - stub\n"));
39 return(0);
40}
41//******************************************************************************
42//******************************************************************************
43void WIN32API FT_Prolog(CONTEXT *context)
44{
45 dprintf(("FT_Prolog - stub\n"));
46}
47//******************************************************************************
48//******************************************************************************
49/**********************************************************************
50 * QT_Thunk (KERNEL32)
51 *
52 * The target address is in EDX.
53 * The 16 bit arguments start at ESP+4.
54 * The number of 16bit argumentbytes is EBP-ESP-0x44 (68 Byte thunksetup).
55 * [ok]
56 */
57VOID WIN32API QT_Thunk(CONTEXT *context)
58{
59 dprintf(("QT_Thunk\n"));
60#if 0
61 CONTEXT context16;
62 DWORD argsize;
63
64 memcpy(&context16,context,sizeof(context16));
65
66 CS_reg(&context16) = HIWORD(EDX_reg(context));
67 IP_reg(&context16) = LOWORD(EDX_reg(context));
68
69 argsize = EBP_reg(context)-ESP_reg(context)-0x44;
70
71 /* additional 4 bytes used by the relaycode for storing the stackptr */
72 memcpy( ((LPBYTE)CURRENT_STACK16)-argsize-4,
73 (LPBYTE)ESP_reg(context)+4,
74 argsize
75 );
76 EAX_reg(context) = CallTo16_regs_short(&context16,-argsize);
77#endif
78}
79//******************************************************************************
80/***********************************************************************
81 * Generates a FT_Prolog call.
82 *
83 * 0FB6D1 movzbl edx,cl
84 * 8B1495xxxxxxxx mov edx,[4*edx + xxxxxxxx]
85 * 68xxxxxxxx push FT_Prolog
86 * C3 lret
87 */
88static void _write_ftprolog(LPBYTE thunk,DWORD thunkstart)
89{
90 LPBYTE x;
91
92 x = thunk;
93 *x++ = 0x0f;*x++=0xb6;*x++=0xd1; /* movzbl edx,cl */
94 *x++ = 0x8B;*x++=0x14;*x++=0x95;*(DWORD*)x= thunkstart;
95 x+=4; /* mov edx, [4*edx + thunkstart] */
96 *x++ = 0x68; *(DWORD*)x = (DWORD)FT_Prolog;
97 x+=4; /* push FT_Prolog */
98 *x++ = 0xC3; /* lret */
99 /* fill rest with 0xCC / int 3 */
100}
101//******************************************************************************
102/***********************************************************************
103 * Generates a QT_Thunk style call.
104 *
105 * 33C9 xor ecx, ecx
106 * 8A4DFC mov cl , [ebp-04]
107 * 8B148Dxxxxxxxx mov edx, [4*ecx + (EAX+EDX)]
108 * B8yyyyyyyy mov eax, QT_Thunk
109 * FFE0 jmp eax
110 */
111static void _write_qtthunk(LPBYTE start,DWORD thunkstart)
112{
113 LPBYTE x;
114
115 x = start;
116 *x++ = 0x33;*x++=0xC9; /* xor ecx,ecx */
117 *x++ = 0x8A;*x++=0x4D;*x++=0xFC; /* movb cl,[ebp-04] */
118 *x++ = 0x8B;*x++=0x14;*x++=0x8D;*(DWORD*)x= thunkstart;
119 x+=4; /* mov edx, [4*ecx + (EAX+EDX) */
120 *x++ = 0xB8; *(DWORD*)x = (DWORD)QT_Thunk;
121 x+=4; /* mov eax , QT_Thunk */
122 *x++ = 0xFF; *x++ = 0xE0; /* jmp eax */
123 /* should fill the rest of the 32 bytes with 0xCC */
124}
125
126//******************************************************************************
127//******************************************************************************
128DWORD WIN32API ThunkConnect32(thunkstruct *ths, LPSTR thunkfun16,
129 LPSTR module16, LPSTR module32, HMODULE hmod32,
130 DWORD dllinitarg1 )
131{
132 thunkstruct *ths16;
133
134// _interrupt(3);
135 dprintf(("ThunkConnect32 %s %s %s not supported\n", thunkfun16, module16, module32));
136
137 if(strncmp(ths->magic,"SL01",4) && strncmp(ths->magic,"LS01",4))
138 return 0;
139
140 ths16 = (thunkstruct *)LocalAlloc(LPTR, ths->length);
141 ths16->length = ths->length;
142 ths16->ptr = (DWORD)ThunkProc;
143
144 if(!strncmp(ths->magic,"SL01",4)) {
145 ths->x0C = (DWORD)ths16;
146 *(DWORD *)ths16->magic = 0x0000304C;
147 }
148 if(!strncmp(ths->magic,"LS01",4)) {
149 ths->ptr = ths16->ptr;
150 /* code offset for QT_Thunk is at 0x1C... */
151 _write_qtthunk (((LPBYTE)ths) + ths->x1C,ths->ptr);
152
153 /* code offset for FT_Prolog is at 0x20... */
154 _write_ftprolog(((LPBYTE)ths) + ths->x20,ths->ptr);
155 return 1;
156 }
157 return TRUE;
158}
159//******************************************************************************
160//******************************************************************************
161DWORD WIN32API K32Thk1632Prolog(DWORD arg1)
162{
163 dprintf(("OS2K32Thk1632Prolog %X not supported\n", arg1));
164 return(0);
165}
166//******************************************************************************
167//******************************************************************************
168DWORD WIN32API K32Thk1632Epilog(DWORD arg1)
169{
170 dprintf(("K32Thk1632Epilog %X not supported\n", arg1));
171 return(0);
172}
173//******************************************************************************
174//******************************************************************************
175DWORD WIN32API MapSLFix(DWORD arg1)
176{
177 dprintf(("MapSLFix %X not supported\n", arg1));
178 return(0);
179}
180//******************************************************************************
181//******************************************************************************
Note: See TracBrowser for help on using the repository browser.