Skip to content

Commit 9bfcbfb

Browse files
author
jan.nijtmans
committed
Fix [44b34c6152]: Fix crash on exit due to faulty asm code in DllMain
2 parents 382b300 + 0263d1b commit 9bfcbfb

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ to the userbase.
3939
- [tk print, canvas: raw smooth not implemented](https://core.tcl-lang.org/tk/info/e10819)
4040
- [Aqua: avoid use-after-free during RefocusGrabWindow()](https://core.tcl-lang.org/tk/info/6da885)
4141
- [Aqua: ttk::notebook tabs](https://core.tcl-lang.org/tk/info/cf296a)
42+
- [Fix crash on exit due to faulty asm code in DllMain](https://core.tcl-lang.org/tk/info/44b34c)
4243

4344
Release Tk 9.0.2 arises from the check-in with tag `core-9-0-2`.
4445

win/tkWin32Dll.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,21 @@ DllMain(
149149

150150
"movq %%rdx, %%gs:0" "\n\t"
151151

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

156-
"movq $0x0, 0x0(%%rsp)" "\n\t"
157-
"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);
158165

166+
__asm__ __volatile__ (
159167
/*
160168
* Come here on a normal exit. Recover the TCLEXCEPTION_REGISTRATION
161169
* and store a TCL_OK status
@@ -189,11 +197,9 @@ DllMain(
189197
:
190198
/* No outputs */
191199
:
192-
[registration] "m" (registration),
193-
[ok] "i" (TCL_OK),
194-
[error] "i" (TCL_ERROR)
200+
[ok] "i" (TCL_OK)
195201
:
196-
"%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", "memory"
202+
"%rax", "%rdx", "memory"
197203
);
198204

199205
# else
@@ -219,12 +225,18 @@ DllMain(
219225

220226
"movl %%edx, %%fs:0" "\n\t"
221227

222-
/*
223-
* Call TkFinalize
224-
*/
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);
225238

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

229241
/*
230242
* Come here on a normal exit. Recover the TCLEXCEPTION_REGISTRATION
@@ -260,11 +272,9 @@ DllMain(
260272
:
261273
/* No outputs */
262274
:
263-
[registration] "m" (registration),
264-
[ok] "i" (TCL_OK),
265-
[error] "i" (TCL_ERROR)
275+
[ok] "i" (TCL_OK)
266276
:
267-
"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
277+
"%eax", "%ebx", "%edx", "memory"
268278
);
269279

270280
# endif

0 commit comments

Comments
 (0)