8 #ifndef LIBNEXUS_RV_RETURN_STACK_H
9 #define LIBNEXUS_RV_RETURN_STACK_H
15 #define NEXUS_RV_RETSTACK_DEFAULT 32
27 stack->end = stack->used = 0;
28 stack->max = stack->size = max;
29 if (max > NEXUS_RV_RETSTACK_DEFAULT)
30 stack->size = NEXUS_RV_RETSTACK_DEFAULT;
31 stack->entries = NULL;
34 stack->entries = (uint64_t*)malloc(
35 sizeof(stack->entries[0]) * stack->size);
43 stack->entries = NULL;
56 if (stack->size == stack->max)
58 assert(stack->used == stack->end);
59 if (stack->used != stack->size)
61 unsigned newsize = stack->size * 2;
62 if (newsize > stack->max)
64 void *newptr = realloc(stack->entries,
65 sizeof(stack->entries[0]) * newsize);
68 stack->size = newsize;
69 stack->entries = (uint64_t*)newptr;
75 if (stack->used == stack->max)
77 int rc = nexusrv_retstack_may_enlarge(stack);
80 if (stack->end == stack->size)
82 stack->entries[stack->end++] = addr;
83 if (stack->used < stack->size)
91 return -nexus_trace_retstack_empty;
93 *addr = stack->entries[--stack->end];
95 if (!stack->end && stack->used)
96 stack->end = stack->size;
100 #undef NEXUS_RV_RETSTACK_DEFAULT
Definition: return-stack.h:17