ems_hmu.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "ems_gc_internal.h"
  6. #if defined(GC_VERIFY)
  7. /* Set default value to prefix and suffix*/
  8. /* @hmu should not be NULL and it should have been correctly initilized (except for prefix and suffix part)*/
  9. /* @tot_size is offered here because hmu_get_size can not be used till now. @tot_size should not be smaller than OBJ_EXTRA_SIZE.*/
  10. /* For VO, @tot_size should be equal to object total size.*/
  11. void hmu_init_prefix_and_suffix(hmu_t *hmu, gc_size_t tot_size, const char *file_name, int line_no)
  12. {
  13. gc_object_prefix_t *prefix = NULL;
  14. gc_object_suffix_t *suffix = NULL;
  15. gc_uint32 i = 0;
  16. bh_assert(hmu);
  17. bh_assert(hmu_get_ut(hmu) == HMU_JO || hmu_get_ut(hmu) == HMU_VO);
  18. bh_assert(tot_size >= OBJ_EXTRA_SIZE);
  19. bh_assert(!(tot_size & 7));
  20. bh_assert(hmu_get_ut(hmu) != HMU_VO || hmu_get_size(hmu) >= tot_size);
  21. prefix = (gc_object_prefix_t *)(hmu + 1);
  22. suffix = (gc_object_suffix_t *)((gc_uint8*)hmu + tot_size - OBJ_SUFFIX_SIZE);
  23. prefix->file_name = file_name;
  24. prefix->line_no = line_no;
  25. prefix->size = tot_size;
  26. for(i = 0;i < GC_OBJECT_PREFIX_PADDING_CNT;i++)
  27. {
  28. prefix->padding[i] = GC_OBJECT_PADDING_VALUE;
  29. }
  30. for(i = 0;i < GC_OBJECT_SUFFIX_PADDING_CNT;i++)
  31. {
  32. suffix->padding[i] = GC_OBJECT_PADDING_VALUE;
  33. }
  34. }
  35. void hmu_verify(hmu_t *hmu)
  36. {
  37. gc_object_prefix_t *prefix = NULL;
  38. gc_object_suffix_t *suffix = NULL;
  39. gc_uint32 i = 0;
  40. hmu_type_t ut;
  41. gc_size_t size = 0;
  42. int is_padding_ok = 1;
  43. bh_assert(hmu);
  44. ut = hmu_get_ut(hmu);
  45. bh_assert(hmu_is_ut_valid(ut));
  46. prefix = (gc_object_prefix_t *)(hmu + 1);
  47. size = prefix->size;
  48. suffix = (gc_object_suffix_t *)((gc_uint8*)hmu + size - OBJ_SUFFIX_SIZE);
  49. if(ut == HMU_VO || ut == HMU_JO)
  50. {
  51. /* check padding*/
  52. for(i = 0;i < GC_OBJECT_PREFIX_PADDING_CNT;i++)
  53. {
  54. if(prefix->padding[i] != GC_OBJECT_PADDING_VALUE)
  55. {
  56. is_padding_ok = 0;
  57. break;
  58. }
  59. }
  60. for(i = 0;i < GC_OBJECT_SUFFIX_PADDING_CNT;i++)
  61. {
  62. if(suffix->padding[i] != GC_OBJECT_PADDING_VALUE)
  63. {
  64. is_padding_ok = 0;
  65. break;
  66. }
  67. }
  68. if(!is_padding_ok)
  69. {
  70. printf("Invalid padding for object created at %s:%d",
  71. (prefix->file_name ? prefix->file_name : ""), prefix->line_no);
  72. }
  73. bh_assert(is_padding_ok);
  74. }
  75. }
  76. #endif