可能重复:
对于包装函数内联汇编不能出于某种原因
我要求写的包装功能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
。
问候
罗恩