hv-balloon-internal.h 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * QEMU Hyper-V Dynamic Memory Protocol driver
  3. *
  4. * Copyright (C) 2020-2023 Oracle and/or its affiliates.
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  7. * See the COPYING file in the top-level directory.
  8. */
  9. #ifndef HW_HYPERV_HV_BALLOON_INTERNAL_H
  10. #define HW_HYPERV_HV_BALLOON_INTERNAL_H
  11. #define HV_BALLOON_PFN_SHIFT 12
  12. #define HV_BALLOON_PAGE_SIZE (1 << HV_BALLOON_PFN_SHIFT)
  13. #define SUM_OVERFLOW_U64(in1, in2) ((in1) > UINT64_MAX - (in2))
  14. #define SUM_SATURATE_U64(in1, in2) \
  15. ({ \
  16. uint64_t _in1 = (in1), _in2 = (in2); \
  17. uint64_t _result; \
  18. \
  19. if (!SUM_OVERFLOW_U64(_in1, _in2)) { \
  20. _result = _in1 + _in2; \
  21. } else { \
  22. _result = UINT64_MAX; \
  23. } \
  24. \
  25. _result; \
  26. })
  27. #endif