Reputation: 21885
Given the wrapper function for system call write :
ssize_t my_write(int fd, const void *buf, size_t count)
{
long __res;
__asm__ volatile
("int $0x80"
: "=a" (__res)
: "0" (4),"D" ((long)(fd)),"S" ((long)(buf)), "d" ((long)(count))
: "ebx","memory");
if (-125 <= __res && __res < 0)
{
errno = -__res;
__res = -1;
}
return __res;
}
I've tried it with the code (from int main()) :
int main() {
my_write(2,"an read error occured\n",26);
return 0;
}
However it doesn't work . Any idea why ?
Thanks
Upvotes: 0
Views: 155
Reputation: 206859
Your constraints are off, the file descriptor needs to go in EBX, the buffer in ECX (not EDI/ESI respectively like you have).
Try:
__asm__ volatile
("int $0x80"
: "=a" (__res)
: "0" (4),"b" ((long)(fd)),"c" ((long)(buf)), "d" ((long)(count))
: "memory");
Upvotes: 3