Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Nov 2004 12:20:18 +0200
From:      Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To:        Andriy Gapon <avg@icyb.net.ua>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: syscall: td_retval and zero return value
Message-ID:  <20041111102018.GA406@pm514-9.comsys.ntu-kpi.kiev.ua>
In-Reply-To: <41921229.9080404@icyb.net.ua>
References:  <41921229.9080404@icyb.net.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041111102018.GA406>