3
可能重复:
Inline Assembler for wrapper function doesn’t work for some reason如何检查我的包装函数系统调用 - read()是否正确?
我要求写的包装功能read , write , close , open & fork
。我写了4个包装函数read , write , close , open
。
我的问题是:
我怎么能写
fork
包装功能,使用我写的read , write , close & open
4包装的功能呢?如何检查我写的包装是否正确?下面是的
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
的包装。
问候
罗恩