libcopp  1.1.0
stack_allocator_split_segment.cpp
Go to the documentation of this file.
1 extern "C" {
2 #include <signal.h>
3 }
4 
5 #include <algorithm>
6 #include <assert.h>
7 #include <cstring>
8 #include <limits>
9 
10 
15 
16 
17 #ifdef LIBCOPP_MACRO_USE_SEGMENTED_STACKS
18 extern "C" {
19 void *__splitstack_makecontext(std::size_t, void * [COPP_MACRO_SEGMENTED_STACK_NUMBER], std::size_t *);
20 
21 void __splitstack_releasecontext(void * [COPP_MACRO_SEGMENTED_STACK_NUMBER]);
22 
23 void __splitstack_resetcontext(void * [COPP_MACRO_SEGMENTED_STACK_NUMBER]);
24 
25 void __splitstack_block_signals_context(void * [COPP_MACRO_SEGMENTED_STACK_NUMBER], int *new_value, int *old_value);
26 }
27 #endif
28 
29 #ifdef COPP_HAS_ABI_HEADERS
30 #include COPP_ABI_PREFIX
31 #endif
32 
33 namespace copp {
34  namespace allocator {
35 
37 
39 
40  void stack_allocator_split_segment::allocate(stack_context &ctx, std::size_t size) UTIL_CONFIG_NOEXCEPT {
41  void *start_ptr = __splitstack_makecontext(size, ctx.segments_ctx, &ctx.size);
42  assert(start_ptr);
43  if (!start_ptr) {
44  ctx.sp = NULL;
45  return;
46  }
47 
48  ctx.sp = static_cast<char *>(start_ptr) + ctx.size; // stack down
49 
50  int off = 0;
51  __splitstack_block_signals_context(ctx.segments_ctx, &off, 0);
52  }
53 
54  void stack_allocator_split_segment::deallocate(stack_context &ctx) UTIL_CONFIG_NOEXCEPT {
55  __splitstack_releasecontext(ctx.segments_ctx);
56  }
57  }
58 }
59 
60 #ifdef COPP_HAS_ABI_HEADERS
61 #include COPP_ABI_SUFFIX
62 #endif
void allocate(stack_context &, std::size_t) UTIL_CONFIG_NOEXCEPT
void deallocate(stack_context &) UTIL_CONFIG_NOEXCEPT