可能的重复:
包装函数的内联汇编器由于某种原因不起作用 https://stackoverflow.com/questions/10260178/inline-assembler-for-wrapper-function-doesnt-work-for-some-reason
我被要求编写包装函数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;
}
Remarks: 我不允许直接使用open ,close ,read , write & fork
命令。
如果需要的话,我可以附上其他 3 个包装器的其余代码。上面是包装read
.
Regards
Ron