ems_hmu.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "ems_gc_internal.h"
  17. #if defined(GC_VERIFY)
  18. /* Set default value to prefix and suffix*/
  19. /* @hmu should not be NULL and it should have been correctly initilized (except for prefix and suffix part)*/
  20. /* @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.*/
  21. /* For VO, @tot_size should be equal to object total size.*/
  22. void hmu_init_prefix_and_suffix(hmu_t *hmu, gc_size_t tot_size, const char *file_name, int line_no)
  23. {
  24. gc_object_prefix_t *prefix = NULL;
  25. gc_object_suffix_t *suffix = NULL;
  26. gc_uint32 i = 0;
  27. bh_assert(hmu);
  28. bh_assert(hmu_get_ut(hmu) == HMU_JO || hmu_get_ut(hmu) == HMU_VO);
  29. bh_assert(tot_size >= OBJ_EXTRA_SIZE);
  30. bh_assert(!(tot_size & 7));
  31. bh_assert(hmu_get_ut(hmu) != HMU_VO || hmu_get_size(hmu) >= tot_size);
  32. prefix = (gc_object_prefix_t *)(hmu + 1);
  33. suffix = (gc_object_suffix_t *)((gc_uint8*)hmu + tot_size - OBJ_SUFFIX_SIZE);
  34. prefix->file_name = file_name;
  35. prefix->line_no = line_no;
  36. prefix->size = tot_size;
  37. for(i = 0;i < GC_OBJECT_PREFIX_PADDING_CNT;i++)
  38. {
  39. prefix->padding[i] = GC_OBJECT_PADDING_VALUE;
  40. }
  41. for(i = 0;i < GC_OBJECT_SUFFIX_PADDING_CNT;i++)
  42. {
  43. suffix->padding[i] = GC_OBJECT_PADDING_VALUE;
  44. }
  45. }
  46. void hmu_verify(hmu_t *hmu)
  47. {
  48. gc_object_prefix_t *prefix = NULL;
  49. gc_object_suffix_t *suffix = NULL;
  50. gc_uint32 i = 0;
  51. hmu_type_t ut;
  52. gc_size_t size = 0;
  53. int is_padding_ok = 1;
  54. bh_assert(hmu);
  55. ut = hmu_get_ut(hmu);
  56. bh_assert(hmu_is_ut_valid(ut));
  57. prefix = (gc_object_prefix_t *)(hmu + 1);
  58. size = prefix->size;
  59. suffix = (gc_object_suffix_t *)((gc_uint8*)hmu + size - OBJ_SUFFIX_SIZE);
  60. if(ut == HMU_VO || ut == HMU_JO)
  61. {
  62. /* check padding*/
  63. for(i = 0;i < GC_OBJECT_PREFIX_PADDING_CNT;i++)
  64. {
  65. if(prefix->padding[i] != GC_OBJECT_PADDING_VALUE)
  66. {
  67. is_padding_ok = 0;
  68. break;
  69. }
  70. }
  71. for(i = 0;i < GC_OBJECT_SUFFIX_PADDING_CNT;i++)
  72. {
  73. if(suffix->padding[i] != GC_OBJECT_PADDING_VALUE)
  74. {
  75. is_padding_ok = 0;
  76. break;
  77. }
  78. }
  79. if(!is_padding_ok)
  80. {
  81. printf("Invalid padding for object created at %s:%d",
  82. (prefix->file_name ? prefix->file_name : ""), prefix->line_no);
  83. }
  84. bh_assert(is_padding_ok);
  85. }
  86. }
  87. #endif