Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Apr 2009 20:09:10 +0530
From:      Joseph Koshy <joseph.koshy@gmail.com>
To:        Mehul Chadha <mehulc87@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: working of syscall handling
Message-ID:  <84dead720904080739q1d98662ch219899990f66767@mail.gmail.com>
In-Reply-To: <251d650c0904080643o8789860w87c8cca070a16489@mail.gmail.com>
References:  <251d650c0904080643o8789860w87c8cca070a16489@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> 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<stdio.h>
>
> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?84dead720904080739q1d98662ch219899990f66767>