linux 培训6,Linux Syscalls有> 6个参数(Linux Syscalls with > 6 parameters)

Linux Syscalls有> 6个参数(Linux Syscalls with > 6 parameters)

是否可以编写一个具有6个以上输入参数的(linux内核)sycall函数? 查看标题我发现定义的系统调用宏最多有6个参数。 我很想尝试定义SYSCALL7和SYSCALL8以允许7和8参数,但我不太确定它是否真的有效。

IS it possible to write a (linux kernel)sycall function that has more than 6 input parameters? Looking at the header I see that the defined syscall macros have a maximum of 6 parameters. I'm tempted to try to define SYSCALL7 and SYSCALL8 to allow for 7 and 8 parameters but I'm not quite sure if that will actually work.

原文:https://stackoverflow.com/questions/21517811

更新时间:2020-02-13 11:44

最满意答案

对于x86,以下函数(来自x86 ... syscall.h )将参数复制到:

static inline void syscall_get_arguments(struct task_struct *task,

struct pt_regs *regs,

unsigned int i, unsigned int n,

unsigned long *args)

{

BUG_ON(i + n > 6);

memcpy(args, &regs->bx + i, n * sizeof(args[0]));

}

在asm_generic / syscall.h的注释中很好地描述了这个函数。 它将参数复制到系统调用中,并且限制为6个参数。 它可以根据架构以多种方式实现。 对于x86(来自上面的代码片段),看起来这些参数都是通过寄存器传递的。

因此,如果要传递6个以上的参数,请使用结构。 如果你必须有一个SYSCALL7,那么你将不得不创建一个自定义内核,并且几乎可以修改系统调用进程的每一步。 x86_64可能更容易适应这种变化,因为它有比x86更多的寄存器。

For x86, the following function (from x86...syscall.h) copies the arguments over:

static inline void syscall_get_arguments(struct task_struct *task,

struct pt_regs *regs,

unsigned int i, unsigned int n,

unsigned long *args)

{

BUG_ON(i + n > 6);

memcpy(args, &regs->bx + i, n * sizeof(args[0]));

}

This function is described well in the comments in asm_generic/syscall.h. It copies the arguments into the syscall, and there is a limit of 6 arguments. It may be implemented in a number of ways depending on architecture. For x86 (from the snippet above) it looks like the arguments are all passed by register.

So, if you want to pass more than 6 arguments, use a struct. If you must have a SYSCALL7, then you are going to have to create a custom kernel and likely modify almost every step of the syscall process. x86_64 would likely accommodate this change easier, since it has more registers than x86.

2014-02-03

相关问答

从man sigaction ( 链接 )我引用: 原始的Linux系统调用被命名为sigaction()。 但是,随着Linux 2.2中添加实时信号,该系统调用支持的固定大小的32位sigset_t类型不再适合用途。 因此,添加了一个新的系统调用rt_sigaction(),以支持放大的sigset_t类型。 新的系统调用采用第四个参数,size_t sigsetsize,它指定了act.sa_mask和oldact.sa_mask中信号集的字节大小。 From man sigaction (

...

过去,我通过使用内核模块修补系统调用表来做了类似的事情。 每个修补功能都做了如下内容: patchFunction(/*params*/)

{

// pre checks

ret = origFunction(/*params*/);

// post checks

return ret;

}

请注意,当您在内核数据结构中开始混淆时,您的模块将变为版本相关的。 内核模块可能必须针对您正在安装的特定内核版本进行编译。 还要注意,这是许多rootkit所采用的技术,所以如果你安

...

Syscall参数首先从用户空间通过寄存器传递给system_call()函数,该函数本质上是一个常见的系统调度程序。 但是,system_call()然后以通常的方式调用实际的系统调用函数,例如sys_read(),通过堆栈传递参数。 因此,搞乱堆栈会导致崩溃。 另外,请看这个SO答案: https : //stackoverflow.com/a/10459713以及关于quora的非常详细的解释: http ://www.quora.com/Linux-Kernel/What-does-asm

...

从内核代码调用系统调用( sys_*函数)不是一个好主意。 实际上,许多系统调用可以用函数表示,可用于内核模块。 我需要使用文件描述符。 所以,我不能使用filp_函数(比如filp_open)。 使用fdget可以轻松地将文件描述符转换为文件指针。 例如,参见fs/open.h的fallocate系统调用( SYSCALL_DEFINE4(fallocate...) fs/open.h )。 至于errno ,这个变量只是用户空间。 系统调用使用-E约定返回错误,libc将此值存储到errno

...

发生这种情况是因为程序的输出不以换行符结束。 您的程序没有打印% 。 您可以通过将其输出管道输入hexdump -C或类似物来验证这一点。 您还可以使用strace来跟踪系统调用它的内容,但这并不显示输出 ,因此它不会排除内核神奇地添加% 。 (但你可以肯定内核不会这样做。唯一可能的是, write尽早返回,而没有编写完整的缓冲区。这只有大缓冲区大小,特别是在写入带有管道的管道时缓冲区大于管道缓冲区(可能是64kiB)。 这是部分行的ZSH功能: 为什么ZSH结束带有突出显示百分号的行? 。 你没

...

系统调用的文档位于手册页的第2部分和/或源代码的注释中。 手册页以: #include

#include

#include

int open(const char *pathname, int flags);

int open(const char *pathname, int flags, mode_t mode);

参数标志必须包括以下访问模式之一: O_RDONLY , O_WRONL

...

我编写了一个简单的SystemTap脚本(基于syscalls_by_pid.stp )。 它产生这样的输出: ProcessName #SysCalls

munin-graph 38609

munin-cron 8160

fping 4502

check_http_demo 2584

check_nrpe 2045

sh 18

...

对于x86,以下函数(来自x86 ... syscall.h )将参数复制到: static inline void syscall_get_arguments(struct task_struct *task,

struct pt_regs *regs,

unsigned int i, unsigned int n,

...

总的来说:不知道。 即使在i386上,如果有第6个参数,它也必须在堆栈上传递(例如对于mmap )。 特别是对于x86_64:将系统调用号放在%rax (注意:系统调用号的分配与32位完全不同), %rdi , %rsi , %rdx , %r10 , %r8和%r9最多6个参数%r9 (几乎,但不完全相同,与寄存器中参数传递的通常ABI相同 - 注意使用%r10而不是%rcx ),并使用syscall指令。 结果在%rax返回, %rcx和%r11被破坏。 x86_64 ABI信息可以在http

...

它会自动在屏幕上打印按键 这是Linux中的默认设置(独立于编程语言): 键盘输入将打印到屏幕上 sys_read将一直等到按下return(回车)键 要更改此行为,必须调用tcsetattr()函数(在C中)。 你应该先调用tcgetattr()函数来存储当前设置并在离开程序之前恢复它们。 如果要直接使用系统调用:tcsetattr和tcgetattr都使用一些sys_ioctl。 要找出使用哪个ioctl()代码,您可以编写一个执行tcsetattr和tcgetattr的C程序,并使用“str

...

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值