FirstStageMain

因为启动时并没有带任何参数,所在最先执行的是FirstStageMain,FirstStageMain函数实现在:system/core/init/first_stage_init.cpp。

int FirstStageMain(int argc, char** argv) {

   if (!DoFirstStageMount(!created_devices)) {
       LOG(FATAL) << "Failed to mount required partitions early ...";
   }

   const char* path = "/system/bin/init";
   const char* args[] = {path, "selinux_setup", nullptr};
   auto fd = open("/dev/kmsg", O_WRONLY | O_CLOEXEC);
   dup2(fd, STDOUT_FILENO);
   dup2(fd, STDERR_FILENO);
   close(fd);
   execv(path, const_cast(args));

   // execv() only returns if an error happened, in which case we
   // panic and never fall through this conditional.
   PLOG(FATAL) << "execv(\"" << path << "\") failed";

}

这个函数的主要功能是创建目录、挂载分区等,然后再次运行init, 并带了selinux_setup参数,进入到SetupSelinux函数。



版权所有,违者必究,欢迎转载请注明出处。