File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -351,21 +351,24 @@ _exit:
351351 ; exit status is currently at (sp + 3), so we need to fix that
352352 pop bc ; destroy return address
353353#endif
354+
354355#if HAS_ATEXIT
355356 ; input: (sp + 0) = exit status
356357 jr .L.exit_function_start
357358
358359.L.exit_function_loop:
359- ld hl , (ix + 1 + 0 * 3 )
360+ push hl
361+ pop ix
362+ ld hl , (hl) ; ld hl, (ix + 0 * 3)
360363 ld (__atexit_functions) , hl
361364 pop hl ; exit status
362365 push hl ; exit status
363- ld de , (ix + 1 + 2 * 3 ) ; arg
366+ ld de , (ix + 2 * 3 ) ; arg
364367 push de ; arg
365368 push hl ; exit status
366- ld hl , (ix + 1 + 1 * 3 ) ; func
369+ ld hl , (ix + 1 * 3 ) ; func
367370 push hl ; func
368- pea ix + 1
371+ push ix
369372 call _free
370373 pop bc ; reset SP
371374 pop hl ; func
@@ -375,12 +378,16 @@ _exit:
375378 pop bc ; reset SP
376379 pop bc ; reset SP
377380.L.exit_function_start:
378- ld ix , (__atexit_functions)
381+ ld hl , (__atexit_functions)
379382 ; NULL indicates no more atexit functions
380- ld bc , - 1
381- add ix , bc
382- jr c , .L.exit_function_loop
383+ add hl , bc
384+ or a , a
385+ sbc hl , bc
386+ jr nz , .L.exit_function_loop
387+
388+ . extern __atexit_functions
383389#endif
390+
384391#if HAS_FINI_ARRAY
385392 ld hl , __fini_array_end
386393 jr .L.fini_array_start
You can’t perform that action at this time.
0 commit comments