• android调用号和libc


      调用号(以arm平台为例)在/bionic/libc/kernel/uapi/asm-arm/asm/unistd.h

    /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
    #define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0)
    #define __NR_exit (__NR_SYSCALL_BASE+ 1)
    #define __NR_fork (__NR_SYSCALL_BASE+ 2)
    #define __NR_read (__NR_SYSCALL_BASE+ 3)
    /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
    #define __NR_write (__NR_SYSCALL_BASE+ 4)
    #define __NR_open (__NR_SYSCALL_BASE+ 5)
    #define __NR_close (__NR_SYSCALL_BASE+ 6)
    #define __NR_creat (__NR_SYSCALL_BASE+ 8)
    /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
    #define __NR_link (__NR_SYSCALL_BASE+ 9)
    #define __NR_unlink (__NR_SYSCALL_BASE+ 10)
    #define __NR_execve (__NR_SYSCALL_BASE+ 11)
    #define __NR_chdir (__NR_SYSCALL_BASE+ 12)
    /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
    #define __NR_time (__NR_SYSCALL_BASE+ 13)
    #define __NR_mknod (__NR_SYSCALL_BASE+ 14)
    #define __NR_chmod (__NR_SYSCALL_BASE+ 15)
    #define __NR_lchown (__NR_SYSCALL_BASE+ 16)
    /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
    #define __NR_lseek (__NR_SYSCALL_BASE+ 19)
    #define __NR_getpid (__NR_SYSCALL_BASE+ 20)
    #define __NR_mount (__NR_SYSCALL_BASE+ 21)
    #define __NR_umount (__NR_SYSCALL_BASE+ 22)
    ......

      如何使用呢,以android5.0源码中的关机代码为例: /system/core/libcutils/android_reboot.c

    #include <unistd.h>
    #include <sys/reboot.h>
    #include <sys/syscall.h>            //  bionic/libc/include/sys/syscall.h
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <string.h>
    ......
    int android_reboot(int cmd, int flags UNUSED, char *arg)
    108{
            ......
        switch (cmd) {
            ......
           case ANDROID_RB_RESTART2:
            ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,    //   /bionic/libc/arch-arm/bionic/syscall.S
                               LINUX_REBOOT_CMD_RESTART2, arg);
            ......
    }

       代码中直接syscall(_NR_reboot)来调用系统reboot函数,注意上面红色标注的代码。

      (dannerWorking:要分析/bionic/libc/tools/gensyscalls.py这个文件啊还没做)

    参考资料:

     1 android 系统调用

  • 相关阅读:
    内置函数zip,map,even
    异常处理
    requests模块(请求接口)
    网络编程之urllib
    cookie/session区别
    测试环境搭建流程
    接口开发01--mock接口
    操作Redis--hash/key-value
    操作excel--xlwt/xlrd/xlutils模块
    可变对象 不可变对象 浅拷贝 深拷贝
  • 原文地址:https://www.cnblogs.com/vendanner/p/4894905.html
Copyright © 2020-2023  润新知