From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 8 15:02:30 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C85681065670 for ; Wed, 8 Apr 2009 15:02:30 +0000 (UTC) (envelope-from joseph.koshy@gmail.com) Received: from wf-out-1314.google.com (wf-out-1314.google.com [209.85.200.169]) by mx1.freebsd.org (Postfix) with ESMTP id 9B3088FC24 for ; Wed, 8 Apr 2009 15:02:30 +0000 (UTC) (envelope-from joseph.koshy@gmail.com) Received: by wf-out-1314.google.com with SMTP id 24so128001wfg.7 for ; Wed, 08 Apr 2009 08:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=djZLrE9ZQK4PcgRH++E068yjbZge7WLf2+nq5gaDUEI=; b=TzXOpa6YGlSuislvPagK9VHTENFyP4f/2Ee08JqAzJeE1kM3DTMY8BP2zbKwDDsg9N 2C3MknOb7QsJDLx8qQCxndhBK8wuFRFgieIMoYJ3eH4auuda9aUx5qiKQrJ5kBW7xAct 9m60Mv5Boz3+JKmjKndoJQLf5wDzfEimb9KUc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=GbWCxozkSndfznxGJbB4rjC5zJcpx4ceeJAaZYkhjTMrsFySrSkNOP2FM9DKo7XkYp ku6U/yVxPf0Ghiy9DfD0KsGwiI/WLvicQQiMh/jRwvnTHb7XCKxEgwTB1ymH/wKMBgEw 4461zoLrycHXwHBVoDrP+xrDvlEsIaN33z54Q= MIME-Version: 1.0 Received: by 10.142.158.3 with SMTP id g3mr490377wfe.29.1239201550092; Wed, 08 Apr 2009 07:39:10 -0700 (PDT) In-Reply-To: <251d650c0904080643o8789860w87c8cca070a16489@mail.gmail.com> References: <251d650c0904080643o8789860w87c8cca070a16489@mail.gmail.com> Date: Wed, 8 Apr 2009 20:09:10 +0530 Message-ID: <84dead720904080739q1d98662ch219899990f66767@mail.gmail.com> From: Joseph Koshy To: Mehul Chadha Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: working of syscall handling X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Apr 2009 15:02:33 -0000 > In the program given below the function readlink gets called up when > printf is executed and the program ends without any output. > > readlink is a system call (syscall number = 58) which is being made by > the printf function, but according to my understanding of system call, > it is made by putting the handler number in eax register and then > interrupting the processor, so that it can enter the kernel mode and > execute the required function, but in this case(dont know why) my > readlink function gets called up which should not have happened. > > I will be very thankful if you can help me with it. > > > #include > > int readlink(void *a, void *b) > { > exit(0); > } > > int main(int argc, char **argv) > { > printf("Hello World"); > } Since you have defined 'readlink' to be a global symbol, the run time linker will satisfy references to the symbol 'readlink' from within libc using the definition you provided. % cc a.c % nm a.out | grep readlink 00000000004006d0 T readlink % gdb a.out ... startup messages snipped ... Breakpoint 1, main (argc=1, argv=0x7fffffffe020) at a.c:11 11 printf("Hello World"); (gdb) b readlink Breakpoint 2 at 0x4006e0: file a.c, line 6. (gdb) c Continuing. Breakpoint 2, readlink (a=0x8007082a9, b=0x7fffffffd660) at a.c:6 6 exit(0); (gdb) bt #0 readlink (a=0x8007082a9, b=0x7fffffffd660) at a.c:6 #1 0x000000080069b87c in _UTF8_init () from /lib/libc.so.6 #2 0x0000000800703343 in __smakebuf () from /lib/libc.so.6 #3 0x00000008007031e8 in __swsetup () from /lib/libc.so.6 #4 0x00000008006f872e in __vfprintf () from /lib/libc.so.6 #5 0x00000008006fbeae in vfprintf () from /lib/libc.so.6 #6 0x00000008006e8eca in printf () from /lib/libc.so.6 #7 0x000000000040070e in main (argc=1, argv=0x7fffffffe020) at a.c:11 (gdb) Regards, Koshy