From owner-freebsd-hackers@FreeBSD.ORG Fri May 10 19:31:27 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 2B400871 for ; Fri, 10 May 2013 19:31:27 +0000 (UTC) (envelope-from k.dreger@yahoo.de) Received: from nm17.bullet.mail.ird.yahoo.com (nm17.bullet.mail.ird.yahoo.com [77.238.189.70]) by mx1.freebsd.org (Postfix) with SMTP id 4D0662D3 for ; Fri, 10 May 2013 19:31:25 +0000 (UTC) Received: from [77.238.189.238] by nm17.bullet.mail.ird.yahoo.com with NNFMP; 10 May 2013 19:31:24 -0000 Received: from [212.82.98.68] by tm19.bullet.mail.ird.yahoo.com with NNFMP; 10 May 2013 19:31:24 -0000 Received: from [127.0.0.1] by omp1005.mail.ir2.yahoo.com with NNFMP; 10 May 2013 19:31:24 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 703092.71468.bm@omp1005.mail.ir2.yahoo.com Received: (qmail 33459 invoked by uid 60001); 10 May 2013 19:31:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1368214284; bh=2hzWxu9PkyXuwJLKUarf/Ldx3gRMkfzHVF4rOKfcVdE=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=e0WAQiM1gpZD9edQTe+1R/t3F9Wk2//vWYeqrEt6VsyNQRZgioP/5RRHJ87JK7bCKZeYznsC0QM5LQz4/HId4U4Hy9qF5WYVYjt6r+QQWgVgc+442faLp/9spSRbd29B4kUG+UbG6jVCOLOic7aUJYlcL9YOrvvcuO6jSSmbG/o= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.de; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=fIiZCysih6KMM7UwL8ckrNs3ohdCPYHxF8xzZxHUCKHPYLdcX2JKBBvfcgql8hyUk/dg7QOsKwS+ixN5MfAAYa0nPCYauDuW79gqN0WAxPL8qQLpuwT93lro0jluSyjOkNgrsYLCopkarpx86gYiMofeT7fDFvpfxVjNC9dOnIc=; X-YMail-OSG: hnnn5rcVM1kpXLJ2XTldQcP3OvisWytb.gaAiBIotJa_Axs e_LL.N2GF8LwuhD4JuFb8cJ26gQDaxOUiokxxWoqBjeNeAr_PP1siPjeirdF i38x8bzyMepgXWDmU_FMI0KDFhzTqKiPxNi5wXiCNB6JL.dj6UHO6t22BrhZ 327DEkhpoN41iGDkogyCeQW7QY56mBvGQxqt9iTgqUdJaikgKcF1I2NycMuj 1L_gaEdyXeCBZvt6kiJWy5Dgsr_MJ4P5JNBuWrJPKwbP5GyfOEaJB9p2O4rK b5jJtyXytn0RlIpcJajuiDhYzA5YXlY1Ztd08bVrEHYC2UCvUoumAzOwfZVV ebg3EiVwC5zS3zDHSyRcHV97NN.UcqqimA3TrkYJa4i8c47Nl_jSVzp0_B8y IVluI7vkVgf1EvSA.W2Q_oHBm3jE- Received: from [222.223.72.19] by web171503.mail.ir2.yahoo.com via HTTP; Fri, 10 May 2013 20:31:24 BST X-Rocket-MIMEInfo: 002.001, SGVsbG8sCkkgaGF2ZSBiZWVuIHRha2luZyBhIGxvb2sgYXQgYSBmZXcgc3lzY2FsbHMgaW4gL3Vzci9zcmMvc3lzL2tlcm4vIGFuZAphbHdheXMgZmluZCB0aGF0IGluIHRoZWlyIGFjdHVhbGwgYyBkZWZpbml0aW9uIHRoZSBmdW5jdGlvbiBuYW1lcyBhcmUKcHJlcHJlbmRlZCBieSBhIHN5c18uIFRha2UgZm9yIGV4YW1wbGUgdGhlIGZvcmsgc3lzdGVtIGNhbGwgd2hpY2gKaXMgZm91bmQgaW4gL3Vzci9zcmMvc3lzL2tlcm4va2Vybl9mb3JrLmMKCmludApzeXNfZm9yayhzdHJ1Y3QgdGhyZWFkICp0ZCwgc3QBMAEBAQE- X-Mailer: YahooMailWebService/0.8.141.536 References: Message-ID: <1368214284.29611.YahooMailNeo@web171503.mail.ir2.yahoo.com> Date: Fri, 10 May 2013 20:31:24 +0100 (BST) From: Karl Dreger Subject: syscall to userland interface To: "freebsd-hackers@freebsd.org" MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Karl Dreger List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 May 2013 19:31:27 -0000 Hello,=0AI have been taking a look at a few syscalls in /usr/src/sys/kern/ = and=0Aalways find that in their actuall c definition the function names are= =0Apreprended by a sys_. Take for example the fork system call which=0Ais f= ound in /usr/src/sys/kern/kern_fork.c=0A=0Aint=0Asys_fork(struct thread *td= , struct fork_args *uap)=0A...=0A=0ANow when I write a program from userlan= d, that makes use of the =0Afork system call, then if call it as:=0A=0Afork= ();=0A=0AAll the syscall are part of libc, which is usually defined in =0A/= usr/src/lib/libc/=0A=0ASince the system calls are already defined in the ke= rnel sources, they =0Ano longer need to be defined in /usr/src/lib/libc/. T= his is the reason =0Awhy one can only find the manpages and no c files in = =0A/usr/src/lib/libc/sys?=0AAt least this is how my thinking goes.=0A=0ANow= , when the syscalls in the kernel sources are all defined as sys_xxx =0Abut= are invoked as xxx and the c headers also show syscall prototypes =0Awitho= ut any prepended sys. How does the actual user-, kernelland =0Amove happen?= In other words, why do I invoke fork() as fork() and=0Anot as sys_fork()?= =0A=0AOr is there something that I missed?=0A=0A=0AClarification on that po= int is highly welcome.=0A=0AThanks=0A From owner-freebsd-hackers@FreeBSD.ORG Fri May 10 19:37:07 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 9CF35B4C for ; Fri, 10 May 2013 19:37:07 +0000 (UTC) (envelope-from bright@mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 8EBCB31B for ; Fri, 10 May 2013 19:37:06 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-67-180-208-218.hsd1.ca.comcast.net [67.180.208.218]) by elvis.mu.org (Postfix) with ESMTPSA id DB7DB1A3D0F; Fri, 10 May 2013 12:37:05 -0700 (PDT) Message-ID: <518D4C4F.90902@mu.org> Date: Fri, 10 May 2013 12:36:47 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: Karl Dreger Subject: Re: syscall to userland interface References: <1368214284.29611.YahooMailNeo@web171503.mail.ir2.yahoo.com> In-Reply-To: <1368214284.29611.YahooMailNeo@web171503.mail.ir2.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: "freebsd-hackers@freebsd.org" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 May 2013 19:37:07 -0000 On 5/10/13 12:31 PM, Karl Dreger wrote: > Hello, > I have been taking a look at a few syscalls in /usr/src/sys/kern/ and > always find that in their actuall c definition the function names are > preprended by a sys_. Take for example the fork system call which > is found in /usr/src/sys/kern/kern_fork.c > > int > sys_fork(struct thread *td, struct fork_args *uap) > ... > > Now when I write a program from userland, that makes use of the > fork system call, then if call it as: > > fork(); > > All the syscall are part of libc, which is usually defined in > /usr/src/lib/libc/ > > Since the system calls are already defined in the kernel sources, they > no longer need to be defined in /usr/src/lib/libc/. This is the reason > why one can only find the manpages and no c files in > /usr/src/lib/libc/sys? > At least this is how my thinking goes. > > Now, when the syscalls in the kernel sources are all defined as sys_xxx > but are invoked as xxx and the c headers also show syscall prototypes > without any prepended sys. How does the actual user-, kernelland > move happen? In other words, why do I invoke fork() as fork() and > not as sys_fork()? > > Or is there something that I missed? > > > Clarification on that point is highly welcome. When you build the system a whole bunch of assembler files are automatically generated that define the functions you are looking for. Look for .S files under the object directory. Those assembler files have the magic to cause a system call to happen. example: src/lib/libc/getauid.S (note, this file is GENERATED, it's not part of src.) -Alfred