void checkIntegrity(void) { struct chunkHeader *walker; struct chunkTrailer *chunkTrailer; unsigned char *memory; // dbgf_all(DBGT_INFO, " "); for (walker = chunkList; walker != NULL; walker = walker->next) { if (walker->magicNumber != MAGIC_NUMBER) { dbgf( DBGL_SYS, DBGT_ERR, "invalid magic number in header: %08x, malloc tag = %d", walker->magicNumber, walker->tag ); cleanup_all( -500073 ); } memory = (unsigned char *)walker; chunkTrailer = (struct chunkTrailer *)(memory + sizeof(struct chunkHeader) + walker->length); if (chunkTrailer->magicNumber != MAGIC_NUMBER) { dbgf( DBGL_SYS, DBGT_ERR, "invalid magic number in trailer: %08x, malloc tag = %d", chunkTrailer->magicNumber, walker->tag ); cleanup_all( -500075 ); } } }
void removeMemory(int32_t tag, int32_t freetag) { struct memoryUsage *walker; for ( walker = memoryList; walker != NULL; walker = walker->next ) { if ( walker->tag == tag ) { if ( walker->counter == 0 ) { dbg( DBGL_SYS, DBGT_ERR, "Freeing more memory than was allocated: malloc tag = %d, free tag = %d", tag, freetag ); cleanup_all( -500069 ); } walker->counter--; break; } } if ( walker == NULL ) { dbg( DBGL_SYS, DBGT_ERR, "Freeing memory that was never allocated: malloc tag = %d, free tag = %d", tag, freetag ); cleanup_all( -500070 ); } }
int main( int argc, char *argv[] ) { struct map_data *map; if ( init(&map, argc, argv) ) { exit( 0 ); } int cur = '\0'; point_t start = get_start_point( map ); do { clear(); print_map( map ); process_key( cur ); switch ( cur ) { default: { point_t target = get_cursor(); //mvprintw( 0, 0, "Cursor was at : (%d, %d)", target.x, target.y); path_t *path_to_target = search_path( start, target, map ); print_path( path_to_target ); refresh(); } } refresh(); } while ( (cur = getch()) != 'q' ); cleanup_all(); return 0; }
/** * Create the Timer Task * @param _init_callback */ void StartTimerLoop(CO_Data* d, TimerCallback_t _init_callback) { int ret = 0; stop_timer = 0; init_callback = _init_callback; callback_od = d; char taskname[32]; snprintf(taskname, sizeof(taskname), "timerloop-%d", current->pid); /* create timerloop_task */ ret = rt_task_create(&timerloop_task, taskname, 0, 50, 0); /* T_JOINABLE only in user space */ if (ret) { printk("Failed to create timerloop_task, code %d\n",ret); return; } /* start timerloop_task */ ret = rt_task_start(&timerloop_task,&timerloop_task_proc,NULL); if (ret) { printk("Failed to start timerloop_task, code %u\n",ret); goto error; } return; error: cleanup_all(); }
static void process_signal(int sig){ int r = 0; switch(sig) { case SIGINT: case SIGQUIT: case SIGTERM: case SIGHUP: r += log_status(); break; case SIGUSR1: case SIGUSR2: log_debug(); /*local_debug();*/ cluster_debug(); return; default: LOG_PRINT("Unknown signal received... ignoring"); return; } if (!r) { LOG_DBG("No current cluster logs... safe to exit."); cleanup_all(); exit(EXIT_SUCCESS); } LOG_ERROR("Cluster logs exist. Refusing to exit."); }
/* Ensures we can read a certain amount of bytes without overrunning the end * of the stream. */ static void ensure_can_read(MVMThreadContext *tc, MVMCompUnit *cu, ReaderState *rs, MVMuint8 *pos, MVMuint32 size) { MVMCompUnitBody *cu_body = &cu->body; if (pos + size > cu_body->data_start + cu_body->data_size) { if (rs) cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Read past end of bytecode stream"); } }
void *_debugRealloc(void *memoryParameter, uint32_t length, int32_t tag) { unsigned char *memory; struct chunkHeader *chunkHeader=NULL; struct chunkTrailer *chunkTrailer; unsigned char *result; uint32_t copyLength; if (memoryParameter) { /* if memoryParameter==NULL, realloc() should work like malloc() !! */ memory = memoryParameter; chunkHeader = (struct chunkHeader *)(memory - sizeof(struct chunkHeader)); if (chunkHeader->magicNumber != MAGIC_NUMBER) { dbgf( DBGL_SYS, DBGT_ERR, "invalid magic number in header: %08x, malloc tag = %d", chunkHeader->magicNumber, chunkHeader->tag ); cleanup_all( -500078 ); } chunkTrailer = (struct chunkTrailer *)(memory + chunkHeader->length); if (chunkTrailer->magicNumber != MAGIC_NUMBER) { dbgf( DBGL_SYS, DBGT_ERR, "invalid magic number in trailer: %08x, malloc tag = %d", chunkTrailer->magicNumber, chunkHeader->tag ); cleanup_all( -500079 ); } } result = _debugMalloc(length, tag); if (memoryParameter) { copyLength = length; if (copyLength > chunkHeader->length) copyLength = chunkHeader->length; memcpy(result, memoryParameter, copyLength); debugFree(memoryParameter, -300280); } return result; }
/* Reads a string index, looks up the string and returns it. Bounds * checks the string heap index too. */ static MVMString * get_heap_string(MVMThreadContext *tc, MVMCompUnit *cu, ReaderState *rs, MVMuint8 *buffer, size_t offset) { MVMuint32 heap_index = read_int32(buffer, offset); if (heap_index >= cu->body.num_strings) { if (rs) cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "String heap index beyond end of string heap"); } return MVM_cu_string(tc, cu, heap_index); }
/* the main program when not doing a compile */ static int ccache_main(int argc, char *argv[]) { int c; size_t v; while ((c = getopt(argc, argv, "hszcCF:M:V")) != -1) { switch (c) { case 'V': printf("ccache version %s\n", CCACHE_VERSION); printf("Copyright Andrew Tridgell 2002\n"); printf("Released under the GNU GPL v2 or later\n"); exit(0); case 'h': usage(); exit(0); case 's': stats_summary(); break; case 'c': cleanup_all(cache_dir); printf("Cleaned cache\n"); break; case 'C': wipe_all(cache_dir); printf("Cleared cache\n"); break; case 'z': stats_zero(); printf("Statistics cleared\n"); break; case 'F': v = atoi(optarg); stats_set_limits(v, -1); printf("Set cache file limit to %u\n", (unsigned)v); break; case 'M': v = value_units(optarg); stats_set_limits(-1, v); printf("Set cache size limit to %uk\n", (unsigned)v); break; default: usage(); exit(1); } } return 0; }
void *_debugRealloc(void *memory, uint32_t length, int32_t tag) { void *result; result = realloc(memory, length); if (result == NULL) { dbg( DBGL_SYS, DBGT_ERR, "Cannot re-allocate %u bytes, malloc tag = %d", length, tag ); cleanup_all( -500071 ); } return result; }
/* Loads the SC dependencies list. */ static void deserialize_sc_deps(MVMThreadContext *tc, MVMCompUnit *cu, ReaderState *rs) { MVMCompUnitBody *cu_body = &cu->body; MVMuint32 i, sh_idx; MVMuint8 *pos; /* Allocate SC lists in compilation unit. */ cu_body->scs = MVM_malloc(rs->expected_scs * sizeof(MVMSerializationContext *)); cu_body->scs_to_resolve = MVM_malloc(rs->expected_scs * sizeof(MVMSerializationContextBody *)); cu_body->sc_handle_idxs = MVM_malloc(rs->expected_scs * sizeof(MVMint32)); cu_body->num_scs = rs->expected_scs; /* Resolve all the things. */ pos = rs->sc_seg; for (i = 0; i < rs->expected_scs; i++) { MVMSerializationContextBody *scb; MVMString *handle; /* Grab string heap index. */ ensure_can_read(tc, cu, rs, pos, 4); sh_idx = read_int32(pos, 0); pos += 4; /* Resolve to string. */ if (sh_idx >= cu_body->num_strings) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "String heap index beyond end of string heap"); } cu_body->sc_handle_idxs[i] = sh_idx; handle = MVM_cu_string(tc, cu, sh_idx); /* See if we can resolve it. */ uv_mutex_lock(&tc->instance->mutex_sc_weakhash); MVM_string_flatten(tc, handle); MVM_HASH_GET(tc, tc->instance->sc_weakhash, handle, scb); if (scb && scb->sc) { cu_body->scs_to_resolve[i] = NULL; MVM_ASSIGN_REF(tc, &(cu->common.header), cu_body->scs[i], scb->sc); } else { if (!scb) { scb = MVM_calloc(1, sizeof(MVMSerializationContextBody)); scb->handle = handle; MVM_HASH_BIND(tc, tc->instance->sc_weakhash, handle, scb); MVM_sc_add_all_scs_entry(tc, scb); } cu_body->scs_to_resolve[i] = scb; cu_body->scs[i] = NULL; } uv_mutex_unlock(&tc->instance->mutex_sc_weakhash); } }
/* wipe all cached files in all subdirs */ void wipe_all(struct conf *conf) { char *dname; int i; for (i = 0; i <= 0xF; i++) { dname = format("%s/%1x", conf->cache_dir, i); traverse(dname, wipe_fn); free(dname); } /* and fix the counters */ cleanup_all(conf); }
/* wipe all cached files in all subdirs */ void wipe_all(const char *dir) { char *dname; int i; for (i = 0; i <= 0xF; i++) { dname = format("%s/%1x", dir, i); traverse(dir, wipe_fn); free(dname); } /* and fix the counters */ cleanup_all(dir); }
void *_debugMalloc(uint32_t length, int32_t tag) { void *result; result = malloc(length); if (result == NULL) { dbg( DBGL_SYS, DBGT_ERR, "Cannot allocate %u bytes, malloc tag = %d", length, tag ); cleanup_all( -500072 ); } return result; }
STATIC_FUNC void json_inotify_event_hook(int fd) { TRACE_FUNCTION_CALL; dbgf_track(DBGT_INFO, "detected changes in directory: %s", smsTx_dir); assertion(-501278, (fd > -1 && fd == extensions_fd)); int ilen = 1024; char *ibuff = debugMalloc(ilen, -300375); int rcvd; int processed = 0; while ((rcvd = read(fd, ibuff, ilen)) == 0 || rcvd == EINVAL) { ibuff = debugRealloc(ibuff, (ilen = ilen * 2), -300376); assertion(-501279, (ilen <= (1024 * 16))); } if (rcvd > 0) { while (processed < rcvd) { struct inotify_event *ievent = (struct inotify_event *) &ibuff[processed]; processed += (sizeof (struct inotify_event) +ievent->len); if (ievent->mask & (IN_DELETE_SELF)) { dbgf_sys(DBGT_ERR, "directory %s has been removed \n", smsTx_dir); cleanup_all(-501290); } } } else { dbgf_sys(DBGT_ERR, "read()=%d: %s \n", rcvd, strerror(errno)); } debugFree(ibuff, -300377); check_for_changed_sms(NULL); }
void *_debugMalloc(uint32_t length, int32_t tag) { unsigned char *memory; struct chunkHeader *chunkHeader; struct chunkTrailer *chunkTrailer; unsigned char *chunk; memory = malloc(length + sizeof(struct chunkHeader) + sizeof(struct chunkTrailer)); if (memory == NULL) { dbg( DBGL_SYS, DBGT_ERR, "Cannot allocate %u bytes, malloc tag = %d", (unsigned int)(length + sizeof(struct chunkHeader) + sizeof(struct chunkTrailer)), tag ); cleanup_all( -500076 ); } chunkHeader = (struct chunkHeader *)memory; chunk = memory + sizeof(struct chunkHeader); chunkTrailer = (struct chunkTrailer *)(memory + sizeof(struct chunkHeader) + length); chunkHeader->length = length; chunkHeader->tag = tag; chunkHeader->magicNumber = MAGIC_NUMBER; chunkTrailer->magicNumber = MAGIC_NUMBER; chunkHeader->next = chunkList; chunkList = chunkHeader; #ifdef MEMORY_USAGE addMemory( length, tag ); #endif return chunk; }
/* Dissects the bytecode stream and hands back a reader pointing to the * various parts of it. */ static ReaderState * dissect_bytecode(MVMThreadContext *tc, MVMCompUnit *cu) { MVMCompUnitBody *cu_body = &cu->body; ReaderState *rs = NULL; MVMuint32 version, offset, size; /* Sanity checks. */ if (cu_body->data_size < HEADER_SIZE) MVM_exception_throw_adhoc(tc, "Bytecode stream shorter than header"); if (memcmp(cu_body->data_start, "MOARVM\r\n", 8) != 0) MVM_exception_throw_adhoc(tc, "Bytecode stream corrupt (missing magic string)"); version = read_int32(cu_body->data_start, 8); if (version < MIN_BYTECODE_VERSION) MVM_exception_throw_adhoc(tc, "Bytecode stream version too low"); if (version > MAX_BYTECODE_VERSION) MVM_exception_throw_adhoc(tc, "Bytecode stream version too high"); /* Allocate reader state. */ rs = MVM_malloc(sizeof(ReaderState)); memset(rs, 0, sizeof(ReaderState)); rs->version = version; rs->read_limit = cu_body->data_start + cu_body->data_size; cu->body.bytecode_version = version; /* Locate SC dependencies segment. */ offset = read_int32(cu_body->data_start, SCDEP_HEADER_OFFSET); if (offset > cu_body->data_size) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Serialization contexts segment starts after end of stream"); } rs->sc_seg = cu_body->data_start + offset; rs->expected_scs = read_int32(cu_body->data_start, SCDEP_HEADER_OFFSET + 4); /* Locate extension ops segment. */ offset = read_int32(cu_body->data_start, EXTOP_HEADER_OFFSET); if (offset > cu_body->data_size) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Extension ops segment starts after end of stream"); } rs->extop_seg = cu_body->data_start + offset; rs->expected_extops = read_int32(cu_body->data_start, EXTOP_HEADER_OFFSET + 4); /* Locate frames segment. */ offset = read_int32(cu_body->data_start, FRAME_HEADER_OFFSET); if (offset > cu_body->data_size) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Frames segment starts after end of stream"); } rs->frame_seg = cu_body->data_start + offset; rs->expected_frames = read_int32(cu_body->data_start, FRAME_HEADER_OFFSET + 4); /* Locate callsites segment. */ offset = read_int32(cu_body->data_start, CALLSITE_HEADER_OFFSET); if (offset > cu_body->data_size) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Callsites segment starts after end of stream"); } rs->callsite_seg = cu_body->data_start + offset; rs->expected_callsites = read_int32(cu_body->data_start, CALLSITE_HEADER_OFFSET + 4); /* Locate strings segment. */ offset = read_int32(cu_body->data_start, STRING_HEADER_OFFSET); if (offset > cu_body->data_size) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Strings segment starts after end of stream"); } rs->string_seg = cu_body->data_start + offset; rs->expected_strings = read_int32(cu_body->data_start, STRING_HEADER_OFFSET + 4); /* Get SC data, if any. */ offset = read_int32(cu_body->data_start, SCDATA_HEADER_OFFSET); size = read_int32(cu_body->data_start, SCDATA_HEADER_OFFSET + 4); if (offset > cu_body->data_size || offset + size > cu_body->data_size) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Serialized data segment overflows end of stream"); } if (offset) { cu_body->serialized = cu_body->data_start + offset; cu_body->serialized_size = size; } /* Locate bytecode segment. */ offset = read_int32(cu_body->data_start, BYTECODE_HEADER_OFFSET); size = read_int32(cu_body->data_start, BYTECODE_HEADER_OFFSET + 4); if (offset > cu_body->data_size || offset + size > cu_body->data_size) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Bytecode segment overflows end of stream"); } rs->bytecode_seg = cu_body->data_start + offset; rs->bytecode_size = size; /* Locate annotations segment. */ offset = read_int32(cu_body->data_start, ANNOTATION_HEADER_OFFSET); size = read_int32(cu_body->data_start, ANNOTATION_HEADER_OFFSET + 4); if (offset > cu_body->data_size || offset + size > cu_body->data_size) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Annotation segment overflows end of stream"); } rs->annotation_seg = cu_body->data_start + offset; rs->annotation_size = size; /* Locate HLL name */ rs->hll_str_idx = read_int32(cu_body->data_start, HLL_NAME_HEADER_OFFSET); /* Locate special frame indexes. Note, they are 0 for none, and the * index + 1 if there is one. */ rs->main_frame = read_int32(cu_body->data_start, SPECIAL_FRAME_HEADER_OFFSET); rs->load_frame = read_int32(cu_body->data_start, SPECIAL_FRAME_HEADER_OFFSET + 4); rs->deserialize_frame = read_int32(cu_body->data_start, SPECIAL_FRAME_HEADER_OFFSET + 8); if (rs->main_frame > rs->expected_frames || rs->load_frame > rs->expected_frames || rs->deserialize_frame > rs->expected_frames) { MVM_exception_throw_adhoc(tc, "Special frame index out of bounds"); } return rs; }
/* Ensures we can read a certain amount of bytes without overrunning the end * of the stream. */ MVM_STATIC_INLINE void ensure_can_read(MVMThreadContext *tc, MVMCompUnit *cu, ReaderState *rs, MVMuint8 *pos, MVMuint32 size) { if (pos + size > rs->read_limit) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Read past end of bytecode stream"); } }
static void throw_past_end(MVMThreadContext *tc, MVMuint8 *labels) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: truncated stream"); }
/* Validate that a static frame's bytecode is executable by the interpreter */ void MVM_validate_static_frame(MVMThreadContext *tc, MVMStaticFrame *static_frame) { MVMCompUnit *cu = static_frame->cu; MVMuint32 bytecode_size = static_frame->bytecode_size; MVMuint8 *bytecode_start = static_frame->bytecode; MVMuint8 *bytecode_end = bytecode_start + bytecode_size; /* current position in the bytestream */ MVMuint8 *cur_op = bytecode_start; /* positions in the bytestream that are starts of ops and goto targets */ MVMuint8 *labels = malloc(bytecode_size); MVMuint32 num_locals = static_frame->num_locals; MVMuint32 branch_target; MVMuint8 bank_num; MVMuint8 op_num; MVMOpInfo *op_info; MVMuint32 operand_size; MVMuint16 operand_target; MVMuint32 instruction = 0; MVMuint32 i; unsigned char op_rw; unsigned char op_type; unsigned char op_flags; MVMuint32 operand_type_var; MVMint64 num_jumplist_labels = 0; memset(labels, 0, bytecode_size); /* printf("bytecode_size %d cur_op %d bytecode_end %d difference %d", bytecode_size, (int)cur_op, (int)bytecode_end, (int)(bytecode_end - cur_op)); */ while (cur_op < bytecode_end - 1) { labels[cur_op - bytecode_start] |= MVM_val_op_boundary; bank_num = *(cur_op++); op_num = *(cur_op++); operand_type_var = 0; op_info = MVM_op_get_op((unsigned char)bank_num, (unsigned char)op_num); if (!op_info) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: non-existent operation bank %u op %u", bank_num, op_num); } if (num_jumplist_labels != 0 && num_jumplist_labels-- != 0 && (bank_num != MVM_OP_BANK_primitives || op_num != MVM_OP_goto)) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "jumplist op must be followed by an additional %d goto ops", num_jumplist_labels + 1); } /*printf("validating op %s, (%d) bank %d", op_info->name, op_num, bank_num);*/ for (i = 0; i < op_info->num_operands; i++) { op_flags = op_info->operands[i]; op_rw = op_flags & MVM_operand_rw_mask; op_type = op_flags & MVM_operand_type_mask; if (op_rw == MVM_operand_literal) { switch (op_type) { case MVM_operand_int8: operand_size = 1; break; case MVM_operand_int16: operand_size = 2; break; case MVM_operand_int32: operand_size = 4; break; case MVM_operand_int64: operand_size = 8; if (bank_num == MVM_OP_BANK_primitives && op_num == MVM_OP_jumplist) { if (cur_op + operand_size > bytecode_end) throw_past_end(tc, labels); num_jumplist_labels = GET_I64(cur_op, 0); if (num_jumplist_labels < 0 || num_jumplist_labels > 4294967295u) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "num_jumplist_labels %d out of range", num_jumplist_labels); } } break; case MVM_operand_num32: operand_size = 4; break; case MVM_operand_num64: operand_size = 8; break; case MVM_operand_callsite: operand_size = 2; if (cur_op + operand_size > bytecode_end) throw_past_end(tc, labels); operand_target = GET_UI16(cur_op, 0); if (operand_target >= cu->num_callsites) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: callsites index (%u) out of range; frame has %u callsites", operand_target, cu->num_callsites); } break; case MVM_operand_coderef: operand_size = 2; if (cur_op + operand_size > bytecode_end) throw_past_end(tc, labels); operand_target = GET_UI16(cur_op, 0); if (operand_target >= cu->num_frames) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: coderef index (%u) out of range; frame has %u coderefs", operand_target, cu->num_frames); } break; /* reset to 0 */ case MVM_operand_str: operand_size = 2; if (cur_op + operand_size > bytecode_end) throw_past_end(tc, labels); operand_target = GET_UI16(cur_op, 0); if (operand_target >= cu->num_strings) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: strings index (%u) out of range (0-%u)", operand_target, cu->num_strings - 1); } break; case MVM_operand_ins: operand_size = 4; if (cur_op + operand_size > bytecode_end) throw_past_end(tc, labels); branch_target = GET_UI32(cur_op, 0); if (branch_target >= bytecode_size) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: branch instruction offset (%u) out of range; frame has %u bytes", branch_target, bytecode_size); } labels[branch_target] |= MVM_val_branch_target; break; case MVM_operand_obj: case MVM_operand_type_var: cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: that operand type (%u) can't be a literal", (MVMuint8)op_type); break; default: { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: non-existent operand type (%u)", (MVMuint8)op_type); } } if (cur_op + operand_size > bytecode_end) throw_past_end(tc, labels); } else if (op_rw == MVM_operand_read_reg || op_rw == MVM_operand_write_reg) { /* register operand */ operand_size = 2; if (cur_op + operand_size > bytecode_end) throw_past_end(tc, labels); if (GET_REG(cur_op, 0) >= num_locals) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: operand register index (%u) out of range; frame has %u locals; at byte %u", GET_REG(cur_op, 0), num_locals, cur_op - bytecode_start); } if (op_type == MVM_operand_type_var) { if (operand_type_var) { /* XXX assume only one type variable */ if ((static_frame->local_types[GET_REG(cur_op, 0)] << 3) != operand_type_var) { cleanup_all(tc, labels); MVM_exception_throw_adhoc(tc, "Bytecode validation error: inconsistent operand types %d and %d to op '%s' with a type variable, at instruction %d", static_frame->local_types[GET_REG(cur_op, 0)], operand_type_var >> 3, op_info->name, instruction); } } else { operand_type_var = (static_frame->local_types[GET_REG(cur_op, 0)] << 3); } } else if ((static_frame->local_types[GET_REG(cur_op, 0)] << 3) != op_type) {
void main(int argc, char **argv) { Errcode err; UBYTE oldconfig; static Argparse_list apl[] = { ARGP(apl,0,"-flic",get_flic_arg), ARGP(apl,APLAST,"-poc",get_poco_arg), }; if((err = init_pj_startup(apl,get_rest_of_command_line,argc,argv, "pj_help","aa.mu")) < Success) { goto error; } oldconfig = err; add_local_pdr(&fli_local_pdr); add_local_pdr(&pic_local_pdr); set_hotkey_func(do_pj_hotkey); /* set input hot key function */ /* initialize pj resource files */ if((err = init_pj_resources()) < Success) goto error; if((err = init_ptools()) < Success) /* initialize tools */ goto error; if((err = init_inks()) < Success) /* load any loadable inks */ goto error; if(cl_poco_name != NULL) { if ((err = compile_cl_poco(cl_poco_name)) < Success) { if (err == Err_in_err_file) po_file_to_stdout(poco_err_name); err = Err_reported; goto error; } } vs = default_vs; /* copy in default settings */ if((err = open_pj_startup_screen(init_after_screen)) < Success) goto error; #ifdef WIDGET widge_ask = TRUE; #endif /* WIDGET */ if(!oldconfig) soft_continu_box("newconfig"); if (cl_flic_name != NULL) pj_delete(tflxname); /* Delete old tempflx */ if((err = force_temp_files()) < Success) goto error; if (cl_flic_name != NULL) resize_load_fli(cl_flic_name); err = go_vpaint(); for(;;) { switch(err) { case RESET_SCREEN_SIZE: err = resize_screen(); break; case RESET_NEW_SIZE: case KILL_NEW_SIZE: scrub_cur_frame(); /* clean up act in case user aborts */ flush_tflx(); err = resize_pencel(FALSE,err == RESET_NEW_SIZE); break; case RESET_DEFAULT_FLX: push_close_toscreen(); if((err = clear_vtemps(TRUE)) < 0) goto error; if((err = open_default_flx()) < 0) goto error; case RESTART_VPAINT: err = go_vpaint(); break; case EXIT_SYSTEM: outofhere(TRUE); /* we've exited, don't need to break... */ case QUIT_SYSTEM: outofhere(FALSE); default: /* not a good return */ goto error; } } error: cleanup_all(err); exit(err); }
DLL_EXPORT void cleanup() { cleanup_all(); }
static void cleanup_sig(int sig) { cleanup_all(); exit(sig); }
void _debugFree(void *memoryParameter, int tag) { unsigned char *memory; struct chunkHeader *chunkHeader; struct chunkTrailer *chunkTrailer; struct chunkHeader *walker; struct chunkHeader *previous; memory = memoryParameter; chunkHeader = (struct chunkHeader *)(memory - sizeof(struct chunkHeader)); if (chunkHeader->magicNumber != MAGIC_NUMBER) { dbgf( DBGL_SYS, DBGT_ERR, "invalid magic number in header: %08x, malloc tag = %d, free tag = %d", chunkHeader->magicNumber, chunkHeader->tag, tag ); cleanup_all( -500080 ); } previous = NULL; for (walker = chunkList; walker != NULL; walker = walker->next) { if (walker == chunkHeader) break; previous = walker; } if (walker == NULL) { dbg( DBGL_SYS, DBGT_ERR, "Double free detected, malloc tag = %d, free tag = %d", chunkHeader->tag, tag ); cleanup_all( -500081 ); } if (previous == NULL) chunkList = walker->next; else previous->next = walker->next; chunkTrailer = (struct chunkTrailer *)(memory + chunkHeader->length); if (chunkTrailer->magicNumber != MAGIC_NUMBER) { dbgf( DBGL_SYS, DBGT_ERR, "invalid magic number in trailer: %08x, malloc tag = %d, free tag = %d", chunkTrailer->magicNumber, chunkHeader->tag, tag ); cleanup_all( -500082 ); } #ifdef MEMORY_USAGE removeMemory( chunkHeader->tag, tag ); #endif free(chunkHeader); }
/* Loads the extension op records. */ static MVMExtOpRecord * deserialize_extop_records(MVMThreadContext *tc, MVMCompUnit *cu, ReaderState *rs) { MVMExtOpRecord *extops; MVMuint32 num = rs->expected_extops; MVMuint8 *pos; MVMuint32 i; if (num == 0) return NULL; extops = MVM_calloc(num, sizeof *extops); pos = rs->extop_seg; for (i = 0; i < num; i++) { MVMuint32 name_idx; MVMuint16 operand_bytes = 0; MVMuint8 *operand_descriptor = extops[i].operand_descriptor; /* Read name string index. */ ensure_can_read(tc, cu, rs, pos, 4); name_idx = read_int32(pos, 0); pos += 4; /* Lookup name string. */ if (name_idx >= cu->body.num_strings) { cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "String heap index beyond end of string heap"); } extops[i].name = MVM_cu_string(tc, cu, name_idx); /* Read operand descriptor. */ ensure_can_read(tc, cu, rs, pos, 8); memcpy(operand_descriptor, pos, 8); pos += 8; /* Validate operand descriptor. * TODO: Unify with validation in MVM_ext_register_extop? */ { MVMuint8 j = 0; for(; j < 8; j++) { MVMuint8 flags = operand_descriptor[j]; if (!flags) break; switch (flags & MVM_operand_rw_mask) { case MVM_operand_literal: goto check_literal; case MVM_operand_read_reg: case MVM_operand_write_reg: operand_bytes += 2; goto check_reg; case MVM_operand_read_lex: case MVM_operand_write_lex: operand_bytes += 4; goto check_reg; default: goto fail; } check_literal: switch (flags & MVM_operand_type_mask) { case MVM_operand_int8: operand_bytes += 1; continue; case MVM_operand_int16: operand_bytes += 2; continue; case MVM_operand_int32: operand_bytes += 4; continue; case MVM_operand_int64: operand_bytes += 8; continue; case MVM_operand_num32: operand_bytes += 4; continue; case MVM_operand_num64: operand_bytes += 8; continue; case MVM_operand_str: operand_bytes += 2; continue; case MVM_operand_coderef: operand_bytes += 2; continue; case MVM_operand_ins: case MVM_operand_callsite: default: goto fail; } check_reg: switch (flags & MVM_operand_type_mask) { case MVM_operand_int8: case MVM_operand_int16: case MVM_operand_int32: case MVM_operand_int64: case MVM_operand_num32: case MVM_operand_num64: case MVM_operand_str: case MVM_operand_obj: case MVM_operand_type_var: case MVM_operand_uint8: case MVM_operand_uint16: case MVM_operand_uint32: case MVM_operand_uint64: continue; default: goto fail; } fail: cleanup_all(tc, rs); MVM_exception_throw_adhoc(tc, "Invalid operand descriptor"); } } extops[i].operand_bytes = operand_bytes; } return extops; }
static void avl_test() { struct avl_node *an = NULL; AVL_TREE(t, sizeof (int)); int i; struct p { int i; int v; }; struct p * p; for (i = 0; i <= 19; i++) { p = debugMalloc(sizeof ( struct p), 999); p->i = i; p->v = 0; avl_insert(&t, p); } for (i = 19; i >= 10; i--) { p = avl_remove(&t, &i); printf(" removed %d/%d\n", p->i, p->v ); debugFree( p, 1999 ); } for (i = 9; i >= 0; i--) { p = debugMalloc(sizeof ( struct p), 999); p->i = i; p->v = 1; avl_insert(&t, p); } for (i = 5; i <= 15; i++) { p = debugMalloc(sizeof ( struct p), 999); p->i = i; p->v = 2; avl_insert(&t, p); } for (i = 3; i <= 9; i++) { p = debugMalloc(sizeof ( struct p), 999); p->i = 2; p->v = i; avl_insert(&t, p); } printf("\navl_iterate():\n"); i=0; an = NULL; while( (an = avl_iterate( &t, an ) ) ) { p = ((struct p*)(an->key)); if ( i > p->i) printf("\nERROR %d > %d \n", i, p->i); i = p->i; printf( "%3d/%1d ", p->i, p->v ); } printf("\n"); #ifdef AVL_DEBUG printf("avl_debug():\n"); avl_debug( &t ); #endif for (i = 9; i >= 3; i--) { int v = 2; if ((p = avl_remove(&t, &v)) ) { printf(" removed %d/%d\n", p->i, p->v); debugFree(p, 1999); } } for (i = 9; i >= 0; i--) { if ( (p = avl_remove(&t, &i) ) ) { printf(" removed %d/%d\n", p->i, p->v); debugFree(p, 1999); } } for (i = 0; i <= 19; i++) { if ((p = avl_remove(&t, &i))) { printf(" removed %d/%d\n", p->i, p->v); debugFree(p, 1999); } else { printf(" failed rm %d\n", i); } } /* for (i = 20; i >= 0; i--) { p = debugMalloc(sizeof ( struct p), 999); p->i = i; p->v = 5; avl_insert(&t, p); } */ i = 0; printf("\n"); printf("\navl_next():\n"); int32_t j = 0; while( (an = avl_next( &t, &j )) ) { p = ((struct p*)(an->key)); j = p->i; if ( i > p->i) printf("\nERROR %d > %d \n", i, p->i); i = p->i; printf( "N%4d/%1d ", p->i, p->v ); if ( i%10 == 0 ) printf("\n"); } printf("\navl_iterate():\n"); i=0; while( (an = avl_iterate( &t, an ) ) ) { p = ((struct p*)(an->key)); if ( i > p->i) printf("\nERROR %d > %d \n", i, p->i); i = p->i; printf( "%3d/%1d ", p->i, p->v ); } printf("\n"); #ifdef AVL_DEBUG printf("avl_debug():\n"); avl_debug( &t ); #endif while( t.root ) { p = (struct p*)t.root->key; p = avl_remove( &t, p ); printf(" removed %d/%d\n", p->i, p->v ); debugFree( p, 1999 ); } printf("\n"); cleanup_all(CLEANUP_SUCCESS); }