summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/corkscrew/map_info.h4
-rw-r--r--libcorkscrew/map_info.c20
-rw-r--r--libcorkscrew/test.cpp5
3 files changed, 25 insertions, 4 deletions
diff --git a/include/corkscrew/map_info.h b/include/corkscrew/map_info.h
index c9b241d..14bfad6 100644
--- a/include/corkscrew/map_info.h
+++ b/include/corkscrew/map_info.h
@@ -63,6 +63,10 @@ map_info_t* acquire_my_map_info_list();
* previous acquired using acquire_my_map_info_list(). */
void release_my_map_info_list(map_info_t* milist);
+/* Flushes the cached memory map so the next call to
+ * acquire_my_map_info_list() gets fresh data. */
+void flush_my_map_info_list();
+
#ifdef __cplusplus
}
#endif
diff --git a/libcorkscrew/map_info.c b/libcorkscrew/map_info.c
index 00e901e..93dffbf 100644
--- a/libcorkscrew/map_info.c
+++ b/libcorkscrew/map_info.c
@@ -83,7 +83,7 @@ map_info_t* load_map_info_list(pid_t pid) {
milist = mi;
}
}
- fclose(fp);
+ pclose(fp);
return milist;
}
@@ -220,7 +220,7 @@ map_info_t* acquire_my_map_info_list() {
pthread_mutex_lock(&g_my_map_info_list_mutex);
int64_t time = now_ns();
- if (g_my_map_info_list) {
+ if (g_my_map_info_list != NULL) {
my_map_info_data_t* data = (my_map_info_data_t*)g_my_map_info_list->data;
int64_t age = time - data->timestamp;
if (age >= MAX_CACHE_AGE) {
@@ -232,10 +232,10 @@ map_info_t* acquire_my_map_info_list() {
}
}
- if (!g_my_map_info_list) {
+ if (g_my_map_info_list == NULL) {
my_map_info_data_t* data = (my_map_info_data_t*)malloc(sizeof(my_map_info_data_t));
g_my_map_info_list = load_map_info_list(getpid());
- if (g_my_map_info_list) {
+ if (g_my_map_info_list != NULL) {
ALOGV("Loaded my_map_info_list %p.", g_my_map_info_list);
g_my_map_info_list->data = data;
data->refs = 1;
@@ -265,3 +265,15 @@ void release_my_map_info_list(map_info_t* milist) {
pthread_mutex_unlock(&g_my_map_info_list_mutex);
}
}
+
+void flush_my_map_info_list() {
+ pthread_mutex_lock(&g_my_map_info_list_mutex);
+
+ if (g_my_map_info_list != NULL) {
+ my_map_info_data_t* data = (my_map_info_data_t*) g_my_map_info_list->data;
+ dec_ref(g_my_map_info_list, data);
+ g_my_map_info_list = NULL;
+ }
+
+ pthread_mutex_unlock(&g_my_map_info_list_mutex);
+}
diff --git a/libcorkscrew/test.cpp b/libcorkscrew/test.cpp
index 6f7be3b..22dfa7d 100644
--- a/libcorkscrew/test.cpp
+++ b/libcorkscrew/test.cpp
@@ -66,6 +66,11 @@ extern "C" __attribute__ ((noinline)) int f() {
}
int main() {
+ flush_my_map_info_list();
f();
+
+ flush_my_map_info_list();
+ f();
+
return 0;
}