_ReadSLEB.c 465 B

12345678910111213141516171819202122232425
  1. #include <libunwind.h>
  2. unw_word_t
  3. _ReadSLEB (unsigned char **dpp)
  4. {
  5. unsigned shift = 0;
  6. unw_word_t byte, result = 0;
  7. unsigned char *bp = *dpp;
  8. while (1)
  9. {
  10. byte = *bp++;
  11. result |= (byte & 0x7f) << shift;
  12. shift += 7;
  13. if ((byte & 0x80) == 0)
  14. break;
  15. }
  16. if (shift < 8 * sizeof (unw_word_t) && (byte & 0x40) != 0)
  17. /* sign-extend negative value */
  18. result |= ((unw_word_t) -1) << shift;
  19. *dpp = bp;
  20. return result;
  21. }