Example #1
0
File: lib_ffi.c Project: ktap/ktap
static int kplib_ffi_new(ktap_state_t *ks)
{
	int n = kp_arg_nr(ks);
	csymbol_id cs_id = kp_arg_checknumber(ks, 1);
	int array_size = kp_arg_checknumber(ks, 2);
	int is_array = kp_arg_checknumber(ks, 3);
	ktap_cdata_t *cd;

	if (unlikely(n != 3)) {
		/* this is not likely to happen since ffi.new arguments are
		 * generated by compiler */
		set_nil(ks->top++);
		kp_error(ks, "wrong number of arguments\n");
		return 1;
	}

	if (unlikely(cs_id > max_csym_id(ks)))
		kp_error(ks, "invalid csymbol id\n");

	kp_verbose_printf(ks, "ffi.new symbol %s with length %d\n",
			id_to_csym(ks, cs_id)->name, array_size);

	if (is_array)
		cd = kp_cdata_new_ptr(ks, NULL, array_size, cs_id, 1);
	else
		cd = kp_cdata_new_by_id(ks, NULL, cs_id);
	set_cdata(ks->top, cd);
	incr_top(ks);

	return 1;
}
Example #2
0
/**
 * function ansi.set_color2 - Set the ansi Select Graphic Rendition mode.
 * @fg: Foreground color to set.
 * @bg: Background color to set.
 *
 * Description: Sends ansi code for Select Graphic Rendition mode for the
 * given forground color, Black (30), Blue (34), Green (32), Cyan (36),
 * Red (31), Purple (35), Brown (33), Light Gray (37) and the given
 * background color, Black (40), Red (41), Green (42), Yellow (43),
 * Blue (44), Magenta (45), Cyan (46), White (47).
 */
static int kplib_ansi_set_color2(ktap_state_t *ks)
{
	int fg = kp_arg_checknumber(ks, 1);
	int bg = kp_arg_checknumber(ks, 2);
	
	kp_printf(ks, "\033[%d;%dm", fg, bg);
	return 0;
}
Example #3
0
/**
 * function ansi.set_color3 - Set the ansi Select Graphic Rendition mode.
 * @fg: Foreground color to set.
 * @bg: Background color to set.
 * @attr: Color attribute to set.
 *
 * Description: Sends ansi code for Select Graphic Rendition mode for the
 * given forground color, Black (30), Blue (34), Green (32), Cyan (36),
 * Red (31), Purple (35), Brown (33), Light Gray (37), the given
 * background color, Black (40), Red (41), Green (42), Yellow (43),
 * Blue (44), Magenta (45), Cyan (46), White (47) and the color attribute
 * All attributes off (0), Intensity Bold (1), Underline Single (4),
 * Blink Slow (5), Blink Rapid (6), Image Negative (7).
 */
static int kplib_ansi_set_color3(ktap_state_t *ks)
{
	int fg = kp_arg_checknumber(ks, 1);
	int bg = kp_arg_checknumber(ks, 2);
	int attr = kp_arg_checknumber(ks, 3);

	if (attr)
		kp_printf(ks, "\033[%d;%d;%dm", fg, bg, attr);
	else
		kp_printf(ks, "\033[%d;%dm", fg, bg);
	
	return 0;
}
Example #4
0
/*
 * use gdb to get field offset of struct task_struct, for example:
 *
 * gdb vmlinux
 * (gdb)p &(((struct task_struct *)0).prio)
 */
static int kplib_curr_taskinfo(ktap_state_t *ks)
{
	int offset = kp_arg_checknumber(ks, 1);
	int fetch_bytes  = kp_arg_checkoptnumber(ks, 2, 4); /* fetch 4 bytes */

	if (offset >= sizeof(struct task_struct)) {
		set_nil(ks->top++);
		kp_error(ks, "access out of bound value of task_struct\n");
		return 1;
	}

#define RET_VALUE ((unsigned long)current + offset)

	switch (fetch_bytes) {
	case 4:
		set_number(ks->top, *(unsigned int *)RET_VALUE);
		break;
	case 8:
		set_number(ks->top, *(unsigned long *)RET_VALUE);
		break;
	default:
		kp_error(ks, "unsupported fetch bytes in curr_task_info\n");
		set_nil(ks->top);
		break;
	}

#undef RET_VALUE

	incr_top(ks);
	return 1;
}
Example #5
0
static int kplib_ipof(ktap_state_t *ks)
{
	unsigned long addr = kp_arg_checknumber(ks, 1);

	set_ip(ks->top++, addr);
	return 1;
}
Example #6
0
File: lib_ffi.c Project: ktap/ktap
static int kplib_ffi_cast(ktap_state_t *ks)
{
	int n = kp_arg_nr(ks);
	csymbol_id cs_id = kp_arg_checknumber(ks, 1);
	unsigned long addr = kp_arg_checknumber(ks, 2);
	ktap_cdata_t *cd;

	if (unlikely(n != 2)) {
		/* this is not likely to happen since ffi.cast arguments are
		 * generated by compiler */
		set_nil(ks->top++);
		kp_error(ks, "wrong number of arguments\n");
		return 1;
	}

	if (unlikely(cs_id > max_csym_id(ks)))
		kp_error(ks, "invalid csymbol id\n");

	cd = kp_cdata_new_record(ks, (void *)addr, cs_id);
	set_cdata(ks->top, cd);
	incr_top(ks);
	return 1;
}
Example #7
0
static int kplib_kernel_string(ktap_state_t *ks)
{
	unsigned long addr = kp_arg_checknumber(ks, 1);
	char str[256] = {0};
	ktap_str_t *ts;
	char *ret;

	ret = strncpy((void *)str, (const void *)addr, 256);
	(void) &ret;  /* Silence compiler warning. */
	str[255] = '\0';

	ts = kp_str_newz(ks, str);
	if (unlikely(!ts))
		return -1;

	set_string(ks->top, ts);
	incr_top(ks);
	return 1;
}
Example #8
0
static int kplib_user_string(ktap_state_t *ks)
{
	unsigned long addr = kp_arg_checknumber(ks, 1);
	char str[256] = {0};
	ktap_str_t *ts;
	int ret;

	pagefault_disable();
	ret = __copy_from_user_inatomic((void *)str, (const void *)addr, 256);
	(void) &ret;  /* Silence compiler warning. */
	pagefault_enable();
	str[255] = '\0';

	ts = kp_str_newz(ks, str);
	if (unlikely(!ts))
		return -1;

	set_string(ks->top, ts);
	incr_top(ks);
	return 1;
}