working of syscall handling
Joseph Koshy
joseph.koshy at gmail.com
Wed Apr 8 08:02:33 PDT 2009
> 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
More information about the freebsd-hackers
mailing list