pthread_mutex_unlock(&maps_lock);
}
+/* TODO refactor this function to alloc map_inst_list_set and copy it frm src*/
// WARNING! this function use maps_set and set it to NULL
// so first param must be malloced and do not free maps_set after call
int set_map_inst_list(char **maps_set, uint32_t maps_count)
}
map_inst_list = real_malloc(sizeof(*map_inst_list) * maps_count);
- if (maps_set != NULL && *maps_set != NULL)
+ if (maps_count != 0 && map_inst_list == NULL) {
+ PRINTERR("Cannot allocate data for map_inst_list\n");
+ res = -1;
+ goto unlock_exit;
+ }
+
+ if (maps_set != NULL && *maps_set != NULL && map_inst_list != NULL) {
map_inst_list_set = *maps_set;
- map_inst_count = maps_count;
-
- /* add library mapping names */
- p = map_inst_list_set + sizeof(maps_count);
- for (i = 0; i < maps_count; i++) {
- map_inst_list[i] = p;
- p += strlen(p) + 1;
- PRINTMSG("-------> %s", map_inst_list[i]);
+ map_inst_count = maps_count;
+
+ /* add library mapping names */
+ p = map_inst_list_set + sizeof(maps_count);
+ for (i = 0; i < maps_count; i++) {
+ map_inst_list[i] = p;
+ p += strlen(p) + 1;
+ PRINTMSG("-------> %s", map_inst_list[i]);
+ }
+ } else {
+ map_inst_count = 0;
}
res = update_is_instrument_lib_attr_nolock();
if (maps_set != NULL)
*maps_set = NULL;
+unlock_exit:
maps_reader_unlock_all();
maps_writer_unlock();
return res;
}
-void maps_make()
+int maps_make()
{
+ int res = 0;
maps_writer_lock();
maps_reader_lock_all();
FILE *f = fopen("/proc/self/maps", "r");
/* add locations */
map = (*real_malloc)(sizeof(*map));
+ if (map == NULL) {
+ PRINTERR("Can not alloc data for map\n");
+ res = -1;
+ goto unlock_exit;
+ }
while (read_mapping_line(f, map)) {
if (map->permissions[2] == 'x') {
map->hash = calc_string_hash(map->filename);
update_is_instrument_lib_attr_nolock();
+unlock_exit:
maps_reader_unlock_all();
maps_writer_unlock();
+
+ return res;
}
int maps_print_maps_by_addr(const void *addr)
if (ret == -1) {
PRINTMSG("========> hz addr %p. remap", addr);
- maps_make();
+ if (maps_make() != 0) {
+ PRINTERR("maps make failed\n");
+ ret = -1;
+ goto exit;
+ }
ret = maps_is_instrument_section_by_addr_no_remap(addr);
if (ret == -1) {
print_list();
}
}
+exit:
return ret;
}
recvlen = recv(gTraceInfo.socket.daemonSock, data_buf,
log.length, MSG_WAITALL);
+ if (recvlen != log.length) {
+ PRINTERR("Can not get data from daemon sock\n");
+ goto free_data_buf;
+ }
+
if (log.type == MSG_CONFIG) {
PRINTMSG("MSG_CONFIG");
_configure(data_buf);
PRINTERR("unknown message! %d", log.type);
}
+free_data_buf:
if (data_buf != NULL)
free(data_buf);
}
recvlen = recv(gTraceInfo.socket.daemonSock, data_buf,
log.length, MSG_WAITALL);
-
+ if (recvlen != log.length) {
+ PRINTERR("Can not recv data from\n");
+ goto free_data_buf;
+ }
}
if (log.type == MSG_CAPTURE_SCREEN) {
PRINTERR("recv unknown message. id = (%d)", log.type);
}
+free_data_buf:
if (data_buf) {
free(data_buf);
data_buf = NULL;
return err;
}
-void _init_(void)
+int _init_(void)
{
+ int res = 0;
+
probeBlockStart();
/* redirect stderr and stdout.*/
getpid());
gTraceInfo.init_complete = 1;
- maps_make();
+ if (maps_make() != 0) {
+ PRINTERR("maps make failed\n");
+ res = -1;
+ goto unlock_exit;
+ }
+
+unlock_exit:
probeBlockEnd();
+ return res;
}
void __attribute__((constructor)) _init_probe()
probeBlockStart();
pClientEvent = (Ecore_X_Event_Client_Message*)pEvent;
- //This code from ecore_x
- //So I don't know what 32 does mean
- if (pClientEvent->format != 32)
- return ECORE_CALLBACK_PASS_ON;
-
if (pClientEvent != NULL) {
+
+ //This code from ecore_x
+ //So I don't know what 32 does mean
+ if (pClientEvent->format != 32) {
+ probeBlockEnd();
+ return ECORE_CALLBACK_PASS_ON;
+ }
+
if (pClientEvent->message_type ==
ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE) {
int orientation = (int)pClientEvent->data.l[1];