Android2.3.5-Based System: launch mechanism for Android [4]

Source: Internet
Author: User

**************************************** **************************************** **************************************** ***
Author: EasyWave time: 2013.02.08

Category: Android source code analysis statement: reprinted. Please keep the link

NOTE: If any error occurs, please correct it. These are my Learning Log articles ......

**************************************** **************************************** **************************************** ***

In my blogLearning from android2.3.5: how to activate Android [3]The parsing mechanism of ueventd is described in detail. Before analyzing action_list, action_queue, and service_list in andriod2.3.5, we should first introduce how Andriod calls some functions in the kernel, for example: chown and chroot. Shows the three linked lists in Andriod:

The detailed introduction will be detailed in the subsequent articles, because, before that, you need to first understand the syscall in linux, that is, the system call. Taking the chown command as an example, we will detail how to execute the chown command in Android. In system/core/init/keywords. h, we can see the following definition:

Here, we only analyze the parts in the red circle, and analyze the code in other parts by yourself. They are all similar. Go to the do_chown function and see the following code (in/system/core/init/Builtins. c ):

Go deep and find that chown is chown under bionic \ libc \ arch-arm \ syscils. s file, of course, if it is another platform, the path is different. Here we only discuss the code under the ARM architecture, as shown in:

See it, the end is to call the function address specified by the _ NR_chown32 label, where it is called, we can find the answer from the # include <sys/linux-syscalls.h> above. The following code:

/* auto-generated by gensyscalls.py, do not touch */#ifndef _BIONIC_LINUX_SYSCALLS_H_#if !defined __ASM_ARM_UNISTD_H && !defined __ASM_I386_UNISTD_H#if defined __arm__ && !defined __ARM_EABI__ && !defined __thumb__  #  define __NR_SYSCALL_BASE  0x900000  #else  #  define  __NR_SYSCALL_BASE  0  #endif#define __NR_exit                         (__NR_SYSCALL_BASE + 1)#define __NR_fork                         (__NR_SYSCALL_BASE + 2)#define __NR_clone                        (__NR_SYSCALL_BASE + 120)......#define __NR_chown32                      (__NR_SYSCALL_BASE + 212)#define __NR_lchown32                     (__NR_SYSCALL_BASE + 198)......#ifdef __arm__#define __NR_exit_group                   (__NR_SYSCALL_BASE + 248)#define __NR_waitid                       (__NR_SYSCALL_BASE + 280)#define __NR_vfork                        (__NR_SYSCALL_BASE + 190)#define __NR_openat                       (__NR_SYSCALL_BASE + 322)......#define __NR_ARM_set_tls                  (__NR_SYSCALL_BASE + 983045)#define __NR_ARM_cacheflush               (__NR_SYSCALL_BASE + 983042)#endif#endif#endif /* _BIONIC_LINUX_SYSCALLS_H_

From the code above, we can see that this line of code # define _ NR_chown32 (_ NR_SYSCALL_BASE + 212) is good. This is what we need to know.

In the Unistd. h file in bionic \ libc \ kernel \ arch-arm \ asm, we can also see the following code. Note that this is related to Linux kernel. As follows:

The section in the red circle does not show any name hall. Of course, they all point to the offset address _ NR_SYSCALL_BASE + 212, in linux, the definition is as follows (arch \ arm \ include \ asm \ Unistd. h ):

As you can see, the definitions in the red circle above are the same as those in Andriod. They are all: # define _ NR_chown32 (_ NR_SYSCALL_BASE + 212) offset addresses. Let's take a look at the definition of syscall. The syscall function under the arch \ arm \ kernel \ entry-common.S is called, as shown in:

The syscall Function Code is as follows:

In the end, the # include "CILS. S" file will be added. The CILS. S file mainly defines a sys_call_table table, as shown below:

/** Linux/arch/arm/kernel/CILS. S ** Copyright (C) 1995-2005 Russell King ** This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. ** This file is wrongly ded thrice in entry-common.S * // * 0 */CALL (sys_restart_syscall) CALL (sys_exit) CALL (sys_fork_wrapper) CALL (sys_read) CALL (Sys_write)/* 5 */CALL (sys_open) CALL (sys_close) CALL (sys_ni_syscall)/* was sys_waitpid */CALL (sys_creat) CALL (sys_link )...... /* 210 */CALL (sys_setresgid) CALL (sys_getresgid) CALL (sys_chown) // 212: CALL sys_chown function CALL (sys_setuid) CALL (sys_setgid )...... /* 300 */CALL (sys_semctl) CALL (sys_msgsnd) CALL (sys_msgrcv) CALL (sys_msgget) CALL (sys_msgctl)/* 305 */CALL (sys_shmat) CALL (sys_shmdt) CALL (sys_shmget) CALL (sys_sh Mctl) CALL (sys_add_key)/* 310 */CALL (sys_request_key) CALL (sys_keyctl) CALL (ABI (sys_semtimedop, latency)/* vserver */CALL (sys_ni_syscall) CALL (sys_ioprio_set)/* 315 */CALL (sys_ioprio_get) CALL (sys_inotify_init) CALL (callback) CALL (sys_mbind)/* 320 */CALL (sys_get_mempolicy) CALL (sys_set_mempolicy) CALL (sys_openat) CALL (sys_mkdirat) CALL (sys_mknodat )...... CAL L (sys_preadv) CALL (sys_pwritev) CALL (bytes) CALL (sys_perf_event_open)/* 365 */CALL (sys_recvmmsg) # ifndef inclusyscalls_padding, (nr_syscils + 3 )&~ 3)-nr_syscils # define syscalls_counted # endif. rept syscalls_paddingCALL (sys_ni_syscall). endr

So far, we have learned that the chown command in the Anriod system uses syscall to call the chown function in the Linux kernel. Now we should understand that the other commands are basically the same, in fact, busybox uses an internal method. For details about the syscall call method, you can search for it on the Internet. I will not explain it in detail here.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.