Exemplo n.º 1
0
static void init_kprobe_prohibited_area(void)
{
	static int once = 0;

	if (once > 0)
		return;

	once = 1;

	core_kernel_text_start = find_kernel_symbol("_stext");
	core_kernel_text_end   = find_kernel_symbol("_etext");
	kprobes_text_start     = find_kernel_symbol("__kprobes_text_start");
	kprobes_text_end       = find_kernel_symbol("__kprobes_text_end");
}
Exemplo n.º 2
0
int cp_symbol_build_func(struct cp_ctype *type, const char *fname, int fn_size)
{
	int i = 1, arg_nr, id;
	int *argsym_id_arr;
	csymbol nfcs;
	csymbol_func *fcs;

	if (cts.top == 0 || fn_size < 0 || !fname) {
		cp_error("invalid function definition.\n");
	}

	argsym_id_arr = NULL;
	memset(&nfcs, 0, sizeof(csymbol));
	csym_type(&nfcs) = FFI_FUNC;

	strncpy(csym_name(&nfcs), fname, fn_size);

	fcs = csym_func(&nfcs);
	fcs->has_var_arg = type->has_var_arg;
	/* Type needed for handling variable args handle */
	if (fcs->has_var_arg && !ctype_lookup_type("void *"))
		cp_symbol_build_pointer(ctype_lookup_type("void"));

	/* Fetch start address of function  */
	fcs->addr = (void *)find_kernel_symbol(csym_name(&nfcs));
	if (!fcs->addr)
		cp_error("wrong function address for %s\n", csym_name(&nfcs));

	/* bottom of the stack is return type */
	fcs->ret_id = ct_stack_ct(0)->ffi_cs_id;

	/* the rest is argument type */
	if (cts.top == 1) {
		/* function takes no argument */
		arg_nr = 0;
	} else {
		arg_nr = cts.top - 1;
		argsym_id_arr = malloc(arg_nr * sizeof(int));
		if (!argsym_id_arr)
			cp_error("failed to allocate memory for function args.\n");
		for (i = 0; i < arg_nr; i++) {
			argsym_id_arr[i] = ct_stack_ct(i+1)->ffi_cs_id;
		}
	}
	fcs->arg_nr = arg_nr;
	fcs->arg_ids = argsym_id_arr;

	id = cp_ctype_reg_csymbol(&nfcs);

	/* clear stack since we have consumed all the ctypes */
	ctype_stack_reset();

	return id;
}