xo-alloc2: add guard-byte spans to AllocInfo

This commit is contained in:
Roland Conybeare 2025-12-16 21:43:51 -05:00
commit 5a5de795c1
8 changed files with 231 additions and 175 deletions

View file

@ -168,7 +168,8 @@ namespace xo {
//retval.checkpoint_ = lo_;
/** make sure guard size is aligned **/
config_.guard_z_ = padding::with_padding(config_.guard_z_);
config_.header_.guard_z_
= padding::with_padding(config_.header_.guard_z_);
}
DArena::DArena(DArena && other) {
@ -272,7 +273,17 @@ namespace xo {
this->reserved());
}
return AllocInfo(&config_.header_, (AllocHeader *)header_mem);
AllocHeader * header = (AllocHeader *)header_mem;
const byte * guard_lo
= header_mem - config_.header_.guard_z_;
const byte * guard_hi
= mem + config_.header_.size(*header);
return AllocInfo(&config_.header_,
guard_lo,
(AllocHeader *)header_mem,
guard_hi);
}
void

View file

@ -63,30 +63,6 @@ namespace xo {
IAllocator_DArena::alloc_info(DArena & s, value_type mem) noexcept
{
return s.alloc_info(mem);
if (!s.config_.store_header_flag_) [[unlikely]] {
++(s.error_count_);
s.last_error_ = AllocError(error::alloc_info_disabled,
s.error_count_,
0 /*add_commit_z*/,
s.committed_z_,
reserved(s));
return AllocInfo::error_not_configured(&s.config_.header_);
}
byte * header_mem = mem - sizeof(AllocHeader);
if (!s.contains(header_mem)) {
++(s.error_count_);
s.last_error_ = AllocError(error::alloc_info_address,
s.error_count_,
0 /*add_commit_z*/,
s.committed_z_,
reserved(s));
}
return AllocInfo(&s.config_.header_, (AllocHeader*)header_mem);
}
bool
@ -163,15 +139,14 @@ namespace xo {
s.committed_z_ = aligned_target_z;
s.limit_ = s.lo_ + s.committed_z_;
if (commit_start == s.lo_) [[unlikely]]
{
/* first expand() for this allocator - start with guard_z_ bytes */
if (commit_start == s.lo_) [[unlikely]] {
/* first expand() for this allocator - start with guard_z_ bytes */
::memset(s.free_,
s.config_.guard_byte_,
s.config_.guard_z_);
s.config_.header_.guard_byte_,
s.config_.header_.guard_z_);
s.free_ += s.config_.guard_z_;
s.free_ += s.config_.header_.guard_z_;
}
assert(s.committed_z_ % s.config_.hugepage_z_ == 0);
@ -403,10 +378,10 @@ namespace xo {
if (store_guard) {
/* write guard bytes for overrun detection */
::memset(s.free_,
s.config_.guard_byte_,
s.config_.guard_z_);
s.config_.header_.guard_byte_,
s.config_.header_.guard_z_);
s.free_ += s.config_.guard_z_;
s.free_ += s.config_.header_.guard_z_;
}
log && log(xtag("self", s.config_.name_),