[libc-commits] [libc] [libc] Implement getcontext and setcontext for x86_64 (PR #192343)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Thu Apr 16 01:16:00 PDT 2026
https://github.com/labath commented:
Despite the number/length of comments, I think this is looks pretty good :)
regarding the testing standards we talked about, I'm not sure whether we misunderstood each other, or you forgot to include something in the PR. The test you have are okay, but practically, they only test that RIP and RSP and RBP (maybe one or two more registers in optimized mode) are restored correctly. I think a test which explicitly tests register restoration could be useful.
This isn't exactly a matter of (line) coverage, as all of this is straight-line code, but of ensuring the straight line actually does what you expect of it.
I haven't tried to compile this, but I think something like this would do it with minimal asm
```
register void *rdi asm("rdi") = uc;
register long rsi asm("rsi") = 0xdead;
register long rbx asm("rbx") = 0xbeef;
// etc. can't list all of them because we need to leave some for the complier
asm ("call *%[getcontext]" : "+r"(rdi), "+r"(rsi), "+r"(rbx) : [getcontext]"r"(LIBC_NAMESPACE::getcontext));
ASSERT_EQ(rdi, uc);
ASSERT_EQ(rsi, 0xdead);
...
// modify register values and call setcontext
```
The reason I was asking about testing standards is that I'm new to this subproject, and I don't know what's a reasonable level of testing that a function like this should get -- which is also why I'm not insisting on adding this.
If you think it's useful, but don't have the time to write it, I'm also volunteering to do that myself. :)
https://github.com/llvm/llvm-project/pull/192343
More information about the libc-commits
mailing list