From owner-freebsd-hackers@FreeBSD.ORG Mon Nov 8 19:00:07 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 F347016A4CE for ; Mon, 8 Nov 2004 19:00:06 +0000 (GMT) Received: from mail835.megamailservers.com (mail835.carrierinternetsolutions.com [69.49.106.45]) by mx1.FreeBSD.org (Postfix) with ESMTP id 52D5443D49 for ; Mon, 8 Nov 2004 19:00:06 +0000 (GMT) (envelope-from strick@covad.net) X-POP-User: strick.covad.net Received: from mist.nodomain (h-67-101-150-200.snfccasy.dynamic.covad.net [67.101.150.200])iA8Iv8EF004132; Mon, 8 Nov 2004 13:57:09 -0500 Received: from mist.nodomain (localhost [127.0.0.1]) by mist.nodomain (8.12.11/8.12.11) with ESMTP id iA8Iv8rQ000577; Mon, 8 Nov 2004 10:57:08 -0800 (PST) (envelope-from dan@mist.nodomain) Received: (from dan@localhost) by mist.nodomain (8.12.11/8.12.11/Submit) id iA8Iv725000576; Mon, 8 Nov 2004 10:57:07 -0800 (PST) (envelope-from dan) Date: Mon, 8 Nov 2004 10:57:07 -0800 (PST) From: Dan Strick Message-Id: <200411081857.iA8Iv725000576@mist.nodomain> To: freebsd-hackers@freebsd.org cc: simon@comsys.ntu-kpi.kiev.ua cc: dan@mist.nodomain 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: Mon, 08 Nov 2004 19:00:07 -0000 On Sun, 7 Nov 2004 16:29:42 -0800 (PST), I wrote: > > Does anyone know where the system calls are really defined? > I followed open() to _open() to __sys_open() which seems > to be part of something called libc_r before I ran into a > blank wall. I grepped all of the regular files in /usr/src > and /usr/include and turned up nothing. I even tried > grepping for open in the output of "nm -g /usr/lib/libc.a". > There is no __sys_open() in libc. Am I dealing with > C-compiler magic? Secret macro instructions invoking > undocumented gnu C-compiler asm() features? A CIA plot? > Perhaps I did not make it clear that I was looking for the definitions of the subroutines in libc that converted C-language function calls, such as open(), into assembler language system calls. For example, in version 7 pdp11 unix, the open() system call was defined in the very straight forward assembler language program /usr/src/libc/sys/open.s: / C library -- open / file = open(string, mode) / file == -1 means error .globl _open, .globl cerror .open = 5. _open: mov r5,-(sp) mov sp,r5 mov 4(r5),0f mov 6(r5),0f+2 sys 0; 9f bec 1f jmp cerror 1: mov (sp)+,r5 rts pc .data 9: sys .open; 0:..; .. Being unable to find any analogous code in FreeBSD (release 4.10), I surmised it was done with multiple layers of highly complex cpp macro instructions constructing a highly complex asm() statement that was compiled in-line and never visible in a source file because it existed only momentarily during compilation in the byte stream passed from the c-preprocessor to the first phase of the c-compiler. On Mon, 8 Nov 2004 13:14:08 +0200, Andrey Simonenko responded: > > You didn't say the version of FreeBSD you use (I guess > that you use 4.x). > > __sys_open is an entry name for open() syscall and it (and most > of other ones) is "constructed" in the /usr/src/lib/libc/i386/SYS.h > file for i386, check it. > 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. Thanks to all of you who responded to my question. Dan Strick strick@covad.net