將參數傳遞給系統調用 (Passing arguments to system calls)


問題描述

將參數傳遞給系統調用 (Passing arguments to system calls)

我知道當我們想要進行系統調用時,我們通常會圍繞該系統調用調用一個 C 包裝器,該包裝器在內部將參數放在正確的位置(有時在特定的寄存器或堆棧中)。

之後放置參數(並忽略諸如 syscall 指令之類的方法,因為它並非在所有平台上都可用),包裝器通常執行 int 0x80(軟件中斷)。

現在,當遇到中斷時,硬件會將正在運行的進程的所有寄存器保存在其堆棧中並進行上下文切換(這將包括切換程序計數器和堆棧指針等)。

我無法理解系統調用處理程序如何訪問最初由 C 包裝器在特定寄存器中設置的參數,這些參數現在駐留在 user 進程堆棧中(not in 內核進程堆棧)


參考解法

方法 1:

Now, when an interrupt is encountered hardware will save all the registers of the running process on its stack and make context switch (which will include switching program counter and stack pointer among other things).

Nope ;‑) On Linux AMD64, syscall arguments are directly passed in registers (registers do not get stacked).

For details, see "x86‑64 Linux System Call convention" http://refspecs.linuxfoundation.org/elf/x86_64‑abi‑0.99.pdf , Sect. 'A.2.1 Calling Conventions' at the bottom of page 123/head of p. 124.

(by Rahul Patelsenatores conscripti)

參考文件

  1. Passing arguments to system calls (CC BY‑SA 2.5/3.0/4.0)

#interrupt #linux-kernel #system-calls #linux






相關問題

無法在 java 命令行程序中捕獲中斷 (Unable to catch interrupt in java command line program)

不連續的 BitBlt 捕獲 (discontinuous BitBlt capture)

GPIO 更改狀態時如何更新 sysfs? (How is sysfs updated when a GPIO changes state?)

Linux IRQ 處理程序中的固有競爭條件 (Inherent race condition in Linux IRQ handlers)

STM32 外部中斷僅在調試模式下響應 (STM32 external interrupt responds only in debug mode)

Java中的線程 (Threading in Java)

如何在被 Python 殺死之前運行最後一個函數? (How to run one last function before getting killed in Python?)

在 C++ 中處理中斷 (Handling Interrupt in C++)

應用程序中斷瘋狂 (Application interrupts like crazy)

SetPriorityClass(REALTIME_PRIORITY_CLASS) 實際上做了什麼? (What does SetPriorityClass(REALTIME_PRIORITY_CLASS) actually do?)

如何找出軟件掛起的原因?(qemu + zephyr + tfm 的問題) (How to find out the cause of hanging software? (problem with qemu + zephyr + tfm))

將參數傳遞給系統調用 (Passing arguments to system calls)







留言討論