Date: Tue, 09 Nov 2004 02:20:18 +0100 From: des@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) To: Dan Strick <strick@covad.net> Cc: simon@comsys.ntu-kpi.kiev.ua Subject: Re: Where is the source to the system calls? Message-ID: <xzp654f7r8t.fsf@dwp.des.no> In-Reply-To: <200411081857.iA8Iv725000576@mist.nodomain> (Dan Strick's message of "Mon, 8 Nov 2004 10:57:07 -0800 (PST)") References: <200411081857.iA8Iv725000576@mist.nodomain>
next in thread | previous in thread | raw e-mail | index | archive | help
Dan Strick <strick@covad.net> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzp654f7r8t.fsf>