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, ®s->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, ®s->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
...
總結
以上是生活随笔為你收集整理的linux 培训6,Linux Syscalls有 6个参数(Linux Syscalls with 6 parameters)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: echarts3D使用时会遇到的问题(版
- 下一篇: linux可用机场客户端,Linux系统