Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

retval.c 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2018 The strace developers.
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: LGPL-2.1-or-later
  6. */
  7. #include "defs.h"
  8. #include "retval.h"
  9. static kernel_long_t *retval_vec;
  10. static size_t retval_vec_capacity; /* size of the arena */
  11. static size_t retval_vec_size; /* size of the used arena */
  12. static void
  13. expand_retval_vec(void)
  14. {
  15. const size_t old_capacity = retval_vec_capacity;
  16. retval_vec = xgrowarray(retval_vec, &retval_vec_capacity,
  17. sizeof(*retval_vec));
  18. memset(retval_vec + old_capacity, 0,
  19. (retval_vec_capacity - old_capacity)
  20. * sizeof(*retval_vec));
  21. }
  22. uint16_t
  23. retval_new(const kernel_long_t rval)
  24. {
  25. const uint16_t idx = retval_vec_size;
  26. if (idx < retval_vec_size)
  27. error_func_msg_and_die("retval index overflow");
  28. if (retval_vec_size == retval_vec_capacity)
  29. expand_retval_vec();
  30. retval_vec[idx] = rval;
  31. ++retval_vec_size;
  32. return idx;
  33. }
  34. kernel_long_t
  35. retval_get(const uint16_t rval_idx)
  36. {
  37. if (rval_idx >= retval_vec_size)
  38. error_func_msg_and_die("rval_idx >= retval_vec_size");
  39. return retval_vec[rval_idx];
  40. }