fix crash on invalid configurations by setting thread pointer and log buffer to a statically allocated descriptor until the threading structures have been initialized properly

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2018-05-22 09:49:50 +08:00
parent 33c89f0d47
commit 12cc159949
4 changed files with 11 additions and 2 deletions

View file

@ -110,6 +110,7 @@ dds_init(void)
os_mutexInit (&gv.static_logbuf_lock);
gv.static_logbuf_lock_inited = 1;
os_mutexInit (&dds_global.m_mutex);
thread_states_init_static();
uri = os_getenv (DDSC_PROJECT_NAME_NOSPACE_CAPS"_URI");
dds_cfgst = config_init (uri);

View file

@ -86,6 +86,7 @@ struct thread_states {
extern struct thread_states thread_states;
extern os_threadLocal struct thread_state1 *tsd_thread_state;
void thread_states_init_static (void);
void thread_states_init (_In_ unsigned maxthreads);
void thread_states_fini (void);

View file

@ -93,7 +93,7 @@ static void nn_vlogb (struct thread_state1 *self, const char *fmt, va_list ap)
logbuf_t lb;
if (*fmt == 0)
return;
if (self && self->lb)
if (self->lb)
lb = self->lb;
else
{

View file

@ -56,6 +56,13 @@ static void os_free_aligned ( _Pre_maybenull_ _Post_invalid_ void *ptr)
}
}
void thread_states_init_static (void)
{
static struct thread_state1 ts =
{ .state = THREAD_STATE_ALIVE, .vtime = 1, .watchdog = 1, .lb = NULL, .name = "(anon)" };
tsd_thread_state = &ts;
}
void thread_states_init (_In_ unsigned maxthreads)
{
unsigned i;
@ -324,7 +331,7 @@ void downgrade_main_thread (void)
logbuf_free (ts1->lb);
/* no need to sync with service lease: already stopped */
reap_thread_state (ts1, 0);
tsd_thread_state = NULL;
thread_states_init_static ();
}
struct thread_state1 *get_thread_state (_In_ os_threadId id)