I’m trying to implement a poor man’s “call with current continuation” for a program written in C. I can “easily” access and memcpy the relevant part of the C stack (obviously, that’s not portable and is full of UB, but I already bit that bullet).
What I’m wondering is how to get the actual stack pointer and return address and how to restore them. I have the impression that I can probably get away with doing it only for the stack pointer (the return address itself will be hopefully stashed inside the stack chunk that I copied&restored).
I suspect this will require a bit of assembly, but I’m hoping that there’s either some clever way to avoid it, or better that there’s a library out there which does the ugly bits for me, or in the worst case some existing code I could copy which has similar needs and has the needed inline ASM for the usual-suspect ISAs.