Home | History | Annotate | Download | only in liblegacy
      1 /**
      2  * @file opd_mapping.h
      3  * Management of process mappings
      4  *
      5  * @remark Copyright 2002 OProfile authors
      6  * @remark Read the file COPYING
      7  *
      8  * @author John Levon
      9  * @author Philippe Elie
     10  */
     11 
     12 #ifndef OPD_MAPPING_H
     13 #define OPD_MAPPING_H
     14 
     15 #include "op_list.h"
     16 
     17 struct opd_image;
     18 struct opd_proc;
     19 struct op_note;
     20 
     21 /**
     22  * represent a mmap'ed area, we create such area only for vma area with exec
     23  * access right
     24  */
     25 struct opd_map {
     26 	/** next mapping for this image */
     27 	struct list_head next;
     28 	/** owning image */
     29 	struct opd_image * image;
     30 	/** mapping start vma */
     31 	unsigned long start;
     32 	/** mapping offset */
     33 	unsigned long offset;
     34 	/** mapping end vma */
     35 	unsigned long end;
     36 };
     37 
     38 /**
     39  * opd_init_hash_map - initialise the hashmap
     40  */
     41 void opd_init_hash_map(void);
     42 
     43 /**
     44  * op_cleanup_hash_name
     45  *
     46  * release resource owned by hash_name array
     47  */
     48 void opd_cleanup_hash_name(void);
     49 
     50 /**
     51  * opd_handle_mapping - deal with mapping notification
     52  * @param note  mapping notification
     53  *
     54  * Deal with one notification that a process has mapped
     55  * in a new executable file. The mapping information is
     56  * added to the process structure.
     57  */
     58 void opd_handle_mapping(struct op_note const * note);
     59 
     60 /**
     61  * opd_put_mapping - add a mapping to a process
     62  * @param proc  process to add map to
     63  * @param image  mapped image pointer
     64  * @param start  start of mapping
     65  * @param offset  file offset of mapping
     66  * @param end  end of mapping
     67  *
     68  * Add the mapping specified to the process proc growing the maps array
     69  * if necessary.
     70  */
     71 void opd_add_mapping(struct opd_proc * proc, struct opd_image * image,
     72 		unsigned long start, unsigned long offset, unsigned long end);
     73 
     74 /**
     75  * opd_kill_maps - delete mapping information for a process
     76  * @param proc  process to work on
     77  *
     78  * Frees structures holding mapping information
     79  */
     80 void opd_kill_maps(struct opd_proc * proc);
     81 
     82 /**
     83  * opd_is_in_map - check whether an EIP is within a mapping
     84  * @param map  map to check
     85  * @param eip  EIP value
     86  *
     87  * Return %1 if the EIP value @eip is within the boundaries
     88  * of the map @map, %0 otherwise.
     89  */
     90 inline static int opd_is_in_map(struct opd_map * map, unsigned long eip)
     91 {
     92 	return (eip >= map->start && eip < map->end);
     93 }
     94 
     95 
     96 /*
     97  * opd_map_offset - return offset of sample against map
     98  * @param map  map to use
     99  * @param eip  EIP value to use
    100  *
    101  * Returns the offset of the EIP value @eip into
    102  * the map @map, which is the same as the file offset
    103  * for the relevant binary image.
    104  */
    105 inline static unsigned long opd_map_offset(struct opd_map * map,
    106 					   unsigned long eip)
    107 {
    108 	return (eip - map->start) + map->offset;
    109 }
    110 
    111 #endif /* OPD_MAPPING_H */
    112