[Ecls-list] cl_boot crash

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sat Jul 31 14:32:28 UTC 2010


I will post what I found because it may be important for other plugin
developers.

The Boehm-Weiser garbage collector assumes that it is initialized from the
main thread of a program. That thread has to live as long as the garbage
collector, and in some platforms it has some special properties, such as a
fixed stack bottom.

In your case ECL is initialized from a secondary thread, because this is a
GUI, and the garbage collector fails to recognize the limits of the stack.
Furthermore, the thread in which it is initialized, is not known to the
garbage collector, for it has not been registered with it.

static pthread_t ecl_thread;

static pthread_mutex_t ecl_wait;


static void *

ecl_thread_entry(void *aux)

{

int argc = 1;

    char * argv[256];

cl_env_ptr env;

    argv[0] = "";    // cl_boot(argc, argv);

printf("Hola2\n");

GC_register_my_thread(argv);

GC_stackbottom = (void*)(argv+255);

printf("%x\n", GC_stackbottom);

cl_boot(argc,argv);

env = ecl_process_env();

CL_CATCH_ALL_BEGIN(env) {

pthread_mutex_lock(&ecl_wait);

} CL_CATCH_ALL_END;

cl_shutdown();

printf("Exited\n");

return NULL;

}


void InitPlugin()

{

 /*

ecl_set_option(ECL_OPT_TRAP_SIGSEGV, 0);

ecl_set_option(ECL_OPT_TRAP_SIGFPE, 0);

ecl_set_option(ECL_OPT_TRAP_SIGSEGV, 0);

ecl_set_option(ECL_OPT_TRAP_SIGINT, 0);

ecl_set_option(ECL_OPT_TRAP_SIGILL, 0);

ecl_set_option(ECL_OPT_TRAP_SIGBUS, 0);

ecl_set_option(ECL_OPT_TRAP_INTERRUPT_SIGNAL, 0);

ecl_set_option(ECL_OPT_SIGNAL_HANDLING_THREAD, 0);

ecl_set_option(ECL_OPT_INCREMENTAL_GC, 0);

 */

#undef pthread_create

pthread_mutex_init(&ecl_wait, NULL);

pthread_mutex_lock(&ecl_wait);

pthread_create(&ecl_thread, NULL, ecl_thread_entry, NULL);

}


void DeinitPlugin()

{

pthread_mutex_unlock(&ecl_wait);

// cl_shutdown();

}

I managed to solve the problems with the previous code. What it does is the
following.

First of all it reserves some space (argv[256]) and registers the current
thread with the given stack base (argv) and sets up the global application
stack "bottom" (it is actually the top on Intel processors).

The value of GC_stackbottom only matters for the main thread and we will set
it to be the location of the uppermost byte in the array argv. This should
be safe as the thread is going to survive for a long time.

Finally, to shut down the plugin one needs some mechanism to communicate it
to the thread that it should stop. I used locks, but this is a hack: you
will need something better.

Juanjo
-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20100731/c22a6192/attachment.html>


More information about the ecl-devel mailing list