void dmtcp::VirtualPidTable::readPidMapsFromFile() { dmtcp::string mapFile; size_t numMaps; mapFile = jalib::Filesystem::ResolveSymlink( "/proc/self/fd/" + jalib::XToString(PROTECTED_PIDMAP_FD)); JASSERT(mapFile.length() > 0) (mapFile); JTRACE("Read PidMaps from file") (mapFile); Util::lockFile(PROTECTED_PIDMAP_FD); _do_lock_tbl(); jalib::JBinarySerializeReaderRaw maprd(mapFile, PROTECTED_PIDMAP_FD); maprd.rewind(); while (!maprd.isEOF()) { maprd.serializeMap(_pidMapTable); } _do_unlock_tbl(); Util::unlockFile(PROTECTED_PIDMAP_FD); printPidMaps(); close(PROTECTED_PIDMAP_FD); unlink(mapFile.c_str()); }
dmtcp::ProcessInfo::ProcessInfo() { char buf[PATH_MAX]; _do_lock_tbl(); _pid = -1; _ppid = -1; _gid = -1; _sid = -1; _isRootOfProcessTree = false; _noCoordinator = false; _childTable.clear(); _pthreadJoinId.clear(); _procSelfExe = jalib::Filesystem::ResolveSymlink("/proc/self/exe"); _uppid = UniquePid(); JASSERT(getcwd(buf, sizeof buf) != NULL); _launchCWD = buf; #ifdef CONFIG_M32 _elfType = Elf_32; #else _elfType = Elf_64; #endif _restoreBufLen = RESTORE_TOTAL_SIZE; _restoreBufAddr = 0; _do_unlock_tbl(); }
pid_t dmtcp::VirtualPidTable::getNewVirtualTid() { pid_t tid = -1; if (_numTids == MAX_VIRTUAL_TID) { refresh(); } JASSERT(_numTids < MAX_VIRTUAL_TID) .Text("Exceeded maximum number of threads allowed"); _do_lock_tbl(); int count = 0; while (1) { tid = getpid() + _nextVirtualTid++; if (_nextVirtualTid >= MAX_VIRTUAL_TID) { _nextVirtualTid = INITIAL_VIRTUAL_TID; } pid_iterator i = _pidMapTable.find(tid); if (i == _pidMapTable.end()) { break; } if (++count == MAX_VIRTUAL_TID) { break; } } _do_unlock_tbl(); JASSERT(tid != -1) .Text("Not Reachable"); return tid; }
pid_t dmtcp::VirtualPidTable::realToVirtual(pid_t realPid) { if (realPid == -1 || realPid == 0) { return realPid; } /* This code is called from MTCP while the checkpoint thread is holding the JASSERT log lock. Therefore, don't call JTRACE/JASSERT/JINFO/etc. in this function. */ _do_lock_tbl(); for (pid_iterator i = _pidMapTable.begin(); i != _pidMapTable.end(); ++i) { if ( realPid == i->second ) { _do_unlock_tbl(); return i->first; } } if (dmtcp_is_ptracing != 0 && dmtcp_is_ptracing()) { pid_t virtualPid = readVirtualTidFromFileForPtrace(gettid()); if (virtualPid != -1) { _do_unlock_tbl(); updateMapping(virtualPid, realPid); return virtualPid; } } //JWARNING(false) (realPid) //.Text("No virtual pid/tid found for the given real pid"); _do_unlock_tbl(); return realPid; }
void dmtcp::ProcessInfo::endPthreadJoin(pthread_t thread) { _do_lock_tbl(); JASSERT(pthread_equal(_pthreadJoinId[thread], pthread_self())); _pthreadJoinId.erase(thread); _do_unlock_tbl(); }
void dmtcp::ProcessInfo::eraseChild(pid_t virtualPid) { _do_lock_tbl(); iterator i = _childTable.find(virtualPid); if (i != _childTable.end()) _childTable.erase(virtualPid); _do_unlock_tbl(); }
void dmtcp::ProcessInfo::clearPthreadJoinState(pthread_t thread) { _do_lock_tbl(); if (_pthreadJoinId.find(thread) != _pthreadJoinId.end()) { _pthreadJoinId.erase(thread); } _do_unlock_tbl(); }
void dmtcp::ProcessInfo::insertTid( pid_t tid ) { eraseTid( tid ); _do_lock_tbl(); _tidVector.push_back ( tid ); _do_unlock_tbl(); return; }
void dmtcp::ProcessInfo::endPthreadJoin(pthread_t thread) { _do_lock_tbl(); if (_pthreadJoinId.find(thread) != _pthreadJoinId.end() && pthread_equal(_pthreadJoinId[thread], pthread_self())) { _pthreadJoinId.erase(thread); } _do_unlock_tbl(); }
dmtcp::VirtualPidTable::VirtualPidTable() { _do_lock_tbl(); _pidMapTable.clear(); //_pidMapTable[getpid()] = _real_getpid(); //_pidMapTable[getppid()] = _real_getppid(); _do_unlock_tbl(); }
dmtcp::vector< pid_t > dmtcp::VirtualPidTable::getPidVector( ) { dmtcp::vector< pid_t > pidVec; _do_lock_tbl(); for ( pid_iterator i = _pidMapTable.begin(); i != _pidMapTable.end(); ++i ) pidVec.push_back ( i->first ); _do_unlock_tbl(); return pidVec; }
void dmtcp::VirtualPidTable::postRestart() { /* * PROTECTED_PIDMAP_FD corresponds to the file containg computation wide * virtualPid -> realPid map to avoid pid/tid collisions. */ _do_lock_tbl(); _pidMapTable.clear(); _pidMapTable[getpid()] = _real_getpid(); _do_unlock_tbl(); }
bool dmtcp::VirtualPidTable::pidExists( pid_t pid ) { bool retVal = false; _do_lock_tbl(); pid_iterator j = _pidMapTable.find ( pid ); if ( j != _pidMapTable.end() ) retVal = true; _do_unlock_tbl(); return retVal; }
void dmtcp::ProcessInfo::insertChild(pid_t pid, dmtcp::UniquePid uniquePid) { _do_lock_tbl(); iterator i = _childTable.find(pid); JWARNING(i == _childTable.end()) (pid) (uniquePid) (i->second) .Text("child pid already exists!"); _childTable[pid] = uniquePid; _do_unlock_tbl(); JTRACE("Creating new virtualPid -> realPid mapping.") (pid) (uniquePid); }
bool dmtcp::ProcessInfo::beginPthreadJoin(pthread_t thread) { bool res = false; _do_lock_tbl(); dmtcp::map<pthread_t, pthread_t>::iterator i = _pthreadJoinId.find(thread); if (i == _pthreadJoinId.end()) { _pthreadJoinId[thread] = pthread_self(); res = true; } _do_unlock_tbl(); return res; }
void dmtcp::ProcessInfo::postExec( ) { /// FIXME JTRACE("Post-Exec. Emptying tidVector"); _do_lock_tbl(); _tidVector.clear(); _procname = jalib::Filesystem::GetProgramName(); _upid = UniquePid::ThisProcess(); _uppid = UniquePid::ParentProcess(); _do_unlock_tbl(); }
bool dmtcp::ProcessInfo::isChild(const UniquePid& upid) { bool res = false; _do_lock_tbl(); for (iterator i = _childTable.begin(); i != _childTable.end(); i++) { if (i->second == upid) { res = true; break; } } _do_unlock_tbl(); return res; }
bool dmtcp::VirtualPidTable::realPidExists( pid_t pid ) { bool retval = false; _do_lock_tbl(); for (pid_iterator i = _pidMapTable.begin(); i != _pidMapTable.end(); ++i) { if (i->second == pid) { retval = true; break; } } _do_unlock_tbl(); return retval; }
dmtcp::ProcessInfo::ProcessInfo() { _do_lock_tbl(); _pid = -1; _ppid = -1; _gid = -1; _sid = -1; _isRootOfProcessTree = false; _childTable.clear(); _tidVector.clear(); _pthreadJoinId.clear(); _do_unlock_tbl(); }
void dmtcp::ProcessInfo::eraseTid( pid_t tid ) { _do_lock_tbl(); dmtcp::vector< pid_t >::iterator iter = _tidVector.begin(); while ( iter != _tidVector.end() ) { if ( *iter == tid ) { _tidVector.erase( iter ); break; } else ++iter; } _do_unlock_tbl(); return; }
dmtcp::ProcessInfo::ProcessInfo() { _do_lock_tbl(); _pid = -1; _ppid = -1; _gid = -1; _sid = -1; _isRootOfProcessTree = false; _noCoordinator = false; _childTable.clear(); _tidVector.clear(); _pthreadJoinId.clear(); _procSelfExe = jalib::Filesystem::ResolveSymlink("/proc/self/exe"); _do_unlock_tbl(); }
void dmtcp::VirtualPidTable::refresh() { pid_t pid = getpid(); pid_iterator i; pid_iterator next; pid_t _real_pid = _real_getpid(); _do_lock_tbl(); for (i = _pidMapTable.begin(), next = i; i != _pidMapTable.end(); i = next) { next++; if (i->second > pid && i->second <= pid + MAX_VIRTUAL_TID && _real_tgkill(_real_pid, i->second, 0) == -1) { _pidMapTable.erase(i); } } _do_unlock_tbl(); printPidMaps(); }
void dmtcp::VirtualPidTable::writePidMapsToFile() { //size_t numMaps = 0; dmtcp::string mapFile; mapFile = jalib::Filesystem::ResolveSymlink( "/proc/self/fd/" + jalib::XToString(PROTECTED_PIDMAP_FD)); JASSERT (mapFile.length() > 0) (mapFile); JTRACE ("Write PidMaps to file") (mapFile); // Lock fileset before any operations Util::lockFile(PROTECTED_PIDMAP_FD); _do_lock_tbl(); jalib::JBinarySerializeWriterRaw mapwr(mapFile, PROTECTED_PIDMAP_FD); mapwr.serializeMap(_pidMapTable); _do_unlock_tbl(); Util::unlockFile(PROTECTED_PIDMAP_FD); }
pid_t dmtcp::VirtualPidTable::virtualToReal(pid_t virtualPid) { pid_t retVal = 0; if (virtualPid == -1 || virtualPid == 0) { return virtualPid; } /* This code is called from MTCP while the checkpoint thread is holding the JASSERT log lock. Therefore, don't call JTRACE/JASSERT/JINFO/etc. in this function. */ _do_lock_tbl(); pid_iterator i = _pidMapTable.find(virtualPid < -1 ? abs(virtualPid) : virtualPid); if (i == _pidMapTable.end()) { _do_unlock_tbl(); return virtualPid; } retVal = virtualPid < -1 ? (-i->second) : i->second; _do_unlock_tbl(); return retVal; }
void dmtcp::VirtualPidTable::erase( pid_t virtualPid ) { _do_lock_tbl(); _pidMapTable.erase( virtualPid ); _do_unlock_tbl(); }
void dmtcp::VirtualPidTable::updateMapping( pid_t virtualPid, pid_t realPid ) { _do_lock_tbl(); _pidMapTable[virtualPid] = realPid; _do_unlock_tbl(); }