One more attempt to implement [set,get,make,swap]context inside libc scope, much smaller - only asm files moved from previous attempt (overall around 400+- lines): git apply --stat ../mc.patch repos/libports/lib/import/import-libc-context.mk | 1 repos/libports/lib/mk/libc.mk | 2 repos/libports/lib/mk/spec/x86_64/libc-context.mk | 9 + repos/libports/lib/symbols/libc | 2 repos/libports/ports/libc.hash | 2 repos/libports/recipes/api/libc_setjmp/content.mk | 2 repos/libports/src/lib/libc/dummies.cc | 28 +- repos/libports/src/lib/libc/patches/mcontext.patch | 346 ++++++++++++++++++++ 8 files changed, 387 insertions(+), 5 deletions(-)
https://github.com/tor-m6/genode/commit/b5ed6a49b0b6c09b20161b1ea726dbb685ae...
Also add test for them, see separate patch. Not yet choose where to put, potentially should be near makecontext() declaration inside libc include/libc/ucontext.h. extern "C" void *alloc_secondary_stack(char const *name, size_t stack_size);
Josef, please, take a look for this patch and for anon_mmap!
My understanding of limitations: - x86_64 only (easy to extend to others like arm64) - ignore set/restore of signals (need kernel support?) - replace/add old code from libc references to interpose table/etc; not 100% sure that all related aux functions like __getcontextx will work as FreeBSD intended… - require alloc_secondary_stack for correct operations in makecontext (the only way to work) - free_secondary_stack not yet tested actively - could be some problems with alignment/etc related to secondary stack allocation - do not restore temporary/etc registers (for amd64 preserve only rbp/rbx/r12/r13/r14/r15/rsi/rdi/rdx/rcx/r8/r9/rip/rsp general registers and fp_state and MXCSR) - not sure that fpstate stored and restored correctly, not tested yet
And I still need to patch part of libc related to anonymous memory mapping. Updated implementation for libc 21.02:
https://github.com/tor-m6/genode/commit/c64bfeeba6e8cca4376636bdd2e9e8bbf3aa...