当前位置: 移动技术网 > 网络运营>服务器>Linux > Android/Linux 系统调用

Android/Linux 系统调用

2020年07月23日  | 移动技术网网络运营  | 我要评论

在调试Android 设备驱动时 ,应用层总是被各种权限束缚,这里给出其中一种解决方案。

一 kernel 层修改

drivers/input/fingerprint/zpx_fp_mtk_tee/zpx_fp_mtk_tee.c

	#include <linux/syscalls.h>

        static long zpx_method(long arg)
	{
	
		printk("%s enter,arg=%ld\n",__func__ ,arg);
		read_all_reg_test(fp_global);
		return 0;
	}
	
	
	SYSCALL_DEFINE1(zpx_method,long,arg)//一个形参
	{
	
		return zpx_method(arg);
	}

include/linux/syscalls.h

asmlinkage long sys_zpx_method(long arg);

include/uapi/asm-generic/unistd.h

 __SYSCALL(__NR_zpx_method, sys_zpx_method)

arch/arm/include/uapi/asm/unistd.h

#define __NR_zpx_method                (__NR_SYSCALL_BASE+391)

arch/arm/kernel/calls.S

		CALL(sys_zpx_method)
.rept syscalls_padding  //注释如下空函数
        /*      CALL(sys_ni_syscall) */  /*null func*/

arch/arm/include/asm/unistd.h

#define __NR_syscalls  (392) // last call +1

二 应用层调用

#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
#define _SYSCALL_zpx_ 391
int main(int argc,char **argv)
{

   syscall(_SYSCALL_zpx_,13);

	return 0;
}

三 结果

无需任何权限

k39_bsp:/data/local/tmp $ ls -l
total 80
-rwxrwxrwx 1 shell shell 78968 2020-07-20 09:28 driver_test
k39_bsp:/data/local/tmp $ ./driver_test                                                                                    
k39_bsp:/data/local/tmp $ 

kernel log

[  100.325202] (2)[2506:driver_test]zpx_method enter,arg=13
[  100.325234] (2)[2506:driver_test][zpx] zpx_spi_clk_enable enter
[  100.325249] (2)[2506:driver_test][zpx] zpx_spi_clk_enable finsish
[  100.325469] (2)[2506:driver_test][zpx] [0]=FF
[  100.325483] (2)[2506:driver_test][zpx] [1]=0
[  100.325490] (2)[2506:driver_test][zpx] [2]=0
[  100.325497] (2)[2506:driver_test][zpx] [3]=3F
[  100.325503] (2)[2506:driver_test][zpx] [4]=0
[  100.325510] (2)[2506:driver_test][zpx] [5]=57

 

本文地址:https://blog.csdn.net/piao3956/article/details/107480886

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网