Date: Mon, 8 Nov 2004 10:57:07 -0800 (PST) From: Dan Strick <strick@covad.net> To: freebsd-hackers@freebsd.org Cc: dan@mist.nodomain Subject: Re: Where is the source to the system calls? Message-ID: <200411081857.iA8Iv725000576@mist.nodomain>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200411081857.iA8Iv725000576>