我是内核新手,我想实现我自己的系统调用。我搜索了这么多的链接,几乎达到了,但仍然无法得到确切的输出。
我跟踪了内核上自己的系统调用-3.8.8 (youtube视频教程)。
我的设计是:
os: Ubuntu14.04LTS
arch: x86_64
我遵循的程序是
我可以使用syscall num通过syscall() api调用syscall。但我想要的是传统的方式,比如open sys_open。我想要像mycall一样需要调用sys_mycall.
发布于 2016-11-12 04:31:56
您可以编辑您的glibc以在syscall周围添加包装器。类似于syscalls.list文件中的glibc/sysdeps/unix (搜索您的平台) https://github.com/lattera/glibc/blob/master/sysdeps/unix/syscalls.list 64/syscalls.list
# File name Caller Syscall name Args Strong name Weak names
accept - accept Ci:iBN __libc_accept accept
access - access i:si __access access
close - close Ci:i __libc_close __close close
open - open Ci:siv __libc_open __open open
read - read Ci:ibn __libc_read __read read
uname - uname i:p __uname uname
write - write Ci:ibn __libc_write __write write要解码这种格式,请使用“处理此文件的脚本中的注释:sysdeps/unix/make-syscalls.sh”,这是https://blog.packagecloud.io/eng/2016/04/05/the-definitive-guide-to-linux-system-calls/中推荐的。
# This script is used to process the syscall data encoded in the various
# syscalls.list files to produce thin assembly syscall wrappers around the
# appropriate OS syscall. See syscall-template.s for more details on the
# actual wrapper.
#
# Syscall Signature Prefixes:
#
# E: errno and return value are not set by the call
# V: errno is not set, but errno or zero (success) is returned from the call
#
# Syscall Signature Key Letters:
#
# a: unchecked address (e.g., 1st arg to mmap)
# b: non-NULL buffer (e.g., 2nd arg to read; return value from mmap)
# B: optionally-NULL buffer (e.g., 4th arg to getsockopt)
# f: buffer of 2 ints (e.g., 4th arg to socketpair)
# F: 3rd arg to fcntl
# i: scalar (any signedness & size: int, long, long long, enum, whatever)
# I: 3rd arg to ioctl
# n: scalar buffer length (e.g., 3rd arg to read)
# N: pointer to value/return scalar buffer length (e.g., 6th arg to recvfrom)
# p: non-NULL pointer to typed object (e.g., any non-void* arg)
# P: optionally-NULL pointer to typed object (e.g., 2nd argument to gettimeofday)
# s: non-NULL string (e.g., 1st arg to open)
# S: optionally-NULL string (e.g., 1st arg to acct)
# v: vararg scalar (e.g., optional 3rd arg to open)
# V: byte-per-page vector (3rd arg to mincore)
# W: wait status, optionally-NULL pointer to int (e.g., 2nd arg of wait4)关于glibc的syscall包装器的更多信息,请访问官方网站:https://sourceware.org/glibc/wiki/SyscallWrappers
由glibc使用的操作系统内核系统调用包装器有三种类型:汇编、宏和定制。 将glibc中的程序集syscalls简单内核系统调用从名称列表转换为程序集包装器,然后进行编译。..。使用包装器的syscalls列表保存在./sysdeps/unix/sysv/linux/x86_64/syscalls.list文件中:.
不要忘记为您的syscall在linux头中定义__NR号。
只有linux内核开发人员门户网站kernel.org或文档/添加-syscalls.*文件中有来自linux内核源代码:https://www.kernel.org/doc/html/v4.10/process/adding-syscalls.html https://github.com/torvalds/linux/blob/master/Documentation/process/adding-syscalls.rst的说明。
对于其他操作系统(如FreeBSD:https://wiki.freebsd.org/AddingSyscalls ),该方法将有所不同
https://stackoverflow.com/questions/40559537
复制相似问题