Enlightenment CVS committal Author : raster Project : e17 Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore Modified Files: Tag: SPLIT ecore_events.c ecore_exe.c ecore_idle_enterer.c ecore_idler.c ecore_main.c ecore_private.h ecore_timer.c Log Message: "safe" interface. a rogue/bad app will find it REALLY hard to bring ecore down now. ecore does pointer AND magic number checks so it can safely abort using stale pointers (already freed, but ram is still valid in memory space) and getting NULL pointers from apps etc. since handles for timers, idlers etc. etc. are all pointers, this keeps stability up, at least on the ecore side of things. technically the app is STILL bad and has a fatal bug, but it wont necessarily crash strangely inside ecore (easily) due to the badness. this is also what evas does and seems to work wonders in preventing acciental segv's or wierd bugs during development. i need to make ecore "complain" bitterly next if the pointers are NULL or the types wrong. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Attic/ecore_events.c,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -3 -r1.1.2.3 -r1.1.2.4 --- ecore_events.c 23 Jan 2003 23:03:23 -0000 1.1.2.3 +++ ecore_events.c 23 Jan 2003 23:51:41 -0000 1.1.2.4 @@ -27,6 +27,7 @@ if ((type <= ECORE_EVENT_NONE) || (type >= event_id_max)) return NULL; eh = calloc(1, sizeof(Ecore_Event_Handler)); if (!eh) return NULL; + ECORE_MAGIC_SET(eh, ECORE_MAGIC_EVENT_HANDLER); eh->type = type; eh->func = func; eh->data = (void *)data; @@ -44,7 +45,7 @@ void * ecore_event_handler_del(Ecore_Event_Handler *event_handler) { - if (!event_handler) return NULL; + if (!ECORE_MAGIC_CHECK(event_handler, ECORE_MAGIC_EVENT_HANDLER)) return NULL; event_handler->delete_me = 1; event_handlers_delete_me = 1; return event_handler->data; @@ -66,6 +67,7 @@ if (!func_free) return NULL; if (!ev) return NULL; if (type <= ECORE_EVENT_NONE) return NULL; + if (type >= event_id_max) return NULL; return _ecore_event_add(type, ev, func_free, data); } @@ -79,7 +81,7 @@ void * ecore_event_del(Ecore_Event *event) { - if (!event) return NULL; + if (!ECORE_MAGIC_CHECK(event, ECORE_MAGIC_EVENT)) return NULL; event->delete_me = 1; return event->data; } @@ -111,6 +113,7 @@ e = calloc(1, sizeof(Ecore_Event)); if (!e) return NULL; + ECORE_MAGIC_SET(e, ECORE_MAGIC_EVENT); e->type = type; e->event = ev; e->func_free = func_free; @@ -128,6 +131,7 @@ data = event->data; event->func_free(event->event, event->data); events = _ecore_list_remove(events, event); + ECORE_MAGIC_SET(event, ECORE_MAGIC_NONE); free(event); events_num--; return data; @@ -173,6 +177,7 @@ if (eh->delete_me) { event_handlers = _ecore_list_remove(event_handlers, eh); + ECORE_MAGIC_SET(eh, ECORE_MAGIC_NONE); free(eh); } } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Attic/ecore_exe.c,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -3 -r1.1.2.3 -r1.1.2.4 --- ecore_exe.c 23 Jan 2003 23:03:23 -0000 1.1.2.3 +++ ecore_exe.c 23 Jan 2003 23:51:41 -0000 1.1.2.4 @@ -38,6 +38,7 @@ kill(pid, SIGKILL); return NULL; } + ECORE_MAGIC_SET(exe, ECORE_MAGIC_EXE); exe->pid = pid; exe->data = (void *)data; exes = _ecore_list_append(exes, exe); @@ -61,7 +62,7 @@ void * ecore_exe_free(Ecore_Exe *exe) { - if (!exe) return NULL; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return NULL; return _ecore_exe_free(exe); } @@ -75,7 +76,7 @@ pid_t ecore_exe_pid_get(Ecore_Exe *exe) { - if (!exe) return -1; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return -1; return exe->pid; } @@ -90,7 +91,7 @@ void * ecore_exe_data_get(Ecore_Exe *exe) { - if (!exe) return NULL; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return NULL; return exe->data; } @@ -103,7 +104,7 @@ void ecore_exe_pause(Ecore_Exe *exe) { - if (!exe) return; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return; kill(exe->pid, SIGSTOP); } @@ -116,7 +117,7 @@ void ecore_exe_continue(Ecore_Exe *exe) { - if (!exe) return; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return; kill(exe->pid, SIGCONT); } @@ -129,7 +130,7 @@ void ecore_exe_terminate(Ecore_Exe *exe) { - if (!exe) return; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return; kill(exe->pid, SIGTERM); } @@ -142,7 +143,7 @@ void ecore_exe_kill(Ecore_Exe *exe) { - if (!exe) return; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return; kill(exe->pid, SIGKILL); } @@ -155,7 +156,7 @@ void ecore_exe_signal(Ecore_Exe *exe, int num) { - if (!exe) return; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return; if (num == 1) kill(exe->pid, SIGUSR1); else if (num == 2) @@ -171,7 +172,7 @@ void ecore_exe_hup(Ecore_Exe *exe) { - if (!exe) return; + if (!ECORE_MAGIC_CHECK(exe, ECORE_MAGIC_EXE)) return; kill(exe->pid, SIGHUP); } @@ -197,6 +198,7 @@ data = exe->data; exes = _ecore_list_remove(exes, exe); + ECORE_MAGIC_SET(exe, ECORE_MAGIC_NONE); free(exe); return data; } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Attic/ecore_idle_enterer.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -3 -r1.1.2.2 -r1.1.2.3 --- ecore_idle_enterer.c 23 Jan 2003 23:03:23 -0000 1.1.2.2 +++ ecore_idle_enterer.c 23 Jan 2003 23:51:41 -0000 1.1.2.3 @@ -20,6 +20,7 @@ if (!func) return NULL; ie = calloc(1, sizeof(Ecore_Idle_Enterer)); if (!ie) return NULL; + ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLE_ENTERER); ie->func = func; ie->data = (void *)data; idle_enterers = _ecore_list_append(idle_enterers, ie); @@ -36,7 +37,7 @@ void * ecore_idle_enterer_del(Ecore_Idle_Enterer *idle_enterer) { - if (!idle_enterer) return NULL; + if (!ECORE_MAGIC_CHECK(idle_enterer, ECORE_MAGIC_IDLE_ENTERER)) return NULL; idle_enterer->delete_me = 1; idle_enterers_delete_me = 1; return idle_enterer->data; @@ -68,6 +69,7 @@ if (ie->delete_me) { idle_enterers = _ecore_list_remove(idle_enterers, ie); + ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE); free(ie); } } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Attic/ecore_idler.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -3 -r1.1.2.2 -r1.1.2.3 --- ecore_idler.c 23 Jan 2003 23:03:23 -0000 1.1.2.2 +++ ecore_idler.c 23 Jan 2003 23:51:41 -0000 1.1.2.3 @@ -20,6 +20,7 @@ if (!func) return NULL; ie = calloc(1, sizeof(Ecore_Idler)); if (!ie) return NULL; + ECORE_MAGIC_SET(ie, ECORE_MAGIC_IDLER); ie->func = func; ie->data = (void *)data; idlers = _ecore_list_append(idlers, ie); @@ -36,7 +37,7 @@ void * ecore_idler_del(Ecore_Idler *idler) { - if (!idler) return NULL; + if (!ECORE_MAGIC_CHECK(idler, ECORE_MAGIC_IDLER)) return NULL; idler->delete_me = 1; idlers_delete_me = 1; return idler->data; @@ -68,6 +69,7 @@ if (ie->delete_me) { idlers = _ecore_list_remove(idlers, ie); + ECORE_MAGIC_SET(ie, ECORE_MAGIC_NONE); free(ie); } } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Attic/ecore_main.c,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -3 -r1.1.2.3 -r1.1.2.4 --- ecore_main.c 23 Jan 2003 23:03:24 -0000 1.1.2.3 +++ ecore_main.c 23 Jan 2003 23:51:41 -0000 1.1.2.4 @@ -177,6 +177,7 @@ (!func)) return NULL; fdh = calloc(1, sizeof(Ecore_Fd_Handler)); if (!fdh) return NULL; + ECORE_MAGIC_SET(fdh, ECORE_MAGIC_FD_HANDLER); fdh->fd = fd; fdh->flags = flags; fdh->read_active = 0; @@ -201,7 +202,7 @@ void * ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler) { - if (!fd_handler) return NULL; + if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER)) return NULL; fd_handler->delete_me = 1; fd_handlers_delete_me = 1; return fd_handler->data; @@ -217,7 +218,7 @@ int ecore_main_fd_handler_fd_get(Ecore_Fd_Handler *fd_handler) { - if (!fd_handler) return -1; + if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER)) return -1; return fd_handler->fd; } @@ -234,7 +235,7 @@ { int ret; - if (!fd_handler) return 0; + if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER)) return 0; ret = 0; if ((flags & ECORE_FD_READ) && (fd_handler->read_active)) ret = 1; if ((flags & ECORE_FD_WRITE) && (fd_handler->write_active)) ret = 1; @@ -328,6 +329,7 @@ if (fdh->delete_me) { fd_handlers = _ecore_list_remove(fd_handlers, fdh); + ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE); free(fdh); } } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Attic/ecore_private.h,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -3 -r1.1.2.3 -r1.1.2.4 --- ecore_private.h 23 Jan 2003 23:03:24 -0000 1.1.2.3 +++ ecore_private.h 23 Jan 2003 23:51:41 -0000 1.1.2.4 @@ -15,6 +15,22 @@ }; typedef enum _Ecore_Fd_Handler_Flags Ecore_Fd_Handler_Flags; +#define ECORE_MAGIC_NONE 0x1234fedc +#define ECORE_MAGIC_EXE 0xf7e712f5 +#define ECORE_MAGIC_TIMER 0xf7d613f4 +#define ECORE_MAGIC_IDLER 0xf7c514f3 +#define ECORE_MAGIC_IDLE_ENTERER 0xf7b415f2 +#define ECORE_MAGIC_FD_HANDLER 0xf7a316f1 +#define ECORE_MAGIC_EVENT_HANDLER 0xf79217f0 +#define ECORE_MAGIC_EVENT 0xf78118ff + +#define ECORE_MAGIC Ecore_Magic __magic + +#define ECORE_MAGIC_SET(d, m) (d)->__magic = (m) +#define ECORE_MAGIC_CHECK(d, m) ((d) && ((d)->__magic == (m))) + +typedef int Ecore_Magic; + typedef struct _Ecore_List Ecore_List; typedef struct _Ecore_Exe Ecore_Exe; @@ -34,6 +50,7 @@ struct _Ecore_Exe { Ecore_List __list_data; + ECORE_MAGIC; pid_t pid; void *data; }; @@ -41,6 +58,7 @@ struct _Ecore_Timer { Ecore_List __list_data; + ECORE_MAGIC; double in; double at; int (*func) (void *data); @@ -50,6 +68,7 @@ struct _Ecore_Idler { Ecore_List __list_data; + ECORE_MAGIC; int delete_me : 1; int (*func) (void *data); void *data; @@ -58,6 +77,7 @@ struct _Ecore_Idle_Enterer { Ecore_List __list_data; + ECORE_MAGIC; int delete_me : 1; int (*func) (void *data); void *data; @@ -66,6 +86,7 @@ struct _Ecore_Fd_Handler { Ecore_List __list_data; + ECORE_MAGIC; int fd; Ecore_Fd_Handler_Flags flags; int read_active : 1; @@ -80,6 +101,7 @@ struct _Ecore_Event_Handler { Ecore_List __list_data; + ECORE_MAGIC; int type; int delete_me : 1; int (*func) (int type, void *event, void *data); @@ -89,6 +111,7 @@ struct _Ecore_Event { Ecore_List __list_data; + ECORE_MAGIC; int type; void *event; int delete_me : 1; =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/Attic/ecore_timer.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -3 -r1.1.2.2 -r1.1.2.3 --- ecore_timer.c 23 Jan 2003 23:03:24 -0000 1.1.2.2 +++ ecore_timer.c 23 Jan 2003 23:51:41 -0000 1.1.2.3 @@ -26,6 +26,7 @@ if (in < 0.0) in = 0.0; timer = calloc(1, sizeof(Ecore_Timer)); if (!timer) return NULL; + ECORE_MAGIC_SET(timer, ECORE_MAGIC_TIMER); now = ecore_time_get(); _ecore_timer_set(timer, now + in, in, func, (void *)data); return timer; @@ -44,9 +45,10 @@ { void *data; - if (!timer) return NULL; + if (!ECORE_MAGIC_CHECK(timer, ECORE_MAGIC_TIMER)) return NULL; timers = _ecore_list_remove(timers, timer); data = timer->data; + ECORE_MAGIC_SET(timer, ECORE_MAGIC_NONE); free(timer); return data; } ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ enlightenment-cvs mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs