static void update_umad_port_cache(struct oib_port *port) { int rc; struct ibv_async_event event; ibv_get_async_event(port->verbs_ctx, &event); ibv_ack_async_event(&event); switch (event.event_type) { case IBV_EVENT_PORT_ACTIVE: case IBV_EVENT_PORT_ERR: case IBV_EVENT_LID_CHANGE: case IBV_EVENT_PKEY_CHANGE: rc = cache_port_details(port); if (rc != 0) OUTPUT_ERROR ("umad port cache data invalid!\n"); break; case IBV_EVENT_SM_CHANGE: case IBV_EVENT_CLIENT_REREGISTER: if (reregister_traps(port)) OUTPUT_ERROR("failed to reregister traps.\n"); rc = cache_port_details(port); if (rc != 0) OUTPUT_ERROR ("umad port cache data invalid!\n"); break; case IBV_EVENT_CQ_ERR: OUTPUT_ERROR("got IBV_EVENT_CQ_ERR\n"); break; default: break; } }
/** * Gets the node type for the specified HFI. * * @param port The pointer to the port object for which the node type is asked. * @param nodeType * * @return FSTATUS */ FSTATUS oib_get_hfi_node_type(IN struct oib_port *port, OUT int *nodeType) { FSTATUS status; umad_ca_t cainfo; if (port == NULL) { OUTPUT_ERROR("Port must be specified.\n"); return FINVALID_PARAMETER; } else if (nodeType == NULL) { OUTPUT_ERROR("Invalid output pointer.\n"); return FINVALID_PARAMETER; } status = umad_get_ca(port->hfi_name, &cainfo); if (status != FSUCCESS) { OUTPUT_ERROR("umad_get_ca() failed (returned: %u)\n", status); return status; } *nodeType = cainfo.node_type; umad_release_ca(&cainfo); return FSUCCESS; }
static enum oib_th_event handle_th_msg(struct oib_port *port) { struct oib_thread_msg msg; int s; memset(&msg, 0, sizeof(msg)); s = read(port->umad_port_sv[1], &msg, sizeof(msg)); if (s <= 0 || s != sizeof(msg)) { OUTPUT_ERROR ("th event read failed : %s\n", strerror(errno)); return OIB_TH_EVT_NONE; } switch (msg.evt) { case OIB_TH_EVT_SHUTDOWN: break; case OIB_TH_EVT_UD_MONITOR_ON: port->run_sa_cq_poll = 1; break; case OIB_TH_EVT_UD_MONITOR_OFF: port->run_sa_cq_poll = 0; break; case OIB_TH_EVT_START_OUTSTANDING_REQ_TIME: port->poll_timeout_ms = NOTICE_REG_TIMEOUT_MS; break; default: OUTPUT_ERROR ("Unknown msg : %d\n", msg.evt); break; } return msg.evt; }
static void join_port_thread(struct oib_port *port) { struct oib_thread_msg msg; int rc, err; int retries = 3; msg.size = sizeof(msg); msg.evt = OIB_TH_EVT_SHUTDOWN; do { rc = write(port->umad_port_sv[0], &msg, sizeof(msg)); if (rc <= 0) OUTPUT_ERROR("failed to send Thread shutdown to cache thread\n"); /* I don't think we need to wait for a response */ } while (rc <= 0 && retries--); if (rc <= 0) { OUTPUT_ERROR("Thread NOT SHUTDOWN aborting join...\n"); return; } pthread_join(port->umad_port_thread, NULL); // close the sockets err = close(port->umad_port_sv[0]); if (err != 0) { OUTPUT_ERROR("Failed to close thread sock pair(0) : %s\n", strerror(errno)); } }
int ConfigMapParser::parse(bool noThrow) { int returnValue = 0; ASSERT(lexer); ASSERT(configMap); try { if(!lexer->isValid()) { returnValue = ConfigMap::E_FILE; throw ParseException(0, 0, "Cannot read file."); } nextToken(); // get the first token return file(configMap); } catch(ParseException& pe) { // If the returnValue indicates not that the file connot be opened, there // has to be a syntax error. if (returnValue != ConfigMap::E_FILE) returnValue = ConfigMap::E_SYNTAX; if(verbose) pe.printError(lexer->getFilename()); std::stringstream buf; std::cout<<"[EXCEPTION ERROR ] ConfigMapParser.cpp 3"<<std::endl; buf << lexer->getFilename() << ":" << pe.line << "," << pe.column << ": " << pe.what(); ParseException e = ParseException(pe.line, pe.column, buf.str()); if (noThrow) setError(e); else throw e; } catch(invalid_key) { if(verbose) OUTPUT_ERROR("ConfigMapParser::parse catched a invalid_key exception.\n" "This indicates, that there is a bug into the parser."); ASSERT(false); } catch(std::invalid_argument) { if(verbose) OUTPUT_ERROR("ConfigMapParser::parse catched a invalid_argument exception.\n" "This indicates, that there is a bug into the parser."); ASSERT(false); } return returnValue; }
void TeamMessageHandler::writeMessage(BHumanMessageOutputGenerator& outputGenerator, RoboCup::SPLStandardMessage* const m) const { ASSERT(outputGenerator.sendThisFrame); outputGenerator.theBHULKsStandardMessage.write(reinterpret_cast<void*>(m->data)); int offset = outputGenerator.theBHULKsStandardMessage.sizeOfBHULKsMessage(); outputGenerator.theBHumanStandardMessage.write(reinterpret_cast<void*>(m->data + offset)); offset += outputGenerator.theBHumanStandardMessage.sizeOfBHumanMessage(); const int restBytes = SPL_STANDARD_MESSAGE_DATA_SIZE - offset; ASSERT(restBytes > 10); int sizeOfArbitraryMessage; if((sizeOfArbitraryMessage = outputGenerator.theBHumanArbitraryMessage.sizeOfArbitraryMessage()) > restBytes) { OUTPUT_ERROR("outputGenerator.theBHumanArbitraryMessage.sizeOfArbitraryMessage() > restBytes " "-- with size of " << sizeOfArbitraryMessage << "and restBytes:" << int(restBytes)); do outputGenerator.theBHumanArbitraryMessage.queue.removeLastMessage(); while((sizeOfArbitraryMessage = outputGenerator.theBHumanArbitraryMessage.sizeOfArbitraryMessage()) > restBytes && !outputGenerator.theBHumanArbitraryMessage.queue.isEmpty()); } ASSERT(sizeOfArbitraryMessage < restBytes); outputGenerator.theBHumanArbitraryMessage.write(reinterpret_cast<void*>(m->data + offset)); outputGenerator.theBSPLStandardMessage.numOfDataBytes = static_cast<uint16_t>(offset + sizeOfArbitraryMessage); outputGenerator.theBSPLStandardMessage.write(reinterpret_cast<void*>(&m->header[0])); outputGenerator.sentMessages++; timeLastSent = theFrameInfo.time; }
void error(const std::string &errMsg) { #ifndef TARGET_TOOL std::string msg("BehaviorError: "); msg += errMsg; OUTPUT_ERROR(msg.c_str()); #endif }
void Obstacle::fusion2D(Obstacle& one, const Obstacle& other) { if(!twoDimSquareEquation(one.center, one.covariance, other.center, other.covariance)) { OUTPUT_ERROR("Call Florian: one's type " << one.type << " cov: " << one.covariance(0, 0) << " " << one.covariance(1, 1) << " other type " << other.type << " cov: " << other.covariance(0, 0) << " " << other.covariance(1, 1)); } }
bool NaoCamera::captureNew() { // requeue the buffer of the last captured image which is obsolete now if(currentBuf) { BH_TRACE; VERIFY(ioctl(fd, VIDIOC_QBUF, currentBuf) != -1); } BH_TRACE; const unsigned startPollingTimestamp = SystemCall::getCurrentSystemTime(); struct pollfd pollfd = {fd, POLLIN | POLLPRI, 0}; int polled = poll(&pollfd, 1, 200); // Fail after missing 6 frames (200ms) if(polled < 0) { OUTPUT_ERROR(CameraInfoBH::getName(camera) << "camera : Cannot poll. Reason: " << strerror(errno)); ASSERT(false); } else if(polled == 0) { OUTPUT_ERROR(CameraInfoBH::getName(camera) << "camera : 200 ms passed and there's still no image to read from the camera. Terminating."); return false; } else if(pollfd.revents & (POLLERR | POLLNVAL)) { OUTPUT_ERROR(CameraInfoBH::getName(camera) << "camera : Polling failed."); return false; } // dequeue a frame buffer (this call blocks when there is no new image available) */ VERIFY(ioctl(fd, VIDIOC_DQBUF, buf) != -1); BH_TRACE; //ASSERT(buf->bytesused == SIZE); currentBuf = buf; timeStamp = (unsigned long long) currentBuf->timestamp.tv_sec * 1000000ll + currentBuf->timestamp.tv_usec; const unsigned endPollingTimestamp = SystemCall::getCurrentSystemTime(); timeWaitedForLastImage = endPollingTimestamp - startPollingTimestamp; if(first) { first = false; printf("%s camera is working\n", CameraInfoBH::getName(camera)); } return true; }
/** ========================================================================= * Cache the pkeys associated with the port passed into the port object. * * @param port * @return 0 on success +ERRNO on failure */ static int cache_port_details(struct oib_port *port) { int err = 0; if ((err = oib_lock_sem(&port->umad_port_cache_lock)) != 0) { OUTPUT_ERROR("Cannot cache pkeys, failed to acquire lock (err: %d)\n", err); return EIO; } if (port->umad_port_cache_valid) { umad_release_port(&port->umad_port_cache); } port->umad_port_cache.pkeys_size = 0; port->umad_port_cache_valid = 0; if (umad_get_port(port->hfi_name, port->hfi_port_num, &port->umad_port_cache) < 0) { OUTPUT_ERROR ("can't get UMAD port information (%s:%d)\n", port->hfi_name, port->hfi_port_num); err = EIO; goto fail; } if (!port->umad_port_cache.pkeys) { OUTPUT_ERROR ("no UMAD pkeys for (%s:%d)\n", port->hfi_name, port->hfi_port_num); err = EIO; goto fail2; } /* NOTE the umad interface returns network byte order here; fix it */ port->umad_port_cache.port_guid = ntoh64(port->umad_port_cache.port_guid); port->umad_port_cache.gid_prefix = ntoh64(port->umad_port_cache.gid_prefix); port->umad_port_cache_valid = 1; oib_unlock_sem(&port->umad_port_cache_lock); return 0; fail2: umad_release_port(&port->umad_port_cache); port->umad_port_cache.pkeys_size = 0; port->umad_port_cache_valid = 0; fail: oib_unlock_sem(&port->umad_port_cache_lock); return err; }
SpecialActions::SpecialActions() : wasEndOfSpecialAction(false), //stiffnessInterpolationStart(0), stiffnessInterpolationCounter(0), stiffnessInterpolationLength(0), wasActive(false), dataRepetitionCounter(0), lastSpecialAction(SpecialActionRequest::numOfSpecialActionIDs), mirror(false) { theInstance = this; std::vector<float> motionData; char errorBuffer[10000]; MofCompiler* mofCompiler = new MofCompiler; if(!mofCompiler->compileMofs(errorBuffer, sizeof(errorBuffer), motionData)) OUTPUT_TEXT("Error while parsing mof files:"); else motionNetData.load(motionData); delete mofCompiler; if(*errorBuffer) OUTPUT_TEXT(" " << errorBuffer); // create an uninitialised motion request to set startup motion currentNode = motionNetData.label_extern_start[SpecialActionRequest().specialAction]; // read entries from file InMapFile cm("specialActions.cfg"); if(!cm.exists()) { OUTPUT_ERROR("'specialActions.cfg' not found."); } else { OdometryParams infos; cm >> infos; for(std::vector<SpecialActionInfo>::const_iterator it = infos.specialActionInfos.begin(); it != infos.specialActionInfos.end(); it++) { infoTable[it->id] = SpecialActionInfo(*it); if(it->type == SpecialActionInfo::once || it->type == SpecialActionInfo::homogeneous) { infoTable[it->id].odometryOffset.rotation = it->odometryOffset.rotation; if(it->type == SpecialActionInfo::homogeneous) { // convert from mm/seconds to mm/tick float motionCycleTime = theFrameInfo.cycleTime; infoTable[it->type].odometryOffset.translation.x() *= motionCycleTime; infoTable[it->type].odometryOffset.translation.y() *= motionCycleTime; // convert from rad/seconds to rad/tick infoTable[it->type].odometryOffset.rotation *= motionCycleTime; } } } } }
void bs_assert(bool b, const std::string &msg) { #ifndef TARGET_TOOL if(!b) { ASSERT(false); OUTPUT_ERROR("BehaviorAssert failed: " << msg); } #endif }
InConfigMap::InConfigMap(const std::string& name) : name(name), map() { stack.reserve(20); status = map.read(name); if (status == ConfigMap::E_SYNTAX) OUTPUT_ERROR(map.getErrorMessage()); map.setFlags(map.getFlags() | ConfigMap::READONLY); }
/** * Function to refresh the pkey table for the MAD interface * for a given hfi name and port. * To use with oib_xxx_mad, and the umad OFED library. * * @param *port pointer to port object * * @return 0 success * -1 Failure */ int oib_mad_refresh_port_pkey(struct oib_port *port) { if (!port) { OUTPUT_ERROR("%s: Port must be specified\n", __func__); return (-1); } // The local function takes care of everything. return cache_port_details(port); }
bool NaoCamera::captureNew() { // requeue the buffer of the last captured image which is obsolete now if(currentBuf) { BH_TRACE; VERIFY(ioctl(fd, VIDIOC_QBUF, currentBuf) != -1); } BH_TRACE; pollfd pollfd = {fd, POLLIN | POLLPRI, 0}; int polled = poll(&pollfd, 1, 200); // Fail after missing 6 frames (200ms) if(polled < 0) { OUTPUT_ERROR(TypeRegistry::getEnumName(camera) << "camera : Cannot poll. Reason: " << strerror(errno)); FAIL(TypeRegistry::getEnumName(camera) << "camera : Cannot poll. Reason: " << strerror(errno) << "."); } else if(polled == 0) { OUTPUT_ERROR(TypeRegistry::getEnumName(camera) << "camera : 200 ms passed and there's still no image to read from the camera. Terminating."); return false; } else if(pollfd.revents & (POLLERR | POLLNVAL)) { OUTPUT_ERROR(TypeRegistry::getEnumName(camera) << "camera : Polling failed."); return false; } // dequeue a frame buffer (this call blocks when there is no new image available) */ VERIFY(ioctl(fd, VIDIOC_DQBUF, buf) != -1); BH_TRACE; currentBuf = buf; timeStamp = static_cast<unsigned long long>(currentBuf->timestamp.tv_sec) * 1000000ll + currentBuf->timestamp.tv_usec; if(first) { first = false; printf("%s camera is working\n", TypeRegistry::getEnumName(camera)); } return true; }
/** * Gets the ISSM device corresponding to the specified port. * * @param port Pointer to the opened local port object. * @param path Buffer in which to place the device path * @param path_max Maximum length of the output buffer * * @return FSUCCESS on success, or UMad error code on failure */ FSTATUS oib_get_issm_device(struct oib_port *port, char *path, int path_max) { int status; if (port == NULL) { OUTPUT_ERROR("port must be specified.\n"); return FINVALID_PARAMETER; } else if (path == NULL) { OUTPUT_ERROR("Invalid output path buffer.\n"); return FINVALID_PARAMETER; } status = umad_get_issm_path(port->hfi_name, port->hfi_port_num, path, path_max); if (status) { OUTPUT_ERROR("Failed to resolve ISSM device name (status: %d)\n", status); return status; } return FSUCCESS; }
/** ========================================================================= */ static void destroy_sa_qp(struct oib_port *port) { int i; // if the user just unregistered trap messages those messages may still // be on this list, wait 5 seconds for the thread to handle the response. for (i = 0; i < 5000; i++) { if (!LIST_EMPTY(&port->pending_reg_msg_head)) { usleep(1000); } else { DBGPRINT("destroy_sa_qp: wait %d ms for LIST_EMPTY\n", i); break; } } stop_ud_cq_monitor(port); join_port_thread(port); /* Free any remaining unregistration messages */ if (!LIST_EMPTY(&port->pending_reg_msg_head)) { OUTPUT_ERROR("Ignoring Pending Notice un-registation requests\n"); oib_sa_remove_all_pending_reg_msgs(port); } if (port->sa_ah) ibv_destroy_ah(port->sa_ah); if (port->sa_qp) ibv_destroy_qp(port->sa_qp); for (i = 0; i<port->num_userspace_recv_buf; i++) if (port->recv_bufs) ibv_dereg_mr(port->recv_bufs[i].mr); if (port->sa_qp_pd) ibv_dealloc_pd(port->sa_qp_pd); if (port->sa_qp_cq) ibv_destroy_cq(port->sa_qp_cq); if (port->recv_bufs) { free(port->recv_bufs); port->recv_bufs = NULL; } if (port->sa_qp_comp_channel) ibv_destroy_comp_channel(port->sa_qp_comp_channel); }
/** ========================================================================= */ static int open_verbs_ctx(struct oib_port *port) { int i; int num_devices; struct ibv_device **dev_list; dev_list = ibv_get_device_list(&num_devices); for (i = 0; i < num_devices; ++i) if (dev_list[i] != NULL && (strncmp(dev_list[i]->name, port->hfi_name, sizeof(dev_list[i]->name)) == 0) ) break; if (i >= num_devices) { ibv_free_device_list(dev_list); OUTPUT_ERROR("failed to find verbs device\n"); return EIO; } port->verbs_ctx = ibv_open_device(dev_list[i]); ibv_free_device_list(dev_list); if (port->verbs_ctx == NULL) { OUTPUT_ERROR("failed to open verbs device\n"); return EIO; } if (sem_init(&port->lock,0,1) != 0) { ibv_close_device(port->verbs_ctx); OUTPUT_ERROR("failed to init registry lock\n"); return EIO; } return 0; }
void InConfigMap::printError(const std::string& msg) { std::string path = ""; for(std::vector<Entry>::const_iterator i = stack.begin(); i != stack.end(); ++i) { if(i->key) { if(path != "") path += '.'; path += i->key; } else { char buf[20]; sprintf(buf, "[%d]", i->type); path += buf; } } if(name == "") OUTPUT_ERROR(path << ": " << msg); else OUTPUT_ERROR(name << ", " << path << ": " << msg); }
ANALYZE_TREE() { CallSite gets("gets"); CallSite strcpy("strcpy"); CallSite strcat("strcat"); CallSite sprintf("sprintf"); CallSite rand("rand"); if(MATCH(gets)) OUTPUT_ERROR("buffer overflow "<<"gets() makes no guarantee of safety. "<<"Use fgets() instead."<<" VERY RISKY" << CURRENT_TREE); if(MATCH(strcpy)) OUTPUT_ERROR("buffer overflow "<<"strcpy() makes no guarantee of safety. "<<"Use strncpy() instead."<<" [VERY RISKY]" << CURRENT_TREE); if(MATCH(strcat)) OUTPUT_ERROR("buffer overflow "<<"strcat() makes no guarantee of safety. "<<"Use strncat() instead."<<" [VERY RISKY]" << CURRENT_TREE); if(MATCH(sprintf)) OUTPUT_ERROR("buffer overflow "<<"sprintf() makes no guarantee of safety. "<<"Use snprintf() instead."<<" [VERY RISKY]" << CURRENT_TREE); if(MATCH(rand)) OUTPUT_ERROR("buffer overflow "<<"rand() makes no guarantee of safety. "<<"Use srand() instead."<<" [VERY RISKY]" << CURRENT_TREE); }
/** ========================================================================= * Init sub libraries like umad here * */ static int init_sub_lib(void) { static int done = 0; if (done) return 0; if (umad_init() < 0) { OUTPUT_ERROR("can't init UMAD library\n"); return EIO; } done = 1; return (0); }
/** ========================================================================= */ uint8_t oib_get_port_state(struct oib_port *port) { uint8_t rc; int err = 0; if ((err = oib_lock_sem(&port->umad_port_cache_lock)) != 0) { OUTPUT_ERROR("Cannot get port state, failed to acquire lock (err: %d)\n", err); return 0; } rc = port->umad_port_cache.state; oib_unlock_sem(&port->umad_port_cache_lock); return rc; }
/** ========================================================================= */ static int start_port_thread(struct oib_port *port) { int err, flags; pthread_attr_t attr; err = socketpair(AF_UNIX, SOCK_DGRAM, 0, port->umad_port_sv); if (err != 0) { OUTPUT_ERROR("Failed to open thread sock pair : %s\n", strerror(errno)); return EIO; } /* change the blocking mode of the async event queue */ flags = fcntl(port->verbs_ctx->async_fd, F_GETFL); err = fcntl(port->verbs_ctx->async_fd, F_SETFL, flags | O_NONBLOCK); if (err < 0) { OUTPUT_ERROR("Failed to change file descriptor of async event queue\n"); return EIO; } pthread_attr_init(&attr); err = pthread_create(&port->umad_port_thread, &attr, umad_port_thread, (void *)port); pthread_attr_destroy(&attr); return err; }
void DebugDataStreamer::serialize(In* in, Out* out) { ASSERT((inData && out) || (outData && in)); if(type.size() > 8 && type.substr(type.size() - 8) == " __ptr64") type = type.substr(0, type.size() - 8); if(type[type.size() - 1] == ']' || type[type.size() - 1] == '*') { unsigned size; std::string elementType; bool staticSize = type[type.size() - 1] == ']'; if(staticSize) { size_t i = type.size(); while(type[i - 1] != '[') --i; size_t j = type[i - 2] == ' ' ? i - 2 : i - 1; size = atoi(&type[i]); elementType = std::string(type).substr(0, j); } else { elementType = std::string(type).substr(0, type.size() - (type.size() > 1 && type[type.size() - 2] == ' ' ? 2 : 1)); if(inData) *inData >> size; } if(in) { in->select(name, -1); unsigned dynamicSize; *in >> dynamicSize; if(!staticSize) { size = dynamicSize; *outData << size; } else if(size != dynamicSize) { char buf[100]; sprintf(buf, "array has %d elements instead of %d", dynamicSize, size); OUTPUT_ERROR(buf); size = dynamicSize; } } else {
void DebugDataStreamer::serialize(In* in, Out* out) { ASSERT((inData && out) || (outData && in)); if(type[type.size() - 1] == ']' || type[type.size() - 1] == '*') { unsigned size = 0; std::string elementType; bool staticSize = type[type.size() - 1] == ']'; if(staticSize) { size_t endOfType = type.find_last_of('['); size = atoi(&type[endOfType + 1]); elementType = type.substr(0, endOfType); } else { elementType = type.substr(0, type.size() - 1); if(inData) *inData >> size; } if(in) { in->select(name, -1); unsigned dynamicSize; *in >> dynamicSize; if(!staticSize) { size = dynamicSize; *outData << size; } else if(size != dynamicSize) { std::ostringstream stream; stream << "array has " << dynamicSize << " elements instead of " << size; InMap* inMap = dynamic_cast<InMap*>(in); if(inMap) inMap->printError(stream.str()); else { OUTPUT_ERROR(stream.str()); size = dynamicSize; } } } else {
/* Returns 0 (invalid base version) on error */ static uint8_t get_base_version_from_ni(int fd, uint32_t aid, int pkey_index) { uint8_t rc; void *umad_p = NULL; struct umad_smp *send_mad; size_t length; umad_p = umad_alloc(1, sizeof(*send_mad) + umad_size()); if (!umad_p) { OUTPUT_ERROR ("can't alloc umad for OPA check; send_size %ld\n", sizeof(*send_mad)); return 0; } memset(umad_p, 0, sizeof(*send_mad) + umad_size()); umad_set_grh(umad_p, 0); send_mad = umad_get_mad(umad_p); send_mad->base_version = UMAD_BASE_VERSION; send_mad->mgmt_class = UMAD_CLASS_SUBN_DIRECTED_ROUTE; send_mad->class_version = 0x01; send_mad->method = UMAD_METHOD_GET; send_mad->tid = htonl(0xDEADBEEF); send_mad->attr_id = htons(UMAD_SM_ATTR_NODE_INFO); send_mad->dr_slid = 0xffff; send_mad->dr_dlid = 0xffff; umad_set_pkey(umad_p, pkey_index); umad_set_addr(umad_p, 0xffff, 0, 0, 0); rc = 0; if (umad_send(fd, aid, umad_p, sizeof(*send_mad), 100, 1) < 0) goto free_mad; length = sizeof(*send_mad); if (umad_recv(fd, umad_p, (int *)&length, 100) < 0) goto free_mad; if (length < sizeof(*send_mad)) goto free_mad; if (umad_status(umad_p) != 0) goto free_mad; rc = ((NODE_INFO *)(send_mad->data))->BaseVersion; free_mad: free(umad_p); return rc; }
/** ========================================================================= */ int oib_find_pkey(struct oib_port *port, uint16_t pkey) { int err; int i = -1; if (pkey == 0) return -1; if ((err = oib_lock_sem(&port->umad_port_cache_lock)) != 0) { OUTPUT_ERROR("Cannot find pKey, failed to acquire lock (err: %d)\n", err); return -1; } i = find_pkey_from_umad_port(&port->umad_port_cache, pkey); oib_unlock_sem(&port->umad_port_cache_lock); return i; }
static uint16_t oib_find_pkey_from_idx(struct oib_port *port, unsigned idx) { uint16_t rc; int err; if ((err = oib_lock_sem(&port->umad_port_cache_lock)) != 0) { OUTPUT_ERROR("Cannot locate pKey, failed to acquire lock (err: %d)\n", err); return 0x0000; } if (idx < port->umad_port_cache.pkeys_size) rc = port->umad_port_cache.pkeys[idx]; else rc = 0x0000; oib_unlock_sem(&port->umad_port_cache_lock); return rc; }
ANALYZE_TREE() { CallSite strncat("strncat"); Array a; Expr b; Const_int x; if(MATCH(strncat(a,b,x))) { //get the first arguement des string size and third arguemnt length of second stringget_size_of_type(a) if(get_size_of_type((array_type_t const *) get_type_of_tree(a)) <= x.llval()) { OUTPUT_ERROR("the size of source string is potentionally larger than destination string, will lead buffer overflow"<<" [VERY RISKY]" << CURRENT_TREE); } } }
/** ========================================================================= */ static inline int is_my_lid_port(struct oib_port *port, uint32_t lid) { int rc; int err = 0; unsigned last_lid; if ((err = oib_lock_sem(&port->umad_port_cache_lock)) != 0) { OUTPUT_ERROR("Cannot check LID information, failed to acquire lock (err: %d)\n", err); return 0; } last_lid = port->umad_port_cache.base_lid + (1<<port->umad_port_cache.lmc)-1; if (lid >= port->umad_port_cache.base_lid && lid <= last_lid) rc = 1; else rc = 0; oib_unlock_sem(&port->umad_port_cache_lock); return rc; }