obj plain_load_boot( const char *path, rs_bool verboseq ) { char *gc_argv[3]; int vers; obj r; gc_argv[0] = "rs"; gc_argv[1] = verboseq ? NULL : "-q"; gc_argv[2] = NULL; init_gc( verboseq ? 1 : 2, (const char **)gc_argv ); /* make room for it... */ gc_safe_point( 1024*1024 ); r = load_image_file( path, FALSE_OBJ, FALSE_OBJ, &vers ); if (truish(r)) { switch (vers) { case FMTV_RSCHEME_0_5: /* assume it's bootable */ case FMTV_RSCHEME_0_6_BOOT: break; default: fprintf( stderr, "%s: image version %d -- not bootable\n", path, vers ); return FALSE_OBJ; } } return r; }
/** Init WMFS */ void init(void) { /* Init lists heads */ SLIST_INIT(&bwhead); SLIST_INIT(&clients); SLIST_INIT(&trayicons); /* First init */ ewmh_init_hints(); init_conf(); init_gc(); init_font(); init_cursor(); init_key(); init_root(); screen_init_geo(); event_make_array(); infobar_init(); systray_acquire(); ewmh_update_current_tag_prop(); grabkeys(); return; }
obj load_initial_heap( const char *path, rs_bool verbose ) { char *gc_argv[3]; int vers; obj r; gc_argv[0] = "rs"; gc_argv[1] = verbose ? (char *)NULL : "-q"; gc_argv[2] = NULL; init_gc( verbose ? 1 : 2, (const char **)gc_argv ); /* make room for it... */ gc_safe_point( 1024*1024 ); r = load_image_file( path, FALSE_OBJ, FALSE_OBJ, &vers ); if (EQ(r,FALSE_OBJ)) return FALSE_OBJ; switch (vers) { case FMTV_RSCHEME_0_5: /* assume it's bootable */ case FMTV_RSCHEME_0_6_BOOT: return r; default: fprintf( stderr, "%s: image version %d -- not bootable\n", path, vers ); return FALSE_OBJ; } }
int main(int argc, char *argv[]) { struct sigaction act; if(!(display = XOpenDisplay(DISPLAY))){ LOG("BARE: cannot open display! Ending session.\n"); return -1; } if((root = DefaultRootWindow(display))) { XSetWindowBackground(display, root, BlackPixel(display, XDefaultScreen(display))); XClearWindow(display, root); } else { LOG("BARE: cannot get root window! Ending session.\n"); return -1; } if((screen = DefaultScreenOfDisplay(display))) { SCREEN_WIDTH = XWidthOfScreen(screen); SCREEN_HEIGHT = XHeightOfScreen(screen); LOG("Screen: %d x %d\n", SCREEN_WIDTH, SCREEN_HEIGHT); } else { LOG("BARE: cannot get screen! Ending session.\n"); return -1; } selected = root; fontstruct = XLoadQueryFont(display, FONT); if (!fontstruct) { LOG("Couldn't find font \"%s\", loading default\n", FONT); fontstruct = XLoadQueryFont(display, "-*-fixed-medium-r-*-*-12-*-*-*-*-*-iso8859-1"); if (!fontstruct) { LOG("Couldn't load default fixed font. Something is seriouslly wrong. Ending session.\n"); return -1; } } XDefineCursor(display, selected, (XCreateFontCursor(display, CURSOR))); grab_keyboard(); XSelectInput(display, root, SubstructureNotifyMask | SubstructureRedirectMask | KeyPressMask); BARE_colormap = DefaultColormap(display, 0); init_gc(); message("Welcome to Bare WM v%s", VERSION); act.sa_handler = sighandler; sigemptyset(&act.sa_mask); act.sa_flags = SA_NOCLDSTOP | SA_RESTART ; sigaction(SIGCHLD, &act, NULL); main_loop(); XFree(BARE_GC); XFree(BARE_SELECTEDFG_GC); XCloseDisplay(display); return 0; }
void window_signal_show(void) { gtk_widget_show_all(window_signal); if(is_stop==TRUE) { g_print("init_gc\n"); init_gc(); pthread_create(&thread_music, NULL, &play_music, NULL); //draw rectangle with standard background of draw_area widget //Der Index 0 ist einfach ausprobiert, die stehen fuer unterschiedlichen Status des Widgets! gdk_draw_rectangle(pixmap, draw_area->style->bg_gc[0], TRUE, 0, 0, 2*DRAW_AREA_WIDTH, DRAW_AREA_HEIGHT); // make screen in default color /*gdk_draw_line(pixmap, gcbl, 1, 0, 1, DRAW_AREA_HEIGHT-3); gdk_draw_line(pixmap, gcbl, 0, DRAW_AREA_HEIGHT-3, DRAW_AREA_WIDTH-3, DRAW_AREA_HEIGHT-3); gdk_draw_line(pixmap, gcbl, 0, 1, DRAW_AREA_WIDTH-3, 1); gdk_draw_line(pixmap, gcbl, DRAW_AREA_WIDTH-3, 0, DRAW_AREA_WIDTH-3, DRAW_AREA_HEIGHT-3); gdk_draw_line(pixmap, gcbl, 10, 10, 20, 20);*/ //uart = fopen("/dev/ttyAMA0", "r"); uart2_is_start = TRUE; uart2 = fopen("/dev/ttyAMA0", "w"); //pthread_create(&thread_send, NULL, &uart_send, NULL); fputc(0x55, uart2); fputc(0x44, uart2); fputc(0x33, uart2); fputc((unsigned char)calibration_min, uart2); fputc((unsigned char)calibration_max, uart2); fputc((unsigned char)(uart_received_multiplier*100), uart2); fputc(100, uart2); /* divider of uart_received_multiplier */ fputc(uart_send_multiplier, uart2); fputc(50, uart2); fputc((unsigned char)VARIATION_NUMBER, uart2); fputc((unsigned char)VARIATION_OFFSET, uart2); fputc((unsigned char)STANDARD_SIGNAL_LOW, uart2); fputc((unsigned char)STANDARD_SIGNAL_HIGH, uart2); fputc(0x33, uart2); fputc(0x44, uart2); fputc(0x55, uart2); fflush(uart2); fputc(0x33, uart2); fflush(uart2); fputc(0x11, uart2); fflush(uart2); char* music_file = strrchr(music_path, '/'); g_print("%s\n", music_file); gtk_label_set_text(GTK_LABEL(lbl_music_file), music_file+1); system("echo . > /tmp/cmd"); /* start music */ g_print("tmp/cmd written\n"); } }
GTEST_API_ int main(int argc, char **argv) { printf("Running main() from gtest_main.cc\n"); init_gc(); testing::InitGoogleTest(&argc, argv); int ret; if(!(setjmp(ex_jbuf))) { ret = RUN_ALL_TESTS(); } else { fprintf(stderr, "get exception; terminate test. error:%s\n", ex_buf); } term_gc(); return ret; }
PUBLIC int main(int argc, char *argv[]) { if (argc < 2) { fprintf(stderr, "Usage: move [-t] <dbfilename> [<move-source-code-file> ...]\n" "\t-t\tInhibits loading threads which were active when the DB was saved\n"); exit(MOVE_EXIT_ERROR); } signal(SIGINT, siginthandler); /* %%% This can be made to emergency-flush the database to disk, later on %%% */ write_pid(); init_gc(); init_object(); init_prim(); init_vm_global(); init_thread(); checkpoint_filename = "move.checkpoint"; install_primitives(); { int load_threads = 1; if (!strcmp(argv[1], "-t")) { load_threads = 0; argv++; argc--; } import_db(argv[1], load_threads); } bind_primitives_to_symbols(); import_cmdline_files(argc - 2, argv + 2); run_main_loop(); done_gc(); return MOVE_EXIT_OK; }
/** Init MWM */ void init(void) { /* First init */ ewmh_init_hints(); init_conf(); init_gc(); init_font(); init_cursor(); init_key(); init_root(); screen_init_geo(); infobar_init(); systray_acquire(); init_status(); ewmh_update_current_tag_prop(); grabkeys(); return; }
int main(int argc, char * argv[]) { int fd; struct exec_trailer trail; int i, r; struct longjmp_buffer raise_buf; struct channel * chan; int verbose_init = 0, percent_free_init = Percent_free_def; long minor_heap_init = Minor_heap_def, heap_chunk_init = Heap_chunk_def; #ifdef DEBUG char * debugger_address = NULL; verbose_init = 1; #endif i = 0; fd = attempt_open(&argv[0], &trail, 0); if (fd < 0) { for(i = 1; i < argc && argv[i][0] == '-'; i++) { switch(argv[i][1]) { #ifdef DEBUG case 't': { extern int trace_flag; trace_flag = 1; break; } #endif case 'v': verbose_init = 1; break; case 'V': fprintf(stderr, "The Caml Light runtime system for Ex-SML, version %s\n", VERSION); fprintf(stderr, " git commit %s\n", GIT_HEAD); sys_exit(INT_TO_VAL(0)); default: fatal_error_arg("Unknown option %s.\n", argv[i]); } } if (argv[i] == 0) fatal_error("No bytecode file specified.\n"); fd = attempt_open(&argv[i], &trail, 1); switch(fd) { case FILE_NOT_FOUND: fatal_error_arg("Fatal error: cannot find file %s\n", argv[i]); break; case TRUNCATED_FILE: case BAD_MAGIC_NUM: fatal_error_arg( "Fatal error: the file %s is not a bytecode executable file\n", argv[i]); break; default: /* By default, accept */ break; } } /* Runtime options. The option letter is the first letter of the last word of the ML name of the option (see [lib/gc.mli]). */ { char *opt = getenv ("CAMLRUNPARAM"); if (opt != NULL){ while (*opt != '\0'){ switch (*opt++){ case 's': sscanf (opt, "=%ld", &minor_heap_init); break; case 'i': sscanf (opt, "=%ld", &heap_chunk_init); break; case 'o': sscanf (opt, "=%d", &percent_free_init); break; case 'v': sscanf (opt, "=%d", &verbose_init); break; default: perror("Unknown CAMLRUNPARAM Option"); break; } } } } #ifdef DEBUG if (debugger_address == NULL) debugger_address = getenv("CAML_DEBUG_SOCKET"); #endif if (setjmp(raise_buf.buf) == 0) { external_raise = &raise_buf; init_gc (minor_heap_init, heap_chunk_init, percent_free_init, verbose_init); init_stack(); init_atoms(); lseek(fd, - (long) (TRAILER_SIZE + trail.code_size + trail.data_size + trail.symbol_size + trail.debug_size), 2); code_size = trail.code_size; start_code = (bytecode_t) stat_alloc(code_size); r = read(fd, (char *) start_code, code_size); if (r == -1) { fatal(NULL); } else if ((unsigned) r != code_size) { fatal_error("Fatal error: truncated bytecode file.\n"); } #if defined(WORDS_BIGENDIAN) && !defined(HAVE_ALIGNED_ACCESS_REQUIRED) fixup_endianness(start_code, code_size); #endif chan = open_descr(fd); global_data = intern_val(chan); modify(&Field(global_data, GLOBAL_DATA), global_data); close_in(chan); sys_init(argv + i); interprete(/* mode=init */ 0, NULL, NULL); interprete(/* mode=byte exec */ 1, start_code, NULL); sys_exit(INT_TO_VAL(0)); } else { if (Field(exn_bucket, 0) == Field(global_data, SYS__EXN_MEMORY)) fatal_error ("Fatal error: out of memory.\n"); else { char* buf = (char*)malloc(201); char* exnmsg = exnmessage_aux(exn_bucket); snprintf(buf, 200, "Uncaught exception:\n%s\n", exnmsg); free(exnmsg); fatal_error(buf); } } return 0; /* Can't get here */ }
void perform_gc(struct s_arena* arena){ struct s_gc s_gc; init_gc(&s_gc,arena); /* phase 1 mark or evac root */ evacuate(arena->root,&s_gc); /* phase 2 process scavenge queue */ do{ void* scav_obj; scav_obj = find_small_object(&s_gc); if( scav_obj != NULL){ scavenge_small(scav_obj,&s_gc); continue; } scav_obj = find_big_object(&s_gc); if( scav_obj != NULL){ scavenge_big(scav_obj,&s_gc); continue; } /* no scavenging object */ break; }while( 1 ); debug("========================================================\n",NULL); debug("%s : small %016x(%d) big %016x(%d)\n",__FUNCTION__,s_gc.small_evaced,s_gc.small_evaced,s_gc.big_evaced,s_gc.big_evaced); debug("========================================================\n",NULL); /* phase 3 adjust objects */ /* big dead objects : free */ struct bdescr* block; block = TAILQ_FIRST(&(arena->big_blocks)); while(block){ debug("-",NULL); struct bdescr* new_block = TAILQ_NEXT(block,link); debug("%s : %08x dead big\n",__FUNCTION__,(unsigned int)block); /* finalize */ /* TODO if any finalizer, call here (before small blocks released)*/ free_big_block(arena,(struct big_bdescr*)block); block = new_block; } /* big live objects : clear used bit & move to arena->blocks */ TAILQ_INIT(&(arena->big_blocks)); TAILQ_CONCAT(&(arena->big_blocks),&(s_gc.big_live_queue),link); block = TAILQ_FIRST(&(arena->big_blocks)); while(block){ debug("+",NULL); struct bdescr* new_block = TAILQ_NEXT(block,link); debug("%s : %08x live big\n",__FUNCTION__,(unsigned int)block); ((struct big_bdescr*)block)-> used = 0; block = new_block; } /* free old spaces */ block = TAILQ_FIRST(&(arena->blocks)); while(block){ debug("-",NULL); struct bdescr* next_block = TAILQ_NEXT(block,link); free_single_block(arena,(struct single_bdescr*)block); debug("%s : %08x dead small\n",__FUNCTION__,(unsigned int)block); block = next_block; } /* move live small area */ TAILQ_INIT(&(arena->blocks)); TAILQ_CONCAT(&(arena->blocks),&(s_gc.to_space_queue),link); #ifdef CGC_DEBUG block = TAILQ_FIRST(&(arena->blocks)); while(block){ debug("+",NULL); struct bdescr* next_block = TAILQ_NEXT(block,link); debug("%s : %08x live small\n",__FUNCTION__,(unsigned int)block); block = next_block; } #endif debug("========================================================\n",NULL); debug("%s : end\n",__FUNCTION__); debug("========================================================\n",NULL); }
int main(int argc, char * argv[]) #endif { int fd; struct exec_trailer trail; int i; struct longjmp_buffer raise_buf; struct channel * chan; int verbose_init = 0, percent_free_init = Percent_free_def; long minor_heap_init = Minor_heap_def, heap_chunk_init = Heap_chunk_def; char * debugger_address = NULL; #ifdef MSDOS extern char ** check_args(); argv = check_args(argv); #endif #ifdef DEBUG verbose_init = 1; #endif #ifdef WIN32 BOOL fOk; fOk = SetConsoleCtrlHandler(NULL, FALSE); #endif i = 0; fd = attempt_open(&argv[0], &trail, 0); if (fd < 0) { for(i = 1; i < argc && argv[i][0] == '-'; i++) { switch(argv[i][1]) { #ifdef DEBUG case 't': { extern int trace_flag; trace_flag = 1; break; } #endif case 'v': verbose_init = 1; break; case 'V': fprintf(stderr, "The Caml Light runtime system, version %s\n", VERSION); sys_exit(Val_int(0)); default: fatal_error_arg("Unknown option %s.\n", argv[i]); } } if (argv[i] == 0) fatal_error("No bytecode file specified.\n"); fd = attempt_open(&argv[i], &trail, 1); switch(fd) { case FILE_NOT_FOUND: fatal_error_arg("Fatal error: cannot find file %s\n", argv[i]); break; case TRUNCATED_FILE: case BAD_MAGIC_NUM: fatal_error_arg( "Fatal error: the file %s is not a bytecode executable file\n", argv[i]); break; } } /* Runtime options. The option letter is the first letter of the last word of the ML name of the option (see [lib/gc.mli]). */ { char *opt = getenv ("CAMLRUNPARAM"); if (opt != NULL){ while (*opt != '\0'){ switch (*opt++){ case 's': sscanf (opt, "=%ld", &minor_heap_init); break; case 'i': sscanf (opt, "=%ld", &heap_chunk_init); break; case 'o': sscanf (opt, "=%d", &percent_free_init); break; case 'v': sscanf (opt, "=%d", &verbose_init); break; } } } } #ifdef HAS_SOCKETS if (debugger_address == NULL) debugger_address = getenv("CAML_DEBUG_SOCKET"); #endif if (setjmp(raise_buf.buf) == 0) { external_raise = &raise_buf; init_gc (minor_heap_init, heap_chunk_init, percent_free_init, verbose_init); init_stack(); init_atoms(); lseek(fd, - (long) (TRAILER_SIZE + trail.code_size + trail.data_size + trail.symbol_size + trail.debug_size), 2); code_size = trail.code_size; #if defined(DIRECT_JUMP) && defined(THREADED) start_code = (bytecode_t) alloc_string(code_size); #else start_code = (bytecode_t) stat_alloc(code_size); #endif if (read(fd, (char *) start_code, code_size) != code_size) fatal_error("Fatal error: truncated bytecode file.\n"); #if defined(MOSML_BIG_ENDIAN) && !defined(ALIGNMENT) fixup_endianness(start_code, code_size); #endif chan = open_descr(fd); global_data = intern_val(chan); modify(&Field(global_data, GLOBAL_DATA), global_data); close_in(chan); sys_init(argv + i); interprete(/* mode=init */ 0, NULL, 0, NULL); interprete(/* mode=byte exec */ 1, start_code, code_size, NULL); sys_exit(Val_int(0)); } else { if (Field(exn_bucket, 0) == Field(global_data, SYS__EXN_MEMORY)) fatal_error ("Fatal error: out of memory.\n"); else { char* buf = (char*)malloc(201); char* exnmsg = exnmessage_aux(exn_bucket); #if defined(__CYGWIN__) || defined(hpux) sprintf(buf, "Uncaught exception:\n%s\n", exnmsg); #elif defined(WIN32) _snprintf(buf, 200, "Uncaught exception:\n%s\n", exnmsg); #else snprintf(buf, 200, "Uncaught exception:\n%s\n", exnmsg); #endif free(exnmsg); fatal_error(buf); } } return 0; /* Can't get here */ }
int init_type_array(int type){ if (init_gc() == ES_ERROR) return ES_ERROR; updatePartCfg(WITHOUT_BONDS); if (!partCfg) return ES_ERROR; int type_index=-1; type_index= (Type.max_entry++); if ( type_index == number_of_type_lists ) { reallocate_global_type_list(number_of_type_lists*2); } Type.index = (int *) realloc ( (void *) Type.index, sizeof(int)*Type.max_entry); //reallocate the array that holds the particle type and points to the type index used for the type_list if ( type >= Index.max_entry ) { Index.type= (int * ) realloc( (void *) Index.type, (type+1)*sizeof(int)); Index.max_entry = type + 1; } for (int i=0; i<Type.max_entry; i++) Index.type[i]=-1; if (Type.index == (int *) 0 || Index.type == (int *) 0) return ES_ERROR; //allocates a list for ids for as many entries as there are particles right now if ( !(partCfg) || type < 0 ) { return ES_ERROR; } Type.index[type_index]=type; //fill in array type_index_of_type for (int i=0; i<Type.max_entry; i++ ) { Index.type[Type.index[i]] = i; } int t_c = 0; //index type_array[Index.type[type]].id_list = (int *) malloc (sizeof (int) * n_part); for (int i=0; i<n_part; i++) { if ( partCfg[i].p.type==type ) type_array[Index.type[type]].id_list[t_c++]=partCfg[i].p.identity; } int max_size=n_part; if ( t_c != 0 ) { while ( t_c < (double) max_size/4.0) { max_size= floor( (double ) max_size/2.0); } // now the array is shrinked to at least 4 times the highest entry type_array[Index.type[type]].id_list= (int *) realloc( (void *) type_array[Index.type[type]].id_list, sizeof(int)*2*max_size); type_array[Index.type[type]].max_entry = t_c; type_array[Index.type[type]].cur_size = max_size*2; } else { //no particles of the given type were found, so leave array size fixed at a reasonable start entry 64 ints in this case type_array[Index.type[type]].id_list= (int *) realloc( (void *) type_array[Index.type[type]].id_list, sizeof(int)*64); type_array[Index.type[type]].max_entry = t_c; type_array[Index.type[type]].cur_size = 64; } //fill remaining entries with -1 for (int i=type_array[Index.type[type]].max_entry; i<type_array[Index.type[type]].cur_size; i++) { type_array[Index.type[type]].id_list[i] = -1; } Type_array_init = 1; return ES_OK; }
int main(int argc, char** argv) { pre=sbrk(0); bottom=malloc(256)-sizeof(size_t); // don't free this one - that keeps it an innocuous stub (a root with no graph attached) init_gc(); timediff(); printf("Checking global root set handling an general GC functionality\n"); /* the most basic allocation and clearing pointer exercise. This only checks for following the root set pointers one level. */ void *pre = sbrk(0); for(int i=0;i<MAX_ALLOCATIONS;i++) allocs[i]=malloc(i*2+128); printf("Heap after first round of allocations: %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); for(int i=0;i<MAX_ALLOCATIONS;i++) allocs[i]=0; gc(); printf("Heap after first gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); /* allocations which all point to each other. this checks for proper traversal of the chunk graph. */ for(int i=0;i<MAX_ALLOCATIONS;i++) { allocs[i]=malloc(i*2+128); if(i>0) *(void**)(allocs[i])=allocs[i-1]; } printf("Heap after second round of allocations: %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); for(int i=0;i<MAX_ALLOCATIONS-1;i++) allocs[i]=0; gc(); // here, since we keep the last entry, which points to the next-to-last and so on, everything should still be around printf("Heap after clearing all but one, and gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); allocs[MAX_ALLOCATIONS-1]=0; gc(); printf("Heap after clearing last one, and gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); /* allocations which all point to each other. this checks for proper traversal of the chunk graph. */ for(int i=0;i<MAX_ALLOCATIONS;i++) { allocs[i]=malloc(i*2+128); if(i>0) { void *start_of_new_alloc = allocs[i]; void *start_of_prev_alloc = allocs[i-1]; int offset_into_new_alloc = 8*random_up_to((i*2+120)/8); int offset_into_old_alloc = 8*random_up_to(((i-1)*2+120)/8); void **location_of_pointer = (void**)(start_of_new_alloc + offset_into_new_alloc); *location_of_pointer = start_of_prev_alloc + offset_into_old_alloc; } } printf("Heap after third round of allocations: %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); for(int i=0;i<MAX_ALLOCATIONS-1;i++) allocs[i]=0; gc(); // here, since we keep the last entry, which points to the next-to-last and so on, everything should still be around printf("Heap after clearing all but one, and gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); allocs[MAX_ALLOCATIONS-1]=0; gc(); printf("Heap after clearing last one, and gc(): %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); printf("Now checking stack root set handling.\n"); recursive_allocations(100); gc(); printf("After Recursive1 %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); recursive_allocations2(100); gc(); printf("After Recursive2 %zu, free %d, inuse %d\n",heap_size(),free_chunks(),inuse_chunks()); }