[libc-commits] [PATCH] D145584: [libc] Add support for setjmp and longjmp in riscv

Mikhail Ramalho via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Mar 23 05:09:59 PDT 2023


mikhail.ramalho added inline comments.


================
Comment at: libc/src/setjmp/riscv64/longjmp.h:56
+
+  LIBC_INLINE_ASM("seqz %0, %1" : "+r"(buf) : "r"(val) :);
+  LIBC_INLINE_ASM("add %0, %0, %1" : "+r"(buf) : "r"(val), "r"(buf) :);
----------------
sivachandra wrote:
> Why is this required? Can we just copy `val` to `a0` and return? Or, even better would be just `return val;` if we can make this a `naked` function?
This is the fake return mentioned on the Linux man page:
```
Following  a  successful  longjmp(), execution continues as if setjmp()
had returned for a second time.  This  "fake"  return  can  be  distin-
guished from a true setjmp() call because the "fake" return returns the
value provided in val.  If the programmer mistakenly passes the value 0
in val, the "fake" return will instead return 1.
```

We can't return normally here, since `longjmp` has no return.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145584/new/

https://reviews.llvm.org/D145584



More information about the libc-commits mailing list