/* [<][>][^][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 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 <sys/types.h>
26 #include <unistd.h>
27 #include <sys/time.h>
28 #include <time.h>
29 #include <iostream>
30 #include <map>
31 #include "../jalib/jserialize.h"
32 #include "../jalib/jalloc.h"
33 #include "dmtcpalloc.h"
34 #include "dmtcp.h"
35 #include "virtualidtable.h"
36
37 #define REAL_TO_VIRTUAL_PID(pid) \
38 dmtcp::VirtualPidTable::instance().realToVirtual(pid)
39 #define VIRTUAL_TO_REAL_PID(pid) \
40 dmtcp::VirtualPidTable::instance().virtualToReal(pid)
41
42 namespace dmtcp
43 {
44 class VirtualPidTable : public VirtualIdTable<pid_t>
45 {
46 public:
47 #ifdef JALIB_ALLOCATOR
48 static void* operator new(size_t nbytes, void* p) { return p; }
49 static void* operator new(size_t nbytes) { JALLOC_HELPER_NEW(nbytes); }
50 static void operator delete(void* p) { JALLOC_HELPER_DELETE(p); }
51 #endif
52 VirtualPidTable();
53 static VirtualPidTable& instance();
54 static pid_t getPidFromEnvVar();
55
56 virtual void postRestart();
57 virtual void resetOnFork();
58
59 void updateMapping(pid_t virtualId, pid_t realId);
60 pid_t realToVirtual(pid_t realPid);
61 pid_t virtualToReal(pid_t virtualId);
62 void refresh();
63 void writeVirtualTidToFileForPtrace(pid_t pid);
64 pid_t readVirtualTidFromFileForPtrace(pid_t realTid = -1);
65
66 pid_t getNewVirtualTid();
67
68
69 private:
70 };
71 }
72
73 #endif