syscall: td_retval and zero return value
Andrey Simonenko
simon at comsys.ntu-kpi.kiev.ua
Thu Nov 11 02:21:40 PST 2004
On Wed, Nov 10, 2004 at 03:05:45PM +0200, Andriy Gapon wrote:
>
> I have very little assembler/x86 knowledge.
> Could anyone please help me understand what it means to assign a
> non-zero value to td_retval in a system call when return value of the
> call is zero/success?
If a syscall returns some data to userland process/thread, then
td_retval[2] array has these values, in i386/trap.c they are copied
to %eax and %edx. A return value of a syscall is not always zero,
for example read(2) returns number of bytes. In i386 an error from
syscall is marked by setting carry flag and error code is saved in
%eax, otherwise carry flag is cleared.
> register in a stack frame of a calling process. But I don't understand
> what it practically means for the calling process.
Check how pipe(2) syscall works. It returns two values (two descriptors)
and it returns a return value to indicate error or success.
In sys/kern/sys_pipe.c:pipe() td_retval[0] and td_retal[1] keeps
numbers of created file descriptors. In libc/i386/SYS.h there is
a generic macro, which generates code for syscalls (check thread
in this mailing list about SYS.h). If an error occurred, then cerror
is called. libc/i386/sys/pipe.S has code for calling pipe(2), note,
that %eax and %edx a moved to the array given by a process, which
invoked pipe(2). Also in that directory there is cerror.S which move
an error code from syscalls to errno.
And as it was said, read paragraphs about Assembler Programming in
Developers' Handbook.
More information about the freebsd-hackers
mailing list