Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c5c46d2 authored by Sorin Basca's avatar Sorin Basca
Browse files

Using jniThrowErrnoException in android_util_Process

Since libnativehelper now has an implementation of jniThrowErrnoException,
this method is now used when a system error occurs to avoid code
duplication.

Bug: 180958753
Test: m
Change-Id: I14b8f6c5fb7179624450ecaae10c6bb1f48b4029
parent 039e79a2
Loading
Loading
Loading
Loading
+1 −19
Original line number Diff line number Diff line
@@ -1290,24 +1290,6 @@ void android_os_Process_removeAllProcessGroups(JNIEnv* env, jobject clazz)
    return removeAllProcessGroups();
}

static void throwErrnoException(JNIEnv* env, const char* functionName, int error) {
    ScopedLocalRef<jstring> detailMessage(env, env->NewStringUTF(functionName));
    if (detailMessage.get() == NULL) {
        // Not really much we can do here. We're probably dead in the water,
        // but let's try to stumble on...
        env->ExceptionClear();
    }
    static jclass errnoExceptionClass =
            MakeGlobalRefOrDie(env, FindClassOrDie(env, "android/system/ErrnoException"));

    static jmethodID errnoExceptionCtor =
            GetMethodIDOrDie(env, errnoExceptionClass, "<init>", "(Ljava/lang/String;I)V");

    jobject exception =
            env->NewObject(errnoExceptionClass, errnoExceptionCtor, detailMessage.get(), error);
    env->Throw(reinterpret_cast<jthrowable>(exception));
}

// Wrapper function to the syscall pidfd_open, which creates a file
// descriptor that refers to the process whose PID is specified in pid.
static inline int sys_pidfd_open(pid_t pid, unsigned int flags) {
@@ -1317,7 +1299,7 @@ static inline int sys_pidfd_open(pid_t pid, unsigned int flags) {
static jint android_os_Process_nativePidFdOpen(JNIEnv* env, jobject, jint pid, jint flags) {
    int fd = sys_pidfd_open(pid, flags);
    if (fd < 0) {
        throwErrnoException(env, "nativePidFdOpen", errno);
        jniThrowErrnoException(env, "nativePidFdOpen", errno);
        return -1;
    }
    return fd;