From 5364bc7c821bb3e30d8c84f5b12fe57b449d1e3b Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Sun, 3 Aug 2025 18:41:32 +0200 Subject: [PATCH] Fix i386 alloca code. I commited the wrong version in previous commit. --- lib/alloca-bt.S | 5 +++-- lib/alloca.S | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/alloca-bt.S b/lib/alloca-bt.S index d9738949..c704af4b 100644 --- a/lib/alloca-bt.S +++ b/lib/alloca-bt.S @@ -15,10 +15,10 @@ _(__bound_alloca): pop %edx pop %eax mov %eax, %ecx + test %eax,%eax + jz p6 add $15+1,%eax and $-16,%eax - sub $4,%eax - jz p6 #ifdef _WIN32 p4: @@ -33,6 +33,7 @@ p5: #endif sub %eax,%esp + and $-16,%esp mov %esp,%eax push %edx diff --git a/lib/alloca.S b/lib/alloca.S index 0c37546e..16f09f57 100644 --- a/lib/alloca.S +++ b/lib/alloca.S @@ -13,28 +13,28 @@ .globl _(alloca), _(__alloca) _(alloca): _(__alloca): - push %ebp - mov %esp,%ebp - mov 8(%ebp),%eax + pop %edx + pop %eax add $15,%eax and $-16,%eax - sub $4,%eax + jz p3 + #ifdef _WIN32 - jmp .+16 #p2 p1: + cmp $4096,%eax + jbe p2 + test %eax,-4096(%esp) sub $4096,%esp sub $4096,%eax - test %eax,(%esp) + jmp p1 p2: - cmp $4096,%eax - jae p1 #endif sub %eax,%esp - mov 4(%ebp),%eax - mov 0(%ebp),%ebp - add $8,%esp - push %eax - lea 8(%esp),%eax + and $-16,%esp + mov %esp,%eax +p3: + push %edx + push %edx ret /* ---------------------------------------------- */