142 void Prelease(struct ps_prochandle* ph) {
143 // do the "derived class" clean-up first
144 ph->ops->release(ph);
145 destroy_lib_info(ph);
146 destroy_thread_info(ph);
147 free(ph);
148 }
149
150 lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base) {
151 return add_lib_info_fd(ph, libname, -1, base);
152 }
153
154 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd, uintptr_t base) {
155 lib_info* newlib;
156
157 if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
158 print_debug("can't allocate memory for lib_info\n");
159 return NULL;
160 }
161
162 strncpy(newlib->name, libname, sizeof(newlib->name));
163 newlib->base = base;
164
165 if (fd == -1) {
166 if ( (newlib->fd = pathmap_open(newlib->name)) < 0) {
167 print_debug("can't open shared object %s\n", newlib->name);
168 free(newlib);
169 return NULL;
170 }
171 } else {
172 newlib->fd = fd;
173 }
174
175 // check whether we have got an ELF file. /proc/<pid>/map
176 // gives out all file mappings and not just shared objects
177 if (is_elf_file(newlib->fd) == false) {
178 close(newlib->fd);
179 free(newlib);
180 return NULL;
181 }
182
|
142 void Prelease(struct ps_prochandle* ph) {
143 // do the "derived class" clean-up first
144 ph->ops->release(ph);
145 destroy_lib_info(ph);
146 destroy_thread_info(ph);
147 free(ph);
148 }
149
150 lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base) {
151 return add_lib_info_fd(ph, libname, -1, base);
152 }
153
154 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd, uintptr_t base) {
155 lib_info* newlib;
156
157 if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
158 print_debug("can't allocate memory for lib_info\n");
159 return NULL;
160 }
161
162 if (strlen(libname) >= sizeof(newlib->name)) {
163 print_debug("libname %s too long\n", libname);
164 return NULL;
165 }
166 strcpy(newlib->name, libname);
167
168 newlib->base = base;
169
170 if (fd == -1) {
171 if ( (newlib->fd = pathmap_open(newlib->name)) < 0) {
172 print_debug("can't open shared object %s\n", newlib->name);
173 free(newlib);
174 return NULL;
175 }
176 } else {
177 newlib->fd = fd;
178 }
179
180 // check whether we have got an ELF file. /proc/<pid>/map
181 // gives out all file mappings and not just shared objects
182 if (is_elf_file(newlib->fd) == false) {
183 close(newlib->fd);
184 free(newlib);
185 return NULL;
186 }
187
|