forked from enlightenment/efl
eo: remove stack->max_size
- define EO_CALL_STACK_SIZE instead of stack->max_size - we are talking about size here not maxsize
This commit is contained in:
parent
dc3add048f
commit
88c5996dc1
|
@ -273,6 +273,8 @@ typedef struct _Eo_Stack_Frame
|
||||||
void *obj_data;
|
void *obj_data;
|
||||||
} Eo_Stack_Frame;
|
} Eo_Stack_Frame;
|
||||||
|
|
||||||
|
#define EO_CALL_STACK_SIZE (EO_CALL_STACK_DEPTH_MIN * sizeof(Eo_Stack_Frame))
|
||||||
|
|
||||||
static Eina_TLS _eo_call_stack_key = 0;
|
static Eina_TLS _eo_call_stack_key = 0;
|
||||||
|
|
||||||
typedef struct _Eo_Call_Stack {
|
typedef struct _Eo_Call_Stack {
|
||||||
|
@ -280,20 +282,19 @@ typedef struct _Eo_Call_Stack {
|
||||||
Eo_Stack_Frame *frame_ptr;
|
Eo_Stack_Frame *frame_ptr;
|
||||||
Eo_Stack_Frame *last_frame;
|
Eo_Stack_Frame *last_frame;
|
||||||
Eo_Stack_Frame *shrink_frame;
|
Eo_Stack_Frame *shrink_frame;
|
||||||
size_t max_size;
|
|
||||||
} Eo_Call_Stack;
|
} Eo_Call_Stack;
|
||||||
|
|
||||||
#define MEM_PAGE_SIZE 4096
|
#define MEM_PAGE_SIZE 4096
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
_eo_call_stack_mem_alloc(size_t maxsize)
|
_eo_call_stack_mem_alloc(size_t size)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
// allocate eo call stack via mmped anon segment if on linux - more
|
// allocate eo call stack via mmped anon segment if on linux - more
|
||||||
// secure and safe. also gives page aligned memory allowing madvise
|
// secure and safe. also gives page aligned memory allowing madvise
|
||||||
void *ptr;
|
void *ptr;
|
||||||
size_t newsize;
|
size_t newsize;
|
||||||
newsize = MEM_PAGE_SIZE * ((maxsize + MEM_PAGE_SIZE - 1) /
|
newsize = MEM_PAGE_SIZE * ((size + MEM_PAGE_SIZE - 1) /
|
||||||
MEM_PAGE_SIZE);
|
MEM_PAGE_SIZE);
|
||||||
ptr = mmap(NULL, newsize, PROT_READ | PROT_WRITE,
|
ptr = mmap(NULL, newsize, PROT_READ | PROT_WRITE,
|
||||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||||
|
@ -305,26 +306,26 @@ _eo_call_stack_mem_alloc(size_t maxsize)
|
||||||
return ptr;
|
return ptr;
|
||||||
#else
|
#else
|
||||||
//in regular cases just use malloc
|
//in regular cases just use malloc
|
||||||
return calloc(1, maxsize);
|
return calloc(1, size);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
static void
|
static void
|
||||||
_eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize, size_t maxsize)
|
_eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize, size_t size)
|
||||||
{
|
{
|
||||||
// resize call stack down - currently won't ever be called
|
// resize call stack down - currently won't ever be called
|
||||||
if (newsize > maxsize)
|
if (newsize > size)
|
||||||
{
|
{
|
||||||
CRI("eo call stack overflow, abort.");
|
CRI("eo call stack overflow, abort.");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
size_t addr = MEM_PAGE_SIZE * ((newsize + MEM_PAGE_SIZE - 1) /
|
size_t addr = MEM_PAGE_SIZE * ((newsize + MEM_PAGE_SIZE - 1) /
|
||||||
MEM_PAGE_SIZE);
|
MEM_PAGE_SIZE);
|
||||||
madvise(((unsigned char *)*ptr) + addr, maxsize - addr, MADV_DONTNEED);
|
madvise(((unsigned char *)*ptr) + addr, size - addr, MADV_DONTNEED);
|
||||||
#else
|
#else
|
||||||
static void
|
static void
|
||||||
_eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize EINA_UNUSED, size_t maxsize EINA_UNUSED)
|
_eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize EINA_UNUSED, size_t size EINA_UNUSED)
|
||||||
{
|
{
|
||||||
// just grow in regular cases
|
// just grow in regular cases
|
||||||
#endif
|
#endif
|
||||||
|
@ -332,13 +333,13 @@ _eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize EINA_UNUSED, si
|
||||||
|
|
||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
static void
|
static void
|
||||||
_eo_call_stack_mem_free(void *ptr, size_t maxsize)
|
_eo_call_stack_mem_free(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
// free mmaped memory
|
// free mmaped memory
|
||||||
munmap(ptr, maxsize);
|
munmap(ptr, size);
|
||||||
#else
|
#else
|
||||||
static void
|
static void
|
||||||
_eo_call_stack_mem_free(void *ptr, size_t maxsize EINA_UNUSED)
|
_eo_call_stack_mem_free(void *ptr, size_t size EINA_UNUSED)
|
||||||
{
|
{
|
||||||
// free regular memory
|
// free regular memory
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
@ -354,8 +355,7 @@ _eo_call_stack_create()
|
||||||
if (!stack)
|
if (!stack)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
stack->max_size = 8192 * sizeof(Eo_Stack_Frame);
|
stack->frames = _eo_call_stack_mem_alloc(EO_CALL_STACK_SIZE);
|
||||||
stack->frames = _eo_call_stack_mem_alloc(stack->max_size);
|
|
||||||
if (!stack->frames)
|
if (!stack->frames)
|
||||||
{
|
{
|
||||||
free(stack);
|
free(stack);
|
||||||
|
@ -378,7 +378,7 @@ _eo_call_stack_free(void *ptr)
|
||||||
if (!stack) return;
|
if (!stack) return;
|
||||||
|
|
||||||
if (stack->frames)
|
if (stack->frames)
|
||||||
_eo_call_stack_mem_free(stack->frames, stack->max_size);
|
_eo_call_stack_mem_free(stack->frames, EO_CALL_STACK_SIZE);
|
||||||
|
|
||||||
free(stack);
|
free(stack);
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,7 @@ _eo_call_stack_resize(Eo_Call_Stack *stack, Eina_Bool grow)
|
||||||
if (!grow)
|
if (!grow)
|
||||||
_eo_call_stack_mem_resize((void **)&(stack->frames),
|
_eo_call_stack_mem_resize((void **)&(stack->frames),
|
||||||
next_sz * sizeof(Eo_Stack_Frame),
|
next_sz * sizeof(Eo_Stack_Frame),
|
||||||
stack->max_size);
|
sz * sizeof(Eo_Stack_Frame));
|
||||||
if (!stack->frames)
|
if (!stack->frames)
|
||||||
{
|
{
|
||||||
CRI("unable to resize call stack, abort.");
|
CRI("unable to resize call stack, abort.");
|
||||||
|
|
Loading…
Reference in New Issue