4 * Copyright 1996, 1997 Alexandre Julliard
5 * Copyright 1998 Ulrich Weigand
17 #include "stackframe.h"
18 #include "selectors.h"
23 #include "flatthunk.h"
26 /* List of the 16-bit callback functions. This list is used */
27 /* by the build program to generate the file if1632/callto16.S */
29 /* ### start build ### */
30 extern LONG CALLBACK
CallTo16_sreg_(const CONTEXT
*context
, INT32 offset
);
31 extern LONG CALLBACK
CallTo16_lreg_(const CONTEXT
*context
, INT32 offset
);
32 extern WORD CALLBACK
CallTo16_word_ (FARPROC16
);
33 extern LONG CALLBACK
CallTo16_long_ (FARPROC16
);
34 extern WORD CALLBACK
CallTo16_word_w (FARPROC16
,WORD
);
35 extern LONG CALLBACK
CallTo16_long_l (FARPROC16
,LONG
);
36 extern WORD CALLBACK
CallTo16_word_ww (FARPROC16
,WORD
,WORD
);
37 extern WORD CALLBACK
CallTo16_word_wl (FARPROC16
,WORD
,LONG
);
38 extern WORD CALLBACK
CallTo16_word_ll (FARPROC16
,LONG
,LONG
);
39 extern LONG CALLBACK
CallTo16_long_ll (FARPROC16
,LONG
,LONG
);
40 extern WORD CALLBACK
CallTo16_word_www (FARPROC16
,WORD
,WORD
,WORD
);
41 extern WORD CALLBACK
CallTo16_word_wwl (FARPROC16
,WORD
,WORD
,LONG
);
42 extern WORD CALLBACK
CallTo16_word_wlw (FARPROC16
,WORD
,LONG
,WORD
);
43 extern LONG CALLBACK
CallTo16_long_wwl (FARPROC16
,WORD
,WORD
,LONG
);
44 extern LONG CALLBACK
CallTo16_long_lll (FARPROC16
,LONG
,LONG
,LONG
);
45 extern WORD CALLBACK
CallTo16_word_llwl (FARPROC16
,LONG
,LONG
,WORD
,LONG
);
46 extern WORD CALLBACK
CallTo16_word_lwll (FARPROC16
,LONG
,WORD
,LONG
,LONG
);
47 extern WORD CALLBACK
CallTo16_word_lwww (FARPROC16
,LONG
,WORD
,WORD
,WORD
);
48 extern WORD CALLBACK
CallTo16_word_wwll (FARPROC16
,WORD
,WORD
,LONG
,LONG
);
49 extern WORD CALLBACK
CallTo16_word_llll (FARPROC16
,LONG
,LONG
,LONG
,LONG
);
50 extern LONG CALLBACK
CallTo16_long_llll (FARPROC16
,LONG
,LONG
,LONG
,LONG
);
51 extern WORD CALLBACK
CallTo16_word_wllwl(FARPROC16
,WORD
,LONG
,LONG
,WORD
,LONG
);
52 extern LONG CALLBACK
CallTo16_long_lwwll(FARPROC16
,LONG
,WORD
,WORD
,LONG
,LONG
);
53 extern WORD CALLBACK
CallTo16_word_wwlll(FARPROC16
,WORD
,WORD
,LONG
,LONG
,LONG
);
54 extern WORD CALLBACK
CallTo16_word_wwwww(FARPROC16
,WORD
,WORD
,WORD
,WORD
,WORD
);
55 extern WORD CALLBACK
CallTo16_word_lwlll(FARPROC16
,LONG
,WORD
,LONG
,LONG
,LONG
);
56 extern LONG CALLBACK
CallTo16_long_lwlll(FARPROC16
,LONG
,WORD
,LONG
,LONG
,LONG
);
57 extern LONG CALLBACK
CallTo16_long_lllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,LONG
);
58 extern LONG CALLBACK
CallTo16_long_llllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,LONG
,
60 extern LONG CALLBACK
CallTo16_long_lllllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,LONG
,
62 extern WORD CALLBACK
CallTo16_word_llwwlll(FARPROC16
,LONG
,LONG
,WORD
,WORD
,LONG
,
64 extern LONG CALLBACK
CallTo16_word_lwwlllll(FARPROC16
,LONG
,WORD
,WORD
,LONG
,LONG
,
66 extern LONG CALLBACK
CallTo16_long_llllllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,LONG
,
68 extern LONG CALLBACK
CallTo16_long_lllllllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,
69 LONG
,LONG
,LONG
,LONG
,LONG
);
70 extern LONG CALLBACK
CallTo16_long_llllllllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,
71 LONG
,LONG
,LONG
,LONG
,LONG
,LONG
);
72 extern LONG CALLBACK
CallTo16_long_lllllllllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,
73 LONG
,LONG
,LONG
,LONG
,LONG
,LONG
,
75 extern LONG CALLBACK
CallTo16_long_llllllllllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,
76 LONG
,LONG
,LONG
,LONG
,LONG
,LONG
,
78 extern LONG CALLBACK
CallTo16_long_lwwllwlllllw(FARPROC16
,LONG
,WORD
,WORD
,LONG
,
79 LONG
,WORD
,LONG
,LONG
,LONG
,LONG
,
81 extern LONG CALLBACK
CallTo16_long_lllllllllllll(FARPROC16
,LONG
,LONG
,LONG
,LONG
,
82 LONG
,LONG
,LONG
,LONG
,LONG
,LONG
,
84 extern LONG CALLBACK
CallTo16_long_llllllllllllll(FARPROC16
,LONG
,LONG
,LONG
,
85 LONG
,LONG
,LONG
,LONG
,LONG
,
86 LONG
,LONG
,LONG
,LONG
,LONG
,
88 extern LONG CALLBACK
CallTo16_word_lwwwwlwwwwllll(FARPROC16
,LONG
,WORD
,WORD
,
89 WORD
,WORD
,LONG
,WORD
,WORD
,
90 WORD
,WORD
,LONG
,LONG
,LONG
,
92 extern LONG CALLBACK
CallTo16_long_lllllllllllllll(FARPROC16
,LONG
,LONG
,LONG
,
93 LONG
,LONG
,LONG
,LONG
,LONG
,
94 LONG
,LONG
,LONG
,LONG
,LONG
,
96 extern LONG CALLBACK
CallTo16_long_llllllllllllllll(FARPROC16
,LONG
,LONG
,LONG
,
97 LONG
,LONG
,LONG
,LONG
,LONG
,
98 LONG
,LONG
,LONG
,LONG
,LONG
,
100 /* ### stop build ### */
103 typedef void (*RELAY
)();
107 typedef struct tagTHUNK
109 BYTE popl_eax
; /* 0x58 popl %eax (return address)*/
110 BYTE pushl_func
; /* 0x68 pushl $proc */
111 FARPROC32 proc WINE_PACKED
;
112 BYTE pushl_eax
; /* 0x50 pushl %eax */
113 BYTE jmp
; /* 0xe9 jmp relay (relative jump)*/
114 RELAY relay WINE_PACKED
;
115 struct tagTHUNK
*next WINE_PACKED
;
120 #define DECL_THUNK(name,proc,relay) \
121 THUNK name = { 0x58, 0x68, (FARPROC32)(proc), 0x50, 0xe9, \
122 (RELAY)((char *)(relay) - (char *)(&(name).next)), NULL }
125 static THUNK
*firstThunk
= NULL
;
127 static LRESULT WINAPI
THUNK_CallWndProc16( WNDPROC16 proc
, HWND16 hwnd
,
128 UINT16 msg
, WPARAM16 wParam
,
130 static void WINAPI
THUNK_CallTaskReschedule(void);
131 static BOOL32 WINAPI
THUNK_WOWCallback16Ex( FARPROC16
,DWORD
,DWORD
,
134 /* TASK_Reschedule() 16-bit entry point */
135 static FARPROC16 TASK_RescheduleProc
;
137 static BOOL32
THUNK_ThunkletInit( void );
139 extern void CallFrom16_p_long_wwwll(void);
141 /* Callbacks function table for the emulator */
142 static const CALLBACKS_TABLE CALLBACK_EmulatorTable
=
144 (void *)CallTo16_sreg_
, /* CallRegisterShortProc */
145 (void *)CallTo16_lreg_
, /* CallRegisterLongProc */
146 THUNK_CallTaskReschedule
, /* CallTaskRescheduleProc */
147 CallFrom16_p_long_wwwll
, /* CallFrom16WndProc */
148 THUNK_CallWndProc16
, /* CallWndProc */
149 (void *)CallTo16_long_lwwll
, /* CallDriverProc */
150 (void *)CallTo16_word_wwlll
, /* CallDriverCallback */
151 (void *)CallTo16_word_wwlll
, /* CallTimeFuncProc */
152 (void *)CallTo16_word_w
, /* CallWindowsExitProc */
153 (void *)CallTo16_word_lwww
, /* CallWordBreakProc */
154 (void *)CallTo16_word_ww
, /* CallBootAppProc */
155 (void *)CallTo16_word_www
, /* CallLoadAppSegProc */
156 (void *)CallTo16_word_
, /* CallSystemTimerProc */
157 (void *)CallTo16_word_www
, /* CallResourceHandlerProc */
158 (void *)CallTo16_long_l
, /* CallWOWCallbackProc */
159 THUNK_WOWCallback16Ex
, /* CallWOWCallback16Ex */
160 (void *)CallTo16_long_l
, /* CallASPIPostProc */
161 (void *)CallTo16_word_lwll
, /* CallDrvControlProc */
162 (void *)CallTo16_word_lwlll
, /* CallDrvEnableProc */
163 (void *)CallTo16_word_llll
, /* CallDrvEnumDFontsProc */
164 (void *)CallTo16_word_lwll
, /* CallDrvEnumObjProc */
165 (void *)CallTo16_word_lwwlllll
, /* CallDrvOutputProc */
166 (void *)CallTo16_long_lwlll
, /* CallDrvRealizeProc */
167 (void *)CallTo16_word_lwwwwlwwwwllll
, /* CallDrvStretchBltProc */
168 (void *)CallTo16_long_lwwllwlllllw
, /* CallDrvExtTextOutProc */
169 (void *)CallTo16_word_llwwlll
/* CallDrvGetCharWidth */
173 /***********************************************************************
176 BOOL32
THUNK_Init(void)
178 /* Set the window proc calling functions */
179 Callbacks
= &CALLBACK_EmulatorTable
;
180 /* Get the 16-bit reschedule function pointer */
181 TASK_RescheduleProc
= MODULE_GetWndProcEntry16( "TASK_Reschedule" );
182 /* Initialize Thunklets */
183 return THUNK_ThunkletInit();
186 /***********************************************************************
189 static THUNK
*THUNK_Alloc( FARPROC32 func
, RELAY relay
)
191 THUNK
*thunk
= HeapAlloc( GetProcessHeap(), 0, sizeof(*thunk
) );
194 thunk
->popl_eax
= 0x58;
195 thunk
->pushl_func
= 0x68;
197 thunk
->pushl_eax
= 0x50;
199 thunk
->relay
= (RELAY
)((char *)relay
- (char *)(&thunk
->next
));
200 thunk
->next
= firstThunk
;
207 /***********************************************************************
210 static THUNK
*THUNK_Find( FARPROC32 func
)
212 THUNK
*thunk
= firstThunk
;
213 while (thunk
&& (thunk
->proc
!= func
)) thunk
= thunk
->next
;
218 /***********************************************************************
221 static void THUNK_Free( THUNK
*thunk
)
223 if (HEAP_IsInsideHeap( GetProcessHeap(), 0, thunk
))
225 THUNK
**prev
= &firstThunk
;
226 while (*prev
&& (*prev
!= thunk
)) prev
= &(*prev
)->next
;
230 HeapFree( GetProcessHeap(), 0, thunk
);
234 ERR(thunk
, "invalid thunk addr %p\n", thunk
);
238 /***********************************************************************
239 * THUNK_CallWndProc16
241 * Call a 16-bit window procedure
243 static LRESULT WINAPI
THUNK_CallWndProc16( WNDPROC16 proc
, HWND16 hwnd
,
244 UINT16 msg
, WPARAM16 wParam
,
250 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
252 THDB
*thdb
= THREAD_Current();
254 /* Window procedures want ax = hInstance, ds = es = ss */
256 memset(&context
, '\0', sizeof(context
));
257 DS_reg(&context
) = SELECTOROF(thdb
->cur_stack
);
258 ES_reg(&context
) = DS_reg(&context
);
259 EAX_reg(&context
) = wndPtr
? wndPtr
->hInstance
: DS_reg(&context
);
260 CS_reg(&context
) = SELECTOROF(proc
);
261 EIP_reg(&context
) = OFFSETOF(proc
);
262 EBP_reg(&context
) = OFFSETOF(thdb
->cur_stack
)
263 + (WORD
)&((STACK16FRAME
*)0)->bp
;
267 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
268 work if structures passed in lParam are placed in the stack/data
269 segment. Programmers easily make the mistake of converting lParam
270 to a near rather than a far pointer, since Windows apparently
271 allows this. We copy the structures to the 16 bit stack; this is
272 ugly but makes these programs work. */
277 offset
= sizeof(CREATESTRUCT16
); break;
279 offset
= sizeof(DRAWITEMSTRUCT16
); break;
281 offset
= sizeof(COMPAREITEMSTRUCT16
); break;
285 void *s
= PTR_SEG_TO_LIN(lParam
);
286 lParam
= STACK16_PUSH( thdb
, offset
);
287 memcpy( PTR_SEG_TO_LIN(lParam
), s
, offset
);
291 args
= (WORD
*)THREAD_STACK16(thdb
) - 5;
292 args
[0] = LOWORD(lParam
);
293 args
[1] = HIWORD(lParam
);
298 ret
= CallTo16_sreg_( &context
, 5 * sizeof(WORD
) );
299 if (offset
) STACK16_POP( thdb
, offset
);
304 /***********************************************************************
305 * THUNK_CallTaskReschedule
307 static void WINAPI
THUNK_CallTaskReschedule(void)
309 CallTo16_word_(TASK_RescheduleProc
);
313 /***********************************************************************
314 * THUNK_EnumObjects16 (GDI.71)
316 INT16 WINAPI
THUNK_EnumObjects16( HDC16 hdc
, INT16 nObjType
,
317 GOBJENUMPROC16 func
, LPARAM lParam
)
319 DECL_THUNK( thunk
, func
, CallTo16_word_ll
);
320 return EnumObjects16( hdc
, nObjType
, (GOBJENUMPROC16
)&thunk
, lParam
);
324 /*************************************************************************
325 * THUNK_EnumFonts16 (GDI.70)
327 INT16 WINAPI
THUNK_EnumFonts16( HDC16 hdc
, LPCSTR lpFaceName
,
328 FONTENUMPROC16 func
, LPARAM lParam
)
330 DECL_THUNK( thunk
, func
, CallTo16_word_llwl
);
331 return EnumFonts16( hdc
, lpFaceName
, (FONTENUMPROC16
)&thunk
, lParam
);
334 /******************************************************************
335 * THUNK_EnumMetaFile16 (GDI.175)
337 BOOL16 WINAPI
THUNK_EnumMetaFile16( HDC16 hdc
, HMETAFILE16 hmf
,
338 MFENUMPROC16 func
, LPARAM lParam
)
340 DECL_THUNK( thunk
, func
, CallTo16_word_wllwl
);
341 return EnumMetaFile16( hdc
, hmf
, (MFENUMPROC16
)&thunk
, lParam
);
345 /*************************************************************************
346 * THUNK_EnumFontFamilies16 (GDI.330)
348 INT16 WINAPI
THUNK_EnumFontFamilies16( HDC16 hdc
, LPCSTR lpszFamily
,
349 FONTENUMPROC16 func
, LPARAM lParam
)
351 DECL_THUNK( thunk
, func
, CallTo16_word_llwl
);
352 return EnumFontFamilies16(hdc
, lpszFamily
, (FONTENUMPROC16
)&thunk
, lParam
);
356 /*************************************************************************
357 * THUNK_EnumFontFamiliesEx16 (GDI.613)
359 INT16 WINAPI
THUNK_EnumFontFamiliesEx16( HDC16 hdc
, LPLOGFONT16 lpLF
,
360 FONTENUMPROCEX16 func
, LPARAM lParam
,
363 DECL_THUNK( thunk
, func
, CallTo16_word_llwl
);
364 return EnumFontFamiliesEx16( hdc
, lpLF
, (FONTENUMPROCEX16
)&thunk
,
369 /**********************************************************************
370 * THUNK_LineDDA16 (GDI.100)
372 void WINAPI
THUNK_LineDDA16( INT16 nXStart
, INT16 nYStart
, INT16 nXEnd
,
373 INT16 nYEnd
, LINEDDAPROC16 func
, LPARAM lParam
)
375 DECL_THUNK( thunk
, func
, CallTo16_word_wwl
);
376 LineDDA16( nXStart
, nYStart
, nXEnd
, nYEnd
, (LINEDDAPROC16
)&thunk
, lParam
);
380 /*******************************************************************
381 * THUNK_EnumWindows16 (USER.54)
383 BOOL16 WINAPI
THUNK_EnumWindows16( WNDENUMPROC16 func
, LPARAM lParam
)
385 DECL_THUNK( thunk
, func
, CallTo16_word_wl
);
386 return EnumWindows16( (WNDENUMPROC16
)&thunk
, lParam
);
390 /**********************************************************************
391 * THUNK_EnumChildWindows16 (USER.55)
393 BOOL16 WINAPI
THUNK_EnumChildWindows16( HWND16 parent
, WNDENUMPROC16 func
,
396 DECL_THUNK( thunk
, func
, CallTo16_word_wl
);
397 return EnumChildWindows16( parent
, (WNDENUMPROC16
)&thunk
, lParam
);
401 /**********************************************************************
402 * THUNK_EnumTaskWindows16 (USER.225)
404 BOOL16 WINAPI
THUNK_EnumTaskWindows16( HTASK16 hTask
, WNDENUMPROC16 func
,
407 DECL_THUNK( thunk
, func
, CallTo16_word_wl
);
408 return EnumTaskWindows16( hTask
, (WNDENUMPROC16
)&thunk
, lParam
);
412 /***********************************************************************
413 * THUNK_EnumProps16 (USER.27)
415 INT16 WINAPI
THUNK_EnumProps16( HWND16 hwnd
, PROPENUMPROC16 func
)
417 DECL_THUNK( thunk
, func
, CallTo16_word_wlw
);
418 return EnumProps16( hwnd
, (PROPENUMPROC16
)&thunk
);
422 /***********************************************************************
423 * THUNK_GrayString16 (USER.185)
425 BOOL16 WINAPI
THUNK_GrayString16( HDC16 hdc
, HBRUSH16 hbr
,
426 GRAYSTRINGPROC16 func
, LPARAM lParam
,
427 INT16 cch
, INT16 x
, INT16 y
,
430 DECL_THUNK( thunk
, func
, CallTo16_word_wlw
);
432 return GrayString16( hdc
, hbr
, NULL
, lParam
, cch
, x
, y
, cx
, cy
);
434 return GrayString16( hdc
, hbr
, (GRAYSTRINGPROC16
)&thunk
, lParam
, cch
,
439 /***********************************************************************
440 * THUNK_SetWindowsHook16 (USER.121)
442 FARPROC16 WINAPI
THUNK_SetWindowsHook16( INT16 id
, HOOKPROC16 proc
)
444 HINSTANCE16 hInst
= FarGetOwner( HIWORD(proc
) );
445 HTASK16 hTask
= (id
== WH_MSGFILTER
) ? GetCurrentTask() : 0;
446 THUNK
*thunk
= THUNK_Alloc( (FARPROC16
)proc
, (RELAY
)CallTo16_long_wwl
);
447 if (!thunk
) return 0;
448 return (FARPROC16
)SetWindowsHookEx16( id
, (HOOKPROC16
)thunk
, hInst
, hTask
);
452 /***********************************************************************
453 * THUNK_UnhookWindowsHook16 (USER.234)
455 BOOL16 WINAPI
THUNK_UnhookWindowsHook16( INT16 id
, HOOKPROC16 proc
)
458 THUNK
*thunk
= THUNK_Find( (FARPROC16
)proc
);
459 if (!thunk
) return FALSE
;
460 ret
= UnhookWindowsHook16( id
, (HOOKPROC16
)thunk
);
466 /***********************************************************************
467 * THUNK_SetWindowsHookEx16 (USER.291)
469 HHOOK WINAPI
THUNK_SetWindowsHookEx16( INT16 id
, HOOKPROC16 proc
,
470 HINSTANCE16 hInst
, HTASK16 hTask
)
472 THUNK
*thunk
= THUNK_Alloc( (FARPROC16
)proc
, (RELAY
)CallTo16_long_wwl
);
473 if (!thunk
) return 0;
474 return SetWindowsHookEx16( id
, (HOOKPROC16
)thunk
, hInst
, hTask
);
478 /***********************************************************************
479 * THUNK_UnhookWindowHookEx16 (USER.292)
481 BOOL16 WINAPI
THUNK_UnhookWindowsHookEx16( HHOOK hhook
)
483 THUNK
*thunk
= (THUNK
*)HOOK_GetProc16( hhook
);
484 BOOL16 ret
= UnhookWindowsHookEx16( hhook
);
485 if (thunk
) THUNK_Free( thunk
);
491 static FARPROC16 defDCHookProc
= NULL
;
493 /***********************************************************************
494 * THUNK_SetDCHook (GDI.190)
496 BOOL16 WINAPI
THUNK_SetDCHook( HDC16 hdc
, FARPROC16 proc
, DWORD dwHookData
)
498 THUNK
*thunk
, *oldThunk
;
500 if (!defDCHookProc
) /* Get DCHook Win16 entry point */
501 defDCHookProc
= NE_GetEntryPoint( GetModuleHandle16("USER"), 362 );
503 if (proc
!= defDCHookProc
)
505 thunk
= THUNK_Alloc( proc
, (RELAY
)CallTo16_word_wwll
);
506 if (!thunk
) return FALSE
;
508 else thunk
= (THUNK
*)DCHook
;
510 /* Free the previous thunk */
511 GetDCHook( hdc
, (FARPROC16
*)&oldThunk
);
512 if (oldThunk
&& (oldThunk
!= (THUNK
*)DCHook
)) THUNK_Free( oldThunk
);
514 return SetDCHook( hdc
, (FARPROC16
)thunk
, dwHookData
);
518 /***********************************************************************
519 * THUNK_GetDCHook (GDI.191)
521 DWORD WINAPI
THUNK_GetDCHook( HDC16 hdc
, FARPROC16
*phookProc
)
524 DWORD ret
= GetDCHook( hdc
, (FARPROC16
*)&thunk
);
527 if (thunk
== (THUNK
*)DCHook
)
529 if (!defDCHookProc
) /* Get DCHook Win16 entry point */
530 defDCHookProc
= NE_GetEntryPoint(GetModuleHandle16("USER"),362);
531 *phookProc
= defDCHookProc
;
533 else *phookProc
= thunk
->proc
;
539 /***********************************************************************
540 * THUNK_SetTaskSignalProc (KERNEL.38)
542 FARPROC16 WINAPI
THUNK_SetTaskSignalProc( HTASK16 hTask
, FARPROC16 proc
)
544 static FARPROC16 defSignalProc16
= NULL
;
548 if( !defSignalProc16
)
549 defSignalProc16
= NE_GetEntryPoint(GetModuleHandle16("USER"), 314 );
551 if( proc
== defSignalProc16
)
552 thunk
= (THUNK
*)SetTaskSignalProc( hTask
, (FARPROC16
)&USER_SignalProc
);
555 thunk
= THUNK_Alloc( proc
, (RELAY
)CallTo16_word_wwwww
);
556 if( !thunk
) return FALSE
;
557 thunk
= (THUNK
*)SetTaskSignalProc( hTask
, (FARPROC16
)thunk
);
560 if( thunk
!= (THUNK
*)USER_SignalProc
)
562 if( !thunk
) return NULL
;
568 return defSignalProc16
;
571 /***********************************************************************
572 * THUNK_CreateThread16 (KERNEL.441)
574 static DWORD CALLBACK
THUNK_StartThread16( LPVOID threadArgs
)
576 FARPROC16 start
= ((FARPROC16
*)threadArgs
)[0];
577 DWORD param
= ((DWORD
*)threadArgs
)[1];
578 HeapFree( GetProcessHeap(), 0, threadArgs
);
580 return CallTo16_long_l( start
, param
);
582 HANDLE32 WINAPI
THUNK_CreateThread16( SECURITY_ATTRIBUTES
*sa
, DWORD stack
,
583 FARPROC16 start
, SEGPTR param
,
584 DWORD flags
, LPDWORD id
)
586 DWORD
*threadArgs
= HeapAlloc( GetProcessHeap(), 0, 2*sizeof(DWORD
) );
587 if (!threadArgs
) return INVALID_HANDLE_VALUE32
;
588 threadArgs
[0] = (DWORD
)start
;
589 threadArgs
[1] = (DWORD
)param
;
591 return CreateThread( sa
, stack
, THUNK_StartThread16
, threadArgs
, flags
, id
);
594 /***********************************************************************
595 * THUNK_WOWCallback16Ex (WOW32.3)(KERNEL32.55)
596 * Generic thunking routine to call 16 bit functions from 32bit code.
599 * TRUE if the call was done
601 static BOOL32 WINAPI
THUNK_WOWCallback16Ex(
602 FARPROC16 proc
, /* [in] 16bit function to call */
603 DWORD dwFlags
, /* [in] flags (WCB_*) */
604 DWORD cbArgs
, /* [in] number of arguments */
605 LPVOID xargs
, /* [in/out] arguments */
606 LPDWORD pdwret
/* [out] return value of the 16bit call */
608 LPDWORD args
= (LPDWORD
)xargs
;
611 TRACE(relay
,"(%p,0x%08lx,%ld,%p,%p)\n",
612 proc
,dwFlags
,cbArgs
,xargs
,pdwret
614 if (dwFlags
== WCB16_CDECL
) {
615 /* swap the arguments */
616 args
= HeapAlloc(GetProcessHeap(),0,cbArgs
*sizeof(DWORD
));
617 for (i
=0;i
<cbArgs
;i
++)
618 args
[i
] = ((DWORD
*)xargs
)[cbArgs
-i
-1];
621 case 0: ret
= CallTo16_long_(proc
);break;
622 case 1: ret
= CallTo16_long_l(proc
,args
[0]);break;
623 case 2: ret
= CallTo16_long_ll(proc
,args
[0],args
[1]);break;
624 case 3: ret
= CallTo16_long_lll(proc
,args
[0],args
[1],args
[2]);break;
625 case 4: ret
= CallTo16_long_llll(proc
,args
[0],args
[1],args
[2],args
[3]);
627 case 5: ret
= CallTo16_long_lllll(proc
,args
[0],args
[1],args
[2],args
[3],
631 case 6: ret
= CallTo16_long_llllll(proc
,args
[0],args
[1],args
[2],args
[3],
635 case 7: ret
= CallTo16_long_lllllll(proc
,args
[0],args
[1],args
[2],args
[3],
636 args
[4],args
[5],args
[6]
639 case 8: ret
= CallTo16_long_llllllll(proc
,args
[0],args
[1],args
[2],args
[3],
640 args
[4],args
[5],args
[6],args
[7]
643 case 9: ret
= CallTo16_long_lllllllll(proc
,args
[0],args
[1],args
[2],args
[3],
644 args
[4],args
[5],args
[6],args
[7],args
[8]
647 case 10:ret
= CallTo16_long_llllllllll(proc
,args
[0],args
[1],args
[2],args
[3],
648 args
[4],args
[5],args
[6],args
[7],args
[8],args
[9]
651 case 11:ret
= CallTo16_long_lllllllllll(proc
,args
[0],args
[1],args
[2],
652 args
[3],args
[4],args
[5],args
[6],args
[7],args
[8],args
[9],args
[10]
655 case 12:ret
= CallTo16_long_llllllllllll(proc
,args
[0],args
[1],args
[2],
656 args
[3],args
[4],args
[5],args
[6],args
[7],args
[8],args
[9],
660 case 13:ret
= CallTo16_long_lllllllllllll(proc
,args
[0],args
[1],args
[2],
661 args
[3],args
[4],args
[5],args
[6],args
[7],args
[8],args
[9],
662 args
[10],args
[11],args
[12]
665 case 14:ret
= CallTo16_long_llllllllllllll(proc
,args
[0],args
[1],args
[2],
666 args
[3],args
[4],args
[5],args
[6],args
[7],args
[8],args
[9],
667 args
[10],args
[11],args
[12],args
[13]
670 case 15:ret
= CallTo16_long_lllllllllllllll(proc
,args
[0],args
[1],args
[2],
671 args
[3],args
[4],args
[5],args
[6],args
[7],args
[8],args
[9],
672 args
[10],args
[11],args
[12],args
[13],args
[14]
675 case 16:ret
= CallTo16_long_llllllllllllllll(proc
,args
[0],args
[1],args
[2],
676 args
[3],args
[4],args
[5],args
[6],args
[7],args
[8],args
[9],
677 args
[10],args
[11],args
[12],args
[13],args
[14],args
[15]
681 ERR(thunk
,"%ld arguments not supported.\n",cbArgs
);
682 if (dwFlags
== WCB16_CDECL
)
683 HeapFree(GetProcessHeap(),0,args
);
686 if (dwFlags
== WCB16_CDECL
)
687 HeapFree(GetProcessHeap(),0,args
);
694 /***********************************************************************
695 * 16->32 Flat Thunk routines:
698 /***********************************************************************
699 * ThunkConnect16 (KERNEL.651)
700 * Connects a 32bit and a 16bit thunkbuffer.
702 UINT32 WINAPI
ThunkConnect16(
703 LPSTR module16
, /* [in] name of win16 dll */
704 LPSTR module32
, /* [in] name of win32 dll */
705 HINSTANCE16 hInst16
, /* [in] hInst of win16 dll */
706 DWORD dwReason
, /* [in] initialisation argument */
707 struct ThunkDataCommon
*TD
, /* [in/out] thunkbuffer */
708 LPSTR thunkfun32
, /* [in] win32 thunkfunction */
709 WORD CS
/* [in] CS of win16 dll */
713 if (!lstrncmp32A(TD
->magic
, "SL01", 4))
717 TRACE(thunk
, "SL01 thunk %s (%lx) -> %s (%s), Reason: %ld\n",
718 module16
, (DWORD
)TD
, module32
, thunkfun32
, dwReason
);
720 else if (!lstrncmp32A(TD
->magic
, "LS01", 4))
724 TRACE(thunk
, "LS01 thunk %s (%lx) <- %s (%s), Reason: %ld\n",
725 module16
, (DWORD
)TD
, module32
, thunkfun32
, dwReason
);
729 ERR(thunk
, "Invalid magic %c%c%c%c\n",
730 TD
->magic
[0], TD
->magic
[1], TD
->magic
[2], TD
->magic
[3]);
736 case DLL_PROCESS_ATTACH
:
739 struct ThunkDataSL16
*SL16
= (struct ThunkDataSL16
*)TD
;
740 struct ThunkDataSL
*SL
= SL16
->fpData
;
744 SL
= HeapAlloc(GetProcessHeap(), 0, sizeof(*SL
));
746 SL
->common
= SL16
->common
;
747 SL
->flags1
= SL16
->flags1
;
748 SL
->flags2
= SL16
->flags2
;
750 SL
->apiDB
= PTR_SEG_TO_LIN(SL16
->apiDatabase
);
753 lstrcpyn32A(SL
->pszDll16
, module16
, 255);
754 lstrcpyn32A(SL
->pszDll32
, module32
, 255);
756 /* We should create a SEGPTR to the ThunkDataSL,
757 but since the contents are not in the original format,
758 any access to this by 16-bit code would crash anyway. */
764 if (SL
->flags2
& 0x80000000)
766 TRACE(thunk
, "Preloading 32-bit library\n");
767 LoadLibrary32A(module32
);
776 case DLL_PROCESS_DETACH
:
785 /***********************************************************************
786 * C16ThkSL (KERNEL.630)
789 void WINAPI
C16ThkSL(CONTEXT
*context
)
791 extern void CallFrom16_t_long_(void);
792 LPBYTE stub
= PTR_SEG_TO_LIN(EAX_reg(context
)), x
= stub
;
797 /* We produce the following code:
802 * mov edx, es:[ecx + $EDX]
805 * call __FLATCS:CallFrom16_t_long_
808 *x
++ = 0xB8; *((WORD
*)x
)++ = ds
;
809 *x
++ = 0x8E; *x
++ = 0xC0;
810 *x
++ = 0x66; *x
++ = 0x0F; *x
++ = 0xB7; *x
++ = 0xC9;
811 *x
++ = 0x67; *x
++ = 0x66; *x
++ = 0x26; *x
++ = 0x8B;
812 *x
++ = 0x91; *((DWORD
*)x
)++ = EDX_reg(context
);
815 *x
++ = 0x66; *x
++ = 0x52;
816 *x
++ = 0x66; *x
++ = 0x9A; *((DWORD
*)x
)++ = (DWORD
)CallFrom16_t_long_
;
819 /* Jump to the stub code just created */
820 IP_reg(context
) = LOWORD(EAX_reg(context
));
821 CS_reg(context
) = HIWORD(EAX_reg(context
));
823 /* Since C16ThkSL got called by a jmp, we need to leave the
824 orginal return address on the stack */
825 SP_reg(context
) -= 4;
828 /***********************************************************************
829 * C16ThkSL01 (KERNEL.631)
832 void WINAPI
C16ThkSL01(CONTEXT
*context
)
834 LPBYTE stub
= PTR_SEG_TO_LIN(EAX_reg(context
)), x
= stub
;
838 struct ThunkDataSL16
*SL16
= PTR_SEG_TO_LIN(EDX_reg(context
));
839 struct ThunkDataSL
*td
= SL16
->fpData
;
841 extern void CallFrom16_t_long_(void);
842 DWORD procAddress
= (DWORD
)GetProcAddress16(GetModuleHandle16("KERNEL"), 631);
848 ERR(thunk
, "ThunkConnect16 was not called!\n");
852 TRACE(thunk
, "Creating stub for ThunkDataSL %08lx\n", (DWORD
)td
);
855 /* We produce the following code:
862 * call __FLATCS:CallFrom16_t_long_
865 *x
++ = 0x66; *x
++ = 0x33; *x
++ = 0xC0;
866 *x
++ = 0x66; *x
++ = 0xBA; *((DWORD
*)x
)++ = (DWORD
)td
;
867 *x
++ = 0x9A; *((DWORD
*)x
)++ = procAddress
;
870 *x
++ = 0x66; *x
++ = 0x52;
871 *x
++ = 0x66; *x
++ = 0x9A; *((DWORD
*)x
)++ = (DWORD
)CallFrom16_t_long_
;
874 /* Jump to the stub code just created */
875 IP_reg(context
) = LOWORD(EAX_reg(context
));
876 CS_reg(context
) = HIWORD(EAX_reg(context
));
878 /* Since C16ThkSL01 got called by a jmp, we need to leave the
879 orginal return address on the stack */
880 SP_reg(context
) -= 4;
884 struct ThunkDataSL
*td
= (struct ThunkDataSL
*)EDX_reg(context
);
885 DWORD targetNr
= CX_reg(context
) / 4;
886 struct SLTargetDB
*tdb
;
888 TRACE(thunk
, "Process %08lx calling target %ld of ThunkDataSL %08lx\n",
889 (DWORD
)PROCESS_Current(), targetNr
, (DWORD
)td
);
891 for (tdb
= td
->targetDB
; tdb
; tdb
= tdb
->next
)
892 if (tdb
->process
== PROCESS_Current())
897 TRACE(thunk
, "Loading 32-bit library %s\n", td
->pszDll32
);
898 LoadLibrary32A(td
->pszDll32
);
900 for (tdb
= td
->targetDB
; tdb
; tdb
= tdb
->next
)
901 if (tdb
->process
== PROCESS_Current())
907 EDX_reg(context
) = tdb
->targetTable
[targetNr
];
909 TRACE(thunk
, "Call target is %08lx\n", EDX_reg(context
));
913 WORD
*stack
= PTR_SEG_OFF_TO_LIN(SS_reg(context
), SP_reg(context
));
914 DX_reg(context
) = HIWORD(td
->apiDB
[targetNr
].errorReturnValue
);
915 AX_reg(context
) = LOWORD(td
->apiDB
[targetNr
].errorReturnValue
);
916 IP_reg(context
) = stack
[2];
917 CS_reg(context
) = stack
[3];
918 SP_reg(context
) += td
->apiDB
[targetNr
].nrArgBytes
+ 4;
920 ERR(thunk
, "Process %08lx did not ThunkConnect32 %s to %s\n",
921 (DWORD
)PROCESS_Current(), td
->pszDll32
, td
->pszDll16
);
927 WOW16Call(WORD x
,WORD y
,WORD z
) {
930 FIXME(thunk
,"(0x%04x,0x%04x,%d),calling (",x
,y
,z
);
932 for (i
=0;i
<x
/2;i
++) {
933 WORD a
= STACK16_POP(THREAD_Current(),2);
936 calladdr
= STACK16_POP(THREAD_Current(),4);
937 DPRINTF(") calling address was 0x%08lx\n",calladdr
);
942 /***********************************************************************
943 * 16<->32 Thunklet/Callback API:
947 typedef struct _THUNKLET
962 struct _THUNKLET
*next
;
966 #define THUNKLET_TYPE_LS 1
967 #define THUNKLET_TYPE_SL 2
969 static HANDLE32 ThunkletHeap
= 0;
970 static THUNKLET
*ThunkletAnchor
= NULL
;
972 static FARPROC32 ThunkletSysthunkGlueLS
= 0;
973 static SEGPTR ThunkletSysthunkGlueSL
= 0;
975 static FARPROC32 ThunkletCallbackGlueLS
= 0;
976 static SEGPTR ThunkletCallbackGlueSL
= 0;
978 /***********************************************************************
981 static BOOL32
THUNK_ThunkletInit( void )
985 ThunkletHeap
= HeapCreate(HEAP_WINE_SEGPTR
| HEAP_WINE_CODE16SEG
, 0, 0);
986 if (!ThunkletHeap
) return FALSE
;
988 thunk
= HeapAlloc( ThunkletHeap
, 0, 5 );
989 if (!thunk
) return FALSE
;
991 ThunkletSysthunkGlueLS
= (FARPROC32
)thunk
;
992 *thunk
++ = 0x58; /* popl eax */
993 *thunk
++ = 0xC3; /* ret */
995 ThunkletSysthunkGlueSL
= HEAP_GetSegptr( ThunkletHeap
, 0, thunk
);
996 *thunk
++ = 0x66; *thunk
++ = 0x58; /* popl eax */
997 *thunk
++ = 0xCB; /* lret */
1002 /***********************************************************************
1003 * SetThunkletCallbackGlue (KERNEL.560)
1005 void WINAPI
SetThunkletCallbackGlue( FARPROC32 glueLS
, SEGPTR glueSL
)
1007 ThunkletCallbackGlueLS
= glueLS
;
1008 ThunkletCallbackGlueSL
= glueSL
;
1012 /***********************************************************************
1013 * THUNK_FindThunklet
1015 THUNKLET
*THUNK_FindThunklet( DWORD target
, DWORD relay
,
1016 DWORD glue
, BYTE type
)
1020 for (thunk
= ThunkletAnchor
; thunk
; thunk
= thunk
->next
)
1021 if ( thunk
->type
== type
1022 && thunk
->target
== target
1023 && thunk
->relay
== relay
1024 && thunk
->glue
== glue
)
1030 /***********************************************************************
1031 * THUNK_AllocLSThunklet
1033 FARPROC32
THUNK_AllocLSThunklet( SEGPTR target
, DWORD relay
,
1034 FARPROC32 glue
, HTASK16 owner
)
1036 THUNKLET
*thunk
= THUNK_FindThunklet( (DWORD
)target
, relay
, (DWORD
)glue
,
1040 TDB
*pTask
= (TDB
*)GlobalLock16( owner
);
1042 if ( !(thunk
= HeapAlloc( ThunkletHeap
, 0, sizeof(THUNKLET
) )) )
1045 thunk
->prefix_target
= thunk
->prefix_relay
= 0x90;
1046 thunk
->pushl_target
= thunk
->pushl_relay
= 0x68;
1047 thunk
->jmp_glue
= 0xE9;
1049 thunk
->target
= (DWORD
)target
;
1050 thunk
->relay
= (DWORD
)relay
;
1051 thunk
->glue
= (DWORD
)glue
- (DWORD
)&thunk
->owner
;
1053 thunk
->type
= THUNKLET_TYPE_LS
;
1054 thunk
->owner
= pTask
? pTask
->hInstance
: 0;
1056 thunk
->next
= ThunkletAnchor
;
1057 ThunkletAnchor
= thunk
;
1060 return (FARPROC32
)thunk
;
1063 /***********************************************************************
1064 * THUNK_AllocSLThunklet
1066 SEGPTR
THUNK_AllocSLThunklet( FARPROC32 target
, DWORD relay
,
1067 SEGPTR glue
, HTASK16 owner
)
1069 THUNKLET
*thunk
= THUNK_FindThunklet( (DWORD
)target
, relay
, (DWORD
)glue
,
1073 TDB
*pTask
= (TDB
*)GlobalLock16( owner
);
1075 if ( !(thunk
= HeapAlloc( ThunkletHeap
, 0, sizeof(THUNKLET
) )) )
1078 thunk
->prefix_target
= thunk
->prefix_relay
= 0x66;
1079 thunk
->pushl_target
= thunk
->pushl_relay
= 0x68;
1080 thunk
->jmp_glue
= 0xEA;
1082 thunk
->target
= (DWORD
)target
;
1083 thunk
->relay
= (DWORD
)relay
;
1084 thunk
->glue
= (DWORD
)glue
;
1086 thunk
->type
= THUNKLET_TYPE_SL
;
1087 thunk
->owner
= pTask
? pTask
->hInstance
: 0;
1089 thunk
->next
= ThunkletAnchor
;
1090 ThunkletAnchor
= thunk
;
1093 return HEAP_GetSegptr( ThunkletHeap
, 0, thunk
);
1096 /**********************************************************************
1099 BOOL16 WINAPI
IsLSThunklet( THUNKLET
*thunk
)
1101 return thunk
->prefix_target
== 0x90 && thunk
->pushl_target
== 0x68
1102 && thunk
->prefix_relay
== 0x90 && thunk
->pushl_relay
== 0x68
1103 && thunk
->jmp_glue
== 0xE9 && thunk
->type
== THUNKLET_TYPE_LS
;
1106 /**********************************************************************
1107 * IsSLThunklet (KERNEL.612)
1109 BOOL16 WINAPI
IsSLThunklet( THUNKLET
*thunk
)
1111 return thunk
->prefix_target
== 0x66 && thunk
->pushl_target
== 0x68
1112 && thunk
->prefix_relay
== 0x66 && thunk
->pushl_relay
== 0x68
1113 && thunk
->jmp_glue
== 0xEA && thunk
->type
== THUNKLET_TYPE_SL
;
1118 /***********************************************************************
1119 * AllocLSThunkletSysthunk (KERNEL.607)
1121 FARPROC32 WINAPI
AllocLSThunkletSysthunk( SEGPTR target
,
1122 FARPROC32 relay
, DWORD dummy
)
1124 return THUNK_AllocLSThunklet( (SEGPTR
)relay
, (DWORD
)target
,
1125 ThunkletSysthunkGlueLS
, GetCurrentTask() );
1128 /***********************************************************************
1129 * AllocSLThunkletSysthunk (KERNEL.608)
1131 SEGPTR WINAPI
AllocSLThunkletSysthunk( FARPROC32 target
,
1132 SEGPTR relay
, DWORD dummy
)
1134 return THUNK_AllocSLThunklet( (FARPROC32
)relay
, (DWORD
)target
,
1135 ThunkletSysthunkGlueSL
, GetCurrentTask() );
1139 /***********************************************************************
1140 * AllocLSThunkletCallbackEx (KERNEL.567)
1142 FARPROC32 WINAPI
AllocLSThunkletCallbackEx( SEGPTR target
,
1143 DWORD relay
, HTASK16 task
)
1145 THUNKLET
*thunk
= (THUNKLET
*)target
;
1146 if ( IsSLThunklet( thunk
) && thunk
->relay
== relay
1147 && thunk
->glue
== (DWORD
)ThunkletCallbackGlueSL
)
1148 return (FARPROC32
)thunk
->target
;
1150 return THUNK_AllocLSThunklet( target
, relay
,
1151 ThunkletCallbackGlueLS
, task
);
1154 /***********************************************************************
1155 * AllocSLThunkletCallbackEx (KERNEL.568)
1157 SEGPTR WINAPI
AllocSLThunkletCallbackEx( FARPROC32 target
,
1158 DWORD relay
, HTASK16 task
)
1160 THUNKLET
*thunk
= (THUNKLET
*)target
;
1161 if ( IsLSThunklet( thunk
) && thunk
->relay
== relay
1162 && thunk
->glue
== (DWORD
)ThunkletCallbackGlueLS
)
1163 return (SEGPTR
)thunk
->target
;
1165 return THUNK_AllocSLThunklet( target
, relay
,
1166 ThunkletCallbackGlueSL
, task
);
1169 /***********************************************************************
1170 * AllocLSThunkletCallback (KERNEL.561) (KERNEL.606)
1172 FARPROC32 WINAPI
AllocLSThunkletCallback( SEGPTR target
, DWORD relay
)
1174 return AllocLSThunkletCallbackEx( target
, relay
, GetCurrentTask() );
1177 /***********************************************************************
1178 * AllocSLThunkletCallback (KERNEL.562) (KERNEL.605)
1180 SEGPTR WINAPI
AllocSLThunkletCallback( FARPROC32 target
, DWORD relay
)
1182 return AllocSLThunkletCallbackEx( target
, relay
, GetCurrentTask() );
1185 /***********************************************************************
1186 * FindLSThunkletCallback (KERNEL.563) (KERNEL.609)
1188 FARPROC32 WINAPI
FindLSThunkletCallback( SEGPTR target
, DWORD relay
)
1190 THUNKLET
*thunk
= (THUNKLET
*)PTR_SEG_TO_LIN( target
);
1191 if ( thunk
&& IsSLThunklet( thunk
) && thunk
->relay
== relay
1192 && thunk
->glue
== (DWORD
)ThunkletCallbackGlueSL
)
1193 return (FARPROC32
)thunk
->target
;
1195 thunk
= THUNK_FindThunklet( (DWORD
)target
, relay
,
1196 (DWORD
)ThunkletCallbackGlueLS
,
1198 return (FARPROC32
)thunk
;
1201 /***********************************************************************
1202 * FindSLThunkletCallback (KERNEL.564) (KERNEL.610)
1204 SEGPTR WINAPI
FindSLThunkletCallback( FARPROC32 target
, DWORD relay
)
1206 THUNKLET
*thunk
= (THUNKLET
*)target
;
1207 if ( thunk
&& IsLSThunklet( thunk
) && thunk
->relay
== relay
1208 && thunk
->glue
== (DWORD
)ThunkletCallbackGlueLS
)
1209 return (SEGPTR
)thunk
->target
;
1211 thunk
= THUNK_FindThunklet( (DWORD
)target
, relay
,
1212 (DWORD
)ThunkletCallbackGlueSL
,
1214 return HEAP_GetSegptr( ThunkletHeap
, 0, thunk
);
1218 /***********************************************************************
1219 * Callback Client API
1222 #define N_CBC_FIXED 20
1223 #define N_CBC_VARIABLE 10
1224 #define N_CBC_TOTAL (N_CBC_FIXED + N_CBC_VARIABLE)
1226 static SEGPTR
*CBClientRelay16
[ N_CBC_TOTAL
];
1227 static FARPROC32
*CBClientRelay32
[ N_CBC_TOTAL
];
1229 /***********************************************************************
1230 * RegisterCBClient (KERNEL.619)
1232 INT16 WINAPI
RegisterCBClient( INT16 wCBCId
,
1233 SEGPTR
*relay16
, FARPROC32
*relay32
)
1235 /* Search for free Callback ID */
1237 for ( wCBCId
= N_CBC_FIXED
; wCBCId
< N_CBC_TOTAL
; wCBCId
++ )
1238 if ( !CBClientRelay16
[ wCBCId
] )
1241 /* Register Callback ID */
1242 if ( wCBCId
> 0 && wCBCId
< N_CBC_TOTAL
)
1244 CBClientRelay16
[ wCBCId
] = relay16
;
1245 CBClientRelay32
[ wCBCId
] = relay32
;
1253 /***********************************************************************
1254 * UnRegisterCBClient (KERNEL.622)
1256 INT16 WINAPI
UnRegisterCBClient( INT16 wCBCId
,
1257 SEGPTR
*relay16
, FARPROC32
*relay32
)
1259 if ( wCBCId
>= N_CBC_FIXED
&& wCBCId
< N_CBC_TOTAL
1260 && CBClientRelay16
[ wCBCId
] == relay16
1261 && CBClientRelay32
[ wCBCId
] == relay32
)
1263 CBClientRelay16
[ wCBCId
] = 0;
1264 CBClientRelay32
[ wCBCId
] = 0;
1273 /***********************************************************************
1274 * InitCBClient (KERNEL.623)
1276 void WINAPI
InitCBClient( FARPROC32 glueLS
)
1278 HMODULE16 kernel
= GetModuleHandle16( "KERNEL" );
1279 SEGPTR glueSL
= (SEGPTR
)WIN32_GetProcAddress16( kernel
, (LPCSTR
)604 );
1281 SetThunkletCallbackGlue( glueLS
, glueSL
);
1284 /***********************************************************************
1285 * CBClientGlueSL (KERNEL.604)
1287 void WINAPI
CBClientGlueSL( CONTEXT
*context
)
1289 /* Create stack frame */
1290 SEGPTR stackSeg
= STACK16_PUSH( THREAD_Current(), 12 );
1291 LPWORD stackLin
= PTR_SEG_TO_LIN( stackSeg
);
1294 stackLin
[3] = BP_reg( context
);
1295 stackLin
[2] = SI_reg( context
);
1296 stackLin
[1] = DI_reg( context
);
1297 stackLin
[0] = DS_reg( context
);
1299 BP_reg( context
) = OFFSETOF( stackSeg
) + 6;
1300 SP_reg( context
) = OFFSETOF( stackSeg
) - 4;
1301 GS_reg( context
) = 0;
1303 /* Jump to 16-bit relay code */
1304 glue
= CBClientRelay16
[ stackLin
[5] ][ stackLin
[4] ];
1305 CS_reg ( context
) = SELECTOROF( glue
);
1306 EIP_reg( context
) = OFFSETOF ( glue
);
1309 /***********************************************************************
1310 * CBClientThunkSL (KERNEL.620)
1312 void WINAPI
CBClientThunkSL( CONTEXT
*context
)
1314 /* Call 32-bit relay code */
1315 extern DWORD WINAPI
CALL32_CBClient( FARPROC32 proc
, LPWORD args
);
1317 LPWORD args
= PTR_SEG_OFF_TO_LIN( SS_reg( context
), BP_reg( context
) );
1318 FARPROC32 proc
= CBClientRelay32
[ args
[2] ][ args
[1] ];
1320 EAX_reg(context
) = CALL32_CBClient( proc
, args
);
1323 /***********************************************************************
1324 * KERNEL_365 (KERNEL.365)
1326 * This is declared as a register function as it has to preserve
1327 * *all* registers, even AX/DX !
1330 void WINAPI
KERNEL_365( CONTEXT
*context
)
1332 LPWORD args
= PTR_SEG_OFF_TO_LIN( SS_reg( context
), SP_reg( context
) );
1333 FIXME( thunk
, "(%04X, %d): stub!\n", args
[3], (INT16
)args
[2] );