From owner-freebsd-hackers@FreeBSD.ORG Thu Nov 11 10:21:40 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3C05B16A4CE for ; Thu, 11 Nov 2004 10:21:40 +0000 (GMT) Received: from comsys.ntu-kpi.kiev.ua (comsys.ntu-kpi.kiev.ua [194.125.244.127]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0E6B943D2D for ; Thu, 11 Nov 2004 10:21:10 +0000 (GMT) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from pm514-9.comsys.ntu-kpi.kiev.ua (pm514-9.comsys.ntu-kpi.kiev.ua [10.18.54.109]) (authenticated bits=0)iABAKqPD049520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 11 Nov 2004 12:20:52 +0200 (EET) Received: by pm514-9.comsys.ntu-kpi.kiev.ua (Postfix, from userid 1000) id 9931C12D; Thu, 11 Nov 2004 12:20:18 +0200 (EET) Date: Thu, 11 Nov 2004 12:20:18 +0200 From: Andrey Simonenko To: Andriy Gapon Message-ID: <20041111102018.GA406@pm514-9.comsys.ntu-kpi.kiev.ua> References: <41921229.9080404@icyb.net.ua> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41921229.9080404@icyb.net.ua> User-Agent: Mutt/1.4.2.1i cc: freebsd-hackers@freebsd.org Subject: Re: syscall: td_retval and zero return value X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Nov 2004 10:21:40 -0000 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.