// Copy the message buffer so that we could start logging without holding a
// lock that gets aquired during printing.
- InternalScopedBuffer<char> buffer_copy(kErrorMessageBufferSize);
+ InternalMmapVector<char> buffer_copy(kErrorMessageBufferSize);
{
BlockingMutexLock l(&error_message_buf_mutex);
internal_memcpy(buffer_copy.data(),
internal_prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
// Set up a signal handler on an alternate stack for safety.
- InternalScopedBuffer<char> StackMap(SigAltStackSize);
+ InternalMmapVector<char> StackMap(SigAltStackSize);
stack_t SigAltStack;
SigAltStack.ss_sp = StackMap.data();
SigAltStack.ss_size = SigAltStackSize;
if (!ai.is_store && !ai.is_load)
return false;
- InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
+ InternalMmapVector<BufferedStackTrace> stack_buffer(1);
BufferedStackTrace *stack = stack_buffer.data();
stack->Reset();
SignalContext sig{info, uc};
// Scans thread data (stacks and TLS) for heap pointers.
static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
Frontier *frontier) {
- InternalScopedBuffer<uptr> registers(suspended_threads.RegisterCount());
+ InternalMmapVector<uptr> registers(suspended_threads.RegisterCount());
uptr registers_begin = reinterpret_cast<uptr>(registers.data());
uptr registers_end =
reinterpret_cast<uptr>(registers.data() + registers.size());
class InternalMmapVector : public InternalMmapVectorNoCtor<T> {
public:
InternalMmapVector() { InternalMmapVectorNoCtor<T>::Initialize(1); }
+ explicit InternalMmapVector(uptr cnt) {
+ InternalMmapVectorNoCtor<T>::Initialize(cnt);
+ this->resize(cnt);
+ }
~InternalMmapVector() { InternalMmapVectorNoCtor<T>::Destroy(); }
// Disallow copies and moves.
InternalMmapVector(const InternalMmapVector &) = delete;
InternalMmapVector &operator=(InternalMmapVector &&) = delete;
};
-// InternalScopedBuffer can be used instead of large stack arrays to
-// keep frame size low.
-// FIXME: use InternalAlloc instead of MmapOrDie once
-// InternalAlloc is made libc-free.
-template <typename T>
-class InternalScopedBuffer : public InternalMmapVector<T> {
- public:
- explicit InternalScopedBuffer(uptr cnt) : InternalMmapVector<T>() {
- this->resize(cnt);
- }
-};
-
-class InternalScopedString : public InternalScopedBuffer<char> {
+class InternalScopedString : public InternalMmapVector<char> {
public:
explicit InternalScopedString(uptr max_length)
- : InternalScopedBuffer<char>(max_length), length_(0) {
+ : InternalMmapVector<char>(max_length), length_(0) {
(*this)[0] = '\0';
}
uptr length() { return length_; }
if (!path)
return nullptr;
uptr name_len = internal_strlen(name);
- InternalScopedBuffer<char> buffer(kMaxPathLength);
+ InternalMmapVector<char> buffer(kMaxPathLength);
const char *beg = path;
while (true) {
const char *end = internal_strchrnul(beg, kPathSeparator);
int pid_;
int descriptor_;
- InternalScopedBuffer<char> buffer_;
+ InternalMmapVector<char> buffer_;
bool error_;
struct linux_dirent* entry_;
int bytes_read_;
uptr fd = internal_open("/sys/devices/system/cpu", O_RDONLY | O_DIRECTORY);
if (internal_iserror(fd))
return 0;
- InternalScopedBuffer<u8> buffer(4096);
+ InternalMmapVector<u8> buffer(4096);
uptr bytes_read = buffer.size();
uptr n_cpus = 0;
u8 *d_type;
thread_suspender_instance = &thread_suspender;
// Alternate stack for signal handling.
- InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
+ InternalMmapVector<char> handler_stack_memory(kHandlerStackSize);
stack_t handler_stack;
internal_memset(&handler_stack, 0, sizeof(handler_stack));
handler_stack.ss_sp = handler_stack_memory.data();
ScopedErrorReportLock l;
SanitizerCommonDecorator d;
- InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
+ InternalMmapVector<BufferedStackTrace> stack_buffer(1);
BufferedStackTrace *stack = stack_buffer.data();
stack->Reset();
uptr top = 0;
SanitizerToolName, kDescription, (void *)sig.addr, (void *)sig.pc,
(void *)sig.bp, (void *)sig.sp, tid);
Printf("%s", d.Default());
- InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
+ InternalMmapVector<BufferedStackTrace> stack_buffer(1);
BufferedStackTrace *stack = stack_buffer.data();
stack->Reset();
unwind(sig, unwind_context, stack);
Report("Hint: address points to the zero page.\n");
}
MaybeReportNonExecRegion(sig.pc);
- InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
+ InternalMmapVector<BufferedStackTrace> stack_buffer(1);
BufferedStackTrace *stack = stack_buffer.data();
stack->Reset();
unwind(sig, unwind_context, stack);
void *map = acquire_my_map_info_list();
CHECK(map);
- InternalScopedBuffer<backtrace_frame_t> frames(kStackTraceMax);
+ InternalMmapVector<backtrace_frame_t> frames(kStackTraceMax);
// siginfo argument appears to be unused.
sptr res = unwind_backtrace_signal_arch(/* siginfo */ 0, context, map,
frames.data(),
modules.init();
uptr num_modules = modules.size();
- InternalScopedBuffer<ModuleInfo> module_infos(num_modules);
+ InternalMmapVector<ModuleInfo> module_infos(num_modules);
for (size_t i = 0; i < num_modules; ++i) {
module_infos[i].filepath = modules[i].full_name();
module_infos[i].base_address = modules[i].ranges().front()->beg;
TEST(Allocator, ScopedBuffer) {
const int kSize = 512;
{
- InternalScopedBuffer<int> int_buf(kSize);
+ InternalMmapVector<int> int_buf(kSize);
EXPECT_EQ((uptr)kSize, int_buf.size()); // NOLINT
}
- InternalScopedBuffer<char> char_buf(kSize);
+ InternalMmapVector<char> char_buf(kSize);
EXPECT_EQ((uptr)kSize, char_buf.size()); // NOLINT
internal_memset(char_buf.data(), 'c', kSize);
for (int i = 0; i < kSize; i++) {
}
void OpenStatsFile(const char *path_env) {
- InternalScopedBuffer<char> path(kMaxPathLength);
+ InternalMmapVector<char> path(kMaxPathLength);
SubstituteForFlagValue(path_env, path.data(), kMaxPathLength);
error_t err;
fd_t fd = openrv;
// Fill the file with kShadowRodata.
const uptr kMarkerSize = 512 * 1024 / sizeof(u64);
- InternalScopedBuffer<u64> marker(kMarkerSize);
+ InternalMmapVector<u64> marker(kMarkerSize);
// volatile to prevent insertion of memset
for (volatile u64 *p = marker.data(); p < marker.data() + kMarkerSize; p++)
*p = kShadowRodata;
uptr n_threads;
uptr n_running_threads;
ctx->thread_registry->GetNumberOfThreads(&n_threads, &n_running_threads);
- InternalScopedBuffer<char> buf(4096);
+ InternalMmapVector<char> buf(4096);
WriteMemoryProfile(buf.data(), buf.size(), n_threads, n_running_threads);
WriteToFile(fd, buf.data(), internal_strlen(buf.data()));
}