working of syscall handling
Hello all, I have a doubt in understanding the working of the freebsd OS. 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. #includestdio.h int readlink(void *a, void *b) { exit(0); } int main(int argc, char **argv) { printf(Hello World); } ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: working of syscall handling
In the last episode (Apr 08), Mehul Chadha said: 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. Readlink is not only a syscall, but a POSIX library function. You are overriding that, and FreeBSD's malloc function uses readlink to read the /etc/malloc.conf settings file. printf calls malloc, so that's why your program exits. http://www.opengroup.org/onlinepubs/9699919799/functions/readlink.html I will be very thankful if you can help me with it. #includestdio.h int readlink(void *a, void *b) { exit(0); } int main(int argc, char **argv) { printf(Hello World); } -- Dan Nelson dnel...@allantgroup.com ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org
Re: working of syscall handling
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. #includestdio.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 004006d0 T readlink % gdb a.out ... startup messages snipped ... Breakpoint 1, main (argc=1, argv=0x7fffe020) 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=0x7fffd660) at a.c:6 6exit(0); (gdb) bt #0 readlink (a=0x8007082a9, b=0x7fffd660) at a.c:6 #1 0x00080069b87c in _UTF8_init () from /lib/libc.so.6 #2 0x000800703343 in __smakebuf () from /lib/libc.so.6 #3 0x0008007031e8 in __swsetup () from /lib/libc.so.6 #4 0x0008006f872e in __vfprintf () from /lib/libc.so.6 #5 0x0008006fbeae in vfprintf () from /lib/libc.so.6 #6 0x0008006e8eca in printf () from /lib/libc.so.6 #7 0x0040070e in main (argc=1, argv=0x7fffe020) at a.c:11 (gdb) Regards, Koshy ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org