On Wednesday 07 March 2007 00:32, Haifeng He wrote: > Hi, > > I am beginner of UML. I have a question about how the system call > trap happens in UML in skas0 mode. Suppose a user application > within UML initialed a system call. How does UML track the > system call and is the host OS the one to actually handle the system > call?
The base tool is ptrace (see man 2 ptrace). Basically ptrace(PTRACE_SYSCALL) (also used by the strace tool - look at man strace) is used to intercept the syscalls to the host. Registers are modified so that getpid() is executed (it is a syscall doing no harm), and the syscall is then executed by the UML kernel. arch/um/os-Linux/skas/process.c contains the core code: the main loop in userspace() runs for the process lifetime, once for each process. handle_trap() does the above trick with getpid and ptrace and calls handle_syscall(), which performs the actual syscall. Assume local_using_sysemu == 0; that does not change the core, it's just a faster API to tell the host "don't execute this syscall" than changing the syscall to getpid(). No difference about this exists in SKAS0 and SKAS3, that I remember (I think it's also valid for TT mode, with a few differences). > Particularly, I found a file: arch/um/sys-i386/stub.S. Is the file used > for handling syscalls in user application? No. That code is injected in all user applications within UML. When we need that the user process does a certain syscall, we change EIP to point to that piece of code, write the syscalls to perform and their arguments in a fixed location, and resume the process with ptrace(). The 'virtual RAM' of a UML instance is represented by a file, which is mapped with MAP_SHARED. So, memory mappings for userspace processes are installed by making that stub call mmap() with certain arguments decided by UML; munmap() and mprotect() are also used. Since demand paging is used, when mmap is called no mapping is installed; when a page is allocated and page tables are modified, we can call mmap() to install the mapping. > Can somebody explain the > process to me? The above is just a little start, to let you explore more and ask more specific questions. Bye -- Inform me of my mistakes, so I can add them to my list! Paolo Giarrusso, aka Blaisorblade http://www.user-mode-linux.org/~blaisorblade Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ User-mode-linux-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
