sandbox: add initjmp()
authorJerome Forissier <jerome.forissier@linaro.org>
Fri, 18 Apr 2025 14:09:32 +0000 (16:09 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 23 Apr 2025 19:19:44 +0000 (13:19 -0600)
commita27844cc9443341ffe1314ccc4c384a54ad1ae32
tree4a99e50a494582975b7fd3f9d65db01fa9141ddb
parent3691328ef69555148962654e7f834fd0b5273fcb
sandbox: add initjmp()

Add initjm[() to sandbox, a non-standard extension to setjmp()/
longjmp() allowing to initialize a jump buffer with a function pointer
and a stack pointer. This will be useful to later introduce threads.
With this new function it becomes possible to longjmp() to a particular
function pointer (rather than to a point previously reached during
program execution as is the case with setjmp()), and with a custom stack.
Both things are needed to spin off a new thread. Then the usual
setjmp()/longjmp() pair is enough to save and restore a context, i.e.,
switch thread. The implementation is taken verbatim from barebox [1] with
the exception of the additional stack_sz argument. It is quite complex
because contrary to U-Boot platform code we don't know how the system's
C library implements the jump buffer, so we can't just write the function
and stack pointers into it.

[1] https://github.com/barebox/barebox/blob/b2a15c383ddc/arch/sandbox/os/setjmp.c

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
arch/Kconfig
arch/sandbox/cpu/Makefile
arch/sandbox/cpu/initjmp.c [new file with mode: 0644]