linux 培训6,Linux Syscalls有 6个参数(Linux Syscalls with 6 parameters)
Linux Syscalls有> 6個(gè)參數(shù)(Linux Syscalls with > 6 parameters)
是否可以編寫一個(gè)具有6個(gè)以上輸入?yún)?shù)的(linux內(nèi)核)sycall函數(shù)? 查看標(biāo)題我發(fā)現(xiàn)定義的系統(tǒng)調(diào)用宏最多有6個(gè)參數(shù)。 我很想嘗試定義SYSCALL7和SYSCALL8以允許7和8參數(shù),但我不太確定它是否真的有效。
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
更新時(shí)間:2020-02-13 11:44
最滿意答案
對于x86,以下函數(shù)(來自x86 ... syscall.h )將參數(shù)復(fù)制到:
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的注釋中很好地描述了這個(gè)函數(shù)。 它將參數(shù)復(fù)制到系統(tǒng)調(diào)用中,并且限制為6個(gè)參數(shù)。 它可以根據(jù)架構(gòu)以多種方式實(shí)現(xiàn)。 對于x86(來自上面的代碼片段),看起來這些參數(shù)都是通過寄存器傳遞的。
因此,如果要傳遞6個(gè)以上的參數(shù),請使用結(jié)構(gòu)。 如果你必須有一個(gè)SYSCALL7,那么你將不得不創(chuàng)建一個(gè)自定義內(nèi)核,并且?guī)缀蹩梢孕薷南到y(tǒng)調(diào)用進(jìn)程的每一步。 x86_64可能更容易適應(yīng)這種變化,因?yàn)樗斜葂86更多的寄存器。
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
相關(guān)問答
從man sigaction ( 鏈接 )我引用: 原始的Linux系統(tǒng)調(diào)用被命名為sigaction()。 但是,隨著Linux 2.2中添加實(shí)時(shí)信號,該系統(tǒng)調(diào)用支持的固定大小的32位sigset_t類型不再適合用途。 因此,添加了一個(gè)新的系統(tǒng)調(diào)用rt_sigaction(),以支持放大的sigset_t類型。 新的系統(tǒng)調(diào)用采用第四個(gè)參數(shù),size_t sigsetsize,它指定了act.sa_mask和oldact.sa_mask中信號集的字節(jié)大小。 From man sigaction (
...
過去,我通過使用內(nèi)核模塊修補(bǔ)系統(tǒng)調(diào)用表來做了類似的事情。 每個(gè)修補(bǔ)功能都做了如下內(nèi)容: patchFunction(/*params*/)
{
// pre checks
ret = origFunction(/*params*/);
// post checks
return ret;
}
請注意,當(dāng)您在內(nèi)核數(shù)據(jù)結(jié)構(gòu)中開始混淆時(shí),您的模塊將變?yōu)榘姹鞠嚓P(guān)的。 內(nèi)核模塊可能必須針對您正在安裝的特定內(nèi)核版本進(jìn)行編譯。 還要注意,這是許多rootkit所采用的技術(shù),所以如果你安
...
Syscall參數(shù)首先從用戶空間通過寄存器傳遞給system_call()函數(shù),該函數(shù)本質(zhì)上是一個(gè)常見的系統(tǒng)調(diào)度程序。 但是,system_call()然后以通常的方式調(diào)用實(shí)際的系統(tǒng)調(diào)用函數(shù),例如sys_read(),通過堆棧傳遞參數(shù)。 因此,搞亂堆棧會導(dǎo)致崩潰。 另外,請看這個(gè)SO答案: https : //stackoverflow.com/a/10459713以及關(guān)于quora的非常詳細(xì)的解釋: http ://www.quora.com/Linux-Kernel/What-does-asm
...
從內(nèi)核代碼調(diào)用系統(tǒng)調(diào)用( sys_*函數(shù))不是一個(gè)好主意。 實(shí)際上,許多系統(tǒng)調(diào)用可以用函數(shù)表示,可用于內(nèi)核模塊。 我需要使用文件描述符。 所以,我不能使用filp_函數(shù)(比如filp_open)。 使用fdget可以輕松地將文件描述符轉(zhuǎn)換為文件指針。 例如,參見fs/open.h的fallocate系統(tǒng)調(diào)用( SYSCALL_DEFINE4(fallocate...) fs/open.h )。 至于errno ,這個(gè)變量只是用戶空間。 系統(tǒng)調(diào)用使用-E約定返回錯(cuò)誤,libc將此值存儲到errno
...
發(fā)生這種情況是因?yàn)槌绦虻妮敵霾灰該Q行符結(jié)束。 您的程序沒有打印% 。 您可以通過將其輸出管道輸入hexdump -C或類似物來驗(yàn)證這一點(diǎn)。 您還可以使用strace來跟蹤系統(tǒng)調(diào)用它的內(nèi)容,但這并不顯示輸出 ,因此它不會排除內(nèi)核神奇地添加% 。 (但你可以肯定內(nèi)核不會這樣做。唯一可能的是, write盡早返回,而沒有編寫完整的緩沖區(qū)。這只有大緩沖區(qū)大小,特別是在寫入帶有管道的管道時(shí)緩沖區(qū)大于管道緩沖區(qū)(可能是64kiB)。 這是部分行的ZSH功能: 為什么ZSH結(jié)束帶有突出顯示百分號的行? 。 你沒
...
系統(tǒng)調(diào)用的文檔位于手冊頁的第2部分和/或源代碼的注釋中。 手冊頁以: #include
#include
#include
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
參數(shù)標(biāo)志必須包括以下訪問模式之一: O_RDONLY , O_WRONL
...
我編寫了一個(gè)簡單的SystemTap腳本(基于syscalls_by_pid.stp )。 它產(chǎn)生這樣的輸出: ProcessName #SysCalls
munin-graph 38609
munin-cron 8160
fping 4502
check_http_demo 2584
check_nrpe 2045
sh 18
...
對于x86,以下函數(shù)(來自x86 ... syscall.h )將參數(shù)復(fù)制到: static inline void syscall_get_arguments(struct task_struct *task,
struct pt_regs *regs,
unsigned int i, unsigned int n,
...
總的來說:不知道。 即使在i386上,如果有第6個(gè)參數(shù),它也必須在堆棧上傳遞(例如對于mmap )。 特別是對于x86_64:將系統(tǒng)調(diào)用號放在%rax (注意:系統(tǒng)調(diào)用號的分配與32位完全不同), %rdi , %rsi , %rdx , %r10 , %r8和%r9最多6個(gè)參數(shù)%r9 (幾乎,但不完全相同,與寄存器中參數(shù)傳遞的通常ABI相同 - 注意使用%r10而不是%rcx ),并使用syscall指令。 結(jié)果在%rax返回, %rcx和%r11被破壞。 x86_64 ABI信息可以在http
...
它會自動(dòng)在屏幕上打印按鍵 這是Linux中的默認(rèn)設(shè)置(獨(dú)立于編程語言): 鍵盤輸入將打印到屏幕上 sys_read將一直等到按下return(回車)鍵 要更改此行為,必須調(diào)用tcsetattr()函數(shù)(在C中)。 你應(yīng)該先調(diào)用tcgetattr()函數(shù)來存儲當(dāng)前設(shè)置并在離開程序之前恢復(fù)它們。 如果要直接使用系統(tǒng)調(diào)用:tcsetattr和tcgetattr都使用一些sys_ioctl。 要找出使用哪個(gè)ioctl()代碼,您可以編寫一個(gè)執(zhí)行tcsetattr和tcgetattr的C程序,并使用“str
...
總結(jié)
以上是生活随笔為你收集整理的linux 培训6,Linux Syscalls有 6个参数(Linux Syscalls with 6 parameters)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: echarts3D使用时会遇到的问题(版
- 下一篇: linux可用机场客户端,Linux系统