avb_sysdeps_posix.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #include <endian.h>
  25. #include <stdarg.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "avb_sysdeps.h"
  30. #include <pal_log.h>
  31. #include <load_vfy_boot.h>
  32. #include <assert.h>
  33. uint32_t g_avb_heap_cur_alloc = 0;
  34. #define MOD "AVB20"
  35. int avb_memcmp(const void *src1, const void *src2, size_t n)
  36. {
  37. return memcmp(src1, src2, n);
  38. }
  39. void *avb_memcpy(void *dest, const void *src, size_t n)
  40. {
  41. return memcpy(dest, src, n);
  42. }
  43. void *avb_memset(void *dest, const int c, size_t n)
  44. {
  45. return memset(dest, c, n);
  46. }
  47. int avb_strcmp(const char *s1, const char *s2)
  48. {
  49. return strcmp(s1, s2);
  50. }
  51. size_t avb_strlen(const char *str)
  52. {
  53. return strlen(str);
  54. }
  55. void avb_abort(void)
  56. {
  57. pal_log_err("[%s] something error!", MOD);
  58. assert(0);
  59. }
  60. void avb_print(const char *message)
  61. {
  62. pal_log_err("%s", message);
  63. }
  64. void avb_printv(const char *message, ...)
  65. {
  66. va_list ap;
  67. const char *m;
  68. va_start(ap, message);
  69. for (m = message; m != NULL; m = va_arg(ap, const char *))
  70. pal_log_err("%s", m);
  71. va_end(ap);
  72. }
  73. void *avb_malloc_(size_t size)
  74. {
  75. uint32_t given_size = 0;
  76. uint32_t ret_addr = 0;
  77. uint32_t heap_max_size = avb_heap_sz;
  78. /* the size is bytes */
  79. if (size == 0) {
  80. pal_log_err("[%s] malloc: try to allocate size zero\n", MOD);
  81. return NULL;
  82. }
  83. if (size > heap_max_size) {
  84. pal_log_err("[%s] malloc: heap size too small\n", MOD);
  85. return NULL;
  86. }
  87. if ((g_avb_heap_cur_alloc + size) > heap_max_size) {
  88. pal_log_err("[%s] malloc: heap size not enough\n", MOD);
  89. return NULL;
  90. }
  91. /* alignment to 4 bytes */
  92. given_size = ((size + 3) / 4) * 4;
  93. ret_addr = (uint32_t)avb_heap + g_avb_heap_cur_alloc;
  94. g_avb_heap_cur_alloc += given_size;
  95. return (void *)ret_addr;
  96. }
  97. void avb_free(void *ptr)
  98. {
  99. return;
  100. }
  101. uint32_t avb_div_by_10(uint64_t* dividend)
  102. {
  103. uint32_t rem = (uint32_t)(*dividend % 10);
  104. *dividend /= 10;
  105. return rem;
  106. }