void print_regs(struct pushregs *regs) { int i; for (i = 0; i < 30; i++) { cprintf(" $"); printbase10(i+1); cprintf("\t: "); printhex(regs->reg_r[i]); cputchar('\n'); } }
/* * * print_kerninfo - print the information about kernel, including the location * of kernel entry, the start addresses of data and text segements, the start * address of free memory and how many memory that kernel has used. * */ void print_kerninfo(void) { extern char etext[], edata[], end[], kern_init[]; kprintf("Special kernel symbols:\n"); kprintf(" entry 0x"); printhex((unsigned int)kern_init); kprintf(" (phys)\n"); kprintf(" etext\t0x"); printhex((unsigned int)etext); kprintf(" (phys)\n"); kprintf(" edata\t0x"); printhex((unsigned int)edata); kprintf(" (phys)\n"); kprintf(" end\t0x"); printhex((unsigned int)end); kprintf(" (phys)\n"); kprintf("Kernel executable memory footprint: "); printbase10( (end - etext + 1023)>>10 ); kprintf("KB\n"); }
void updateScoreMoney(int addScore, int income) { info.score += addScore; info.currency += income; updateScoreFrame(); printhex(info.score); char second_row2[15]; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0); sprintf(second_row2, "$$ %d ", info.currency); alt_up_character_lcd_string(char_lcd_dev, second_row2); }
int main () { int i, val; puts ("Testing integer shift.\n"); printhex (0x1234); putchar ('\n'); printhex (0x4321); putchar ('\n'); for (i=0; i<16; ++i) { puts ("1 << "); printhex (i); puts (" --> "); val = 1; val <<= i; printhex (val); puts (", 0x8000 >> "); printhex (i); puts (" --> "); val = 0x8000; val >>= i; printhex (val); puts ("\n"); } puts ("Done.\n"); return 0; }
//--------------------------------------------------------------------------------------- unsigned char *readdata(void) { unsigned char c, maske, z, s, row; for(z=0; z<8; z++) { row=0; for(s=0; s<5; s++) { c=getchar(); if(c=='0' || c==' ') c='0'; else if(c==0x1B) return(NULL); // unvollendet else if(c==ENTER) // daten[k] fetig { while(s<5) { maske=0x10>>s; row=row&~maske; // 0 eintragen putchar('_'); s++; } break; } else if(c==0x08) // Backspace { if(s>0) { s--; putchar(c); // Backspace ausgeben } s--; continue; } if(c == '0') putchar('.'); else putchar('#'); maske=0x10>>s; if(c=='0') row=row&~maske; // 0 eintragen else row=row|maske; // 1 eintragen } daten[z]=row; printstring(" daten["); putchar(z+'0'); printstring("] = "); printhex(daten[z]); putchar('\n'); }
void game_frame() { static char cbak; static int8_t gpx, gpy; // mouse vram[cy / 8][cx / 8] = cbak; cy += mouse_y; mouse_y=0; if (cy < 0) cy = VGA_V_PIXELS; else if (cy >= VGA_V_PIXELS) cy = 0; cx += mouse_x; mouse_x=0; if (cx < 0) cx = VGA_H_PIXELS; else if (cx >= VGA_H_PIXELS) cx = 0; printhex(11,6,cx/8); printhex(16,6,cy/8); cbak = vram[cy / 8][cx / 8]; vram[cy / 8][cx / 8] = 127; vram[6][19]=mouse_buttons & mousebut_left?'L':'l'; vram[6][20]=mouse_buttons & mousebut_middle?'M':'m'; vram[6][21]=mouse_buttons & mousebut_right?'R':'r'; printhex(23,6,mouse_buttons); // gamepad buttons update_controller(PAD_X, PAD_Y,gamepad_buttons[0]); update_controller(PAD_X, PAD_Y2,gamepad_buttons[1]); // analog gamepad printhex(40,PAD_Y-2,gamepad_x[0]); printhex(43,PAD_Y-2,gamepad_y[0]); vram[15 + gpy / 32][36 + gpx / 16] = ' '; gpx = gamepad_x[0]; gpy = gamepad_y[0]; vram[15 + gpy / 32][36 + gpx / 16] = '+'; // KB codes for (int i=0;i<6;i++) { printhex(5+i*3,KB_Y+2,keyboard_key[0][i]); } // KB mods for (int i=0;i<8;i++) vram[KB_Y+3][5+i]=keyboard_mod[0] & (1<<i) ? KBMOD[i] : '-' ; // low level stuff update_host_status(); }
int main () { int a, b, c; puts ("Testing integer multiplication.\n"); puts (" "); for (b=2; b<10; ++b) { puts (" "); printhex (b); } puts ("\n"); for (a=2; a<10; ++a) { printhex (a); puts (":"); for (b=2; b<10; ++b) { c = a * b; puts (" "); printhex (c); } puts ("\n"); } puts ("Done.\n"); return 0; }
//myprintf function void myprintf(const char *fmt, ...) { const char *p; va_list argp; int i; char *s; va_start(argp, fmt); //for loop for (p = fmt; *p != '\0'; p++) { if (*p != '%') { putchar(*p); continue; } switch (*++p) { //c case 'c': i = va_arg(argp, int); putchar(i); break; //d case 'd': i = va_arg(argp, int); printint(i); break; //s case 's': s = va_arg(argp, char *); printstring(s); break; //x case 'x': i = va_arg(argp, int); printhex(i); break; //% case '%': putchar('%'); break; } } va_end(argp); }
int main() { nfc3d_keygen_derivedkeys outkeys; nfc3d_keygen(&NFC3D_NINKEYS_RETAIL_UNFIXED_INFOS, SEED, &outkeys); printf("Calculated:\n"); printhex(&outkeys, sizeof(outkeys)); printf("Matches console: "); if (memcmp(&CORRECT, &outkeys, sizeof(outkeys)) == 0) { printf("YES\n"); } else { printf("NO\n"); } return 0; }
void printhex2(const char *mem, uint16_t len) { uint16_t i; const uint16_t _len = 10; if (len <= _len) { printhex((const char*)mem, len); return; } printf("[0x%.4x-0x%.4x] ", (int)mem, len + (int)mem); for (i=0; i < _len; i++) printf("%.2x", mem[i]); printf("... + %d bytes\n", len-_len); }
static void dump_message(char *buffer) { printf("message received\r\n content: "); printhex(buffer, PKTLEN); printf("\r\n type: "); switch(buffer[MSG_BYTE_TYPE]) { case MSG_TYPE_ID_REQUEST: printf("id request"); break; case MSG_TYPE_ID_REPLY: printf("id reply"); break; case MSG_TYPE_TEMPERATURE: printf("temperature"); break; } printf("\r\n num hops: %d\r\n", buffer[MSG_BYTE_HOPS]); printf(" route: "); unsigned int i; for(i = MSG_BYTE_SRC_ROUTE; i < MSG_BYTE_SRC_ROUTE + buffer[MSG_BYTE_HOPS]; i++) { if(buffer[i] == 0x00) { printf("undefined"); } else { printf("%02X", buffer[i]); } if(i < MSG_BYTE_SRC_ROUTE + buffer[MSG_BYTE_HOPS]) { printf("->"); } } printf("%02X\r\n", node_id); if(buffer[MSG_BYTE_TYPE] == MSG_TYPE_TEMPERATURE) { unsigned int temperature; char *pt = (char *) &temperature; pt[0] = buffer[MSG_BYTE_CONTENT + 1]; pt[1] = buffer[MSG_BYTE_CONTENT]; printf(" temperature: %d\r\n", temperature); } }
void *dmr_handle_data_hook(char *pkt, int len){ /* This hook handles the dmr_contact_check() function, calling back to the original function where appropriate. Packes are up to twelve bytes, but they are always preceeded by two bytes of C5000 overhead. */ //Turn on the red LED to know that we're here. red_led(1); printf("Data: "); printhex(pkt,len+2); printf("\n"); //Forward to the original function. return dmr_handle_data(pkt,len); }
// 0 1 2 3 4 5 6 7 // |...|...|...|...|...|...|...|...| // ^ // | // sample bit 3 times // // Display the HEX value of the digital stream void HEXSerial(void) { int8_t start,end; int16_t increment,index; // The vertical cursors define the section to decode start = M.VcursorA; end = M.VcursorB; // If the vertical cursors are off, use the entire screen if(!testbit(Mcursors, cursorv)) { start = 0; end = 127; } increment = (end-start); increment<<=3; if(Srate>=11) { increment*=2; start=start<<1; } uint8_t result; // Does not need to be initialized uint8_t data,bit=0,yPos,mask; yPos = M.CHDpos>>3; for(mask=0x80; mask; mask=mask>>1) { // Loop 8 digital channels index = (start<<8); if(Srate<11) index+=(M.HPos<<8); index+=increment; if(CHDmask&mask) { // Is this channel on? for(uint8_t i=1; i<=32; i++) { // Scan buffer data = DC.CHDdata[hibyte(index)]; if(!(i&0x03)) { // Time to check bits when i is multiple of 4 result<<=1; if(bit) result+=1; bit=0; } else { if(data&mask) bit++; } index+=increment; } lcd_goto(120,yPos); // Print on right edge of the screen printhex(result); yPos++; } } }
void myprintf(const char *fmt, ...) {//instructer's code here: const char *p; va_list argp; int i; char *s; va_start(argp, fmt); for (p = fmt; *p != '\0'; p++) { if (*p != '%') { putchar(*p); continue; } switch (*++p) { case 'c': i = va_arg(argp, int); putchar(i); break; case 'd': i = va_arg(argp, int); printint(i); break; case 's': s = va_arg(argp, char *); printstring(s); break; case 'x': i = va_arg(argp, int); printhex(i); break; case '%': putchar('%'); break; } } va_end(argp); }
static int MakeAuthString(char *auth_name, char *data, int len, char **auth_ret) { char *auth, *ptr; int name_len; name_len = strlen(auth_name); /* we'll have the name + ':' + 2 characters per byte + '\0' */ auth = (char *) Malloc(name_len + 1 + 2*len + 1); if (auth == NULL) return 1; strcpy(auth, auth_name); ptr = auth + name_len; *ptr++ = ':'; printhex(ptr, (unsigned char *)data, len); *auth_ret = auth; return 0; }
int base64decode (char *in, size_t inLen, unsigned char *out, size_t *outLen) { char *end = in + inLen; char iter = 0; size_t buf = 0, len = 0; url64decode(in); V17DO printf("base64:dec:"); V17DO printhex((byte*)in, inLen); V17DO printf("\n"); while (in < end) { unsigned char c = d[*in++]; switch (c) { case WHITESPACE: continue; /* skip whitespace */ case INVALID: return 0; /* invalid input, return error */ case EQUALS: /* pad character, end of data */ in = end; continue; default: buf = buf << 6 | c; iter++; // increment the number of iteration /* If the buffer is full, split it into bytes */ if (iter == 4) { if ((len += 3) > *outLen) return 0; /* buffer overflow */ *(out++) = (buf >> 16) & 255; *(out++) = (buf >> 8) & 255; *(out++) = buf & 255; buf = 0; iter = 0; } } } if (iter == 3) { if ((len += 2) > *outLen) return 0; /* buffer overflow */ *(out++) = (buf >> 10) & 255; *(out++) = (buf >> 2) & 255; } else if (iter == 2) {
void midiMainLoop(void) { fprintf (stderr, "midiMainLoop\n"); jack_midi_event_t input_event; int timeout = 10*1000*1000+time_us(); // 10 seconds in microseconds //int exitMainLoop = 0; while (!exitMainLoop) { jack_nframes_t nframes = jack_cycle_wait(jack_client); /* Get input and output buffer pointers. */ void* input_buf = jack_port_get_buffer (jack_midi_input_port, nframes); //void* output_buf = jack_port_get_buffer (jack_midi_output_port, nframes); jack_nframes_t input_event_count = jack_midi_get_event_count(input_buf); if (input_event_count>0) { unsigned int event_index = 0; for (;event_index<input_event_count;event_index++) { if (0==jack_midi_event_get(&input_event, input_buf, event_index)) { if (input_event.size > 0) { printhex("receive:", input_event.buffer,input_event.size); int i = 0; for (; i < input_event.size; i++) { midiReceive(input_event.buffer[i]); } } } } } if (time_us() > timeout) { fprintf(stderr, "timeout\n"); exit(1); } } jack_end(); fprintf (stderr, "midiMainLoop:end\n"); }
avb_stream_entry *srp_add_reservation_entry(avb_srp_info_t *reservation) { int entry = srp_match_reservation_entry_by_id(reservation->stream_id); if (entry >= 0) { const int reservation_size_minus_failure_info = sizeof(avb_srp_info_t)-(sizeof(avb_srp_info_t)-offsetof(avb_srp_info_t, failure_bridge_id)); memcpy(&stream_table[entry].reservation, reservation, reservation_size_minus_failure_info); debug_printf("Added stream:\n ID: %x%x\n DA:", reservation->stream_id[0], reservation->stream_id[1]); for (int i=0; i < 6; i++) { printhex(stream_table[entry].reservation.dest_mac_addr[i]); printchar(':'); } debug_printf("\n max size: %d\n interval: %d\n", stream_table[entry].reservation.tspec_max_frame_size, stream_table[entry].reservation.tspec_max_interval ); stream_table[entry].talker_present = 1; } else { debug_printf("Assert: Out of stream entries\n"); return NULL; } return &stream_table[entry]; }
//printhex function void printhex(int x) { if (x == 0) putchar(0); else { int digit = x % 16; printhex(x/16); if(digit == 10) putchar(97); else if(digit == 11) putchar(98); else if(digit == 12) putchar(99); else if(digit == 13) putchar(100); else if(digit == 14) putchar(101); else if(digit == 15) putchar(102); else putchar(digit + 48); } }
int main(){ string directoryPath = "datasets/email/enron_mail_20110402/maildir/mann-k/inbox/"; BStore* store = new BStore(); int numFiles = 12; string filenumbers[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9" , "10", "267", "207"}; for(int i = 0; i < numFiles; i++){ string filename = directoryPath + filenumbers[i] + "."; size_t size = readFileSize(filename); byte fileBytes[size]; readFile(filename, fileBytes, size); printhex(fileBytes, size, "FILE BYTES"); store->add(filename, fileBytes, size); } double execTime; store->finalize(execTime); delete store; return 0; }
void mmio_window_update( mmio_window_t mmio ) { int i,j, count = 0; GtkCList *page, *all_page; char data[10], bits[40]; all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window), "All" )); for( i=0; i < num_io_rgns; i++ ) { page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window), io_rgn[i]->id )); for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) { if( *io_rgn[i]->ports[j].val != *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){ int sz = io_rgn[i]->ports[j].width; /* Changed */ printhex( data, sz, *io_rgn[i]->ports[j].val ); printbits( bits, sz, *io_rgn[i]->ports[j].val ); gtk_clist_set_text( page, j, 2, data ); gtk_clist_set_text( page, j, 3, bits ); gtk_clist_set_foreground( page, j, &gui_colour_changed ); gtk_clist_set_text( all_page, count, 2, data ); gtk_clist_set_text( all_page, count, 3, bits ); gtk_clist_set_foreground( all_page, count, &gui_colour_changed ); } else { gtk_clist_set_foreground( page, j, &gui_colour_normal ); gtk_clist_set_foreground( all_page, count, &gui_colour_normal ); } count++; } memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, LXDREAM_PAGE_SIZE ); } }
/* perform export command */ static int procexport(const char *upath, uint64_t ts, uint32_t sid){ TCULOG *ulog = tculognew(); if(!tculogopen(ulog, upath, 0)){ printerr("tculogopen"); return 1; } bool err = false; TCULRD *ulrd = tculrdnew(ulog, ts); if(ulrd){ const char *rbuf; int rsiz; uint64_t rts; uint32_t rsid, rmid; while(!err && (rbuf = tculrdread(ulrd, &rsiz, &rts, &rsid, &rmid)) != NULL){ if(rsid == sid || rmid == sid) continue; printf("%llu\t%u:%u\t", (unsigned long long)rts, (unsigned int)rsid, (unsigned int)rmid); if(rsiz >= 2){ printf("%s\t", ttcmdidtostr(((unsigned char *)rbuf)[1])); printhex(rbuf, rsiz); putchar('\n'); } else { printf("[broken entry]\n"); } } tculrddel(ulrd); } else { printerr("tculrdnew"); err = true; } if(!tculogclose(ulog)){ printerr("tculogclose"); err = true; } tculogdel(ulog); return err ? 1 : 0; }
void sysColumnsFunction(int choice) { string fName; int pageSize,pNo,result; switch(choice) { case 1: cout<<"Enter the file name: "; cin>>fName; cout<<"Enter the page size: "; cin>>pageSize; result = createSysColumnFile(fName,pageSize); break; case 3: cout<<"Enter the file name: "; cin>>fName; cout<<"Enter the page size: "; cin>>pageSize; result = insertEntry(fName,pageSize); break; case 4: cout<<"Enter the file name: "; cin>>fName; cout<<"Enter the page size: "; cin>>pageSize; result = deleteEntry(fName,pageSize); break; case 6: cout<<"Enter the file name: "; cin>>fName; cout<<"Enter the page no.: "; cin>>pNo; cout<<"Enter the page size: "; cin>>pageSize; printhex(fName,pNo,pageSize); break; default: cout<<"Unimplemented operation..."<<endl; break; } }
void midiSendLong(unsigned char *buf, unsigned long len) { /*int err = snd_rawmidi_write(handle_out, buf, len); if (err != len) { fprintf(stderr, "could not write %ld byte to output, return: %d\n", len, err); exit(1); }*/ if (jack_midi_output_port == NULL) { fprintf(stderr, "midiSendLong failed: output port closed\n"); exit(1); } void* output_buf = jack_port_get_buffer (jack_midi_output_port, 1); jack_midi_clear_buffer(output_buf); printhex("send:", buf, len); int err = jack_midi_event_write(output_buf, 0, buf, len); if (err != 0) { if (err == ENOBUFS) { // if there's not enough space in buffer for event } fprintf(stderr, "could not write %ld byte to output, return: %d\n", len, err); exit(1); } }
void vPortFree( void *pv ) { unsigned char *puc = ( unsigned char * ) pv; xBlockLink *pxLink; if( pv ) { /* The memory being freed will have an xBlockLink structure immediately before it. */ puc -= heapSTRUCT_SIZE; /* This casting is to keep the compiler from issuing warnings. */ pxLink = ( void * ) puc; vTaskSuspendAll(); { /* Add this block to the list of free blocks. */ prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) ); xFreeBytesRemaining += pxLink->xBlockSize; printhex(" free: xFreeBytesRemaining", xFreeBytesRemaining); } xTaskResumeAll(); } }
int base64encode(const uint8_t* data_buf, size_t dataLength, char* result, size_t resultSize) { const char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const uint8_t *data = (const uint8_t *)data_buf; size_t resultIndex = 0; size_t x; uint32_t n = 0; int padCount = dataLength % 3; uint8_t n0, n1, n2, n3; V17DO printf("base64:enc:"); V17DO printhex(data, dataLength); V17DO printf("\n"); /* increment over the length of the string, three characters at a time */ for (x = 0; x < dataLength; x += 3) { /* these three 8-bit (ASCII) characters become one 24-bit number */ n = (uint32_t)data[x] << 16; if((x+1) < dataLength) n += (uint32_t)data[x+1] << 8; if((x+2) < dataLength) n += data[x+2]; /* this 24-bit number gets separated into four 6-bit numbers */ n0 = (uint8_t)(n >> 18) & 63; n1 = (uint8_t)(n >> 12) & 63; n2 = (uint8_t)(n >> 6) & 63; n3 = (uint8_t)n & 63; /* * if we have one byte available, then its encoding is spread * out over two characters */ if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */ result[resultIndex++] = base64chars[n0]; if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */ result[resultIndex++] = base64chars[n1]; /* * if we have only two bytes available, then their encoding is * spread out over three chars */ if((x+1) < dataLength) { if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */ result[resultIndex++] = base64chars[n2]; } /* * if we have all three bytes available, then their encoding is spread * out over four characters */ if((x+2) < dataLength) { if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */ result[resultIndex++] = base64chars[n3]; } } /* * create and add padding that is required if we did not have a multiple of 3 * number of characters available */ if (padCount > 0) { for (; padCount < 3; padCount++) { if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */ result[resultIndex++] = '='; } } if(resultIndex >= resultSize) return 0; /* indicate failure: buffer too small */ result[resultIndex] = 0; url64encode(result); return 1; /* indicate success */ }
static int processor(uint8_t *f, int fd, size_t l) { uint8_t frag[33]; size_t start, off; ssize_t scan; int rc = EXIT_SUCCESS; int stop = 0; char ch = 0; if (stdin_nobuf()) { return EXIT_FAILURE; } while (1) { if (0xa != ch) { printf("\n> "); } ch = fgetc(stdin); printf("%c", ch); switch (ch) { case '+': if (readnum(&start)) { printf("\nINVALID START\n"); break; } if (readnum(&off)) { printf("\nINVALID LENGTH\n"); break; } printf("%lx\n", off+start); break; case '-': if (readnum(&start)) { printf("\nINVALID START\n"); break; } if (readnum(&off)) { printf("\nINVALID LENGTH\n"); break; } printf("%lx\n", start-off); break; case 'e': if (readnum(&off)) { printf("\nINVALID OFFSET\n"); break; } if (-1 == expand(&f, fd, l, off)) { stop = 1; rc = EXIT_FAILURE; break; } l += off; printf("\nEXTENDED %lu BYTES\n", (long unsigned)off); break; case 'f': if (readnum(&start) || (start >= l)) { printf("\nINVALID START\n"); break; } if (readnum(&off)) { printf("\nINVALID LENGTH\n"); break; } if (-1 == read_fragment(frag, off)) { printf("\nINVALID FRAGMENT\n"); break; } printf("\nFIND FRAG FROM %lx SIZE %lu\n", start, off); find_frag(f+start, l-start, start, frag, off); break; case 'i': if (readnum(&start) || (start >= l)) { printf("\nINVALID START\n"); break; } if (-1 == expand(&f, fd, l, 1)) { stop = 1; rc = EXIT_FAILURE; break; } l++; if (-1 == shift_by(f+start, l-start)) { stop = 1; rc = EXIT_FAILURE; break; } break; case 'l': printf(" %lx\n", l); break; case 0x4: case 'q': printf("\nQUIT\n"); stop++; break; case 'r': if (readnum(&start) || (start >=l)) { printf("\nINVALID START\n"); break; } if (readnum(&off) || ((start+off) > l)) { printf("\nINVALID OFFSET\n"); rc = EXIT_FAILURE; break; } if (0 == off) { off = (l - start); } printhex(f+start, off, start); break; case 's': if (readnum(&start) || (start >= l)) { printf("\nINVALID START\n"); break; } if (readnum(&off)) { printf("\nINVALID LENGTH\n"); break; } if (-1 == read_fragment(frag, off)) { printf("\nINVALID FRAGMENT\n"); break; } printf("\nSCAN FRAG FROM %lx SIZE %lu\n", start, off); while (-1 != (scan = find_frag(f+start, l-start, start, frag, off))) { start += scan + 1; } break; case 'w': if (readnum(&start) || (start >=l)) { printf("\nINVALID START\n"); break; } writehex(f+start, l-start); break; } if (stop) { break; } } return rc; }
int32 runtime·gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, int32 max) { int32 i, n, iter; uintptr pc, lr, tracepc, x; byte *fp, *p; bool waspanic; Stktop *stk; Func *f; pc = (uintptr)pc0; lr = (uintptr)lr0; fp = nil; waspanic = false; // If the PC is goexit, the goroutine hasn't started yet. if(pc == (uintptr)runtime·goexit) { pc = (uintptr)g->entry; lr = (uintptr)runtime·goexit; } // If the PC is zero, it's likely a nil function call. // Start in the caller's frame. if(pc == 0) { pc = lr; lr = 0; } n = 0; stk = (Stktop*)g->stackbase; for(iter = 0; iter < 100 && n < max; iter++) { // iter avoids looping forever // Typically: // pc is the PC of the running function. // sp is the stack pointer at that program counter. // fp is the frame pointer (caller's stack pointer) at that program counter, or nil if unknown. // stk is the stack containing sp. // The caller's program counter is lr, unless lr is zero, in which case it is *(uintptr*)sp. if(pc == (uintptr)runtime·lessstack) { // Hit top of stack segment. Unwind to next segment. pc = (uintptr)stk->gobuf.pc; sp = stk->gobuf.sp; lr = 0; fp = nil; if(pcbuf == nil) runtime·printf("----- stack segment boundary -----\n"); stk = (Stktop*)stk->stackbase; continue; } if(pc <= 0x1000 || (f = runtime·findfunc(pc)) == nil) { // Dangerous, but worthwhile: see if this is a closure by // decoding the instruction stream. // // We check p < p+4 to avoid wrapping and faulting if // we have lost track of where we are. p = (byte*)pc; if((pc&3) == 0 && p < p+4 && runtime·mheap.arena_start < p && p+4 < runtime·mheap.arena_used) { x = *(uintptr*)p; if((x&0xfffff000) == 0xe49df000) { // End of closure: // MOVW.P frame(R13), R15 pc = *(uintptr*)sp; lr = 0; sp += x & 0xfff; fp = nil; continue; } if((x&0xfffff000) == 0xe52de000 && lr == (uintptr)runtime·goexit) { // Beginning of closure. // Closure at top of stack, not yet started. p += 5*4; if((x&0xfff) != 4) { // argument copying p += 7*4; } if((byte*)pc < p && p < p+4 && p+4 < runtime·mheap.arena_used) { pc = *(uintptr*)p; fp = nil; continue; } } } break; } // Found an actual function. if(lr == 0) lr = *(uintptr*)sp; if(fp == nil) { fp = sp; if(pc > f->entry && f->frame >= 0) fp += f->frame; } if(skip > 0) skip--; else if(pcbuf != nil) pcbuf[n++] = pc; else { if(showframe(f)) { // Print during crash. // main(0x1, 0x2, 0x3) // /home/rsc/go/src/runtime/x.go:23 +0xf tracepc = pc; // back up to CALL instruction for funcline. if(n > 0 && pc > f->entry && !waspanic) tracepc -= sizeof(uintptr); runtime·printf("%S(", f->name); for(i = 0; i < f->args; i++) { if(i != 0) runtime·prints(", "); runtime·printhex(((uintptr*)fp)[1+i]); if(i >= 4) { runtime·prints(", ..."); break; } } runtime·prints(")\n"); runtime·printf("\t%S:%d", f->src, runtime·funcline(f, tracepc)); if(pc > f->entry) runtime·printf(" +%p", (uintptr)(pc - f->entry)); runtime·printf("\n"); } n++; } waspanic = f->entry == (uintptr)runtime·sigpanic; if(pcbuf == nil && f->entry == (uintptr)runtime·newstack && g == m->g0) { runtime·printf("----- newstack called from goroutine %d -----\n", m->curg->goid); pc = (uintptr)m->morepc; sp = (byte*)m->moreargp - sizeof(void*); lr = (uintptr)m->morebuf.pc; fp = m->morebuf.sp; g = m->curg; stk = (Stktop*)g->stackbase; continue; } if(pcbuf == nil && f->entry == (uintptr)runtime·lessstack && g == m->g0) { runtime·printf("----- lessstack called from goroutine %d -----\n", m->curg->goid); g = m->curg; stk = (Stktop*)g->stackbase; sp = stk->gobuf.sp; pc = (uintptr)stk->gobuf.pc; fp = nil; lr = 0; continue; } // Unwind to next frame. pc = lr; lr = 0; sp = fp; fp = nil; // If this was div or divu or mod or modu, the caller had // an extra 8 bytes on its stack. Adjust sp. if(f->entry == (uintptr)_div || f->entry == (uintptr)_divu || f->entry == (uintptr)_mod || f->entry == (uintptr)_modu) sp += 8; // If this was deferproc or newproc, the caller had an extra 12. if(f->entry == (uintptr)runtime·deferproc || f->entry == (uintptr)runtime·newproc) sp += 12; } if(pcbuf == nil && (pc = g->gopc) != 0 && (f = runtime·findfunc(pc)) != nil && g->goid != 1) { runtime·printf("created by %S\n", f->name); tracepc = pc; // back up to CALL instruction for funcline. if(n > 0 && pc > f->entry) tracepc -= sizeof(uintptr); runtime·printf("\t%S:%d", f->src, runtime·funcline(f, tracepc)); if(pc > f->entry) runtime·printf(" +%p", (uintptr)(pc - f->entry)); runtime·printf("\n"); } return n; }
void *pvPortMalloc( size_t xWantedSize ) { xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink; static portBASE_TYPE xHeapHasBeenInitialised = pdFALSE; void *pvReturn = NULL; vTaskSuspendAll(); { /* If this is the first call to malloc then the heap will require initialisation to setup the list of free blocks. */ if( xHeapHasBeenInitialised == pdFALSE ) { printk("initializing heap\r\n"); printhex(" init: xFreeBytesRemaining", xFreeBytesRemaining); prvHeapInit(); xHeapHasBeenInitialised = pdTRUE; printhex(" init: xFreeBytesRemaining", xFreeBytesRemaining); } /* The wanted size is increased so it can contain a xBlockLink structure in addition to the requested amount of bytes. */ if( xWantedSize > 0 ) { xWantedSize += heapSTRUCT_SIZE; /* Ensure that blocks are always aligned to the required number of bytes. */ if( xWantedSize & portBYTE_ALIGNMENT_MASK ) { /* Byte alignment required. */ xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); } } if( ( xWantedSize > 0 ) && ( xWantedSize < configTOTAL_HEAP_SIZE ) ) { /* Blocks are stored in byte order - traverse the list from the start (smallest) block until one of adequate size is found. */ pxPreviousBlock = &xStart; pxBlock = xStart.pxNextFreeBlock; while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock ) ) { pxPreviousBlock = pxBlock; pxBlock = pxBlock->pxNextFreeBlock; } /* If we found the end marker then a block of adequate size was not found. */ if( pxBlock != &xEnd ) { /* Return the memory space - jumping over the xBlockLink structure at its start. */ pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE ); /* This block is being returned for use so must be taken our of the list of free blocks. */ pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock; /* If the block is larger than required it can be split into two. */ if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE ) { /* This block is to be split into two. Create a new block following the number of bytes requested. The void cast is used to prevent byte alignment warnings from the compiler. */ pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize ); /* Calculate the sizes of two blocks split from the single block. */ pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize; pxBlock->xBlockSize = xWantedSize; /* Insert the new block into the list of free blocks. */ prvInsertBlockIntoFreeList( ( pxNewBlockLink ) ); } xFreeBytesRemaining -= pxBlock->xBlockSize; printhex("malloc: xFreeBytesRemaining", xFreeBytesRemaining); } } } xTaskResumeAll(); #if( configUSE_MALLOC_FAILED_HOOK == 1 ) { if( pvReturn == NULL ) { extern void vApplicationMallocFailedHook( void ); vApplicationMallocFailedHook(); } } #else if (pvReturn == NULL) { printk("malloc failed: "); printhex("xWantedSize", xWantedSize); } #endif return pvReturn; }
void dataPageFunction(int choice) { string fname,data,updatedData; int pageNo,result; switch(choice) { case 1: cout<<"\n Creating data page....."; cout<<"\n Enter the name of the data file to be created: "; cin>>fname; createFileName(fname); break; case 2: cout<<"\n Opening a data page....."; cout<<"\n Enter the name of the data file to be opened: "; cin>>fname; openFileName(fname); break; case 3: cout<<"\n Displaying the properties of the data page...."; cout<<"\n Enter the name of the data file: "; cin>>fname; cout<<"\n Enter the page, for which details are to be displayed: "; cin>>pageNo; dispPageProperties(fname,pageNo); break; case 4: cout<<"\n Displaying the page as hex....."; cout<<"\n Enter the name of the data file: "; cin>>fname; cout<<"\n Enter the page, for which hex dump has to be displayed: "; cin>>pageNo; printhex(fname,pageNo); break; case 5: cout<<"\n Inserting data into a data page....."; cout<<"\n Enter the name of the data file: "; cin>>fname; cout<<"\n Enter the page no.: "; cin>>pageNo; cout<<"\n Enter the data to be inserted: "; cin>>data; result = insertData(fname,pageNo,data); cout<<"\n No. of rows modified: "<<result; break; case 6: cout<<"\n Deleting data from a data page...."; cout<<"\n Enter the name of the data file: "; cin>>fname; cout<<"\n Enter the data to be deleted: "; cin>>data; result = deleteData(fname,data); cout<<"\n No. of rows modified: "<<result; break; case 7: cout<<"\n Listing all the data pages....."; cout<<"\n Enter the name of the data file: "; cin>>fname; dispPageProperties(fname); break; case 8: cout<<"\n Modifying data in a data page....."; cout<<"\n Enter the name of the data file: "; cin>>fname; cout<<"\n Enter the data to be modified: "; cin>>data; cout<<"\n Enter the data to be updated: "; cin>>updatedData; result = updateData(fname,data,updatedData); cout<<"\n No. of rows modified: "<<result; break; case 9: cout<<"\n Printing all the slots information....."; cout<<"\n Enter the name of the data file: "; cin>>fname; printAllSlotsInformation(fname); break; case 10: cout<<"\n Exiting....."; break; } }