• 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

56.52
/hermes_shm/src/memory/stack_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/stack_allocator.h>
15
#include <hermes_shm/memory/allocator/mp_page.h>
16

17
namespace hshm::ipc {
18

19
void StackAllocator::shm_init(allocator_id_t id,
133✔
20
                              size_t custom_header_size,
21
                              char *buffer,
22
                              size_t buffer_size) {
23
  buffer_ = buffer;
133✔
24
  buffer_size_ = buffer_size;
133✔
25
  header_ = reinterpret_cast<StackAllocatorHeader*>(buffer_);
133✔
26
  custom_header_ = reinterpret_cast<char*>(header_ + 1);
133✔
27
  size_t region_off = (custom_header_ - buffer_) + custom_header_size;
133✔
28
  size_t region_size = buffer_size_ - region_off;
133✔
29
  header_->Configure(id, custom_header_size, region_off, region_size);
133✔
30
}
133✔
31

32
void StackAllocator::shm_deserialize(char *buffer,
77✔
33
                                     size_t buffer_size) {
34
  buffer_ = buffer;
77✔
35
  buffer_size_ = buffer_size;
77✔
36
  header_ = reinterpret_cast<StackAllocatorHeader*>(buffer_);
77✔
37
  custom_header_ = reinterpret_cast<char*>(header_ + 1);
77✔
38
}
77✔
39

40
size_t StackAllocator::GetCurrentlyAllocatedSize() {
×
41
  return header_->total_alloc_;
×
42
}
43

44
OffsetPointer StackAllocator::AllocateOffset(size_t size) {
87,342✔
45
  size += sizeof(MpPage);
87,342✔
46
  if (header_->region_size_ < size) {
87,342✔
47
    return OffsetPointer::GetNull();
×
48
  }
49
  OffsetPointer p(header_->region_off_.fetch_add(size));
174,684✔
50
  auto hdr = Convert<MpPage>(p);
87,342✔
51
  hdr->SetAllocated();
87,342✔
52
  hdr->page_size_ = size;
87,342✔
53
  hdr->off_ = 0;
87,342✔
54
  header_->region_size_.fetch_sub(hdr->page_size_);
87,342✔
55
  header_->total_alloc_.fetch_add(hdr->page_size_);
87,342✔
56
  return p + sizeof(MpPage);
87,342✔
57
}
58

59
OffsetPointer StackAllocator::AlignedAllocateOffset(size_t size,
×
60
                                                    size_t alignment) {
61
  throw ALIGNED_ALLOC_NOT_SUPPORTED.format();
×
62
}
63

64
OffsetPointer StackAllocator::ReallocateOffsetNoNullCheck(OffsetPointer p,
×
65
                                                          size_t new_size) {
66
  OffsetPointer new_p;
67
  void *src = Convert<void>(p);
×
68
  auto hdr = Convert<MpPage>(p - sizeof(MpPage));
×
69
  size_t old_size = hdr->page_size_ - sizeof(MpPage);
×
70
  void *dst = AllocatePtr<void, OffsetPointer>(new_size, new_p);
×
71
  memcpy((void*)dst, (void*)src, old_size);
×
72
  Free(p);
×
73
  return new_p;
×
74
}
75

76
void StackAllocator::FreeOffsetNoNullCheck(OffsetPointer p) {
×
77
  auto hdr = Convert<MpPage>(p - sizeof(MpPage));
×
78
  if (!hdr->IsAllocated()) {
×
79
    throw DOUBLE_FREE.format();
×
80
  }
81
  hdr->UnsetAllocated();
×
82
  header_->total_alloc_.fetch_sub(hdr->page_size_);
×
83
}
×
84

85
}  // 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

© 2025 Coveralls, Inc