kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

uctx_rv64_linux.c (919B)


      1 /* ucontext_t <-> KitUnwindFrame marshalling for riscv64 on Linux.
      2  * glibc's mcontext_t exposes __gregs[0..31] where __gregs[0] holds the PC
      3  * and __gregs[1..31] hold x1..x31. DWARF numbering assigns 0..31 to
      4  * x0..x31, so we marshal pc separately and fold x1..x31 into f->regs[1..31],
      5  * leaving f->regs[0] as the constant zero. */
      6 
      7 #include <stdint.h>
      8 
      9 #include "env_posix.h"
     10 
     11 void dbg_ucontext_to_frame(const ucontext_t* uc, KitUnwindFrame* f) {
     12   const mcontext_t* mc = &uc->uc_mcontext;
     13   int i;
     14   f->regs[0] = 0;
     15   for (i = 1; i < 32; ++i) f->regs[i] = (uint64_t)mc->__gregs[i];
     16   f->pc = (uint64_t)mc->__gregs[0];
     17   f->cfa = (uint64_t)mc->__gregs[8]; /* s0/fp; CFI refines */
     18 }
     19 
     20 void dbg_frame_to_ucontext(const KitUnwindFrame* f, ucontext_t* uc) {
     21   mcontext_t* mc = &uc->uc_mcontext;
     22   int i;
     23   for (i = 1; i < 32; ++i) mc->__gregs[i] = (unsigned long)f->regs[i];
     24   mc->__gregs[0] = (unsigned long)f->pc;
     25 }