198 // do the "derived class" clean-up first
199 ph->ops->release(ph);
200 destroy_lib_info(ph);
201 destroy_thread_info(ph);
202 free(ph);
203 }
204
205 lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base) {
206 return add_lib_info_fd(ph, libname, -1, base);
207 }
208
209 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd, uintptr_t base) {
210 lib_info* newlib;
211 print_debug("add_lib_info_fd %s\n", libname);
212
213 if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
214 print_debug("can't allocate memory for lib_info\n");
215 return NULL;
216 }
217
218 strncpy(newlib->name, libname, sizeof(newlib->name));
219 newlib->base = base;
220
221 if (fd == -1) {
222 if ( (newlib->fd = pathmap_open(newlib->name)) < 0) {
223 print_debug("can't open shared object %s\n", newlib->name);
224 free(newlib);
225 return NULL;
226 }
227 } else {
228 newlib->fd = fd;
229 }
230
231 #ifdef __APPLE__
232 // check whether we have got an Macho file.
233 if (is_macho_file(newlib->fd) == false) {
234 close(newlib->fd);
235 free(newlib);
236 print_debug("not a mach-o file\n");
237 return NULL;
238 }
|
198 // do the "derived class" clean-up first
199 ph->ops->release(ph);
200 destroy_lib_info(ph);
201 destroy_thread_info(ph);
202 free(ph);
203 }
204
205 lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base) {
206 return add_lib_info_fd(ph, libname, -1, base);
207 }
208
209 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd, uintptr_t base) {
210 lib_info* newlib;
211 print_debug("add_lib_info_fd %s\n", libname);
212
213 if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
214 print_debug("can't allocate memory for lib_info\n");
215 return NULL;
216 }
217
218 if (strlen(libname) >= sizeof(newlib->name)) {
219 print_debug("libname %s too long\n", libname);
220 return NULL;
221 }
222 strcpy(newlib->name, libname);
223
224 newlib->base = base;
225
226 if (fd == -1) {
227 if ( (newlib->fd = pathmap_open(newlib->name)) < 0) {
228 print_debug("can't open shared object %s\n", newlib->name);
229 free(newlib);
230 return NULL;
231 }
232 } else {
233 newlib->fd = fd;
234 }
235
236 #ifdef __APPLE__
237 // check whether we have got an Macho file.
238 if (is_macho_file(newlib->fd) == false) {
239 close(newlib->fd);
240 free(newlib);
241 print_debug("not a mach-o file\n");
242 return NULL;
243 }
|