Merge "Frameworks/base: Make RuntimeAbort more expressive"
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -74,8 +75,10 @@ enum MountExternalKind {
|
|||||||
MOUNT_EXTERNAL_WRITE = 3,
|
MOUNT_EXTERNAL_WRITE = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void RuntimeAbort(JNIEnv* env) {
|
static void RuntimeAbort(JNIEnv* env, int line, const char* msg) {
|
||||||
env->FatalError("RuntimeAbort");
|
std::ostringstream oss;
|
||||||
|
oss << __FILE__ << ":" << line << ": " << msg;
|
||||||
|
env->FatalError(oss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// This signal handler is for zygote mode, since the zygote must reap its children
|
// This signal handler is for zygote mode, since the zygote must reap its children
|
||||||
@@ -169,12 +172,11 @@ static void SetGids(JNIEnv* env, jintArray javaGids) {
|
|||||||
|
|
||||||
ScopedIntArrayRO gids(env, javaGids);
|
ScopedIntArrayRO gids(env, javaGids);
|
||||||
if (gids.get() == NULL) {
|
if (gids.get() == NULL) {
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "Getting gids int array failed");
|
||||||
}
|
}
|
||||||
int rc = setgroups(gids.size(), reinterpret_cast<const gid_t*>(&gids[0]));
|
int rc = setgroups(gids.size(), reinterpret_cast<const gid_t*>(&gids[0]));
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
ALOGE("setgroups failed");
|
RuntimeAbort(env, __LINE__, "setgroups failed");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,8 +196,7 @@ static void SetRLimits(JNIEnv* env, jobjectArray javaRlimits) {
|
|||||||
ScopedLocalRef<jobject> javaRlimitObject(env, env->GetObjectArrayElement(javaRlimits, i));
|
ScopedLocalRef<jobject> javaRlimitObject(env, env->GetObjectArrayElement(javaRlimits, i));
|
||||||
ScopedIntArrayRO javaRlimit(env, reinterpret_cast<jintArray>(javaRlimitObject.get()));
|
ScopedIntArrayRO javaRlimit(env, reinterpret_cast<jintArray>(javaRlimitObject.get()));
|
||||||
if (javaRlimit.size() != 3) {
|
if (javaRlimit.size() != 3) {
|
||||||
ALOGE("rlimits array must have a second dimension of size 3");
|
RuntimeAbort(env, __LINE__, "rlimits array must have a second dimension of size 3");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rlim.rlim_cur = javaRlimit[1];
|
rlim.rlim_cur = javaRlimit[1];
|
||||||
@@ -205,7 +206,7 @@ static void SetRLimits(JNIEnv* env, jobjectArray javaRlimits) {
|
|||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
ALOGE("setrlimit(%d, {%ld, %ld}) failed", javaRlimit[0], rlim.rlim_cur,
|
ALOGE("setrlimit(%d, {%ld, %ld}) failed", javaRlimit[0], rlim.rlim_cur,
|
||||||
rlim.rlim_max);
|
rlim.rlim_max);
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "setrlimit failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,8 +217,7 @@ extern "C" int gMallocLeakZygoteChild;
|
|||||||
static void EnableKeepCapabilities(JNIEnv* env) {
|
static void EnableKeepCapabilities(JNIEnv* env) {
|
||||||
int rc = prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
|
int rc = prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
ALOGE("prctl(PR_SET_KEEPCAPS) failed");
|
RuntimeAbort(env, __LINE__, "prctl(PR_SET_KEEPCAPS) failed");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,8 +229,7 @@ static void DropCapabilitiesBoundingSet(JNIEnv* env) {
|
|||||||
ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
|
ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
|
||||||
"your kernel is compiled with file capabilities support");
|
"your kernel is compiled with file capabilities support");
|
||||||
} else {
|
} else {
|
||||||
ALOGE("prctl(PR_CAPBSET_DROP) failed");
|
RuntimeAbort(env, __LINE__, "prctl(PR_CAPBSET_DROP) failed");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,7 +250,7 @@ static void SetCapabilities(JNIEnv* env, int64_t permitted, int64_t effective) {
|
|||||||
|
|
||||||
if (capset(&capheader, &capdata[0]) == -1) {
|
if (capset(&capheader, &capdata[0]) == -1) {
|
||||||
ALOGE("capset(%" PRId64 ", %" PRId64 ") failed", permitted, effective);
|
ALOGE("capset(%" PRId64 ", %" PRId64 ") failed", permitted, effective);
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "capset failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +258,7 @@ static void SetSchedulerPolicy(JNIEnv* env) {
|
|||||||
errno = -set_sched_policy(0, SP_DEFAULT);
|
errno = -set_sched_policy(0, SP_DEFAULT);
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
ALOGE("set_sched_policy(0, SP_DEFAULT) failed");
|
ALOGE("set_sched_policy(0, SP_DEFAULT) failed");
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "set_sched_policy(0, SP_DEFAULT) failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,8 +369,7 @@ static void DetachDescriptors(JNIEnv* env, jintArray fdsToClose) {
|
|||||||
jsize count = env->GetArrayLength(fdsToClose);
|
jsize count = env->GetArrayLength(fdsToClose);
|
||||||
ScopedIntArrayRO ar(env, fdsToClose);
|
ScopedIntArrayRO ar(env, fdsToClose);
|
||||||
if (ar.get() == NULL) {
|
if (ar.get() == NULL) {
|
||||||
ALOGE("Bad fd array");
|
RuntimeAbort(env, __LINE__, "Bad fd array");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
jsize i;
|
jsize i;
|
||||||
int devnull;
|
int devnull;
|
||||||
@@ -379,13 +377,13 @@ static void DetachDescriptors(JNIEnv* env, jintArray fdsToClose) {
|
|||||||
devnull = open("/dev/null", O_RDWR);
|
devnull = open("/dev/null", O_RDWR);
|
||||||
if (devnull < 0) {
|
if (devnull < 0) {
|
||||||
ALOGE("Failed to open /dev/null: %s", strerror(errno));
|
ALOGE("Failed to open /dev/null: %s", strerror(errno));
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "Failed to open /dev/null");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ALOGV("Switching descriptor %d to /dev/null: %s", ar[i], strerror(errno));
|
ALOGV("Switching descriptor %d to /dev/null: %s", ar[i], strerror(errno));
|
||||||
if (dup2(devnull, ar[i]) < 0) {
|
if (dup2(devnull, ar[i]) < 0) {
|
||||||
ALOGE("Failed dup2() on descriptor %d: %s", ar[i], strerror(errno));
|
ALOGE("Failed dup2() on descriptor %d: %s", ar[i], strerror(errno));
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "Failed dup2()");
|
||||||
}
|
}
|
||||||
close(devnull);
|
close(devnull);
|
||||||
}
|
}
|
||||||
@@ -493,8 +491,7 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra
|
|||||||
// FUSE hasn't been created yet by init.
|
// FUSE hasn't been created yet by init.
|
||||||
// In either case, continue without external storage.
|
// In either case, continue without external storage.
|
||||||
} else {
|
} else {
|
||||||
ALOGE("Cannot continue without emulated storage");
|
RuntimeAbort(env, __LINE__, "Cannot continue without emulated storage");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,13 +519,13 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra
|
|||||||
int rc = setresgid(gid, gid, gid);
|
int rc = setresgid(gid, gid, gid);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
ALOGE("setresgid(%d) failed: %s", gid, strerror(errno));
|
ALOGE("setresgid(%d) failed: %s", gid, strerror(errno));
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "setresgid failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = setresuid(uid, uid, uid);
|
rc = setresuid(uid, uid, uid);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
ALOGE("setresuid(%d) failed: %s", uid, strerror(errno));
|
ALOGE("setresuid(%d) failed: %s", uid, strerror(errno));
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "setresuid failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NeedsNoRandomizeWorkaround()) {
|
if (NeedsNoRandomizeWorkaround()) {
|
||||||
@@ -550,8 +547,7 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra
|
|||||||
se_info = new ScopedUtfChars(env, java_se_info);
|
se_info = new ScopedUtfChars(env, java_se_info);
|
||||||
se_info_c_str = se_info->c_str();
|
se_info_c_str = se_info->c_str();
|
||||||
if (se_info_c_str == NULL) {
|
if (se_info_c_str == NULL) {
|
||||||
ALOGE("se_info_c_str == NULL");
|
RuntimeAbort(env, __LINE__, "se_info_c_str == NULL");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const char* se_name_c_str = NULL;
|
const char* se_name_c_str = NULL;
|
||||||
@@ -560,15 +556,14 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra
|
|||||||
se_name = new ScopedUtfChars(env, java_se_name);
|
se_name = new ScopedUtfChars(env, java_se_name);
|
||||||
se_name_c_str = se_name->c_str();
|
se_name_c_str = se_name->c_str();
|
||||||
if (se_name_c_str == NULL) {
|
if (se_name_c_str == NULL) {
|
||||||
ALOGE("se_name_c_str == NULL");
|
RuntimeAbort(env, __LINE__, "se_name_c_str == NULL");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc = selinux_android_setcontext(uid, is_system_server, se_info_c_str, se_name_c_str);
|
rc = selinux_android_setcontext(uid, is_system_server, se_info_c_str, se_name_c_str);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
ALOGE("selinux_android_setcontext(%d, %d, \"%s\", \"%s\") failed", uid,
|
ALOGE("selinux_android_setcontext(%d, %d, \"%s\", \"%s\") failed", uid,
|
||||||
is_system_server, se_info_c_str, se_name_c_str);
|
is_system_server, se_info_c_str, se_name_c_str);
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "selinux_android_setcontext failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make it easier to debug audit logs by setting the main thread's name to the
|
// Make it easier to debug audit logs by setting the main thread's name to the
|
||||||
@@ -588,8 +583,7 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra
|
|||||||
env->CallStaticVoidMethod(gZygoteClass, gCallPostForkChildHooks, debug_flags,
|
env->CallStaticVoidMethod(gZygoteClass, gCallPostForkChildHooks, debug_flags,
|
||||||
is_system_server ? NULL : instructionSet);
|
is_system_server ? NULL : instructionSet);
|
||||||
if (env->ExceptionCheck()) {
|
if (env->ExceptionCheck()) {
|
||||||
ALOGE("Error calling post fork hooks.");
|
RuntimeAbort(env, __LINE__, "Error calling post fork hooks.");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
} else if (pid > 0) {
|
} else if (pid > 0) {
|
||||||
// the parent process
|
// the parent process
|
||||||
@@ -621,16 +615,14 @@ static jint com_android_internal_os_Zygote_nativeForkAndSpecialize(
|
|||||||
jsize length = env->GetArrayLength(reinterpret_cast<jarray>(gids));
|
jsize length = env->GetArrayLength(reinterpret_cast<jarray>(gids));
|
||||||
jintArray gids_with_system = env->NewIntArray(length + 1);
|
jintArray gids_with_system = env->NewIntArray(length + 1);
|
||||||
if (!gids_with_system) {
|
if (!gids_with_system) {
|
||||||
ALOGE("could not allocate java array for gids");
|
RuntimeAbort(env, __LINE__, "could not allocate java array for gids");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jint *gids_elements = env->GetIntArrayElements(gids, NULL);
|
jint *gids_elements = env->GetIntArrayElements(gids, NULL);
|
||||||
jint *gids_with_system_elements = env->GetIntArrayElements(gids_with_system, NULL);
|
jint *gids_with_system_elements = env->GetIntArrayElements(gids_with_system, NULL);
|
||||||
|
|
||||||
if (!gids_elements || !gids_with_system_elements) {
|
if (!gids_elements || !gids_with_system_elements) {
|
||||||
ALOGE("could not allocate arrays for gids");
|
RuntimeAbort(env, __LINE__, "could not allocate arrays for gids");
|
||||||
RuntimeAbort(env);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gids_with_system_elements[0] = AID_SYSTEM;
|
gids_with_system_elements[0] = AID_SYSTEM;
|
||||||
@@ -665,7 +657,7 @@ static jint com_android_internal_os_Zygote_nativeForkSystemServer(
|
|||||||
int status;
|
int status;
|
||||||
if (waitpid(pid, &status, WNOHANG) == pid) {
|
if (waitpid(pid, &status, WNOHANG) == pid) {
|
||||||
ALOGE("System server process %d has died. Restarting Zygote!", pid);
|
ALOGE("System server process %d has died. Restarting Zygote!", pid);
|
||||||
RuntimeAbort(env);
|
RuntimeAbort(env, __LINE__, "System server process has died. Restarting Zygote!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pid;
|
return pid;
|
||||||
|
|||||||
Reference in New Issue
Block a user