Android_android系统启动流程_1_init进程启动流程/4 Init进程启动第三阶段 February 27, 2025 2 minute read 页-1 其他片段.263 工作表.265 5.解析init.rc等文件 & action触发运行rc文件 5.解析init.rc等文件 &action触发运行rc文件 其他片段.247 工作表.248 4.加载属性 & 启动属性服务监听属性请求 4.加载属性 &启动属性服务监听属性请求 其他片段.190 工作表.191 3.信号处理 3.信号处理 其他片段.163 工作表.164 2.Selinux第二阶段初始化 2.Selinux第二阶段初始化 其他片段.131 工作表.132 1.初始化属性 1.初始化属性 Actor lifeline system/core/init/main.cpp 工作表.2 工作表.3 工作表.4 system/core/init/main.cpp Object lifeline system/core/init/init.cpp 工作表.6 工作表.7 工作表.8 工作表.9 system/core/init/init.cpp Object lifeline.54 system/core/init/util.cpp 工作表.11 工作表.12 工作表.13 工作表.14 system/core/init/util.cpp Activation 激活.16 激活.17 Message.21 SecondStageMain SecondStageMain 消息.132 property_init property_init Object lifeline.150 bionic/libc/system_properties/system_properties.cpp 工作表.22 工作表.23 工作表.24 工作表.25 bionic/libc/system_properties/system_properties.cpp 激活.157 其他片段 工作表.28 init进程启动第三阶段 -- SecondStageMain init进程启动第三阶段 -- SecondStageMain Object lifeline.42 system/core/init/property_service.cpp 工作表.31 工作表.32 工作表.33 工作表.34 system/core/init/property_service.cpp 激活.47 消息.48 CreateSerializedPropertyInfo CreateSerializedPropertyInfo 激活.37 消息.38 __system_property_area_init __system_property_area_init 消息.59 InitKernelLogging InitKernelLogging 黄色便条.77 初始化kernel日志系统不再赘述 初始化kernel日志系统(不再赘述) 黄色便条.42 第一阶段在上一步骤 (第一阶段在上一步骤) Object lifeline.86 bionic/libc/system_properties/contexts_serialized.cpp 工作表.44 工作表.45 工作表.46 工作表.47 bionic/libc/system_properties/contexts_serialized.cpp 激活.91 激活.103 消息.104 process_kernel_dt process_kernel_dt Object lifeline.107 bionic/libc/bionic/system_property_api.cpp 工作表.56 工作表.57 工作表.58 工作表.59 bionic/libc/bionic/system_property_api.cpp 激活.112 黄色便条.114 处理并赋值内核dt设备树、cmdline、boot的一些property属性ro属性 处理并赋值内核dt设备树、cmdline、boot的一些property属性(ro属性) 消息.117 2SelabelInitialize (2)SelabelInitialize 黄色便条.77 首先通过mkdir创建"/dev/__properties__"目录 首先通过mkdir创建"/dev/__properties__"目录 消息.78 AreaInit AreaInit 消息.79 Initialize Initialize 激活.80 消息.81 InitializeProperties() InitializeProperties() Object lifeline.82 bionic/libc/system_properties/contexts_serialized.cpp 工作表.83 工作表.84 工作表.85 工作表.86 bionic/libc/system_properties/contexts_serialized.cpp 激活.87 消息.88 LoadDefaultPath() LoadDefaultPath() 激活.89 消息.90 LoadPath("/dev/__properties__/property_info") LoadPath("/dev/__properties__/property_info") 黄色便条.91 通过mmap将"/dev/__properties__/property_info"加载到共享内存 通过mmap将"/dev/__properties__/property_info"加载到共享内存 激活.92 消息.93 process_kernel_cmdline process_kernel_cmdline 激活.94 消息.95 export_kernel_boot_props export_kernel_boot_props 激活.96 消息.97 1SelinuxSetupKernelLogging (1)SelinuxSetupKernelLogging 黄色便条.100 参照InitKernelLogging此处就是将加载Selinux的日志在kernel内核中打印不再赘述 参照InitKernelLogging,此处就是将加载Selinux的日志在kernel内核中打印(不再赘述) Object lifeline.103 system/core/init/selinux.cpp 工作表.104 工作表.105 工作表.106 工作表.107 system/core/init/selinux.cpp Object lifeline.109 external/selinux/libselinux/src/android/android_platform.c 工作表.110 工作表.111 工作表.112 工作表.113 external/selinux/libselinux/src/android/android_platform.c 激活.114 激活.115 消息.116 selinux_android_file_context_handle selinux_android_file_context_handle 黄色便条.118 将四个目录下的file_contexts文件添加到seopts_file容器中 1./system/etc/selinux... 将四个目录下的file_contexts文件添加到seopts_file容器中:1./system/etc/selinux/plat_file_contexts2./product/etc/selinux/product_file_contexts3./vendor/etc/selinux/vendor_file_contexts4./odm/etc/selinux/odm_file_contexts) 激活.119 消息.120 selinux_android_file_context selinux_android_file_context Object lifeline.121 external/selinux/libselinux/src/label.c 工作表.122 工作表.123 工作表.124 工作表.125 external/selinux/libselinux/src/label.c Object lifeline.126 external/selinux/libselinux/src/label_file.c 工作表.127 工作表.128 工作表.129 工作表.130 external/selinux/libselinux/src/label_file.c 黄色便条 读取几个目录下的属性上下文文件写入到"/dev/__properties__/property_info" 1./syst... 读取几个目录下的属性上下文文件写入到"/dev/__properties__/property_info":1./system/etc/selinux/plat_property_contexts2./vendor/etc/selinux/vendor_property_contexts3./product/etc/selinux/product_property_contexts4./odm/etc/selinux/odm_property_contexts 激活.134 消息.135 selabel_open selabel_open 黄色便条.136 分配一块内存将入参即file_context文件列表内容写到这块内存中 分配一块内存,将入参即file_context文件列表内容写到这块内存中 激活.137 消息.138 initfuncs initfuncs 激活.140 黄色便条.139 调用到第一个方法CONFIG_FILE_BACKEND(selabel_file_init) 调用到第一个方法CONFIG_FILE_BACKEND(selabel_file_init) 消息.141 selabel_file_init selabel_file_init 激活.142 消息.143 init init 激活.144 消息.145 process_file process_file 激活.146 消息.147 process_text_file process_text_file 黄色便条.148 解析每行data内容 解析每行data内容 消息.149 selinux_android_restorecon selinux_android_restorecon 消息.150 3SelinuxRestoreContext (3)SelinuxRestoreContext 激活.151 消息.152 selinux_android_restorecon_common selinux_android_restorecon_common 激活.153 消息.154 restorecon_sb restorecon_sb 激活.156 消息.157 pkgdir_selabel_lookup pkgdir_selabel_lookup 激活.158 消息.159 seapp_context_lookup seapp_context_lookup 黄色便条.160 根据UIDisSystemServerseinfo,pkgname等信息匹配/seapp_contexts的规则完全符合的... 根据UID,isSystemServer,seinfo,pkgname等信息匹配/seapp_contexts的规则,完全符合的项会被用来设置新的context_t,保存在最后一个入参ctx中。seinfo就是“platform”或“android”,根据apk是否拥有系统签名而定 黄色便条.161 第二段初始化解析所有file_contexts 第二段初始化,解析所有file_contexts 黄色便条.162 恢复安全上下文 恢复安全上下文 Object lifeline.168 system/core/init/epoll.cpp 工作表.169 工作表.170 工作表.171 工作表.172 system/core/init/epoll.cpp Object lifeline.173 system/core/init/sigchld_handler.cpp 工作表.174 工作表.175 工作表.176 工作表.177 system/core/init/sigchld_handler.cpp 激活.178 消息.179 InstallSignalFdHandler InstallSignalFdHandler 消息.181 RegisterHandler RegisterHandler 激活.183 消息.182 InstallSignalFdHandler InstallSignalFdHandler 黄色便条.184 通过epoll机制监听SIGHLD信号处理子进程防止僵尸进程 通过epoll机制监听SIGHLD信号,处理子进程防止僵尸进程 激活.185 消息.186 ReapAnyOutstandingChildren ReapAnyOutstandingChildren 激活.187 消息.188 ReapOneProcess ReapOneProcess 黄色便条.189 处理出现问题的子进程 1.用waitpid找出挂掉进程的Pid 2.根据pid找到对应Service 3.调用Servic... 处理出现问题的子进程:1.用waitpid找出挂掉进程的Pid2.根据pid找到对应Service3.调用Service的Reap方法清除资源,根据进程对应的类型,决定是否重启机器或重启进程 Object lifeline.193 system/core/init/property_service.cpp 工作表.194 工作表.195 工作表.196 工作表.197 system/core/init/property_service.cpp 激活.198 消息.199 (1)property_load_boot_defaults (1)property_load_boot_defaults 激活.201 消息.202 load_properties_from_file load_properties_from_file 激活.203 消息.204 LoadProperties LoadProperties 黄色便条.205 Step 1 加载各个目录的.prop文件将prop文件的属性遍历写到properties键值对变量中 Step 1: 加载各个目录的.prop文件,将prop文件的属性遍历写到properties键值对变量中 激活.206 消息.207 PropertySet PropertySet 黄色便条.208 Step 2 遍历properties对每个属性调用PropertySet方法存入属性到系统中 Step 2: 遍历properties,对每个属性调用PropertySet方法存入属性到系统中 Object lifeline.210 bionic/libc/bionic/system_property_api.cpp 工作表.211 工作表.212 工作表.213 工作表.214 bionic/libc/bionic/system_property_api.cpp 消息.215 __system_property_update更新/__system_property_add新增 __system_property_update更新/__system_property_add新增 激活.216 激活.217 消息.218 property_initialize_ro_product_props property_initialize_ro_product_props 激活.219 消息.220 PropertySet PropertySet 激活.223 消息.224 property_derive_build_fingerprint property_derive_build_fingerprint 激活.225 消息.226 PropertySet PropertySet 黄色便条.227 Step 3 初始化ro.product.***属性遍历调用PropertySet Step 3: 初始化ro.product.***属性(遍历调用PropertySet) 黄色便条.228 Step 4 设置编译相关属性遍历调用PropertySet Step 4: 设置编译相关属性(遍历调用PropertySet) 激活.229 消息.230 update_sys_usb_config update_sys_usb_config 激活.231 消息.232 property_set property_set 黄色便条.233 Step 4 设置usb属性persist.sys.usb.config Step 4: 设置usb属性persist.sys.usb.config 消息.234 (2)StartPropertyService (2)StartPropertyService 激活.235 消息.236 CreateSocket CreateSocket 激活.237 消息.238 listen listen 激活.239 消息.240 epoll->RegisterHandler(..., handle_property_set_fd) epoll->RegisterHandler(..., handle_property_set_fd) 激活.241 消息.242 HandlePropertySet HandlePropertySet 黄色便条.243 1.创建socket监听系统属性请求 2.注册epoll handler处理机制收到属性请求调用handle_proper... 1.创建socket监听系统属性请求2.注册epoll handler处理机制,收到属性请求调用handle_property_set_fd3.最终也是调用到property_set处理属性新增/更新请求 激活.244 消息.245 property_set property_set 激活.255 消息.257 LoadBootScripts LoadBootScripts 激活.258 消息.259 QueueEventTrigger QueueEventTrigger 激活.260 消息.261 ExecuteOneCommand ExecuteOneCommand 黄色便条.262 Step 1. 依次解析/init.rc、/system/etc/init、/Vendor/etc/init的rc文件 S... Step 1. 依次解析/init.rc、/system/etc/init、/Vendor/etc/init的rc文件Step 2. 执行rc文件的触发器"on early-init" -> "on init" -> "on late-init"Step 3. 依次执行每个action中携带command对应的执行函数 Share on Twitter Facebook LinkedIn Previous Next Leave a comment
Leave a comment