Kernel Random notes--system call here refers to the arm Linux architecture (Android4.4)
1,referenhttp://blog.csdn.net/myarrow/article/details/70362661.1, this is a more comprehensive story. After reading, you can roughly tell the process of system call
"System call is the user people through the SWI instruction into the kernel, the CPU from user mode into the SVC mode process, the process is basically to back up the current task context (the corresponding stack information), and then through the parameters of the SWI directive, to find the corresponding system call table, execute the system call, Write the return value in the specified register, restore the original scene, complete the system call "1.2, but also the difference between the system call and the common API (mainly is not trapped in the kernel state)
http://blog.csdn.net/myarrow/article/details/7036215 the list of Linux system calls is listed here for reference
2, I understand. Take Clone () as an example 2.1 API some do not need system calls, such as Math.h inside. Some need, such as the next pthread.h2.2 in user space. Create a thread that has the following API calls:#include <pthread.h>pthread_create(&tid, &attr, THR_FN, NULL);=> $android _root/bionic/libc/include/pthrea.h intpthread_create(pthread_t *thread, pthread_attr_t const * attr, void * (*start_routine) (void *), void * arg);=> $adnroid _root/bionic/libc/bionic/pt Hread_create.cpp intpthread_create(pthread_t* thread_out, pthread_attr_t const* attr,
void* (*start_routine) (void*), void* arg) {... int tid =
__pthread_clone(Start_routine, Child_stack, Flags, arg);//Final Call here}=>bionic/libc/arch-arm/bionic/clone.s this is done by assembly. int __pthread_clone (void* (*FN) (void*), void* child_stack, int flags, void* arg); ENTRY (__pthread_clone) # Push ' fn ' and ' arg ' onto ' child_stack '.
Stmdb r1!, {r0, r3}
# The Sys_clone system call is only takes, arguments: ' Flags ' and ' child_stack '.
# ' Child_stack ' is already in R1, but we need to move ' flags ' into position.
mov r0, R2
# System call.
mov IP, R7
Ldr R7, =__nr_clone//The system call number is defined in theUnistd.h #define __nr_clone (__nr_syscall_base+120), 120th write R7
SWI #0//ThroughSWISoft interrupt instruction trapped in kernel
...END (__pthread_clone)
2.3 In the kernel space first processes the SWI instruction $kernel_root/arch/arm/kernel/entry-common. s/*=============================================================================
* SWI Handler
*-----------------------------------------------------------------------------
*/
. Align 5
ENTRY (VECTOR_SWI)
Sub sp, SP, #S_FRAME_SIZE
Stmia sp, {r0-r12} @ calling R0-r12
ARM (add R8, SP, #S_PC)
ARM (Stmdb R8, {sp, lr}^) @ calling SP, LR
THUMB (mov r8, SP)
THUMB (Store_user_sp_lr R8, R10, s_sp) @ calling SP, LR
Mrs R8, SPSR @ called from Non-fiq mode, so OK.
str LR, [sp, #S_PC] @ Save calling PC
Str R8, [sp, #S_PSR] @ Save CPSR
STR r0, [sp, #S_OLD_R0] @ Save old_r0
ZERO_FP ... Addne Scno, R7, #__NR_SYSCALL_BASE @ put OS number in//read the system call from R7 ... adr tbl, sys_call_table @ load SYSCALL Table pointer//And then according to the system call number, query sys_call_table This table, find the corresponding system callENTRY (sys_call_table)
#include "calls. S "Sys_call_table is calls. S=>calls. s.../* */Call (Sys_clone)//120 corresponds to Sys_clone ... =>entry-common. S LDRCC pc, [TBL, Scno, LSL #2] @ call sys_* routine//perform system calls here.
So where do you realize the Sys_clone? Different system calls, in different directories, compare Open is under fs/, clone is under kernel. Use the macro syscall_define to work together. =>kernel/fork.c#ifdef __arch_want_sys_clone
#ifdef Config_clone_backwards
Syscall_define5 (clone, unsigned long, clone_flags, unsigned long, newsp,
int __user *, parent_tidptr,
int, Tls_val,
int __user *, child_tidptr)
#elif defined (CONFIG_CLONE_BACKWARDS2)
Syscall_define5 (clone, unsigned long, newsp, unsigned long, clone_flags,
int __user *, parent_tidptr,
int __user *, child_tidptr,
int, tls_val)
#elif defined (CONFIG_CLONE_BACKWARDS3)
Syscall_define6 (clone, unsigned long, clone_flags, unsigned long, newsp,
int, stack_size,
int __user *, parent_tidptr,
int __user *, child_tidptr,
int, tls_val)
#else
Syscall_define5 (clone, unsigned long, clone_flags, unsigned long, newsp,
int __user *, parent_tidptr,
int __user *, child_tidptr,
int, tls_val)
#endif
{
Return
do_fork(Clone_flags, newsp, 0, Parent_tidptr, child_tidptr);
}
#endif and finally call Forkc.c/do_fork (). The whole process is like this, through the process, there is a need to have the energy to go into the details.
Kernel Random notes--system call