+
+
+static LIST_HEAD(libs);
+
+/*
+ * Returns 0 if current not found.
+ * Returns 1 if current found.
+ */
+int lib_get_iter_markers(struct marker_iter *iter)
+{
+ struct lib *iter_lib;
+ int found = 0;
+
+//ust// mutex_lock(&module_mutex);
+ list_for_each_entry(iter_lib, &libs, list) {
+ if (iter_lib < iter->lib)
+ continue;
+ else if (iter_lib > iter->lib)
+ iter->marker = NULL;
+ found = marker_get_iter_range(&iter->marker,
+ iter_lib->markers_start,
+ iter_lib->markers_start + iter_lib->markers_count);
+ if (found) {
+ iter->lib = iter_lib;
+ break;
+ }
+ }
+//ust// mutex_unlock(&module_mutex);
+ return found;
+}
+
+void lib_update_markers(void)
+{
+ struct lib *lib;
+
+//ust// mutex_lock(&module_mutex);
+ list_for_each_entry(lib, &libs, list)
+ marker_update_probe_range(lib->markers_start,
+ lib->markers_start + lib->markers_count);
+//ust// mutex_unlock(&module_mutex);
+}
+
+int marker_register_lib(struct marker *markers_start, int markers_count)
+{
+ struct lib *pl;
+
+ pl = (struct lib *) malloc(sizeof(struct lib));
+
+ pl->markers_start = markers_start;
+ pl->markers_count = markers_count;
+
+ list_add(&pl->list, &libs);
+
+ /* FIXME: update just the loaded lib */
+ lib_update_markers();
+
+ printf("just registered a markers section from %p and having %d markers\n", markers_start, markers_count);
+
+ return 0;
+}
+
+static int initialized = 0;
+
+void __attribute__((constructor)) init_markers(void)
+{
+ if(!initialized) {
+ marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));
+ printf("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers);
+ initialized = 1;
+ }
+}