当前位置: 首页 > ai >正文

QEMU模拟32位ARM实现自定义系统调用

实现自定义系统调用

如何使用 QEMU 模拟32位 ARM 环境参考:使用Qemu模拟32位ARM系统

修改linux内核源码

使用 linux-4.4.240 源码,下载链接:下载链接

arch\arm\include\uapi\asm\unistd.h 文件下新增系统调用 sys_test

//added sys call
#define __NR_sys_test         	(__NR_SYSCALL_BASE+391) 

在这里插入图片描述
kernel/sys.c 添加系统调用函数 sys_test

//new sys_call sys_test
asmlinkage int sys_test(char * str, int count){int ret; char buf[256] = {0};if(count >= 256){ return -1; } ret = copy_from_user(buf, str, count);printk("[systest] Hello, %s. This is Kernel systest!\n", buf);return ret;
}

在这里插入图片描述

include/linux/syscalls.h 中添加 sys_test 的函数声明:

//new sys_call sys_test
asmlinkage int sys_test(char * str, int count);

在这里插入图片描述

arch/arm/kernel/calls.S 中添加 CALL(sys_test)

CALL(sys_test)

在这里插入图片描述

重新编译内核

依次执行

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- vexpress_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j$(nproc)

测试系统调用

在共享目录 share 下,创建测试代码 sys_test.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <string.h>int main ()
{char * buffer = "i am dinggongwurusai";int ret;ret = syscall(391, buffer, strlen(buffer)+1);printf("syscall ret: %d\n", ret);return 0;
}

采用静态链接的方式编译程序:

arm-linux-gnueabi-gcc sys_test.c -o app -static

qemu模拟启动

qemu-system-arm \-M vexpress-a9 \-m 512M \-kernel /home/wurusai/workspace/linux-4.4.240/arch/arm/boot/zImage \-dtb /home/wurusai/workspace/linux-4.4.240/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \-nographic \-append "root=/dev/mmcblk0 rw console=ttyAMA0" \-drive file=rootfs.ext3,format=raw,if=sd,readonly=off \-fsdev local,id=host0,path=./shared,security_model=passthrough \-device virtio-9p-device,fsdev=host0,mount_tag=host0

进入共享目录 /mnt/shared ,执行程序 app
在这里插入图片描述

调用自定义系统调用 sys_test 成功。

注意:

对于大部分遇到的问题都参考 使用Qemu模拟32位ARM系统

http://www.xdnf.cn/news/5752.html

相关文章:

  • 基于STM32、HAL库的PCM3060PWR 音频接口芯片驱动程序设计
  • 深度学习计算
  • GOOSE 协议中MAC配置
  • wpf DataGrid 行选择 命令绑定
  • polarctf-web-[简单rce]
  • Linux学习心得问题整理(一)
  • UDP--DDR--SFP,FPGA实现之指令监测模块实现
  • 鸿蒙北向应用开发: deveco5.0 创建开源鸿蒙项目
  • django扩展练习记录
  • 一文详解Spring Boot如何配置日志
  • 第一章 应急响应-webshell查杀
  • 【免杀】C2免杀技术(一)VS设置
  • 逆向破解:x64dbg
  • 操作系统实战——QEMU模拟器搭建【rCore 操作系统】
  • 多线程访问Servlet如何谨慎处理共享资源
  • 5.10-套接字通信 - C++
  • Spring急速入门
  • Linux系统管理与编程18:自动化部署dhcp服务
  • QML状态机制示例(State)
  • 数据知识产权质押融资风险控制
  • 前端面试每日三题 - Day 31
  • 环境扫描电镜对含水样品的观察技术与方法
  • Yolov8数据增强配置
  • 聊一聊AI对接口测试的潜在影响有哪些?
  • 【Mysql基础】一、基础入门和常见SQL语句
  • Service Mesh实战之Istio
  • 12.2.2 allocator类
  • CMake 命令行参数全解析(2025年更新版)
  • Clang实现C++文件分析,含Python实战
  • 使用webservice生成节假日/双休日/工作日信息