dynamic linker is running for init
init is now built as a dynamic executable, so the dynamic linker has to
be able to run in the init process. However, since init is launched so
early, even /dev/* and /proc/* file systems are not mounted and thus
some APIs that rely on the paths do not work. The dynamic linker now
goes alternative path when it is running in the init process.
For example, /proc/self/exe is not read for the init since we always now
the path of the init (/init). Also, arc4random* APIs are not used since
the APIs rely on /dev/urandom. Linker now does not randomize library
loading order and addresses when running in the init process.
Bug: 80454183
Test: `adb reboot recovery; adb devices` shows the device ID
Change-Id: I29b6d70e4df5f7f690876126d5fe81258c1d3115
diff --git a/linker/linker_utils.cpp b/linker/linker_utils.cpp
index 661e7cb..789d5c1 100644
--- a/linker/linker_utils.cpp
+++ b/linker/linker_utils.cpp
@@ -239,3 +239,8 @@
}
}
}
+
+bool is_init() {
+ static bool ret = (getpid() == 1);
+ return ret;
+}