static void heap_chunk_callback(const void *chunkptr, size_t chunklen, const void *userptr, size_t userlen, void *arg) { HeapDumpContext *ctx = (HeapDumpContext *)arg; bool chunkFree = (userptr == NULL); if (chunkFree != ctx->chunkFree || ((char *)ctx->chunkStart + ctx->chunkLen) != chunkptr) { /* The new chunk is of a different type or isn't * contiguous with the current chunk. Dump the * old one and start a new one. */ if (ctx->chunkStart != NULL) { /* It's not the first chunk. */ dump_context(ctx); } ctx->chunkStart = (void *)chunkptr; ctx->chunkLen = chunklen; ctx->chunkFree = chunkFree; } else { /* Extend the current chunk. */ ctx->chunkLen += chunklen; } }
int f3(void) { uwx_self_init_context(uenv); printf("In f3():\n"); dump_context((uint64_t *)uenv); return f4(); }
int f4(void) { int status; int foo[10]; f5(foo); uwx_self_init_context(uenv); printf("In f4():\n"); dump_context((uint64_t *)uenv); for (;;) { status = uwx_step(uenv); printf("uwx_step returned %d\n", status); if (status != UWX_OK) break; printf("After step:\n"); dump_context((uint64_t *)uenv); } return 0; }
int dos_free_paragraphs(void) { union REGS rin; union REGS rout; rin.x.ax = 0x4800; rin.x.bx = 0xffff; int86(0x21, &rin, &rout); ok(rout.x.cflag, "dos_free_paragraphs failed!\n"); if (!rout.x.cflag) { trace(" context in: "); dump_context(&rin); trace(" context out: "); dump_context(&rout); return 0; } return rout.x.bx; }
static void segfault(int code, unsigned long error, void *addr) { kprintf("Segmentation fault: %s mode %s at 0x%p%s\n", (error & PGF_USER) ? "user" : "kernel", (error & PGF_WRITE) ? "write" : "read", addr, (error & PGF_PERM) ? "" : " (page not present)"); dump_context(current->esp); if (is_kernel_context(current->esp)) panic("Segfault in kernel"); __kill(current, SIGSEGV, code); }
int dos_alloc(WORD paras) { union REGS rin; union REGS rout; rin.x.ax = 0x4800; rin.x.bx = paras; int86(0x21, &rin, &rout); #ifdef DEBUG dump_context(&rout); #endif ok(!rout.x.cflag, "dos_alloc failed!\n"); if (rout.x.cflag) { trace(" context in: "); dump_context(&rin); trace(" context out: "); dump_context(&rout); return 0; } return 1; }
int main(int argc, char **argv) { int status; unsigned int *wp; uenv = uwx_init(); printf("uwx_init returned %08x\n", uenv); cbinfo = uwx_self_init_info(uenv); status = uwx_register_callbacks( uenv, (intptr_t)cbinfo, uwx_self_copyin, uwx_self_lookupip); printf("uwx_register_callbacks returned %d\n", status); uwx_self_init_context(uenv); printf("In main():\n"); dump_context((uint64_t *)uenv); (void) f1(); uwx_free(uenv); return 0; }
static int dumpstats(http_connection_t *hc, const char *remain, void *opaque, http_cmd_t method) { int i; htsbuf_queue_t out; htsbuf_queue_init(&out, 0); np_context_t **vec = np_get_all_contexts(); for(i = 0; vec[i] != NULL; i++) dump_context(&out, vec[i]); np_context_vec_free(vec); htsbuf_qprintf(&out, "\n"); return http_send_reply(hc, 0, "text/plain; charset=utf-8", NULL, NULL, 0, &out); }
/* Dumps free and used ranges, as text, to the named file. */ void dvmDumpHeapToFile(const char *fileName) { HeapDumpContext ctx; FILE *fp; fp = fopen(fileName, "w+"); if (fp == NULL) { LOGE("Can't open %s for writing: %s\n", fileName, strerror(errno)); return; } LOGW("Dumping heap to %s...\n", fileName); fprintf(fp, "==== Dalvik heap dump ====\n"); memset(&ctx, 0, sizeof(ctx)); ctx.fp = fp; dvmHeapSourceWalk(heap_chunk_callback, (void *)&ctx); dump_context(&ctx); fprintf(fp, "==== end heap dump ====\n"); LOGW("Dumped heap to %s.\n", fileName); fclose(fp); }
/** * Start relay server * Return: * 0 success * -1 failed */ int rs_start(rscntxt_t *cntxt) { if (NULL == cntxt) { LogE("NULL Pointer"); return -1; } dump_context(cntxt); cntxt->fd_srvr = prepare_tcp_server(cntxt->port, cntxt->backlog); if (cntxt->fd_srvr < 0) { LogE("Failed prepare tcp server"); return -1; } #define EPOLL_MAX_SIZE 32 cntxt->fd_epoll = epoll_create(EPOLL_MAX_SIZE); if (cntxt->fd_epoll < 0) { LogE("Failed epoll_create()"); return -1; } struct epoll_event ev; memset(&ev, 0, sizeof(ev)); ev.data.fd = cntxt->fd_srvr; ev.events = EPOLLIN; if (epoll_ctl(cntxt->fd_epoll, EPOLL_CTL_ADD, cntxt->fd_srvr, &ev) < 0) { LogE("Failed add fd_srvr to epoll:%s", strerror(errno)); return -1; } return 0; }
/* Check */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <parse_tree.h> #include <aurochs.h> static unsigned char *load_file(char *name, size_t *size)/*{{{*/ { size_t m; struct stat st; unsigned char *data; FILE *f; unsigned char *retval; retval = 0; if(!stat(name, &st)) { m = st.st_size; *size = m; data = malloc(m); if(data) { f = fopen(name, "rb"); if(f) { if(1 == fread(data, m, 1, f)) { retval = data; data = 0; } fclose(f); } if(data) free(data); } } return retval; }/*}}}*/ int main(int argc, char **argv) { unsigned char *peg_data; char *peg_fn; size_t peg_data_size; nog_program_t *pg; packer_t pk; staloc_t *st; int rc; rc = 0; argv ++; argc --; if(!argc) { printf("No PEG data\n"); exit(EXIT_FAILURE); } peg_fn = *(argv ++); argc --; printf("Loading peg_data from file %s\n", peg_fn); peg_data = load_file(peg_fn, &peg_data_size); if(!peg_data) { printf("Can't load peg data.\n"); exit(EXIT_FAILURE); } /* Create a stack allocator */ st = staloc_create(&alloc_stdlib); if(!st) { printf("Can't create stack allocator.\n"); exit(EXIT_FAILURE); } if(pack_init_from_string(&pk, peg_data, peg_data_size)) { printf("peg_data[0] = %d\n", peg_data[0]); pg = nog_unpack_program(&st->s_alloc, &pk); printf("Unpacked to %p\n", pg); if(pg) { peg_context_t *cx; size_t m; int i; int error_pos; char *fn; unsigned char *buf; int rc; rc = 0; for(i = 0; i < argc; i ++) { fn = argv[i]; peg_builder_t pb; staloc_t *s2; s2 = staloc_create(&alloc_stdlib); buf = load_file(fn, &m); printf("Loaded file %s to %p\n", fn, buf); if(buf) { ptree_init(&pb, &s2->s_alloc); cx = peg_create_context(&alloc_stdlib, pg, &pb, &s2->s_alloc, buf, m); printf("Created context %p\n", cx); if(cx) { tree tr; if(nog_execute(cx, pg, &tr)) { printf("Parsed as %p.\n", tr); ptree_dump_tree(cx->cx_builder_info, stdout, buf, tr, 0); } else { printf("Doesn't parse.\n"); error_pos = nog_error_position(cx, pg); printf("Error at %d\n", error_pos); } peg_delete_context(cx); } } staloc_dispose(s2); free(buf); } #if 0 i = foobar_parse_start(cx, - m); if(getenv("DUMP_CONTEXT")) dump_context(stdout, cx); if(!i) { printf("%05d RESULT OK\n", count); tree *tr0; if(getenv("DUMP_TREE")) { tr0 = create_node("Root"); (void) foobar_build_start(cx, &tr0->t_element.t_node, -m); reverse_tree(tr0); dump_tree(stdout, cx->cx_input, tr0, 0); } } else { error_pos = error_position(cx); if(i > 0) { printf("%05d RESULT NOPREFIX; ERROR AT %d\n", count, error_pos); rc = 1; } else { printf("%05d RESULT PREFIX %d; ERROR AT %d\n", count, m + i, error_pos); } } fflush(stdout); delete_context(cx); fclose(f); } #endif /* nog_free_program(&st->s_alloc, pg); */ staloc_dispose(st); } }