Android/Linux 系统调用

在调试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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值