From ce673578fdcdf197648bbba1dfdc55402d48bb22 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sun, 22 Sep 2024 09:30:42 +0300 Subject: [PATCH] fix(amd64-386): crash with sample-based oscillator in 32-bit library --- CHANGELOG.md | 2 ++ vm/compiler/templates/amd64-386/sources.asm | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14aeb32..3822211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). the command line tools. ### Fixed +- Crashes with sample-based oscillators in the 32-bit library, as the pointer to + sample-table (edi) got accidentally overwritten by detune - Sample-based oscillators could hard crash if a x87 stack overflow happened when calculating the current position in the sample ([#149][i149]) - Numeric updown widget calculated dp-to-px conversion incorrectly, resulting in diff --git a/vm/compiler/templates/amd64-386/sources.asm b/vm/compiler/templates/amd64-386/sources.asm index 9611c03..558c46c 100644 --- a/vm/compiler/templates/amd64-386/sources.asm +++ b/vm/compiler/templates/amd64-386/sources.asm @@ -127,6 +127,9 @@ su_op_oscillat_mono: {{- end}} {{- if .SupportsParamValueOtherThan "oscillator" "unison" 0}} {{.PushRegs .AX "" .WRK "OscWRK" .AX "OscFlags"}} +{{- if and (not .Amd64) .Library}} + push {{.AX}} ; pushregs is pushad in 32-bit, and pushes edi last, so decrease SP because library needs to save edi and we can store detune there +{{- end}} fldz ; 0 d fxch ; d a=0, "accumulated signal" su_op_oscillat_unison_loop: @@ -147,6 +150,9 @@ su_op_oscillat_unison_loop: dec eax jmp short su_op_oscillat_unison_loop su_op_oscillat_unison_out: +{{- if and (not .Amd64) .Library}} + pop {{.AX}} ; pushregs is pushad in 32-bit, and pushes edi last, so we inscrease SP to avoid destroying edi +{{- end}} {{.PopRegs .AX .WRK .AX}} ret su_op_oscillat_single: