Update copyright to LGPL on all files
[dyninst.git] / dyninstAPI / src / saveSharedLibrary.h
1 /*
2  * Copyright (c) 1996-2009 Barton P. Miller
3  * 
4  * We provide the Paradyn Parallel Performance Tools (below
5  * described as "Paradyn") on an AS IS basis, and do not warrant its
6  * validity or performance.  We reserve the right to update, modify,
7  * or discontinue this software at any time.  We shall have no
8  * obligation to supply such updates or modifications or any other
9  * form of support to you.
10  * 
11  * By your use of Paradyn, you understand and agree that we (or any
12  * other person or entity with proprietary rights in Paradyn) are
13  * under no obligation to provide either maintenance services,
14  * update services, notices of latent defects, or correction of
15  * defects for Paradyn.
16  * 
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  * 
22  * This library is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * Lesser General Public License for more details.
26  * 
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31
32 #if defined(sparc_sun_solaris2_4) \
33  || defined(i386_unknown_linux2_0) \
34  || defined(x86_64_unknown_linux2_4) /* Blind duplication - Ray */
35
36
37 #include  <fcntl.h>
38 #include  <stdio.h>
39 #include  <libelf.h>
40 #include  <stdlib.h>
41 #include  <string.h>
42 #include <unistd.h>
43 #include "../../common/h/Types.h"
44
45 class sharedLibrary{
46
47         private:
48                 Address base_addr;
49                 char *pathname;
50                 
51         public:
52                 sharedLibrary(){
53                         base_addr = 0;
54                         pathname = 0;
55                 };
56
57                 sharedLibrary(Address baseAddr, char* name) : 
58                 base_addr(baseAddr){
59                         pathname = new char[strlen(name)+1];
60                         strcpy(pathname, name);
61                 } ;
62         
63                 ~sharedLibrary(){
64                         if(pathname){
65                                 delete [] pathname;
66                         }
67                 }
68         
69                 char* getpathname(){
70                         return pathname;
71                 }
72
73                 Address getbase_addr(){
74                         return base_addr;
75                 }
76
77                 void setpathname(const char *name){
78                         if(pathname){
79                                 free(pathname);
80                         }
81                         pathname = new char[strlen(name)+1];
82                         strcpy(pathname, name);
83
84                 }
85
86                 void setbase_addr(Address baseAddr){
87                         base_addr = baseAddr;
88                 }       
89 };
90
91
92 class saveSharedLibrary {
93
94
95         private:
96
97                 sharedLibrary soObject;
98                 char* newpathname;
99                 //Elf *oldElf;
100                 Elf *newElf;
101                 int /*oldfd, */ newfd;
102                 Address textSize;
103                 Address textAddr;
104                 Elf_Data* textData;
105
106                 bool openElf();
107                 void copyElf();
108                 void closeElf();        
109                 bool readNewLib();
110
111                 char *newShstrtabData_d_buf;
112         public:
113                 saveSharedLibrary(sharedLibrary sharedLib, char* newname=NULL);
114
115                 saveSharedLibrary(Address baseAddr, const char* oldname,
116                                         char* newname);
117                 saveSharedLibrary(); 
118
119                 ~saveSharedLibrary();
120
121                 void setnewname(char *newname);
122
123                 void openBothLibraries();
124                 void closeOriginalLibrary();
125
126                 void getTextInfo(Address &textScnAddr, Address &textScnSize);
127                 void closeNewLibrary();
128                 void saveMutations(char *textInsn);
129
130                 //char* getTextSection();
131 };
132
133 #endif
134
135