Date: Thu, 2 Nov 2000 12:16:34 +0200 (SAST) From: Robert Nordier <rnordier@nordier.com> To: adam@whizkidtech.net (G. Adam Stanislav) Cc: hackers@FreeBSD.org Subject: Re: Kernel calls, are they documented somewhere? Message-ID: <200011021016.MAA93760@siri.nordier.com> In-Reply-To: <20001102001056.A276@whizkidtech.net> from "G. Adam Stanislav" at Nov 02, 2000 12:10:56 AM
next in thread | previous in thread | raw e-mail | index | archive | help
G. Adam Stanislav wrote:
> On Thu, Nov 02, 2000 at 12:12:02AM -0500, Michael Bacarella wrote:
> >gcc does not generate code that can make FreeBSD system calls directly.
> >Most system calls as we know them by the manual have corresponding
> >wrappers in libc. See /usr/src/lib/libc if you have the source installed.
>
> I do have the source code, and I have studied it, but it is uncommented.
> And, it seems, not all of it is included. For example, there is a
> /usr/src/lib/libc/sys/open.2 but no corresponding open.c. I have been
> unable to find the source code for open() in libc. There is an open.c
> in /usr/src/lib/libstand/ but it makes no system calls. Actually, it
> looks like a system call (it assigns its own file descriptors to files
> it opens), but it does not behave like our kernel (since it returns -1
> on errors, while our kernel has been returning 2 in my tests when trying
> to open a non-existing file as O_RDONLY:
>
> sub eax, eax ; EAX = 0 = O_RDONLY
> push eax
> push eax
> push esi ; points at file name
> push eax ; fake return address
> int 80h
> add esp, byte 16
>
> (That's NASM syntax.) If the file exists, I get a file descriptor in EAX,
> otherwise EAX = 2. It would be nice if I could get some kind of formal
> confirmation that this is how it is supposed to be, and that all FreeBSD
> versions behave like that.
Here's open(2) implemented as a C function:
open: mov $0x5,%eax
int $0x80
jc .L1
ret
.L1: jmp __cerror
__cerror: mov %eax,errno
mov $-1,%eax
ret
The idea is to check the carry flag, since the kernel returns two
different things in %eax, depending on whether an error has
occurred. Our function maintains errno, since this is how things
are done in the C library.
If you need more info, e-mail me directly.
--
Robert Nordier
rnordier@nordier.com
rnordier@FreeBSD.org
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200011021016.MAA93760>
