1 #define MYBINARYNAME "model"
2 #define MYLIBRARYNAME "libmodel.so"
3 #define MYALLOCNAME "libmymemory.so"
4 #define PROCNAME "/proc/*/maps"
7 #include "snapshot-interface.h"
11 #include <sys/types.h>
13 typedef std::basic_stringstream< char, std::char_traits< char >, MyAlloc< char > > MyStringStream;
14 std::vector< MyString, MyAlloc< MyString> > splitString( MyString input, char delim ){
15 std::vector< MyString, MyAlloc< MyString > > splits;
16 MyStringStream ss( input );
18 while( std::getline( ss, item, delim ) ){
19 splits.push_back( item );
24 bool checkPermissions( MyString permStr ){
25 return permStr.find("w") != MyString::npos;
27 std::vector< std::pair< void *, size_t >, MyAlloc< std::pair< void *, size_t > > > snapshot_utils::ReturnGlobalSegmentsToSnapshot(){
28 std::vector< std::pair< void *, size_t >, MyAlloc< std::pair< void *, size_t > > > theVec;
29 MyString fn = PROCNAME;
30 static char sProcessSize[ 12 ] = { 0 };
31 std::pair< const char *, bool > dataSect[ 3 ];
32 dataSect[ 0 ] = std::make_pair( MYBINARYNAME, false );
33 dataSect[ 1 ] = std::make_pair( MYLIBRARYNAME, false );
34 dataSect[ 2 ] = std::make_pair( MYALLOCNAME, false );
35 static pid_t sProcID = 0;
38 sprintf( sProcessSize, "%d", sProcID );
40 fn.replace( REPLACEPOS, 1, sProcessSize );
41 std::ifstream procName( fn.c_str() );
42 if( procName.is_open() ){
44 while( procName.good() ){
45 getline( procName, line );
47 for( i = 0; i < 3; ++i ){
48 if( MyString::npos != line.find( dataSect[ i ].first ) ) break;
50 if( i >= 3 || dataSect[ i ].second == true ) continue;
51 dataSect[ i ].second = true;
52 if( !procName.good() )return theVec;
53 getline( procName, line );
54 std::vector< MyString, MyAlloc< MyString > > firstSplit = splitString( line, ' ' );
55 if( !checkPermissions( firstSplit[ 1 ] ) ) continue;
56 std::vector< MyString, MyAlloc< MyString > > secondSplit = splitString( firstSplit[ 0 ], '-' );
57 size_t val1 = 0, val2 = 0;
58 sscanf( secondSplit[ 0 ].c_str(), "%zx", &val1 );
59 sscanf( secondSplit[ 1 ].c_str(), "%zx", &val2 );
60 size_t len = ( val2 - val1 ) / PAGESIZE;
61 theVec.push_back( std::make_pair( ( void * ) val1, len ) );