2016-03-29 06:47:22 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2018-01-11 09:59:34 -08:00
|
|
|
#ifdef HAVE_VALGRIND
|
|
|
|
# include <valgrind.h>
|
|
|
|
# include <memcheck.h>
|
|
|
|
#endif
|
|
|
|
|
2016-03-29 06:47:22 -07:00
|
|
|
#if defined HAVE_DLADDR && ! defined _WIN32
|
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Eina.h>
|
|
|
|
|
|
|
|
#include "eo_ptr_indirection.h"
|
|
|
|
#include "eo_private.h"
|
|
|
|
|
|
|
|
#include "eo_add_fallback.h"
|
|
|
|
|
|
|
|
// 1024 entries == 16k or 32k (32 or 64bit) for eo call stack. that's 1023
|
|
|
|
// imbricated/recursive calls it can handle before barfing. i'd say that's ok
|
2016-08-15 06:44:41 -07:00
|
|
|
#define EFL_OBJECT_CALL_STACK_DEPTH_MIN 1024
|
2016-03-29 06:47:22 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
typedef struct _Efl_Object_Call_Stack {
|
2016-03-29 06:47:22 -07:00
|
|
|
Eo_Stack_Frame *frames;
|
|
|
|
Eo_Stack_Frame *frame_ptr;
|
2016-08-15 06:44:41 -07:00
|
|
|
} Efl_Object_Call_Stack;
|
2016-03-29 06:47:22 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
#define EFL_OBJECT_CALL_STACK_SIZE (EFL_OBJECT_CALL_STACK_DEPTH_MIN * sizeof(Eo_Stack_Frame))
|
2016-03-29 06:47:22 -07:00
|
|
|
|
|
|
|
static Eina_TLS _eo_call_stack_key = 0;
|
|
|
|
|
|
|
|
#define MEM_PAGE_SIZE 4096
|
|
|
|
|
|
|
|
static void *
|
|
|
|
_eo_call_stack_mem_alloc(size_t size)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_MMAP
|
2018-01-11 09:59:34 -08:00
|
|
|
# ifdef HAVE_VALGRIND
|
|
|
|
if (RUNNING_ON_VALGRIND) return calloc(1, size);
|
|
|
|
else
|
|
|
|
# endif
|
2016-03-29 06:47:22 -07:00
|
|
|
{
|
2018-01-11 09:59:34 -08:00
|
|
|
// allocate eo call stack via mmped anon segment if on linux - more
|
|
|
|
// secure and safe. also gives page aligned memory allowing madvise
|
|
|
|
void *ptr;
|
|
|
|
size_t newsize;
|
|
|
|
newsize = MEM_PAGE_SIZE * ((size + MEM_PAGE_SIZE - 1) /
|
|
|
|
MEM_PAGE_SIZE);
|
|
|
|
ptr = mmap(NULL, newsize, PROT_READ | PROT_WRITE,
|
|
|
|
MAP_PRIVATE | MAP_ANON, -1, 0);
|
|
|
|
if (ptr == MAP_FAILED)
|
|
|
|
{
|
|
|
|
ERR("eo call stack mmap failed.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ptr;
|
2016-03-29 06:47:22 -07:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
//in regular cases just use malloc
|
|
|
|
return calloc(1, size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eo_call_stack_mem_free(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_MMAP
|
2018-01-11 09:59:34 -08:00
|
|
|
# ifdef HAVE_VALGRIND
|
|
|
|
if (RUNNING_ON_VALGRIND) free(ptr);
|
|
|
|
else
|
|
|
|
# endif
|
2016-03-29 06:47:22 -07:00
|
|
|
munmap(ptr, size);
|
|
|
|
#else
|
|
|
|
(void) size;
|
|
|
|
free(ptr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
static Efl_Object_Call_Stack *
|
2016-12-06 05:33:24 -08:00
|
|
|
_eo_call_stack_create(void)
|
2016-03-29 06:47:22 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Object_Call_Stack *stack;
|
2016-03-29 06:47:22 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
stack = calloc(1, sizeof(Efl_Object_Call_Stack));
|
2016-03-29 06:47:22 -07:00
|
|
|
if (!stack)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
stack->frames = _eo_call_stack_mem_alloc(EFL_OBJECT_CALL_STACK_SIZE);
|
2016-03-29 06:47:22 -07:00
|
|
|
if (!stack->frames)
|
|
|
|
{
|
|
|
|
free(stack);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// first frame is never used
|
|
|
|
stack->frame_ptr = stack->frames;
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_eo_call_stack_free(void *ptr)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Object_Call_Stack *stack = (Efl_Object_Call_Stack *) ptr;
|
2016-03-29 06:47:22 -07:00
|
|
|
|
|
|
|
if (!stack) return;
|
|
|
|
|
|
|
|
if (stack->frames)
|
2016-08-15 06:44:41 -07:00
|
|
|
_eo_call_stack_mem_free(stack->frames, EFL_OBJECT_CALL_STACK_SIZE);
|
2016-03-29 06:47:22 -07:00
|
|
|
|
|
|
|
free(stack);
|
|
|
|
}
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
static Efl_Object_Call_Stack *main_loop_stack = NULL;
|
2016-03-29 06:47:22 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
#define _EFL_OBJECT_CALL_STACK_GET() ((EINA_LIKELY(eina_main_loop_is())) ? main_loop_stack : _eo_call_stack_get_thread())
|
2016-03-29 06:47:22 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
static inline Efl_Object_Call_Stack *
|
2016-03-29 06:47:22 -07:00
|
|
|
_eo_call_stack_get_thread(void)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Object_Call_Stack *stack = eina_tls_get(_eo_call_stack_key);
|
2016-03-29 06:47:22 -07:00
|
|
|
|
|
|
|
if (stack) return stack;
|
|
|
|
|
|
|
|
stack = _eo_call_stack_create();
|
|
|
|
eina_tls_set(_eo_call_stack_key, stack);
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
eo: Rename EAPI macro to EO_API in Eo library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
= The Rationale =
This patch is from a series of patches to rename EAPI symbols to
specific library DSOs.
EAPI was designed to be able to pass
`__attribute__ ((visibility ("default")))` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
`__atttribute__((visibility("default")))`.
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
LIBAPI is the only solution that works for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Reviewers: jptiz, lucas, vtorri, woohyun
Reviewed By: jptiz, lucas, vtorri
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12203
2020-12-09 08:50:29 -08:00
|
|
|
EO_API Eo *
|
2016-09-05 08:57:35 -07:00
|
|
|
_efl_added_get(void)
|
2016-03-29 06:47:22 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
return _EFL_OBJECT_CALL_STACK_GET()->frame_ptr->obj;
|
2016-03-29 06:47:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Eo_Stack_Frame *
|
2016-08-15 06:44:41 -07:00
|
|
|
_efl_add_fallback_stack_push(Eo *obj)
|
2016-03-29 06:47:22 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Object_Call_Stack *stack = _EFL_OBJECT_CALL_STACK_GET();
|
|
|
|
if (stack->frame_ptr == (stack->frames + EFL_OBJECT_CALL_STACK_DEPTH_MIN))
|
2016-03-29 06:47:22 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
CRI("efl_add fallback stack overflow.");
|
2016-03-29 06:47:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
stack->frame_ptr++;
|
|
|
|
stack->frame_ptr->obj = obj;
|
|
|
|
|
|
|
|
return stack->frame_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eo_Stack_Frame *
|
2016-08-15 06:44:41 -07:00
|
|
|
_efl_add_fallback_stack_pop(void)
|
2016-03-29 06:47:22 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Object_Call_Stack *stack = _EFL_OBJECT_CALL_STACK_GET();
|
2016-03-29 06:47:22 -07:00
|
|
|
if (stack->frame_ptr == stack->frames)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
CRI("efl_add fallback stack underflow.");
|
2016-03-29 06:47:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
stack->frame_ptr--;
|
|
|
|
|
|
|
|
return stack->frame_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
2016-08-15 06:44:41 -07:00
|
|
|
_efl_add_fallback_init(void)
|
2016-03-29 06:47:22 -07:00
|
|
|
{
|
|
|
|
if (_eo_call_stack_key != 0)
|
|
|
|
WRN("_eo_call_stack_key already set, this should not happen.");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!eina_tls_cb_new(&_eo_call_stack_key, _eo_call_stack_free))
|
|
|
|
{
|
|
|
|
EINA_LOG_ERR("Could not create TLS key for call stack.");
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main_loop_stack = _eo_call_stack_create();
|
|
|
|
if (!main_loop_stack)
|
|
|
|
{
|
|
|
|
EINA_LOG_ERR("Could not alloc eo call stack.");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
2016-08-15 06:44:41 -07:00
|
|
|
_efl_add_fallback_shutdown(void)
|
2016-03-29 06:47:22 -07:00
|
|
|
{
|
|
|
|
if (_eo_call_stack_key != 0)
|
|
|
|
{
|
|
|
|
eina_tls_free(_eo_call_stack_key);
|
|
|
|
_eo_call_stack_key = 0;
|
|
|
|
}
|
|
|
|
|
2016-11-22 22:24:02 -08:00
|
|
|
_eo_call_stack_free(main_loop_stack);
|
|
|
|
main_loop_stack = NULL;
|
|
|
|
|
2016-03-29 06:47:22 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|