int ecl_boot(const char *root_dir) { int argc = 1; char *argv[256]; argv[0] = "ecl"; GC_allow_register_threads(); GC_register_my_thread((const struct GC_stack_base *)argv); GC_stackbottom = (void*)(argv+255); setenv("ECLDIR", "", 1); cl_boot(argc, argv); main_lib_ECL_HELP(); main_lib_ASDF(); main_lib_SOCKETS(); main_lib_IPHONEPSYSTEM(); si_select_package(ecl_make_simple_base_string("CL-USER", 7)); char tmp[2048]; sprintf(tmp, "(setq *default-pathnames-defaults* #p\"%s\")", root_dir); si_safe_eval(3, c_string_to_object(tmp), Cnil, OBJNULL); init_callbacks_registry(); ecl_toplevel(root_dir); return 0; }
GC *create_conservative_gc(pointer_iterator rm, void *roots, unsigned int root_size, unsigned int allocations_per_collection) { GC_INIT(); /* We need to tell the collector about the root set because it was not allocated by the garbage collector. */ GC_add_roots(roots, ((char *)roots)+root_size); /* Inform the collector that we will be registering additional threads. */ GC_allow_register_threads(); GC *g = (GC *) GC_MALLOC(sizeof(GC)); if(g == NULL) return NULL; g->protect_ptr_count = 0; g->thread_start = conservative_thread_start; g->thread_end = conservative_thread_end; g->enable_gc = conservative_enable_gc; g->disable_gc = conservative_disable_gc; g->free_gc = conservative_free_gc; g->gc_allocate = conservative_allocate; g->collect_garbage = conservative_collect_garbage; g->set_gc_default_value = conservative_set_gc_default_value; g->set_gc_post_collection_callback = conservative_set_gc_post_collection_callback; g->set_gc_mode = conservative_set_gc_mode; g->set_gc_work_per_alloc = conservative_set_gc_work_per_alloc; g->store = conservative_store; g->protect_ptr = conservative_protect_ptr; g->unprotect_ptr = conservative_unprotect_ptr; return g; }
void mono_gc_base_init (void) { MonoThreadInfoCallbacks cb; char *env; if (gc_initialized) return; /* * Handle the case when we are called from a thread different from the main thread, * confusing libgc. * FIXME: Move this to libgc where it belongs. * * we used to do this only when running on valgrind, * but it happens also in other setups. */ #if defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) { size_t size; void *sstart; pthread_attr_t attr; pthread_getattr_np (pthread_self (), &attr); pthread_attr_getstack (&attr, &sstart, &size); pthread_attr_destroy (&attr); /*g_print ("stackbottom pth is: %p\n", (char*)sstart + size);*/ #ifdef __ia64__ /* * The calculation above doesn't seem to work on ia64, also we need to set * GC_register_stackbottom as well, but don't know how. */ #else /* apparently with some linuxthreads implementations sstart can be NULL, * fallback to the more imprecise method (bug# 78096). */ if (sstart) { GC_stackbottom = (char*)sstart + size; } else { int dummy; gsize stack_bottom = (gsize)&dummy; stack_bottom += 4095; stack_bottom &= ~4095; GC_stackbottom = (char*)stack_bottom; } #endif } #elif defined(HAVE_PTHREAD_GET_STACKSIZE_NP) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) GC_stackbottom = (char*)pthread_get_stackaddr_np (pthread_self ()); #elif defined(__OpenBSD__) # include <pthread_np.h> { stack_t ss; int rslt; rslt = pthread_stackseg_np(pthread_self(), &ss); g_assert (rslt == 0); GC_stackbottom = (char*)ss.ss_sp; } #elif defined(__native_client__) /* Do nothing, GC_stackbottom is set correctly in libgc */ #else { int dummy; gsize stack_bottom = (gsize)&dummy; stack_bottom += 4095; stack_bottom &= ~4095; /*g_print ("stackbottom is: %p\n", (char*)stack_bottom);*/ GC_stackbottom = (char*)stack_bottom; } #endif #if !defined(PLATFORM_ANDROID) /* If GC_no_dls is set to true, GC_find_limit is not called. This causes a seg fault on Android. */ GC_no_dls = TRUE; #endif GC_init (); GC_oom_fn = mono_gc_out_of_memory; GC_set_warn_proc (mono_gc_warning); GC_finalize_on_demand = 1; GC_finalizer_notifier = mono_gc_finalize_notify; #ifdef HAVE_GC_GCJ_MALLOC GC_init_gcj_malloc (5, NULL); #endif #ifdef HAVE_GC_ALLOW_REGISTER_THREADS GC_allow_register_threads(); #endif if ((env = getenv ("MONO_GC_PARAMS"))) { char **ptr, **opts = g_strsplit (env, ",", -1); for (ptr = opts; *ptr; ++ptr) { char *opt = *ptr; if (g_str_has_prefix (opt, "max-heap-size=")) { glong max_heap; opt = strchr (opt, '=') + 1; if (*opt && mono_gc_parse_environment_string_extract_number (opt, &max_heap)) { if (max_heap < MIN_BOEHM_MAX_HEAP_SIZE) { fprintf (stderr, "max-heap-size must be at least %dMb.\n", MIN_BOEHM_MAX_HEAP_SIZE_IN_MB); exit (1); } GC_set_max_heap_size (max_heap); } else { fprintf (stderr, "max-heap-size must be an integer.\n"); exit (1); } continue; } else { fprintf (stderr, "MONO_GC_PARAMS must be a comma-delimited list of one or more of the following:\n"); fprintf (stderr, " max-heap-size=N (where N is an integer, possibly with a k, m or a g suffix)\n"); exit (1); } } g_strfreev (opts); } memset (&cb, 0, sizeof (cb)); cb.thread_register = boehm_thread_register; cb.mono_method_is_critical = (gpointer)mono_runtime_is_critical_method; #ifndef HOST_WIN32 cb.mono_gc_pthread_create = (gpointer)mono_gc_pthread_create; #endif mono_threads_init (&cb, sizeof (MonoThreadInfo)); mono_gc_enable_events (); gc_initialized = TRUE; }
void GC::Init() { GC_init(); GC_allow_register_threads(); }