Skip to content

Commit 12f1941

Browse files
author
jan.nijtmans
committed
Fix [44b34c6152]: Fix crash on exit due to faulty asm code in DllMain
1 parent 1e06319 commit 12f1941

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8325,4 +8325,6 @@ Tk Cocoa 2.0: More drawing internals refinements (culler,walzer)
83258325

83268326
2025-11-04 (bug) [6da885]: Aqua: avoid use-after-free during RefocusGrabWindow() (chavez)
83278327

8328+
2025-11-11 (bug) [[44b34]: Fix crash on exit due to faulty asm code in DllMain (fuentes)
8329+
83288330
- (to be) Released 8.6.18, Apr ??, 2026 - https://core.tcl-lang.org/tk/ for details

win/tkWin32Dll.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ DllMain(
104104
#if defined(HAVE_NO_SEH) && !defined(__aarch64__)
105105
TCLEXCEPTION_REGISTRATION registration;
106106
#endif
107+
(void)reserved;
107108

108109
/*
109110
* If we are attaching to the DLL from a new process, tell Tk about the
@@ -148,13 +149,21 @@ DllMain(
148149

149150
"movq %%rdx, %%gs:0" "\n\t"
150151

151-
/*
152-
* Call TkFinalize
153-
*/
152+
:
153+
/* No outputs */
154+
:
155+
[registration] "m" (registration),
156+
[error] "i" (TCL_ERROR)
157+
:
158+
"%rax", "%rdx", "memory"
159+
);
154160

155-
"movq $0x0, 0x0(%%rsp)" "\n\t"
156-
"call TkFinalize" "\n\t"
161+
/* Just do a regular C call so we don't need to worry about following
162+
* the calling convention, specially the registers the function may
163+
* clobber: */
164+
TkFinalize(NULL);
157165

166+
__asm__ __volatile__ (
158167
/*
159168
* Come here on a normal exit. Recover the TCLEXCEPTION_REGISTRATION
160169
* and store a TCL_OK status
@@ -188,11 +197,9 @@ DllMain(
188197
:
189198
/* No outputs */
190199
:
191-
[registration] "m" (registration),
192-
[ok] "i" (TCL_OK),
193-
[error] "i" (TCL_ERROR)
200+
[ok] "i" (TCL_OK)
194201
:
195-
"%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", "memory"
202+
"%rax", "%rdx", "%rbp", "memory"
196203
);
197204

198205
# else
@@ -218,12 +225,18 @@ DllMain(
218225

219226
"movl %%edx, %%fs:0" "\n\t"
220227

221-
/*
222-
* Call TkFinalize
223-
*/
228+
:
229+
/* No outputs */
230+
:
231+
[registration] "m" (registration),
232+
[error] "i" (TCL_ERROR)
233+
:
234+
"%eax", "%ebx", "%edx", "memory"
235+
);
236+
237+
TkFinalize(NULL);
224238

225-
"movl $0x0, 0x0(%%esp)" "\n\t"
226-
"call _TkFinalize" "\n\t"
239+
__asm__ __volatile__ (
227240

228241
/*
229242
* Come here on a normal exit. Recover the TCLEXCEPTION_REGISTRATION
@@ -259,11 +272,9 @@ DllMain(
259272
:
260273
/* No outputs */
261274
:
262-
[registration] "m" (registration),
263-
[ok] "i" (TCL_OK),
264-
[error] "i" (TCL_ERROR)
275+
[ok] "i" (TCL_OK)
265276
:
266-
"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
277+
"%eax", "%ebx", "%edx", "%ebp", "memory"
267278
);
268279

269280
# endif

0 commit comments

Comments
 (0)