diff --git a/library/DFProcess-linux-base.cpp b/library/DFProcess-linux-base.cpp index 4c81222d7..92628dd1d 100644 --- a/library/DFProcess-linux-base.cpp +++ b/library/DFProcess-linux-base.cpp @@ -22,8 +22,10 @@ must not be misrepresented as being the original software. distribution. */ #include "Internal.h" +#include "PlatformInternal.h" #include +#include #include #include #include @@ -76,10 +78,43 @@ int LinuxProcessBase::getPID() return my_pid; } -//FIXME: implement +int getdir (string dir, vector &files) +{ + DIR *dp; + struct dirent *dirp; + if((dp = opendir(dir.c_str())) == NULL) { + cout << "Error(" << errno << ") opening " << dir << endl; + return errno; + } + + while ((dirp = readdir(dp)) != NULL) { + files.push_back(string(dirp->d_name)); + } + closedir(dp); + return 0; +} + bool LinuxProcessBase::getThreadIDs(vector & threads ) { - return false; + stringstream ss; + vector subdirs; + ss << "/proc/" << my_pid << "/task/"; + if(getdir(ss.str(),subdirs) != 0) + { + //FIXME: needs exceptions. this is a fatal error + cerr << "unable to enumerate threads. This is BAD!" << endl; + return false; + } + threads.clear(); + for(int i = 0; i < subdirs.size();i++) + { + uint32_t tid; + if(sscanf(subdirs[i].c_str(),"%d", &tid)) + { + threads.push_back(tid); + } + } + return true; } //FIXME: cross-reference with ELF segment entries? diff --git a/library/DFProcess-linux.cpp b/library/DFProcess-linux.cpp index cfcf2a603..235a27489 100644 --- a/library/DFProcess-linux.cpp +++ b/library/DFProcess-linux.cpp @@ -45,6 +45,7 @@ namespace { { private: uint8_t vector_start; + vector thread_ids; public: NormalProcess(uint32_t pid, VersionInfoFactory * known_versions); ~NormalProcess() @@ -128,7 +129,7 @@ struct _Rep_base { uint32_t _M_length; // length of text stored, not including zero termination uint32_t _M_capacity; // capacity, not including zero termination - uint32_t _M_refcount; // reference count (two STL strings can share a common buffer, copy on write rules apply) + int32_t _M_refcount; // reference count (two STL strings can share a common buffer, copy on write rules apply) }; size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) @@ -153,7 +154,7 @@ size_t NormalProcess::writeSTLString(const uint32_t address, const std::string w // the buffer has actual size = 1. no space for storing anything more than a zero byte if(header._M_capacity == 0) return 0; - if(header._M_refcount != 0 && header._M_refcount != 0xFFFFFFFF ) // one ref or one non-shareable ref + if(header._M_refcount > 0 ) // one ref or one non-shareable (-1) ref return 0; // get writeable length (lesser of our string length and capacity of the target) diff --git a/library/private/PlatformInternal.h b/library/private/PlatformInternal.h index f33b53e5e..4b2a3f424 100644 --- a/library/private/PlatformInternal.h +++ b/library/private/PlatformInternal.h @@ -34,6 +34,7 @@ #include #include #include + #include #include #include #else