Example #1
0
static int __init px_tp_init(void)
{
	int ret;
	unsigned int func_address = 0;

	/* register pmu device */
	ret = misc_register(&px_tp_d);
	if (ret) {
		   printk(KERN_ERR "[CPA] Unable to register \"%s\" misc device: ret = %d\n", PX_TP_DRV_NAME, ret);
		   goto init_err_0;
	}
#if 0
	/* register counter monitor thread collector DSA device */
	ret = misc_register(&pxtp_dsa_d);

	if (ret != 0){
		printk(KERN_ERR "[CPA] Unable to register \"%s\" misc device: ret = %d\n", PX_TP_DSA_DRV_NAME, ret);
		goto init_err_1;
	}

	/* register tp event buffer device */
	ret = misc_register(&pxtp_event_d);

	if (ret != 0){
		printk(KERN_ERR "[CPA] Unable to register \"%s\" misc device: ret = %d\n", PX_TP_EVENT_DRV_NAME, ret);
		goto init_err_2;
	}

	/* register tp module buffer device */
	ret = misc_register(&pxtp_module_d);

	if (ret != 0){
		printk(KERN_ERR "[CPA] Unable to register \"%s\" misc device: ret = %d\n", PX_TP_MODULE_DRV_NAME, ret);
		goto init_err_3;
	}
#endif
#ifdef SYS_CALL_TABLE_ADDRESS
	//system_call_table =(void**) SYS_CALL_TABLE_ADDRESS;
#endif

#if defined(LINUX_VERSION_CODE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
	kallsyms_lookup_name_func = (void*)kallsyms_lookup_name;
#else

	if (param_kallsyms_lookup_name_addr != 0) {
		kallsyms_lookup_name_func = (void*) param_kallsyms_lookup_name_addr;
	}

#endif

	if (kallsyms_lookup_name_func == NULL) {
		printk(KERN_ALERT "[CPA] *ERROR* Can't find kallsyms_lookup_name address\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	system_call_table = (void **)kallsyms_lookup_name_func("sys_call_table");

	if (system_call_table == NULL) {
		printk(KERN_ALERT "[CPA] *ERROR* Can't find sys_call_table address\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	func_address = (unsigned int)kallsyms_lookup_name_func("access_process_vm");
	if (func_address == 0)
	{
		printk(KERN_ALERT "[CPA] *ERROR* Can't find access_process_vm address\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	set_access_process_vm_address(func_address);

	set_address_access_process_vm(func_address);

	func_address = (unsigned int)kallsyms_lookup_name_func("register_undef_hook");
	if (func_address == 0)
	{
		printk(KERN_ALERT "[CPA] *ERROR* Can't find register_undef_hook address\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	set_address_register_undef_hook(func_address);

	func_address = (unsigned int)kallsyms_lookup_name_func("unregister_undef_hook");
	if (func_address == 0)
	{
		printk(KERN_ALERT "[CPA] *ERROR* Can't find unregister_undef_hook address\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	set_address_unregister_undef_hook(func_address);
#if 0
	if (allocate_dsa() != 0){
		printk(KERN_ERR "[CPA] Unable to create dsa in kernel\n");
		ret = -EFAULT;
		goto init_err_4;
	}
#endif
	init_dsa();

	return 0;
init_err_4:
#if 0
	misc_deregister(&pxtp_module_d);
init_err_3:
	misc_deregister(&pxtp_event_d);
init_err_2:
	misc_deregister(&pxtp_dsa_d);
init_err_1:
#endif
	misc_deregister(&px_tp_d);
init_err_0:
	return ret;
}
Example #2
0
static int __init px_hotspot_init(void)
{
	int ret;
	unsigned int address;

	/* register pmu device */
	ret = misc_register(&px_hotspot_d);
	if (ret) {
		   printk(KERN_ERR "[CPA] Unable to register \"%s\" misc device: ret = %d\n", PX_HS_DRV_NAME, ret);
		   goto init_err_0;
	}

#if 0
	/* register counter monitor thread collector DSA device */
	ret = misc_register(&pxhs_dsa_d);

	if (ret != 0){
		printk(KERN_ERR "[CPA] Unable to register \"%s\" misc device: ret = %d\n", PX_HS_DSA_DRV_NAME, ret);
		goto init_err_1;
	}
	/* register hotspot sample buffer device */
	ret = misc_register(&pxhs_sample_d);

	if (ret != 0){
		printk(KERN_ERR "[CPA] Unable to register \"%s\" misc device: ret = %d\n", PX_HS_SAMPLE_DRV_NAME, ret);
		goto init_err_2;
	}

	/* register hotspot module buffer device */
	ret = misc_register(&pxhs_module_d);

	if (ret != 0){
		printk(KERN_ERR "[CPA] Unable to register \"%s\" misc device: ret = %d\n", PX_HS_MODULE_DRV_NAME, ret);
		goto init_err_3;
	}
#endif
#ifdef SYS_CALL_TABLE_ADDRESS
	//system_call_table_hs =(void**) SYS_CALL_TABLE_ADDRESS;
#endif

#if defined(LINUX_VERSION_CODE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
	kallsyms_lookup_name_func = (void*)kallsyms_lookup_name;
#else
	if (param_kallsyms_lookup_name_addr != 0) {
		kallsyms_lookup_name_func = (kallsyms_lookup_name_func_t) param_kallsyms_lookup_name_addr;
	}
#endif

	if (kallsyms_lookup_name_func == NULL) {
		printk(KERN_ALERT "[CPA] *ERROR* Can't find kallsyms_lookup_name address\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	system_call_table_hs = (void **)kallsyms_lookup_name_func("sys_call_table");

	if (system_call_table_hs == NULL) {
		printk(KERN_ALERT "[CPA] *ERROR* Can't find sys_call_table address\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	address = kallsyms_lookup_name_func("access_process_vm");

	if (address == 0) {
		printk(KERN_ALERT "[CPA] *ERROR* Can't find access_process_vm address\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	set_access_process_vm_address(address);
#if 0
	if (allocate_dsa() != 0){
		printk(KERN_ERR "[CPA] Unable to create dsa in kernel\n");
		ret = -EFAULT;
		goto init_err_4;
	}

	init_dsa();
#endif

	init_func_for_cpu();

	return 0;
init_err_4:
#if 0
	misc_deregister(&pxhs_module_d);
init_err_3:
	misc_deregister(&pxhs_sample_d);
init_err_2:
	misc_deregister(&pxhs_dsa_d);
init_err_1:
#endif
	misc_deregister(&px_hotspot_d);
init_err_0:
	return ret;
}