summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-23 10:43:36 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-23 10:43:36 +0200
commit88c5996dc16b6356ec03f9c4d0562203c6d0cb54 (patch)
tree03c6378b445d9d381b348cf10178992691ccb8a7
parentdc3add048f3bdf5e0ed4a138bba89e70d5e1c0c4 (diff)
eo: remove stack->max_size
- define EO_CALL_STACK_SIZE instead of stack->max_size - we are talking about size here not maxsize
-rw-r--r--src/lib/eo/eo.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 6b0834a..b27b221 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -273,6 +273,8 @@ typedef struct _Eo_Stack_Frame
273 void *obj_data; 273 void *obj_data;
274} Eo_Stack_Frame; 274} Eo_Stack_Frame;
275 275
276#define EO_CALL_STACK_SIZE (EO_CALL_STACK_DEPTH_MIN * sizeof(Eo_Stack_Frame))
277
276static Eina_TLS _eo_call_stack_key = 0; 278static Eina_TLS _eo_call_stack_key = 0;
277 279
278typedef struct _Eo_Call_Stack { 280typedef struct _Eo_Call_Stack {
@@ -280,20 +282,19 @@ typedef struct _Eo_Call_Stack {
280 Eo_Stack_Frame *frame_ptr; 282 Eo_Stack_Frame *frame_ptr;
281 Eo_Stack_Frame *last_frame; 283 Eo_Stack_Frame *last_frame;
282 Eo_Stack_Frame *shrink_frame; 284 Eo_Stack_Frame *shrink_frame;
283 size_t max_size;
284} Eo_Call_Stack; 285} Eo_Call_Stack;
285 286
286#define MEM_PAGE_SIZE 4096 287#define MEM_PAGE_SIZE 4096
287 288
288static void * 289static void *
289_eo_call_stack_mem_alloc(size_t maxsize) 290_eo_call_stack_mem_alloc(size_t size)
290{ 291{
291#ifdef HAVE_MMAP 292#ifdef HAVE_MMAP
292 // allocate eo call stack via mmped anon segment if on linux - more 293 // allocate eo call stack via mmped anon segment if on linux - more
293 // secure and safe. also gives page aligned memory allowing madvise 294 // secure and safe. also gives page aligned memory allowing madvise
294 void *ptr; 295 void *ptr;
295 size_t newsize; 296 size_t newsize;
296 newsize = MEM_PAGE_SIZE * ((maxsize + MEM_PAGE_SIZE - 1) / 297 newsize = MEM_PAGE_SIZE * ((size + MEM_PAGE_SIZE - 1) /
297 MEM_PAGE_SIZE); 298 MEM_PAGE_SIZE);
298 ptr = mmap(NULL, newsize, PROT_READ | PROT_WRITE, 299 ptr = mmap(NULL, newsize, PROT_READ | PROT_WRITE,
299 MAP_PRIVATE | MAP_ANON, -1, 0); 300 MAP_PRIVATE | MAP_ANON, -1, 0);
@@ -305,26 +306,26 @@ _eo_call_stack_mem_alloc(size_t maxsize)
305 return ptr; 306 return ptr;
306#else 307#else
307 //in regular cases just use malloc 308 //in regular cases just use malloc
308 return calloc(1, maxsize); 309 return calloc(1, size);
309#endif 310#endif
310} 311}
311 312
312#ifdef HAVE_MMAP 313#ifdef HAVE_MMAP
313static void 314static void
314_eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize, size_t maxsize) 315_eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize, size_t size)
315{ 316{
316 // resize call stack down - currently won't ever be called 317 // resize call stack down - currently won't ever be called
317 if (newsize > maxsize) 318 if (newsize > size)
318 { 319 {
319 CRI("eo call stack overflow, abort."); 320 CRI("eo call stack overflow, abort.");
320 abort(); 321 abort();
321 } 322 }
322 size_t addr = MEM_PAGE_SIZE * ((newsize + MEM_PAGE_SIZE - 1) / 323 size_t addr = MEM_PAGE_SIZE * ((newsize + MEM_PAGE_SIZE - 1) /
323 MEM_PAGE_SIZE); 324 MEM_PAGE_SIZE);
324 madvise(((unsigned char *)*ptr) + addr, maxsize - addr, MADV_DONTNEED); 325 madvise(((unsigned char *)*ptr) + addr, size - addr, MADV_DONTNEED);
325#else 326#else
326static void 327static void
327_eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize EINA_UNUSED, size_t maxsize EINA_UNUSED) 328_eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize EINA_UNUSED, size_t size EINA_UNUSED)
328{ 329{
329 // just grow in regular cases 330 // just grow in regular cases
330#endif 331#endif
@@ -332,13 +333,13 @@ _eo_call_stack_mem_resize(void **ptr EINA_UNUSED, size_t newsize EINA_UNUSED, si
332 333
333#ifdef HAVE_MMAP 334#ifdef HAVE_MMAP
334static void 335static void
335_eo_call_stack_mem_free(void *ptr, size_t maxsize) 336_eo_call_stack_mem_free(void *ptr, size_t size)
336{ 337{
337 // free mmaped memory 338 // free mmaped memory
338 munmap(ptr, maxsize); 339 munmap(ptr, size);
339#else 340#else
340static void 341static void
341_eo_call_stack_mem_free(void *ptr, size_t maxsize EINA_UNUSED) 342_eo_call_stack_mem_free(void *ptr, size_t size EINA_UNUSED)
342{ 343{
343 // free regular memory 344 // free regular memory
344 free(ptr); 345 free(ptr);
@@ -354,8 +355,7 @@ _eo_call_stack_create()
354 if (!stack) 355 if (!stack)
355 return NULL; 356 return NULL;
356 357
357 stack->max_size = 8192 * sizeof(Eo_Stack_Frame); 358 stack->frames = _eo_call_stack_mem_alloc(EO_CALL_STACK_SIZE);
358 stack->frames = _eo_call_stack_mem_alloc(stack->max_size);
359 if (!stack->frames) 359 if (!stack->frames)
360 { 360 {
361 free(stack); 361 free(stack);
@@ -378,7 +378,7 @@ _eo_call_stack_free(void *ptr)
378 if (!stack) return; 378 if (!stack) return;
379 379
380 if (stack->frames) 380 if (stack->frames)
381 _eo_call_stack_mem_free(stack->frames, stack->max_size); 381 _eo_call_stack_mem_free(stack->frames, EO_CALL_STACK_SIZE);
382 382
383 free(stack); 383 free(stack);
384} 384}
@@ -430,7 +430,7 @@ _eo_call_stack_resize(Eo_Call_Stack *stack, Eina_Bool grow)
430 if (!grow) 430 if (!grow)
431 _eo_call_stack_mem_resize((void **)&(stack->frames), 431 _eo_call_stack_mem_resize((void **)&(stack->frames),
432 next_sz * sizeof(Eo_Stack_Frame), 432 next_sz * sizeof(Eo_Stack_Frame),
433 stack->max_size); 433 sz * sizeof(Eo_Stack_Frame));
434 if (!stack->frames) 434 if (!stack->frames)
435 { 435 {
436 CRI("unable to resize call stack, abort."); 436 CRI("unable to resize call stack, abort.");