Home | History | Annotate | Download | only in corkscrew
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /* Process memory map. */
     18 
     19 #ifndef _CORKSCREW_MAP_INFO_H
     20 #define _CORKSCREW_MAP_INFO_H
     21 
     22 #include <sys/types.h>
     23 #include <stdbool.h>
     24 #include <stdint.h>
     25 
     26 #ifdef __cplusplus
     27 extern "C" {
     28 #endif
     29 
     30 typedef struct map_info {
     31     struct map_info* next;
     32     uintptr_t start;
     33     uintptr_t end;
     34     bool is_readable;
     35     bool is_writable;
     36     bool is_executable;
     37     void* data; // arbitrary data associated with the map by the user, initially NULL
     38     char name[];
     39 } map_info_t;
     40 
     41 /* Loads memory map from /proc/<tid>/maps. */
     42 map_info_t* load_map_info_list(pid_t tid);
     43 
     44 /* Frees memory map. */
     45 void free_map_info_list(map_info_t* milist);
     46 
     47 /* Finds the memory map that contains the specified address. */
     48 const map_info_t* find_map_info(const map_info_t* milist, uintptr_t addr);
     49 
     50 /* Returns true if the addr is in a readable map. */
     51 bool is_readable_map(const map_info_t* milist, uintptr_t addr);
     52 /* Returns true if the addr is in a writable map. */
     53 bool is_writable_map(const map_info_t* milist, uintptr_t addr);
     54 /* Returns true if the addr is in an executable map. */
     55 bool is_executable_map(const map_info_t* milist, uintptr_t addr);
     56 
     57 /* Acquires a reference to the memory map for this process.
     58  * The result is cached and refreshed automatically.
     59  * Make sure to release the map info when done. */
     60 map_info_t* acquire_my_map_info_list();
     61 
     62 /* Releases a reference to the map info for this process that was
     63  * previous acquired using acquire_my_map_info_list(). */
     64 void release_my_map_info_list(map_info_t* milist);
     65 
     66 /* Flushes the cached memory map so the next call to
     67  * acquire_my_map_info_list() gets fresh data. */
     68 void flush_my_map_info_list();
     69 
     70 #ifdef __cplusplus
     71 }
     72 #endif
     73 
     74 #endif // _CORKSCREW_MAP_INFO_H
     75