void *malloc (size_t size) { void *ret; int pool_idx; if (malloc_base == NULL || size == 0) { ret = NULL; } else if (size >= MAX_ELEM_SIZE) { ret = big_malloc((size + PAGE_SIZE - 1) / PAGE_SIZE); } else { if (size <= MIN_ELEM_SIZE) pool_idx = 0; else { pool_idx = get_pool_idx(size); } ret = pool_malloc(pool_idx); } if (ret != NULL) memset(ret, 0, size); #if 0 memory_dump(); printf("%s(%d) => %p\n", __func__, size, ret); #endif return ret; }
// memory commands static void cmd_memory(void) { u08 cmd,res; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { case 'i': res = memory_init(); set_result(res); break; case 'c': res = memory_check(parse_hex_byte(0)); set_result(res); break; case 'd': memory_dump(parse_hex_byte(0),parse_hex_byte(0)); set_result(STATUS_OK); break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } }
// Creates one index containing all tokens // Uses sort-based multiway merge void InvertedIndex::sorted_index(string temp_name){ int value, i = 0; vector<int> aux(5); bool test, final = false; priority_queue<vector<int>, vector<vector<int>>, comparator> min_heap; if (this->memory_usage){ memory_dump(); } cout << "Saving"; cout << " text index\n"; cout << "Total of files evaluated: " << this->total_docs << endl; cout << "Total tokens: " << this->total_size_index << " " << this->total_token << endl; cout << "Vocabulary size: " << this->vocabulary.size() << endl; cout << "Memory Limit: " << (MEMORY_LIMITE/INDEX_LINE_SIZE) << endl; cout << "Total of files: " << this->n_dumps << endl << endl; this->vocabulary_init(temp_name); while(i < this->n_dumps){ int n_files; fstream out; // Testing wether is possible to open all files at once if ((this->n_dumps - i) <= (MEMORY_LIMITE/INDEX_LINE_SIZE) && ((this->n_dumps - i) < (MAX_OS_OPEN_FILE - 1000))){ // If true, needs saving final sorted index n_files = this->n_dumps - i; out.open(temp_name+INDEX_SORTED_FILE_NAME, ios::out | ios::binary); final = true; } else {
/* stack dump and information dump * for stack dump, a common rules is: * 0x2000xxxx (r7) 0x0000xxxx(lr), r7 will in stack and lr will in flash. * usually 12th long word is the address which calls panic(). */ void panic(char *infostr) { uint32_t sp; uint32_t size; fsave(); kprintf("PANIC: %s\n", infostr); #if 0 if(get_psr() & 0xFF){ /* in exception context, dump exception stack */ sp = __get_MSP(); if((sp>(uint32_t)_irq_stack_start) && (sp<(uint32_t)_irq_stack_start+1024)) { size = (uint32_t)_irq_stack_start+1024-sp; kprintf("exception stacks: sp=0x%x depth=%d bytes\n", sp, size); dump_buffer((uint8_t *)sp, size); } else kprintf("broken MSP: 0x%x\n", sp); } if((current>=&systask[0]) && (current<&systask[MAX_TASK_NUMBER])) { /* dump task stack */ sp = __get_PSP(); if((sp>(uint32_t)current->stack_base) && (sp<(uint32_t)current->stack_base+current->stack_size)) { size = (uint32_t)current->stack_base+current->stack_size-sp; kprintf("task stacks: sp=0x%x depth=%d bytes\n", sp, size); dump_buffer((uint8_t *)sp, size); } else kprintf("broken PSP: 0x%x\n", sp); /* dump current task info */ kprintf("current=0x%x last sp=0x%x stack_base=0x%x taskname=%s state=%d taskq=0x%x\n", current, current->sp, current->stack_base, current->name, current->state, current->taskq); } else kprintf("current is overwriten! current=0x%x\n", current); #endif // 0 /* dump system ready queue */ /* dump memory usage */ memory_dump(); while(1); }
int main(int argc, char **argv) { if(argc < 2) { printf("Especifique o arquivo com o codigo\n"); exit(0); } init_memory(); init_stack(); loadcode(argv[1]); init_cpu(); while(cpu_cycle()); memory_dump(); free_memory(); return 0; }
void signal_user2(int sig) { int i; signal(SIGUSR2, signal_user2); sig = sig; context(); ioutput(OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "-------------------------------------------"); ioutput(OUTPUT_DEST_LOG | OUTPUT_DEST_NO | OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "context trace"); context_dump(OUTPUT_DEST_CORE); ioutput(OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "-------------------------------------------"); ioutput(OUTPUT_DEST_LOG | OUTPUT_DEST_NO | OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "memory trace"); ioutput(OUTPUT_DEST_LOG | OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "%i memory units allocated", g.meminfo_depth); memory_dump(OUTPUT_DEST_CORE); ioutput(OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "-------------------------------------------"); ioutput(OUTPUT_DEST_LOG | OUTPUT_DEST_NO | OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "timer queue dump"); for (i=0; i<TIMER_QUEUE_SIZE; i++) ioutput(OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "timer %d/%d value (%d)", i, TIMER_QUEUE_SIZE, g.timer_wait_queue[i]); ioutput(OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "-------------------------------------------"); module_dumpstatus(); return; }
void signal_crash(int sig) { signal(SIGBUS, SIG_DFL); //crash signal(SIGABRT, SIG_DFL); //crash signal(SIGILL, SIG_DFL); //crash signal(SIGFPE, SIG_DFL); //crash signal(SIGSEGV, SIG_DFL); //crash sig = sig; ioutput(OUTPUT_DEST_LOG | OUTPUT_DEST_NO | OUTPUT_TYPE_INFO, "got signal crash (SIGBUS/ABRT/ILL/FPE/SEGV) !"); #ifdef DEBUG_ENABLED ioutput(OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "-------------------------------------------"); ioutput(OUTPUT_DEST_LOG | OUTPUT_DEST_NO | OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "context trace"); context_dump(OUTPUT_DEST_CORE); ioutput(OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "-------------------------------------------"); ioutput(OUTPUT_DEST_LOG | OUTPUT_DEST_NO | OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "memory trace"); ioutput(OUTPUT_DEST_LOG | OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "%i memory units allocated", g.meminfo_depth); memory_dump(OUTPUT_DEST_CORE); ioutput(OUTPUT_DEST_CORE | OUTPUT_TYPE_DEBUG, "-------------------------------------------"); #endif abort(); /* will crash when we leave the function because returning signal handling back to default */ }
void SAM(C64 *the_c64) { bool done = false; char c; TheCPU = the_c64->TheCPU; TheCPU1541 = the_c64->TheCPU1541; TheVIC = the_c64->TheVIC; TheSID = the_c64->TheSID; TheCIA1 = the_c64->TheCIA1; TheCIA2 = the_c64->TheCIA2; // Get CPU registers and current memory configuration TheCPU->GetState(&R64); TheCPU->ExtConfig = (~R64.ddr | R64.pr) & 7; TheCPU1541->GetState(&R1541); #ifdef __riscos__ Wimp_CommandWindow((int)"SAM"); #endif #ifdef AMIGA if (!(fin = fout = ferr = fopen("CON:0/0/640/480/SAM", "w+"))) return; #else fin = stdin; fout = stdout; ferr = stdout; #endif access_1541 = false; address = R64.pc; fprintf(ferr, "\n *** SAM - Simple Assembler and Monitor ***\n *** Press 'h' for help ***\n\n"); init_abort(); display_registers(); while (!done) { if (access_1541) fprintf(ferr, "1541> "); else fprintf(ferr, "C64> "); fflush(ferr); read_line(); while ((c = get_char()) == ' ') ; switch (c) { case 'a': // Assemble get_token(); assemble(); break; case 'b': // Binary dump get_token(); binary_dump(); break; case 'c': // Compare get_token(); compare(); break; case 'd': // Disassemble get_token(); disassemble(); break; case 'e': // Interrupt vectors int_vectors(); break; case 'f': // Fill get_token(); fill(); break; case 'h': // Help help(); break; case 'i': // ASCII dump get_token(); ascii_dump(); break; case 'k': // Memory configuration get_token(); mem_config(); break; case 'l': // Load data get_token(); load_data(); break; case 'm': // Memory dump get_token(); memory_dump(); break; case 'n': // Screen code dump get_token(); screen_dump(); break; case 'o': // Redirect output get_token(); redir_output(); break; case 'p': // Sprite dump get_token(); sprite_dump(); break; case 'r': // Registers get_reg_token(); registers(); break; case 's': // Save data get_token(); save_data(); break; case 't': // Transfer get_token(); transfer(); break; case 'v': // View machine state view_state(); break; case 'x': // Exit done = true; break; case ':': // Change memory get_token(); modify(); break; case '1': // Switch to 1541 mode access_1541 = true; break; case '6': // Switch to C64 mode access_1541 = false; break; case '?': // Compute expression get_token(); print_expr(); break; case '\n': // Blank line break; default: // Unknown command error("Unknown command"); break; } } exit_abort(); #ifdef AMIGA fclose(fin); #endif if (fout != ferr) fclose(fout); #ifdef __riscos__ Wimp_CommandWindow(-1); #endif // Set CPU registers TheCPU->SetState(&R64); TheCPU1541->SetState(&R1541); }
/* * NOTES: * - val_len is ignored for everything other than PT_BYTEBUF. * - fromuser is ignored for numeric types */ inline int val_to_ring(struct event_filler_arguments *args, uint64_t val, u16 val_len, bool fromuser) { int len = -1; u16 *psize = (u16 *)(args->buffer + args->curarg * sizeof(u16)); if (unlikely(args->curarg >= args->nargs)) { pr_info("(%u)val_to_ring: too many arguments for event #%u, type=%u, curarg=%u, nargs=%u tid:%u\n", smp_processor_id(), args->nevents, (u32)args->event_type, args->curarg, args->nargs, current->pid); memory_dump(args->buffer - sizeof(struct ppm_evt_hdr), 32); ASSERT(0); return PPM_FAILURE_BUG; } switch (g_event_info[args->event_type].params[args->curarg].type) { case PT_CHARBUF: case PT_FSPATH: if (likely(val != 0)) { if (fromuser) { len = ppm_strncpy_from_user(args->buffer + args->arg_data_offset, (const char __user *)(unsigned long)val, args->arg_data_size); if (unlikely(len < 0)) return PPM_FAILURE_INVALID_USER_MEMORY; } else { char *dest = strncpy(args->buffer + args->arg_data_offset, (const char *)(unsigned long)val, args->arg_data_size); dest[args->arg_data_size - 1] = 0; len = strlen(dest) + 1; } /* * Make sure the string is null-terminated */ *(char *)(args->buffer + args->arg_data_offset + len) = 0; } else { /* * Handle NULL pointers */ char *dest = strncpy(args->buffer + args->arg_data_offset, "(NULL)", args->arg_data_size); dest[args->arg_data_size - 1] = 0; len = strlen(dest) + 1; } break; case PT_BYTEBUF: case PT_SOCKADDR: case PT_SOCKTUPLE: case PT_FDLIST: if (likely(val != 0)) { if (unlikely(val_len >= args->arg_data_size)) { return PPM_FAILURE_BUFFER_FULL; } else { if (fromuser) { len = (int)ppm_copy_from_user(args->buffer + args->arg_data_offset, (const void __user *)(unsigned long)val, val_len); if (unlikely(len != 0)) return PPM_FAILURE_INVALID_USER_MEMORY; len = val_len; } else { memcpy(args->buffer + args->arg_data_offset, (void *)(unsigned long)val, val_len); len = val_len; } } } else { /* * Handle NULL pointers */ len = 0; } break; case PT_FLAGS8: case PT_UINT8: case PT_SIGTYPE: if (likely(args->arg_data_size >= sizeof(u8))) { *(u8 *)(args->buffer + args->arg_data_offset) = (u8)val; len = sizeof(u8); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_FLAGS16: case PT_UINT16: case PT_SYSCALLID: if (likely(args->arg_data_size >= sizeof(u16))) { *(u16 *)(args->buffer + args->arg_data_offset) = (u16)val; len = sizeof(u16); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_FLAGS32: case PT_UINT32: if (likely(args->arg_data_size >= sizeof(u32))) { *(u32 *)(args->buffer + args->arg_data_offset) = (u32)val; len = sizeof(u32); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_RELTIME: case PT_ABSTIME: case PT_UINT64: if (likely(args->arg_data_size >= sizeof(u64))) { *(u64 *)(args->buffer + args->arg_data_offset) = (u64)val; len = sizeof(u64); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_INT8: if (likely(args->arg_data_size >= sizeof(s8))) { *(s8 *)(args->buffer + args->arg_data_offset) = (s8)(long)val; len = sizeof(s8); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_INT16: if (likely(args->arg_data_size >= sizeof(s16))) { *(s16 *)(args->buffer + args->arg_data_offset) = (s16)(long)val; len = sizeof(s16); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_INT32: if (likely(args->arg_data_size >= sizeof(s32))) { *(s32 *)(args->buffer + args->arg_data_offset) = (s32)(long)val; len = sizeof(s32); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_INT64: case PT_ERRNO: case PT_FD: case PT_PID: if (likely(args->arg_data_size >= sizeof(s64))) { *(s64 *)(args->buffer + args->arg_data_offset) = (s64)(long)val; len = sizeof(s64); } else { return PPM_FAILURE_BUFFER_FULL; } break; default: ASSERT(0); pr_info("val_to_ring: invalid argument type %d. Event %u (%s) might have less parameters than what has been declared in nparams\n", (int)g_event_info[args->event_type].params[args->curarg].type, (u32)args->event_type, g_event_info[args->event_type].name); return PPM_FAILURE_BUG; } ASSERT(len <= 65535); ASSERT(len <= args->arg_data_size); *psize = (u16)len; args->curarg++; args->arg_data_offset += len; args->arg_data_size -= len; return PPM_SUCCESS; }
/* * NOTES: * - val_len is ignored for everything other than PT_BYTEBUF. * - fromuser is ignored for numeric types * - dyn_idx is ignored for everything other than PT_DYN */ int val_to_ring(struct event_filler_arguments *args, uint64_t val, u16 val_len, bool fromuser, u8 dyn_idx) { const struct ppm_param_info *param_info; int len = -1; u16 *psize = (u16 *)(args->buffer + args->curarg * sizeof(u16)); if (unlikely(args->curarg >= args->nargs)) { pr_err("(%u)val_to_ring: too many arguments for event #%u, type=%u, curarg=%u, nargs=%u tid:%u\n", smp_processor_id(), args->nevents, (u32)args->event_type, args->curarg, args->nargs, current->pid); memory_dump(args->buffer - sizeof(struct ppm_evt_hdr), 32); ASSERT(0); return PPM_FAILURE_BUG; } if (unlikely(args->arg_data_size == 0)) return PPM_FAILURE_BUFFER_FULL; param_info = &(g_event_info[args->event_type].params[args->curarg]); if (param_info->type == PT_DYN && param_info->info != NULL) { const struct ppm_param_info *dyn_params; if (unlikely(dyn_idx >= param_info->ninfo)) { ASSERT(0); return PPM_FAILURE_BUG; } dyn_params = (const struct ppm_param_info *)param_info->info; param_info = &dyn_params[dyn_idx]; if (likely(args->arg_data_size >= sizeof(u8))) { *(u8 *)(args->buffer + args->arg_data_offset) = dyn_idx; len = sizeof(u8); } else { return PPM_FAILURE_BUFFER_FULL; } args->arg_data_offset += len; args->arg_data_size -= len; *psize = (u16)len; } else { *psize = 0; } switch (param_info->type) { case PT_CHARBUF: case PT_FSPATH: if (likely(val != 0)) { if (fromuser) { len = ppm_strncpy_from_user(args->buffer + args->arg_data_offset, (const char __user *)(unsigned long)val, args->arg_data_size); if (unlikely(len < 0)) return PPM_FAILURE_INVALID_USER_MEMORY; } else { len = strlcpy(args->buffer + args->arg_data_offset, (const char *)(unsigned long)val, args->arg_data_size); if (++len > args->arg_data_size) len = args->arg_data_size; } /* * Make sure the string is null-terminated */ *(char *)(args->buffer + args->arg_data_offset + len) = 0; } else { /* * Handle NULL pointers */ len = strlcpy(args->buffer + args->arg_data_offset, "(NULL)", args->arg_data_size); if (++len > args->arg_data_size) len = args->arg_data_size; } break; case PT_BYTEBUF: if (likely(val != 0)) { if (fromuser) { /* * Copy the lookahead portion of the buffer that we will use DPI-based * snaplen calculation */ u32 dpi_lookahead_size = DPI_LOOKAHED_SIZE; if (dpi_lookahead_size > val_len) dpi_lookahead_size = val_len; if (unlikely(dpi_lookahead_size >= args->arg_data_size)) return PPM_FAILURE_BUFFER_FULL; len = (int)ppm_copy_from_user(args->buffer + args->arg_data_offset, (const void __user *)(unsigned long)val, dpi_lookahead_size); if (unlikely(len != 0)) return PPM_FAILURE_INVALID_USER_MEMORY; /* * Check if there's more to copy */ if (likely((dpi_lookahead_size != val_len))) { /* * Calculate the snaplen */ if (likely(args->enforce_snaplen)) { u32 sl = args->consumer->snaplen; sl = compute_snaplen(args, args->buffer + args->arg_data_offset, dpi_lookahead_size); if (val_len > sl) val_len = sl; } if (unlikely((val_len) >= args->arg_data_size)) val_len = args->arg_data_size; if (val_len > dpi_lookahead_size) { len = (int)ppm_copy_from_user(args->buffer + args->arg_data_offset + dpi_lookahead_size, (const void __user *)(unsigned long)val + dpi_lookahead_size, val_len - dpi_lookahead_size); if (unlikely(len != 0)) return PPM_FAILURE_INVALID_USER_MEMORY; } } len = val_len; } else { if (likely(args->enforce_snaplen)) { u32 sl = compute_snaplen(args, (char *)(unsigned long)val, val_len); if (val_len > sl) val_len = sl; } if (unlikely(val_len >= args->arg_data_size)) return PPM_FAILURE_BUFFER_FULL; memcpy(args->buffer + args->arg_data_offset, (void *)(unsigned long)val, val_len); len = val_len; } } else { /* * Handle NULL pointers */ len = 0; } break; case PT_SOCKADDR: case PT_SOCKTUPLE: case PT_FDLIST: if (likely(val != 0)) { if (unlikely(val_len >= args->arg_data_size)) return PPM_FAILURE_BUFFER_FULL; if (fromuser) { len = (int)ppm_copy_from_user(args->buffer + args->arg_data_offset, (const void __user *)(unsigned long)val, val_len); if (unlikely(len != 0)) return PPM_FAILURE_INVALID_USER_MEMORY; len = val_len; } else { memcpy(args->buffer + args->arg_data_offset, (void *)(unsigned long)val, val_len); len = val_len; } } else { /* * Handle NULL pointers */ len = 0; } break; case PT_FLAGS8: case PT_UINT8: case PT_SIGTYPE: if (likely(args->arg_data_size >= sizeof(u8))) { *(u8 *)(args->buffer + args->arg_data_offset) = (u8)val; len = sizeof(u8); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_FLAGS16: case PT_UINT16: case PT_SYSCALLID: if (likely(args->arg_data_size >= sizeof(u16))) { *(u16 *)(args->buffer + args->arg_data_offset) = (u16)val; len = sizeof(u16); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_FLAGS32: case PT_UINT32: case PT_UID: case PT_GID: case PT_SIGSET: if (likely(args->arg_data_size >= sizeof(u32))) { *(u32 *)(args->buffer + args->arg_data_offset) = (u32)val; len = sizeof(u32); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_RELTIME: case PT_ABSTIME: case PT_UINT64: if (likely(args->arg_data_size >= sizeof(u64))) { *(u64 *)(args->buffer + args->arg_data_offset) = (u64)val; len = sizeof(u64); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_INT8: if (likely(args->arg_data_size >= sizeof(s8))) { *(s8 *)(args->buffer + args->arg_data_offset) = (s8)(long)val; len = sizeof(s8); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_INT16: if (likely(args->arg_data_size >= sizeof(s16))) { *(s16 *)(args->buffer + args->arg_data_offset) = (s16)(long)val; len = sizeof(s16); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_INT32: if (likely(args->arg_data_size >= sizeof(s32))) { *(s32 *)(args->buffer + args->arg_data_offset) = (s32)(long)val; len = sizeof(s32); } else { return PPM_FAILURE_BUFFER_FULL; } break; case PT_INT64: case PT_ERRNO: case PT_FD: case PT_PID: if (likely(args->arg_data_size >= sizeof(s64))) { *(s64 *)(args->buffer + args->arg_data_offset) = (s64)(long)val; len = sizeof(s64); } else { return PPM_FAILURE_BUFFER_FULL; } break; default: ASSERT(0); pr_err("val_to_ring: invalid argument type %d. Event %u (%s) might have less parameters than what has been declared in nparams\n", (int)g_event_info[args->event_type].params[args->curarg].type, (u32)args->event_type, g_event_info[args->event_type].name); return PPM_FAILURE_BUG; } ASSERT(len <= 65535); ASSERT(len <= args->arg_data_size); *psize += (u16)len; args->curarg++; args->arg_data_offset += len; args->arg_data_size -= len; return PPM_SUCCESS; }
bool cn_show_debug_memory_dump_execute(console_base &cb, utf8str command) { cb.print(memory_dump()); return true; }
void example_2() { int array[] = {7, 3, 2, 10, -5}; int size = sizeof(array) / sizeof(int); memory_dump(array, size * sizeof(int), 4); }
void example_1() { char* text = "I love to break free"; int len = strlen(text) + 1; memory_dump(text, len, 5); }
/** * Prints out the state of the emulator * * @param emu Reference to the emulator structure */ void emulator_dump(emulator_t* emu) { cpu_dump(&emu->cpu); memory_dump(&emu->memory); }