Rather than always zeroing memory.
headerSize, tabSize, confirmTmp.size(), floodControlTmp.size(),
size);
- auto fdr = make_bytecode_ptr<FDR>(size, 64);
+ auto fdr = make_zeroed_bytecode_ptr<FDR>(size, 64);
assert(fdr); // otherwise would have thrown std::bad_alloc
fdr->size = size;
sizeof(LitInfo) * lits.size() + totalLitSize;
size = ROUNDUP_N(size, alignof(FDRConfirm));
- auto fdrc = make_bytecode_ptr<FDRConfirm>(size);
+ auto fdrc = make_zeroed_bytecode_ptr<FDRConfirm>(size);
assert(fdrc); // otherwise would have thrown std::bad_alloc
fdrc->andmsk = andmsk;
u32 totalConfSwitchSize = nBuckets * sizeof(u32);
u32 totalSize = ROUNDUP_16(totalConfSwitchSize + totalConfirmSize);
- auto buf = make_bytecode_ptr<u8>(totalSize, 16);
+ auto buf = make_zeroed_bytecode_ptr<u8>(totalSize, 16);
assert(buf); // otherwise would have thrown std::bad_alloc
u32 *confBase = (u32 *)buf.get();
size_t floodStructSize = sizeof(FDRFlood) * nDistinctFloods;
size_t totalSize = ROUNDUP_16(floodHeaderSize + floodStructSize);
- auto buf = make_bytecode_ptr<u8>(totalSize, 16);
+ auto buf = make_zeroed_bytecode_ptr<u8>(totalSize, 16);
assert(buf); // otherwise would have thrown std::bad_alloc
u32 *floodHeader = (u32 *)buf.get();
floodControlTmp.size(),
16 * maskWidth);
- auto fdr = make_bytecode_ptr<FDR>(size, 64);
+ auto fdr = make_zeroed_bytecode_ptr<FDR>(size, 64);
assert(fdr); // otherwise would have thrown std::bad_alloc
Teddy *teddy = (Teddy *)fdr.get(); // ugly
u8 *teddy_base = (u8 *)teddy;
throw ResourceLimitError();
}
- auto h = make_bytecode_ptr<HWLM>(ROUNDUP_CL(sizeof(HWLM)) + engSize, 64);
+ const size_t hwlm_len = ROUNDUP_CL(sizeof(HWLM)) + engSize;
+ auto h = make_zeroed_bytecode_ptr<HWLM>(hwlm_len, 64);
h->type = engType;
memcpy(HWLM_DATA(h.get()), eng.get(), engSize);
const auto &s = lit.s;
size_t noodle_len = sizeof(noodTable) + s.length();
- auto n = make_bytecode_ptr<noodTable>(noodle_len);
+ auto n = make_zeroed_bytecode_ptr<noodTable>(noodle_len);
assert(n);
size_t key_offset = findNoodFragOffset(lit);
total_size = ROUNDUP_N(total_size, alignof(mmbit_sparse_iter));
total_size += byte_length(stale_iter); // stale sparse iter
- auto nfa = make_bytecode_ptr<NFA>(total_size);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
nfa->type = verify_u8(CASTLE_NFA);
nfa->length = verify_u32(total_size);
nfa->nPositions = verify_u32(subs.size());
gi.stream_som_loc_width = somPrecision;
u32 gough_size = ROUNDUP_N(curr_offset, 16);
- auto gough_dfa = make_bytecode_ptr<NFA>(gough_size);
+ auto gough_dfa = make_zeroed_bytecode_ptr<NFA>(gough_size);
memcpy(gough_dfa.get(), basic_dfa.get(), basic_dfa->length);
memcpy((char *)gough_dfa.get() + haig_offset, &gi, sizeof(gi));
u32 tableOffset, tugMaskOffset;
size_t len = repeatAllocSize(br, &tableOffset, &tugMaskOffset);
- auto info = make_bytecode_ptr<NFARepeatInfo>(len);
+ auto info = make_zeroed_bytecode_ptr<NFARepeatInfo>(len);
char *info_ptr = (char *)info.get();
// Collect state space info.
size_t nfaSize = sizeof(NFA) + offset;
DEBUG_PRINTF("nfa size %zu\n", nfaSize);
- auto nfa = make_bytecode_ptr<NFA>(nfaSize);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(nfaSize);
assert(nfa); // otherwise we would have thrown std::bad_alloc
implNFA_t *limex = (implNFA_t *)getMutableImplNfa(nfa.get());
accel_offset -= sizeof(NFA); /* adj accel offset to be relative to m */
assert(ISALIGNED_N(accel_offset, alignof(union AccelAux)));
- auto nfa = make_bytecode_ptr<NFA>(total_size);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
char *nfa_base = (char *)nfa.get();
populateBasicInfo(sizeof(u16), info, total_size, aux_offset, accel_offset,
accel_offset -= sizeof(NFA); /* adj accel offset to be relative to m */
assert(ISALIGNED_N(accel_offset, alignof(union AccelAux)));
- auto nfa = bytecode_ptr<NFA>(total_size);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
char *nfa_base = (char *)nfa.get();
mcclellan *m = (mcclellan *)getMutableImplNfa(nfa.get());
accel_offset -= sizeof(NFA); /* adj accel offset to be relative to m */
assert(ISALIGNED_N(accel_offset, alignof(union AccelAux)));
- auto nfa = make_bytecode_ptr<NFA>(total_size);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
mcsheng *m = (mcsheng *)getMutableImplNfa(nfa.get());
populateBasicInfo(sizeof(u16), info, total_size, aux_offset, accel_offset,
accel_offset -= sizeof(NFA); /* adj accel offset to be relative to m */
assert(ISALIGNED_N(accel_offset, alignof(union AccelAux)));
- auto nfa = make_bytecode_ptr<NFA>(total_size);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
mcsheng *m = (mcsheng *)getMutableImplNfa(nfa.get());
allocateImplId8(info, sheng_end, accel_escape_info, &m->accel_limit_8,
DEBUG_PRINTF("%u puffs, len = %u\n", puffette_count, len);
- auto nfa = make_bytecode_ptr<NFA>(len);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(len);
mpv_puffette *pa_base = (mpv_puffette *)
((char *)nfa.get() + sizeof(NFA) + sizeof(mpv)
DEBUG_PRINTF("NFA: %u, aux: %u, reports: %u, accel: %u, total: %u\n",
nfa_size, total_aux, total_reports, total_accel, total_size);
- auto nfa = make_bytecode_ptr<NFA>(total_size);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
populateBasicInfo(nfa.get(), info, accelInfo, nfa_size, reports_offset,
accel_offset, total_size, total_size - sizeof(NFA));
// use subSize as a sentinel value for no active subengines,
// so add one to subSize here
u32 activeIdxSize = calcPackedBytes(subSize + 1);
- auto nfa = make_bytecode_ptr<NFA>(total_size);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(total_size);
nfa->type = verify_u8(TAMARAMA_NFA);
nfa->length = verify_u32(total_size);
nfa->queueIndex = queue;
}
size_t len = sizeof(NFA) + sizeof(LbrStruct) + sizeof(RepeatInfo) +
tableLen + sizeof(u64a);
- auto nfa = make_bytecode_ptr<NFA>(len);
+ auto nfa = make_zeroed_bytecode_ptr<NFA>(len);
nfa->type = verify_u8(nfa_type);
nfa->length = verify_u32(len);
return nfa;
throw ResourceLimitError();
}
- auto atable = make_bytecode_ptr<anchored_matcher_info>(total_size, 64);
+ auto atable =
+ make_zeroed_bytecode_ptr<anchored_matcher_info>(total_size, 64);
char *curr = (char *)atable.get();
u32 state_offset = 0;
const size_t smwrOffset = ROUNDUP_CL(mainSize);
const size_t newSize = smwrOffset + smallWriteSize;
- auto rose2 = make_bytecode_ptr<RoseEngine>(newSize, 64);
+ auto rose2 = make_zeroed_bytecode_ptr<RoseEngine>(newSize, 64);
char *ptr = (char *)rose2.get();
memcpy(ptr, rose.get(), mainSize);
memcpy(ptr + smwrOffset, smwr_engine.get(), smallWriteSize);
proto.size = currOffset;
// Time to allocate the real RoseEngine structure, at cacheline alignment.
- auto engine = make_bytecode_ptr<RoseEngine>(currOffset, 64);
+ auto engine = make_zeroed_bytecode_ptr<RoseEngine>(currOffset, 64);
assert(engine); // will have thrown bad_alloc otherwise.
// Copy in our prototype engine data.
}
u32 size = sizeof(SmallWriteEngine) + nfa->length;
- auto smwr = make_bytecode_ptr<SmallWriteEngine>(size);
+ auto smwr = make_zeroed_bytecode_ptr<SmallWriteEngine>(size);
smwr->size = size;
smwr->start_offset = start_offset;
if (!ptr) {
throw std::bad_alloc();
}
- std::memset(ptr.get(), 0, bytes);
}
bytecode_ptr(std::nullptr_t) {}
size_t alignment = 0; //!< Alignment of memory region in bytes.
};
+/**
+ * \brief Constructs a bytecode_ptr<T> with the given size and alignment.
+ */
template<typename T>
inline bytecode_ptr<T> make_bytecode_ptr(size_t size,
size_t align = alignof(T)) {
return bytecode_ptr<T>(size, align);
}
+/**
+ * \brief Constructs a bytecode_ptr<T> with the given size and alignment and
+ * fills the memory region with zeroes.
+ */
+template<typename T>
+inline bytecode_ptr<T> make_zeroed_bytecode_ptr(size_t size,
+ size_t align = alignof(T)) {
+ auto ptr = make_bytecode_ptr<T>(size, align);
+ std::memset(ptr.get(), 0, size);
+ return ptr;
+}
+
} // namespace ue2
#endif // UTIL_BYTECODE_PTR_H