重複の可能性:
ラッパー関数のインライン アセンブラーが何らかの理由で機能しない
のラッパー関数を書いてほしいと頼まれましたread , write , close , open & fork
。
の 4 つのラッパー関数を作成しましたread , write , close , open
。
私の質問は次のとおりです。
fork
用に書いた 4 つのラッパー関数を使用して、用のラッパー関数を作成するにはどうすればよいread , write , close & open
ですか?私が書いたラッパーが正しいかどうかを確認するにはどうすればよいですか?
read
- と呼ばれるラッパー関数のコードは次のmy_read
とおりです。
ssize_t my_read(int fd, void *buf, size_t count)
{
ssize_t res;
__asm__ volatile(
"int $0x80" /* make the request to the OS */
: "=a" (res), /* return result in eax ("a") */
"+b" (fd), /* pass arg1 in ebx ("b") */
"+c" (buf), /* pass arg2 in ecx ("c") */
"+d" (count) /* pass arg3 in edx ("d") */
: "a" (5) /* passing the system call for read to %eax , with call number 5 */
: "memory", "cc");
/* The operating system will return a negative value on error;
* wrappers return -1 on error and set the errno global variable */
if (-125 <= res && res < 0)
{
errno = -res;
res = -1;
}
return res;
}
備考open ,close ,read , write & fork
:コマンドを直接使用することは許可されていません。
必要に応じて、他の 3 つのラッパーの残りのコードを添付できます。上記は のラッパーですread
。
よろしく
ロン