root/processinfo.h
/* [<][>][^][v][top][bottom][index][help] */
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 DMTCP. *
6 * *
7 * DMTCP 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 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 PROCESS_INFO_H
23 #define PROCESS_INFO_H
24
25 #include <sys/types.h>
26 #include "uniquepid.h"
27 #include "../jalib/jalloc.h"
28
29 #define MB 1024*1024
30 #define RESTORE_STACK_SIZE 5*MB
31 #define RESTORE_MEM_SIZE 5*MB
32 #define RESTORE_TOTAL_SIZE (RESTORE_STACK_SIZE+RESTORE_MEM_SIZE)
33
34 namespace dmtcp
35 {
36 class ProcessInfo
37 {
38 public:
39 enum ElfType {
40 Elf_32,
41 Elf_64
42 };
43
44 #ifdef JALIB_ALLOCATOR
45 static void* operator new(size_t nbytes, void* p) { return p; }
46 static void* operator new(size_t nbytes) { JALLOC_HELPER_NEW(nbytes); }
47 static void operator delete(void* p) { JALLOC_HELPER_DELETE(p); }
48 #endif
49 ProcessInfo();
50 static ProcessInfo& instance();
51 void init();
52 void postExec();
53 void resetOnFork();
54 void restart();
55 void postRestartRefill();
56 void restoreProcessGroupInfo();
57 void restoreHeap();
58 void growStack();
59
60 void insertChild (pid_t virtualPid, UniquePid uniquePid);
61 void eraseChild (pid_t virtualPid);
62
63 bool beginPthreadJoin(pthread_t thread);
64 void endPthreadJoin(pthread_t thread);
65 void clearPthreadJoinState(pthread_t thread);
66
67 void refresh();
68 void refreshChildTable();
69 void setRootOfProcessTree() { _isRootOfProcessTree = true; }
70 bool isRootOfProcessTree() const { return _isRootOfProcessTree; }
71
72 void serialize ( jalib::JBinarySerializer& o );
73
74 UniquePid compGroup() { return _compGroup; }
75 void compGroup(UniquePid cg) { _compGroup = cg; }
76 uint32_t numPeers() { return _numPeers; }
77 void numPeers(uint32_t np) { _numPeers = np; }
78 bool noCoordinator() { return _noCoordinator; }
79 void noCoordinator(bool nc) { _noCoordinator = nc; }
80 pid_t pid() const { return _pid; }
81 pid_t sid() const { return _sid; }
82 uint32_t get_generation() { return _generation; }
83 void set_generation(uint32_t generation) { _generation = generation; }
84
85 size_t argvSize() { return _argvSize; }
86 void argvSize(int size) { _argvSize = size; }
87 size_t envSize() { return _envSize; }
88 void envSize(int size) { _envSize = size; }
89
90 const string& procname() const { return _procname; }
91 const string& procSelfExe() const { return _procSelfExe; }
92 const string& hostname() const { return _hostname; }
93 const UniquePid& upid() const { return _upid; }
94 const UniquePid& uppid() const { return _uppid; }
95
96 bool isOrphan() const { return _ppid == 1; }
97 bool isSessionLeader() const { return _pid == _sid; }
98 bool isGroupLeader() const { return _pid == _gid; }
99 bool isForegroundProcess() const { return _gid == _fgid; }
100 bool isChild(const UniquePid& upid);
101
102 int elfType() const { return _elfType; }
103 uint64_t savedBrk(void) const { return _savedBrk;}
104 uint64_t restoreBufAddr(void) const { return _restoreBufAddr;}
105 uint64_t restoreBufLen(void) const { return RESTORE_TOTAL_SIZE;}
106
107 uint64_t vdsoStart(void) const { return _vdsoStart;}
108 uint64_t vdsoEnd(void) const { return _vdsoEnd;}
109 uint64_t vvarStart(void) const { return _vvarStart;}
110 uint64_t vvarEnd(void) const { return _vvarEnd;}
111
112 string getCkptFilename() const { return _ckptFileName; }
113 string getCkptFilesSubDir() const { return _ckptFilesSubDir; }
114 string getCkptDir() const { return _ckptDir; }
115 void setCkptDir(const char*);
116 void setCkptFilename(const char*);
117 void updateCkptDirFileSubdir(string newCkptDir = "");
118
119 private:
120 map<pid_t, UniquePid> _childTable;
121 map<pthread_t, pthread_t> _pthreadJoinId;
122 map<pid_t, pid_t> _sessionIds;
123 typedef map<pid_t, UniquePid>::iterator iterator;
124
125 uint32_t _isRootOfProcessTree;
126 pid_t _pid;
127 pid_t _ppid;
128 pid_t _sid;
129 pid_t _gid;
130 pid_t _fgid;
131
132 uint32_t _numPeers;
133 uint32_t _noCoordinator;
134 uint32_t _generation;
135 // _generation, above, is per-process. This constrasts with
136 // _computation_generation, which is shared among all processes on a host.
137 // _computation_generation is updated in shareddata.cpp by:
138 // sharedDataHeader->compId._computation_generation = generation;
139 // _generation is updated later when this process begins its checkpoint.
140 uint32_t _argvSize;
141 uint32_t _envSize;
142 uint32_t _elfType;
143
144 string _procname;
145 string _procSelfExe;
146 string _hostname;
147 string _launchCWD;
148 string _ckptCWD;
149
150 string _ckptDir;
151 string _ckptFileName;
152 string _ckptFilesSubDir;
153
154 UniquePid _upid;
155 UniquePid _uppid;
156 UniquePid _compGroup;
157
158 uint64_t _restoreBufAddr;
159 uint64_t _restoreBufLen;
160
161 uint64_t _savedHeapStart;
162 uint64_t _savedBrk;
163
164 uint64_t _vdsoStart;
165 uint64_t _vdsoEnd;
166 uint64_t _vvarStart;
167 uint64_t _vvarEnd;
168 };
169
170 }
171 #endif /* PROCESS_INFO */