execution process problem

Hi , I know little about the system call

I write a test file hello.c

[code]#include<stdio.h>

int main()

{

printf("hello");

return 0;

}

[/code]

I use the dtrace to probe the system call mmap, and found this syscall has been invoked twice during the execution, and I print tout he stack.

first invoke

libc.so.1`mmap+0xc

libc.so.1`lmalloc+0xa4

libc.so.1`atexit+0x1c

libc.so.1`libc_init+0x44

ld.so.1`call_init+0x70

ld.so.1`setup+0x13ac

ld.so.1`_setup+0x3b0

ld.so.1`_rt_boot+0x88

second :

ld.so.1`mmap+0xc

ld.so.1`file_open+0x2e0

ld.so.1`find_path+0x170

ld.so.1`load_so+0x210

ld.so.1`load_path+0x68

ld.so.1`_elf_lookup_filtee+0x4b8

ld.so.1`elf_lookup_filtee+0x90

ld.so.1`elf_find_sym+0x310

ld.so.1`_lookup_sym+0x60

ld.so.1`lookup_sym+0x240

ld.so.1`elf_bndr+0x14c

ld.so.1`elf_rtbndr+0x10

libc.so.1`0xff369288

libc.so.1`_ndoprnt+0x32c

libc.so.1`printf+0xf4

hello`main+0xc

hello`_start+0x5c

who can explain it, why system call mmap twice, and echo for what?

[1209 byte] By [shock_ua] at [2007-11-27 0:13:57]
# 1

You'll find most precise answers by looking at the code:

http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen /atexit.c

(line 100, impl. of atexit)

http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/thr eads/alloc.c#179

(impl. of lmalloc)

http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen /catopen.c#280

(impl. of file_open)

MaximKartasheva at 2007-7-11 21:58:26 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
I checked the code, my rough concept is the first call is to init the thread, and the second call is for "[code]printf[/code]"so solaris use mmap to implement mallocand then use mmap for IO operationam I right?
shock_ua at 2007-7-11 21:58:26 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3

>so solaris use mmap to implement malloc

lmalloc(), which is internal libc function; see malloc implementation here:

http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen /malloc.c

>and then use mmap for IO operation

>am I right?

Yes, and in a hundreds of other places as well. See http://cvs.opensolaris.org/source/search?q=&defs=&refs=mmap&path=&# 38;hist=&project=%2Fonnv

MaximKartasheva at 2007-7-11 21:58:26 > top of Java-index,Development Tools,Solaris and Linux Development Tools...