void listenthread(void *arg) { Conn *c; Ioproc *io; io = ioproc(); USED(arg); threadsetname("listen %s", adir); for(;;){ c = emalloc(sizeof(Conn)); c->fd = iolisten(io, adir, c->dir); if(c->fd < 0){ if(verbose) fprint(2, "%T listen: %r\n"); close(afd); free(c); return; } c->inc = chancreate(sizeof(void*), 0); c->internal = chancreate(sizeof(void*), 0); c->inq = qalloc(); c->outq = qalloc(); c->outqdead = chancreate(sizeof(void*), 0); if(verbose) fprint(2, "%T incoming call on %s\n", c->dir); threadcreate(connthread, c, STACK); } }
//---------------------------------------------------------------------- void glb_min(Float * float_p) { int NP[4] = {GJP.Xnodes(), GJP.Ynodes(), GJP.Znodes(), GJP.Tnodes()}; if (transmit_buf == NULL) transmit_buf = (Float *)qalloc(QFAST|QNONCACHE,sizeof(Float)); if (receive_buf == NULL) receive_buf = (Float *)qalloc(QFAST|QNONCACHE,sizeof(Float)); if (gsum_buf == NULL) gsum_buf = (Float *)qalloc(QFAST|QNONCACHE,sizeof(Float)); *gsum_buf = *float_p; for(int i = 0; i < 4; ++i) { *transmit_buf = *gsum_buf; for (int itmp = 1; itmp < NP[i]; itmp++) { SCUDirArg send(transmit_buf, dir[2*i], SCU_SEND, sizeof(Float)); SCUDirArg rcv(receive_buf, dir[2*i+1], SCU_REC, sizeof(Float)); send.StartTrans(); rcv.StartTrans(); send.TransComplete(); rcv.TransComplete(); *gsum_buf = min(*gsum_buf, *receive_buf) ; *transmit_buf = *receive_buf; } } *float_p = *gsum_buf; }
/*************** FUNCTIONS ***************/ struct RP_class * alloc_class(ea_t adr, size_t namelen, struct RP_class *parent) { struct RP_class *res = (struct RP_class *)qalloc(sizeof(struct RP_class)); res->parent = parent; res->CRuntime = adr; res->vtbl = 0; res->total = 0; res->namelen = namelen; res->children = (struct RP_class **)qalloc(sizeof(struct RP_class *) * (res->alloced = RP_INITIAL)); total_classes++; return res; }
void Buffer::init(uint32_t size) { bptr = (unsigned char *)qalloc(size); sz = bptr ? size : 0; rptr = 0; wptr = 0; error = bptr == NULL; }
static void setter(char *name, ea_t rt, ea_t vtbl, bool latch) { if ( !name || !*name ) return; int len = strlen(name); char *name2 = (char *)qalloc(len + 6); // fill CRunTime record name2[0] = 'R'; name2[1] = 'T'; name2[2] = '_'; strcpy(name2 + 3, name); set_name(rt, name2, SN_AUTO); make_RTStruct(rt, len); if ( !latch ) { qfree(name2); return; } if ( vtbl ) { // vtbl processing name2[0] = 'v'; name2[1] = 't'; name2[2] = 'b'; name2[3] = 'l'; name2[4] = '_'; strcpy(name2 + 5, name); set_name(vtbl, name2, SN_AUTO); } qfree(name2); }
//--------------------------------------------------------------------------- static bool extractData(uint32 off) { IMAGE_RESOURCE_DATA_ENTRY rd; if ( off + sizeof(rd) > ResTop ) return false; if ( !get_many_bytes(ResBase + off, &rd, sizeof(rd)) ) return false; if ( rd.OffsetToData >= ImgSize || rd.Size > ImgSize || rd.OffsetToData + rd.Size > ImgSize ) return false; void *data = qalloc(rd.Size); if ( data == NULL ) { msg("Not enough memory for resources\n"); return false; } bool res = false; if ( get_many_bytes(curmod.startEA + rd.OffsetToData, data, rd.Size) ) { store(data, rd.Size); res = true; } qfree(data); return res; }
// recursive processing of message mapz void process_message_map(ea_t ptr, char *class_name = NULL) { if ( class_name && *class_name ) { int len = strlen(class_name); char *mm_name = (char *)qalloc(len + 8); strcpy(mm_name, class_name); strcat(mm_name, "_MsgMap"); set_name(ptr, mm_name, SN_NOWARN | SN_AUTO); qfree(mm_name); } do_unknown_range(ptr, 8, true); ea_t prev = get_long(ptr); ea_t my = get_long(ptr + 4 ); if ( get_long(my) ) { do_dref(ptr + 4, my); process_AfxMessages(my); } else { doDwrd(ptr+4,4); } if ( prev ) { do_dref(ptr, prev); if ( !is_mfc_dlled ) process_message_map(prev); } else { doDwrd(ptr,4); } }
//firstly sear //ea_t loc - address of import //size - len of array //returns list of xrefs to, and size of list array ea_t* find_function_xref(ea_t addr, int *size) { //*size = 0; int count = 0, i = 0; *size = 0; xrefblk_t xb; char funcname_incode[MAXSTR]; ea_t *list; if(addr == BADADDR)return NULL; for(bool ok = xb.first_to(addr, XREF_ALL); ok; ok = xb.next_to()) { count++; } list = (ea_t*)qalloc(sizeof(ea_t) * count); if(!list){ msg("qalloc failed: bytes %a \n", count); return NULL; } for (bool ok = xb.first_to(addr, XREF_ALL); ok; ok = xb.next_to()) { //*list++ = xb.from; list[i] = xb.from; i++; } *size = count; return list; }
// TODO: need to optimize qstring_t qstring_catvprintf(qstring_t string, const char *fmt, ...) { va_list ap; va_list cpy; char *buf, *t; size_t buflen; buflen = 16; va_start(ap,fmt); while(1) { buf = qalloc(buflen); if (buf == NULL) { return NULL; } buf[buflen - 2] = '\0'; va_copy(cpy, ap); vsnprintf(buf, buflen, fmt, cpy); if (buf[buflen - 2] != '\0') { qfree(buf); buflen *= 2; continue; } break; } t = qstring_append(string, buf); qfree(buf); va_end(ap); return t; }
//---------------------------------------------------------------------- // // store trainer to netnode // static bool save_trainer_as_blob( linput_t *li ) { netnode node; uchar *buffer; if( !INES_MASK_TRAINER( hdr.rom_control_byte_0 ) ) return false; buffer = (uchar *)qalloc( TRAINER_SIZE ); if( buffer == 0 ) return false; qlseek( li, INES_HDR_SIZE ); qlread( li, buffer, TRAINER_SIZE ); if( !node.create( "$ Trainer" ) ) { qfree( buffer ); return false; } if( !node.setblob( buffer, TRAINER_SIZE, 0, 'I' ) ) msg("Could not store trainer to netnode!\n"); qfree( buffer ); return true; }
static qltimer_t* new_timer(qdict_t *args, const char *mod, const char *func) { qltimer_t *timer; timer = (qltimer_t*)qalloc(sizeof(qltimer_t)); if (timer == NULL) { return NULL; } timer->args = args; timer->mod = qstring_new(mod); timer->func = qstring_new(func); if (timer->mod == NULL || timer->func == NULL) { goto error; } return timer; error: if (timer->mod) { qstring_destroy(timer->mod); } if (timer->func) { qstring_destroy(timer->func); } qfree(timer); return NULL; }
//ea_t loc - address of import //size - len of array //returns list of xrefs to, and size of list array ea_t* find_import_xref(ea_t loc, int *size) { //*size = 0; int count = 0, i = 0; xrefblk_t xb; ea_t *list; for(bool ok = xb.first_to(loc, XREF_ALL); ok; ok = xb.next_to()) { //msg("Caller to ExAllocatePoolWithTag %a \n", xb.from); count++; } // msg("find_import_xref %d \n", count); list = (ea_t*)qalloc(sizeof(ea_t) * count); if(!list){ msg("qalloc failed: bytes %a \n", count); return NULL; } for (bool ok = xb.first_to(loc, XREF_ALL); ok; ok = xb.next_to()) { //*list++ = xb.from; list[i] = xb.from; i++; } // msg("find_import_xref i = %d \n", i); *size = count; return list; }
//-------------------------------------------------------------------------- static void load_dl_header(linput_t *li) { if ( first_text_subspace_fpos == -1 ) return; qlseek(li, first_text_subspace_fpos); dl_header dl; lread(li, &dl, sizeof(dl)); dl.swap(); switch ( dl.hdr_version ) { case OLD_HDR_VERSION: break; case HDR_VERSION : break; default: msg("Unknown DL header version, skipping...\n"); } if ( dl.string_table_size != 0 ) { dl_ssize = dl.string_table_size; dl_strings = (char *)qalloc(dl_ssize); if ( dl_strings == NULL ) nomem("dl_strings"); qlseek(li, first_text_subspace_fpos+dl.string_table_loc); lread(li, dl_strings, dl_ssize); } if ( dl.dreloc_count ) complain_fixup(); load_imports(li, dl); load_exports(li, dl); qfree(dl_strings); dl_strings = NULL; }
//---------------------------------------------------------------------- // // store CHR ROM pages to netnode // static bool save_chr_rom_pages_as_blobs( linput_t *li, uchar count ) { netnode node; char chr_node_name[MAXSTR]; uchar *buffer = (uchar *)qalloc( CHR_PAGE_SIZE ); if( buffer == 0 ) return false; qlseek( li, INES_HDR_SIZE + (INES_MASK_TRAINER(hdr.rom_control_byte_0) ? TRAINER_SIZE : 0) + PRG_PAGE_SIZE * hdr.prg_page_count_16k ); for(int i=0; i<count; i++) { qlread( li, buffer, CHR_PAGE_SIZE ); qsnprintf( chr_node_name, sizeof(chr_node_name), "$ CHR-ROM page %d", i ); if( !node.create( chr_node_name ) ) { qfree( buffer ); return false; } if( !node.setblob( buffer, CHR_PAGE_SIZE, 0, 'I' ) ) msg("Could not store CHR-ROM pages to netnode!\n"); } qfree( buffer ); return true; }
static int copy_to_remote(const char *lname, const char *rname) { int code = 0; int fn = s_open_file(rname, NULL, false); if ( fn != -1 ) { linput_t *li = open_linput(lname, false); if ( li != NULL ) { size_t size = qlsize(li); if ( size > 0 ) { char *buf = (char *)qalloc(size); qlread(li, buf, size); if ( s_write_file(fn, 0, buf, size) != ssize_t(size) ) code = qerrcode(); } close_linput(li); } else { code = qerrcode(); } s_close_file(fn); #if DEBUGGER_ID == DEBUGGER_ID_X86_IA32_LINUX_USER // chmod +x s_ioctl(0, rname, strlen(rname)+1, NULL, 0); #endif } else { code = qerrcode(); } return code; }
//---------------------------------------------------------------------- // // replace invalid characters, add required ones for // multiline comments // char *validate_comment(char *cmt) { size_t bufsize; char *buf = NULL; size_t j = 0; bufsize = get_newline_count( cmt )+1; if( bufsize == 0 ) return NULL; bufsize += strlen(cmt); buf = (char *)qalloc( bufsize ); for(size_t i=0; i<=strlen(cmt); i++) { switch(cmt[i]) { default: buf[j] = cmt[i]; break; case '#': // conflicting with FCEUXD SP syntax buf[j]='*'; // convert to '*' break; case 0xA: buf[j] = cmt[i]; // multiline comment buf[++j] = '\\'; } j++; } //buf[j] = 0; return buf; }
void StrucCmp::add_all_members(void) throw() { if(m_struc_id != BADNODE) { struc_t *sptr = get_struc(m_struc_id); ssize_t const struc_len = get_struc_name(m_struc_id, NULL, 0); for(size_t idx = 0; idx < sptr->memqty; ++idx) { member_t *mptr = &(sptr->members[idx]); // get_member_name crashes when given a NULL pointer... // we need to get the "struct.field" name and // substract the "struct." part // len is without the '\0' character ssize_t len = get_member_fullname(mptr->id, NULL, 0); if(len != -1) { len -= struc_len; char *buf = static_cast<char *>(qalloc(len)); if(buf != NULL) { get_member_name(mptr->id, buf, len); m_members[buf] = m_is_union ? 0 : mptr->soff; } } } } }
bool do_choose_perms(Buffer &b) { #if DEBUG //msg(PLUGIN_NAME": in do_choose_perms"); #endif Options mask; projectBuffer = &b; tempOpts.pub = projectBuffer->readLong(); tempOpts.sub = projectBuffer->readLong(); mask.pub = projectBuffer->readLong(); mask.sub = projectBuffer->readLong(); Options current = tempOpts; #if DEBUG msg(PLUGIN_NAME": P %x S %x \n", (unsigned int)tempOpts.pub, (unsigned int)tempOpts.sub); #endif int numOptions = projectBuffer->readInt(); numOptionsGlobal = numOptions; optLabels = (char**)qalloc(numOptions * sizeof(char*)); for (int i = 0; i < numOptions; i++) { optLabels[i] = projectBuffer->readUTF8(); } showOptionsDlg(mainWindow, optLabels, numOptionsGlobal, &tempOpts, &tempOpts, &mask); for (int i = 0; i < numOptionsGlobal; i++) { qfree(optLabels[i]); } qfree(optLabels); optLabels = NULL; return memcmp(¤t, &tempOpts, sizeof(Options)) != 0; }
char *DieHolder::get_type_comment(void) { char *comment = NULL; uint32 ordinal = 0; if(get_type_ordinal(&ordinal)) { type_t const *type = NULL; p_list const *fields = NULL; bool const found = get_numbered_type(idati, ordinal, &type, &fields); if(found) { // dynamic type string allocation does not work (returns T_SHORTSTR) // so allocate a huge buffer on the stack... char buf[MAXSTR]; int const ret = print_type_to_one_line(buf, sizeof(buf), idati, type, get_name(), NULL, fields, NULL); if(ret >= 0); { size_t len = strlen(buf); comment = static_cast<char *>(qalloc(len + 1)); if(comment != NULL) { memcpy(comment, buf, len + 1); } } } } return comment; }
clist_t * clist_init_from_refs(hpsig_t * hsig, frefs_t * refs) { clist_t * cl; fref_t * fl; psig_t * sig; cl = (clist_t *)qalloc(sizeof(*cl)); if (!cl) return NULL; cl->num = 0; cl->nmatch = 0; cl->sigs = NULL; cl->pos = NULL; cl->msigs = NULL; if (!refs) return cl; fl = refs->list; while(fl) { sig = hash_find_ea(hsig, fl->ea); if (sig && sig_get_matched_type(sig) == DIFF_UNMATCHED) clist_insert(cl, sig); fl = fl->next; } cl->pos = cl->sigs; return cl; }
void mainproc(void *v) { int n, nn; Fcall f; USED(v); atnotify(ignorepipe, 1); fmtinstall('D', dirfmt); fmtinstall('M', dirmodefmt); fmtinstall('F', fcallfmt); fmtinstall('H', encodefmt); outq = qalloc(); inq = qalloc(); if(!versioned){ f.type = Tversion; f.version = "9P2000"; f.msize = msize; f.tag = NOTAG; n = convS2M(&f, vbuf, sizeof vbuf); if(n <= BIT16SZ) sysfatal("convS2M conversion error"); if(verbose > 1) fprint(2, "%T * <- %F\n", &f); nn = write(1, vbuf, n); if(n != nn) sysfatal("error writing Tversion: %r\n"); n = read9pmsg(0, vbuf, sizeof vbuf); if(n < 0) sysfatal("read9pmsg failure"); if(convM2S(vbuf, n, &f) != n) sysfatal("convM2S failure"); if(f.msize < msize) msize = f.msize; if(verbose > 1) fprint(2, "%T * -> %F\n", &f); } threadcreate(inputthread, nil, STACK); threadcreate(outputthread, nil, STACK); /* if(rootfid) */ /* dorootstat(); */ threadcreate(listenthread, nil, STACK); threadexits(0); }
char* construct_output_filename(char *prefix) { //char result[MAXSTR]; char *result = (char*)qalloc(MAXSTR); get_root_filename(result, MAXSTR); qstrncat(result, prefix, MAXSTR); return result; }
void read_fat(DOS_FS *fs) { int eff_size; unsigned long i; void *first,*second,*use; int first_ok,second_ok; eff_size = ((fs->clusters+2)*fs->fat_bits+7)/8; first = alloc(eff_size); second = alloc(eff_size); fs_read(fs->fat_start,eff_size,first); fs_read(fs->fat_start+fs->fat_size,eff_size,second); use = first; if (memcmp(first,second,eff_size) != 0) { FAT_ENTRY first_media, second_media; get_fat(&first_media,first,0,fs); get_fat(&second_media,second,0,fs); first_ok = (first_media.value & FAT_EXTD(fs)) == FAT_EXTD(fs); second_ok = (second_media.value & FAT_EXTD(fs)) == FAT_EXTD(fs); if (first_ok && !second_ok) { printf("FATs differ - using first FAT.\n"); fs_write(fs->fat_start+fs->fat_size,eff_size,use = first); } if (!first_ok && second_ok) { printf("FATs differ - using second FAT.\n"); fs_write(fs->fat_start,eff_size,use = second); } if (first_ok && second_ok) { if (interactive) { printf("FATs differ but appear to be intact. Use which FAT ?\n" "1) Use first FAT\n2) Use second FAT\n"); if (get_key("12","?") == '1') fs_write(fs->fat_start+fs->fat_size,eff_size,use = first); else fs_write(fs->fat_start,eff_size,use = second); } else { printf("FATs differ but appear to be intact. Using first " "FAT.\n"); fs_write(fs->fat_start+fs->fat_size,eff_size,use = first); } } if (!first_ok && !second_ok) { printf("Both FATs appear to be corrupt. Giving up.\n"); exit(1); } } fs->fat = qalloc(&mem_queue,sizeof(FAT_ENTRY)*(fs->clusters+2)); for (i = 2; i < fs->clusters+2; i++) get_fat(&fs->fat[i],use,i,fs); for (i = 2; i < fs->clusters+2; i++) if (fs->fat[i].value >= fs->clusters+2 && (fs->fat[i].value < FAT_MIN_BAD(fs))) { printf("Cluster %ld out of range (%ld > %ld). Setting to EOF.\n", i-2,fs->fat[i].value,fs->clusters+2-1); set_fat(fs,i,-1); } free(first); free(second); }
CPS_START_NAMESPACE static void* v_alloc(char *s, size_t bytes){ #if TARGET==QCDOC void *ptr = qalloc(QFAST,bytes); if(ptr ==NULL){ ptr = qalloc(QCOMMS,bytes); } #else void *ptr = smalloc(bytes); #endif // printf("%s:%p\n",s,ptr); if(ptr ==NULL){ printf(" v_alloc of %s failed\n",s);exit(34); } return ptr; }
CPS_START_NAMESPACE void* fmalloc(size_t request, const char *vname, const char *fname, const char *cname){ void *p = qalloc(QFAST,request); if (!p) return smalloc(request, cname, fname, vname); VRB.Smalloc(cname, fname, vname, p, request); return p; }
/*********************************************************************** * scf_properties_rhf * * wrapper for the 'scf_properties' function. * transforms density matrix into [equal] alpha and beta components. **********************************************************************/ void scf_properties_rhf(struct cart_mol *molecule, double *P, int M) { double *Pa, *Pb; int nbytes = M * M * sizeof(double); int i; Pa = (double *) qalloc(nbytes); Pb = (double *) qalloc(nbytes); // RHF: Pa = Pb = P/2 for (i = 0; i < M * M; i++) { Pa[i] = P[i] * 0.5; Pb[i] = P[i] * 0.5; } scf_properties(molecule, Pa, Pb, M); qfree(Pa, nbytes); qfree(Pb, nbytes); }
int qlog_thread_new(qmem_pool_t *pool, int thread_num) { int i; int result, fd; g_log_thread = qalloc(pool, sizeof(qlog_thread_t)); if (g_log_thread == NULL) { return -1; } if (pthread_key_create(&g_thread_log_key, log_key_destroy) < 0) { return -1; } g_log_thread->engine = qengine_new(pool); if (g_log_thread->engine == NULL) { qfree(pool, g_log_thread, sizeof(qlog_thread_t)); g_log_thread = NULL; return -1; } g_log_thread->thread_num = thread_num; g_log_thread->signals = qalloc(pool, thread_num * sizeof(qsignal_t*)); if (g_log_thread->signals == NULL) { qengine_destroy(g_log_thread->engine); qfree(pool, g_log_thread, sizeof(qlog_thread_t)); g_log_thread = NULL; return -1; } for (i = 0; i < thread_num; ++i) { g_log_thread->signals[i] = qsignal_new(pool); fd = qsignal_get_fd(g_log_thread->signals[i]); qengine_add_event(g_log_thread->engine, fd, QEVENT_READ, thread_log_box, g_log_thread->signals[i]); } g_log_thread->started = 0; result = pthread_create(&g_log_thread->id, NULL, main_loop, g_log_thread); qassert(result == 0); /* ugly, but works */ while (g_log_thread->started == 0) { usleep(100); } return 0; }
void *blas_memory_alloc(int numproc){ if (sa == NULL){ #if 1 sa = (void *)qalloc(QFAST, BUFFER_SIZE); #else sa = (void *)malloc(BUFFER_SIZE); #endif sb = (void *)&static_buffer[0]; } return sa; }
inline char *__rc_rstralloc(region r, size_t size) { void *mem, *dummy; record_alloc(size); qalloc(r, &r->normal, &dummy, 0, 1, &mem, size, RALIGNMENT, 0); // fprintf(stderr, "## __rc_rstralloc: r=%p, mem=%p, size=%d\n", r, mem, size); // VALGRIND_DO_QUICK_LEAK_CHECK; VALGRIND_MEMPOOL_ALLOC(r, mem, size); return mem; }
static bool internal_build_rt_tree(ea_t adr) { /* check what we have */ ea_t root = find_root(adr & ~4, true); /* RT struct must be aligned on 4 bytes */ if ( NULL == root ) return false; if ( NULL != CObject ) classes_deinit(); /* make root class */ CObject = alloc_class(root, ROOT_LEN, NULL); make_RTStruct(root, ROOT_LEN); back_trace_rt(CObject); misc_buffer1 = (char *)qalloc(6 + max_size); /* 'vtbl_' + one for leading zero */ misc_buffer2 = (char *)qalloc(1 + max_size); sort_and_name_all(CObject); /* next fill linear array and sort it too */ rt_database = (struct RP_class **)qalloc(total_classes * sizeof(struct RP_class *)); filler_index = 0; fill_rt_database(CObject); qsort(rt_database, total_classes, sizeof(struct RP_class *), rt_compare_names); return true; }