278{
279 char *
file =
"/proc/self/map";
280 char *resolve_pattern = "/proc/self/path/%s";
281
282 char lastobject[PRMAPSZ];
285
286 prmap_t mapping;
287
288 int fd,
count = 0,
total = 0, position = -1, first = 1;
289 vptr_t t_min, t_max, d_min, d_max;
290
292
293#ifdef DEBUG
294 SUBDBG(
"ENTERING FUNCTION >>%s<< at %s:%d\n", __func__, __FILE__,
295 __LINE__ );
296#endif
297
299
300 if ( fd == -1 ) {
302 }
303
304 memset( lastobject, 0, PRMAPSZ );
305
306#ifdef DEBUG
307 SUBDBG(
" -> %s: Preprocessing memory maps from procfs\n", __func__ );
308#endif
309
310
311
312 while (
read( fd, &mapping,
sizeof ( prmap_t ) ) > 0 ) {
313#ifdef DEBUG
314 SUBDBG(
" -> %s: Found a new memory map entry\n", __func__ );
315#endif
316
318
319
320 if ( mapping.pr_mflags & ( MA_READ | MA_WRITE | MA_EXEC ) &&
321 !( mapping.pr_mflags & MA_ANON ) ) {
322
323
324 if ( strcmp( lastobject, mapping.pr_mapname ) != 0 ) {
325 strncpy( lastobject, mapping.pr_mapname, PRMAPSZ );
327
328#ifdef DEBUG
329 SUBDBG(
" -> %s: Memory mapping entry valid for %s\n", __func__,
330 mapping.pr_mapname );
331#endif
332 }
333 }
334 }
335#ifdef DEBUG
336 SUBDBG(
" -> %s: Preprocessing done, starting to analyze\n", __func__ );
337#endif
338
339
340
341 if (
lseek( fd, 0, SEEK_SET ) == -1 ) {
343 }
344
345 memset( lastobject, 0, PRMAPSZ );
346
347
348 pam =
351
352 while (
read( fd, &mapping,
sizeof ( prmap_t ) ) > 0 ) {
353
354 if ( mapping.pr_mflags & MA_ANON ) {
355#ifdef DEBUG
357 ( " -> %s: Anonymous mapping (MA_ANON) found for %s, skipping\n",
358 __func__, mapping.pr_mapname );
359#endif
360 continue;
361 }
362
363
364 if ( strcmp( mapping.pr_mapname, lastobject ) != 0 ) {
365#ifdef DEBUG
366 SUBDBG(
" -> %s: Analyzing mapping for %s\n", __func__,
367 mapping.pr_mapname );
368#endif
369 cur = &( pam[++position] );
370 strncpy( lastobject, mapping.pr_mapname, PRMAPSZ );
375#ifdef DEBUG
376 SUBDBG(
" -> %s: Resolved name for %s: %s\n", __func__,
377 mapping.pr_mapname, cur->
name );
378#endif
379 }
380
381 if ( mapping.pr_mflags & MA_READ ) {
382
383 if ( mapping.pr_mflags & MA_WRITE ) {
386 (
vptr_t ) ( mapping.pr_vaddr + mapping.pr_size );
387
388 if ( strcmp
395 }
396
397 if ( first )
399 if ( first )
401
404 }
405
408 }
409 } else if ( mapping.pr_mflags & MA_EXEC ) {
412 (
vptr_t ) ( mapping.pr_vaddr + mapping.pr_size );
413
414 if ( strcmp
421 }
422
423 if ( first )
425 if ( first )
427
430 }
431
434 }
435 }
436 }
437
438 first = 0;
439 }
440
442
443
444
445
446
447
448
449
450
451
452
453
454
455#ifdef DEBUG
456 SUBDBG(
" -> %s: Analysis of memory maps done, results:\n", __func__ );
457 SUBDBG(
" -> %s: text_start=%#x, text_end=%#x, text_size=%lld\n", __func__,
462 SUBDBG(
" -> %s: data_start=%#x, data_end=%#x, data_size=%lld\n", __func__,
467#endif
468
469
472
473#ifdef DEBUG
474 SUBDBG(
"LEAVING FUNCTION >>%s<< at %s:%d\n", __func__, __FILE__,
475 __LINE__ );
476#endif
477
479}
off_t lseek(int fd, off_t offset, int whence)
#define papi_calloc(a, b)
get the executable's address space info
PAPI_shlib_info_t shlib_info