zoukankan      html  css  js  c++  java
  • [国嵌攻略][109][Linux系统调用]

    系统调用

    函数实现体在内核空间,提供给应用程序来使用,就是一个系统调用。

    工作流程

    1.通过软中断(swi)从用户空间切换到内核空间。entry-common.S中的ENTRY(vector_swi)是用来处理软中断的。系统调用通常从r7寄存器中取出系统调用编号。

    2.通过系统调用编号从系统调用表中找出调用的系统调用函数。也是是calls.S文件中找出系统调用编号对应的函数。

    实现系统调用

    1.打开.../kernel/printk.c,添加系统调用函数

    void sys_iprint(){

        printk(“This is a new system call! ”);

    }

    2.打开.../arch/arm/kernel/calls.S,添加系统调用入口

    CALL(sys_iprint)

    3.打开.../arch/arm/include/asm/unistd.h,条件系统调用编号

    #define __NR_iprint   (__NR_SYSCALL_BASE+365)

    4.重新编译内核

    make clean

    make uImage ARCH=arm CROSS_COMPILE=arm-liunx-

    5.编写应用程序

    //系统调用接口
    void ipirnt(){
        __asm__(
            "ldr r7, =365
    "
            "swi
    "
            :
            :
            :"memory"
        );
    }
    
    int main(int argc, char **argv){
        ipirnt();
        
        return 0;
    }

    6.编译应用程序

    arc-linux-gcc –static syscall.c –o syscall

  • 相关阅读:
    gdb调试core文件
    设计模式之工厂模式
    设计模式之简单工厂模式
    正确理解python的装饰器
    深入理解MVC架构
    django的模板系统过滤器笔记
    python net-snmp 的使用
    用django写个CMS系统
    django的CMS系统(内容管理系统)
    RESTful 的通俗解释
  • 原文地址:https://www.cnblogs.com/d442130165/p/5247507.html
Copyright © 2011-2022 走看看