avb_sysdeps_posix.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. int avb_strncmp(const char* s1, const char* s2, size_t n)
  52. {
  53. return strncmp(s1, s2, n);
  54. }
  55. size_t avb_strlen(const char* str)
  56. {
  57. return strlen(str);
  58. }
  59. void avb_abort(void)
  60. {
  61. pal_log_err("[%s] something error!", MOD);
  62. assert(0);
  63. }
  64. void avb_print(const char *message)
  65. {
  66. pal_log_err("%s", message);
  67. }
  68. void avb_printv(const char *message, ...)
  69. {
  70. va_list ap;
  71. const char *m;
  72. va_start(ap, message);
  73. for (m = message; m != NULL; m = va_arg(ap, const char *))
  74. pal_log_err("%s", m);
  75. va_end(ap);
  76. }
  77. void *avb_malloc_(size_t size)
  78. {
  79. uint32_t given_size = 0;
  80. uint32_t ret_addr = 0;
  81. uint32_t heap_max_size = avb_heap_sz;
  82. /* the size is bytes */
  83. if (size == 0) {
  84. pal_log_err("[%s] malloc: try to allocate size zero\n", MOD);
  85. return NULL;
  86. }
  87. if (size > heap_max_size) {
  88. pal_log_err("[%s] malloc: heap size too small\n", MOD);
  89. return NULL;
  90. }
  91. if ((g_avb_heap_cur_alloc + size) > heap_max_size) {
  92. pal_log_err("[%s] malloc: heap size not enough\n", MOD);
  93. return NULL;
  94. }
  95. /* alignment to 4 bytes */
  96. given_size = ((size + 3) / 4) * 4;
  97. ret_addr = (uint32_t)avb_heap + g_avb_heap_cur_alloc;
  98. g_avb_heap_cur_alloc += given_size;
  99. return (void *)ret_addr;
  100. }
  101. void avb_free(void *ptr)
  102. {
  103. return;
  104. }
  105. uint32_t avb_div_by_10(uint64_t* dividend)
  106. {
  107. uint32_t rem = (uint32_t)(*dividend % 10);
  108. *dividend /= 10;
  109. return rem;
  110. }