Ah, I think I understand what you're getting at.
You'll want to read 
this: 
https://github.com/golang/go/blob/b44b360dd40a537e953225d70ca96361e2c57600/src/runtime/stack.go#L21
TL;DR the thing the header is checking against isn't the bottom of stack, 
it is a mark some constant above the bottom.

> what frame size is safe

StackSmall, which is 128 bytes.

On Thursday, April 17, 2025 at 4:48:18 PM UTC-7 Wojciech Kaczmarek wrote:

> piątek, 18 kwietnia 2025 o 00:10:02 UTC+2 Keith Randall napisał(a):
>
> On Thursday, April 17, 2025 at 11:50:18 AM UTC-7 Wojciech Kaczmarek wrote:
>
> Hi Gophers,
>
> I am experimenting with assembler, ABI0 and stuff. 
> While I was learning the ABI0 frame structure from disassembled code, I 
> noticed that the stack check happens before subtracting from RSP (I'm on 
> arm64, but the same applies to SP on amd64, I mean the hardware register 
> ofc). 
> Then, what if the frame being allocated is big enough to cause trouble?
>
>
> Do you mean, what if the stack check fails? It calls into 
> runtime.morestack. morestack will allocate a new, larger stack and copy the 
> existing contents over.
>
>
> I wasn't quite asking about check fail scenario. The stack check is done 
> before frame is even considered, and later the frame size is subtracted 
> from RSP.  But then there is no checking again.
>  
>
> Also, after the CALL runtime.morestack*, what is the safe amount to 
> subtract from RSP?
>
>
> There's no specific amount. Probably the frame that didn't fit at the 
> start will fit after calling morestack. But not necessarily, if the frame 
> is really large it will call into morestack again. (That's why after 
> calling morestack we jump to the top of the function and redo the stack 
> check.) 
>
>  
> Hmm, as above - it seems that g.stackguard0 is compared to the RSP before 
> frame gets allocated on the stack, so the question remains - what frame 
> size is safe?
> (I am also thinking about some form of limited "alloca", to have a NOFRAME 
> function and make frame manually in the asm - the more it seems important 
> to know what limit on modifying RSP is safe here).
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/b9302710-7325-4a95-b814-519bf0c25407n%40googlegroups.com.

Reply via email to