1 /****************************************************************************
2 * Copyright (C) 2006-2008 by Jason Ansel, Kapil Arya, and Gene Cooperman *
3 * jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu *
4 * *
5 * This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src). *
6 * *
7 * DMTCP:dmtcp/src is free software: you can redistribute it and/or *
8 * modify it under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * DMTCP:dmtcp/src is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with DMTCP:dmtcp/src. If not, see *
19 * <http://www.gnu.org/licenses/>. *
20 ****************************************************************************/
21
22 #ifndef VIRTUAL_PID_TABLE_H
23 #define VIRTUAL_PID_TABLE_H
24
25 #include "dmtcpalloc.h"
26 #include <sys/types.h>
27 #include <unistd.h>
28 #include <sys/time.h>
29 #include <time.h>
30 #include <iostream>
31 #include <map>
32 #include "../jalib/jserialize.h"
33 #include "../jalib/jalloc.h"
34 #include "uniquepid.h"
35 #include "constants.h"
36
37 #ifdef PID_VIRTUALIZATION
38 # define CURRENT_TO_ORIGINAL_PID(pid) \
39 dmtcp::VirtualPidTable::instance().currentToOriginalPid(pid)
40 # define ORIGINAL_TO_CURRENT_PID(pid) \
41 dmtcp::VirtualPidTable::instance().originalToCurrentPid(pid)
42 #else
43 # define CURRENT_TO_ORIGINAL_PID(pid) (pid)
44 # define ORIGINAL_TO_CURRENT_PID(pid) (pid)
45 #endif
46
47 #ifdef PID_VIRTUALIZATION
48 namespace dmtcp
49 {
50 /* Shall we create seperate classes for holding original to current pid map
51 * and for holding child process ids?
52 */
53
54 class VirtualPidTable
55 {
56 public:
57 #ifdef JALIB_ALLOCATOR
58 static void* operator new(size_t nbytes, void* p) { return p; }
59 static void* operator new(size_t nbytes) { JALLOC_HELPER_NEW(nbytes); }
60 static void operator delete(void* p) { JALLOC_HELPER_DELETE(p); }
61 #endif
62 VirtualPidTable();
63 static VirtualPidTable& instance();
64 static bool isConflictingPid( pid_t pid );
65 void postRestart();
66 void restoreProcessGroupInfo();
67 void preCheckpoint();
68
69 pid_t originalToCurrentPid( pid_t originalPid );
70 pid_t currentToOriginalPid( pid_t currentPid );
71
72 void printPidMaps();
73
74 void insert(pid_t originalPid, dmtcp::UniquePid uniquePid);
75 void insertTid(pid_t tid);
76 void insertInferior(pid_t tid);
77 //void insertTid(pid_t tid) { _tids.pushback(tid); }
78
79 void erase(pid_t originalPid);
80 void eraseTid(pid_t tid);
81 void eraseInferior(pid_t tid);
82
83 void postExec();
84
85 void refresh();
86 void refreshChildTable();
87 void refreshTidVector();
88
89 void serialize ( jalib::JBinarySerializer& o );
90 void serializeChildTable ( jalib::JBinarySerializer& o );
91 static void serializeChildTableEntry ( jalib::JBinarySerializer& o,
92 pid_t& originalPid,
93 dmtcp::UniquePid& uniquePid );
94 void serializePidMap ( jalib::JBinarySerializer& o );
95 static void serializePidMapEntry ( jalib::JBinarySerializer& o,
96 pid_t& originalPid,
97 pid_t& currentPid );
98 static void serializeEntryCount( jalib::JBinarySerializer& o,
99 size_t& count );
100 static void InsertIntoPidMapFile( pid_t originalPid, pid_t currentPid);
101 void readPidMapsFromFile();
102
103
104 void setRootOfProcessTree() { _isRootOfProcessTree = true; }
105 bool isRootOfProcessTree() const { return _isRootOfProcessTree; }
106 void updateRootOfProcessTree();
107
108 dmtcp::vector< pid_t > getPidVector();
109 dmtcp::vector< pid_t > getChildPidVector();
110 dmtcp::vector< pid_t > getTidVector();
111 dmtcp::vector< pid_t > getInferiorVector();
112
113 bool pidExists( pid_t pid );
114
115 typedef dmtcp::map< pid_t , dmtcp::UniquePid >::iterator iterator;
116 iterator begin() { return _childTable.begin(); }
117 iterator end() { return _childTable.end(); }
118
119 pid_t pid() const { return _pid; }
120 pid_t ppid() const { return _ppid; }
121 pid_t sid() const { return _sid; }
122 pid_t gid() const { return _gid; }
123 pid_t fgid() const { return _fgid; }
124
125 void setppid( pid_t ppid ) { _ppid = ppid; }
126 void setsid( pid_t sid ) { _sid = sid; }
127 void setgid( pid_t gid ) { _gid = gid; }
128 void setfgid( pid_t fgid ) { _fgid = fgid; }
129
130 void updateMapping (pid_t originalPid, pid_t currentPid);
131
132 void resetOnFork();
133
134 protected:
135
136 private:
137 dmtcp::map< pid_t , dmtcp::UniquePid > _childTable;
138 dmtcp::vector< pid_t > _inferiorVector;
139 dmtcp::vector< pid_t > _tidVector;
140
141 typedef dmtcp::map< pid_t , pid_t >::iterator pid_iterator;
142 dmtcp::map< pid_t , pid_t > _pidMapTable;
143
144 //dmtcp::vector< pid_t > _tids;
145 //typedef dmtcp::vector< pid_t >::iterator tid_iterator;
146
147 bool _isRootOfProcessTree;
148 pid_t _pid;
149 pid_t _ppid;
150 pid_t _sid;
151 pid_t _gid;
|
Event member_decl: |
Class member declaration for _fgid. |
| Also see events: |
[uninit_member] |
152 pid_t _fgid;
153 };
154
155 }
156
157 #endif /* PID_VIRTUALIZATION */
158 #endif