From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 9 01:20:29 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 5DE5416A4CE for ; Tue, 9 Nov 2004 01:20:29 +0000 (GMT) Received: from smtp.des.no (flood.des.no [217.116.83.31]) by mx1.FreeBSD.org (Postfix) with ESMTP id A6FC643D31 for ; Tue, 9 Nov 2004 01:20:28 +0000 (GMT) (envelope-from des@des.no) Received: by smtp.des.no (Pony Express, from userid 666) id 2762B5310; Tue, 9 Nov 2004 02:20:27 +0100 (CET) Received: from dwp.des.no (des.no [80.203.228.37]) by smtp.des.no (Pony Express) with ESMTP id 9AF67530A; Tue, 9 Nov 2004 02:20:19 +0100 (CET) Received: by dwp.des.no (Postfix, from userid 2602) id 27CCFB861; Tue, 9 Nov 2004 02:20:19 +0100 (CET) To: Dan Strick References: <200411081857.iA8Iv725000576@mist.nodomain> From: des@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) Date: Tue, 09 Nov 2004 02:20:18 +0100 In-Reply-To: <200411081857.iA8Iv725000576@mist.nodomain> (Dan Strick's message of "Mon, 8 Nov 2004 10:57:07 -0800 (PST)") Message-ID: User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Checker-Version: SpamAssassin 2.64 (2004-01-11) on flood.des.no X-Spam-Level: X-Spam-Status: No, hits=0.0 required=5.0 tests=AWL autolearn=no version=2.64 cc: freebsd-hackers@freebsd.org cc: dan@mist.nodomain cc: simon@comsys.ntu-kpi.kiev.ua Subject: Re: Where is the source to the system calls? 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: Tue, 09 Nov 2004 01:20:29 -0000 Dan Strick writes: > Thanks for the pointer to /usr/src/lib/libc/i386/SYS.h. It contains > precisely the "secret macro instructions invoking undocumented gnu > C-compiler asm() features" that I suspected but could not find. > > I still don't understand all the details but I do understand enough > to realize that I don't want to understand any more. I don't see what's so hard to understand: #define SYSCALL(x) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); \ ENTRY(__CONCAT(__sys_,x)); \ .weak CNAME(x); \ .set CNAME(x),CNAME(__CONCAT(__sys_,x)); \ .weak CNAME(__CONCAT(_,x)); \ .set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x))= ; \ mov __CONCAT($SYS_,x),%eax; KERNCALL; jb 2b the important part is the beginning of the last line, which for open() corresponds to: mov SYS_open, %eax int $0x80 (where SYS_open is the syscall number for open(), normally 5) the rest is just error handling ('jb 2b' jumps back to the 'jmp cerror' if the system call returns an error) and namespace management (the .weak and .set stuff create two weak aliases, _open and open, for the real syscall name which is __sys_open) most of the complexity comes from the use of macros to hide differences between relocatable and non-relocatable code so that the same definition can be used for both. DES --=20 Dag-Erling Sm=F8rgrav - des@des.no