-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsignal_stack.cc
52 lines (40 loc) · 1.13 KB
/
signal_stack.cc
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
42
43
44
45
46
47
48
49
50
51
52
#include "signal_stack.h"
#include <lace/try.h>
#include <lace/container_of.h>
#include <cassert>
namespace {
bool stack_is_current(const stack_t & self) {
stack_t test;
TRY(::sigaltstack, NULL, &test);
return true
&& test.ss_sp == self.ss_sp
&& test.ss_size == self.ss_size
;;
}
}
signal_stack::signal_stack() : cookie(NULL)
{
ss_sp = space;
ss_size = sizeof space;
ss_flags = 0;
assert(MINSIGSTKSZ <= ss_size);
TRY(::sigaltstack, static_cast<const stack_t*>(this), &save);
assert(this == ¤t());
}
signal_stack::~signal_stack() {
assert(stack_is_current(*this));
TRY_ABORT(::sigaltstack, &save, NULL);
memset(static_cast<stack_t*>(this), 0, sizeof(stack_t));
}
signal_stack &
signal_stack::current() {
stack_t test;
TRY(::sigaltstack, NULL, &test);
assert(test.ss_sp);
typedef typeof(signal_stack::space) space_t;
space_t & space = *reinterpret_cast<space_t*>(test.ss_sp);
return lace::container_of<signal_stack, space_t>(space, &signal_stack::space);
}
void * signal_stack::base() const { return ss_sp; }
std::size_t signal_stack::size() const { return ss_size; }
//