VOID ReallocEnter(CHAR * name, ADDRINT previousAddress, ADDRINT newSize, THREADID tid) { ThreadLocalStorage* tls = getTLS(tid); tls->nextReallocAddr = previousAddress; tls->nextReallocSize = newSize; }
void TrafficLight::setPhaseDuration(const std::string& tlsID, const double phaseDuration) { MSTrafficLightLogic* const active = getTLS(tlsID).getActive(); const SUMOTime cTime = MSNet::getInstance()->getCurrentTimeStep(); const int index = active->getCurrentPhaseIndex(); active->changeStepAndDuration(MSNet::getInstance()->getTLSControl(), cTime, index, TIME2STEPS(phaseDuration)); }
// ------------------------------------------------------------- // Function exit event // ------------------------------------------------------------- VOID PIN_FAST_ANALYSIS_CALL A_ProcessReturn(ADDRINT sp, THREADID threadid) { _STool_TThreadRec* tdata = getTLS(threadid); // roll back stack in case of longjmp AdjustStack(tdata, sp); if ( tdata->stackTop < 1 ) graceful_exit(threadid, "Internal error: stack bottomed out"); // call routine exit callback (if any was specified by the analysis tool) if (gSetup.rtnExit) gSetup.rtnExit(tdata + 1); // pop activation tdata->stackTop--; #if DEBUG printf("[TID=%u] Leaving %s\n", threadid, Target2RtnName(tdata->activationStack[tdata->stackTop].target).c_str()); #endif #if DEBUG if (tdata->stackTop > 0) printf("[TID=%u] Back to %s - # activations = %d - stack size = %d\n", threadid, Target2RtnName(tdata->activationStack[tdata->stackTop-1].target).c_str(), tdata->stackTop, tdata->stackSize); else printf("[TID=%u] Back to stack bottom\n", threadid); #endif }
void TrafficLight::setProgram(const std::string& tlsID, const std::string& programID) { try { getTLS(tlsID).switchTo(MSNet::getInstance()->getTLSControl(), programID); } catch (ProcessError& e) { throw TraCIException(e.what()); } }
// ------------------------------------------------------------- // Buffer overflow function // ------------------------------------------------------------- VOID* BufferOverflow(BUFFER_ID id, THREADID tid, const CONTEXT *ctxt, VOID *buf, UINT64 numElements, VOID *v) { _STool_TThreadRec* tdata = getTLS(tid); // call user-defined trace buffer processing function gSetup.memBuf(tdata+1, static_cast<STool_TMemRec*>(tdata->buf_addr), numElements - (UINT64)(((ADDRINT)tdata->buf_addr - (ADDRINT)buf) / sizeof(STool_TMemRec))); tdata->buf_addr = buf; return buf; }
void WinDisplay::releaseAll(){ TlsData * tls = getTLS(); for(std::map<int,DisplayInfo>::iterator it = tls->m_map.begin(); it != tls->m_map.end();it++){ if((*it).second.hwnd){ DestroyWindow((*it).second.hwnd); } DeleteDC((*it).second.dc); } }
std::vector<std::string> TrafficLight::getControlledJunctions(const std::string& tlsID) { std::set<std::string> junctionIDs; const MSTrafficLightLogic::LinkVectorVector& links = getTLS(tlsID).getActive()->getLinks(); for (const MSTrafficLightLogic::LinkVector& llinks : links) { for (const MSLink* l : llinks) { junctionIDs.insert(l->getJunction()->getID()); } } return std::vector<std::string>(junctionIDs.begin(), junctionIDs.end()); }
void TrafficLight::setPhase(const std::string& tlsID, const int index) { MSTrafficLightLogic* const active = getTLS(tlsID).getActive(); if (index < 0 || active->getPhaseNumber() <= index) { throw TraCIException("The phase index " + toString(index) + " is not in the allowed range [0," + toString(active->getPhaseNumber() - 1) + "]."); } const SUMOTime cTime = MSNet::getInstance()->getCurrentTimeStep(); const SUMOTime duration = active->getPhase(index).duration; active->changeStepAndDuration(MSNet::getInstance()->getTLSControl(), cTime, index, duration); }
std::vector<std::string> TrafficLight::getControlledLanes(const std::string& tlsID) { std::vector<std::string> laneIDs; const MSTrafficLightLogic::LaneVectorVector& lanes = getTLS(tlsID).getActive()->getLaneVectors(); for (const MSTrafficLightLogic::LaneVector& llanes : lanes) { for (const MSLane* l : llanes) { laneIDs.push_back(l->getID()); } } return laneIDs; }
VOID ReallocAfter(ADDRINT mallocStartAddr, THREADID tid) { ThreadLocalStorage* tls = getTLS(tid); ADDRINT previousAddress = tls->nextReallocAddr; ADDRINT newSize = tls->nextReallocSize; //if previous address is NULL, this is the same as malloc if (previousAddress == 0) { tls->nextMallocSize = tls->nextReallocSize; tls->nextReallocAddr = 0; tls->nextReallocSize = 0; MallocAfter(mallocStartAddr, tid); return; } const MemoryArea& prevArea = findMemoryArea(mallocStartAddr); MemoryArea newArea(tid, mallocStartAddr, mallocStartAddr + newSize); ADDRINT prevSize = prevArea.to - prevArea.from; // Realloc gives the same address as previos realloc(or malloc,calloc) if (prevArea.from == mallocStartAddr) { //eger yeni yer daha kucuk ise, eskiden bizim olan aradaki yerleri free edelim if (newSize < prevSize) { freeMemoryAddress(mallocStartAddr + newSize, mallocStartAddr + prevSize, tid); } } else { if (newSize < prevSize) { moveMemoryAddresses(previousAddress, mallocStartAddr, newSize, tid); freeMemoryAddress(previousAddress + newSize, previousAddress + prevSize, tid); } else { moveMemoryAddresses(previousAddress, mallocStartAddr, prevSize, tid); freeMemoryAddress(previousAddress, previousAddress + prevSize, tid); } } GetLock(&memorySetLock, tid); memorySet.insert(newArea); memorySet.erase(prevArea); ReleaseLock(&memorySetLock); }
std::vector<std::vector<TraCILink> > TrafficLight::getControlledLinks(const std::string& tlsID) { std::vector<std::vector<TraCILink> > result; const MSTrafficLightLogic::LaneVectorVector& lanes = getTLS(tlsID).getActive()->getLaneVectors(); const MSTrafficLightLogic::LinkVectorVector& links = getTLS(tlsID).getActive()->getLinks(); for (int i = 0; i < (int)lanes.size(); ++i) { std::vector<TraCILink> subList; const MSTrafficLightLogic::LaneVector& llanes = lanes[i]; const MSTrafficLightLogic::LinkVector& llinks = links[i]; // number of links controlled by this signal (signal i) for (int j = 0; j < (int)llanes.size(); ++j) { MSLink* link = llinks[j]; // approached non-internal lane (if any) const std::string to = link->getLane() != nullptr ? link->getLane()->getID() : ""; // approached "via", internal lane (if any) const std::string via = link->getViaLane() != nullptr ? link->getViaLane()->getID() : ""; subList.emplace_back(TraCILink(llanes[j]->getID(), via, to)); } result.emplace_back(subList); } return result; }
// ------------------------------------------------------------- // Function direct call event (with calling site info) // ------------------------------------------------------------- VOID PIN_FAST_ANALYSIS_CALL A_ProcessDirectCallCSBuf(ADDRINT ip, ADDRINT target, ADDRINT sp, THREADID threadid, CONTEXT *ctxt) { // get thread local data _STool_TThreadRec* tdata = getTLS(threadid); // roll back stack in case of longjmp AdjustStackBuf(tdata, sp, ctxt); // possibly expand stack if (tdata->stackTop >= tdata->stackMaxSize) { // double stack size tdata->stackMaxSize <<= 1; // expand activation stack tdata->activationStack = (_STool_TActivationRec*)realloc(tdata->activationStack, tdata->stackMaxSize*sizeof(_STool_TActivationRec)); if (tdata->activationStack == NULL) graceful_exit(threadid, "Can't expand activation stack"); // expand user stack (if any is needed) if (tdata->userStack) { tdata->userStack = (char*)realloc(tdata->userStack, tdata->stackMaxSize*gSetup.activationRecSize); if (tdata->userStack == NULL) graceful_exit(threadid, "Can't expand user stack"); } } // push current activation record to stack _ActivationAt(tdata, tdata->stackTop).currentSP = sp; _ActivationAt(tdata, tdata->stackTop).target = target; // increase activations counter tdata->stackTop++; #if DEBUG printf("[TID=%u] Entering %s - # activations = %d - stack size = %d\n", threadid, Target2RtnName(target).c_str(), tdata->stackTop, tdata->stackSize); #endif // call routine enter callback (if any was specified by the analysis tool) if (gSetup.rtnEnter) gSetup.rtnEnter(tdata + 1, ip); }
VOID MallocAfter(ADDRINT mallocStartAddr, THREADID tid) { ThreadLocalStorage* tls = getTLS(tid); ADDRINT mallocEndAddr = tls->nextMallocSize + mallocStartAddr; tls->nextMallocSize = 0; MemoryArea newArea(tid, mallocStartAddr, mallocEndAddr); GetLock(&memorySetLock, tid); MemorySetItr overlaps = smallestOverlappingMemoryArea(newArea); if (overlaps != memorySet.end()) { // has overlapping elements } ReleaseLock(&memorySetLock); }
// ------------------------------------------------------------- // Thread end function // ------------------------------------------------------------- VOID ThreadEnd(THREADID threadid, const CONTEXT *ctxt, INT32 code, VOID *v) { // get pointer to thread local data _STool_TThreadRec* tdata = getTLS(threadid); // call thread end callback (if any was specified by the analysis tool) if (gSetup.threadEnd) gSetup.threadEnd(tdata + 1); // free shadow activation stack free(tdata->activationStack); // free user stack (if any) if (tdata->userStack) free(tdata->userStack); // free thread local data free(tdata); }
void TrafficLight::setCompleteRedYellowGreenDefinition(const std::string& tlsID, const TraCILogic& logic) { MSTLLogicControl::TLSLogicVariants& vars = getTLS(tlsID); // make sure index and phaseNo are consistent if (logic.currentPhaseIndex >= (int)logic.phases.size()) { throw TraCIException("set program: parameter index must be less than parameter phase number."); } std::vector<MSPhaseDefinition*> phases; for (TraCIPhase phase : logic.phases) { phases.push_back(new MSPhaseDefinition(TIME2STEPS(phase.duration), phase.state, TIME2STEPS(phase.minDur), TIME2STEPS(phase.maxDur), phase.next, phase.name)); } if (vars.getLogic(logic.programID) == nullptr) { MSTrafficLightLogic* mslogic = new MSSimpleTrafficLightLogic(MSNet::getInstance()->getTLSControl(), tlsID, logic.programID, TLTYPE_STATIC, phases, logic.currentPhaseIndex, 0, logic.subParameter); vars.addLogic(logic.programID, mslogic, true, true); } else { static_cast<MSSimpleTrafficLightLogic*>(vars.getLogic(logic.programID))->setPhases(phases, logic.currentPhaseIndex); } }
// ------------------------------------------------------------- // Function exit event // ------------------------------------------------------------- VOID PIN_FAST_ANALYSIS_CALL A_ProcessReturnBuf(ADDRINT sp, THREADID threadid, CONTEXT *ctxt) { _STool_TThreadRec* tdata = getTLS(threadid); // roll back stack in case of longjmp AdjustStackBuf(tdata, sp, ctxt); if ( tdata->stackTop < 1 ) graceful_exit(threadid, "Internal error: stack bottomed out"); // if using memory operations buffering, call trace buffer processing callback // and reset buffer if (gSetup.memBuf) { void * curr_buf_pointer = PIN_GetBufferPointer(ctxt, buf_id); UINT64 numElements = ((ADDRINT)curr_buf_pointer - (ADDRINT)tdata->buf_addr) / sizeof(STool_TMemRec); gSetup.memBuf(tdata+1, static_cast<STool_TMemRec*>(tdata->buf_addr), numElements); tdata->buf_addr = curr_buf_pointer; } // call routine exit callback (if any was specified by the analysis tool) if (gSetup.rtnExit) gSetup.rtnExit(tdata + 1); // pop activation tdata->stackTop--; #if DEBUG printf("[TID=%u] Leaving %s\n", threadid, Target2RtnName(tdata->activationStack[tdata->stackTop].target).c_str()); #endif #if DEBUG if (tdata->stackTop > 0) printf("[TID=%u] Back to %s - # activations = %d - stack size = %d\n", threadid, Target2RtnName(tdata->activationStack[tdata->stackTop-1].target).c_str(), tdata->stackTop, tdata->stackSize); else printf("[TID=%u] Back to stack bottom\n", threadid); #endif }
VOID CallocEnter(CHAR * name, ADDRINT nElements, ADDRINT sizeOfEachElement, THREADID tid) { ThreadLocalStorage* tls = getTLS(tid); tls->nextMallocSize = nElements * sizeOfEachElement; }
std::string TrafficLight::getParameter(const std::string& tlsID, const std::string& paramName) { return getTLS(tlsID).getActive()->getParameter(paramName, ""); }
void TrafficLight::setRedYellowGreenState(const std::string& tlsID, const std::string& state) { getTLS(tlsID).setStateInstantiatingOnline(MSNet::getInstance()->getTLSControl(), state); }
void WinDisplay::setInfo(int configurationIndex,const DisplayInfo& info){ getTLS()->m_map[configurationIndex] = info; }
bool WinDisplay::infoExists(int configurationIndex){ return getTLS()->m_map.find(configurationIndex) != getTLS()->m_map.end(); }
void TrafficLight::setPhaseName(const std::string& tlsID, const std::string& name) { MSTrafficLightLogic* const active = getTLS(tlsID).getActive(); const_cast<MSPhaseDefinition&>(active->getCurrentPhaseDef()).setName(name); }
void pixelFormatWasSet(int cfgId){getTLS()->m_map[cfgId].isPixelFormatSet = true;}
bool isPixelFormatSet(int cfgId){ return getTLS()->m_map[cfgId].isPixelFormatSet;}
HDC getDC(int configId){return getTLS()->m_map[configId].dc;}
DisplayInfo& getInfo(int configurationIndex){ return getTLS()->m_map[configurationIndex];}
double TrafficLight::getNextSwitch(const std::string& tlsID) { return STEPS2TIME(getTLS(tlsID).getActive()->getNextSwitchTime()); }
void TrafficLight::setParameter(const std::string& tlsID, const std::string& paramName, const std::string& value) { return getTLS(tlsID).getActive()->setParameter(paramName, value); }
// ------------------------------------------------------------- // Memory write event // ------------------------------------------------------------- VOID PIN_FAST_ANALYSIS_CALL A_MemWrite(THREADID threadid, ADDRINT addr) { gSetup.memWrite((_STool_TThreadRec*)getTLS(threadid)+1, addr); }
VOID MallocEnter(CHAR * name, ADDRINT size, THREADID tid) { ThreadLocalStorage* tls = getTLS(tid); tls->nextMallocSize = size; }