static int _vlsctlc_pack_cmd_probe_service(struct vlsctlc* lsctlc, void* buf, int len) { struct probe_service_args* args = &lsctlc->args.probe_service_args; void* len_addr = NULL; int tsz = 0; int bsz = 0; vassert(lsctlc); vassert(buf); vassert(len > 0); if (lsctlc->bound_cmd != VLSCTL_PROBE_SERVICE) { return 0; } set_uint16(buf + tsz, lsctlc->bound_cmd); tsz += sizeof(uint16_t); set_uint16(len_addr = buf + tsz, 0); tsz += sizeof(uint16_t); memcpy(buf + tsz, &args->hash, sizeof(vsrvcHash)); bsz += sizeof(vsrvcHash); tsz += sizeof(vsrvcHash); set_uint16(len_addr, bsz); return tsz; }
static int _vlsctlc_unpack_cmd_probe_service_rsp(struct vlsctlc* lsctlc, void* buf, int len) { struct probe_service_rsp_args* args = &lsctlc->rsp_args.probe_service_rsp_args; int tsz = 0; int i = 0; vassert(lsctlc); vassert(buf); vassert(len > 0); if (lsctlc->bound_cmd != VLSCTL_PROBE_SERVICE) { return 0; } memcpy(&args->hash, buf + tsz, sizeof(vsrvcHash)); tsz += sizeof(vsrvcHash); args->proto = *(int32_t*)(buf + tsz); tsz += sizeof(int32_t); while(len - tsz > 0) { tsz += _aux_vlsctlc_unpack_vaddr(buf + tsz, len - tsz, &args->addrs[i]); i++; } args->num = i; return tsz; }
static int _vlsctlc_pack_cmd_unpost_service(struct vlsctlc* lsctlc, void* buf, int len) { struct unpost_service_args* args = &lsctlc->args.unpost_service_args; void* len_addr = NULL; int tsz = 0; int bsz = 0; int ret = 0; int i = 0; vassert(lsctlc); vassert(buf); vassert(len > 0); if (lsctlc->bound_cmd != VLSCTL_UNPOST_SERVICE) { return 0; } set_uint16(buf + tsz, lsctlc->bound_cmd); tsz += sizeof(uint16_t); set_uint16(len_addr = buf + tsz, 0); tsz += sizeof(uint16_t); memcpy(buf + tsz, &args->hash, sizeof(vsrvcHash)); bsz += sizeof(vsrvcHash); tsz += sizeof(vsrvcHash); for (i = 0;i < args->naddrs; i++) { ret = _aux_vlsctlc_pack_addr(buf + tsz, len - tsz, &args->addrs[i]); bsz += ret; tsz += ret; } set_uint16(len_addr, bsz); return tsz; }
static int _vlsctlc_pack_cmd_bogus_query(struct vlsctlc* lsctlc, void* buf, int len) { struct bogus_query_args* args = &lsctlc->args.bogus_query_args; void* len_addr = NULL; int tsz = 0; int bsz = 0; int ret = 0; vassert(lsctlc); vassert(buf); vassert(len > 0); if (lsctlc->bound_cmd != VLSCTL_BOGUS_QUERY) { return 0; } set_uint16(buf + tsz, lsctlc->bound_cmd); tsz += sizeof(uint16_t); set_uint16(len_addr = buf + tsz, 0); tsz += sizeof(uint16_t); set_int32(buf + tsz, args->queryId); bsz += sizeof(int32_t); tsz += sizeof(int32_t); ret = _aux_vlsctlc_pack_addr(buf + tsz, len - tsz, &args->addr); bsz += ret; tsz += ret; set_uint16(len_addr, bsz); return tsz; }
static int _vlsctlc_pack_cmd_join_node(struct vlsctlc* lsctlc, void* buf, int len) { struct join_node_args* args = &lsctlc->args.join_node_args; void* len_addr = NULL; int tsz = 0; int bsz = 0; vassert(lsctlc); vassert(buf); vassert(len > 0); if (lsctlc->bound_cmd != VLSCTL_JOIN_NODE) { return 0; } set_uint16(buf + tsz, lsctlc->bound_cmd); tsz += sizeof(uint16_t); set_uint16(len_addr = buf + tsz, 0); tsz += sizeof(uint16_t); bsz = _aux_vlsctlc_pack_addr(buf + tsz, len - tsz, &args->addr); tsz += bsz; set_uint16(len_addr, bsz); return tsz; }
static int _vlsctlc_pack_cmd(struct vlsctlc* lsctlc, void* buf, int len) { struct vlsctlc_pack_cmd_desc* desc = lsctlc_pack_cmd_desc; void* len_addr = NULL; int ret = 0; int tsz = 0; int bsz = 0; vassert(lsctlc); vassert(buf); vassert(len > 0); set_uint8(buf + tsz, VLSCTL_VERSION); tsz += sizeof(uint8_t); set_uint8(buf + tsz, (uint8_t)lsctlc->type); tsz += sizeof(uint8_t); set_uint16(len_addr = buf + tsz, 0); tsz += sizeof(uint16_t); set_uint32(buf + tsz, VLSCTL_MAGIC); tsz += sizeof(uint32_t); for (; desc->cmd; desc++) { ret = desc->cmd(lsctlc, buf + tsz, len - tsz); if (ret < 0) { return -1; } bsz += ret; tsz += ret; } *(uint16_t*)len_addr = (uint16_t)bsz; return tsz; }
char *strcasestr(const char *str1,const char *str2) { char *res = NULL; char *sub; vassert(str1 != NULL,"str1 == NULL"); vassert(str2 != NULL,"str2 == NULL"); /* handle special case to prevent looping the string */ if(!*str2) return (char*)str1; while(*str1) { /* matching char? */ if(tolower(*str1++) == tolower(*str2)) { res = (char*)--str1; sub = (char*)str2; /* continue until the strings don't match anymore */ while(*sub && tolower(*str1) == tolower(*sub)) { str1++; sub++; } /* complete substring matched? */ if(!*sub) return res; } } return NULL; }
static int _vlsctlc_bind_cmd_post_service(struct vlsctlc* lsctlc, vsrvcHash* hash, struct vsockaddr_in* addrs, int num, int proto) { struct post_service_args* args = &lsctlc->args.post_service_args; int i = 0; vassert(lsctlc); vassert(hash); vassert(addrs); vassert(num > 0); if (lsctlc->bound_cmd > 0) { return -1; } lsctlc->bound_cmd = VLSCTL_POST_SERVICE; lsctlc->type = vlsctl_cmd; args->proto = proto; args->naddrs = num; memcpy(&args->hash, hash, sizeof(vsrvcHash)); for (i = 0; i < num; i++) { memcpy(&args->addrs[i], &addrs[i], sizeof(struct vsockaddr_in)); } return 0; }
static int _vlsctlc_unbind_cmd_probe_service(struct vlsctlc* lsctlc, vsrvcHash* hash, struct vsockaddr_in* addrs, int* num, int* proto) { struct probe_service_rsp_args* args = &lsctlc->rsp_args.probe_service_rsp_args; vassert(lsctlc); vassert(hash); vassert(addrs); vassert(num); vassert(proto); int i = 0; if (lsctlc->bound_cmd != VLSCTL_PROBE_SERVICE) { return -1; } if (lsctlc->type == vlsctl_rsp_err) { //todo with errno. return -1; } memcpy(hash, &args->hash, sizeof(vsrvcHash)); *proto = args->proto; *num = args->num; for (i = 0; i < args->num; i++) { memcpy(&addrs[i], &args->addrs[i], sizeof(struct vsockaddr_in)); } return 0; }
/* Search forward from some given point in the incoming instruction sequence. Point is to select a virtual register to spill, by finding the vreg which is mentioned as far ahead as possible, in the hope that this will minimise the number of consequent reloads. Only do the search for vregs which are Bound in the running state, and for which the .is_spill_cand field is set. This allows the caller to arbitrarily restrict the set of spill candidates to be considered. Returns an index into the state array indicating the (v,r) pair to spill, or -1 if none was found. */ static Int findMostDistantlyMentionedVReg ( void (*getRegUsage) (HRegUsage*, HInstr*), HInstrArray* instrs_in, Int search_from_instr, RRegState* state, Int n_state ) { Int k, m; Int furthest_k = -1; Int furthest = -1; vassert(search_from_instr >= 0); for (k = 0; k < n_state; k++) { if (!state[k].is_spill_cand) continue; vassert(state[k].disp == Bound); for (m = search_from_instr; m < instrs_in->arr_used; m++) { if (instrMentionsReg(getRegUsage, instrs_in->arr[m], state[k].vreg)) break; } if (m > furthest) { furthest = m; furthest_k = k; } } return furthest_k; }
void vexSetAllocMode ( VexAllocMode m ) { vexAllocSanityCheck(); /* Save away the current allocation point .. */ if (mode == VexAllocModeTEMP){ temporary_curr = private_LibVEX_alloc_curr; } else if (mode == VexAllocModePERM) { permanent_curr = private_LibVEX_alloc_curr; } else vassert(0); /* Did that screw anything up? */ vexAllocSanityCheck(); if (m == VexAllocModeTEMP){ private_LibVEX_alloc_first = temporary_first; private_LibVEX_alloc_curr = temporary_curr; private_LibVEX_alloc_last = temporary_last; } else if (m == VexAllocModePERM) { private_LibVEX_alloc_first = permanent_first; private_LibVEX_alloc_curr = permanent_curr; private_LibVEX_alloc_last = permanent_last; } else vassert(0); mode = m; }
/* * the routine to find best suitable service from service routing table * so that local app can meet its needs with that service. * * @route: * @svc_hash: service hash id. * @addr : [out] address of service */ static int _vroute_find_service(struct vroute* route, vsrvcHash* hash, vsrvcInfo_number_addr_t ncb, vsrvcInfo_iterate_addr_t icb, void* cookie) { struct vroute_srvc_space* srvc_space = &route->srvc_space; vsrvcInfo_relax srvci; int ret = 0; int i = 0; vassert(route); vassert(hash); vassert(ncb); vassert(icb); memset(&srvci, 0, sizeof(srvci)); srvci.capc = VSRVCINFO_MAX_ADDRS; vlock_enter(&route->lock); ret = srvc_space->ops->get_service(srvc_space, hash, (vsrvcInfo*)&srvci); vlock_leave(&route->lock); retE((ret < 0)); if (!ret) { ncb(&srvci.hash, 0, VPROTO_UNKNOWN, cookie); return 0; } ncb(&srvci.hash, srvci.naddrs, VPROTO_UDP, cookie); for (i = 0; i < srvci.naddrs; i++) { icb(&srvci.hash, &srvci.addrs[i], ((i+1) == srvci.naddrs), cookie); } return 0; }
/* * the routine to get service info from service routing table space if local host * require some kind of system service. * * @space: service routing table space; * @srvcHash: * @svci : service infos */ static int _vroute_srvc_space_get_service(struct vroute_srvc_space* space, vsrvcHash* hash, vsrvcInfo* srvci) { struct vservice* to = NULL; int min_nice = 100; int found = 0; int i = 0; vassert(space); vassert(hash); vassert(srvci); for (i = 0; i < NBUCKETS; i++) { void* argv[] = { &to, hash, &min_nice }; varray_iterate(&space->bucket[i].srvcs, _aux_srvc_get_service_cb, argv); if (to) { vsrvcInfo_copy(&srvci, to->srvci); found = 1; } } return found; }
void ufDestroy(ufOgNode * element) { HWord hashkey; ufOgHashNode * delHashNode; vassert(element != NULL); vassert(element != NULL); // VG_(printf)("XXX ufDestroy %u %u \n", element->tmpName, element->bbExecNum); hashkey = locToHashKey(element->tmpName, element->bbExecNum, TmpLoc); // delete x from H delHashNode = VG_(HT_remove)(ufOgHash, hashkey); if (delHashNode) { VG_(free)(delHashNode); } // delete x from LiveTempVarNodes // delHashNode = VG_(HT_remove)(ufOgLiveTempVarNodes, hashkey); // if (delHashNode) //{ // VG_(free)(delHashNode); //} // free x itself VG_(free)(element); }
static int _vlsctlc_unpack_cmd(struct vlsctlc* lsctlc, void* buf, int len) { struct vlsctlc_unpack_cmd_desc* desc = lsctlc_unpack_cmd_desc; uint32_t magic = 0; int tsz = 0; int bsz = 0; int csz = 0; int ret = 0; vassert(lsctlc); vassert(buf); vassert(len > 0); tsz += sizeof(uint8_t); // skip version; lsctlc->type = get_uint8(buf + tsz); tsz += sizeof(uint8_t); bsz = (int)get_uint16(buf + tsz); tsz += sizeof(uint16_t); magic = get_uint32(buf + tsz); tsz += sizeof(uint32_t); // _aux_vhexbuf_dump(buf, bsz); if (magic != VLSCTL_MAGIC) { return -1; } while(bsz - csz > 0) { uint16_t cmd_id = 0; int cmd_len = 0; int i = 0; cmd_id = get_uint16(buf + tsz); tsz += sizeof(uint16_t); csz += sizeof(uint16_t); cmd_len = get_uint16(buf + tsz); tsz += sizeof(uint16_t); csz += sizeof(uint16_t); lsctlc->bound_cmd = cmd_id; while(cmd_len > 0) { for (i = 0; desc[i].cmd; i++) { ret = desc[i].cmd(lsctlc, buf + tsz, cmd_len); if (ret < 0) { return -1; } else if (ret > 0) { tsz += ret; csz += ret; cmd_len -= ret; break; }else { //do nothing; } } } } return 0; }
int kmytid_test() { reset(); kmytid(t1); vassert(t1->state == READY); vassert(task_get_return_value(t1) == 1); return 0; }
projectile_data *get_projectile_data( const short projectile_index) { struct projectile_data *projectile = GetMemberWithBounds(projectiles,projectile_index,MAXIMUM_PROJECTILES_PER_MAP); vassert(projectile, csprintf(temporary, "projectile index #%d is out of range", projectile_index)); vassert(SLOT_IS_USED(projectile), csprintf(temporary, "projectile index #%d (%p) is unused", projectile_index, projectile)); return projectile; }
static int vservice_init(struct vservice* item, vsrvcInfo* srvci, time_t ts) { vassert(item); vassert(srvci); vsrvcInfo_copy(&item->srvci, srvci); item->rcv_ts = ts; return 0; }
void _vroute_set_inspect_cb(struct vroute* route, vroute_inspect_t cb, void* cookie) { vassert(route); vassert(cb); vlock_enter(&route->lock); route->insp_cb = cb; route->insp_cookie = cookie; vlock_leave(&route->lock); return ; }
void _vroute_inspect(struct vroute* route, vtoken* token, uint32_t insp_id) { vassert(route); vassert(token); vlock_enter(&route->lock); if (route->insp_cb) { route->insp_cb(route, route->insp_cookie, token, insp_id); } vlock_leave(&route->lock); return ; }
int kmy_parent_tid_test() { reset(); kmy_parent_tid(t1); kmy_parent_tid(t2); vassert(t1->state == READY); vassert(task_get_return_value(t1) == 0); vassert(t2->state == READY); vassert(task_get_return_value(t2) == 1); return 0; }
int kcreate_test() { reset(); kcreate(t2, MEDIUM, 0, 0); vassert(t2->state == READY); vassert(task_get_return_value(t2) > t2->tid); Task *child = task_get(task_get_return_value(t2)); vassert(child != 0); vassert(child->state == READY); return 0; }
int _vroute_probe_connectivity(struct vroute* route, struct sockaddr_in* laddr) { struct vroute_node_space* node_space = &route->node_space; int ret = 0; vassert(route); vassert(laddr); vlock_enter(&route->lock); ret = node_space->ops->probe_connectivity(node_space, laddr); vlock_leave(&route->lock); retE((ret < 0)); return 0; }
int vroute_srvc_space_init(struct vroute_srvc_space* space, struct vconfig* cfg) { int i = 0; vassert(space); vassert(cfg); for (i = 0; i < NBUCKETS; i++) { varray_init(&space->bucket[i].srvcs, 8); } space->bucket_sz = cfg->ext_ops->get_route_bucket_sz(cfg); space->ops = &route_srvc_space_ops; return 0; }
static int _vroute_reflex_addr(struct vroute* route, struct sockaddr_in* addr) { struct vroute_node_space* node_space = &route->node_space; int ret = 0; vassert(route); vassert(addr); vlock_enter(&route->lock); ret = node_space->ops->reflex_addr(node_space, addr); vlock_leave(&route->lock); retE((ret < 0)); return 0; }
static int _vroute_air_service(struct vroute* route, vsrvcInfo* srvci) { struct vroute_node_space* node_space = &route->node_space; int ret = 0; vassert(route); vassert(srvci); vlock_enter(&route->lock); ret = node_space->ops->air_service(node_space, srvci); vlock_leave(&route->lock); retE((ret < 0)); return 0; }
size_t strnzcpy(char *to,const char *from,size_t size) { char *res = to; vassert(from != NULL,"from == NULL"); vassert(to != NULL,"to == NULL"); /* copy source string */ while(*from && size > 1) { *to++ = *from++; size--; } /* terminate */ *to = '\0'; return to - res; }
/* Add a register to a usage table. Combines incoming read uses with existing write uses into a modify use, and vice versa. Does not create duplicate entries -- each reg is only mentioned once. */ void addHRegUse ( HRegUsage* tab, HRegMode mode, HReg reg ) { /* Because real and virtual registers are represented differently, they have completely different paths here. */ if (LIKELY(hregIsVirtual(reg))) { /* Virtual register */ UInt i; /* Find it ... */ for (i = 0; i < tab->n_vRegs; i++) if (sameHReg(tab->vRegs[i], reg)) break; if (i == tab->n_vRegs) { /* Not found, add new entry. */ vassert(tab->n_vRegs < N_HREGUSAGE_VREGS); tab->vRegs[tab->n_vRegs] = reg; tab->vMode[tab->n_vRegs] = mode; tab->n_vRegs++; } else { /* Found: combine or ignore. */ /* This is a greatest-lower-bound operation in the poset: R W \ / M Need to do: tab->mode[i] = GLB(tab->mode, mode). In this case very simple -- if tab->mode[i] != mode then result must be M. */ if (tab->vMode[i] == mode) { /* duplicate, ignore */ } else { tab->vMode[i] = HRmModify; } } } else { /* Real register */ UInt ix = hregIndex(reg); vassert(ix < N_RREGUNIVERSE_REGS); ULong mask = 1ULL << ix; switch (mode) { case HRmRead: tab->rRead |= mask; break; case HRmWrite: tab->rWritten |= mask; break; case HRmModify: tab->rRead |= mask; tab->rWritten |= mask; break; default: vassert(0); } } }
int setTypeOf(HWord varname, IntType type) { OgTypeOfHashNode * node; node = VG_(HT_lookup)(ogTypeOf,varname); if (!node) { /* Allocate and add node for varname, since we are setting TypeOf()*/ node = (OgTypeOfHashNode *)VG_(malloc)("HashNode", sizeof(OgTypeOfHashNode)); node->varname = varname; VG_(HT_add_node)(ogTypeOf,node); } vassert(node->varname == varname); node->type = type; /* Debugging only for now: */ /* switch (type) { case (Bot) : VG_(printf)("XXX Varname var.%u set to Bot. \n",varname); break; case (Top) : VG_(printf)("XXX Varname var.%u set to Top. \n",varname); break; case (SignedTy) : VG_(printf)("XXX Varname var.%u set to SIGNED. \n",varname); break; case (UnsignedTy) : VG_(printf)("XXX Varname var.%u set to UNSIGNED. \n",varname); break; case (BogusTy) : vpanic("Set variable to bogus type!\n"); } */ return 0; }
bool ParameterManager::handleMessage(const message::SetParameter ¶m) { // sent by controller switch (param.getParameterType()) { case Parameter::Integer: setIntParameter(param.getName(), param.getInteger(), ¶m); break; case Parameter::Float: setFloatParameter(param.getName(), param.getFloat(), ¶m); break; case Parameter::Vector: setVectorParameter(param.getName(), param.getVector(), ¶m); break; case Parameter::IntVector: setIntVectorParameter(param.getName(), param.getIntVector(), ¶m); break; case Parameter::String: setStringParameter(param.getName(), param.getString(), ¶m); break; default: std::cerr << "Module::handleMessage: unknown parameter type " << param.getParameterType() << std::endl; vassert("unknown parameter type" == 0); break; } return true; }