Example #1
0
static void pre_pwrite(void *drcontext)
{
	int fd;
	struct per_thread_journal_state *jstate;
	struct journal_descriptor *jd;

	fd = (int)dr_syscall_get_param(drcontext, 0);
	if (fd != jfile_fds[0] && fd != jfile_fds[1])
		return;

	jstate = (struct per_thread_journal_state *)
		drmgr_get_tls_field(drcontext, tls_idx);

	fi_printf("writing journal\n");
	jstate->using_fd = fd;
	jstate->state = THREAD_STATE_WRITING_JFILE;

	jd = (struct journal_descriptor *)dr_syscall_get_param(drcontext, 1);
	DR_ASSERT(jd->magic == JOURNAL_DESC_MAGIC);
	if (jd->flag == JF_STORE)
		jstate->pwrite_state = PWRITE_WRITING_STORE;
	else if (jd->flag == JF_REMOVE_OBJ)
		fi_printf("FIXME: testing object removal is not supported yet");
	else
		die("unknown journal flag: %d\n", jd->flag);
}
Example #2
0
static void post_pwrite64(void *drcontext)
{
	int fd;
	struct per_thread_journal_state *jstate;

	jstate = (struct per_thread_journal_state *)
		drmgr_get_tls_field(drcontext, tls_idx);

	if (jstate->state != THREAD_STATE_WRITING_JFILE)
		return;

	fd = jstate->using_fd;
	DR_ASSERT(fd == jfile_fds[0] || fd == jfile_fds[1]);

	switch (sid) {
	case SID_DEATH_AFTER_STORE:
		if (jstate->pwrite_state != PWRITE_WRITING_STORE)
			return;

		fi_printf("scenario is death after writing normal store,"
			" exiting\n");
		exit(1);
		break;
	default:
		die("invalid SID: %d\n", sid);
		break;
	}
}
Example #3
0
static void pre_open(void *drcontext)
{
	const char *path;
	struct per_thread_journal_state *jstate;

	jstate = (struct per_thread_journal_state *)
		drmgr_get_tls_field(drcontext, tls_idx);

	path = (const char *)dr_syscall_get_param(drcontext, 0);

	if (strstr(path, "journal_file0")) {
		fi_printf("journal_file0 is opened\n");
		DR_ASSERT(jstate->state == THREAD_STATE_DEFAULT);
		jstate->state = THREAD_STATE_OPENING_JFILE_0;
	} else if (strstr(path, "journal_file1")) {
		fi_printf("journal_file1 is opened\n");
		DR_ASSERT(jstate->state == THREAD_STATE_DEFAULT);
		jstate->state = THREAD_STATE_OPENING_JFILE_1;
	}
}
Example #4
0
static void post_open(void *drcontext)
{
	int fd;
	struct per_thread_journal_state *jstate;

	jstate = (struct per_thread_journal_state *)
		drmgr_get_tls_field(drcontext, tls_idx);

	if (jstate->state == THREAD_STATE_DEFAULT)
		return;

	fd = (int)dr_syscall_get_result(drcontext);

	if (jstate->state == THREAD_STATE_OPENING_JFILE_0) {
		fi_printf("fd of jfile0: %d\n", fd);
		jfile_fds[0] = fd;
	} else if (jstate->state == THREAD_STATE_OPENING_JFILE_1) {
		fi_printf("fd of jfile1: %d\n", fd);
		jfile_fds[1] = fd;
	}

	jstate->state = THREAD_STATE_DEFAULT;
}
Example #5
0
DR_EXPORT void dr_init(client_id_t id)
{
	const char *option;

	option = dr_get_options(id);
	fi_printf("the passed option to this client: %s\n", option);
	sid = atoi(option);
	fi_printf("sid: %d\n", sid);

	init_log_file();

	dr_register_filter_syscall_event(pre_syscall_filter);
	drmgr_init();

	tls_idx = drmgr_register_tls_field();
	drmgr_register_pre_syscall_event(pre_syscall);
	drmgr_register_post_syscall_event(post_syscall);

	drmgr_register_thread_init_event(thread_init_event);
	drmgr_register_thread_exit_event(thread_exit_event);

	jfile_fds[0] = -1;
	jfile_fds[1] = -1;
}
Example #6
0
static void print_data(coda_cursor *cursor, int depth)
{
    coda_type_class type_class;
    int has_attributes;

    if (coda_cursor_has_attributes(cursor, &has_attributes) != 0)
    {
        handle_coda_error();
    }
    if (has_attributes)
    {
        if (coda_cursor_goto_attributes(cursor) != 0)
        {
            handle_coda_error();
        }
        fi_printf("{attributes}\n");
        INDENT++;
        print_data(cursor, depth);
        INDENT--;
        coda_cursor_goto_parent(cursor);
    }

    if (coda_cursor_get_type_class(cursor, &type_class) != 0)
    {
        handle_coda_error();
    }
    switch (type_class)
    {
        case coda_record_class:
            {
                long num_fields;

                if (coda_cursor_get_num_elements(cursor, &num_fields) != 0)
                {
                    handle_coda_error();
                }
                if (num_fields > 0)
                {
                    coda_type *record_type;
                    int is_union;
                    long i;

                    if (coda_cursor_get_type(cursor, &record_type) != 0)
                    {
                        handle_coda_error();
                    }

                    if (coda_type_get_record_union_status(record_type, &is_union) != 0)
                    {
                        handle_coda_error();
                    }
                    if (is_union)
                    {
                        const char *field_name;

                        if (coda_cursor_get_available_union_field_index(cursor, &i) != 0)
                        {
                            handle_coda_error();
                        }
                        if (coda_type_get_record_field_name(record_type, i, &field_name) != 0)
                        {
                            handle_coda_error();
                        }
                        if (coda_cursor_goto_record_field_by_index(cursor, i) != 0)
                        {
                            handle_coda_error();
                        }
                        fi_printf("[%s]", field_name);
                        if (print_offsets)
                        {
                            int64_t offset;

                            if (coda_cursor_get_file_bit_offset(cursor, &offset) != 0)
                            {
                                handle_coda_error();
                            }
                            if (offset >= 0)
                            {
                                char s[21];

                                coda_str64(offset >> 3, s);
                                ff_printf(":%s", s);
                                if ((offset & 0x7) != 0)
                                {
                                    ff_printf(":%d", (int)(offset & 0x7));
                                }
                            }
                        }
                        ff_printf("\n");
                        INDENT++;
                        if (max_depth < 0 || depth < max_depth)
                        {
                            print_data(cursor, depth + 1);
                        }
                        else
                        {
                            fi_printf("...\n");
                        }
                        INDENT--;
                        coda_cursor_goto_parent(cursor);
                    }
                    else
                    {
                        if (coda_cursor_goto_first_record_field(cursor) != 0)
                        {
                            handle_coda_error();
                        }
                        for (i = 0; i < num_fields; i++)
                        {
                            const char *field_name;

                            if (coda_type_get_record_field_name(record_type, i, &field_name) != 0)
                            {
                                handle_coda_error();
                            }
                            fi_printf("[%s]", field_name);
                            if (print_offsets)
                            {
                                int64_t offset;

                                if (coda_cursor_get_file_bit_offset(cursor, &offset) != 0)
                                {
                                    handle_coda_error();
                                }
                                if (offset >= 0)
                                {
                                    char s[21];

                                    coda_str64(offset >> 3, s);
                                    ff_printf(":%s", s);
                                    if ((offset & 0x7) != 0)
                                    {
                                        ff_printf(":%d", (int)(offset & 0x7));
                                    }
                                }
                            }
                            ff_printf("\n");
                            INDENT++;
                            if (max_depth < 0 || depth < max_depth)
                            {
                                print_data(cursor, depth + 1);
                            }
                            else
                            {
                                fi_printf("...\n");
                            }
                            INDENT--;
                            if (i < num_fields - 1)
                            {
                                if (coda_cursor_goto_next_record_field(cursor) != 0)
                                {
                                    handle_coda_error();
                                }
                            }
                        }
                        coda_cursor_goto_parent(cursor);
                    }