parseauxv.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "common/h/parseauxv.h"
00032 #include <elf.h>
00033 #include <unistd.h>
00034 #include <assert.h>
00035 #include <stdio.h>
00036 #include <sys/types.h>
00037 #include <sys/stat.h>
00038 #include <fcntl.h>
00039
00040 #include <vector>
00041
00042 std::map<int, AuxvParser *> AuxvParser::pid_to_parser;
00043
00044 AuxvParser *AuxvParser::createAuxvParser(int pid, unsigned asize)
00045 {
00046 AuxvParser *newparser = NULL;
00047 if (pid_to_parser.count(pid))
00048 {
00049 newparser = pid_to_parser[pid];
00050 }
00051 else
00052 {
00053 newparser = new AuxvParser(pid, asize);
00054 if (!newparser)
00055 {
00056 return NULL;
00057 }
00058 if (newparser->create_err)
00059 {
00060 delete newparser;
00061 return NULL;
00062 }
00063 pid_to_parser[pid] = newparser;
00064 }
00065
00066 newparser->ref_count++;
00067 return newparser;
00068 }
00069
00070 void AuxvParser::deleteAuxvParser()
00071 {
00072 assert(ref_count);
00073 ref_count--;
00074 if (!ref_count) {
00075 delete this;
00076 return;
00077 }
00078 }
00079
00080 AuxvParser::~AuxvParser()
00081 {
00082 pid_to_parser.erase(pid);
00083 }
00084
00085 AuxvParser::AuxvParser(int pid_, unsigned addr_size_) :
00086 pid(pid_),
00087 ref_count(0),
00088 interpreter_base(0x0),
00089 vsyscall_base(0x0),
00090 vsyscall_text(0x0),
00091 vsyscall_end(0x0),
00092 found_vsyscall(false),
00093 phdr(0x0),
00094 page_size(0x0),
00095 addr_size(addr_size_)
00096 {
00097 create_err = !readAuxvInfo();
00098 }
00099
00100 Address AuxvParser::getInterpreterBase()
00101 {
00102 return interpreter_base;
00103 }
00104
00105 bool AuxvParser::parsedVsyscall()
00106 {
00107 return found_vsyscall;
00108 }
00109
00110 Address AuxvParser::getVsyscallBase()
00111 {
00112 return vsyscall_base;
00113 }
00114
00115 Address AuxvParser::getVsyscallText()
00116 {
00117 return vsyscall_text;
00118 }
00119
00120 Address AuxvParser::getVsyscallEnd()
00121 {
00122 return vsyscall_end;
00123 }
00124
00125 Address AuxvParser::getProgramBase()
00126 {
00127 return phdr;
00128 }
00129
00130 Address AuxvParser::getPageSize()
00131 {
00132 return page_size;
00133 }