aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/rain_check/core/coro_stack.cpp
blob: 96ab66865c562b883280c8da03e0c3ac9f2b636e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "coro_stack.h"

#include <util/generic/singleton.h>
#include <util/system/valgrind.h>

#include <cstdlib>
#include <stdio.h>

using namespace NRainCheck;
using namespace NRainCheck::NPrivate;

TCoroStack::TCoroStack(size_t size)
    : SizeValue(size)
{
    Y_ABORT_UNLESS(size % sizeof(ui32) == 0);
    Y_ABORT_UNLESS(size >= 0x1000);

    DataHolder.Reset(malloc(size));

    // register in valgrind

    *MagicNumberLocation() = MAGIC_NUMBER;

#if defined(WITH_VALGRIND)
    ValgrindStackId = VALGRIND_STACK_REGISTER(Data(), (char*)Data() + Size());
#endif
}

TCoroStack::~TCoroStack() {
#if defined(WITH_VALGRIND)
    VALGRIND_STACK_DEREGISTER(ValgrindStackId);
#endif

    VerifyNoStackOverflow();
}

void TCoroStack::FailStackOverflow() {
    static const char message[] = "stack overflow\n";
    fputs(message, stderr);
    abort();
}