avb_sysdeps.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright (C) 2016 The Android Open Source Project
  4. */
  5. #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
  6. #error "Never include this file directly, include libavb.h instead."
  7. #endif
  8. #ifndef AVB_SYSDEPS_H_
  9. #define AVB_SYSDEPS_H_
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /* Change these includes to match your platform to bring in the
  14. * equivalent types available in a normal C runtime. At least things
  15. * like uint8_t, uint64_t, and bool (with |false|, |true| keywords)
  16. * must be present.
  17. */
  18. #include <common.h>
  19. /* If you don't have gcc or clang, these attribute macros may need to
  20. * be adjusted.
  21. */
  22. #define AVB_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  23. #define AVB_ATTR_PACKED __attribute__((packed))
  24. #define AVB_ATTR_NO_RETURN __attribute__((noreturn))
  25. #define AVB_ATTR_SENTINEL __attribute__((__sentinel__))
  26. /* Size in bytes used for alignment. */
  27. #ifdef __LP64__
  28. #define AVB_ALIGNMENT_SIZE 8
  29. #else
  30. #define AVB_ALIGNMENT_SIZE 4
  31. #endif
  32. /* Compare |n| bytes in |src1| and |src2|.
  33. *
  34. * Returns an integer less than, equal to, or greater than zero if the
  35. * first |n| bytes of |src1| is found, respectively, to be less than,
  36. * to match, or be greater than the first |n| bytes of |src2|. */
  37. int avb_memcmp(const void* src1,
  38. const void* src2,
  39. size_t n) AVB_ATTR_WARN_UNUSED_RESULT;
  40. /* Compare two strings.
  41. *
  42. * Return an integer less than, equal to, or greater than zero if |s1|
  43. * is found, respectively, to be less than, to match, or be greater
  44. * than |s2|.
  45. */
  46. int avb_strcmp(const char* s1, const char* s2);
  47. /* Copy |n| bytes from |src| to |dest|. */
  48. void* avb_memcpy(void* dest, const void* src, size_t n);
  49. /* Set |n| bytes starting at |s| to |c|. Returns |dest|. */
  50. void* avb_memset(void* dest, const int c, size_t n);
  51. /* Prints out a message. The string passed must be a NUL-terminated
  52. * UTF-8 string.
  53. */
  54. void avb_print(const char* message);
  55. /* Prints out a vector of strings. Each argument must point to a
  56. * NUL-terminated UTF-8 string and NULL should be the last argument.
  57. */
  58. void avb_printv(const char* message, ...) AVB_ATTR_SENTINEL;
  59. /* Aborts the program or reboots the device. */
  60. void avb_abort(void) AVB_ATTR_NO_RETURN;
  61. /* Allocates |size| bytes. Returns NULL if no memory is available,
  62. * otherwise a pointer to the allocated memory.
  63. *
  64. * The memory is not initialized.
  65. *
  66. * The pointer returned is guaranteed to be word-aligned.
  67. *
  68. * The memory should be freed with avb_free() when you are done with it.
  69. */
  70. void* avb_malloc_(size_t size) AVB_ATTR_WARN_UNUSED_RESULT;
  71. /* Frees memory previously allocated with avb_malloc(). */
  72. void avb_free(void* ptr);
  73. /* Returns the lenght of |str|, excluding the terminating NUL-byte. */
  74. size_t avb_strlen(const char* str) AVB_ATTR_WARN_UNUSED_RESULT;
  75. /* Divide the |dividend| by 10 and saves back to the pointer. Return the
  76. * remainder. */
  77. uint32_t avb_div_by_10(uint64_t* dividend);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* AVB_SYSDEPS_H_ */