• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HDFGroup / hermes / 4851036339

pending completion
4851036339

Pull #515

github

GitHub
Merge aee741046 into 87672e106
Pull Request #515: v1.0

5501 of 5501 new or added lines in 117 files covered. (100.0%)

4997 of 7299 relevant lines covered (68.46%)

6131966.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/hermes_shm/src/memory/malloc_allocator.cc
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Distributed under BSD 3-Clause license.                                   *
3
 * Copyright by The HDF Group.                                               *
4
 * Copyright by the Illinois Institute of Technology.                        *
5
 * All rights reserved.                                                      *
6
 *                                                                           *
7
 * This file is part of Hermes. The full Hermes copyright notice, including  *
8
 * terms governing use, modification, and redistribution, is contained in    *
9
 * the COPYING file, which can be found at the top directory. If you do not  *
10
 * have access to the file, you may request a copy from help@hdfgroup.org.   *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12

13

14
#include <hermes_shm/memory/allocator/malloc_allocator.h>
15

16
namespace hshm::ipc {
17

18
struct MallocPage {
19
  size_t page_size_;
20
};
21

22
void MallocAllocator::shm_init(allocator_id_t id,
×
23
                               size_t custom_header_size,
24
                               char *buffer,
25
                               size_t buffer_size) {
26
  buffer_ = buffer;
×
27
  buffer_size_ = buffer_size;
×
28
  header_ = reinterpret_cast<MallocAllocatorHeader*>(
×
29
    malloc(sizeof(MallocAllocatorHeader) + custom_header_size));
×
30
  custom_header_ = reinterpret_cast<char*>(header_ + 1);
×
31
  header_->Configure(id, custom_header_size);
×
32
}
×
33

34
void MallocAllocator::shm_deserialize(char *buffer,
×
35
                                      size_t buffer_size) {
36
  throw NOT_IMPLEMENTED.format("MallocAllocator::shm_deserialize");
×
37
}
38

39
size_t MallocAllocator::GetCurrentlyAllocatedSize() {
×
40
  return header_->total_alloc_size_;
×
41
}
42

43
OffsetPointer MallocAllocator::AllocateOffset(size_t size) {
×
44
  auto page = reinterpret_cast<MallocPage*>(
45
    malloc(sizeof(MallocPage) + size));
×
46
  page->page_size_ = size;
×
47
  header_->total_alloc_size_ += size;
×
48
  return OffsetPointer(size_t(page + 1));
×
49
}
50

51
OffsetPointer MallocAllocator::AlignedAllocateOffset(size_t size,
×
52
                                                     size_t alignment) {
53
  auto page = reinterpret_cast<MallocPage*>(
54
    aligned_alloc(alignment, sizeof(MallocPage) + size));
×
55
  page->page_size_ = size;
×
56
  header_->total_alloc_size_ += size;
×
57
  return OffsetPointer(size_t(page + 1));
×
58
}
59

60
OffsetPointer MallocAllocator::ReallocateOffsetNoNullCheck(OffsetPointer p,
×
61
                                                           size_t new_size) {
62
  // Get the input page
63
  auto page = reinterpret_cast<MallocPage*>(
64
    p.off_.load() - sizeof(MallocPage));
×
65
  header_->total_alloc_size_ += new_size - page->page_size_;
×
66

67
  // Reallocate the input page
68
  auto new_page = reinterpret_cast<MallocPage*>(
69
    realloc(page, sizeof(MallocPage) + new_size));
×
70
  new_page->page_size_ = new_size;
×
71

72
  // Create the pointer
73
  return OffsetPointer(size_t(new_page + 1));
×
74
}
75

76
void MallocAllocator::FreeOffsetNoNullCheck(OffsetPointer p) {
×
77
  auto page = reinterpret_cast<MallocPage*>(
78
    p.off_.load() - sizeof(MallocPage));
×
79
  header_->total_alloc_size_ -= page->page_size_;
×
80
  free(page);
×
81
}
×
82

83
}  // namespace hshm::ipc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc